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
@@ -1,8 +1,9 @@
|
||||
import { ConfigType } from '@pages/ModulesPage/module.type.ts'
|
||||
import { ConfigType, ModuleType } from '@pages/ModulesPage/module.type.ts'
|
||||
|
||||
export interface ActiveConfigurationsTablePropsType {
|
||||
isActiveTable?: boolean
|
||||
data: ConfigType[]
|
||||
handleShowConfig: (config: ConfigType) => void
|
||||
handleShowCompareModal: (config: ConfigType) => void
|
||||
currentModule?: ModuleType
|
||||
}
|
||||
@@ -17,6 +17,8 @@ import './active-configurations-table.scss'
|
||||
import dayjs from 'dayjs'
|
||||
import CanEdit from '@components/CanEdit'
|
||||
import { dateFormats } from '@constants/date.ts'
|
||||
import { routePaths } from '@routes/routePaths.ts'
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
|
||||
|
||||
const ActiveConfigurationsTable: FC<ActiveConfigurationsTablePropsType> =
|
||||
@@ -24,7 +26,8 @@ const ActiveConfigurationsTable: FC<ActiveConfigurationsTablePropsType> =
|
||||
isActiveTable = false,
|
||||
handleShowConfig,
|
||||
handleShowCompareModal,
|
||||
data
|
||||
data,
|
||||
currentModule = {}
|
||||
}) => {
|
||||
const [editKeyConfig, setEditKeyConfig] = useState<string>('')
|
||||
const [tempEditValues, setTempEditValues] = useState<any>()
|
||||
@@ -32,7 +35,8 @@ const ActiveConfigurationsTable: FC<ActiveConfigurationsTablePropsType> =
|
||||
const [createUpdateConfig] = configApi.useCreateUpdateConfigMutation()
|
||||
const [markConfigAsActive] = configApi.useMarkConfigAsActiveMutation()
|
||||
const [deleteConfig] = configApi.useDeleteConfigMutation()
|
||||
|
||||
const navigate = useNavigate()
|
||||
const {id: moduleId} = useParams()
|
||||
|
||||
useEffect(() => {
|
||||
if (inputRefs.current[editKeyConfig]) {
|
||||
@@ -198,9 +202,7 @@ const ActiveConfigurationsTable: FC<ActiveConfigurationsTablePropsType> =
|
||||
{!isActiveTable && <CanEdit>
|
||||
<Button
|
||||
className="configurations__buttons__new-config-brn"
|
||||
onClick={() => {
|
||||
// TODO создание новой конфигурации
|
||||
}}
|
||||
onClick={() => navigate(`/${moduleId}/${routePaths.configEditor}/new`, {state: currentModule})}
|
||||
>
|
||||
Создать
|
||||
</Button>
|
||||
|
||||
@@ -5,5 +5,5 @@ import { JSONSchema } from '@pages/ModulesPage/module.type.ts'
|
||||
|
||||
export interface ConfigSchemaModalPropsType
|
||||
extends Omit<ModalPropsType, 'title' | 'children'> {
|
||||
schema: JSONSchema
|
||||
schema?: JSONSchema
|
||||
}
|
||||
@@ -7,12 +7,12 @@ import { ConfigSchemaModalPropsType } from '@components/ConfigSchemaModal/config
|
||||
|
||||
import './config-schema-modal.scss'
|
||||
|
||||
|
||||
const ConfigSchemaModal: FC<ConfigSchemaModalPropsType> = ({
|
||||
open,
|
||||
onClose,
|
||||
schema
|
||||
schema = {}
|
||||
}) => {
|
||||
|
||||
return (
|
||||
<div className="config-schema-modal">
|
||||
<Modal title="Текущая схема" open={open} onClose={onClose}>
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
import { FC } from 'react'
|
||||
import { ConfigurationEditorPropsType } from '@pages/ConfigurationEditorPage'
|
||||
import Editor from '@monaco-editor/react'
|
||||
import { ConfigType } from '@pages/ModulesPage/module.type.ts'
|
||||
import { message } from 'antd'
|
||||
|
||||
const ConfigurationEditorCode: FC<ConfigurationEditorPropsType> = ({setDisableBtn= () => {}, bufConfig, setBufConfig }) => {
|
||||
const debounce = (func: (...args: any[]) => void, wait: number) => {
|
||||
let timeout: NodeJS.Timeout
|
||||
return (...args: []) => {
|
||||
clearTimeout(timeout)
|
||||
timeout = setTimeout(() => {
|
||||
func.apply(this, [...args])
|
||||
}, wait)
|
||||
}
|
||||
}
|
||||
|
||||
const debouncedHandleError = debounce(() => {
|
||||
message.error('Невалидный JSON объект')
|
||||
}, 500)
|
||||
|
||||
const handleChange = (data: string | undefined) => {
|
||||
|
||||
if (data) {
|
||||
try {
|
||||
const newData = {
|
||||
...bufConfig,
|
||||
data: {...JSON.parse(data) }
|
||||
} as ConfigType
|
||||
setDisableBtn(false)
|
||||
setBufConfig(newData)
|
||||
} catch (error) {
|
||||
debouncedHandleError()
|
||||
setDisableBtn(true)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const editorValue = JSON.stringify(bufConfig?.data, null, '\t')
|
||||
|
||||
return (
|
||||
<div>
|
||||
<Editor
|
||||
width="auto"
|
||||
height="100vh"
|
||||
language="json"
|
||||
theme="vs-white"
|
||||
value={editorValue}
|
||||
onChange={handleChange}
|
||||
options={{
|
||||
minimap: {
|
||||
enabled: false
|
||||
},
|
||||
fontSize: 16,
|
||||
}}
|
||||
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ConfigurationEditorCode
|
||||
@@ -0,0 +1,112 @@
|
||||
import { Theme as AntDTheme } from '@rjsf/antd'
|
||||
import { withTheme } from '@rjsf/core'
|
||||
import { UiSchema } from '@rjsf/utils'
|
||||
import validator from '@rjsf/validator-ajv8'
|
||||
import { FC, useEffect, useState } from 'react'
|
||||
|
||||
import { ConfigurationEditorPropsType } from '@pages/ConfigurationEditorPage'
|
||||
import { Tabs } from 'antd'
|
||||
import equal from 'deep-equal'
|
||||
import { useParams } from 'react-router-dom'
|
||||
|
||||
const ConfigurationEditorForm: FC<ConfigurationEditorPropsType> = ({
|
||||
bufConfig ={},
|
||||
JsonSchema,
|
||||
setBufConfig,
|
||||
}) => {
|
||||
const Form = withTheme(AntDTheme)
|
||||
const sortProps = (a, b) => a.name.localeCompare(b.name)
|
||||
|
||||
const [formState, setFormState] = useState(bufConfig.data)
|
||||
const [activeTabKey, setActiveTabKey] = useState()
|
||||
const {id} = useParams()
|
||||
|
||||
useEffect(() => {
|
||||
if(!equal(formState, bufConfig.data)) {
|
||||
setFormState(bufConfig.data)
|
||||
}
|
||||
}, [bufConfig.data])
|
||||
|
||||
const uiSchema: UiSchema = {
|
||||
'ui:submitButtonOptions': {
|
||||
norender: true
|
||||
}
|
||||
}
|
||||
|
||||
const onFormChange = data => {
|
||||
if(!equal(data.formData, bufConfig.data)) {
|
||||
const newData = {
|
||||
...bufConfig,
|
||||
data: { ...data.formData }
|
||||
}
|
||||
if(!equal(newData, bufConfig.data)) {
|
||||
setBufConfig(newData)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
const handleTabsChange = e => {
|
||||
setActiveTabKey(e)
|
||||
}
|
||||
|
||||
const ObjectFieldTemplate = (props) => {
|
||||
const {
|
||||
properties,
|
||||
idSchema,
|
||||
schema: { properties: schemaProperties }
|
||||
} = props
|
||||
properties.sort(sortProps)
|
||||
|
||||
if (idSchema.$id === 'root') {
|
||||
const propsComplex: [] = []
|
||||
const propsSimple: [] = []
|
||||
|
||||
properties.forEach((prop) => {
|
||||
const fieldType = schemaProperties[prop.name].type
|
||||
if (!fieldType || fieldType === 'array' || fieldType === 'object') {
|
||||
propsComplex.push(prop)
|
||||
} else {
|
||||
propsSimple.push(prop)
|
||||
}
|
||||
})
|
||||
|
||||
return (
|
||||
<Tabs activeKey={activeTabKey} tabPosition="right" onChange={handleTabsChange} items={[
|
||||
...(propsSimple.length ? [{
|
||||
label: 'Остальные',
|
||||
key: 'General',
|
||||
children: propsSimple.map((element) => element.content),
|
||||
}] : []),
|
||||
...propsComplex.map((element) => ({
|
||||
label: schemaProperties[element.name]?.title || element.name,
|
||||
key: element.name,
|
||||
children: element.content,
|
||||
})),
|
||||
]} />
|
||||
)
|
||||
}
|
||||
|
||||
return properties.map((element) => element.content)
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="configuration-editor-page__form">
|
||||
<Form
|
||||
formContext={{
|
||||
// labelCol: { span: 8 },
|
||||
// wrapperCol: { span: 30 },
|
||||
// layout: 'horizontal'
|
||||
}}
|
||||
uiSchema={uiSchema}
|
||||
templates={{ ObjectFieldTemplate }}
|
||||
validator={validator}
|
||||
schema={JsonSchema?.schema}
|
||||
formData={id === 'new' ? {} : formState}
|
||||
onChange={onFormChange}
|
||||
></Form>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
export default ConfigurationEditorForm
|
||||
@@ -0,0 +1,34 @@
|
||||
import { FC } from 'react'
|
||||
import {ConfigurationEditorPropsType} from '@pages/ConfigurationEditorPage'
|
||||
import { ReactJsonView } from 'isp-ui-kit'
|
||||
import {Spin} from 'antd'
|
||||
import { cleanEmptyParamsObject } from '@utils/objectUtils.ts'
|
||||
|
||||
const ConfigurationEditorJson: FC<ConfigurationEditorPropsType> = ({ bufConfig = {}, setBufConfig, isCurrentConfigLoading, JsonSchema}) => {
|
||||
if (isCurrentConfigLoading) {
|
||||
return <Spin className="spin" />
|
||||
}
|
||||
|
||||
return (
|
||||
<ReactJsonView
|
||||
displayDataTypes={false}
|
||||
displayObjectSize={false}
|
||||
name={null}
|
||||
enableClipboard={true}
|
||||
iconStyle="square"
|
||||
onEdit={({updated_src}: any) => {
|
||||
const newData = {
|
||||
...bufConfig,
|
||||
data: { ...updated_src }
|
||||
}
|
||||
setBufConfig(cleanEmptyParamsObject(newData))
|
||||
}
|
||||
}
|
||||
src={bufConfig.data}
|
||||
sortKeys={true}
|
||||
collapsed={1}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
export default ConfigurationEditorJson
|
||||
@@ -0,0 +1,48 @@
|
||||
import { Button } from 'antd'
|
||||
import Modal from '@widgets/Modal'
|
||||
import { ModalPropsType } from '@widgets/Modal/modal.type.ts'
|
||||
import { Dispatch, FC, SetStateAction } from 'react'
|
||||
import { ConfigType } from '@pages/ModulesPage/module.type.ts'
|
||||
import { useParams } from 'react-router-dom'
|
||||
import configServiceApi from '@services/configService.ts'
|
||||
|
||||
|
||||
interface ConfirmModalProps
|
||||
extends Omit<ModalPropsType, 'title' | 'children'> {
|
||||
handleSaveClick: (upVersion?: number, unsafe?: boolean) => void
|
||||
setBufConfig: Dispatch<SetStateAction<ConfigType | undefined>>
|
||||
currentConfig: ConfigType | undefined
|
||||
}
|
||||
|
||||
const ConfirmConfigModal: FC<ConfirmModalProps> = ({
|
||||
currentConfig,
|
||||
setBufConfig,
|
||||
handleSaveClick,
|
||||
onClose = () => null,
|
||||
open
|
||||
}) => {
|
||||
const { id = '' } = useParams()
|
||||
const isNew = id === 'new' ? '' : id
|
||||
|
||||
const {
|
||||
data
|
||||
} = configServiceApi.useGetConfigByIdQuery(isNew)
|
||||
|
||||
|
||||
const onConfirmHandler = () => {
|
||||
setBufConfig(currentConfig)
|
||||
onClose()
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal title="Версия конфигурации была кем-то изменена" open={open}
|
||||
onClose={onClose}>
|
||||
<Button className="confirm-btn danger" type="primary" danger onClick={() => {
|
||||
handleSaveClick(data && data.version)
|
||||
onClose()
|
||||
}}>Сохранить принудительно</Button>
|
||||
<Button className="confirm-btn" type="primary" onClick={onConfirmHandler}>Принять изменения</Button>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
export default ConfirmConfigModal
|
||||
@@ -0,0 +1,40 @@
|
||||
import Modal from '@widgets/Modal'
|
||||
import { ModalPropsType } from '@widgets/Modal/modal.type.ts'
|
||||
import { FC } from 'react'
|
||||
import { Table } from 'antd'
|
||||
|
||||
interface ErrorConfigModalProps
|
||||
extends Omit<ModalPropsType, 'title' | 'children'> {
|
||||
details?: { [key: string]: string }
|
||||
}
|
||||
|
||||
const ErrorConfigModal: FC<ErrorConfigModalProps> = ({ details = {}, onClose, open }) => {
|
||||
|
||||
const columns = [
|
||||
{
|
||||
dataIndex: 'key',
|
||||
key: 'key',
|
||||
render: (text: string) => <span style={{ color: 'red' }}>{text}</span>
|
||||
},
|
||||
{
|
||||
dataIndex: 'value',
|
||||
key: 'value'
|
||||
}
|
||||
]
|
||||
|
||||
const data = Object.keys(details).map((key) => ({
|
||||
key,
|
||||
value: details[key]
|
||||
}))
|
||||
|
||||
return (
|
||||
<Modal title="Несоотвествия схемы конфигурации" open={open}
|
||||
onClose={onClose}>
|
||||
<div>
|
||||
<Table columns={columns} dataSource={data} showHeader={false} pagination={false} />
|
||||
</div>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
|
||||
export default ErrorConfigModal
|
||||
Reference in new issue
Block a user