[front]: value fix
This commit is contained in:
parent
17ba979e41
commit
bc53f252d6
@ -5,7 +5,7 @@ import clsx from 'clsx';
|
||||
import React, { useState } from 'react';
|
||||
import { downloadImage, getWindmillData } from 'src/api';
|
||||
|
||||
import { WindmillTable } from '../windmill-table';
|
||||
import { WindmillTable } from '@components/ux';
|
||||
import { initialValues } from './constants';
|
||||
import styles from './styles.module.scss';
|
||||
import { WindmillFormProps, WindmillFormStore } from './types';
|
||||
|
@ -8,21 +8,20 @@ import { WindmillTableRow } from './parts/windmill-table-row';
|
||||
import styles from './styles.module.scss';
|
||||
import { WindmillTableProps } from './types';
|
||||
|
||||
export function WindmillTable({ value, onChange }: WindmillTableProps) {
|
||||
export function WindmillTable({ value = [], onChange }: WindmillTableProps) {
|
||||
const [selectedRows, setSelectedRows] = useState<Record<string, boolean>>({});
|
||||
const localValue = value ?? [];
|
||||
|
||||
const handleDeleteButtonClick = () => {
|
||||
onChange?.(localValue.filter((_, i) => !selectedRows[i]));
|
||||
onChange?.(value.filter((_, i) => !selectedRows[i]));
|
||||
setSelectedRows({});
|
||||
};
|
||||
|
||||
const handlePlusButtonClick = () => {
|
||||
onChange?.([...localValue, { x: '', y: '', angle: '' }]);
|
||||
onChange?.([...value, { x: '', y: '', angle: '' }]);
|
||||
};
|
||||
|
||||
const handleRowChange = (index: number, windmill: WindmillConfig) => {
|
||||
onChange?.(localValue.with(index, windmill));
|
||||
onChange?.(value.with(index, windmill));
|
||||
};
|
||||
|
||||
const handleRowSelect = (index: number) => {
|
||||
@ -38,7 +37,7 @@ export function WindmillTable({ value, onChange }: WindmillTableProps) {
|
||||
<Span className={styles.span}>y</Span>
|
||||
<Span className={styles.span}>angle</Span>
|
||||
</header>
|
||||
{localValue.map((v, i) => (
|
||||
{value.map((v, i) => (
|
||||
<WindmillTableRow
|
||||
key={i}
|
||||
value={v}
|
||||
|
Loading…
Reference in New Issue
Block a user