feat: ui:disabled allowed in GithubRepoPicker

Signed-off-by: Nikunj Hudka <nikunjhudka123@gmail.com>
This commit is contained in:
Nikunj Hudka
2025-02-23 23:06:32 -04:00
parent 9695c9e29b
commit 6c840fe9c7
2 changed files with 45 additions and 2 deletions
@@ -170,4 +170,38 @@ describe('GithubRepoPicker', () => {
);
});
});
describe('GithubRepoPicker - isDisabled', () => {
it('disables all inputs when isDisabled is true', async () => {
const { getByLabelText } = await renderInTestApp(
<TestApiProvider apis={[[scaffolderApiRef, scaffolderApiMock]]}>
<GithubRepoPicker
onChange={jest.fn()}
rawErrors={[]}
state={{ repoName: 'repo' }}
isDisabled
/>
</TestApiProvider>,
);
const ownerInput = getByLabelText(/owner/i);
expect(ownerInput).toBeDisabled();
});
it('does not disable inputs when isDisabled is false', async () => {
const { getByLabelText } = await renderInTestApp(
<TestApiProvider apis={[[scaffolderApiRef, scaffolderApiMock]]}>
<GithubRepoPicker
onChange={jest.fn()}
rawErrors={[]}
state={{ repoName: 'repo' }}
isDisabled={false}
/>
</TestApiProvider>,
);
const ownerInput = getByLabelText(/owner/i);
expect(ownerInput).not.toBeDisabled();
});
});
});
@@ -34,7 +34,14 @@ export const GithubRepoPicker = (
accessToken?: string;
}>,
) => {
const { allowedOwners = [], rawErrors, state, onChange, accessToken } = props;
const {
allowedOwners = [],
rawErrors,
state,
onChange,
accessToken,
isDisabled,
} = props;
const { t } = useTranslationRef(scaffolderTranslationRef);
const ownerItems: SelectItem[] = allowedOwners
? allowedOwners.map(i => ({ label: i, value: i }))
@@ -110,7 +117,7 @@ export const GithubRepoPicker = (
onChange={s =>
onChange({ owner: String(Array.isArray(s) ? s[0] : s) })
}
disabled={allowedOwners.length === 1}
disabled={isDisabled || allowedOwners.length === 1}
selected={owner}
items={ownerItems}
/>
@@ -126,10 +133,12 @@ export const GithubRepoPicker = (
<TextField
{...params}
label={t('fields.githubRepoPicker.owner.inputTitle')}
disabled={isDisabled}
required
/>
)}
freeSolo
disabled={isDisabled}
autoSelect
/>
)}