Skip to content

Commit

Permalink
[Bug][Workspace]Fix page display errors and add loading status (opens…
Browse files Browse the repository at this point in the history
…earch-project#8086)

* Fix page display errors and add loading status

Signed-off-by: yubonluo <[email protected]>

* Changeset file for PR opensearch-project#8086 created/updated

* optimize the code

Signed-off-by: yubonluo <[email protected]>

---------

Signed-off-by: yubonluo <[email protected]>
Co-authored-by: opensearch-changeset-bot[bot] <154024398+opensearch-changeset-bot[bot]@users.noreply.github.com>
  • Loading branch information
yubonluo and opensearch-changeset-bot[bot] authored Sep 10, 2024
1 parent 9f76399 commit af2b2d4
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 13 deletions.
2 changes: 2 additions & 0 deletions changelogs/fragments/8086.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fix:
- [Workspace]Fix page display errors and add loading status ([#8086](https://github.com/opensearch-project/OpenSearch-Dashboards/pull/8086))
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const defaultProps = {
numberOfChanges: 2,
numberOfErrors: 1,
handleResetForm: mockHandleResetForm,
isFormSubmitting: false,
};

describe('WorkspaceBottomBar', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ interface WorkspaceBottomBarProps {
numberOfChanges: number;
numberOfErrors: number;
handleResetForm: () => void;
isFormSubmitting: boolean;
}

export const WorkspaceBottomBar = ({
formId,
numberOfChanges,
numberOfErrors,
handleResetForm,
isFormSubmitting,
}: WorkspaceBottomBarProps) => {
const applicationElement = document.querySelector('.app-wrapper');
const bottomBar = (
Expand Down Expand Up @@ -82,6 +84,7 @@ export const WorkspaceBottomBar = ({
fill
color="primary"
data-test-subj="workspaceForm-bottomBar-updateButton"
isLoading={isFormSubmitting}
>
{i18n.translate('workspace.form.bottomBar.saveChanges', {
defaultMessage: 'Save changes',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {

export interface WorkspaceDetailProps {
registeredUseCases$: BehaviorSubject<WorkspaceUseCase[]>;
isFormSubmitting: boolean;
}

export const WorkspaceDetail = (props: WorkspaceDetailProps) => {
Expand Down Expand Up @@ -292,6 +293,7 @@ export const WorkspaceDetail = (props: WorkspaceDetailProps) => {
numberOfChanges={numberOfChanges}
numberOfErrors={numberOfErrors}
handleResetForm={handleResetForm}
isFormSubmitting={props.isFormSubmitting}
/>
)}
</>
Expand Down
11 changes: 9 additions & 2 deletions src/plugins/workspace/public/components/workspace_detail_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export const WorkspaceDetailApp = (props: WorkspaceDetailProps) => {
const currentWorkspace = useObservable(workspaces ? workspaces.currentWorkspace$ : of(null));
const availableUseCases = useObservable(props.registeredUseCases$, []);
const isPermissionEnabled = application?.capabilities.workspaces.permissionEnabled;
const [isFormSubmitting, setIsFormSubmitting] = useState(false);

/**
* set breadcrumbs to chrome
Expand Down Expand Up @@ -105,6 +106,9 @@ export const WorkspaceDetailApp = (props: WorkspaceDetailProps) => {
const handleWorkspaceFormSubmit = useCallback(
async (data: WorkspaceFormSubmitData) => {
let result;
if (isFormSubmitting) {
return;
}
if (!currentWorkspace) {
notifications?.toasts.addDanger({
title: i18n.translate('Cannot find current workspace', {
Expand All @@ -113,6 +117,7 @@ export const WorkspaceDetailApp = (props: WorkspaceDetailProps) => {
});
return;
}
setIsFormSubmitting(true);

try {
const { permissionSettings, selectedDataSourceConnections, ...attributes } = data;
Expand Down Expand Up @@ -158,9 +163,11 @@ export const WorkspaceDetailApp = (props: WorkspaceDetailProps) => {
text: error instanceof Error ? error.message : JSON.stringify(error),
});
return;
} finally {
setIsFormSubmitting(false);
}
},
[notifications?.toasts, currentWorkspace, http, application, workspaceClient]
[isFormSubmitting, currentWorkspace, notifications?.toasts, workspaceClient, application, http]
);

if (!workspaces || !application || !http || !savedObjects || !currentWorkspaceFormData) {
Expand All @@ -178,7 +185,7 @@ export const WorkspaceDetailApp = (props: WorkspaceDetailProps) => {
availableUseCases={availableUseCases}
>
<I18nProvider>
<WorkspaceDetail {...props} />
<WorkspaceDetail {...props} isFormSubmitting={isFormSubmitting} />
</I18nProvider>
</WorkspaceFormProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export const DataSourceConnectionTable = ({
itemIdToExpandedRowMap={itemIdToExpandedRowMap}
isExpandable={true}
selection={selection}
className="workspace-detail-direct-query-table"
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -182,17 +182,19 @@ export const WorkspacePermissionSettingPanel = ({
</React.Fragment>
))}
{isEditing && (
<EuiSmallButton
fullWidth={false}
onClick={handleAddNewOne}
data-test-subj={`workspaceForm-permissionSettingPanel-addNew`}
color="primary"
iconType="plusInCircle"
>
{i18n.translate('workspace.form.permissionSettingPanel.addCollaborator', {
defaultMessage: 'Add collaborator',
})}
</EuiSmallButton>
<EuiCompressedFormRow fullWidth>
<EuiSmallButton
fullWidth={false}
onClick={handleAddNewOne}
data-test-subj={`workspaceForm-permissionSettingPanel-addNew`}
color="primary"
iconType="plusInCircle"
>
{i18n.translate('workspace.form.permissionSettingPanel.addCollaborator', {
defaultMessage: 'Add collaborator',
})}
</EuiSmallButton>
</EuiCompressedFormRow>
)}
</>
);
Expand Down

0 comments on commit af2b2d4

Please sign in to comment.