Skip to content

Commit

Permalink
feat: update create workspace page UI and implement unit tests (opens…
Browse files Browse the repository at this point in the history
…earch-project#226)

* ui update: workspace create page

Signed-off-by: yuye-aws <[email protected]>

* implement cancel button and wrap string with i18n

Signed-off-by: yuye-aws <[email protected]>

* eslint fix

Signed-off-by: yuye-aws <[email protected]>

* breadcrumb bug fix

Signed-off-by: yuye-aws <[email protected]>

* workspace create unit tests

Signed-off-by: yuye-aws <[email protected]>

* bug fix

Signed-off-by: yuye-aws <[email protected]>

* update bread crumbs for workspace create page

Signed-off-by: yuye-aws <[email protected]>

* udpate test case

Signed-off-by: yuye-aws <[email protected]>

* optimize create page ui

Signed-off-by: yuye-aws <[email protected]>

* update test file

Signed-off-by: yuye-aws <[email protected]>

* change library category definition

Signed-off-by: yuye-aws <[email protected]>

* remove key definition

Signed-off-by: yuye-aws <[email protected]>

* change default permission type to Read

Signed-off-by: yuye-aws <[email protected]>

* refactor bottom bar and cancel modal into components

Signed-off-by: yuye-aws <[email protected]>

* declare consts outside functional components

Signed-off-by: yuye-aws <[email protected]>

* remove key definition

Signed-off-by: yuye-aws <[email protected]>

* refactor bottom bar and cancel model

Signed-off-by: yuye-aws <[email protected]>

* Update src/plugins/workspace/public/components/workspace_updater/workspace_updater.tsx

Co-authored-by: SuZhou-Joe <[email protected]>

* Update src/plugins/workspace/public/components/workspace_creator/workspace_permission_setting_panel.tsx

Co-authored-by: SuZhou-Joe <[email protected]>

* Update src/plugins/workspace/public/components/workspace_creator/workspace_permission_setting_panel.tsx

Co-authored-by: SuZhou-Joe <[email protected]>

* wrap string with i18n

Signed-off-by: yuye-aws <[email protected]>

* reimplement tab selection to enum

Signed-off-by: yuye-aws <[email protected]>

* fix data-test-subj duplicate bug

Signed-off-by: yuye-aws <[email protected]>

* update tests and id

Signed-off-by: yuye-aws <[email protected]>

* update UI

Signed-off-by: yuye-aws <[email protected]>

* track the number of errors

Signed-off-by: yuye-aws <[email protected]>

* add test cases

Signed-off-by: yuye-aws <[email protected]>

* resolve conflicts

Signed-off-by: yuye-aws <[email protected]>

* hide permission section when workspace permission is not enabled

Signed-off-by: yuye-aws <[email protected]>

* sort permissions decreasingly

Signed-off-by: yuye-aws <[email protected]>

* update test file

Signed-off-by: yuye-aws <[email protected]>

* feat: remove some error and optimize mock

Signed-off-by: SuZhou-Joe <[email protected]>

* feat: update

Signed-off-by: SuZhou-Joe <[email protected]>

* update test file

Signed-off-by: yuye-aws <[email protected]>

* refactor with EuiTab

Signed-off-by: yuye-aws <[email protected]>

* remove sort logic

Signed-off-by: yuye-aws <[email protected]>

* remove unused import

Signed-off-by: yuye-aws <[email protected]>

---------

Signed-off-by: yuye-aws <[email protected]>
Signed-off-by: SuZhou-Joe <[email protected]>
Co-authored-by: SuZhou-Joe <[email protected]>
  • Loading branch information
yuye-aws and SuZhou-Joe authored Oct 17, 2023
1 parent 7a72a73 commit f00cb3c
Show file tree
Hide file tree
Showing 12 changed files with 847 additions and 229 deletions.
12 changes: 0 additions & 12 deletions src/plugins/workspace/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { i18n } from '@osd/i18n';
import { AppCategory } from '../../../core/types';

export const WORKSPACE_CREATE_APP_ID = 'workspace_create';
export const WORKSPACE_LIST_APP_ID = 'workspace_list';
export const WORKSPACE_UPDATE_APP_ID = 'workspace_update';
Expand All @@ -22,12 +19,3 @@ export const PATHS = {
export const WORKSPACE_OP_TYPE_CREATE = 'create';
export const WORKSPACE_OP_TYPE_UPDATE = 'update';
export const WORKSPACE_SAVED_OBJECTS_CLIENT_WRAPPER_ID = 'workspace';

export const WORKSPACE_NAV_CATEGORY: AppCategory = {
id: 'workspace',
label: i18n.translate('core.ui.workspaceNavList.label', {
defaultMessage: 'Workspaces',
}),
euiIconType: 'folderClosed',
order: 2000,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import {
EuiBottomBar,
EuiButton,
EuiButtonEmpty,
EuiFlexGroup,
EuiFlexItem,
EuiSpacer,
EuiText,
} from '@elastic/eui';
import { i18n } from '@osd/i18n';
import React, { useState } from 'react';
import { ApplicationStart } from 'opensearch-dashboards/public';
import { WORKSPACE_OP_TYPE_CREATE, WORKSPACE_OP_TYPE_UPDATE } from '../../../common/constants';
import { WorkspaceCancelModal } from './workspace_cancel_modal';

interface WorkspaceBottomBarProps {
formId: string;
opType?: string;
numberOfErrors: number;
application: ApplicationStart;
}

// Number of saved changes will be implemented in workspace update page PR
export const WorkspaceBottomBar = ({
formId,
opType,
numberOfErrors,
application,
}: WorkspaceBottomBarProps) => {
const [isCancelModalVisible, setIsCancelModalVisible] = useState(false);
const closeCancelModal = () => setIsCancelModalVisible(false);
const showCancelModal = () => setIsCancelModalVisible(true);

return (
<div>
<EuiSpacer size="xl" />
<EuiSpacer size="xl" />
<EuiBottomBar>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize="s">
{opType === WORKSPACE_OP_TYPE_UPDATE ? (
<EuiText textAlign="left">
{i18n.translate('workspace.form.bottomBar.unsavedChanges', {
defaultMessage: '1 Unsaved change(s)',
})}
</EuiText>
) : (
<EuiText textAlign="left">
{i18n.translate('workspace.form.bottomBar.errors', {
defaultMessage: `${numberOfErrors} Error(s)`,
})}
</EuiText>
)}
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiFlexGroup gutterSize="m">
<EuiButtonEmpty
color="ghost"
onClick={showCancelModal}
data-test-subj="workspaceForm-bottomBar-cancelButton"
>
{i18n.translate('workspace.form.bottomBar.cancel', {
defaultMessage: 'Cancel',
})}
</EuiButtonEmpty>
<EuiSpacer />
{opType === WORKSPACE_OP_TYPE_CREATE && (
<EuiButton
fill
type="submit"
color="primary"
form={formId}
data-test-subj="workspaceForm-bottomBar-createButton"
>
{i18n.translate('workspace.form.bottomBar.createWorkspace', {
defaultMessage: 'Create workspace',
})}
</EuiButton>
)}
{opType === WORKSPACE_OP_TYPE_UPDATE && (
<EuiButton form={formId} type="submit" fill color="primary">
{i18n.translate('workspace.form.bottomBar.saveChanges', {
defaultMessage: 'Save changes',
})}
</EuiButton>
)}
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
</EuiBottomBar>
<WorkspaceCancelModal
application={application}
visible={isCancelModalVisible}
closeCancelModal={closeCancelModal}
/>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { i18n } from '@osd/i18n';
import { EuiConfirmModal } from '@elastic/eui';
import { ApplicationStart } from 'opensearch-dashboards/public';
import { WORKSPACE_LIST_APP_ID } from '../../../common/constants';

interface WorkspaceCancelModalProps {
visible: boolean;
application: ApplicationStart;
closeCancelModal: () => void;
}

export const WorkspaceCancelModal = ({
application,
visible,
closeCancelModal,
}: WorkspaceCancelModalProps) => {
if (!visible) {
return null;
}

return (
<EuiConfirmModal
data-test-subj="workspaceForm-cancelModal"
title={i18n.translate('workspace.form.cancelModal.title', {
defaultMessage: 'Discard changes?',
})}
onCancel={closeCancelModal}
onConfirm={() => application?.navigateToApp(WORKSPACE_LIST_APP_ID)}
cancelButtonText={i18n.translate('workspace.form.cancelButtonText.', {
defaultMessage: 'Continue editing',
})}
confirmButtonText={i18n.translate('workspace.form.confirmButtonText.', {
defaultMessage: 'Discard changes',
})}
buttonColor="danger"
defaultFocusedButton="confirm"
>
{i18n.translate('workspace.form.cancelModal.body', {
defaultMessage: 'This will discard all changes. Are you sure?',
})}
</EuiConfirmModal>
);
};
Loading

0 comments on commit f00cb3c

Please sign in to comment.