Skip to content

Commit

Permalink
feat: navigate to workspace create page after button clicked (opensea…
Browse files Browse the repository at this point in the history
…rch-project#23)

Signed-off-by: Lin Wang <wonglam@amazon.com>
  • Loading branch information
wanglam authored and SuZhou-Joe committed Aug 31, 2023
1 parent 8c62430 commit 6fbd54d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import React, { useState, useCallback, useMemo, useEffect } from 'react';
import { EuiButton, EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';
import useObservable from 'react-use/lib/useObservable';
import { CoreStart, WorkspaceAttribute } from '../../../../../core/public';
import { WORKSPACE_APP_ID, PATHS } from '../../../common/constants';

type WorkspaceOption = EuiComboBoxOptionOption<WorkspaceAttribute>;

interface WorkspaceDropdownListProps {
coreStart: CoreStart;
onCreateWorkspace: () => void;
onSwitchWorkspace: (workspaceId: string) => Promise<void>;
}

Expand All @@ -22,7 +22,7 @@ function workspaceToOption(workspace: WorkspaceAttribute): WorkspaceOption {
}

export function WorkspaceDropdownList(props: WorkspaceDropdownListProps) {
const { coreStart, onCreateWorkspace, onSwitchWorkspace } = props;
const { coreStart, onSwitchWorkspace } = props;
const workspaceList = useObservable(coreStart.workspaces.client.workspaceList$, []);
const currentWorkspaceId = useObservable(coreStart.workspaces.client.currentWorkspaceId$, '');

Expand Down Expand Up @@ -62,6 +62,10 @@ export function WorkspaceDropdownList(props: WorkspaceDropdownListProps) {
});
};

const onCreateWorkspaceClick = () => {
coreStart.application.navigateToApp(WORKSPACE_APP_ID, { path: PATHS.create });
};

useEffect(() => {
onSearchChange('');
}, [onSearchChange]);
Expand All @@ -76,7 +80,7 @@ export function WorkspaceDropdownList(props: WorkspaceDropdownListProps) {
selectedOptions={currentWorkspaceOption}
singleSelection={{ asPlainText: true }}
onSearchChange={onSearchChange}
append={<EuiButton onClick={onCreateWorkspace}>Create workspace</EuiButton>}
append={<EuiButton onClick={onCreateWorkspaceClick}>Create workspace</EuiButton>}
/>
</>
);
Expand Down
1 change: 0 additions & 1 deletion src/plugins/workspace/public/mount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export const mountDropdownList = (core: CoreStart) => {
ReactDOM.render(
<WorkspaceDropdownList
coreStart={core}
onCreateWorkspace={() => alert('create')}
onSwitchWorkspace={async (id: string) => {
await new Promise((resolve) => setTimeout(resolve, 1000));
alert(`switch to workspace ${id}`);
Expand Down

0 comments on commit 6fbd54d

Please sign in to comment.