Skip to content

Commit 111ea64

Browse files
authored
feat: replace code studio home icon with "Code Studio" as label (#1951)
Fixes #1794 - Label home as "vsTerminal Code Studio" - Make it part of the navtab list to get an active state - Allow navtab list to accept an Icon | JSX.Element
1 parent 9e9e272 commit 111ea64

4 files changed

Lines changed: 37 additions & 22 deletions

File tree

packages/code-studio/src/main/AppInit.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ function AppInit(props: AppInitProps): JSX.Element {
166166
});
167167

168168
const dashboardData = {
169+
title: 'Code Studio',
169170
filterSets: data.filterSets,
170171
links: data.links,
171172
};

packages/code-studio/src/main/AppMainContainer.tsx

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import {
5959
dhPanels,
6060
vsDebugDisconnect,
6161
dhSquareFilled,
62-
vsHome,
62+
vsTerminal,
6363
} from '@deephaven/icons';
6464
import { getVariableDescriptor } from '@deephaven/jsapi-bootstrap';
6565
import dh from '@deephaven/jsapi-shim';
@@ -256,12 +256,12 @@ export class AppMainContainer extends Component<
256256
isSettingsMenuShown: false,
257257
unsavedNotebookCount: 0,
258258
widgets: [],
259-
tabs: Object.entries(allDashboardData)
260-
.filter(([key]) => key !== DEFAULT_DASHBOARD_ID)
261-
.map(([key, value]) => ({
262-
key,
263-
title: value.title ?? 'Untitled',
264-
})),
259+
tabs: Object.entries(allDashboardData).map(([key, value]) => ({
260+
key,
261+
title: value.title ?? 'Untitled',
262+
isClosable: key !== DEFAULT_DASHBOARD_ID,
263+
icon: key === DEFAULT_DASHBOARD_ID ? vsTerminal : undefined,
264+
})),
265265
activeTabKey: DEFAULT_DASHBOARD_ID,
266266
layoutIteration: 0,
267267
};
@@ -856,12 +856,14 @@ export class AppMainContainer extends Component<
856856
layoutConfig: layoutConfig as ItemConfigType[],
857857
key: `${DEFAULT_DASHBOARD_ID}-${layoutIteration}`,
858858
},
859-
...tabs.map(tab => ({
860-
id: tab.key,
861-
layoutConfig: (allDashboardData[tab.key]?.layoutConfig ??
862-
EMPTY_ARRAY) as ItemConfigType[],
863-
key: `${tab.key}-${layoutIteration}`,
864-
})),
859+
...tabs
860+
.filter(tab => tab.key !== DEFAULT_DASHBOARD_ID)
861+
.map(tab => ({
862+
id: tab.key,
863+
layoutConfig: (allDashboardData[tab.key]?.layoutConfig ??
864+
EMPTY_ARRAY) as ItemConfigType[],
865+
key: `${tab.key}-${layoutIteration}`,
866+
})),
865867
];
866868
}
867869

@@ -898,14 +900,9 @@ export class AppMainContainer extends Component<
898900
>
899901
<div className="app-main-top-nav-menus">
900902
<Logo className="ml-1" style={{ maxHeight: '20px' }} />
901-
{tabs.length > 0 && (
903+
{/* Only show the Code Studio tab if there is also an open dashboard */}
904+
{tabs.length > 1 && (
902905
<div style={{ flexShrink: 0, flexGrow: 1, display: 'flex' }}>
903-
<Button
904-
kind="ghost"
905-
icon={vsHome}
906-
tooltip="Go to Code Studio"
907-
onClick={this.handleHomeClick}
908-
/>
909906
<NavTabList
910907
tabs={tabs}
911908
activeKey={activeTabKey}

packages/components/src/navigation/NavTab.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React, { memo } from 'react';
22
import classNames from 'classnames';
33
import { Draggable } from 'react-beautiful-dnd';
4-
import { vsClose } from '@deephaven/icons';
4+
import { IconDefinition, vsClose } from '@deephaven/icons';
5+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
56
import type { NavTabItem } from './NavTabList';
67
import Button from '../Button';
78
import ContextActions from '../context-actions/ContextActions';
@@ -29,7 +30,16 @@ const NavTab = memo(
2930
isDraggable,
3031
contextActions,
3132
}: NavTabProps) => {
32-
const { key, isClosable = onClose != null, title } = tab;
33+
const { key, isClosable = onClose != null, title, icon } = tab;
34+
35+
let iconElem: JSX.Element | undefined;
36+
if (icon != null) {
37+
iconElem = React.isValidElement(icon) ? (
38+
icon
39+
) : (
40+
<FontAwesomeIcon icon={icon as IconDefinition} />
41+
);
42+
}
3343

3444
return (
3545
<Draggable
@@ -68,6 +78,7 @@ const NavTab = memo(
6878
if (event.key === 'Enter') onSelect(key);
6979
}}
7080
>
81+
{iconElem}
7182
{title}
7283
{isClosable && (
7384
<Button

packages/components/src/navigation/NavTabList.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
OnDragEndResponder,
1414
} from 'react-beautiful-dnd';
1515
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
16+
import { IconDefinition } from '@fortawesome/fontawesome-svg-core';
1617
import { vsChevronRight, vsChevronLeft } from '@deephaven/icons';
1718
import { useResizeObserver } from '@deephaven/react-hooks';
1819
import DragUtils from '../DragUtils';
@@ -39,6 +40,11 @@ export interface NavTabItem {
3940
*/
4041
title: string;
4142

43+
/**
44+
* Icon to display on the tab.
45+
*/
46+
icon?: IconDefinition | JSX.Element;
47+
4248
/**
4349
* Whether the tab is closable.
4450
* If omitted, the tab will be closeable if onClose exists.

0 commit comments

Comments
 (0)