diff --git a/plugins/scaffolder-react/alpha-api-report.md b/plugins/scaffolder-react/alpha-api-report.md index 78205460ac..d5a3ca3cdc 100644 --- a/plugins/scaffolder-react/alpha-api-report.md +++ b/plugins/scaffolder-react/alpha-api-report.md @@ -291,7 +291,7 @@ export interface TemplateGroupsProps { } // @alpha -export const useFeatureFlaggedProperties: ( +export const useFilteredSchemaProperties: ( manifest: TemplateParameterSchema | undefined, ) => { steps: { diff --git a/plugins/scaffolder-react/src/next/components/Workflow/Workflow.tsx b/plugins/scaffolder-react/src/next/components/Workflow/Workflow.tsx index c10b4e081e..0554e76cf6 100644 --- a/plugins/scaffolder-react/src/next/components/Workflow/Workflow.tsx +++ b/plugins/scaffolder-react/src/next/components/Workflow/Workflow.tsx @@ -27,8 +27,9 @@ import { errorApiRef, useApi } from '@backstage/core-plugin-api'; import { useTemplateParameterSchema } from '../../hooks/useTemplateParameterSchema'; import { Stepper, type StepperProps } from '../Stepper/Stepper'; import { SecretsContextProvider } from '../../../secrets/SecretsContext'; -import { ReviewStepProps } from '@backstage/plugin-scaffolder-react'; -import { useFeatureFlaggedProperties } from '../../hooks/useFeatureFlaggedProperties'; + +import { useFilteredSchemaProperties } from '../../hooks/useFilteredSchemaProperties'; +import { ReviewStepProps } from '../../../components'; const useStyles = makeStyles(() => ({ markdown: { @@ -82,7 +83,7 @@ export const Workflow = (workflowProps: WorkflowProps): JSX.Element | null => { const { loading, manifest, error } = useTemplateParameterSchema(templateRef); - const sortedManifest = useFeatureFlaggedProperties(manifest); + const sortedManifest = useFilteredSchemaProperties(manifest); useEffect(() => { if (error) { diff --git a/plugins/scaffolder-react/src/next/hooks/index.ts b/plugins/scaffolder-react/src/next/hooks/index.ts index 9e192c143f..63f8cda4e9 100644 --- a/plugins/scaffolder-react/src/next/hooks/index.ts +++ b/plugins/scaffolder-react/src/next/hooks/index.ts @@ -19,4 +19,4 @@ export { type ParsedTemplateSchema, } from './useTemplateSchema'; export { useTemplateParameterSchema } from './useTemplateParameterSchema'; -export { useFeatureFlaggedProperties } from './useFeatureFlaggedProperties'; +export { useFilteredSchemaProperties } from './useFilteredSchemaProperties'; diff --git a/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx b/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx new file mode 100644 index 0000000000..d5f4b6e477 --- /dev/null +++ b/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.test.tsx @@ -0,0 +1,86 @@ +/* + * Copyright 2023 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import React from 'react'; +import { renderHook } from '@testing-library/react-hooks'; +import { TestApiProvider } from '@backstage/test-utils'; +import { useFilteredSchemaProperties } from './useFilteredSchemaProperties'; +import { TemplateParameterSchema } from '../../types'; + +describe('useFilteredSchemaProperties', () => { + it('should hide "Fill in some steps" from steps of template', () => { + const manifest: TemplateParameterSchema = { + title: 'Test Action template', + description: 'scaffolder v1beta3 template demo', + steps: [ + { + title: 'Fill in some steps', + schema: { + type: 'object', + 'backstage:featureFlag': 'experimental-feature', + properties: { + name: { + description: 'Unique name of the component', + title: 'Name', + type: 'string', + 'ui:autofocus': true, + }, + }, + }, + }, + { + title: 'Choose a location', + schema: { + type: 'object', + properties: { + repoUrl: { + type: 'string', + title: 'Repository Location', + 'ui:field': 'RepoUrlPicker', + }, + }, + }, + }, + ], + }; + + const sortedManifest = renderHook(() => + useFilteredSchemaProperties(manifest), + ); + + const expectedManifest: TemplateParameterSchema = { + title: 'Test Action template', + description: 'scaffolder v1beta3 template demo', + steps: [ + { + title: 'Choose a location', + schema: { + type: 'object', + properties: { + repoUrl: { + type: 'string', + title: 'Repository Location', + 'ui:field': 'RepoUrlPicker', + }, + }, + }, + }, + ], + }; + + expect(sortedManifest).toEqual(expectedManifest); + }); +}); diff --git a/plugins/scaffolder-react/src/next/hooks/useFeatureFlaggedProperties.ts b/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.ts similarity index 98% rename from plugins/scaffolder-react/src/next/hooks/useFeatureFlaggedProperties.ts rename to plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.ts index ae1a6d9c67..9c351348dc 100644 --- a/plugins/scaffolder-react/src/next/hooks/useFeatureFlaggedProperties.ts +++ b/plugins/scaffolder-react/src/next/hooks/useFilteredSchemaProperties.ts @@ -22,7 +22,7 @@ import { TemplateParameterSchema } from '@backstage/plugin-scaffolder-react'; * @alpha */ -export const useFeatureFlaggedProperties = ( +export const useFilteredSchemaProperties = ( manifest: TemplateParameterSchema | undefined, ) => { const featureFlagKey = 'backstage:featureFlag';