feat: ui:disabled allowed in RepoUrlPickerHost

Signed-off-by: Nikunj Hudka <nikunjhudka123@gmail.com>
This commit is contained in:
Nikunj Hudka
2025-02-23 23:08:04 -04:00
parent cd6d232010
commit c5d2049c54
2 changed files with 30 additions and 2 deletions
@@ -100,4 +100,31 @@ describe('RepoUrlPickerHostField', () => {
expect(listbox.getAllByRole('option')).toHaveLength(2);
});
it('disables the host select when isDisabled is true', async () => {
const mockOnChange = jest.fn();
const mockScaffolderApi = {
getIntegrationsList: jest.fn().mockResolvedValue({
integrations: [
{ host: 'github.com', title: 'github.com', type: 'github' },
{ host: 'gitlab.com', title: 'gitlab.com', type: 'gitlab' },
],
}),
};
const { getByTestId } = await renderInTestApp(
<TestApiProvider apis={[[scaffolderApiRef, mockScaffolderApi]]}>
<RepoUrlPickerHost
hosts={['github.com', 'gitlab.com']}
onChange={mockOnChange}
rawErrors={[]}
isDisabled
/>
</TestApiProvider>,
);
const selectElement = getByTestId('host-select').querySelector('select');
expect(selectElement).toBeDisabled();
});
});
@@ -28,8 +28,9 @@ export const RepoUrlPickerHost = (props: {
hosts?: string[];
onChange: (host: string) => void;
rawErrors: string[];
isDisabled?: boolean;
}) => {
const { host, hosts, onChange, rawErrors } = props;
const { host, hosts, onChange, rawErrors, isDisabled } = props;
const { t } = useTranslationRef(scaffolderTranslationRef);
const scaffolderApi = useApi(scaffolderApiRef);
@@ -75,7 +76,7 @@ export const RepoUrlPickerHost = (props: {
>
<Select
native
disabled={hosts?.length === 1}
disabled={isDisabled || hosts?.length === 1}
label={t('fields.repoUrlPicker.host.title')}
onChange={s => onChange(String(Array.isArray(s) ? s[0] : s))}
selected={host}