@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* Copyright 2022 The Backstage Authors
|
||||
*
|
||||
* 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 { extractSchemaFromManifest } from './schema';
|
||||
|
||||
describe('schema utils', () => {
|
||||
it('should do stuff', () => {
|
||||
const inputSchema = {
|
||||
type: 'object',
|
||||
'ui:welp': 'warp',
|
||||
properties: {
|
||||
field1: {
|
||||
type: 'string',
|
||||
'ui:derp': 'herp',
|
||||
},
|
||||
field2: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
fieldX: {
|
||||
type: 'string',
|
||||
'ui:derp': 'xerp',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const expectedSchema = {
|
||||
type: 'object',
|
||||
properties: {
|
||||
field1: {
|
||||
type: 'string',
|
||||
},
|
||||
field2: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
fieldX: {
|
||||
type: 'string',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const expectedUiSchema = {
|
||||
'ui:welp': 'warp',
|
||||
field1: {
|
||||
'ui:derp': 'herp',
|
||||
},
|
||||
field2: {
|
||||
fieldX: {
|
||||
'ui:derp': 'xerp',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
expect(
|
||||
extractSchemaFromManifest({
|
||||
title: 'test',
|
||||
steps: [{ title: 'test', schema: inputSchema }],
|
||||
}),
|
||||
).toEqual({
|
||||
schema: expectedSchema,
|
||||
uiSchema: expectedUiSchema,
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -13,3 +13,27 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import { UiSchema } from '@rjsf/core';
|
||||
import { JSONSchema7 } from 'json-schema';
|
||||
|
||||
import { TemplateParameterSchema } from '../../../types';
|
||||
|
||||
export const extractSchemaFromManifest = (
|
||||
manifest: TemplateParameterSchema,
|
||||
): { uiSchema: UiSchema; schema: JSONSchema7 } => {
|
||||
const schema = manifest.steps[0].schema;
|
||||
const uiSchema = JSON.parse(JSON.stringify(schema), (key, value) => {
|
||||
if (typeof value === 'object') {
|
||||
return Object.fromEntries(
|
||||
Object.entries(value).filter(
|
||||
([k, v]) => k.startsWith('ui:') || typeof v === 'object',
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return value;
|
||||
});
|
||||
|
||||
console.log(uiSchema);
|
||||
return { uiSchema, schema: {} };
|
||||
};
|
||||
|
||||
@@ -90,7 +90,7 @@ export const TemplateWizardPage = (_props: TemplateWizardPageProps) => {
|
||||
noPadding
|
||||
titleTypographyProps={{ component: 'h2' }}
|
||||
>
|
||||
<Stepper manifest={manifest} />
|
||||
<Stepper manifest={manifest} fields={{}} widgets={{}} />
|
||||
</InfoCard>
|
||||
)}
|
||||
</Content>
|
||||
|
||||
Reference in New Issue
Block a user