From 41eac3fc4fe6169c902ae8977d1879b7d2207e0b Mon Sep 17 00:00:00 2001
From: IRBorisov <8611739+IRBorisov@users.noreply.github.com>
Date: Sun, 24 Mar 2024 19:25:42 +0300
Subject: [PATCH] UI refactoring and small fixes
---
.../src/components/info/GrammemeBadge.tsx | 4 +-
.../select/ConstituentaMultiPicker.tsx | 8 +-
.../components/select/SubstitutionsPicker.tsx | 263 ++++++++++++++++++
.../src/components/select/VersionSelector.tsx | 11 +-
.../DlgInlineSynthesis/DlgInlineSynthesis.tsx | 5 +-
.../dialogs/DlgInlineSynthesis/SchemaTab.tsx | 7 +-
.../DlgInlineSynthesis/SubstitutionsTab.tsx | 129 +--------
.../DlgInlineSynthesis/SubstitutionsTable.tsx | 130 ---------
.../RSFormPage/EditorRSForm/FormRSForm.tsx | 1 +
9 files changed, 290 insertions(+), 268 deletions(-)
create mode 100644 rsconcept/frontend/src/components/select/SubstitutionsPicker.tsx
delete mode 100644 rsconcept/frontend/src/dialogs/DlgInlineSynthesis/SubstitutionsTable.tsx
diff --git a/rsconcept/frontend/src/components/info/GrammemeBadge.tsx b/rsconcept/frontend/src/components/info/GrammemeBadge.tsx
index 2ae861c2..e235df23 100644
--- a/rsconcept/frontend/src/components/info/GrammemeBadge.tsx
+++ b/rsconcept/frontend/src/components/info/GrammemeBadge.tsx
@@ -6,15 +6,13 @@ import { colorFgGrammeme } from '@/styling/color';
import { labelGrammeme } from '@/utils/labels';
interface GrammemeBadgeProps {
- key?: string;
grammeme: GramData;
}
-function GrammemeBadge({ key, grammeme }: GrammemeBadgeProps) {
+function GrammemeBadge({ grammeme }: GrammemeBadgeProps) {
const { colors } = useConceptTheme();
return (
boolean;
+ filter2?: (cst: IConstituenta) => boolean;
+
+ items: ISubstitution[];
+ setItems: React.Dispatch
>;
+}
+
+function SubstitutionIcon({ item }: { item: ISubstitution }) {
+ if (item.deleteRight) {
+ if (item.takeLeftTerm) {
+ return ;
+ } else {
+ return ;
+ }
+ } else {
+ if (item.takeLeftTerm) {
+ return ;
+ } else {
+ return ;
+ }
+ }
+}
+
+const columnHelper = createColumnHelper();
+
+function SubstitutionsPicker({
+ items,
+ schema1,
+ schema2,
+ filter1,
+ filter2,
+ rows,
+ setItems,
+ prefixID
+}: SubstitutionsPickerProps) {
+ const { colors } = useConceptTheme();
+
+ const [leftCst, setLeftCst] = useState(undefined);
+ const [rightCst, setRightCst] = useState(undefined);
+ const [deleteRight, setDeleteRight] = useState(true);
+ const [takeLeftTerm, setTakeLeftTerm] = useState(true);
+
+ const toggleDelete = () => setDeleteRight(prev => !prev);
+ const toggleTerm = () => setTakeLeftTerm(prev => !prev);
+
+ function addSubstitution() {
+ if (!leftCst || !rightCst) {
+ return;
+ }
+ const newSubstitution: ISubstitution = {
+ leftCst: leftCst,
+ rightCst: rightCst,
+ deleteRight: deleteRight,
+ takeLeftTerm: takeLeftTerm
+ };
+ setItems([
+ newSubstitution,
+ ...items.filter(
+ item =>
+ (!item.deleteRight && item.leftCst.id !== leftCst.id) ||
+ (item.deleteRight && item.rightCst.id !== rightCst.id)
+ )
+ ]);
+ }
+
+ const handleDeleteRow = useCallback(
+ (row: number) => {
+ setItems(prev => {
+ const newItems: ISubstitution[] = [];
+ prev.forEach((item, index) => {
+ if (index !== row) {
+ newItems.push(item);
+ }
+ });
+ return newItems;
+ });
+ },
+ [setItems]
+ );
+
+ const columns = useMemo(
+ () => [
+ columnHelper.accessor(item => describeConstituenta(item.leftCst), {
+ id: 'left_text',
+ header: 'Описание',
+ size: 1000,
+ cell: props => {props.getValue()}
+ }),
+ columnHelper.accessor(item => item.leftCst.alias, {
+ id: 'left_alias',
+ header: 'Имя',
+ size: 65,
+ cell: props => (
+
+ )
+ }),
+ columnHelper.display({
+ id: 'status',
+ header: '',
+ size: 40,
+ cell: props =>
+ }),
+ columnHelper.accessor(item => item.rightCst.alias, {
+ id: 'right_alias',
+ header: 'Имя',
+ size: 65,
+ cell: props => (
+
+ )
+ }),
+ columnHelper.accessor(item => describeConstituenta(item.rightCst), {
+ id: 'right_text',
+ header: 'Описание',
+ size: 1000,
+ cell: props => {props.getValue()}
+ }),
+ columnHelper.display({
+ id: 'actions',
+ size: 50,
+ minSize: 50,
+ maxSize: 50,
+ cell: props => (
+ }
+ onClick={() => handleDeleteRow(props.row.index)}
+ />
+ )
+ })
+ ],
+ [handleDeleteRow, colors, prefixID]
+ );
+
+ return (
+
+
+
+
+
+
+
+ ) : (
+
+ )
+ }
+ />
+
+ ) : (
+
+ )
+ }
+ />
+
+
+
!filter1 || filter1(cst))}
+ value={leftCst}
+ onSelectValue={setLeftCst}
+ />
+
+
+
}
+ disabled={!leftCst || !rightCst}
+ onClick={addSubstitution}
+ />
+
+
+
+
+
+
+ ) : (
+
+ )
+ }
+ />
+
+ ) : (
+
+ )
+ }
+ />
+
+
+
!filter2 || filter2(cst))}
+ value={rightCst}
+ onSelectValue={setRightCst}
+ />
+
+
+
+
+ Список пуст
+ Добавьте отождествление
+
+ }
+ />
+
+ );
+}
+
+export default SubstitutionsPicker;
diff --git a/rsconcept/frontend/src/components/select/VersionSelector.tsx b/rsconcept/frontend/src/components/select/VersionSelector.tsx
index 3835cdfa..5aa2f0e2 100644
--- a/rsconcept/frontend/src/components/select/VersionSelector.tsx
+++ b/rsconcept/frontend/src/components/select/VersionSelector.tsx
@@ -1,19 +1,22 @@
'use client';
+import clsx from 'clsx';
import { useMemo } from 'react';
import { IVersionInfo } from '@/models/library';
import { labelVersion } from '@/utils/labels';
+import { CProps } from '../props';
import SelectSingle from '../ui/SelectSingle';
-interface VersionSelectorProps {
+interface VersionSelectorProps extends CProps.Styling {
+ id?: string;
items?: IVersionInfo[];
value?: number;
onSelectValue: (newValue?: number) => void;
}
-function VersionSelector({ items, value, onSelectValue }: VersionSelectorProps) {
+function VersionSelector({ id, className, items, value, onSelectValue, ...restProps }: VersionSelectorProps) {
const options = useMemo(() => {
return [
{
@@ -33,10 +36,12 @@ function VersionSelector({ items, value, onSelectValue }: VersionSelectorProps)
return (
onSelectValue(data?.value)}
+ {...restProps}
/>
);
}
diff --git a/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/DlgInlineSynthesis.tsx b/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/DlgInlineSynthesis.tsx
index 57017db7..5f69f6f7 100644
--- a/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/DlgInlineSynthesis.tsx
+++ b/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/DlgInlineSynthesis.tsx
@@ -53,7 +53,10 @@ function DlgInlineSynthesis({ hideWindow, receiver, onInlineSynthesis }: DlgInli
onInlineSynthesis(data);
}
- useEffect(() => setSelected(source.schema ? source.schema?.items.map(cst => cst.id) : []), [source.schema]);
+ useEffect(() => {
+ setSelected(source.schema ? source.schema?.items.map(cst => cst.id) : []);
+ setSubstitutions([]);
+ }, [source.schema]);
return (
-
+
);
}
diff --git a/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/SubstitutionsTab.tsx b/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/SubstitutionsTab.tsx
index 7fb7459c..36ba200d 100644
--- a/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/SubstitutionsTab.tsx
+++ b/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/SubstitutionsTab.tsx
@@ -1,19 +1,11 @@
'use client';
-import { useState } from 'react';
-import { LuLocate, LuLocateOff, LuPower, LuPowerOff, LuReplace } from 'react-icons/lu';
-
import { ErrorData } from '@/components/info/InfoError';
-import ConstituentaSelector from '@/components/select/ConstituentaSelector';
-import Button from '@/components/ui/Button';
-import Label from '@/components/ui/Label';
-import MiniButton from '@/components/ui/MiniButton';
-import Overlay from '@/components/ui/Overlay';
import DataLoader from '@/components/wrap/DataLoader';
-import { ConstituentaID, IConstituenta, IRSForm, ISubstitution } from '@/models/rsform';
+import { ConstituentaID, IRSForm, ISubstitution } from '@/models/rsform';
import { prefixes } from '@/utils/constants';
-import SubstitutionsTable from './SubstitutionsTable';
+import SubstitutionsPicker from '../../components/select/SubstitutionsPicker';
interface SubstitutionsTabProps {
receiver?: IRSForm;
@@ -38,125 +30,16 @@ function SubstitutionsTab({
substitutions,
setSubstitutions
}: SubstitutionsTabProps) {
- const [leftCst, setLeftCst] = useState(undefined);
- const [rightCst, setRightCst] = useState(undefined);
- const [deleteRight, setDeleteRight] = useState(false);
- const [takeLeftTerm, setTakeLeftTerm] = useState(false);
-
- const toggleDelete = () => setDeleteRight(prev => !prev);
- const toggleTerm = () => setTakeLeftTerm(prev => !prev);
-
- function addSubstitution() {
- if (!leftCst || !rightCst) {
- return;
- }
- const newSubstitution: ISubstitution = {
- leftCst: leftCst,
- rightCst: rightCst,
- deleteRight: deleteRight,
- takeLeftTerm: takeLeftTerm
- };
- setSubstitutions([
- newSubstitution,
- ...substitutions.filter(
- item =>
- (!item.deleteRight && item.leftCst.id !== leftCst.id) ||
- (item.deleteRight && item.rightCst.id !== rightCst.id)
- )
- ]);
- }
-
return (
-
-
-
-
- ) : (
-
- )
- }
- />
-
- ) : (
-
- )
- }
- />
-
-
- selected.includes(cst.id))}
- value={leftCst}
- onSelectValue={setLeftCst}
- />
-
-
-
}
- disabled={!leftCst || !rightCst}
- onClick={addSubstitution}
- />
-
-
-
-
- ) : (
-
- )
- }
- />
-
- ) : (
-
- )
- }
- />
-
-
-
-
-
-
- Таблица отождествлений
-
- selected.includes(cst.id)}
/>
);
diff --git a/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/SubstitutionsTable.tsx b/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/SubstitutionsTable.tsx
deleted file mode 100644
index 28b0107a..00000000
--- a/rsconcept/frontend/src/dialogs/DlgInlineSynthesis/SubstitutionsTable.tsx
+++ /dev/null
@@ -1,130 +0,0 @@
-'use client';
-
-import { useCallback, useMemo } from 'react';
-import { BiChevronLeft, BiChevronRight, BiFirstPage, BiLastPage, BiX } from 'react-icons/bi';
-
-import ConstituentaBadge from '@/components/info/ConstituentaBadge';
-import DataTable, { createColumnHelper } from '@/components/ui/DataTable';
-import MiniButton from '@/components/ui/MiniButton';
-import { useConceptTheme } from '@/context/ThemeContext';
-import { ISubstitution } from '@/models/rsform';
-import { describeConstituenta } from '@/utils/labels';
-
-interface SubstitutionsTableProps {
- prefixID: string;
- rows?: number;
- items: ISubstitution[];
- setItems: React.Dispatch>;
-}
-
-function SubstitutionIcon({ item }: { item: ISubstitution }) {
- if (item.deleteRight) {
- if (item.takeLeftTerm) {
- return ;
- } else {
- return ;
- }
- } else {
- if (item.takeLeftTerm) {
- return ;
- } else {
- return ;
- }
- }
-}
-
-const columnHelper = createColumnHelper();
-
-function SubstitutionsTable({ items, rows, setItems, prefixID }: SubstitutionsTableProps) {
- const { colors } = useConceptTheme();
-
- const handleDeleteRow = useCallback(
- (row: number) => {
- setItems(prev => {
- const newItems: ISubstitution[] = [];
- prev.forEach((item, index) => {
- if (index !== row) {
- newItems.push(item);
- }
- });
- return newItems;
- });
- },
- [setItems]
- );
-
- const columns = useMemo(
- () => [
- columnHelper.accessor(item => describeConstituenta(item.leftCst), {
- id: 'left_text',
- header: 'Описание',
- size: 1000,
- cell: props => {props.getValue()}
- }),
- columnHelper.accessor(item => item.leftCst.alias, {
- id: 'left_alias',
- header: 'Имя',
- size: 65,
- cell: props => (
-
- )
- }),
- columnHelper.display({
- id: 'status',
- header: '',
- size: 40,
- cell: props =>
- }),
- columnHelper.accessor(item => item.rightCst.alias, {
- id: 'right_alias',
- header: 'Имя',
- size: 65,
- cell: props => (
-
- )
- }),
- columnHelper.accessor(item => describeConstituenta(item.rightCst), {
- id: 'right_text',
- header: 'Описание',
- size: 1000,
- cell: props => {props.getValue()}
- }),
- columnHelper.display({
- id: 'actions',
- size: 50,
- minSize: 50,
- maxSize: 50,
- cell: props => (
- }
- onClick={() => handleDeleteRow(props.row.index)}
- />
- )
- })
- ],
- [handleDeleteRow, colors, prefixID]
- );
-
- return (
-
- Список пуст
- Добавьте отождествление
-
- }
- />
- );
-}
-
-export default SubstitutionsTable;
diff --git a/rsconcept/frontend/src/pages/RSFormPage/EditorRSForm/FormRSForm.tsx b/rsconcept/frontend/src/pages/RSFormPage/EditorRSForm/FormRSForm.tsx
index 6ab3ea0c..6b605183 100644
--- a/rsconcept/frontend/src/pages/RSFormPage/EditorRSForm/FormRSForm.tsx
+++ b/rsconcept/frontend/src/pages/RSFormPage/EditorRSForm/FormRSForm.tsx
@@ -140,6 +140,7 @@ function FormRSForm({ id, isModified, setIsModified }: FormRSFormProps) {