diff --git a/changelogs/fragments/8574.yml b/changelogs/fragments/8574.yml new file mode 100644 index 000000000000..72c73d09947a --- /dev/null +++ b/changelogs/fragments/8574.yml @@ -0,0 +1,2 @@ +feat: +- [Workspace]Show add collaborators modal until collaborators added ([#8574](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8574)) \ No newline at end of file diff --git a/src/plugins/workspace/public/components/add_collaborators_modal/add_collaborators_modal.test.tsx b/src/plugins/workspace/public/components/add_collaborators_modal/add_collaborators_modal.test.tsx index 3cf1c9203760..80cbc4f09c7e 100644 --- a/src/plugins/workspace/public/components/add_collaborators_modal/add_collaborators_modal.test.tsx +++ b/src/plugins/workspace/public/components/add_collaborators_modal/add_collaborators_modal.test.tsx @@ -76,4 +76,28 @@ describe('AddCollaboratorsModal', () => { expect(screen.getByText(instruction.detail)).toBeInTheDocument(); expect(screen.getByText('Learn more in Documentation')).toBeInTheDocument(); }); + + it('should disable "Add collaborators" button during onAddCollaborators execution', async () => { + const onAddCollaboratorsMock = jest.fn().mockReturnValue( + new Promise((resolve) => { + window.setTimeout(resolve, 1000); + }) + ); + render(); + const collaboratorInput = screen.getByLabelText(defaultProps.inputLabel); + fireEvent.change(collaboratorInput, { target: { value: 'user1' } }); + const addCollaboratorsButton = screen.getByRole('button', { name: 'Add collaborators' }); + + jest.useFakeTimers(); + fireEvent.click(addCollaboratorsButton); + await waitFor(() => { + expect(addCollaboratorsButton).toBeDisabled(); + }); + jest.runAllTimers(); + jest.useRealTimers(); + + await waitFor(() => { + expect(addCollaboratorsButton).not.toBeDisabled(); + }); + }); }); diff --git a/src/plugins/workspace/public/components/add_collaborators_modal/add_collaborators_modal.tsx b/src/plugins/workspace/public/components/add_collaborators_modal/add_collaborators_modal.tsx index 48ba9c62ed7d..e75524faca1b 100644 --- a/src/plugins/workspace/public/components/add_collaborators_modal/add_collaborators_modal.tsx +++ b/src/plugins/workspace/public/components/add_collaborators_modal/add_collaborators_modal.tsx @@ -64,9 +64,15 @@ export const AddCollaboratorsModal = ({ } return { collaboratorId, accessLevel, permissionType }; }); + const [isAdding, setIsAdding] = useState(false); - const handleAddCollaborators = () => { - onAddCollaborators(validCollaborators); + const handleAddCollaborators = async () => { + setIsAdding(true); + try { + await onAddCollaborators(validCollaborators); + } finally { + setIsAdding(false); + } }; return ( @@ -131,6 +137,8 @@ export const AddCollaboratorsModal = ({ type="submit" onClick={handleAddCollaborators} fill + isDisabled={isAdding} + isLoading={isAdding} > {i18n.translate('workspace.addCollaboratorsModal.addCollaboratorsButton', { defaultMessage: 'Add collaborators', diff --git a/src/plugins/workspace/public/components/workspace_form/add_collaborator_button.tsx b/src/plugins/workspace/public/components/workspace_form/add_collaborator_button.tsx index c7360d173e02..195f92d98a28 100644 --- a/src/plugins/workspace/public/components/workspace_form/add_collaborator_button.tsx +++ b/src/plugins/workspace/public/components/workspace_form/add_collaborator_button.tsx @@ -23,7 +23,9 @@ import { WorkspacePermissionSetting } from './types'; interface Props { displayedTypes: WorkspaceCollaboratorType[]; permissionSettings: PermissionSetting[]; - handleSubmitPermissionSettings: (permissionSettings: WorkspacePermissionSetting[]) => void; + handleSubmitPermissionSettings: ( + permissionSettings: WorkspacePermissionSetting[] + ) => Promise; } export const AddCollaboratorButton = ({ @@ -55,7 +57,7 @@ export const AddCollaboratorButton = ({ }), })); const newPermissionSettings = [...permissionSettings, ...addedSettings]; - handleSubmitPermissionSettings(newPermissionSettings as WorkspacePermissionSetting[]); + await handleSubmitPermissionSettings(newPermissionSettings as WorkspacePermissionSetting[]); }; const panelItems = displayedTypes.map(({ id, buttonLabel, onAdd }) => ({ diff --git a/src/plugins/workspace/public/components/workspace_form/workspace_collaborator_table.tsx b/src/plugins/workspace/public/components/workspace_form/workspace_collaborator_table.tsx index f87ee2e894c5..2f95df1b5816 100644 --- a/src/plugins/workspace/public/components/workspace_form/workspace_collaborator_table.tsx +++ b/src/plugins/workspace/public/components/workspace_form/workspace_collaborator_table.tsx @@ -74,7 +74,9 @@ export const getDisplayedType = ( interface Props { permissionSettings: PermissionSetting[]; displayedCollaboratorTypes: WorkspaceCollaboratorType[]; - handleSubmitPermissionSettings: (permissionSettings: WorkspacePermissionSetting[]) => void; + handleSubmitPermissionSettings: ( + permissionSettings: WorkspacePermissionSetting[] + ) => Promise; } export const WorkspaceCollaboratorTable = ({ diff --git a/src/plugins/workspace/public/components/workspace_form/workspace_form_context.tsx b/src/plugins/workspace/public/components/workspace_form/workspace_form_context.tsx index 0ec3bffebc77..45d77f7aef5f 100644 --- a/src/plugins/workspace/public/components/workspace_form/workspace_form_context.tsx +++ b/src/plugins/workspace/public/components/workspace_form/workspace_form_context.tsx @@ -32,7 +32,9 @@ interface WorkspaceFormContextProps { >; setSelectedDataSourceConnections: React.Dispatch>; onAppLeave: AppMountParameters['onAppLeave']; - handleSubmitPermissionSettings: (permissionSettings: WorkspacePermissionSetting[]) => void; + handleSubmitPermissionSettings: ( + permissionSettings: WorkspacePermissionSetting[] + ) => Promise; } const initialContextValue: WorkspaceFormContextProps = {} as WorkspaceFormContextProps;