From 33ad3c6b9527bd99512085df841dcbf11a62ce17 Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Thu, 16 Jan 2025 16:31:32 +0300 Subject: [PATCH] R: Refactor dialogs using zustand store --- .../frontend/src/app/ApplicationLayout.tsx | 2 + rsconcept/frontend/src/app/GlobalDialogs.tsx | 83 +++++ .../src/components/RefsInput/RefsInput.tsx | 46 ++- .../frontend/src/components/ui/Modal.tsx | 14 +- .../src/dialogs/DlgChangeInputSchema.tsx | 15 +- .../src/dialogs/DlgChangeLocation.tsx | 9 +- .../src/dialogs/DlgCloneLibraryItem.tsx | 12 +- .../dialogs/DlgConstituentaTemplate/index.tsx | 1 - .../src/dialogs/DlgCreateCst/DlgCreateCst.tsx | 9 +- .../DlgCreateOperation/DlgCreateOperation.tsx | 8 +- .../frontend/src/dialogs/DlgCreateVersion.tsx | 9 +- .../DlgCstTemplate.tsx} | 11 +- .../TabArguments.tsx | 0 .../TabTemplate.tsx | 0 .../src/dialogs/DlgCstTemplate/index.tsx | 1 + .../src/dialogs/DlgDeleteCst/DlgDeleteCst.tsx | 12 +- .../src/dialogs/DlgDeleteOperation.tsx | 15 +- .../dialogs/DlgEditEditors/DlgEditEditors.tsx | 8 +- .../DlgEditOperation/DlgEditOperation.tsx | 8 +- .../DlgEditReference/DlgEditReference.tsx | 8 +- .../DlgEditVersions/DlgEditVersions.tsx | 17 +- .../DlgEditWordForms/DlgEditWordForms.tsx | 8 +- .../frontend/src/dialogs/DlgGraphParams.tsx | 9 +- .../DlgInlineSynthesis/DlgInlineSynthesis.tsx | 9 +- .../src/dialogs/DlgRelocateConstituents.tsx | 9 +- .../frontend/src/dialogs/DlgRenameCst.tsx | 14 +- .../src/dialogs/DlgShowAST/DlgShowAST.tsx | 9 +- rsconcept/frontend/src/dialogs/DlgShowQR.tsx | 14 +- .../DlgShowTypeGraph/DlgShowTypeGraph.tsx | 12 +- .../frontend/src/dialogs/DlgSubstituteCst.tsx | 9 +- .../frontend/src/dialogs/DlgUploadRSForm.tsx | 11 +- .../frontend/src/models/miscellaneous.ts | 29 ++ .../src/pages/LibraryPage/LibraryPage.tsx | 41 +-- .../src/pages/OssPage/OssEditContext.tsx | 252 +++++++--------- .../EditorConstituenta/FormConstituenta.tsx | 10 +- .../EditorRSExpression/EditorRSExpression.tsx | 20 +- .../RSFormPage/EditorTermGraph/TGFlow.tsx | 10 +- .../src/pages/RSFormPage/RSEditContext.tsx | 285 +++++++----------- rsconcept/frontend/src/stores/dialogs.ts | 86 ++++++ 39 files changed, 588 insertions(+), 537 deletions(-) create mode 100644 rsconcept/frontend/src/app/GlobalDialogs.tsx delete mode 100644 rsconcept/frontend/src/dialogs/DlgConstituentaTemplate/index.tsx rename rsconcept/frontend/src/dialogs/{DlgConstituentaTemplate/DlgConstituentaTemplate.tsx => DlgCstTemplate/DlgCstTemplate.tsx} (94%) rename rsconcept/frontend/src/dialogs/{DlgConstituentaTemplate => DlgCstTemplate}/TabArguments.tsx (100%) rename rsconcept/frontend/src/dialogs/{DlgConstituentaTemplate => DlgCstTemplate}/TabTemplate.tsx (100%) create mode 100644 rsconcept/frontend/src/dialogs/DlgCstTemplate/index.tsx create mode 100644 rsconcept/frontend/src/stores/dialogs.ts diff --git a/rsconcept/frontend/src/app/ApplicationLayout.tsx b/rsconcept/frontend/src/app/ApplicationLayout.tsx index 4b92bba5..29f67481 100644 --- a/rsconcept/frontend/src/app/ApplicationLayout.tsx +++ b/rsconcept/frontend/src/app/ApplicationLayout.tsx @@ -9,6 +9,7 @@ import { NavigationState } from '@/context/NavigationContext'; import { useAppLayoutStore, useMainHeight, useViewportHeight } from '@/stores/appLayout'; import { globals } from '@/utils/constants'; +import { GlobalDialogs } from './GlobalDialogs'; import { GlobalTooltips } from './GlobalTooltips'; function ApplicationLayout() { @@ -29,6 +30,7 @@ function ApplicationLayout() { pauseOnFocusLoss={false} /> + diff --git a/rsconcept/frontend/src/app/GlobalDialogs.tsx b/rsconcept/frontend/src/app/GlobalDialogs.tsx new file mode 100644 index 00000000..a20ce7db --- /dev/null +++ b/rsconcept/frontend/src/app/GlobalDialogs.tsx @@ -0,0 +1,83 @@ +'use client'; + +import DlgChangeInputSchema from '@/dialogs/DlgChangeInputSchema'; +import DlgChangeLocation from '@/dialogs/DlgChangeLocation'; +import DlgCloneLibraryItem from '@/dialogs/DlgCloneLibraryItem'; +import DlgCreateCst from '@/dialogs/DlgCreateCst'; +import DlgCreateOperation from '@/dialogs/DlgCreateOperation'; +import DlgCreateVersion from '@/dialogs/DlgCreateVersion'; +import DlgCstTemplate from '@/dialogs/DlgCstTemplate'; +import DlgDeleteCst from '@/dialogs/DlgDeleteCst'; +import DlgDeleteOperation from '@/dialogs/DlgDeleteOperation'; +import DlgEditEditors from '@/dialogs/DlgEditEditors'; +import DlgEditOperation from '@/dialogs/DlgEditOperation'; +import DlgEditReference from '@/dialogs/DlgEditReference'; +import DlgEditVersions from '@/dialogs/DlgEditVersions'; +import DlgEditWordForms from '@/dialogs/DlgEditWordForms'; +import DlgGraphParams from '@/dialogs/DlgGraphParams'; +import DlgInlineSynthesis from '@/dialogs/DlgInlineSynthesis'; +import DlgRelocateConstituents from '@/dialogs/DlgRelocateConstituents'; +import DlgRenameCst from '@/dialogs/DlgRenameCst'; +import DlgShowAST from '@/dialogs/DlgShowAST'; +import DlgShowQR from '@/dialogs/DlgShowQR'; +import DlgShowTypeGraph from '@/dialogs/DlgShowTypeGraph'; +import DlgSubstituteCst from '@/dialogs/DlgSubstituteCst'; +import DlgUploadRSForm from '@/dialogs/DlgUploadRSForm'; +import { DialogType } from '@/models/miscellaneous'; +import { useDialogsStore } from '@/stores/dialogs'; + +export const GlobalDialogs = () => { + const active = useDialogsStore(state => state.active); + + if (active === undefined) { + return null; + } + switch (active) { + case DialogType.CONSTITUENTA_TEMPLATE: + return ; + case DialogType.CREATE_CONSTITUENTA: + return ; + case DialogType.CREATE_OPERATION: + return ; + case DialogType.DELETE_CONSTITUENTA: + return ; + case DialogType.EDIT_EDITORS: + return ; + case DialogType.EDIT_OPERATION: + return ; + case DialogType.EDIT_REFERENCE: + return ; + case DialogType.EDIT_VERSIONS: + return ; + case DialogType.EDIT_WORD_FORMS: + return ; + case DialogType.INLINE_SYNTHESIS: + return ; + case DialogType.SHOW_AST: + return ; + case DialogType.SHOW_TYPE_GRAPH: + return ; + case DialogType.CHANGE_INPUT_SCHEMA: + return ; + case DialogType.CHANGE_LOCATION: + return ; + case DialogType.CLONE_LIBRARY_ITEM: + return ; + case DialogType.CREATE_VERSION: + return ; + case DialogType.DELETE_OPERATION: + return ; + case DialogType.GRAPH_PARAMETERS: + return ; + case DialogType.RELOCATE_CONSTITUENTS: + return ; + case DialogType.RENAME_CONSTITUENTA: + return ; + case DialogType.SHOW_QR_CODE: + return ; + case DialogType.SUBSTITUTE_CONSTITUENTS: + return ; + case DialogType.UPLOAD_RSFORM: + return ; + } +}; diff --git a/rsconcept/frontend/src/components/RefsInput/RefsInput.tsx b/rsconcept/frontend/src/components/RefsInput/RefsInput.tsx index a1687fab..4c2e1ed2 100644 --- a/rsconcept/frontend/src/components/RefsInput/RefsInput.tsx +++ b/rsconcept/frontend/src/components/RefsInput/RefsInput.tsx @@ -9,13 +9,13 @@ import { EditorView } from 'codemirror'; import { forwardRef, useRef, useState } from 'react'; import Label from '@/components/ui/Label'; -import DlgEditReference from '@/dialogs/DlgEditReference'; import { ReferenceType } from '@/models/language'; +import { DialogType } from '@/models/miscellaneous'; import { ConstituentaID, IRSForm } from '@/models/rsform'; +import { useDialogsStore } from '@/stores/dialogs'; import { usePreferencesStore } from '@/stores/preferences'; import { APP_COLORS } from '@/styling/color'; import { CodeMirrorWrapper } from '@/utils/codemirror'; -import { PARAMETER } from '@/utils/constants'; import { refsNavigation } from './clickNavigation'; import { NaturalLanguage, ReferenceTokens } from './parse'; @@ -96,7 +96,10 @@ const RefsInput = forwardRef( const [isFocused, setIsFocused] = useState(false); - const [showEditor, setShowEditor] = useState(false); + const showEditReference = useDialogsStore(state => state.showEditReference); + const activeDialog = useDialogsStore(state => state.active); + const isActive = activeDialog === DialogType.EDIT_REFERENCE; + const [currentType, setCurrentType] = useState(ReferenceType.ENTITY); const [refText, setRefText] = useState(''); const [hintText, setHintText] = useState(''); @@ -146,7 +149,7 @@ const RefsInput = forwardRef( } function handleInput(event: React.KeyboardEvent) { - if (!thisRef.current?.view) { + if (!thisRef.current?.view || !schema) { event.preventDefault(); event.stopPropagation(); return; @@ -174,7 +177,17 @@ const RefsInput = forwardRef( setMainRefs(mainNodes.map(node => wrap.getText(node.from, node.to))); setBasePosition(mainNodes.filter(node => node.to <= selection.from).length); - setShowEditor(true); + showEditReference({ + schema: schema, + initial: { + type: currentType, + refRaw: refText, + text: hintText, + basePosition: basePosition, + mainRefs: mainRefs + }, + onSave: handleInputReference + }); } } @@ -187,27 +200,8 @@ const RefsInput = forwardRef( wrap.replaceWith(referenceText); } - function hideEditReference() { - setShowEditor(false); - setTimeout(() => thisRef.current?.view?.focus(), PARAMETER.refreshTimeout); - } - return (
- {showEditor && schema ? ( - - ) : null}