Skip to content

Commit

Permalink
tweaks types
Browse files Browse the repository at this point in the history
Signed-off-by: Yulong Ruan <[email protected]>
  • Loading branch information
ruanyl committed Mar 7, 2024
1 parent be7391b commit fa55b40
Showing 1 changed file with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ import {
WORKSPACE_OVERVIEW_APP_ID,
} from '../../../common/constants';
import { cleanWorkspaceId, formatUrlWithWorkspaceId } from '../../../../../core/public/utils';
import { CoreStart, WorkspaceAttribute } from '../../../../../core/public';
import { CoreStart, WorkspaceObject } from '../../../../../core/public';

interface Props {
coreStart: CoreStart;
}

function getFilteredWorkspaceList(
workspaceList: WorkspaceAttribute[],
currentWorkspace: WorkspaceAttribute | null
): WorkspaceAttribute[] {
workspaceList: WorkspaceObject[],
currentWorkspace: WorkspaceObject | null
): WorkspaceObject[] {
// list top5 workspaces and place the current workspace at the top
return [
...(currentWorkspace ? [currentWorkspace] : []),
Expand All @@ -56,15 +56,15 @@ export const WorkspaceMenu = ({ coreStart }: Props) => {
const filteredWorkspaceList = getFilteredWorkspaceList(workspaceList, currentWorkspace);
const currentWorkspaceName = currentWorkspace?.name ?? defaultHeaderName;

const onButtonClick = () => {
const openPopover = () => {
setPopover(!isPopoverOpen);
};

const closePopover = () => {
setPopover(false);
};

const workspaceToItem = (workspace: WorkspaceAttribute, index: number) => {
const workspaceToItem = (workspace: WorkspaceObject) => {
const workspaceURL = formatUrlWithWorkspaceId(
coreStart.application.getUrlForApp(WORKSPACE_OVERVIEW_APP_ID, {
absolute: false,
Expand All @@ -73,7 +73,7 @@ export const WorkspaceMenu = ({ coreStart }: Props) => {
coreStart.http.basePath
);
const name =
currentWorkspace !== null && index === 0 ? (
currentWorkspace?.name === workspace.name ? (
<EuiText>
<strong>{workspace.name}</strong>
</EuiText>
Expand All @@ -92,7 +92,7 @@ export const WorkspaceMenu = ({ coreStart }: Props) => {

const getWorkspaceListItems = () => {
const workspaceListItems: EuiContextMenuPanelItemDescriptor[] = filteredWorkspaceList.map(
(workspace, index) => workspaceToItem(workspace, index)
workspaceToItem
);
workspaceListItems.push({
icon: <EuiIcon type="plus" />,
Expand Down Expand Up @@ -135,10 +135,10 @@ export const WorkspaceMenu = ({ coreStart }: Props) => {
<EuiListGroupItem
iconType="spacesApp"
label={currentWorkspaceName}
onClick={onButtonClick}
onClick={openPopover}
extraAction={{
color: 'subdued',
onClick: onButtonClick,
onClick: openPopover,
iconType: isPopoverOpen ? 'arrowDown' : 'arrowRight',
iconSize: 's',
'aria-label': 'Show workspace dropdown selector',
Expand Down Expand Up @@ -175,6 +175,7 @@ export const WorkspaceMenu = ({ coreStart }: Props) => {
return (
<EuiPopover
id="contextMenuExample"
display="block"
button={currentWorkspaceButton}
isOpen={isPopoverOpen}
closePopover={closePopover}
Expand Down

0 comments on commit fa55b40

Please sign in to comment.