MSP-3203 create CompareVersionModal
This commit is contained in:
1 parent
e2a788578b
commit
3d51274487
3 files changed
+160
No files matched your search
@@ -0,0 +1,37 @@
|
|||||||
|
@import "src/constants/style/styleConst";
|
||||||
|
|
||||||
|
.compare-version-modal {
|
||||||
|
.modal__wrap {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
justify-content: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
.modal__content {
|
||||||
|
overflow: initial;
|
||||||
|
}
|
||||||
|
|
||||||
|
&__header {
|
||||||
|
margin-top: $basic-margin;
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
margin-bottom: $basic-margin;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
&__content {
|
||||||
|
.cm-merge-theme {
|
||||||
|
overflow-y: scroll;
|
||||||
|
height: calc(90vh - 150px);
|
||||||
|
}
|
||||||
|
|
||||||
|
&__table {
|
||||||
|
overflow-y: auto;
|
||||||
|
height: calc(90vh - 50px);
|
||||||
|
|
||||||
|
&__row {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import { ModalPropsType } from '@widgets/Modal/modal.type.ts'
|
||||||
|
|
||||||
|
export interface CompareVersionModalPropsType
|
||||||
|
extends Omit<ModalPropsType, 'title' | 'children'> {
|
||||||
|
config: Record<string, any>
|
||||||
|
currentConfigId: string
|
||||||
|
}
|
||||||
@@ -0,0 +1,116 @@
|
|||||||
|
import { EditorState, EditorView } from '@uiw/react-codemirror'
|
||||||
|
import { Button, Spin, Table } from 'antd'
|
||||||
|
import { ColumnsType } from 'antd/es/table'
|
||||||
|
import { FC, useState } from 'react'
|
||||||
|
import CodeMirrorMerge from 'react-codemirror-merge'
|
||||||
|
|
||||||
|
import Modal from '@widgets/Modal'
|
||||||
|
|
||||||
|
import { CompareVersionModalPropsType } from '@components/CompareVersionModal/compare-version-modal.type'
|
||||||
|
|
||||||
|
import { sortObject } from '@utils/objectUtils.ts'
|
||||||
|
|
||||||
|
import { useAppSelector } from '@hooks/redux.ts'
|
||||||
|
|
||||||
|
import configServiceApi from '@services/configService.ts'
|
||||||
|
import userServiceApi from '@services/userService.ts'
|
||||||
|
|
||||||
|
import { VersionType } from '@type/version.type'
|
||||||
|
|
||||||
|
import './compare-version-modal.scss'
|
||||||
|
import dayjs from 'dayjs'
|
||||||
|
|
||||||
|
|
||||||
|
const Original = CodeMirrorMerge.Original
|
||||||
|
const Modified = CodeMirrorMerge.Modified
|
||||||
|
|
||||||
|
const CompareVersionModal: FC<CompareVersionModalPropsType> = ({
|
||||||
|
open,
|
||||||
|
onClose,
|
||||||
|
config,
|
||||||
|
currentConfigId
|
||||||
|
}) => {
|
||||||
|
const [selectedItem, setSelectedItem] = useState<VersionType>()
|
||||||
|
const { data: versions = [], isLoading: isVersionLoading } =
|
||||||
|
configServiceApi.useGetAllVersionQuery(currentConfigId)
|
||||||
|
const { data: allUsers = [], isLoading: isUsersLoading } =
|
||||||
|
userServiceApi.useGetAllUsersQuery()
|
||||||
|
const { profile } = useAppSelector((state) => state.profileReducer)
|
||||||
|
const isLoading = isVersionLoading || isUsersLoading
|
||||||
|
if (isLoading) {
|
||||||
|
return <Spin />
|
||||||
|
}
|
||||||
|
|
||||||
|
const columns: ColumnsType<VersionType> = [
|
||||||
|
{
|
||||||
|
key: 'configVersion',
|
||||||
|
title: 'Версия конфигурации',
|
||||||
|
dataIndex: 'configVersion'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'createdAt',
|
||||||
|
title: 'Создано',
|
||||||
|
dataIndex: 'createdAt',
|
||||||
|
render: (value: string) => {
|
||||||
|
return dayjs(value).format('HH:mm:ss DD.MM.YYYY')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
key: 'user',
|
||||||
|
title: 'Автор',
|
||||||
|
dataIndex: 'adminId',
|
||||||
|
render: (value: number) => {
|
||||||
|
const user = allUsers.find((user) => user.id === value)
|
||||||
|
if (user) {
|
||||||
|
return `${user.lastName} ${user.firstName}`
|
||||||
|
}
|
||||||
|
return `${profile.lastName} ${profile.firstName}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
return (
|
||||||
|
<div className="compare-version-modal">
|
||||||
|
<Modal title="Сравнение версий" open={open} onClose={onClose}>
|
||||||
|
{selectedItem ? (
|
||||||
|
<div className="compare-version-modal__content">
|
||||||
|
<Button onClick={() => setSelectedItem(undefined)}>Назад</Button>
|
||||||
|
<div className="compare-version-modal__header">
|
||||||
|
<span> Версия: {selectedItem.configVersion}</span>
|
||||||
|
<span>Текущая версия : {config?.version || config?.configVersion}</span>
|
||||||
|
</div>
|
||||||
|
<CodeMirrorMerge orientation="a-b">
|
||||||
|
<Original
|
||||||
|
value={JSON.stringify(sortObject(selectedItem.data), null, 2)}
|
||||||
|
/>
|
||||||
|
<Modified
|
||||||
|
value={JSON.stringify(sortObject(config?.data), null, 2)}
|
||||||
|
extensions={[
|
||||||
|
EditorView.editable.of(false),
|
||||||
|
EditorState.readOnly.of(true)
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</CodeMirrorMerge>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="compare-version-modal__content__table">
|
||||||
|
<Table
|
||||||
|
rowClassName="compare-version-modal__content__table__row"
|
||||||
|
size="small"
|
||||||
|
columns={columns}
|
||||||
|
pagination={{ pageSize: 30 }}
|
||||||
|
dataSource={versions}
|
||||||
|
rowKey={(record) => record.id}
|
||||||
|
onRow={(record) => {
|
||||||
|
return {
|
||||||
|
onClick: () => setSelectedItem(record)
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default CompareVersionModal
|
||||||
Reference in new issue
Block a user