From b548f02fbf6995140a10551fc6b7b4b3151c92f8 Mon Sep 17 00:00:00 2001 From: blam Date: Fri, 15 Dec 2023 09:42:32 +0100 Subject: [PATCH] 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,