From 260d6e35e74417772facf9b868a0d2ccd4134c62 Mon Sep 17 00:00:00 2001 From: Zabilsya Date: Tue, 4 Mar 2025 17:58:00 +0600 Subject: [PATCH] [DOP-24048] add transfer canvas on detail page --- src/entities/transformation/constants.ts | 9 +++++ src/entities/transformation/hooks/index.ts | 1 + .../hooks/useShowButtons/index.ts | 5 +++ src/entities/transformation/index.ts | 2 ++ src/entities/transformation/types.ts | 4 +++ .../TransformationForm/TransformationForm.tsx | 7 ++-- .../{index.tsx => MutateTransferForm.tsx} | 0 .../TransferConnectionsCanvas.tsx | 34 +++++++------------ .../TransferConnectionsCanvas/types.ts | 4 ++- .../MutateTransferForm/components/index.ts | 1 + .../transfer/MutateTransferForm/index.ts | 2 ++ .../transfer/TransferDetailInfo/index.tsx | 6 ++-- src/shared/ui/Canvas/index.tsx | 29 ++++++++++++++-- src/shared/ui/Canvas/types.ts | 6 +++- src/widgets/transfer/TransferDetail/index.tsx | 27 +++++++++++++-- .../TransferDetail/styles.module.less | 28 +++++++++++++++ 16 files changed, 133 insertions(+), 32 deletions(-) create mode 100644 src/entities/transformation/constants.ts create mode 100644 src/entities/transformation/hooks/index.ts create mode 100644 src/entities/transformation/hooks/useShowButtons/index.ts rename src/features/transfer/MutateTransferForm/{index.tsx => MutateTransferForm.tsx} (100%) create mode 100644 src/features/transfer/MutateTransferForm/index.ts diff --git a/src/entities/transformation/constants.ts b/src/entities/transformation/constants.ts new file mode 100644 index 00000000..95e05290 --- /dev/null +++ b/src/entities/transformation/constants.ts @@ -0,0 +1,9 @@ +import { createContext } from 'react'; + +import { ShowButtonsContextProps } from './types'; + +const SHOW_BUTTONS_CONTEXT_INITIAL_VALUE: ShowButtonsContextProps = { + isDisplayed: true, +}; + +export const ShowButtonsContext = createContext(SHOW_BUTTONS_CONTEXT_INITIAL_VALUE); diff --git a/src/entities/transformation/hooks/index.ts b/src/entities/transformation/hooks/index.ts new file mode 100644 index 00000000..9073a9cb --- /dev/null +++ b/src/entities/transformation/hooks/index.ts @@ -0,0 +1 @@ +export * from './useShowButtons'; diff --git a/src/entities/transformation/hooks/useShowButtons/index.ts b/src/entities/transformation/hooks/useShowButtons/index.ts new file mode 100644 index 00000000..6332165b --- /dev/null +++ b/src/entities/transformation/hooks/useShowButtons/index.ts @@ -0,0 +1,5 @@ +import { useContext } from 'react'; + +import { ShowButtonsContext } from '../../constants'; + +export const useShowButtons = () => useContext(ShowButtonsContext); diff --git a/src/entities/transformation/index.ts b/src/entities/transformation/index.ts index e12841b6..c12d6394 100644 --- a/src/entities/transformation/index.ts +++ b/src/entities/transformation/index.ts @@ -1,3 +1,5 @@ export * from './types'; export * from './utils'; export * from './ui'; +export * from './constants'; +export * from './hooks'; diff --git a/src/entities/transformation/types.ts b/src/entities/transformation/types.ts index 56088da6..ae4d5335 100644 --- a/src/entities/transformation/types.ts +++ b/src/entities/transformation/types.ts @@ -117,3 +117,7 @@ export interface TransformationsForm { export type TransformationsFormNestedType = Required[T][number]['type']; + +export interface ShowButtonsContextProps { + isDisplayed: boolean; +} diff --git a/src/entities/transformation/ui/TransformationForm/TransformationForm.tsx b/src/entities/transformation/ui/TransformationForm/TransformationForm.tsx index 9f0b8f07..5b011026 100644 --- a/src/entities/transformation/ui/TransformationForm/TransformationForm.tsx +++ b/src/entities/transformation/ui/TransformationForm/TransformationForm.tsx @@ -1,6 +1,7 @@ import { Button, Form } from 'antd'; import React, { memo, useLayoutEffect } from 'react'; +import { useShowButtons } from '../../hooks'; import { Transformations, TransformationType } from '../../types'; import { TransformationFormItem } from './components'; @@ -10,6 +11,8 @@ const TransformationFormComponent = ({ transformationType, ...props }: TransformationFormProps) => { + const { isDisplayed } = useShowButtons(); + const formInstance = Form.useFormInstance(); const filtersValues: Transformations[number]['filters'] | undefined = formInstance.getFieldValue([ 'transformations', @@ -34,11 +37,11 @@ const TransformationFormComponent = ({ {...field} {...props} transformationType={transformationType} - onRemove={field.name ? remove : undefined} + onRemove={field.name && isDisplayed ? remove : undefined} key={field.key} /> ))} - diff --git a/src/features/transfer/MutateTransferForm/index.tsx b/src/features/transfer/MutateTransferForm/MutateTransferForm.tsx similarity index 100% rename from src/features/transfer/MutateTransferForm/index.tsx rename to src/features/transfer/MutateTransferForm/MutateTransferForm.tsx diff --git a/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/TransferConnectionsCanvas.tsx b/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/TransferConnectionsCanvas.tsx index 8c719440..ece488f4 100644 --- a/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/TransferConnectionsCanvas.tsx +++ b/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/TransferConnectionsCanvas.tsx @@ -1,8 +1,8 @@ import React, { useMemo } from 'react'; import { Canvas } from '@shared/ui'; -import { ReactFlowProvider, useEdgesState, useNodesState } from '@xyflow/react'; +import { ReactFlowProvider } from '@xyflow/react'; import { Form } from 'antd'; -import { TransformationsForm, TransformationType } from '@entities/transformation'; +import { ShowButtonsContext, TransformationsForm, TransformationType } from '@entities/transformation'; import { TransformButtons } from '../TransformButtons'; @@ -13,7 +13,7 @@ import classes from './styles.module.less'; import '@xyflow/react/dist/style.css'; -export const TransferConnectionsCanvas = ({ groupId }: TransferCanvasProps) => { +export const TransferConnectionsCanvas = ({ groupId, isDisplayedButtons = true }: TransferCanvasProps) => { const formInstance = Form.useFormInstance(); const initialTransformations = useMemo(() => { @@ -33,25 +33,15 @@ export const TransferConnectionsCanvas = ({ groupId }: TransferCanvasProps) => { return getInitialEdges(initialNodes); }, [initialNodes]); - // setNodes and setEdges will not be used - // eslint-disable-next-line - const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes); - // eslint-disable-next-line - const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges); - return ( - -
- - - -
-
+ + +
+ + {isDisplayedButtons && } + +
+
+
); }; diff --git a/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/types.ts b/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/types.ts index 1869f5df..0e7a6d2d 100644 --- a/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/types.ts +++ b/src/features/transfer/MutateTransferForm/components/TransferConnectionsCanvas/types.ts @@ -6,7 +6,9 @@ import { TargetParamsNodeData } from '../TargetParamsNode'; import { GetInitialNodesProps } from './utils'; -export interface TransferCanvasProps extends Pick {} +export interface TransferCanvasProps extends Pick { + isDisplayedButtons?: boolean; +} export type TransferCanvasNodeData = | SourceParamsNodeData diff --git a/src/features/transfer/MutateTransferForm/components/index.ts b/src/features/transfer/MutateTransferForm/components/index.ts index 007c7fb5..12227410 100644 --- a/src/features/transfer/MutateTransferForm/components/index.ts +++ b/src/features/transfer/MutateTransferForm/components/index.ts @@ -3,3 +3,4 @@ export * from './TargetParams'; export * from './TransferSchedule'; export * from './TransferConnections'; export * from './StrategyParams'; +export * from './TransferConnectionsCanvas'; diff --git a/src/features/transfer/MutateTransferForm/index.ts b/src/features/transfer/MutateTransferForm/index.ts new file mode 100644 index 00000000..1e5ae52b --- /dev/null +++ b/src/features/transfer/MutateTransferForm/index.ts @@ -0,0 +1,2 @@ +export * from './MutateTransferForm'; +export { TransferConnectionsCanvas } from './components'; diff --git a/src/features/transfer/TransferDetailInfo/index.tsx b/src/features/transfer/TransferDetailInfo/index.tsx index ffe2ea35..48da446b 100644 --- a/src/features/transfer/TransferDetailInfo/index.tsx +++ b/src/features/transfer/TransferDetailInfo/index.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PropsWithChildren } from 'react'; import { Descriptions } from 'antd'; import { Link } from 'react-router-dom'; import { CronService } from '@shared/services'; @@ -13,8 +13,9 @@ export const TransferDetailInfo = ({ connectionSource, connectionTarget, queue, + children, ...props -}: TransferDetailInfoProps) => { +}: PropsWithChildren) => { return (
@@ -54,6 +55,7 @@ export const TransferDetailInfo = ({ + {children}
); }; diff --git a/src/shared/ui/Canvas/index.tsx b/src/shared/ui/Canvas/index.tsx index db6caac2..707bbc0f 100644 --- a/src/shared/ui/Canvas/index.tsx +++ b/src/shared/ui/Canvas/index.tsx @@ -1,12 +1,34 @@ -import { Background, BackgroundVariant, Controls, Edge, MiniMap, Node, ReactFlow, useReactFlow } from '@xyflow/react'; +import { + Background, + BackgroundVariant, + Controls, + Edge, + MiniMap, + Node, + ReactFlow, + useEdgesState, + useNodesState, + useReactFlow, +} from '@xyflow/react'; import React, { useEffect } from 'react'; import classes from './styles.module.less'; import { CanvasProps } from './types'; -export const Canvas = ({ children, nodes, ...props }: CanvasProps) => { +export const Canvas = ({ + initialNodes, + initialEdges, + children, + ...props +}: CanvasProps) => { const { fitView } = useReactFlow(); + // setNodes and setEdges will not be used + // eslint-disable-next-line + const [nodes, setNodes, onNodesChange] = useNodesState(initialNodes); + // eslint-disable-next-line + const [edges, setEdges, onEdgesChange] = useEdgesState(initialEdges); + /** Set appropriate zoom of canvas when nodes count has changed */ useEffect(() => { fitView({ duration: 200, padding: 0.4 }); @@ -20,6 +42,9 @@ export const Canvas = ({ children, nodes, ...pro elementsSelectable nodesConnectable={false} nodes={nodes} + edges={edges} + onNodesChange={onNodesChange} + onEdgesChange={onEdgesChange} nodesDraggable panOnScroll={false} panOnDrag diff --git a/src/shared/ui/Canvas/types.ts b/src/shared/ui/Canvas/types.ts index 43fc77dd..ced26a2d 100644 --- a/src/shared/ui/Canvas/types.ts +++ b/src/shared/ui/Canvas/types.ts @@ -1,3 +1,7 @@ import { Edge, Node, ReactFlowProps } from '@xyflow/react'; -export interface CanvasProps extends ReactFlowProps {} +export interface CanvasProps + extends Omit, 'nodes' | 'edges' | 'onNodesChange' | 'onEdgesChange'> { + initialNodes: N[]; + initialEdges: E[]; +} diff --git a/src/widgets/transfer/TransferDetail/index.tsx b/src/widgets/transfer/TransferDetail/index.tsx index 1c94ea81..e13d18e6 100644 --- a/src/widgets/transfer/TransferDetail/index.tsx +++ b/src/widgets/transfer/TransferDetail/index.tsx @@ -1,12 +1,17 @@ import React from 'react'; import { AccessWrapper, PageContentWrapper } from '@shared/ui'; -import { TransferDetailInfo } from '@features/transfer'; +import { TransferDetailInfo, TransferConnectionsCanvas } from '@features/transfer'; import { UserRole } from '@shared/types'; +import { Form } from 'antd'; +import { prepareTransformationForm } from '@entities/transformation'; +import { Typography } from 'antd'; import { TransferDetailProps } from './types'; import { DeleteTransferButton, UpdateTransferButton } from './components'; import classes from './styles.module.less'; +const { Text } = Typography; + export const TransferDetail = ({ transfer, group, connectionSource, connectionTarget, queue }: TransferDetailProps) => { return ( @@ -24,7 +29,25 @@ export const TransferDetail = ({ transfer, group, connectionSource, connectionTa } - /> + > +
+ + Transfer advanced info + +
+ + +
+
); }; diff --git a/src/widgets/transfer/TransferDetail/styles.module.less b/src/widgets/transfer/TransferDetail/styles.module.less index f0c745a4..8717d8db 100644 --- a/src/widgets/transfer/TransferDetail/styles.module.less +++ b/src/widgets/transfer/TransferDetail/styles.module.less @@ -3,3 +3,31 @@ align-items: center; gap: 16px; } + +.advanced { + display: flex; + flex-direction: column; + margin-top: 8px; + + .subtitle { + font-size: 16px; + } + + .form { + :global(.ant-select-selector) { + color: @text-color !important; + } + + :global(.ant-input) { + color: @text-color !important; + } + + :global(.ant-input-number-input) { + color: @text-color !important; + } + + :global(.ant-radio + span) { + color: @text-color !important; + } + } +}