resolveStepLayout function
Signed-off-by: Paul Cowan <paul.cowan@cutting.scot>
This commit is contained in:
@@ -36,7 +36,6 @@ import { transformSchemaToProps } from './schema';
|
||||
import { Content, StructuredMetadataTable } from '@backstage/core-components';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import * as fieldOverrides from './FieldOverrides';
|
||||
import { DEFAULT_SCAFFOLDER_LAYOUT, LayoutOptions } from '../../layouts';
|
||||
|
||||
const Form = withTheme(MuiTheme);
|
||||
type Step = {
|
||||
@@ -196,19 +195,7 @@ export const MultistepJsonForm = (props: Props) => {
|
||||
{steps.map(({ title, schema, ...formProps }, index) => {
|
||||
const schemaProps = transformSchemaToProps(schema);
|
||||
|
||||
const layoutName =
|
||||
schemaProps.uiSchema?.['ui:ObjectFieldTemplate'] ??
|
||||
DEFAULT_SCAFFOLDER_LAYOUT.name;
|
||||
|
||||
delete schemaProps.uiSchema?.['ui:ObjectFieldTemplate'];
|
||||
|
||||
const LayoutComponent = layouts.find(
|
||||
layout => layout.name === layoutName,
|
||||
)?.component;
|
||||
|
||||
if (!LayoutComponent) {
|
||||
throw new Error(`no step layout found for ${layoutName}`);
|
||||
}
|
||||
const Layout = resolveStepLayout(schemaProps.uiSchema, layouts);
|
||||
|
||||
return (
|
||||
<StepUI key={title}>
|
||||
@@ -223,7 +210,7 @@ export const MultistepJsonForm = (props: Props) => {
|
||||
</StepLabel>
|
||||
<StepContent key={title}>
|
||||
<Form
|
||||
ObjectFieldTemplate={LayoutComponent}
|
||||
ObjectFieldTemplate={Layout}
|
||||
showErrorList={false}
|
||||
fields={{ ...fieldOverrides, ...fields }}
|
||||
widgets={widgets}
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
*/
|
||||
|
||||
import { attachComponentData, Extension } from '@backstage/core-plugin-api';
|
||||
import type { LayoutOptions } from './types';
|
||||
import { UiSchema } from '@rjsf/core';
|
||||
import { DEFAULT_SCAFFOLDER_LAYOUT } from './default';
|
||||
import type { LayoutOptions, ObjectFieldTemplate } from './types';
|
||||
|
||||
export const LAYOUTS_KEY = 'scaffolder.layout.v1';
|
||||
export const LAYOUTS_WRAPPER_KEY = 'scaffolder.layouts.wrapper.v1';
|
||||
@@ -47,3 +49,23 @@ attachComponentData(ScaffolderLayouts, LAYOUTS_WRAPPER_KEY, true);
|
||||
export type { LayoutOptions, ObjectFieldTemplate } from './types';
|
||||
|
||||
export { DEFAULT_SCAFFOLDER_LAYOUT } from './default';
|
||||
|
||||
export function resolveStepLayout(
|
||||
uiSchema: UiSchema = {},
|
||||
layouts: LayoutOptions[],
|
||||
): ObjectFieldTemplate {
|
||||
const layoutName =
|
||||
uiSchema?.['ui:ObjectFieldTemplate'] ?? DEFAULT_SCAFFOLDER_LAYOUT.name;
|
||||
|
||||
delete uiSchema?.['ui:ObjectFieldTemplate'];
|
||||
|
||||
const LayoutComponent = layouts.find(
|
||||
layout => layout.name === layoutName,
|
||||
)?.component;
|
||||
|
||||
if (!LayoutComponent) {
|
||||
throw new Error(`no step layout found for ${layoutName}`);
|
||||
}
|
||||
|
||||
return LayoutComponent;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user