ConceptPortal-public/rsconcept/frontend/src/stores/dialogs.ts

148 lines
7.7 KiB
TypeScript
Raw Normal View History

import { create } from 'zustand';
2025-03-12 11:55:43 +03:00
import { type DlgChangeLocationProps } from '@/features/library/dialogs/dlg-change-location';
import { type DlgCloneLibraryItemProps } from '@/features/library/dialogs/dlg-clone-library-item';
import { type DlgCreateVersionProps } from '@/features/library/dialogs/dlg-create-version';
import { type DlgEditEditorsProps } from '@/features/library/dialogs/dlg-edit-editors/dlg-edit-editors';
import { type DlgEditVersionsProps } from '@/features/library/dialogs/dlg-edit-versions/dlg-edit-versions';
import { type DlgChangeInputSchemaProps } from '@/features/oss/dialogs/dlg-change-input-schema';
2025-04-21 20:37:11 +03:00
import { type DlgCreateBlockProps } from '@/features/oss/dialogs/dlg-create-block/dlg-create-block';
2025-03-12 11:55:43 +03:00
import { type DlgCreateOperationProps } from '@/features/oss/dialogs/dlg-create-operation/dlg-create-operation';
import { type DlgDeleteOperationProps } from '@/features/oss/dialogs/dlg-delete-operation';
2025-04-22 13:59:14 +03:00
import { type DlgEditBlockProps } from '@/features/oss/dialogs/dlg-edit-block';
2025-03-12 11:55:43 +03:00
import { type DlgEditOperationProps } from '@/features/oss/dialogs/dlg-edit-operation/dlg-edit-operation';
import { type DlgRelocateConstituentsProps } from '@/features/oss/dialogs/dlg-relocate-constituents';
import { type DlgShowTermGraphProps } from '@/features/oss/dialogs/dlg-show-term-graph/dlg-show-term-graph';
2025-03-12 11:55:43 +03:00
import { type DlgCreateCstProps } from '@/features/rsform/dialogs/dlg-create-cst/dlg-create-cst';
import { type DlgCstTemplateProps } from '@/features/rsform/dialogs/dlg-cst-template/dlg-cst-template';
import { type DlgDeleteCstProps } from '@/features/rsform/dialogs/dlg-delete-cst/dlg-delete-cst';
import { type DlgEditCstProps } from '@/features/rsform/dialogs/dlg-edit-cst/dlg-edit-cst';
2025-03-12 11:55:43 +03:00
import { type DlgEditReferenceProps } from '@/features/rsform/dialogs/dlg-edit-reference/dlg-edit-reference';
import { type DlgEditWordFormsProps } from '@/features/rsform/dialogs/dlg-edit-word-forms/dlg-edit-word-forms';
import { type DlgInlineSynthesisProps } from '@/features/rsform/dialogs/dlg-inline-synthesis/dlg-inline-synthesis';
import { type DlgRenameCstProps } from '@/features/rsform/dialogs/dlg-rename-cst';
import { type DlgShowASTProps } from '@/features/rsform/dialogs/dlg-show-ast/dlg-show-ast';
import { type DlgShowQRProps } from '@/features/rsform/dialogs/dlg-show-qr';
import { type DlgShowTypeGraphProps } from '@/features/rsform/dialogs/dlg-show-type-graph/dlg-show-type-graph';
import { type DlgSubstituteCstProps } from '@/features/rsform/dialogs/dlg-substitute-cst';
import { type DlgUploadRSFormProps } from '@/features/rsform/dialogs/dlg-upload-rsform';
2025-03-14 20:44:23 +03:00
/** Represents global dialog. */
export const DialogType = {
CONSTITUENTA_TEMPLATE: 1,
2025-04-21 20:37:11 +03:00
SUBSTITUTE_CONSTITUENTS: 2,
CREATE_VERSION: 3,
CREATE_CONSTITUENTA: 4,
DELETE_CONSTITUENTA: 5,
RENAME_CONSTITUENTA: 6,
CREATE_BLOCK: 7,
2025-04-22 13:59:14 +03:00
EDIT_BLOCK: 25,
2025-04-21 20:37:11 +03:00
CREATE_OPERATION: 8,
EDIT_OPERATION: 9,
DELETE_OPERATION: 10,
CHANGE_INPUT_SCHEMA: 11,
RELOCATE_CONSTITUENTS: 12,
2025-04-24 13:16:50 +03:00
OSS_SETTINGS: 26,
EDIT_CONSTITUENTA: 27,
2025-04-21 20:37:11 +03:00
CLONE_LIBRARY_ITEM: 13,
UPLOAD_RSFORM: 14,
EDIT_EDITORS: 15,
EDIT_VERSIONS: 16,
CHANGE_LOCATION: 17,
EDIT_REFERENCE: 18,
EDIT_WORD_FORMS: 19,
INLINE_SYNTHESIS: 20,
2025-03-14 20:44:23 +03:00
SHOW_QR_CODE: 21,
2025-04-21 20:37:11 +03:00
SHOW_AST: 22,
SHOW_TYPE_GRAPH: 23,
GRAPH_PARAMETERS: 24,
SHOW_TERM_GRAPH: 25
2025-03-14 20:44:23 +03:00
} as const;
export type DialogType = (typeof DialogType)[keyof typeof DialogType];
2025-03-13 23:21:14 +03:00
interface DialogProps {
2025-02-15 15:34:29 +03:00
onHide?: () => void;
}
interface DialogsStore {
active: DialogType | null;
props: unknown;
hideDialog: () => void;
showCstTemplate: (props: DlgCstTemplateProps) => void;
showCreateCst: (props: DlgCreateCstProps) => void;
2025-04-21 20:37:11 +03:00
showCreateBlock: (props: DlgCreateBlockProps) => void;
showCreateOperation: (props: DlgCreateOperationProps) => void;
showDeleteCst: (props: DlgDeleteCstProps) => void;
showEditEditors: (props: DlgEditEditorsProps) => void;
showEditOperation: (props: DlgEditOperationProps) => void;
2025-04-22 13:59:14 +03:00
showEditBlock: (props: DlgEditBlockProps) => void;
showEditReference: (props: DlgEditReferenceProps) => void;
showEditVersions: (props: DlgEditVersionsProps) => void;
showEditWordForms: (props: DlgEditWordFormsProps) => void;
showInlineSynthesis: (props: DlgInlineSynthesisProps) => void;
showShowAST: (props: DlgShowASTProps) => void;
showShowTypeGraph: (props: DlgShowTypeGraphProps) => void;
showShowTermGraph: (props: DlgShowTermGraphProps) => void;
showChangeInputSchema: (props: DlgChangeInputSchemaProps) => void;
showChangeLocation: (props: DlgChangeLocationProps) => void;
showCloneLibraryItem: (props: DlgCloneLibraryItemProps) => void;
showCreateVersion: (props: DlgCreateVersionProps) => void;
showDeleteOperation: (props: DlgDeleteOperationProps) => void;
2025-02-08 17:10:38 +03:00
showGraphParams: () => void;
2025-04-24 13:16:50 +03:00
showOssOptions: () => void;
showRelocateConstituents: (props: DlgRelocateConstituentsProps) => void;
showRenameCst: (props: DlgRenameCstProps) => void;
showQR: (props: DlgShowQRProps) => void;
showSubstituteCst: (props: DlgSubstituteCstProps) => void;
showUploadRSForm: (props: DlgUploadRSFormProps) => void;
showEditCst: (props: DlgEditCstProps) => void;
}
export const useDialogsStore = create<DialogsStore>()(set => ({
active: null,
props: null,
2025-02-15 15:34:29 +03:00
hideDialog: () => {
set(state => {
2025-03-13 23:21:14 +03:00
(state.props as DialogProps | null)?.onHide?.();
return { active: null, props: null };
2025-02-15 15:34:29 +03:00
});
},
showCstTemplate: props => set({ active: DialogType.CONSTITUENTA_TEMPLATE, props: props }),
showCreateCst: props => set({ active: DialogType.CREATE_CONSTITUENTA, props: props }),
showCreateOperation: props => set({ active: DialogType.CREATE_OPERATION, props: props }),
2025-04-21 20:37:11 +03:00
showCreateBlock: props => set({ active: DialogType.CREATE_BLOCK, props: props }),
showDeleteCst: props => set({ active: DialogType.DELETE_CONSTITUENTA, props: props }),
showEditEditors: props => set({ active: DialogType.EDIT_EDITORS, props: props }),
showEditOperation: props => set({ active: DialogType.EDIT_OPERATION, props: props }),
2025-04-22 13:59:14 +03:00
showEditBlock: props => set({ active: DialogType.EDIT_BLOCK, props: props }),
showEditReference: props => set({ active: DialogType.EDIT_REFERENCE, props: props }),
showEditVersions: props => set({ active: DialogType.EDIT_VERSIONS, props: props }),
showEditWordForms: props => set({ active: DialogType.EDIT_WORD_FORMS, props: props }),
showInlineSynthesis: props => set({ active: DialogType.INLINE_SYNTHESIS, props: props }),
showShowAST: props => set({ active: DialogType.SHOW_AST, props: props }),
showShowTypeGraph: props => set({ active: DialogType.SHOW_TYPE_GRAPH, props: props }),
showShowTermGraph: props => set({ active: DialogType.SHOW_TERM_GRAPH, props: props }),
showChangeInputSchema: props => set({ active: DialogType.CHANGE_INPUT_SCHEMA, props: props }),
showChangeLocation: props => set({ active: DialogType.CHANGE_LOCATION, props: props }),
showCloneLibraryItem: props => set({ active: DialogType.CLONE_LIBRARY_ITEM, props: props }),
showCreateVersion: props => set({ active: DialogType.CREATE_VERSION, props: props }),
showDeleteOperation: props => set({ active: DialogType.DELETE_OPERATION, props: props }),
showGraphParams: () => set({ active: DialogType.GRAPH_PARAMETERS, props: null }),
2025-04-24 13:16:50 +03:00
showOssOptions: () => set({ active: DialogType.OSS_SETTINGS, props: null }),
showRelocateConstituents: props => set({ active: DialogType.RELOCATE_CONSTITUENTS, props: props }),
showRenameCst: props => set({ active: DialogType.RENAME_CONSTITUENTA, props: props }),
showQR: props => set({ active: DialogType.SHOW_QR_CODE, props: props }),
showSubstituteCst: props => set({ active: DialogType.SUBSTITUTE_CONSTITUENTS, props: props }),
showUploadRSForm: props => set({ active: DialogType.UPLOAD_RSFORM, props: props }),
showEditCst: props => set({ active: DialogType.EDIT_CONSTITUENTA, props: props })
}));