feat: add support for allowedOwners at the BitbucketRepoPicker
Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder': minor
|
||||
---
|
||||
|
||||
Add support for `allowedOwners` to the `BitbucketRepoPicker` used for the workspace value.
|
||||
@@ -19,6 +19,21 @@ import { BitbucketRepoPicker } from './BitbucketRepoPicker';
|
||||
import { render, fireEvent } from '@testing-library/react';
|
||||
|
||||
describe('BitbucketRepoPicker', () => {
|
||||
it('renders a select if there is a list of allowed owners', async () => {
|
||||
const allowedOwners = ['owner1', 'owner2'];
|
||||
const { findByText } = render(
|
||||
<BitbucketRepoPicker
|
||||
onChange={jest.fn()}
|
||||
rawErrors={[]}
|
||||
state={{ host: 'bitbucket.org', repoName: 'repo' }}
|
||||
allowedOwners={allowedOwners}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(await findByText('owner1')).toBeInTheDocument();
|
||||
expect(await findByText('owner2')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('renders workspace input when host is bitbucket.org', () => {
|
||||
const state = { host: 'bitbucket.org', workspace: 'lolsWorkspace' };
|
||||
|
||||
|
||||
@@ -18,15 +18,20 @@ import FormControl from '@material-ui/core/FormControl';
|
||||
import FormHelperText from '@material-ui/core/FormHelperText';
|
||||
import Input from '@material-ui/core/Input';
|
||||
import InputLabel from '@material-ui/core/InputLabel';
|
||||
import { Select, SelectItem } from '@backstage/core-components';
|
||||
import { RepoUrlPickerState } from './types';
|
||||
|
||||
export const BitbucketRepoPicker = (props: {
|
||||
allowedOwners?: string[];
|
||||
onChange: (state: RepoUrlPickerState) => void;
|
||||
state: RepoUrlPickerState;
|
||||
rawErrors: string[];
|
||||
}) => {
|
||||
const { onChange, rawErrors, state } = props;
|
||||
const { allowedOwners = [], onChange, rawErrors, state } = props;
|
||||
const { host, workspace, project } = state;
|
||||
const ownerItems: SelectItem[] = allowedOwners
|
||||
? allowedOwners?.map(i => ({ label: i, value: i }))
|
||||
: [];
|
||||
return (
|
||||
<>
|
||||
{host === 'bitbucket.org' && (
|
||||
@@ -35,12 +40,27 @@ export const BitbucketRepoPicker = (props: {
|
||||
required
|
||||
error={rawErrors?.length > 0 && !workspace}
|
||||
>
|
||||
<InputLabel htmlFor="workspaceInput">Workspace</InputLabel>
|
||||
<Input
|
||||
id="workspaceInput"
|
||||
onChange={e => onChange({ workspace: e.target.value })}
|
||||
value={workspace}
|
||||
/>
|
||||
{allowedOwners?.length ? (
|
||||
<Select
|
||||
native
|
||||
label="Allowed Workspaces"
|
||||
onChange={s =>
|
||||
onChange({ workspace: String(Array.isArray(s) ? s[0] : s) })
|
||||
}
|
||||
disabled={allowedOwners.length === 1}
|
||||
selected={workspace}
|
||||
items={ownerItems}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<InputLabel htmlFor="workspaceInput">Workspace</InputLabel>
|
||||
<Input
|
||||
id="workspaceInput"
|
||||
onChange={e => onChange({ workspace: e.target.value })}
|
||||
value={workspace}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<FormHelperText>
|
||||
The Organization that this repo will belong to
|
||||
</FormHelperText>
|
||||
|
||||
@@ -171,6 +171,7 @@ export const RepoUrlPicker = (
|
||||
)}
|
||||
{hostType === 'bitbucket' && (
|
||||
<BitbucketRepoPicker
|
||||
allowedOwners={allowedOwners}
|
||||
rawErrors={rawErrors}
|
||||
state={state}
|
||||
onChange={updateLocalState}
|
||||
|
||||
Reference in New Issue
Block a user