MSP-3472 add copy config logic
This commit is contained in:
1 parent
a251c0eb26
commit
1dbb63f174
1 file changed
+63
-32
@@ -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<ActiveTableActionButtonsPropsType> =
|
||||
({
|
||||
@@ -27,10 +30,25 @@ const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
|
||||
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 (
|
||||
<div className="dropdown">
|
||||
<Tooltip key="1" title="Сравнение версий">
|
||||
@@ -43,6 +61,9 @@ const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
|
||||
<Button onClick={navigateToAllVersion} icon={<HistoryOutlined />} />
|
||||
</Tooltip>
|
||||
<CanEdit>
|
||||
<Tooltip key="4" title="Копировать конфиг">
|
||||
<Button icon={<CopyOutlined />} onClick={copyConfig} />
|
||||
</Tooltip>
|
||||
<Popconfirm
|
||||
title="Вы действительно хотите удалить выбранный конфиг?"
|
||||
onConfirm={() => handleDeleteConfig(record)}
|
||||
@@ -56,23 +77,33 @@ const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
|
||||
)
|
||||
}
|
||||
|
||||
const renderDropDownActive = (record: any) => {
|
||||
return (
|
||||
<div className="dropdown">
|
||||
<Tooltip key="1" title="Сравнение версий">
|
||||
<Button
|
||||
onClick={() => handleShowCompareModal(record)}
|
||||
icon={<SwapOutlined />}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip key="2" title="Просмотр истории">
|
||||
<Button onClick={navigateToAllVersion} icon={<HistoryOutlined />} />
|
||||
</Tooltip>
|
||||
<CanEdit>
|
||||
<Tooltip key="4" title="Копировать конфиг">
|
||||
<Button icon={<CopyOutlined />} onClick={copyConfig} />
|
||||
</Tooltip>
|
||||
</CanEdit>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
const renderAdditionalButtons = () => {
|
||||
if (isActive) {
|
||||
return (
|
||||
<>
|
||||
<Tooltip key="1" title="Сравнение версий">
|
||||
<Button
|
||||
onClick={() => handleShowCompareModal(record)}
|
||||
icon={<SwapOutlined />}
|
||||
/>
|
||||
</Tooltip>
|
||||
<Tooltip key="2" title="Просмотр истории">
|
||||
<Button
|
||||
onClick={navigateToAllVersion}
|
||||
icon={<HistoryOutlined />}
|
||||
/>
|
||||
</Tooltip>
|
||||
</>
|
||||
<Dropdown dropdownRender={() => renderDropDownActive(record)}>
|
||||
<Button icon={<EllipsisOutlined />} />
|
||||
</Dropdown>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -83,8 +114,8 @@ const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
|
||||
<Button onClick={() => handleMarkConfigActive(record)} icon={<AlertOutlined />} />
|
||||
</Tooltip>
|
||||
</CanEdit>
|
||||
<Dropdown dropdownRender={() => renderDropDown(record)}>
|
||||
<Button icon={<EllipsisOutlined />} />
|
||||
<Dropdown dropdownRender={() => renderDropDownNoActive(record)}>
|
||||
<Button icon={<EllipsisOutlined />} />
|
||||
</Dropdown>
|
||||
</>
|
||||
)
|
||||
@@ -92,20 +123,20 @@ const ActiveTableActionButtons: FC<ActiveTableActionButtonsPropsType> =
|
||||
return (
|
||||
<div className="active-configurations-table-actions-field">
|
||||
<Button.Group className="button_group">
|
||||
<Tooltip title="Просмотр">
|
||||
<Button
|
||||
onClick={() => handleShowConfig(record)}
|
||||
icon={<EyeOutlined />}
|
||||
/>
|
||||
</Tooltip>
|
||||
<CanEdit>
|
||||
<Tooltip title="Редактировать">
|
||||
<Button onClick={() => {
|
||||
navigate(`/${record.moduleId}/${routePaths.configEditor}/${record.id}`, { state: record })
|
||||
}} icon={<EditOutlined />} />
|
||||
<Tooltip title="Просмотр">
|
||||
<Button
|
||||
onClick={() => handleShowConfig(record)}
|
||||
icon={<EyeOutlined />}
|
||||
/>
|
||||
</Tooltip>
|
||||
</CanEdit>
|
||||
{renderAdditionalButtons()}
|
||||
<CanEdit>
|
||||
<Tooltip title="Редактировать">
|
||||
<Button onClick={() => {
|
||||
navigate(`/${record.moduleId}/${routePaths.configEditor}/${record.id}`, { state: record })
|
||||
}} icon={<EditOutlined />} />
|
||||
</Tooltip>
|
||||
</CanEdit>
|
||||
{renderAdditionalButtons()}
|
||||
</Button.Group>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user