@@ -19,7 +19,9 @@ import React, { Fragment } from 'react';
1919import { JsonObject } from '@backstage/types' ;
2020
2121import { UiSchema } from '@rjsf/utils' ;
22- import type { JSONSchema7 } from 'json-schema' ;
22+ import type { JSONSchema7 , JSONSchema7Definition } from 'json-schema' ;
23+ import cloneDeep from 'lodash/cloneDeep' ;
24+ import get from 'lodash/get' ;
2325
2426import { OrchestratorFormContextProps } from '@red-hat-developer-hub/backstage-plugin-orchestrator-form-api' ;
2527
@@ -51,12 +53,54 @@ export type OrchestratorFormProps = {
5153 isDataReadonly ?: boolean ;
5254} ;
5355
56+ /**
57+ * Remove hidden steps from the schema.
58+ *
59+ * A wizard step is removed when
60+ * "type": "object"
61+ * "ui:widget": "hidden"
62+ * and properties are empty ("properties": {})
63+ *
64+ * @param schema - The schema to remove hidden steps from.
65+ * @returns The schema with hidden steps removed.
66+ */
67+ const removeHiddenSteps = ( schema : JSONSchema7 ) : JSONSchema7 => {
68+ if ( typeof schema . properties === 'object' ) {
69+ const hiddenSteps = Object . entries ( schema . properties )
70+ . map ( ( [ key , value ] : [ string , JSONSchema7Definition ] ) => {
71+ const uiWidget = get ( value , 'ui:widget' ) ;
72+ if (
73+ typeof value !== 'boolean' &&
74+ value . type === 'object' &&
75+ uiWidget === 'hidden' &&
76+ value . properties &&
77+ Object . keys ( value . properties ) . length === 0
78+ ) {
79+ return key ;
80+ }
81+ return undefined ;
82+ } )
83+ . filter ( Boolean ) as string [ ] ;
84+
85+ if ( hiddenSteps . length > 0 ) {
86+ const newSchema = cloneDeep ( schema ) ;
87+ hiddenSteps . forEach ( step => {
88+ delete newSchema . properties ?. [ step ] ;
89+ } ) ;
90+
91+ return newSchema ;
92+ }
93+ }
94+
95+ return schema ;
96+ } ;
97+
5498/**
5599 * @public
56100 * The component contains the react-json-schema-form and serves as an extensible form. It allows loading a custom plugin decorator to override the default react-json-schema-form properties.
57101 */
58102const OrchestratorForm = ( {
59- schema,
103+ schema : rawSchema ,
60104 updateSchema,
61105 handleExecute,
62106 isExecuting,
@@ -69,6 +113,8 @@ const OrchestratorForm = ({
69113 initialFormData ? ( ) => structuredClone ( initialFormData ) : { } ,
70114 ) ;
71115
116+ const schema = React . useMemo ( ( ) => removeHiddenSteps ( rawSchema ) , [ rawSchema ] ) ;
117+
72118 const numStepsInMultiStepSchema = React . useMemo (
73119 ( ) => getNumSteps ( schema ) ,
74120 [ schema ] ,
0 commit comments