From cd6d2320104dab80b0a74305b683e88af0ef62fd Mon Sep 17 00:00:00 2001 From: Nikunj Hudka Date: Sun, 23 Feb 2025 23:07:27 -0400 Subject: [PATCH] feat: ui:disabled allowed in RepoUrlPicker Signed-off-by: Nikunj Hudka --- .../RepoUrlPicker/RepoUrlPicker.test.tsx | 30 +++++++++++++++++++ .../fields/RepoUrlPicker/RepoUrlPicker.tsx | 13 +++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.test.tsx b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.test.tsx index 163f397857..2d612f317d 100644 --- a/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.test.tsx +++ b/plugins/scaffolder/src/components/fields/RepoUrlPicker/RepoUrlPicker.test.tsx @@ -119,6 +119,36 @@ describe('RepoUrlPicker', () => { ); }); + it('should disable the picker when ui:disabled', async () => { + const onSubmit = jest.fn(); + const { getAllByRole } = await renderInTestApp( + + +
, + }} + onSubmit={onSubmit} + /> + + , + ); + + const [ownerInput, repoInput] = getAllByRole('textbox'); + + expect(ownerInput).toBeDisabled(); + expect(repoInput).toBeDisabled(); + }); + it('should render properly with allowedHosts', async () => { const { getByRole } = await renderInTestApp( uiSchema?.['ui:options']?.allowedRepos ?? [], [uiSchema], ); - + const isDisabled = useMemo( + () => uiSchema?.['ui:disabled'] ?? false, + [uiSchema], + ); const { owner, organization, project, repoName } = state; useEffect(() => { @@ -179,6 +182,7 @@ export const RepoUrlPicker = ( hosts={allowedHosts} onChange={host => setState(prevState => ({ ...prevState, host }))} rawErrors={rawErrors} + isDisabled={isDisabled} /> {hostType === 'github' && ( )} @@ -207,6 +213,7 @@ export const RepoUrlPicker = ( rawErrors={rawErrors} state={state} onChange={updateLocalState} + isDisabled={isDisabled} accessToken={ uiSchema?.['ui:options']?.requestUserCredentials?.secretsKey && secrets[uiSchema['ui:options'].requestUserCredentials.secretsKey] @@ -220,6 +227,7 @@ export const RepoUrlPicker = ( rawErrors={rawErrors} state={state} onChange={updateLocalState} + isDisabled={isDisabled} accessToken={ uiSchema?.['ui:options']?.requestUserCredentials?.secretsKey && secrets[uiSchema['ui:options'].requestUserCredentials.secretsKey] @@ -232,6 +240,7 @@ export const RepoUrlPicker = ( allowedProject={allowedProjects} rawErrors={rawErrors} state={state} + isDisabled={isDisabled} onChange={updateLocalState} /> )} @@ -240,6 +249,7 @@ export const RepoUrlPicker = ( rawErrors={rawErrors} state={state} onChange={updateLocalState} + isDisabled={isDisabled} /> )}