config-schema: switch schema type and separate out SchemaViewer

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-04-05 18:27:59 +02:00
parent e75795ac0f
commit 079b3e025b
6 changed files with 51 additions and 13 deletions
+2 -2
View File
@@ -14,11 +14,11 @@
* limitations under the License.
*/
import { JsonObject } from '@backstage/config';
import { createApiRef, Observable } from '@backstage/core';
import { Schema } from 'jsonschema';
export interface ConfigSchemaResult {
schema?: JsonObject;
schema?: Schema;
}
export interface ConfigSchemaApi {
@@ -22,17 +22,17 @@ import {
ContentHeader,
HeaderLabel,
SupportButton,
CodeSnippet,
useApi,
} from '@backstage/core';
import { useObservable } from 'react-use';
import { configSchemaApiRef } from '../../api';
import { SchemaViewer } from '../SchemaViewer';
export const ConfigSchemaPage = () => {
const configSchemaApi = useApi(configSchemaApiRef);
const schema = useObservable(
useMemo(() => configSchemaApi.schema$(), [configSchemaApi]),
);
)?.schema;
return (
<Page themeId="tool">
@@ -46,14 +46,7 @@ export const ConfigSchemaPage = () => {
</ContentHeader>
<Grid container spacing={3} direction="column">
<Grid item>
{schema ? (
<CodeSnippet
language="json"
text={JSON.stringify(schema, null, 2)}
/>
) : (
'No schema available'
)}
{schema ? <SchemaViewer schema={schema} /> : 'No schema available'}
</Grid>
</Grid>
</Content>
@@ -0,0 +1,26 @@
/*
* Copyright 2021 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import React from 'react';
import { CodeSnippet } from '@backstage/core';
import { Schema } from 'jsonschema';
export interface SchemaViewerProps {
schema: Schema;
}
export const SchemaViewer = ({ schema }: SchemaViewerProps) => {
return <CodeSnippet language="json" text={JSON.stringify(schema, null, 2)} />;
};
@@ -0,0 +1,17 @@
/*
* Copyright 2021 Spotify AB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
export { SchemaViewer } from './SchemaViewer';