From 1dbb63f174ec4faf8ecaa463e976cd909b3ea949 Mon Sep 17 00:00:00 2001 From: mikheikinnv Date: Wed, 19 Jun 2024 12:42:58 +0300 Subject: [PATCH] MSP-3472 add copy config logic --- .../ActiveTableActionButtons/index.tsx | 95 ++++++++++++------- 1 file changed, 63 insertions(+), 32 deletions(-) diff --git a/src/widgets/ActiveTableActionButtons/index.tsx b/src/widgets/ActiveTableActionButtons/index.tsx index d797f76..b2fc0b3 100644 --- a/src/widgets/ActiveTableActionButtons/index.tsx +++ b/src/widgets/ActiveTableActionButtons/index.tsx @@ -5,9 +5,10 @@ import { EyeOutlined, HistoryOutlined, SwapOutlined, - EllipsisOutlined + EllipsisOutlined, + CopyOutlined } from '@ant-design/icons' -import { Button, Dropdown, Popconfirm, Tooltip } from 'antd' +import { Button, Dropdown, message, Popconfirm, Tooltip } from 'antd' import { FC } from 'react' import { useNavigate } from 'react-router-dom' @@ -16,6 +17,8 @@ import { ActiveTableActionButtonsPropsType } from './active-table-action-buttons import './active-table-action-buttons.scss' import CanEdit from '@components/CanEdit' import { routePaths } from '@routes/routePaths.ts' +import configServiceApi from '@services/configService.ts' +import { ConfigType } from '@pages/ModulesPage/module.type.ts' const ActiveTableActionButtons: FC = ({ @@ -27,10 +30,25 @@ const ActiveTableActionButtons: FC = handleMarkConfigActive }) => { const navigate = useNavigate() + const [createUpdateConfig] = configServiceApi.useCreateUpdateConfigMutation() const navigateToAllVersion = () => navigate(`${record.id}/all_versions`) - const renderDropDown = (record: any) => { + const copyConfig = () => { + const newConfig = { + name: `${record.name} (copy)`, + moduleId: record.moduleId, + id: '', + version: 0, + data: record.data + } as ConfigType + createUpdateConfig(newConfig) + .unwrap() + .then(() => message.success('Конфиг успешно скопирован')) + .catch(() => message.error('Не удалось скопировать конфиг')) + } + + const renderDropDownNoActive = (record: any) => { return (
@@ -43,6 +61,9 @@ const ActiveTableActionButtons: FC =
+ ) + } + const renderAdditionalButtons = () => { if (isActive) { return ( - <> - -