From 386a3b5bf580beee4f99d1c77968691875979cd8 Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Tue, 22 Apr 2025 13:59:14 +0300 Subject: [PATCH] F: Implement edit block --- rsconcept/frontend/src/app/global-dialogs.tsx | 7 ++ .../frontend/src/features/oss/backend/api.ts | 2 +- .../features/oss/components/select-parent.tsx | 35 ++++++++ .../dlg-create-block/dlg-create-block.tsx | 2 +- .../dlg-create-block/tab-block-card.tsx | 7 +- .../dlg-create-block/tab-block-children.tsx | 2 +- .../dlg-create-operation.tsx | 2 +- .../tab-input-operation.tsx | 6 +- .../tab-synthesis-operation.tsx | 6 +- .../features/oss/dialogs/dlg-edit-block.tsx | 84 +++++++++++++++++++ .../dlg-edit-operation/tab-operation.tsx | 60 +++++++------ .../editor-oss-graph/graph/block-node.tsx | 4 +- .../oss-page/editor-oss-graph/oss-flow.tsx | 4 + .../editor-oss-graph/toolbar-oss-graph.tsx | 28 ++++--- rsconcept/frontend/src/stores/dialogs.ts | 4 + rsconcept/frontend/src/utils/labels.ts | 1 + 16 files changed, 196 insertions(+), 58 deletions(-) create mode 100644 rsconcept/frontend/src/features/oss/components/select-parent.tsx create mode 100644 rsconcept/frontend/src/features/oss/dialogs/dlg-edit-block.tsx diff --git a/rsconcept/frontend/src/app/global-dialogs.tsx b/rsconcept/frontend/src/app/global-dialogs.tsx index 9b62de62..f0c79d34 100644 --- a/rsconcept/frontend/src/app/global-dialogs.tsx +++ b/rsconcept/frontend/src/app/global-dialogs.tsx @@ -118,6 +118,11 @@ const DlgCreateBlock = React.lazy(() => default: module.DlgCreateBlock })) ); +const DlgEditBlock = React.lazy(() => + import('@/features/oss/dialogs/dlg-edit-block').then(module => ({ + default: module.DlgEditBlock + })) +); export const GlobalDialogs = () => { const active = useDialogsStore(state => state.active); @@ -134,6 +139,8 @@ export const GlobalDialogs = () => { return ; case DialogType.CREATE_BLOCK: return ; + case DialogType.EDIT_BLOCK: + return ; case DialogType.DELETE_CONSTITUENTA: return ; case DialogType.EDIT_EDITORS: diff --git a/rsconcept/frontend/src/features/oss/backend/api.ts b/rsconcept/frontend/src/features/oss/backend/api.ts index 2a160a52..02e09ed3 100644 --- a/rsconcept/frontend/src/features/oss/backend/api.ts +++ b/rsconcept/frontend/src/features/oss/backend/api.ts @@ -66,7 +66,7 @@ export const ossApi = { updateBlock: ({ itemID, data }: { itemID: number; data: IUpdateBlockDTO }) => axiosPatch({ schema: schemaOperationSchema, - endpoint: `/api/oss/${itemID}/update-operation`, + endpoint: `/api/oss/${itemID}/update-block`, request: { data: data, successMessage: infoMsg.changesSaved diff --git a/rsconcept/frontend/src/features/oss/components/select-parent.tsx b/rsconcept/frontend/src/features/oss/components/select-parent.tsx new file mode 100644 index 00000000..1abc9ff7 --- /dev/null +++ b/rsconcept/frontend/src/features/oss/components/select-parent.tsx @@ -0,0 +1,35 @@ +import clsx from 'clsx'; + +import { IconConceptBlock } from '@/components/icons'; +import { globalIDs } from '@/utils/constants'; + +import { type IBlock } from '../models/oss'; + +import { SelectBlock } from './select-block'; + +interface SelectParentProps { + id?: string; + value: IBlock | null; + onChange: (newValue: IBlock | null) => void; + + fullWidth?: boolean; + items?: IBlock[]; + placeholder?: string; + noBorder?: boolean; + popoverClassname?: string; +} + +export function SelectParent({ fullWidth, ...restProps }: SelectParentProps) { + return ( +
+ + +
+ ); +} diff --git a/rsconcept/frontend/src/features/oss/dialogs/dlg-create-block/dlg-create-block.tsx b/rsconcept/frontend/src/features/oss/dialogs/dlg-create-block/dlg-create-block.tsx index 48e48ec9..8e13b8a6 100644 --- a/rsconcept/frontend/src/features/oss/dialogs/dlg-create-block/dlg-create-block.tsx +++ b/rsconcept/frontend/src/features/oss/dialogs/dlg-create-block/dlg-create-block.tsx @@ -78,7 +78,7 @@ export function DlgCreateBlock() { submitText='Создать' canSubmit={isValid} onSubmit={event => void methods.handleSubmit(onSubmit)(event)} - className='w-160 px-6 h-128' + className='w-160 px-6 h-110' helpTopic={HelpTopic.CC_OSS} > ( - field.onChange(value ? value.id : null)} @@ -44,7 +43,7 @@ export function TabBlockCard() { id='operation_comment' // label='Описание' noResize - rows={3} + rows={5} {...register('item_data.description')} /> diff --git a/rsconcept/frontend/src/features/oss/dialogs/dlg-create-block/tab-block-children.tsx b/rsconcept/frontend/src/features/oss/dialogs/dlg-create-block/tab-block-children.tsx index 8dd413b3..e190dbb7 100644 --- a/rsconcept/frontend/src/features/oss/dialogs/dlg-create-block/tab-block-children.tsx +++ b/rsconcept/frontend/src/features/oss/dialogs/dlg-create-block/tab-block-children.tsx @@ -33,7 +33,7 @@ export function TabBlockChildren() { return (
); } diff --git a/rsconcept/frontend/src/features/oss/dialogs/dlg-create-operation/dlg-create-operation.tsx b/rsconcept/frontend/src/features/oss/dialogs/dlg-create-operation/dlg-create-operation.tsx index 985d7d08..03e58bcb 100644 --- a/rsconcept/frontend/src/features/oss/dialogs/dlg-create-operation/dlg-create-operation.tsx +++ b/rsconcept/frontend/src/features/oss/dialogs/dlg-create-operation/dlg-create-operation.tsx @@ -93,7 +93,7 @@ export function DlgCreateOperation() { submitText='Создать' canSubmit={isValid} onSubmit={event => void methods.handleSubmit(onSubmit)(event)} - className='w-160 px-6 h-128' + className='w-180 px-6 h-128' helpTopic={HelpTopic.CC_OSS} > @@ -74,7 +74,7 @@ export function TabInputOperation() { name='item_data.parent' control={control} render={({ field }) => ( - @@ -39,7 +39,7 @@ export function TabSynthesisOperation() { name='item_data.parent' control={control} render={({ field }) => ( - state.props as DlgEditBlockProps); + const { updateBlock } = useUpdateBlock(); + + const { + handleSubmit, + control, + register, + formState: { errors, isValid } + } = useForm({ + resolver: zodResolver(schemaUpdateBlock), + defaultValues: { + target: target.id, + item_data: { + title: target.title, + description: target.description, + parent: target.parent + }, + layout: layout + }, + mode: 'onChange' + }); + + function onSubmit(data: IUpdateBlockDTO) { + return updateBlock({ itemID: oss.id, data }); + } + + return ( + void handleSubmit(onSubmit)(event)} + className='w-160 px-6 h-fit cc-column' + > + + ( + block.id !== target.id)} + value={field.value ? oss.blockByID.get(field.value) ?? null : null} + placeholder='Блок содержания не выбран' + onChange={value => field.onChange(value ? value.id : null)} + /> + )} + /> + +