From c7df031041fcd25b3edf8ed3d5cdeffe35e9eb1a Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Thu, 21 Nov 2024 00:26:04 +0300 Subject: [PATCH] R: Decouple setters from onChange events --- .../components/select/SelectMultiGrammeme.tsx | 6 ++-- .../src/components/ui/DataTable/DataTable.tsx | 4 +-- .../src/components/ui/DataTable/SelectAll.tsx | 6 ++-- .../src/components/ui/DataTable/SelectRow.tsx | 6 ++-- .../src/components/ui/DataTable/TableBody.tsx | 10 +++--- .../components/ui/DataTable/TableHeader.tsx | 6 ++-- .../DlgCreateOperation/DlgCreateOperation.tsx | 16 ++++----- .../DlgCreateOperation/TabInputOperation.tsx | 36 +++++++++---------- .../TabSynthesisOperation.tsx | 18 +++++----- .../DlgEditOperation/DlgEditOperation.tsx | 6 ++-- .../dialogs/DlgEditOperation/TabOperation.tsx | 14 ++++---- .../DlgEditReference/DlgEditReference.tsx | 9 +++-- .../DlgEditReference/TabEntityReference.tsx | 14 ++++---- .../TabSyntacticReference.tsx | 12 +++---- .../DlgEditWordForms/DlgEditWordForms.tsx | 2 +- .../src/pages/LibraryPage/LibraryPage.tsx | 12 +++---- .../src/pages/LibraryPage/ToolbarSearch.tsx | 26 +++++++------- .../pages/LibraryPage/ViewSideLocation.tsx | 22 ++++++------ .../OssPage/EditorOssCard/EditorOssCard.tsx | 2 +- .../pages/OssPage/EditorOssCard/FormOSS.tsx | 2 +- .../OssPage/EditorOssGraph/EditorOssGraph.tsx | 2 +- .../pages/OssPage/EditorOssGraph/OssFlow.tsx | 2 +- .../src/pages/OssPage/OssEditContext.tsx | 2 +- .../EditorConstituenta/EditorConstituenta.tsx | 2 +- .../EditorConstituenta/FormConstituenta.tsx | 8 ++--- .../EditorRSExpression/EditorRSExpression.tsx | 20 +++++------ .../EditorRSFormCard/EditorRSFormCard.tsx | 2 +- .../EditorRSFormCard/FormRSForm.tsx | 2 +- 28 files changed, 138 insertions(+), 131 deletions(-) diff --git a/rsconcept/frontend/src/components/select/SelectMultiGrammeme.tsx b/rsconcept/frontend/src/components/select/SelectMultiGrammeme.tsx index fe8f89ca..6ed16afb 100644 --- a/rsconcept/frontend/src/components/select/SelectMultiGrammeme.tsx +++ b/rsconcept/frontend/src/components/select/SelectMultiGrammeme.tsx @@ -11,11 +11,11 @@ interface SelectMultiGrammemeProps extends Omit, 'value' | 'onChange'>, CProps.Styling { value: IGrammemeOption[]; - setValue: React.Dispatch>; + onChangeValue: (newValue: IGrammemeOption[]) => void; placeholder?: string; } -function SelectMultiGrammeme({ value, setValue, ...restProps }: SelectMultiGrammemeProps) { +function SelectMultiGrammeme({ value, onChangeValue, ...restProps }: SelectMultiGrammemeProps) { const [options, setOptions] = useState([]); useEffect(() => { @@ -29,7 +29,7 @@ function SelectMultiGrammeme({ value, setValue, ...restProps }: SelectMultiGramm setValue([...newValue].sort(compareGrammemeOptions))} + onChange={newValue => onChangeValue([...newValue].sort(compareGrammemeOptions))} {...restProps} /> ); diff --git a/rsconcept/frontend/src/components/ui/DataTable/DataTable.tsx b/rsconcept/frontend/src/components/ui/DataTable/DataTable.tsx index 186d1320..444ace30 100644 --- a/rsconcept/frontend/src/components/ui/DataTable/DataTable.tsx +++ b/rsconcept/frontend/src/components/ui/DataTable/DataTable.tsx @@ -157,7 +157,7 @@ function DataTable({ enableRowSelection={enableRowSelection} enableSorting={enableSorting} headPosition={headPosition} - setLastSelected={setLastSelected} + resetLastSelected={() => setLastSelected(undefined)} /> ) : null} @@ -168,7 +168,7 @@ function DataTable({ conditionalRowStyles={conditionalRowStyles} enableRowSelection={enableRowSelection} lastSelected={lastSelected} - setLastSelected={setLastSelected} + onChangeLastSelected={setLastSelected} onRowClicked={onRowClicked} onRowDoubleClicked={onRowDoubleClicked} /> diff --git a/rsconcept/frontend/src/components/ui/DataTable/SelectAll.tsx b/rsconcept/frontend/src/components/ui/DataTable/SelectAll.tsx index c7da72bd..11ff2b21 100644 --- a/rsconcept/frontend/src/components/ui/DataTable/SelectAll.tsx +++ b/rsconcept/frontend/src/components/ui/DataTable/SelectAll.tsx @@ -4,12 +4,12 @@ import CheckboxTristate from '@/components/ui/CheckboxTristate'; interface SelectAllProps { table: Table; - setLastSelected: React.Dispatch>; + resetLastSelected: () => void; } -function SelectAll({ table, setLastSelected }: SelectAllProps) { +function SelectAll({ table, resetLastSelected }: SelectAllProps) { function handleChange(value: boolean | null) { - setLastSelected(undefined); + resetLastSelected(); table.toggleAllPageRowsSelected(value !== false); } diff --git a/rsconcept/frontend/src/components/ui/DataTable/SelectRow.tsx b/rsconcept/frontend/src/components/ui/DataTable/SelectRow.tsx index b0a673c2..57135c4f 100644 --- a/rsconcept/frontend/src/components/ui/DataTable/SelectRow.tsx +++ b/rsconcept/frontend/src/components/ui/DataTable/SelectRow.tsx @@ -4,12 +4,12 @@ import Checkbox from '@/components/ui/Checkbox'; interface SelectRowProps { row: Row; - setLastSelected: React.Dispatch>; + onChangeLastSelected: (newValue: string | undefined) => void; } -function SelectRow({ row, setLastSelected }: SelectRowProps) { +function SelectRow({ row, onChangeLastSelected }: SelectRowProps) { function handleChange(value: boolean) { - setLastSelected(row.id); + onChangeLastSelected(row.id); row.toggleSelected(value); } diff --git a/rsconcept/frontend/src/components/ui/DataTable/TableBody.tsx b/rsconcept/frontend/src/components/ui/DataTable/TableBody.tsx index 0bb3ce55..8fa11dbf 100644 --- a/rsconcept/frontend/src/components/ui/DataTable/TableBody.tsx +++ b/rsconcept/frontend/src/components/ui/DataTable/TableBody.tsx @@ -14,7 +14,7 @@ interface TableBodyProps { conditionalRowStyles?: IConditionalStyle[]; lastSelected: string | undefined; - setLastSelected: React.Dispatch>; + onChangeLastSelected: (newValue: string | undefined) => void; onRowClicked?: (rowData: TData, event: CProps.EventMouse) => void; onRowDoubleClicked?: (rowData: TData, event: CProps.EventMouse) => void; @@ -27,7 +27,7 @@ function TableBody({ enableRowSelection, conditionalRowStyles, lastSelected, - setLastSelected, + onChangeLastSelected, onRowClicked, onRowDoubleClicked }: TableBodyProps) { @@ -49,9 +49,9 @@ function TableBody({ newSelection[row.id] = !target.getIsSelected(); }); table.setRowSelection(prev => ({ ...prev, ...newSelection })); - setLastSelected(undefined); + onChangeLastSelected(undefined); } else { - setLastSelected(target.id); + onChangeLastSelected(target.id); target.toggleSelected(!target.getIsSelected()); } } @@ -83,7 +83,7 @@ function TableBody({ > {enableRowSelection ? ( - + ) : null} {row.getVisibleCells().map((cell: Cell) => ( diff --git a/rsconcept/frontend/src/components/ui/DataTable/TableHeader.tsx b/rsconcept/frontend/src/components/ui/DataTable/TableHeader.tsx index 4995217d..0f8ad7c6 100644 --- a/rsconcept/frontend/src/components/ui/DataTable/TableHeader.tsx +++ b/rsconcept/frontend/src/components/ui/DataTable/TableHeader.tsx @@ -8,7 +8,7 @@ interface TableHeaderProps { headPosition?: string; enableRowSelection?: boolean; enableSorting?: boolean; - setLastSelected: React.Dispatch>; + resetLastSelected: () => void; } function TableHeader({ @@ -16,7 +16,7 @@ function TableHeader({ headPosition, enableRowSelection, enableSorting, - setLastSelected + resetLastSelected }: TableHeaderProps) { return ( ({ {enableRowSelection ? ( - + ) : null} {headerGroup.headers.map((header: Header) => ( diff --git a/rsconcept/frontend/src/dialogs/DlgCreateOperation/DlgCreateOperation.tsx b/rsconcept/frontend/src/dialogs/DlgCreateOperation/DlgCreateOperation.tsx index 148c5aff..6bc6e600 100644 --- a/rsconcept/frontend/src/dialogs/DlgCreateOperation/DlgCreateOperation.tsx +++ b/rsconcept/frontend/src/dialogs/DlgCreateOperation/DlgCreateOperation.tsx @@ -103,15 +103,15 @@ function DlgCreateOperation({ hideWindow, oss, onCreate, initialInputs }: DlgCre ), @@ -124,11 +124,11 @@ function DlgCreateOperation({ hideWindow, oss, onCreate, initialInputs }: DlgCre diff --git a/rsconcept/frontend/src/dialogs/DlgCreateOperation/TabInputOperation.tsx b/rsconcept/frontend/src/dialogs/DlgCreateOperation/TabInputOperation.tsx index f2288b8b..3447932f 100644 --- a/rsconcept/frontend/src/dialogs/DlgCreateOperation/TabInputOperation.tsx +++ b/rsconcept/frontend/src/dialogs/DlgCreateOperation/TabInputOperation.tsx @@ -18,29 +18,29 @@ import { sortItemsForOSS } from '@/models/ossAPI'; interface TabInputOperationProps { oss: IOperationSchema; alias: string; - setAlias: React.Dispatch>; + onChangeAlias: (newValue: string) => void; title: string; - setTitle: React.Dispatch>; + onChangeTitle: (newValue: string) => void; comment: string; - setComment: React.Dispatch>; + onChangeComment: (newValue: string) => void; attachedID: LibraryItemID | undefined; - setAttachedID: React.Dispatch>; + onChangeAttachedID: (newValue: LibraryItemID | undefined) => void; createSchema: boolean; - setCreateSchema: React.Dispatch>; + onChangeCreateSchema: (newValue: boolean) => void; } function TabInputOperation({ oss, alias, - setAlias, + onChangeAlias, title, - setTitle, + onChangeTitle, comment, - setComment, + onChangeComment, attachedID, - setAttachedID, + onChangeAttachedID, createSchema, - setCreateSchema + onChangeCreateSchema }: TabInputOperationProps) { const baseFilter = useCallback((item: ILibraryItem) => !oss.schemas.includes(item.id), [oss]); const library = useLibrary(); @@ -48,9 +48,9 @@ function TabInputOperation({ useEffect(() => { if (createSchema) { - setAttachedID(undefined); + onChangeAttachedID(undefined); } - }, [createSchema, setAttachedID]); + }, [createSchema, onChangeAttachedID]); return ( @@ -58,7 +58,7 @@ function TabInputOperation({ id='operation_title' label='Полное название' value={title} - onChange={event => setTitle(event.target.value)} + onChange={event => onChangeTitle(event.target.value)} disabled={attachedID !== undefined} />
@@ -67,7 +67,7 @@ function TabInputOperation({ label='Сокращение' className='w-[16rem]' value={alias} - onChange={event => setAlias(event.target.value)} + onChange={event => onChangeAlias(event.target.value)} disabled={attachedID !== undefined} /> @@ -77,7 +77,7 @@ function TabInputOperation({ noResize rows={3} value={comment} - onChange={event => setComment(event.target.value)} + onChange={event => onChangeComment(event.target.value)} disabled={attachedID !== undefined} />
@@ -90,13 +90,13 @@ function TabInputOperation({ noHover noPadding icon={} - onClick={() => setAttachedID(undefined)} + onClick={() => onChangeAttachedID(undefined)} disabled={attachedID == undefined} /> @@ -106,7 +106,7 @@ function TabInputOperation({ items={sortedItems} value={attachedID} itemType={LibraryItemType.RSFORM} - onSelectValue={setAttachedID} + onSelectValue={onChangeAttachedID} rows={8} baseFilter={baseFilter} /> diff --git a/rsconcept/frontend/src/dialogs/DlgCreateOperation/TabSynthesisOperation.tsx b/rsconcept/frontend/src/dialogs/DlgCreateOperation/TabSynthesisOperation.tsx index a1e4ee67..09a9d727 100644 --- a/rsconcept/frontend/src/dialogs/DlgCreateOperation/TabSynthesisOperation.tsx +++ b/rsconcept/frontend/src/dialogs/DlgCreateOperation/TabSynthesisOperation.tsx @@ -10,11 +10,11 @@ import PickMultiOperation from '../../components/select/PickMultiOperation'; interface TabSynthesisOperationProps { oss: IOperationSchema; alias: string; - setAlias: React.Dispatch>; + onChangeAlias: (newValue: string) => void; title: string; - setTitle: React.Dispatch>; + onChangeTitle: (newValue: string) => void; comment: string; - setComment: React.Dispatch>; + onChangeComment: (newValue: string) => void; inputs: OperationID[]; setInputs: React.Dispatch>; } @@ -22,11 +22,11 @@ interface TabSynthesisOperationProps { function TabSynthesisOperation({ oss, alias, - setAlias, + onChangeAlias, title, - setTitle, + onChangeTitle, comment, - setComment, + onChangeComment, inputs, setInputs }: TabSynthesisOperationProps) { @@ -36,7 +36,7 @@ function TabSynthesisOperation({ id='operation_title' label='Полное название' value={title} - onChange={event => setTitle(event.target.value)} + onChange={event => onChangeTitle(event.target.value)} />
setAlias(event.target.value)} + onChange={event => onChangeAlias(event.target.value)} />