From 3d512744879078f9ec221ffd56bb6fcd85f7ec69 Mon Sep 17 00:00:00 2001 From: veselovnk Date: Sat, 27 Apr 2024 16:29:59 +0300 Subject: [PATCH] MSP-3203 create CompareVersionModal --- .../compare-version-modal.scss | 37 ++++++ .../compare-version-modal.type.ts | 7 ++ src/components/CompareVersionModal/index.tsx | 116 ++++++++++++++++++ 3 files changed, 160 insertions(+) create mode 100644 src/components/CompareVersionModal/compare-version-modal.scss create mode 100644 src/components/CompareVersionModal/compare-version-modal.type.ts create mode 100644 src/components/CompareVersionModal/index.tsx diff --git a/src/components/CompareVersionModal/compare-version-modal.scss b/src/components/CompareVersionModal/compare-version-modal.scss new file mode 100644 index 0000000..df98ba5 --- /dev/null +++ b/src/components/CompareVersionModal/compare-version-modal.scss @@ -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; + } + } + } +} diff --git a/src/components/CompareVersionModal/compare-version-modal.type.ts b/src/components/CompareVersionModal/compare-version-modal.type.ts new file mode 100644 index 0000000..278d74a --- /dev/null +++ b/src/components/CompareVersionModal/compare-version-modal.type.ts @@ -0,0 +1,7 @@ +import { ModalPropsType } from '@widgets/Modal/modal.type.ts' + +export interface CompareVersionModalPropsType + extends Omit { + config: Record + currentConfigId: string +} diff --git a/src/components/CompareVersionModal/index.tsx b/src/components/CompareVersionModal/index.tsx new file mode 100644 index 0000000..177f6cb --- /dev/null +++ b/src/components/CompareVersionModal/index.tsx @@ -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 = ({ + open, + onClose, + config, + currentConfigId + }) => { + const [selectedItem, setSelectedItem] = useState() + 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 + } + + const columns: ColumnsType = [ + { + 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 ( +
+ + {selectedItem ? ( +
+ +
+ Версия: {selectedItem.configVersion} + Текущая версия : {config?.version || config?.configVersion} +
+ + + + +
+ ) : ( +
+ record.id} + onRow={(record) => { + return { + onClick: () => setSelectedItem(record) + } + }} + /> + + )} + + + ) +} + +export default CompareVersionModal