From 6eef5a46315b237b69242cf365586c5875970ee7 Mon Sep 17 00:00:00 2001 From: "Clemens S. Heithecker" Date: Wed, 21 Sep 2022 16:19:29 +0200 Subject: [PATCH 1/7] Add `allowedOrganizations` selector for Azure host Signed-off-by: Clemens S. Heithecker --- .../fields/RepoUrlPicker/AzureRepoPicker.tsx | 38 +++++++++++++++---- .../fields/RepoUrlPicker/RepoUrlPicker.tsx | 15 ++++++++ 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx index 0246c67801..a88120e480 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx @@ -20,14 +20,21 @@ import FormHelperText from '@material-ui/core/FormHelperText'; import Input from '@material-ui/core/Input'; import InputLabel from '@material-ui/core/InputLabel'; import { RepoUrlPickerState } from './types'; +import { Select, SelectItem } from '@backstage/core-components'; export const AzureRepoPicker = (props: { + allowedOrganizations?: string[]; + rawErrors: string[]; state: RepoUrlPickerState; onChange: (state: RepoUrlPickerState) => void; - rawErrors: string[]; }) => { - const { rawErrors, state, onChange } = props; + const { allowedOrganizations = [], rawErrors, state, onChange } = props; + const organizationItems: SelectItem[] = allowedOrganizations + ? allowedOrganizations.map(i => ({ label: i, value: i })) + : [{ label: 'Loading...', value: 'loading' }]; + const { organization, owner } = state; + return ( <> 0 && !organization} > - Organization - onChange({ organization: e.target.value })} - value={organization} - /> + {allowedOrganizations?.length ? ( + onChange({ organization: e.target.value })} + value={organization} + /> + + )} The organization that this repo will belong to diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx index 2214997560..6d0648c751 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx @@ -40,6 +40,7 @@ import { useTemplateSecrets } from '../../secrets'; */ export interface RepoUrlPickerUiOptions { allowedHosts?: string[]; + allowedOrganizations?: string[]; allowedOwners?: string[]; allowedRepos?: string[]; requestUserCredentials?: { @@ -74,6 +75,10 @@ export const RepoUrlPicker = ( () => uiSchema?.['ui:options']?.allowedHosts ?? [], [uiSchema], ); + const allowedOrganizations = useMemo( + () => uiSchema?.['ui:options']?.allowedOrganizations ?? [], + [uiSchema], + ); const allowedOwners = useMemo( () => uiSchema?.['ui:options']?.allowedOwners ?? [], [uiSchema], @@ -88,6 +93,15 @@ export const RepoUrlPicker = ( }, [state, onChange]); /* we deal with calling the repo setting here instead of in each components for ease */ + useEffect(() => { + if (allowedOrganizations.length > 0) { + setState(prevState => ({ + ...prevState, + organization: allowedOrganizations[0], + })); + } + }, [setState, allowedOrganizations]); + useEffect(() => { if (allowedOwners.length > 0) { setState(prevState => ({ @@ -183,6 +197,7 @@ export const RepoUrlPicker = ( )} {hostType === 'azure' && ( Date: Wed, 21 Sep 2022 16:31:21 +0200 Subject: [PATCH 2/7] Add selector for Azure host Signed-off-by: Clemens S. Heithecker --- .../fields/RepoUrlPicker/AzureRepoPicker.tsx | 41 +++++++++++++++---- .../fields/RepoUrlPicker/RepoUrlPicker.tsx | 1 + 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx index a88120e480..c001e8f97f 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx @@ -24,15 +24,27 @@ import { Select, SelectItem } from '@backstage/core-components'; export const AzureRepoPicker = (props: { allowedOrganizations?: string[]; + allowedOwners?: string[]; rawErrors: string[]; state: RepoUrlPickerState; onChange: (state: RepoUrlPickerState) => void; }) => { - const { allowedOrganizations = [], rawErrors, state, onChange } = props; + const { + allowedOrganizations = [], + allowedOwners = [], + rawErrors, + state, + onChange, + } = props; + const organizationItems: SelectItem[] = allowedOrganizations ? allowedOrganizations.map(i => ({ label: i, value: i })) : [{ label: 'Loading...', value: 'loading' }]; + const ownerItems: SelectItem[] = allowedOwners + ? allowedOwners.map(i => ({ label: i, value: i })) + : [{ label: 'Loading...', value: 'loading' }]; + const { organization, owner } = state; return ( @@ -72,12 +84,27 @@ export const AzureRepoPicker = (props: { required error={rawErrors?.length > 0 && !owner} > - Owner - onChange({ owner: e.target.value })} - value={owner} - /> + {allowedOwners?.length ? ( + onChange({ owner: e.target.value })} + value={owner} + /> + + )} The Owner that this repo will belong to diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx index 6d0648c751..14fbfcee0b 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.tsx @@ -198,6 +198,7 @@ export const RepoUrlPicker = ( {hostType === 'azure' && ( Date: Thu, 22 Sep 2022 10:40:40 +0200 Subject: [PATCH 3/7] Change `Owner` to `Project` for Azure host Signed-off-by: Clemens S. Heithecker --- .../src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx index c001e8f97f..cd2882ac24 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx @@ -97,7 +97,7 @@ export const AzureRepoPicker = (props: { /> ) : ( <> - Owner + Project onChange({ owner: e.target.value })} @@ -105,7 +105,9 @@ export const AzureRepoPicker = (props: { /> )} - The Owner that this repo will belong to + + The project that this repo will belong to + ); From 8960d830131e5c97d55be281d8d116eee97b75aa Mon Sep 17 00:00:00 2001 From: "Clemens S. Heithecker" Date: Thu, 22 Sep 2022 11:01:53 +0200 Subject: [PATCH 4/7] Add changeset Signed-off-by: Clemens S. Heithecker --- .changeset/tough-hairs-sparkle.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/tough-hairs-sparkle.md diff --git a/.changeset/tough-hairs-sparkle.md b/.changeset/tough-hairs-sparkle.md new file mode 100644 index 0000000000..404657227b --- /dev/null +++ b/.changeset/tough-hairs-sparkle.md @@ -0,0 +1,5 @@ +--- +'@backstage/plugin-scaffolder': patch +--- + +Add support for `allowedOrganizations` and `allowedOwners` to the `AzureRepoPicker`. From 4132eacfe390af86bf72d3b159dee405c9cf9fa5 Mon Sep 17 00:00:00 2001 From: "Clemens S. Heithecker" Date: Mon, 26 Sep 2022 22:40:24 +0200 Subject: [PATCH 5/7] Update helper text for project selection Signed-off-by: Clemens S. Heithecker --- .../src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx index cd2882ac24..335c285faf 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx @@ -106,7 +106,7 @@ export const AzureRepoPicker = (props: { )} - The project that this repo will belong to + The Project that this repo will belong to From 01d3242b47c57efe5fc62b9d1c539a32a8957eff Mon Sep 17 00:00:00 2001 From: "Clemens S. Heithecker" Date: Mon, 26 Sep 2022 22:47:12 +0200 Subject: [PATCH 6/7] Update helper text for organization selection Signed-off-by: Clemens S. Heithecker --- .../src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx index 335c285faf..83f013c8b4 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx @@ -76,7 +76,7 @@ export const AzureRepoPicker = (props: { )} - The organization that this repo will belong to + The Organization that this repo will belong to Date: Mon, 26 Sep 2022 23:43:25 +0200 Subject: [PATCH 7/7] Update api-report.md Signed-off-by: Clemens S. Heithecker --- plugins/scaffolder/api-report.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/plugins/scaffolder/api-report.md b/plugins/scaffolder/api-report.md index e88d2861a7..cfa34c4d40 100644 --- a/plugins/scaffolder/api-report.md +++ b/plugins/scaffolder/api-report.md @@ -225,6 +225,8 @@ export interface RepoUrlPickerUiOptions { // (undocumented) allowedHosts?: string[]; // (undocumented) + allowedOrganizations?: string[]; + // (undocumented) allowedOwners?: string[]; // (undocumented) allowedRepos?: string[];