[front]: value fix

This commit is contained in:
Николай 2024-10-22 22:20:28 +03:00
parent 17ba979e41
commit bc53f252d6
2 changed files with 6 additions and 7 deletions

View File

@ -5,7 +5,7 @@ import clsx from 'clsx';
import React, { useState } from 'react'; import React, { useState } from 'react';
import { downloadImage, getWindmillData } from 'src/api'; import { downloadImage, getWindmillData } from 'src/api';
import { WindmillTable } from '../windmill-table'; import { WindmillTable } from '@components/ux';
import { initialValues } from './constants'; import { initialValues } from './constants';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
import { WindmillFormProps, WindmillFormStore } from './types'; import { WindmillFormProps, WindmillFormStore } from './types';

View File

@ -8,21 +8,20 @@ import { WindmillTableRow } from './parts/windmill-table-row';
import styles from './styles.module.scss'; import styles from './styles.module.scss';
import { WindmillTableProps } from './types'; import { WindmillTableProps } from './types';
export function WindmillTable({ value, onChange }: WindmillTableProps) { export function WindmillTable({ value = [], onChange }: WindmillTableProps) {
const [selectedRows, setSelectedRows] = useState<Record<string, boolean>>({}); const [selectedRows, setSelectedRows] = useState<Record<string, boolean>>({});
const localValue = value ?? [];
const handleDeleteButtonClick = () => { const handleDeleteButtonClick = () => {
onChange?.(localValue.filter((_, i) => !selectedRows[i])); onChange?.(value.filter((_, i) => !selectedRows[i]));
setSelectedRows({}); setSelectedRows({});
}; };
const handlePlusButtonClick = () => { const handlePlusButtonClick = () => {
onChange?.([...localValue, { x: '', y: '', angle: '' }]); onChange?.([...value, { x: '', y: '', angle: '' }]);
}; };
const handleRowChange = (index: number, windmill: WindmillConfig) => { const handleRowChange = (index: number, windmill: WindmillConfig) => {
onChange?.(localValue.with(index, windmill)); onChange?.(value.with(index, windmill));
}; };
const handleRowSelect = (index: number) => { const handleRowSelect = (index: number) => {
@ -38,7 +37,7 @@ export function WindmillTable({ value, onChange }: WindmillTableProps) {
<Span className={styles.span}>y</Span> <Span className={styles.span}>y</Span>
<Span className={styles.span}>angle</Span> <Span className={styles.span}>angle</Span>
</header> </header>
{localValue.map((v, i) => ( {value.map((v, i) => (
<WindmillTableRow <WindmillTableRow
key={i} key={i}
value={v} value={v}