From 151be0e6354449437d8bef466f46d5c536d01b90 Mon Sep 17 00:00:00 2001 From: txix Date: Fri, 14 Jun 2024 16:22:19 +0300 Subject: [PATCH] 2024-06-14 16:22:19: merge [main:0f6b5e91772104b617d4a0d9ddf14a9f3f8b806e]; --- CHANGELOG.md | 2 + package-lock.json | 162 ++++++++++---- package.json | 3 +- .../active-configurations-table.type.ts | 3 +- .../ActiveConfigurationsTable/index.tsx | 12 +- .../config-schema-moda.type.ts | 2 +- src/components/ConfigSchemaModal/index.tsx | 4 +- .../ConfigurationEditorCode/index.tsx | 62 ++++++ .../ConfigurationEditorForm/index.tsx | 112 ++++++++++ .../ConfigurationEditorJson/index.tsx | 34 +++ .../ConfirmConfigModal/ConfirmConfigModal.tsx | 48 ++++ .../ErrorConfigModal/ErrorConfigModal.tsx | 40 ++++ src/constants/api/apiPaths.ts | 2 + .../configuration-editor-page.scss | 76 +++++++ src/pages/ConfigurationEditorPage/index.tsx | 209 ++++++++++++++++++ src/pages/ConfigurationsPage/index.tsx | 2 + src/pages/ModulesPage/index.tsx | 135 +++++------ src/pages/ModulesPage/module.type.ts | 9 + src/pages/ModulesPage/modules-page.scss | 4 +- src/routes/Routers/index.tsx | 12 +- src/routes/routePaths.ts | 4 +- src/services/configService.ts | 4 +- src/services/modulesService.ts | 19 +- src/utils/objectUtils.ts | 34 ++- .../ActiveTableActionButtons/index.tsx | 5 +- 25 files changed, 858 insertions(+), 141 deletions(-) create mode 100644 src/components/ConfigurationEditorCode/index.tsx create mode 100644 src/components/ConfigurationEditorForm/index.tsx create mode 100644 src/components/ConfigurationEditorJson/index.tsx create mode 100644 src/components/ConfirmConfigModal/ConfirmConfigModal.tsx create mode 100644 src/components/ErrorConfigModal/ErrorConfigModal.tsx create mode 100644 src/pages/ConfigurationEditorPage/configuration-editor-page.scss create mode 100644 src/pages/ConfigurationEditorPage/index.tsx diff --git a/CHANGELOG.md b/CHANGELOG.md index e995e48..c18dac9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,5 @@ +## 0.12.0 +- Добавлена страница редактирования/создания конфига ## 0.11.5 - Обновлена библиотека isp-ui-kit - Убраны лишние столбцы на странице токенов diff --git a/package-lock.json b/package-lock.json index 5bd6d1a..79f9459 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,7 @@ "dependencies": { "@apidevtools/json-schema-ref-parser": "^9.0.6", "@codemirror/lang-json": "^6.0.1", + "@monaco-editor/react": "^4.6.0", "@reduxjs/toolkit": "^2.2.3", "@types/react-router-dom": "^5.3.3", "@uiw/react-codemirror": "^4.21.25", @@ -17,6 +18,7 @@ "clipboard": "^2.0.11", "compare-versions": "^6.1.0", "dayjs": "^1.11.10", + "deep-equal": "^2.2.3", "isp-ui-kit": "github:txix-open/isp-ui-kit", "json-schema-view-js": "^2.0.1", "lodash.clonedeep": "^4.5.0", @@ -28,7 +30,8 @@ "react-resizable": "^3.0.5", "react-router-dom": "^6.22.3", "simplebar": "^6.2.5", - "simplebar-react": "^3.2.4" + "simplebar-react": "^3.2.4", + "uuid": "^10.0.0" }, "devDependencies": { "@trivago/prettier-plugin-sort-imports": "^4.3.0", @@ -2961,6 +2964,30 @@ "@lezer/common": "^1.0.0" } }, + "node_modules/@monaco-editor/loader": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/@monaco-editor/loader/-/loader-1.4.0.tgz", + "integrity": "sha512-00ioBig0x642hytVspPl7DbQyaSWRaolYie/UFNjoTdvoKPzo6xrXLhTk9ixgIKcLH5b5vDOjVNiGyY+uDCUlg==", + "dependencies": { + "state-local": "^1.0.6" + }, + "peerDependencies": { + "monaco-editor": ">= 0.21.0 < 1" + } + }, + "node_modules/@monaco-editor/react": { + "version": "4.6.0", + "resolved": "https://registry.npmjs.org/@monaco-editor/react/-/react-4.6.0.tgz", + "integrity": "sha512-RFkU9/i7cN2bsq/iTkurMWOEErmYcY6JiQI3Jn+WeR/FGISH8JbHERjpS9oRuSOPvDMJI0Z8nJeKkbOs9sBYQw==", + "dependencies": { + "@monaco-editor/loader": "^1.4.0" + }, + "peerDependencies": { + "monaco-editor": ">= 0.25.0 < 1", + "react": "^16.8.0 || ^17.0.0 || ^18.0.0", + "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", @@ -4509,7 +4536,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/array-buffer-byte-length/-/array-buffer-byte-length-1.0.1.tgz", "integrity": "sha512-ahC5W1xgou+KTXix4sAO8Ki12Q+jf4i0+tmk3sC+zgcynshkHxzpXdImBehiUYKKKDwvfFiJl1tZt6ewscS1Mg==", - "dev": true, "dependencies": { "call-bind": "^1.0.5", "is-array-buffer": "^3.0.4" @@ -4727,7 +4753,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", "integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==", - "dev": true, "dependencies": { "possible-typed-array-names": "^1.0.0" }, @@ -5091,7 +5116,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", - "dev": true, "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -5716,6 +5740,37 @@ } } }, + "node_modules/deep-equal": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.3.tgz", + "integrity": "sha512-ZIwpnevOurS8bpT4192sqAowWM76JDKSHYzMLty3BZGSswgq6pBaH3DhCSW5xVAZICZyKdOBPjwww5wfgT/6PA==", + "dependencies": { + "array-buffer-byte-length": "^1.0.0", + "call-bind": "^1.0.5", + "es-get-iterator": "^1.1.3", + "get-intrinsic": "^1.2.2", + "is-arguments": "^1.1.1", + "is-array-buffer": "^3.0.2", + "is-date-object": "^1.0.5", + "is-regex": "^1.1.4", + "is-shared-array-buffer": "^1.0.2", + "isarray": "^2.0.5", + "object-is": "^1.1.5", + "object-keys": "^1.1.1", + "object.assign": "^4.1.4", + "regexp.prototype.flags": "^1.5.1", + "side-channel": "^1.0.4", + "which-boxed-primitive": "^1.0.2", + "which-collection": "^1.0.1", + "which-typed-array": "^1.1.13" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/deep-is": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.4.tgz", @@ -5726,7 +5781,6 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", - "dev": true, "dependencies": { "es-define-property": "^1.0.0", "es-errors": "^1.3.0", @@ -5743,7 +5797,6 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.2.1.tgz", "integrity": "sha512-8QmQKqEASLd5nx0U1B1okLElbUuuttJ/AnYmRXbbbGDWh6uS208EjD4Xqq/I9wK7u0v6O08XhTWnt5XtEbR6Dg==", - "dev": true, "dependencies": { "define-data-property": "^1.0.1", "has-property-descriptors": "^1.0.0", @@ -5967,7 +6020,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", - "dev": true, "dependencies": { "get-intrinsic": "^1.2.4" }, @@ -5979,11 +6031,29 @@ "version": "1.3.0", "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "dev": true, "engines": { "node": ">= 0.4" } }, + "node_modules/es-get-iterator": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/es-get-iterator/-/es-get-iterator-1.1.3.tgz", + "integrity": "sha512-sPZmqHBe6JIiTfN5q2pEi//TwxmAFHwj/XEuYjTuse78i8KxaqMTTzxPoFKuzRpDpTJ+0NAbpfenkmH2rePtuw==", + "dependencies": { + "call-bind": "^1.0.2", + "get-intrinsic": "^1.1.3", + "has-symbols": "^1.0.3", + "is-arguments": "^1.1.1", + "is-map": "^2.0.2", + "is-set": "^2.0.2", + "is-string": "^1.0.7", + "isarray": "^2.0.5", + "stop-iteration-iterator": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/es-iterator-helpers": { "version": "1.0.18", "resolved": "https://registry.npmjs.org/es-iterator-helpers/-/es-iterator-helpers-1.0.18.tgz", @@ -6901,7 +6971,6 @@ "version": "0.3.3", "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", - "dev": true, "dependencies": { "is-callable": "^1.1.3" } @@ -6957,7 +7026,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", - "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -6984,7 +7052,6 @@ "version": "1.2.3", "resolved": "https://registry.npmjs.org/functions-have-names/-/functions-have-names-1.2.3.tgz", "integrity": "sha512-xckBUXyTIqT97tq2x2AMb+g163b5JFysYk0x4qxNFwbfQkmNZoiRHb6sPzI9/QV33WeuvVYBUIiD4NzNIyqaRQ==", - "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -7002,7 +7069,6 @@ "version": "1.2.4", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", - "dev": true, "dependencies": { "es-errors": "^1.3.0", "function-bind": "^1.1.2", @@ -7162,7 +7228,6 @@ "version": "1.0.1", "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", - "dev": true, "dependencies": { "get-intrinsic": "^1.1.3" }, @@ -7186,7 +7251,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-bigints/-/has-bigints-1.0.2.tgz", "integrity": "sha512-tSvCKtBr9lkF0Ex0aQiP9N+OpV4zi2r/Nee5VkRDbaqv35RLYMzbwQfFSZZH0kR+Rd6302UJZ2p/bJCEoR3VoQ==", - "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -7204,7 +7268,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", - "dev": true, "dependencies": { "es-define-property": "^1.0.0" }, @@ -7216,7 +7279,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -7228,7 +7290,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -7240,7 +7301,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "dev": true, "dependencies": { "has-symbols": "^1.0.3" }, @@ -7278,7 +7338,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", - "dev": true, "dependencies": { "function-bind": "^1.1.2" }, @@ -7416,7 +7475,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/internal-slot/-/internal-slot-1.0.7.tgz", "integrity": "sha512-NGnrKwXzSms2qUUih/ILZ5JBqNTSa1+ZmP6flaIp6KmSElgE9qdndzS3cqjrDovwFdmwsGsLdeFgB6suw+1e9g==", - "dev": true, "dependencies": { "es-errors": "^1.3.0", "hasown": "^2.0.0", @@ -7430,7 +7488,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", - "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -7446,7 +7503,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.4.tgz", "integrity": "sha512-wcjaerHw0ydZwfhiKbXJWLDY8A7yV7KhjQOpb83hGgGfId/aQa4TOvwyzn2PuswW2gPCYEL/nEAiSVpdOj1lXw==", - "dev": true, "dependencies": { "call-bind": "^1.0.2", "get-intrinsic": "^1.2.1" @@ -7483,7 +7539,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-bigint/-/is-bigint-1.0.4.tgz", "integrity": "sha512-zB9CruMamjym81i2JZ3UMn54PKGsQzsJeo6xvN3HJJ4CAsQNB6iRutp2To77OfCNuoxspsIhzaPoO1zyCEhFOg==", - "dev": true, "dependencies": { "has-bigints": "^1.0.1" }, @@ -7507,7 +7562,6 @@ "version": "1.1.2", "resolved": "https://registry.npmjs.org/is-boolean-object/-/is-boolean-object-1.1.2.tgz", "integrity": "sha512-gDYaKHJmnj4aWxyj6YHyXVpdQawtVLHU5cb+eztPGczf6cjuTdwve5ZIEfgXqH4e57An1D1AKf8CZ3kYrQRqYA==", - "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -7523,7 +7577,6 @@ "version": "1.2.7", "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -7562,7 +7615,6 @@ "version": "1.0.5", "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.5.tgz", "integrity": "sha512-9YQaSxsAiSwcvS33MBk3wTCVnWK+HhF8VZR2jRxehM16QcVOdHqPn4VPHmRK4lSr38n9JriurInLcP90xsYNfQ==", - "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -7625,7 +7677,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-map/-/is-map-2.0.3.tgz", "integrity": "sha512-1Qed0/Hr2m+YqxnM09CjA2d/i6YZNfF6R2oRAOj36eUdS6qIV/huPJNSEpKbupewFs+ZsJlxsjjPbc0/afW6Lw==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -7674,7 +7725,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/is-number-object/-/is-number-object-1.0.7.tgz", "integrity": "sha512-k1U0IRzLMo7ZlYIfzRu23Oh6MiIFasgpb9X76eqfFZAqwH44UI4KTBvBYIZ1dSL9ZzChTB9ShHfLkR4pdW5krQ==", - "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -7698,7 +7748,6 @@ "version": "1.1.4", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.1.4.tgz", "integrity": "sha512-kvRdxDsxZjhzUX07ZnLydzS1TU/TJlTUHHY4YLL87e37oUA49DfkLqgy+VjFocowy29cKvcSiu+kIv728jTTVg==", - "dev": true, "dependencies": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -7714,7 +7763,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-set/-/is-set-2.0.3.tgz", "integrity": "sha512-iPAjerrse27/ygGLxw+EBR9agv9Y6uLeYVJMu+QNCoouJ1/1ri0mGrcWpfCqFZuzzx3WjtwxG098X+n4OuRkPg==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -7726,7 +7774,6 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/is-shared-array-buffer/-/is-shared-array-buffer-1.0.3.tgz", "integrity": "sha512-nA2hv5XIhLR3uVzDDfCIknerhx8XUKnstuOERPNNIinXG7v9u+ohXF67vxm4TPTEPU6lm61ZkwP3c9PCB97rhg==", - "dev": true, "dependencies": { "call-bind": "^1.0.7" }, @@ -7741,7 +7788,6 @@ "version": "1.0.7", "resolved": "https://registry.npmjs.org/is-string/-/is-string-1.0.7.tgz", "integrity": "sha512-tE2UXzivje6ofPW7l23cjDOMa09gb7xlAqG6jG5ej6uPV32TlWP3NKPigtaGeHNu9fohccRYvIiZMfOOnOYUtg==", - "dev": true, "dependencies": { "has-tostringtag": "^1.0.0" }, @@ -7756,7 +7802,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.4.tgz", "integrity": "sha512-C/CPBqKWnvdcxqIARxyOh4v1UUEOCHpgDa0WYgpKDFMszcrPcffg5uhwSgPCLD2WWxmq6isisz87tzT01tuGhg==", - "dev": true, "dependencies": { "has-symbols": "^1.0.2" }, @@ -7786,7 +7831,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/is-weakmap/-/is-weakmap-2.0.2.tgz", "integrity": "sha512-K5pXYOm9wqY1RgjpL3YTkF39tni1XajUIkawTLUo9EZEVUFga5gSQJF8nNS7ZwJQ02y+1YCNYcMh+HIf1ZqE+w==", - "dev": true, "engines": { "node": ">= 0.4" }, @@ -7810,7 +7854,6 @@ "version": "2.0.3", "resolved": "https://registry.npmjs.org/is-weakset/-/is-weakset-2.0.3.tgz", "integrity": "sha512-LvIm3/KWzS9oRFHugab7d+M/GcBXuXX5xZkzPmN+NxihdQlZUQ4dWuSV1xR/sq6upL1TJEDrfBgRepHFdBtSNQ==", - "dev": true, "dependencies": { "call-bind": "^1.0.7", "get-intrinsic": "^1.2.4" @@ -7825,8 +7868,7 @@ "node_modules/isarray": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==", - "dev": true + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==" }, "node_modules/isexe": { "version": "2.0.0", @@ -8246,6 +8288,12 @@ "node": "*" } }, + "node_modules/monaco-editor": { + "version": "0.49.0", + "resolved": "https://registry.npmjs.org/monaco-editor/-/monaco-editor-0.49.0.tgz", + "integrity": "sha512-2I8/T3X/hLxB2oPHgqcNYUVdA/ZEFShT7IAujifIPMfKkNbLOqY8XCoyHCXrsdjb36dW9MwoTwBCFpXKMwNwaQ==", + "peer": true + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", @@ -8376,7 +8424,6 @@ "version": "1.13.1", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.13.1.tgz", "integrity": "sha512-5qoj1RUiKOMsCCNLV1CBiPYE10sziTsnmNxkAI/rZhiD63CF7IqdFGC/XzjWjpSgLf0LxXX3bDFIh0E18f6UhQ==", - "dev": true, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -8385,7 +8432,6 @@ "version": "1.1.6", "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.1.6.tgz", "integrity": "sha512-F8cZ+KfGlSGi09lJT7/Nd6KJZ9ygtvYC0/UYYLI9nmQKLMnydpB9yvbv9K1uSkEu7FU9vYPmVwLg328tX+ot3Q==", - "dev": true, "dependencies": { "call-bind": "^1.0.7", "define-properties": "^1.2.1" @@ -8401,7 +8447,6 @@ "version": "1.1.1", "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==", - "dev": true, "engines": { "node": ">= 0.4" } @@ -8410,7 +8455,6 @@ "version": "4.1.5", "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.5.tgz", "integrity": "sha512-byy+U7gp+FVwmyzKPYhW2h5l3crpmGsxl7X2s8y43IgxvG4g3QZ6CffDtsNQy1WsmZpQbO+ybo0AlW7TY6DcBQ==", - "dev": true, "dependencies": { "call-bind": "^1.0.5", "define-properties": "^1.2.1", @@ -8753,7 +8797,6 @@ "version": "1.0.0", "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", "integrity": "sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==", - "dev": true, "engines": { "node": ">= 0.4" } @@ -9803,7 +9846,6 @@ "version": "1.5.2", "resolved": "https://registry.npmjs.org/regexp.prototype.flags/-/regexp.prototype.flags-1.5.2.tgz", "integrity": "sha512-NcDiDkTLuPR+++OCKB0nWafEmhg/Da8aUPLPMQbK+bxKKCm1/S5he+AqYa4PlMCVBalb4/yxIRub6qkEx5yJbw==", - "dev": true, "dependencies": { "call-bind": "^1.0.6", "define-properties": "^1.2.1", @@ -10146,7 +10188,6 @@ "version": "1.2.2", "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", - "dev": true, "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -10163,7 +10204,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/set-function-name/-/set-function-name-2.0.2.tgz", "integrity": "sha512-7PGFlmtwsEADb0WYyvCMa1t+yke6daIG4Wirafur5kcf+MhUnPms1UeR0CKQdTZD81yESwMHbtn+TR+dMviakQ==", - "dev": true, "dependencies": { "define-data-property": "^1.1.4", "es-errors": "^1.3.0", @@ -10217,7 +10257,6 @@ "version": "1.0.6", "resolved": "https://registry.npmjs.org/side-channel/-/side-channel-1.0.6.tgz", "integrity": "sha512-fDW/EZ6Q9RiO8eFG8Hj+7u/oW+XrPTIChwCOM2+th2A6OblDtYYIpve9m+KvI9Z4C9qSEXlaGR6bTEYHReuglA==", - "dev": true, "dependencies": { "call-bind": "^1.0.7", "es-errors": "^1.3.0", @@ -10338,6 +10377,22 @@ "deprecated": "Please use @jridgewell/sourcemap-codec instead", "dev": true }, + "node_modules/state-local": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/state-local/-/state-local-1.0.7.tgz", + "integrity": "sha512-HTEHMNieakEnoe33shBYcZ7NX83ACUjCu8c40iOGEZsngj9zRnkqS9j1pqQPXwobB0ZcVTk27REb7COQ0UR59w==" + }, + "node_modules/stop-iteration-iterator": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/stop-iteration-iterator/-/stop-iteration-iterator-1.0.0.tgz", + "integrity": "sha512-iCGQj+0l0HOdZ2AEeBADlsRC+vsnDsZsbdSiH1yNSjcfKM7fdpCMfqAL/dwF5BLiw/XhRft/Wax6zQbhq2BcjQ==", + "dependencies": { + "internal-slot": "^1.0.4" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/stream-browserify": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/stream-browserify/-/stream-browserify-3.0.0.tgz", @@ -11002,6 +11057,18 @@ "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, + "node_modules/uuid": { + "version": "10.0.0", + "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", + "integrity": "sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==", + "funding": [ + "https://github.com/sponsors/broofa", + "https://github.com/sponsors/ctavan" + ], + "bin": { + "uuid": "dist/bin/uuid" + } + }, "node_modules/vinyl": { "version": "2.2.1", "resolved": "https://registry.npmjs.org/vinyl/-/vinyl-2.2.1.tgz", @@ -11215,7 +11282,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/which-boxed-primitive/-/which-boxed-primitive-1.0.2.tgz", "integrity": "sha512-bwZdv0AKLpplFY2KZRX6TvyuN7ojjr7lwkg6ml0roIy9YeuSr7JS372qlNW18UQYzgYK9ziGcerWqZOmEn9VNg==", - "dev": true, "dependencies": { "is-bigint": "^1.0.1", "is-boolean-object": "^1.1.0", @@ -11257,7 +11323,6 @@ "version": "1.0.2", "resolved": "https://registry.npmjs.org/which-collection/-/which-collection-1.0.2.tgz", "integrity": "sha512-K4jVyjnBdgvc86Y6BkaLZEN933SwYOuBFkdmBu9ZfkcAbdVbpITnDmjvZ/aQjRXQrv5EPkTnD1s39GiiqbngCw==", - "dev": true, "dependencies": { "is-map": "^2.0.3", "is-set": "^2.0.3", @@ -11275,7 +11340,6 @@ "version": "1.1.15", "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.15.tgz", "integrity": "sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA==", - "dev": true, "dependencies": { "available-typed-arrays": "^1.0.7", "call-bind": "^1.0.7", diff --git a/package.json b/package.json index 8f7b369..7f547ab 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "isp-admin-ui", "private": true, - "version": "0.11.5", + "version": "0.12.0", "type": "module", "scripts": { "start": "vite", @@ -16,6 +16,7 @@ "dependencies": { "@apidevtools/json-schema-ref-parser": "^9.0.6", "@codemirror/lang-json": "^6.0.1", + "@monaco-editor/react": "^4.6.0", "@reduxjs/toolkit": "^2.2.3", "@types/react-router-dom": "^5.3.3", "@uiw/react-codemirror": "^4.21.25", diff --git a/src/components/ActiveConfigurationsTable/active-configurations-table.type.ts b/src/components/ActiveConfigurationsTable/active-configurations-table.type.ts index bc6fd95..5669166 100644 --- a/src/components/ActiveConfigurationsTable/active-configurations-table.type.ts +++ b/src/components/ActiveConfigurationsTable/active-configurations-table.type.ts @@ -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 } diff --git a/src/components/ActiveConfigurationsTable/index.tsx b/src/components/ActiveConfigurationsTable/index.tsx index 0920e17..afdd495 100644 --- a/src/components/ActiveConfigurationsTable/index.tsx +++ b/src/components/ActiveConfigurationsTable/index.tsx @@ -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 = @@ -24,7 +26,8 @@ const ActiveConfigurationsTable: FC = isActiveTable = false, handleShowConfig, handleShowCompareModal, - data + data, + currentModule = {} }) => { const [editKeyConfig, setEditKeyConfig] = useState('') const [tempEditValues, setTempEditValues] = useState() @@ -32,7 +35,8 @@ const ActiveConfigurationsTable: FC = 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 = {!isActiveTable && diff --git a/src/components/ConfigSchemaModal/config-schema-moda.type.ts b/src/components/ConfigSchemaModal/config-schema-moda.type.ts index 3ba81f4..9d73e0e 100644 --- a/src/components/ConfigSchemaModal/config-schema-moda.type.ts +++ b/src/components/ConfigSchemaModal/config-schema-moda.type.ts @@ -5,5 +5,5 @@ import { JSONSchema } from '@pages/ModulesPage/module.type.ts' export interface ConfigSchemaModalPropsType extends Omit { - schema: JSONSchema + schema?: JSONSchema } diff --git a/src/components/ConfigSchemaModal/index.tsx b/src/components/ConfigSchemaModal/index.tsx index 9731076..0735a25 100644 --- a/src/components/ConfigSchemaModal/index.tsx +++ b/src/components/ConfigSchemaModal/index.tsx @@ -7,12 +7,12 @@ import { ConfigSchemaModalPropsType } from '@components/ConfigSchemaModal/config import './config-schema-modal.scss' - const ConfigSchemaModal: FC = ({ open, onClose, - schema + schema = {} }) => { + return (
diff --git a/src/components/ConfigurationEditorCode/index.tsx b/src/components/ConfigurationEditorCode/index.tsx new file mode 100644 index 0000000..891f258 --- /dev/null +++ b/src/components/ConfigurationEditorCode/index.tsx @@ -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 = ({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 ( +
+ +
+ ) +} + +export default ConfigurationEditorCode \ No newline at end of file diff --git a/src/components/ConfigurationEditorForm/index.tsx b/src/components/ConfigurationEditorForm/index.tsx new file mode 100644 index 0000000..5ccd5df --- /dev/null +++ b/src/components/ConfigurationEditorForm/index.tsx @@ -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 = ({ + 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 ( + 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 ( +
+
+
+ ) +} + +export default ConfigurationEditorForm diff --git a/src/components/ConfigurationEditorJson/index.tsx b/src/components/ConfigurationEditorJson/index.tsx new file mode 100644 index 0000000..06974a3 --- /dev/null +++ b/src/components/ConfigurationEditorJson/index.tsx @@ -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 = ({ bufConfig = {}, setBufConfig, isCurrentConfigLoading, JsonSchema}) => { + if (isCurrentConfigLoading) { + return + } + + return ( + { + const newData = { + ...bufConfig, + data: { ...updated_src } + } + setBufConfig(cleanEmptyParamsObject(newData)) + } + } + src={bufConfig.data} + sortKeys={true} + collapsed={1} + /> + ) +} + +export default ConfigurationEditorJson \ No newline at end of file diff --git a/src/components/ConfirmConfigModal/ConfirmConfigModal.tsx b/src/components/ConfirmConfigModal/ConfirmConfigModal.tsx new file mode 100644 index 0000000..e9647ab --- /dev/null +++ b/src/components/ConfirmConfigModal/ConfirmConfigModal.tsx @@ -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 { + handleSaveClick: (upVersion?: number, unsafe?: boolean) => void + setBufConfig: Dispatch> + currentConfig: ConfigType | undefined +} + +const ConfirmConfigModal: FC = ({ + 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 ( + + + + + ) +} +export default ConfirmConfigModal \ No newline at end of file diff --git a/src/components/ErrorConfigModal/ErrorConfigModal.tsx b/src/components/ErrorConfigModal/ErrorConfigModal.tsx new file mode 100644 index 0000000..9b2e5c6 --- /dev/null +++ b/src/components/ErrorConfigModal/ErrorConfigModal.tsx @@ -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 { + details?: { [key: string]: string } +} + +const ErrorConfigModal: FC = ({ details = {}, onClose, open }) => { + + const columns = [ + { + dataIndex: 'key', + key: 'key', + render: (text: string) => {text} + }, + { + dataIndex: 'value', + key: 'value' + } + ] + + const data = Object.keys(details).map((key) => ({ + key, + value: details[key] + })) + + return ( + +
+ + + + ) +} + +export default ErrorConfigModal \ No newline at end of file diff --git a/src/constants/api/apiPaths.ts b/src/constants/api/apiPaths.ts index d3f4eda..30b2540 100644 --- a/src/constants/api/apiPaths.ts +++ b/src/constants/api/apiPaths.ts @@ -52,6 +52,7 @@ type PathKeys = | 'deleteConfig' | 'markConfigAsActive' | 'getUI' + | 'getByModuleId' export const apiPaths: Record = { baseUrl: '/api/kkd-configuration-service', @@ -100,6 +101,7 @@ export const apiPaths: Record = { // ======= MODULES ====== getModules: '/module/get_modules_info', deleteModule: '/module/delete_module', + getByModuleId: '/schema/get_by_module_id', // ======= SERVICE ====== getServiceById: '/service/get_service_by_id', getAllService: '/service/get_service', diff --git a/src/pages/ConfigurationEditorPage/configuration-editor-page.scss b/src/pages/ConfigurationEditorPage/configuration-editor-page.scss new file mode 100644 index 0000000..7a9abec --- /dev/null +++ b/src/pages/ConfigurationEditorPage/configuration-editor-page.scss @@ -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; + } +} \ No newline at end of file diff --git a/src/pages/ConfigurationEditorPage/index.tsx b/src/pages/ConfigurationEditorPage/index.tsx new file mode 100644 index 0000000..ee48a6e --- /dev/null +++ b/src/pages/ConfigurationEditorPage/index.tsx @@ -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> + isCurrentConfigLoading: boolean + setDisableBtn?: Dispatch> +} + +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() + 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 + } + + + const renderContent = () => { + + switch (radioValue) { + // case 'form': + // return ( + // + // ) + case 'json': + return ( + + ) + case 'code': + return ( + + ) + } + } + + + return ( +
+
+ +
+ + { + handleSaveClick() + navigate(`/modules/${moduleId}/configurations`) + }} + disabled={disableBtn} + type="primary" + className="configuration-editor-page__save-btn" + menu={{ items: itemsSaveBtn, onClick: onSaveBtn }} + > + Сохранить и выйти + +
+ +
+
+ + Форма + JSON + Редактор кода + + + {renderContent()} +
+ + + setShowSchemeModal(false)} + /> + + setShowConfirmModal(false)} /> + + setDetailsError({details: {}, isOpenDetailsErrorModal: false })} /> + +
+ ) +} + +export default ConfigurationEditorPage diff --git a/src/pages/ConfigurationsPage/index.tsx b/src/pages/ConfigurationsPage/index.tsx index c0c5e78..5d0cb39 100644 --- a/src/pages/ConfigurationsPage/index.tsx +++ b/src/pages/ConfigurationsPage/index.tsx @@ -101,6 +101,7 @@ const Configurations = () => { { @@ -113,6 +114,7 @@ const Configurations = () => { }} /> { setCurrentConfig(config) diff --git a/src/pages/ModulesPage/index.tsx b/src/pages/ModulesPage/index.tsx index 841b431..d983042 100644 --- a/src/pages/ModulesPage/index.tsx +++ b/src/pages/ModulesPage/index.tsx @@ -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 ( - } color="warning"> - {lastVersion} - - ) + const renderVersion = () => { + if (!isSame && lastVersion) { + return ( + } color="warning"> + {lastVersion} + + ) + } + if (isSame && lastVersion) { + return {lastVersion} + } + return '' } - if (isSame && lastVersion) { - return {lastVersion} - } - return '' - } - return ( - - - - {item.name} - - {renderVersion()} - - - } - description={ -
+ return ( + + + + {item.name} + + {renderVersion()} + +
+ } + description={ +
активные экземпляры: - -
- } - /> -
-
- ) + + + } + /> + + + ) } const renderMainContent = () => { @@ -220,25 +220,26 @@ const ModulesPage = () => { selectedItemId={selectedItemId} setSelectedItemId={setSelectedItemId} /> - { - 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: ( -
{renderMainContent()}
- ) - } - })} - /> + { + 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: ( +
{renderMainContent()}
+ ) + } + })} + /> + ) } diff --git a/src/pages/ModulesPage/module.type.ts b/src/pages/ModulesPage/module.type.ts index 5251ea9..155e4eb 100644 --- a/src/pages/ModulesPage/module.type.ts +++ b/src/pages/ModulesPage/module.type.ts @@ -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[] diff --git a/src/pages/ModulesPage/modules-page.scss b/src/pages/ModulesPage/modules-page.scss index c6d119b..87e2f6a 100644 --- a/src/pages/ModulesPage/modules-page.scss +++ b/src/pages/ModulesPage/modules-page.scss @@ -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 { diff --git a/src/routes/Routers/index.tsx b/src/routes/Routers/index.tsx index eaf6e5b..ab65472 100644 --- a/src/routes/Routers/index.tsx +++ b/src/routes/Routers/index.tsx @@ -4,7 +4,7 @@ import { lazy, Suspense } from 'react' import { Navigate, Route, Routes } from 'react-router-dom' import LayoutComponent from '@components/Layout' - // Составная часть основной страницы, поэтому без lazy +// Составная часть основной страницы, поэтому без lazy import Configurations from '@pages/ConfigurationsPage' import Connections from '@pages/ConnectionsPage' @@ -25,6 +25,8 @@ const AppAccessPage = lazy(() => import('@pages/AppAccessPage')) const ModulesPage = lazy(() => import('@pages/ModulesPage')) const ApplicationsPage = lazy(() => import('@pages/ApplicationsPage')) const AllVersionsPage = lazy(() => import('@pages/AllVersionsPage')) +const ConfigurationEditorPage = lazy( + () => import('@pages/ConfigurationEditorPage')) const Routers = () => { return ( @@ -149,6 +151,14 @@ const Routers = () => { } /> + }> + + + }> + + = { home: '/', @@ -34,5 +35,6 @@ export const routePaths: Record = { application: 'application', connections: 'connections', configurations: 'configurations', - allVersions: ':configId/all_versions' + allVersions: ':configId/all_versions', + configEditor: 'configEditor', } diff --git a/src/services/configService.ts b/src/services/configService.ts index 4930a1d..50084fb 100644 --- a/src/services/configService.ts +++ b/src/services/configService.ts @@ -63,8 +63,8 @@ const configServiceApi = createApi({ invalidatesTags: () => ['versions'] }), deleteConfig: builder.mutation({ - query: (id) => ({ url: apiPaths.deleteVersion, data: [id] }), - invalidatesTags: () => ['versions'] + query: (id) => ({ url: apiPaths.deleteConfig, data: [id] }), + invalidatesTags: () => ['configs'] }), markConfigAsActive: builder.mutation({ query: (id) => ({ url: apiPaths.markConfigAsActive, data: { id } }), diff --git a/src/services/modulesService.ts b/src/services/modulesService.ts index 3fb7392..eee57f5 100644 --- a/src/services/modulesService.ts +++ b/src/services/modulesService.ts @@ -1,15 +1,15 @@ import { createApi } from '@reduxjs/toolkit/query/react' - import { apiPaths } from '@constants/api/apiPaths.ts' -import { ModuleType } from '@pages/ModulesPage/module.type.ts' +import { ModuleType, ResponseSchemaType } from '@pages/ModulesPage/module.type.ts' import { axiosBaseQuery } from '@utils/apiUtils.ts' + const modulesServiceApi = createApi({ reducerPath: 'modulesServiceApi', - refetchOnFocus: true, - tagTypes: ['modules'], + refetchOnFocus: false, + tagTypes: ['modules', 'schema'], baseQuery: axiosBaseQuery({ baseUrl: apiPaths.baseConfigUrl }), endpoints: (builder) => ({ getModules: builder.query({ @@ -22,8 +22,15 @@ const modulesServiceApi = createApi({ data: [id] }), invalidatesTags: ['modules'] - }) + }), + getByModuleId: builder.query({ + query: (moduleId) => ({ + url: apiPaths.getByModuleId, + data: { moduleId } + }), + providesTags: () => ['schema'], + }), }) }) -export default modulesServiceApi +export default modulesServiceApi \ No newline at end of file diff --git a/src/utils/objectUtils.ts b/src/utils/objectUtils.ts index 7ceb023..aa67d89 100644 --- a/src/utils/objectUtils.ts +++ b/src/utils/objectUtils.ts @@ -16,4 +16,36 @@ const sortObject = (obj: any): any => { return sorted } -export { sortObject } +function isEmpty(value: unknown): boolean { + return value === undefined || + value === null || + (typeof value === 'string' && value.trim() === '') || + (typeof value === 'object' && !Array.isArray(value) && Object.keys(value).length === 0) +} + +function cleanEmptyParamsObject(obj: any): any { + if (typeof obj !== 'object' || obj === null) { + return obj + } + + if (Array.isArray(obj)) { + return obj + .map(cleanEmptyParamsObject) + .filter(item => !isEmpty(item)) + } + + return Object.keys(obj).reduce((acc, key) => { + if (key === 'data') { + acc[key] = obj[key] + } else { + const value = cleanEmptyParamsObject(obj[key]) + if (!isEmpty(value)) { + acc[key] = value + } + } + return acc + }, {} as Record) +} + + +export { sortObject, cleanEmptyParamsObject } diff --git a/src/widgets/ActiveTableActionButtons/index.tsx b/src/widgets/ActiveTableActionButtons/index.tsx index c7e70dd..d797f76 100644 --- a/src/widgets/ActiveTableActionButtons/index.tsx +++ b/src/widgets/ActiveTableActionButtons/index.tsx @@ -15,6 +15,7 @@ import { ActiveTableActionButtonsPropsType } from './active-table-action-buttons import './active-table-action-buttons.scss' import CanEdit from '@components/CanEdit' +import { routePaths } from '@routes/routePaths.ts' const ActiveTableActionButtons: FC = ({ @@ -99,7 +100,9 @@ const ActiveTableActionButtons: FC = -