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

+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