MSP-3289 add new json-schema-lib

This commit is contained in:
veselovnk committed 2024-05-20 13:22:52 +03:00
1 parent 358531bead
commit ef8130d352
7 files changed
+1194 -2524

No files matched your search

+1126 -2496
View File
File diff suppressed because it is too large. Load diff
+6 -2
View File
@@ -5,7 +5,7 @@
"type": "module",
"scripts": {
"start": "vite",
"build": "tsc && vite build && node generateVersionFile.cjs",
"build": "vite build && node generateVersionFile.cjs",
"lint": "eslint src --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"fix:prettier": "prettier --write \"src/**/*.{ts,tsx, js}\"",
@@ -14,9 +14,9 @@
"prepare": "husky install"
},
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^9.0.6",
"@codemirror/lang-json": "^6.0.1",
"@reduxjs/toolkit": "^2.2.3",
"@stoplight/json-schema-viewer": "^4.16.0",
"@types/react-router-dom": "^5.3.3",
"@uiw/react-codemirror": "^4.21.25",
"axios": "^1.6.8",
@@ -24,6 +24,8 @@
"compare-versions": "^6.1.0",
"dayjs": "^1.11.10",
"isp-ui-kit": "github:txix-open/isp-ui-kit",
"json-schema-view-js": "^2.0.1",
"lodash.clonedeep": "^4.5.0",
"react": "^18.2.0",
"react-codemirror-merge": "^4.21.25",
"react-dom": "^18.2.0",
@@ -36,6 +38,7 @@
},
"devDependencies": {
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/lodash.clonedeep": "^4.5.9",
"@types/node": "^20.12.4",
"@types/react": "^18.2.74",
"@types/react-dom": "^18.2.24",
@@ -60,6 +63,7 @@
"terser": "^5.30.3",
"typescript": "^5.4.3",
"vite": "^5.2.8",
"vite-plugin-node-polyfills": "^0.21.0",
"vite-plugin-style-import": "^2.0.0",
"vite-plugin-svgr": "^4.2.0",
"vite-tsconfig-paths": "^4.3.2"
+3 -8
View File
@@ -1,12 +1,13 @@
import { JsonSchemaViewer } from '@stoplight/json-schema-viewer'
import { FC } from 'react'
import JsonSchemaViewer from '@widgets/JSONViewer'
import Modal from '@widgets/Modal'
import { ConfigSchemaModalPropsType } from '@components/ConfigSchemaModal/config-schema-moda.type.ts'
import './config-schema-modal.scss'
const ConfigSchemaModal: FC<ConfigSchemaModalPropsType> = ({
open,
onClose,
@@ -15,13 +16,7 @@ const ConfigSchemaModal: FC<ConfigSchemaModalPropsType> = ({
return (
<div className="config-schema-modal">
<Modal title="Текущая схема конфигурации" open={open} onClose={onClose}>
<JsonSchemaViewer
viewMode="view"
className="json-schema-view"
schema={schema}
emptyText="No schema defined"
defaultExpandedDepth={99}
/>
<JsonSchemaViewer schema={schema} />
</Modal>
</div>
)
+1 -2
View File
@@ -1,4 +1,3 @@
import { injectStyles } from '@stoplight/mosaic'
import { Button, Spin } from 'antd'
import { useEffect, useMemo, useState } from 'react'
import { Outlet, useNavigate, useParams } from 'react-router-dom'
@@ -72,7 +71,7 @@ const Configurations = () => {
if (configId) {
return <Outlet />
}
injectStyles()
return (
<section className="configurations">
<ConfigurationPreviewModal
+1 -1
View File
@@ -1,3 +1,3 @@
/// <reference types="vite/client" />
declare const APP_VERSION: string
declare module '@stoplight/json-schema-viewer'
declare module 'json-schema-view-js'
+53
View File
@@ -0,0 +1,53 @@
import RefParser from '@apidevtools/json-schema-ref-parser'
import JSONSchemaView from 'json-schema-view-js'
import cloneDeep from 'lodash.clonedeep'
import React, { useEffect, useRef } from 'react'
import 'json-schema-view-js/dist/style.min.css'
interface JsonSchemaViewerProps {
schema: object
}
const JsonSchemaViewer: React.FC<JsonSchemaViewerProps> = ({ schema }) => {
const myRef = useRef<HTMLDivElement>(null)
useEffect(() => {
const schemas = cloneDeep(schema)
let isMounted = true
RefParser.dereference(
schemas,
{
dereference: {
circular: true
}
},
(err: any, dereferencedSchema: any) => {
if (isMounted) {
if (err) {
console.log(err)
} else {
const view = new JSONSchemaView(dereferencedSchema, 3)
if (myRef.current) {
myRef.current.appendChild(view.render())
}
}
}
}
)
return () => {
isMounted = false
if (myRef.current) {
while (myRef.current.firstChild) {
myRef.current.removeChild(myRef.current.firstChild)
}
}
}
}, [schema])
return <div ref={myRef} />
}
export default JsonSchemaViewer
+4 -15
View File
@@ -1,6 +1,6 @@
import legacy from '@vitejs/plugin-legacy'
import react from '@vitejs/plugin-react'
import { defineConfig, loadEnv } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'
import svgr from 'vite-plugin-svgr'
import tsconfigPaths from 'vite-tsconfig-paths'
@@ -16,22 +16,11 @@ export default defineConfig(({ mode }) => {
APP_VERSION: JSON.stringify(process.env.npm_package_version)
},
build: {
sourcemap:true,
minify: 'terser',
outDir: 'build',
chunkSizeWarningLimit: 1600,
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return id
.toString()
.split('node_modules/')[1]
.split('/')[0]
.toString()
}
}
}
}
commonjsOptions: { transformMixedEsModules: true },
},
server: {
watch: {
@@ -44,6 +33,6 @@ export default defineConfig(({ mode }) => {
'/api': env.PROXY_URL
}
},
plugins: [react(), svgr(), tsconfigPaths()]
plugins: [react(), svgr(), tsconfigPaths(), nodePolyfills()]
}
})