Skip to content

Commit 8b1ce63

Browse files
Prune obsolete properties from form data before Review and Submit (#1706)
1 parent 149804f commit 8b1ce63

File tree

6 files changed

+875
-4
lines changed

6 files changed

+875
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
'@red-hat-developer-hub/backstage-plugin-orchestrator-form-react': minor
3+
---
4+
5+
Prune obsolete properties from form data before Review and Submit
6+
7+
- Update `OrchestratorForm` to prune form data before passing to Review step and execution
8+
- Fixes issue where SchemaUpdater dynamically adds/removes fields but old values remain in form state
9+
- Ensures only properties that exist in the final schema version are displayed on Review page and submitted
10+
- Prevents stale data from previous schema versions from being included in workflow execution

workspaces/orchestrator/plugins/orchestrator-form-react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
"@types/json-schema": "7.0.15",
5656
"@types/lodash": "^4.14.151",
5757
"@types/react": "^18.2.58",
58+
"json-schema": "^0.4.0",
5859
"prettier": "3.6.2",
5960
"react": "^16.13.1 || ^17.0.0 || ^18.0.0",
6061
"react-dom": "^16.13.1 || ^17.0.0 || ^18.0.0",

workspaces/orchestrator/plugins/orchestrator-form-react/src/components/OrchestratorForm.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { OrchestratorFormContextProps } from '@red-hat-developer-hub/backstage-p
2727

2828
import { TranslationFunction } from '../hooks/useTranslation';
2929
import generateUiSchema from '../utils/generateUiSchema';
30+
import { pruneFormData } from '../utils/pruneFormData';
3031
import { StepperContextProvider } from '../utils/StepperContext';
3132
import OrchestratorFormWrapper from './OrchestratorFormWrapper';
3233
import ReviewStep from './ReviewStep';
@@ -136,9 +137,16 @@ const OrchestratorForm = ({
136137
);
137138
const isMultiStep = numStepsInMultiStepSchema !== undefined;
138139

140+
// Prune form data to remove properties that no longer exist in the schema
141+
// This handles the case where SchemaUpdater dynamically adds/removes fields
142+
const prunedFormData = useMemo(() => {
143+
return pruneFormData(formData, schema);
144+
}, [formData, schema]);
145+
139146
const _handleExecute = useCallback(() => {
140-
handleExecute(formData);
141-
}, [formData, handleExecute]);
147+
// Use pruned data for execution to avoid submitting stale properties
148+
handleExecute(prunedFormData);
149+
}, [prunedFormData, handleExecute]);
142150

143151
const onSubmit = useCallback(
144152
(_formData: JsonObject) => {
@@ -154,14 +162,14 @@ const OrchestratorForm = ({
154162
const reviewStep = useMemo(
155163
() => (
156164
<ReviewStep
157-
data={formData}
165+
data={prunedFormData}
158166
schema={schema}
159167
busy={isExecuting}
160168
handleExecute={_handleExecute}
161169
// no schema update here
162170
/>
163171
),
164-
[formData, schema, isExecuting, _handleExecute],
172+
[prunedFormData, schema, isExecuting, _handleExecute],
165173
);
166174

167175
return (

0 commit comments

Comments
 (0)