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`. diff --git a/plugins/scaffolder/api-report.md b/plugins/scaffolder/api-report.md index ffa839740e..23b374541b 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[]; diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx index 0246c67801..83f013c8b4 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/AzureRepoPicker.tsx @@ -20,14 +20,33 @@ 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[]; + allowedOwners?: string[]; + rawErrors: string[]; state: RepoUrlPickerState; onChange: (state: RepoUrlPickerState) => void; - rawErrors: string[]; }) => { - const { 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 ( <> 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 + The Organization that this repo will belong to 0 && !owner} > - Owner - onChange({ owner: e.target.value })} - value={owner} - /> - The Owner that this repo will belong to + {allowedOwners?.length ? ( + onChange({ owner: e.target.value })} + value={owner} + /> + + )} + + The Project 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..14fbfcee0b 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,8 @@ export const RepoUrlPicker = ( )} {hostType === 'azure' && (