Merge pull request #24798 from vinisdl/repo-url-picker-azure-project
Change owner to project for azure host
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder': patch
|
||||
---
|
||||
|
||||
Change owner to project for azure host
|
||||
@@ -44,18 +44,18 @@ describe('AzureRepoPicker', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('owner field', () => {
|
||||
it('calls onChange when the owner changes', () => {
|
||||
describe('project field', () => {
|
||||
it('calls onChange when the project changes', () => {
|
||||
const onChange = jest.fn();
|
||||
const { getAllByRole } = render(
|
||||
<AzureRepoPicker onChange={onChange} rawErrors={[]} state={{}} />,
|
||||
);
|
||||
|
||||
const ownerInput = getAllByRole('textbox')[1];
|
||||
const projectInput = getAllByRole('textbox')[1];
|
||||
|
||||
fireEvent.change(ownerInput, { target: { value: 'owner' } });
|
||||
fireEvent.change(projectInput, { target: { value: 'project' } });
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith({ owner: 'owner' });
|
||||
expect(onChange).toHaveBeenCalledWith({ project: 'project' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -24,14 +24,14 @@ import { Select, SelectItem } from '@backstage/core-components';
|
||||
|
||||
export const AzureRepoPicker = (props: {
|
||||
allowedOrganizations?: string[];
|
||||
allowedOwners?: string[];
|
||||
allowedProject?: string[];
|
||||
rawErrors: string[];
|
||||
state: RepoUrlPickerState;
|
||||
onChange: (state: RepoUrlPickerState) => void;
|
||||
}) => {
|
||||
const {
|
||||
allowedOrganizations = [],
|
||||
allowedOwners = [],
|
||||
allowedProject = [],
|
||||
rawErrors,
|
||||
state,
|
||||
onChange,
|
||||
@@ -41,11 +41,11 @@ export const AzureRepoPicker = (props: {
|
||||
? allowedOrganizations.map(i => ({ label: i, value: i }))
|
||||
: [{ label: 'Loading...', value: 'loading' }];
|
||||
|
||||
const ownerItems: SelectItem[] = allowedOwners
|
||||
? allowedOwners.map(i => ({ label: i, value: i }))
|
||||
const projectItems: SelectItem[] = allowedProject
|
||||
? allowedProject.map(i => ({ label: i, value: i }))
|
||||
: [{ label: 'Loading...', value: 'loading' }];
|
||||
|
||||
const { organization, owner } = state;
|
||||
const { organization, project } = state;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -82,26 +82,26 @@ export const AzureRepoPicker = (props: {
|
||||
<FormControl
|
||||
margin="normal"
|
||||
required
|
||||
error={rawErrors?.length > 0 && !owner}
|
||||
error={rawErrors?.length > 0 && !project}
|
||||
>
|
||||
{allowedOwners?.length ? (
|
||||
{allowedProject?.length ? (
|
||||
<Select
|
||||
native
|
||||
label="Owner"
|
||||
label="Project"
|
||||
onChange={s =>
|
||||
onChange({ owner: String(Array.isArray(s) ? s[0] : s) })
|
||||
onChange({ project: String(Array.isArray(s) ? s[0] : s) })
|
||||
}
|
||||
disabled={allowedOwners.length === 1}
|
||||
selected={owner}
|
||||
items={ownerItems}
|
||||
disabled={allowedProject.length === 1}
|
||||
selected={project}
|
||||
items={projectItems}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<InputLabel htmlFor="ownerInput">Project</InputLabel>
|
||||
<InputLabel htmlFor="projectInput">Project</InputLabel>
|
||||
<Input
|
||||
id="ownerInput"
|
||||
onChange={e => onChange({ owner: e.target.value })}
|
||||
value={owner}
|
||||
id="projectInput"
|
||||
onChange={e => onChange({ project: e.target.value })}
|
||||
value={project}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
@@ -58,6 +58,10 @@ describe('RepoUrlPicker', () => {
|
||||
byHost: () => ({ type: 'github' }),
|
||||
};
|
||||
|
||||
const mockIntegrationsApiAzure: Partial<ScmIntegrationsApi> = {
|
||||
byHost: () => ({ type: 'azure' }),
|
||||
};
|
||||
|
||||
let mockScmAuthApi: Partial<ScmAuthApi>;
|
||||
|
||||
beforeEach(() => {
|
||||
@@ -111,7 +115,7 @@ describe('RepoUrlPicker', () => {
|
||||
const { getByRole } = await renderInTestApp(
|
||||
<TestApiProvider
|
||||
apis={[
|
||||
[scmIntegrationsApiRef, mockIntegrationsApi],
|
||||
[scmIntegrationsApiRef, mockIntegrationsApiAzure],
|
||||
[scmAuthApiRef, {}],
|
||||
[scaffolderApiRef, mockScaffolderApi],
|
||||
]}
|
||||
@@ -137,6 +141,37 @@ describe('RepoUrlPicker', () => {
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render properly with allowedProject', async () => {
|
||||
const { getByRole } = await renderInTestApp(
|
||||
<TestApiProvider
|
||||
apis={[
|
||||
[scmIntegrationsApiRef, mockIntegrationsApiAzure],
|
||||
[scmAuthApiRef, {}],
|
||||
[scaffolderApiRef, mockScaffolderApi],
|
||||
]}
|
||||
>
|
||||
<SecretsContextProvider>
|
||||
<Form
|
||||
validator={validator}
|
||||
schema={{ type: 'string' }}
|
||||
uiSchema={{
|
||||
'ui:field': 'RepoUrlPicker',
|
||||
'ui:options': {
|
||||
allowedHosts: ['dev.azure.com'],
|
||||
allowedProjects: ['Backstage'],
|
||||
},
|
||||
}}
|
||||
fields={{
|
||||
RepoUrlPicker: RepoUrlPicker as ScaffolderRJSFField<string>,
|
||||
}}
|
||||
/>
|
||||
</SecretsContextProvider>
|
||||
</TestApiProvider>,
|
||||
);
|
||||
|
||||
expect(getByRole('option', { name: 'Backstage' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should render properly with title and description', async () => {
|
||||
const { getByText } = await renderInTestApp(
|
||||
<TestApiProvider
|
||||
|
||||
@@ -220,7 +220,7 @@ export const RepoUrlPicker = (props: RepoUrlPickerProps) => {
|
||||
{hostType === 'azure' && (
|
||||
<AzureRepoPicker
|
||||
allowedOrganizations={allowedOrganizations}
|
||||
allowedOwners={allowedOwners}
|
||||
allowedProject={allowedProjects}
|
||||
rawErrors={rawErrors}
|
||||
state={state}
|
||||
onChange={updateLocalState}
|
||||
|
||||
Reference in New Issue
Block a user