From b548f02fbf6995140a10551fc6b7b4b3151c92f8 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 15 Dec 2023 09:42:32 +0100 Subject: [PATCH 1/2] chore: fix a bug that properties is set to empty object when it should not be present when parsing template schema Signed-off-by: blam --- .../src/next/hooks/useTemplateSchema.test.tsx | 1 - .../src/next/hooks/useTemplateSchema.ts | 27 ++++++++++++------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.test.tsx b/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.test.tsx index d2771b2eb9..ac55d73a04 100644 --- a/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.test.tsx +++ b/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.test.tsx @@ -263,7 +263,6 @@ describe('useTemplateSchema', () => { expect(first.schema).toEqual({ type: 'object', - properties: {}, }); }); }); diff --git a/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.ts b/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.ts index 838f8b1c30..aa5cefbaec 100644 --- a/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.ts +++ b/plugins/scaffolder-react/src/next/hooks/useTemplateSchema.ts @@ -59,13 +59,18 @@ export const useTemplateSchema = ( return stepFeatureFlag ? featureFlags.isActive(stepFeatureFlag) : true; }) // Then filter out the properties that are not enabled with feature flag - .map(step => ({ - ...step, - schema: { - ...step.schema, - // Title is rendered at the top of the page, so let's ignore this from jsonschemaform - title: undefined, - properties: Object.fromEntries( + .map(step => { + const strippedSchema = { + ...step, + schema: { + ...step.schema, + // Title is rendered at the top of the page, so let's ignore this from jsonschemaform + title: undefined, + }, + } as ParsedTemplateSchema; + + if (step.schema?.properties) { + strippedSchema.schema.properties = Object.fromEntries( Object.entries((step.schema?.properties ?? []) as JsonObject).filter( ([key]) => { const stepFeatureFlag = @@ -75,9 +80,11 @@ export const useTemplateSchema = ( : true; }, ), - ), - }, - })); + ); + } + + return strippedSchema; + }); return { presentation: manifest.presentation, From 670c7ccde56d7730d502b6e1ad55b1fda6c6081b Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 15 Dec 2023 09:43:54 +0100 Subject: [PATCH 2/2] chore: add changeset Signed-off-by: blam --- .changeset/empty-poets-camp.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/empty-poets-camp.md diff --git a/.changeset/empty-poets-camp.md b/.changeset/empty-poets-camp.md new file mode 100644 index 0000000000..3e5e410ea1 --- /dev/null +++ b/.changeset/empty-poets-camp.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder-react': patch +--- + +Fix bug where `properties` is set to empty object when it should be empty for schema dependencies