2024-06-14 16:22:19: merge [main:0f6b5e91772104b617d4a0d9ddf14a9f3f8b806e];
This commit is contained in:
1 parent
031a92db3f
commit
151be0e635
25 files changed
+858
-141
No files matched your search
@@ -0,0 +1,76 @@
|
||||
@import "../../constants/style/styleConst";
|
||||
|
||||
.configuration-editor-page {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: white;
|
||||
height: 100%;
|
||||
-ms-overflow-style: none; /* IE и Edge */
|
||||
scrollbar-width: none;
|
||||
border-left: 1px solid $border-color;
|
||||
&::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
.react-json-view {
|
||||
margin: $basic-margin *3 0 $basic-margin *2 0;
|
||||
}
|
||||
&__header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
padding: $basic-padding *2 $basic-padding;
|
||||
border-bottom: 1px solid $border-color;
|
||||
}
|
||||
&__controll{
|
||||
display: flex;
|
||||
}
|
||||
|
||||
&__save-btn {
|
||||
width: auto;
|
||||
margin-left: $basic-margin;
|
||||
}
|
||||
&__content {
|
||||
padding: $basic-padding * 3 $basic-padding;
|
||||
}
|
||||
|
||||
.rjsf {
|
||||
display: flex;
|
||||
|
||||
.form-group {
|
||||
width: 100%;
|
||||
}
|
||||
.ant-form-item-label {
|
||||
text-align: start;
|
||||
}
|
||||
.ant-tabs-right {
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
.ant-col-8 .ant-form-item-label {
|
||||
margin-right: $basic-margin *2;
|
||||
}
|
||||
|
||||
}
|
||||
.ant-btn-group {
|
||||
margin-top: 40px;
|
||||
}
|
||||
.ant-row .ant-row-end {
|
||||
width: 60px;
|
||||
margin: 0 0 $basic-margin auto !important;
|
||||
}
|
||||
&__form {
|
||||
padding: $basic-padding;
|
||||
}
|
||||
.modal__wrap {
|
||||
min-height: 110px;
|
||||
}
|
||||
.confirm-btn {
|
||||
width: 190px;
|
||||
}
|
||||
.confirm-btn, .danger {
|
||||
margin-right: $basic-margin;
|
||||
}
|
||||
.error-data {
|
||||
color: red;
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
import { RollbackOutlined } from '@ant-design/icons'
|
||||
import { Button, Dropdown, MenuProps, message, Radio, RadioChangeEvent, Spin } from 'antd'
|
||||
import { Dispatch, FC, SetStateAction, useEffect, useState } from 'react'
|
||||
import { useLocation, useNavigate, useParams } from 'react-router-dom'
|
||||
|
||||
import ConfigurationEditorCode from '@components/ConfigurationEditorCode'
|
||||
import ConfigurationEditorJson from '@components/ConfigurationEditorJson'
|
||||
|
||||
import configServiceApi from '@services/configService.ts'
|
||||
import modulesServiceApi from '@services/modulesService.ts'
|
||||
|
||||
import './configuration-editor-page.scss'
|
||||
import ConfigSchemaModal from '@components/ConfigSchemaModal'
|
||||
import { cleanEmptyParamsObject, sortObject } from '@utils/objectUtils.ts'
|
||||
import { ConfigType, ResponseSchemaType } from '@pages/ModulesPage/module.type.ts'
|
||||
import ConfirmConfigModal from '@components/ConfirmConfigModal/ConfirmConfigModal.tsx'
|
||||
import ErrorConfigModal from '@components/ErrorConfigModal/ErrorConfigModal.tsx'
|
||||
|
||||
export interface ConfigurationEditorPropsType {
|
||||
JsonSchema?: ResponseSchemaType
|
||||
bufConfig?: ConfigType
|
||||
setBufConfig: Dispatch<SetStateAction<ConfigType | undefined>>
|
||||
isCurrentConfigLoading: boolean
|
||||
setDisableBtn?: Dispatch<SetStateAction<boolean>>
|
||||
}
|
||||
|
||||
const ConfigurationEditorPage: FC = () => {
|
||||
const navigate = useNavigate()
|
||||
const { moduleId = '' } = useParams()
|
||||
const { id = '' } = useParams()
|
||||
const isNew = id === 'new'
|
||||
const { data: JsonSchema, isLoading: isLoadingJsonSchema } =
|
||||
modulesServiceApi.useGetByModuleIdQuery(moduleId)
|
||||
const {
|
||||
data: currentConfig,
|
||||
isLoading: isCurrentConfigLoading,
|
||||
} = configServiceApi.useGetConfigByIdQuery(id)
|
||||
const [createUpdateConfig] = configServiceApi.useCreateUpdateConfigMutation()
|
||||
const { state } = useLocation()
|
||||
const [showConfirmModal, setShowConfirmModal] = useState(false)
|
||||
const [showSchemeModal, setShowSchemeModal] = useState(false)
|
||||
const [radioValue, setRadioValue] = useState('json')
|
||||
const [bufConfig, setBufConfig] = useState<ConfigType>()
|
||||
const [detailsErrors, setDetailsError] = useState({ details: {}, isOpenDetailsErrorModal: false })
|
||||
const [disableBtn, setDisableBtn] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
setBufConfig(isNew ? {} : sortObject(currentConfig))
|
||||
}, [isCurrentConfigLoading])
|
||||
|
||||
const itemsSaveBtn = [
|
||||
{
|
||||
key: 'save',
|
||||
label: 'Сохранить'
|
||||
},
|
||||
{
|
||||
key: 'unsafe',
|
||||
label: 'Сохранить небезопасно'
|
||||
}
|
||||
]
|
||||
|
||||
const onSaveBtn: MenuProps['onClick'] = (e, upVersion = undefined) => {
|
||||
const isUnsafe = e.key === 'unsafe'
|
||||
handleSaveClick(upVersion, isUnsafe)
|
||||
}
|
||||
|
||||
const onRadioChange = (e: RadioChangeEvent) => {
|
||||
setRadioValue(e.target.value)
|
||||
}
|
||||
|
||||
const handleSaveClick = (upVersion?: number, unsafe?: boolean) => {
|
||||
let newData = {}
|
||||
if (bufConfig) {
|
||||
if (isNew) {
|
||||
newData = {
|
||||
name: state.name,
|
||||
moduleId: moduleId,
|
||||
id: '',
|
||||
version: 0,
|
||||
data: bufConfig.data,
|
||||
unsafe: unsafe
|
||||
} as ConfigType
|
||||
}
|
||||
if (currentConfig) {
|
||||
newData = {
|
||||
...bufConfig,
|
||||
version: upVersion ? upVersion : currentConfig.version,
|
||||
unsafe: unsafe
|
||||
} as ConfigType
|
||||
}
|
||||
}
|
||||
createUpdateConfig(cleanEmptyParamsObject(newData))
|
||||
.unwrap()
|
||||
.then(({ id }) => {
|
||||
message.success('Конфигурация успешно сохранена')
|
||||
isNew && navigate(`/${moduleId}/configEditor/${id}`)
|
||||
})
|
||||
.catch((e) => {
|
||||
if (e.data.errorCode === 2004) {
|
||||
setShowConfirmModal(true)
|
||||
}
|
||||
if (e.data.errorCode === 2003) {
|
||||
setDetailsError({ details: e.data.details, isOpenDetailsErrorModal: true })
|
||||
}
|
||||
if (e.data.errorCode === 400) {
|
||||
message.error('Невалидный JSON объект')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
if (isLoadingJsonSchema || isCurrentConfigLoading) {
|
||||
return <Spin className="spin" />
|
||||
}
|
||||
|
||||
|
||||
const renderContent = () => {
|
||||
|
||||
switch (radioValue) {
|
||||
// case 'form':
|
||||
// return (
|
||||
// <ConfigurationEditorForm
|
||||
// bufConfig={bufConfig}
|
||||
// setBufConfig={setBufConfig}
|
||||
// isCurrentConfigLoading={isCurrentConfigLoading}
|
||||
// />
|
||||
// )
|
||||
case 'json':
|
||||
return (
|
||||
<ConfigurationEditorJson
|
||||
bufConfig={bufConfig}
|
||||
setBufConfig={setBufConfig}
|
||||
isCurrentConfigLoading={isCurrentConfigLoading}
|
||||
/>
|
||||
)
|
||||
case 'code':
|
||||
return (
|
||||
<ConfigurationEditorCode
|
||||
setDisableBtn={setDisableBtn}
|
||||
bufConfig={bufConfig}
|
||||
setBufConfig={setBufConfig}
|
||||
isCurrentConfigLoading={isCurrentConfigLoading}
|
||||
/>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<main className="configuration-editor-page">
|
||||
<section className="configuration-editor-page__header">
|
||||
<Button onClick={() => navigate(-1)}>
|
||||
<RollbackOutlined />
|
||||
Назад
|
||||
</Button>
|
||||
<div className="configuration-editor-page__controll">
|
||||
<Button
|
||||
disabled={!JsonSchema}
|
||||
className="configurations____buttons__show-schema-btn"
|
||||
onClick={() => setShowSchemeModal(true)}
|
||||
>
|
||||
Текущая схема конфигурации
|
||||
</Button>
|
||||
<Dropdown.Button
|
||||
onClick={() => {
|
||||
handleSaveClick()
|
||||
navigate(`/modules/${moduleId}/configurations`)
|
||||
}}
|
||||
disabled={disableBtn}
|
||||
type="primary"
|
||||
className="configuration-editor-page__save-btn"
|
||||
menu={{ items: itemsSaveBtn, onClick: onSaveBtn }}
|
||||
>
|
||||
Сохранить и выйти
|
||||
</Dropdown.Button>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
<div className="configuration-editor-page__content">
|
||||
<Radio.Group defaultValue="json" size="large" onChange={onRadioChange}>
|
||||
<Radio.Button disabled value="form">Форма</Radio.Button>
|
||||
<Radio.Button disabled={disableBtn} value="json">JSON</Radio.Button>
|
||||
<Radio.Button value="code">Редактор кода</Radio.Button>
|
||||
</Radio.Group>
|
||||
|
||||
{renderContent()}
|
||||
</div>
|
||||
|
||||
|
||||
<ConfigSchemaModal
|
||||
schema={JsonSchema?.schema}
|
||||
open={showSchemeModal}
|
||||
onClose={() => setShowSchemeModal(false)}
|
||||
/>
|
||||
|
||||
<ConfirmConfigModal
|
||||
currentConfig={currentConfig}
|
||||
setBufConfig={setBufConfig}
|
||||
open={showConfirmModal}
|
||||
handleSaveClick={handleSaveClick}
|
||||
onClose={() => setShowConfirmModal(false)} />
|
||||
|
||||
<ErrorConfigModal details={detailsErrors.details} open={detailsErrors.isOpenDetailsErrorModal}
|
||||
onClose={() => setDetailsError({details: {}, isOpenDetailsErrorModal: false })} />
|
||||
|
||||
</main>
|
||||
)
|
||||
}
|
||||
|
||||
export default ConfigurationEditorPage
|
||||
@@ -101,6 +101,7 @@ const Configurations = () => {
|
||||
</Button>
|
||||
</div>
|
||||
<ActiveConfigurationsTable
|
||||
currentModule={currentModule}
|
||||
isActiveTable
|
||||
data={isError ? [] : activeConfigs}
|
||||
handleShowConfig={(config) => {
|
||||
@@ -113,6 +114,7 @@ const Configurations = () => {
|
||||
}}
|
||||
/>
|
||||
<ActiveConfigurationsTable
|
||||
currentModule={currentModule}
|
||||
data={isError ? [] : inactiveConfigs}
|
||||
handleShowConfig={(config) => {
|
||||
setCurrentConfig(config)
|
||||
|
||||
@@ -107,7 +107,7 @@ const ModulesPage = () => {
|
||||
}
|
||||
|
||||
const versionCompare = (versions: string[]) => {
|
||||
const sorted = versions?.sort(compareVersions)
|
||||
const sorted = (versions || ['']).sort(compareVersions)
|
||||
const firstVersion = sorted[0]
|
||||
for (let i = 1; i < sorted.length; i++) {
|
||||
if (compareVersions(firstVersion, sorted[i]) !== 0) {
|
||||
@@ -118,7 +118,7 @@ const ModulesPage = () => {
|
||||
}
|
||||
|
||||
const getLastVersion = (versions: string[]) => {
|
||||
const sorted = versions?.sort(compareVersions)
|
||||
const sorted = (versions || ['']).sort(compareVersions)
|
||||
return sorted[sorted.length - 1]
|
||||
}
|
||||
|
||||
@@ -133,58 +133,58 @@ const ModulesPage = () => {
|
||||
: null
|
||||
|
||||
const renderItems = (item: ModuleType) => {
|
||||
const isSame = versionCompare(item.status.map((i) => i.version))
|
||||
const textTooltip = isSame
|
||||
? 'Активны экземпляры одинаковых версий'
|
||||
: 'Активны экземпляры разных версий'
|
||||
const lastVersion = getLastVersion(item.status.map((i) => i.version))
|
||||
const isSame = versionCompare(item?.status?.map((i) => i.version))
|
||||
const textTooltip = isSame
|
||||
? 'Активны экземпляры одинаковых версий'
|
||||
: 'Активны экземпляры разных версий'
|
||||
const lastVersion = getLastVersion(item.status?.map((i) => i.version))
|
||||
|
||||
const renderVersion = () => {
|
||||
if (!isSame && lastVersion) {
|
||||
return (
|
||||
<Tag icon={<ExclamationCircleOutlined />} color="warning">
|
||||
{lastVersion}
|
||||
</Tag>
|
||||
)
|
||||
const renderVersion = () => {
|
||||
if (!isSame && lastVersion) {
|
||||
return (
|
||||
<Tag icon={<ExclamationCircleOutlined />} color="warning">
|
||||
{lastVersion}
|
||||
</Tag>
|
||||
)
|
||||
}
|
||||
if (isSame && lastVersion) {
|
||||
return <Tag color="default">{lastVersion}</Tag>
|
||||
}
|
||||
return ''
|
||||
}
|
||||
if (isSame && lastVersion) {
|
||||
return <Tag color="default">{lastVersion}</Tag>
|
||||
}
|
||||
return ''
|
||||
}
|
||||
|
||||
return (
|
||||
<List.Item>
|
||||
<Tooltip mouseEnterDelay={1} title={item.name}>
|
||||
<List.Item.Meta
|
||||
title={
|
||||
<div className="module-item__name">
|
||||
<span>{item.name}</span>
|
||||
<Tooltip
|
||||
overlayInnerStyle={{ width: '300px' }}
|
||||
title={textTooltip}
|
||||
>
|
||||
{renderVersion()}
|
||||
</Tooltip>
|
||||
</div>
|
||||
}
|
||||
description={
|
||||
<div className="module-item__content">
|
||||
return (
|
||||
<List.Item>
|
||||
<Tooltip mouseEnterDelay={1} title={item.name}>
|
||||
<List.Item.Meta
|
||||
title={
|
||||
<div className="module-item__name">
|
||||
<span>{item.name}</span>
|
||||
<Tooltip
|
||||
overlayInnerStyle={{ width: '300px' }}
|
||||
title={textTooltip}
|
||||
>
|
||||
{renderVersion()}
|
||||
</Tooltip>
|
||||
</div>
|
||||
}
|
||||
description={
|
||||
<div className="module-item__content">
|
||||
<span className="module-item__content__description">
|
||||
активные экземпляры:
|
||||
</span>
|
||||
<Badge
|
||||
size="small"
|
||||
showZero
|
||||
count={(item.status && item.status.length) || 0}
|
||||
color={!item.status || !item.status.length ? '' : 'cyan'}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</Tooltip>
|
||||
</List.Item>
|
||||
)
|
||||
<Badge
|
||||
size="small"
|
||||
showZero
|
||||
count={(item.status && item.status.length) || 0}
|
||||
color={!item.status || !item.status.length ? '' : 'cyan'}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</Tooltip>
|
||||
</List.Item>
|
||||
)
|
||||
}
|
||||
|
||||
const renderMainContent = () => {
|
||||
@@ -220,25 +220,26 @@ const ModulesPage = () => {
|
||||
selectedItemId={selectedItemId}
|
||||
setSelectedItemId={setSelectedItemId}
|
||||
/>
|
||||
<Tabs
|
||||
activeKey={activeTab}
|
||||
onChange={(activeKey) => {
|
||||
setActiveTab(activeKey)
|
||||
const path = `${selectedItemId}/${activeKey}`
|
||||
navigate(path)
|
||||
}}
|
||||
className="modules-page__tabs"
|
||||
items={secondColumnItems.map((item) => {
|
||||
return {
|
||||
disabled: selectedItemId === '',
|
||||
label: item.name,
|
||||
key: item.key,
|
||||
children: (
|
||||
<div className="modules-page__content">{renderMainContent()}</div>
|
||||
)
|
||||
}
|
||||
})}
|
||||
/>
|
||||
<Tabs
|
||||
activeKey={activeTab}
|
||||
onChange={(activeKey) => {
|
||||
setActiveTab(activeKey)
|
||||
const path = `${selectedItemId}/${activeKey}`
|
||||
navigate(path)
|
||||
}}
|
||||
className="modules-page__tabs"
|
||||
items={secondColumnItems.map((item) => {
|
||||
return {
|
||||
disabled: selectedItemId === '',
|
||||
label: item.name,
|
||||
key: item.key,
|
||||
children: (
|
||||
<div className="modules-page__content">{renderMainContent()}</div>
|
||||
)
|
||||
}
|
||||
})}
|
||||
/>
|
||||
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ export interface ConfigType {
|
||||
updatedAt: string
|
||||
valid: boolean
|
||||
version: number
|
||||
unsafe?: boolean
|
||||
}
|
||||
|
||||
export interface JSONSchema {
|
||||
@@ -88,6 +89,14 @@ export interface ModuleType {
|
||||
configSchema: JSONSchema
|
||||
}
|
||||
|
||||
export interface ResponseSchemaType {
|
||||
createdAt: string,
|
||||
id: string,
|
||||
moduleId: string,
|
||||
schema: JSONSchema,
|
||||
updatedAt: string,
|
||||
version: string
|
||||
}
|
||||
export interface ConfigResponse {
|
||||
originalResponse: ConfigType[]
|
||||
activeConfigs: ConfigType[]
|
||||
|
||||
@@ -2,11 +2,9 @@
|
||||
|
||||
.modules-page {
|
||||
height: 100%;
|
||||
|
||||
&__tabs {
|
||||
padding: 0 $basic-padding*2 $basic-padding*2;
|
||||
padding: 0 $basic-padding*2;
|
||||
width: 100%;
|
||||
overflow-x: scroll;
|
||||
}
|
||||
|
||||
.ant-tag {
|
||||
|
||||
Reference in new issue
Block a user