From afd3f5f7e41fe9b148890412b68813087e2cfb29 Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Mon, 29 Jul 2024 23:14:45 +0300 Subject: [PATCH] F: Prepare frontend for Synthesis execution --- .../apps/oss/serializers/data_access.py | 1 - rsconcept/frontend/src/backend/oss.ts | 7 ++++ rsconcept/frontend/src/components/Icons.tsx | 2 +- .../components/select/PickSubstitutions.tsx | 2 + rsconcept/frontend/src/context/OssContext.tsx | 27 +++++++++++- .../EditorOssGraph/NodeContextMenu.tsx | 6 +-- .../pages/OssPage/EditorOssGraph/OssFlow.tsx | 30 +++++++++++--- .../EditorOssGraph/ToolbarOssGraph.tsx | 41 +++++++++++++++---- .../src/pages/OssPage/OssEditContext.tsx | 28 ++++++++----- rsconcept/frontend/src/utils/labels.ts | 2 + 10 files changed, 116 insertions(+), 30 deletions(-) diff --git a/rsconcept/backend/apps/oss/serializers/data_access.py b/rsconcept/backend/apps/oss/serializers/data_access.py index cf5d5ac8..7da7973c 100644 --- a/rsconcept/backend/apps/oss/serializers/data_access.py +++ b/rsconcept/backend/apps/oss/serializers/data_access.py @@ -1,5 +1,4 @@ ''' Serializers for persistent data manipulation. ''' -import re from typing import cast from django.db.models import F diff --git a/rsconcept/frontend/src/backend/oss.ts b/rsconcept/frontend/src/backend/oss.ts index 05c8a359..8273bbc8 100644 --- a/rsconcept/frontend/src/backend/oss.ts +++ b/rsconcept/frontend/src/backend/oss.ts @@ -73,3 +73,10 @@ export function postExecuteOperation(oss: string, request: FrontExchange) { + AxiosPost({ + endpoint: `/api/oss/${oss}/execute-all`, + request: request + }); +} diff --git a/rsconcept/frontend/src/components/Icons.tsx b/rsconcept/frontend/src/components/Icons.tsx index 34d41ae1..b7da3088 100644 --- a/rsconcept/frontend/src/components/Icons.tsx +++ b/rsconcept/frontend/src/components/Icons.tsx @@ -108,7 +108,7 @@ export { LuNetwork as IconGenerateStructure } from 'react-icons/lu'; export { LuBookCopy as IconInlineSynthesis } from 'react-icons/lu'; export { LuWand2 as IconGenerateNames } from 'react-icons/lu'; export { GrConnect as IconConnect } from 'react-icons/gr'; -export { BsPlay as IconExecute } from 'react-icons/bs'; +export { BiPlayCircle as IconExecute } from 'react-icons/bi'; // ======== Graph UI ======= export { BiCollapse as IconGraphCollapse } from 'react-icons/bi'; diff --git a/rsconcept/frontend/src/components/select/PickSubstitutions.tsx b/rsconcept/frontend/src/components/select/PickSubstitutions.tsx index d8303aad..a0603001 100644 --- a/rsconcept/frontend/src/components/select/PickSubstitutions.tsx +++ b/rsconcept/frontend/src/components/select/PickSubstitutions.tsx @@ -223,6 +223,7 @@ function PickSubstitutions({
item.id !== rightArgument?.id)} value={leftArgument} onSelectValue={setLeftArgument} @@ -275,6 +276,7 @@ function PickSubstitutions({
item.id !== leftArgument?.id)} value={rightArgument} onSelectValue={setRightArgument} diff --git a/rsconcept/frontend/src/context/OssContext.tsx b/rsconcept/frontend/src/context/OssContext.tsx index f0c0c039..1511ce07 100644 --- a/rsconcept/frontend/src/context/OssContext.tsx +++ b/rsconcept/frontend/src/context/OssContext.tsx @@ -19,6 +19,7 @@ import { patchUpdateOperation, patchUpdatePositions, postCreateOperation, + postExecuteAll, postExecuteOperation } from '@/backend/oss'; import { type ErrorData } from '@/components/info/InfoError'; @@ -68,6 +69,7 @@ interface IOssContext { setInput: (data: IOperationSetInputData, callback?: () => void) => void; updateOperation: (data: IOperationUpdateData, callback?: () => void) => void; executeOperation: (data: ITargetOperation, callback?: () => void) => void; + executeAll: (data: IPositionsData, callback?: () => void) => void; } const OssContext = createContext(null); @@ -411,6 +413,28 @@ export const OssState = ({ itemID, children }: OssStateProps) => { [itemID, schema, library] ); + const executeAll = useCallback( + (data: IPositionsData, callback?: () => void) => { + if (!schema) { + return; + } + setProcessingError(undefined); + postExecuteAll(itemID, { + data: data, + showError: true, + setLoading: setProcessing, + onError: setProcessingError, + onSuccess: newData => { + library.setGlobalOSS(newData); + library.reloadItems(() => { + if (callback) callback(); + }); + } + }); + }, + [itemID, schema, library] + ); + return ( { createInput, setInput, updateOperation, - executeOperation + executeOperation, + executeAll }} > {children} diff --git a/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/NodeContextMenu.tsx b/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/NodeContextMenu.tsx index bf4a83b7..781d2d57 100644 --- a/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/NodeContextMenu.tsx +++ b/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/NodeContextMenu.tsx @@ -24,7 +24,7 @@ interface NodeContextMenuProps extends ContextMenuData { onCreateInput: (target: OperationID) => void; onEditSchema: (target: OperationID) => void; onEditOperation: (target: OperationID) => void; - onRunOperation: (target: OperationID) => void; + onExecuteOperation: (target: OperationID) => void; } function NodeContextMenu({ @@ -36,7 +36,7 @@ function NodeContextMenu({ onCreateInput, onEditSchema, onEditOperation, - onRunOperation + onExecuteOperation }: NodeContextMenuProps) { const controller = useOssEdit(); const [isOpen, setIsOpen] = useState(false); @@ -97,7 +97,7 @@ function NodeContextMenu({ const handleRunSynthesis = () => { handleHide(); - onRunOperation(operation.id); + onExecuteOperation(operation.id); }; return ( diff --git a/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/OssFlow.tsx b/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/OssFlow.tsx index 14972767..01435294 100644 --- a/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/OssFlow.tsx +++ b/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/OssFlow.tsx @@ -162,13 +162,21 @@ function OssFlow({ isModified, setIsModified }: OssFlowProps) { [controller, getPositions] ); - const handleRunOperation = useCallback( + const handleExecuteOperation = useCallback( (target: OperationID) => { - controller.runOperation(target, getPositions()); + controller.executeOperation(target, getPositions()); }, [controller, getPositions] ); + const handleExecuteSelected = useCallback(() => { + if (controller.selected.length === 1) { + handleExecuteOperation(controller.selected[0]); + } else { + controller.executeAll(getPositions()); + } + }, [controller, handleExecuteOperation, getPositions]); + const handleFitView = useCallback(() => { flow.fitView({ duration: PARAMETER.zoomDuration }); }, [flow]); @@ -285,8 +293,8 @@ function OssFlow({ isModified, setIsModified }: OssFlowProps) { onNodesChange={handleNodesChange} onEdgesChange={onEdgesChange} onNodeClick={handleNodeClick} - fitView proOptions={{ hideAttribution: true }} + fitView nodeTypes={OssNodeTypes} maxZoom={2} minZoom={0.75} @@ -299,7 +307,17 @@ function OssFlow({ isModified, setIsModified }: OssFlowProps) { {showGrid ? : null} ), - [nodes, edges, handleNodesChange, handleContextMenu, handleClickCanvas, onEdgesChange, OssNodeTypes, showGrid] + [ + nodes, + edges, + handleNodesChange, + handleContextMenu, + handleClickCanvas, + onEdgesChange, + handleNodeClick, + OssNodeTypes, + showGrid + ] ); return ( @@ -313,6 +331,8 @@ function OssFlow({ isModified, setIsModified }: OssFlowProps) { onFitView={handleFitView} onCreate={handleCreateOperation} onDelete={handleDeleteSelected} + onEdit={() => handleEditOperation(controller.selected[0])} + onExecute={handleExecuteSelected} onResetPositions={handleResetPositions} onSavePositions={handleSavePositions} onSaveImage={handleSaveImage} @@ -328,7 +348,7 @@ function OssFlow({ isModified, setIsModified }: OssFlowProps) { onCreateInput={handleCreateInput} onEditSchema={handleEditSchema} onEditOperation={handleEditOperation} - onRunOperation={handleRunOperation} + onExecuteOperation={handleExecuteOperation} {...menuProps} /> ) : null} diff --git a/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/ToolbarOssGraph.tsx b/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/ToolbarOssGraph.tsx index c025f0b7..50c718f7 100644 --- a/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/ToolbarOssGraph.tsx +++ b/rsconcept/frontend/src/pages/OssPage/EditorOssGraph/ToolbarOssGraph.tsx @@ -4,6 +4,8 @@ import { IconAnimation, IconAnimationOff, IconDestroy, + IconEdit2, + IconExecute, IconFitImage, IconGrid, IconImage, @@ -28,6 +30,8 @@ interface ToolbarOssGraphProps { edgeStraight: boolean; onCreate: () => void; onDelete: () => void; + onEdit: () => void; + onExecute: () => void; onFitView: () => void; onSaveImage: () => void; onSavePositions: () => void; @@ -44,6 +48,8 @@ function ToolbarOssGraph({ edgeStraight, onCreate, onDelete, + onEdit, + onExecute, onFitView, onSaveImage, onSavePositions, @@ -57,6 +63,12 @@ function ToolbarOssGraph({ return (
+ } + disabled={!isModified} + onClick={onResetPositions} + /> } title='Сбросить вид' @@ -116,19 +128,30 @@ function ToolbarOssGraph({ onClick={onSavePositions} /> } - disabled={!isModified} - onClick={onResetPositions} - /> - } disabled={controller.isProcessing} onClick={onCreate} /> + } + disabled={controller.isProcessing} + onClick={onExecute} + /> + } + disabled={controller.selected.length !== 1 || controller.isProcessing} + onClick={onEdit} + /> + } disabled={controller.selected.length !== 1 || controller.isProcessing} onClick={onDelete} @@ -138,5 +161,5 @@ function ToolbarOssGraph({
); } - +//IconExecute export default ToolbarOssGraph; diff --git a/rsconcept/frontend/src/pages/OssPage/OssEditContext.tsx b/rsconcept/frontend/src/pages/OssPage/OssEditContext.tsx index 93d2a9e6..b892b391 100644 --- a/rsconcept/frontend/src/pages/OssPage/OssEditContext.tsx +++ b/rsconcept/frontend/src/pages/OssPage/OssEditContext.tsx @@ -56,7 +56,8 @@ export interface IOssEditContext { createInput: (target: OperationID, positions: IOperationPosition[]) => void; promptEditInput: (target: OperationID, positions: IOperationPosition[]) => void; promptEditOperation: (target: OperationID, positions: IOperationPosition[]) => void; - runOperation: (target: OperationID, positions: IOperationPosition[]) => void; + executeOperation: (target: OperationID, positions: IOperationPosition[]) => void; + executeAll: (positions: IOperationPosition[]) => void; } const OssEditContext = createContext(null); @@ -279,15 +280,21 @@ export const OssEditState = ({ selected, setSelected, children }: OssEditStatePr [model, targetOperationID, positions] ); - const runOperation = useCallback( + const executeOperation = useCallback( (target: OperationID, positions: IOperationPosition[]) => { - model.executeOperation( - { - target: target, - positions: positions - }, - () => toast.success(information.changesSaved) - ); + const data = { + target: target, + positions: positions + }; + model.executeOperation(data, () => toast.success(information.operationExecuted)); + }, + [model] + ); + + const executeAll = useCallback( + (positions: IOperationPosition[]) => { + const data = { positions: positions }; + model.executeAll(data, () => toast.success(information.allOperationExecuted)); }, [model] ); @@ -320,7 +327,8 @@ export const OssEditState = ({ selected, setSelected, children }: OssEditStatePr createInput, promptEditInput, promptEditOperation, - runOperation + executeOperation, + executeAll }} > {model.schema ? ( diff --git a/rsconcept/frontend/src/utils/labels.ts b/rsconcept/frontend/src/utils/labels.ts index 385ca4b5..27839cc2 100644 --- a/rsconcept/frontend/src/utils/labels.ts +++ b/rsconcept/frontend/src/utils/labels.ts @@ -940,6 +940,8 @@ export const information = { versionDestroyed: 'Версия удалена', itemDestroyed: 'Схема удалена', operationDestroyed: 'Операция удалена', + operationExecuted: 'Операция выполнена', + allOperationExecuted: 'Все операции выполнены', constituentsDestroyed: (aliases: string) => `Конституенты удалены: ${aliases}` };