Skip to content

Commit

Permalink
chore: allow custom subnav (#734)
Browse files Browse the repository at this point in the history
* chore: allow custom subnav

Signed-off-by: Carina Ursu <[email protected]>

* chore: allow custom subnav

Signed-off-by: Carina Ursu <[email protected]>

* chore: bump console

Signed-off-by: Carina Ursu <[email protected]>

* chore: fixes

Signed-off-by: Carina Ursu <[email protected]>

* chore: fix ExecutionDetailsAppBarContent.test.tsx

Signed-off-by: Carina Ursu <[email protected]>

* chore: versions

Signed-off-by: Carina Ursu <[email protected]>

---------

Signed-off-by: Carina Ursu <[email protected]>
  • Loading branch information
ursucarina authored Apr 15, 2023
1 parent 5aecd5c commit 33ee52a
Show file tree
Hide file tree
Showing 21 changed files with 338 additions and 282 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"scripts": {
"postinstall": "husky install",
"install:console": "yarn workspaces focus --production --all",
"build:pack": "yarn workspaces foreach -vit --include '{@flyteorg/flyteidl-types,@flyteorg/flyte-api,@flyteorg/ui-atoms,@flyteorg/common,@flyteorg/locale,@flyteorg/flyte-api,@flyteorg/components,@flyteorg/console}' run build",
"build:types": "yarn workspaces foreach -vit --include '{@flyteorg/flyteidl-types,@flyteorg/flyte-api,@flyteorg/ui-atoms,@flyteorg/common,@flyteorg/locale,@flyteorg/flyte-api,@flyteorg/components,@flyteorg/console}' run build:types",
"clean": "git clean -fxd --exclude script",
Expand Down
2 changes: 1 addition & 1 deletion packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flyteorg/common",
"version": "0.0.3",
"version": "0.0.4",
"description": "Flyteconsole common utilities",
"main": "./dist/index.js",
"module": "./lib/index.js",
Expand Down
4 changes: 3 additions & 1 deletion packages/common/src/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ThemeOptions } from '@material-ui/core/styles';

type StatusColor = {
FAILURE: string;
RUNNING: string;
Expand Down Expand Up @@ -44,5 +46,5 @@ export type AppConfig = {
inputFocusBorderColor?: string;
statusColors?: StatusColor;
graphStatusColors?: GraphStatusColor;
flyteNavigation?: FlyteNavigation;
themeOptions?: ThemeOptions;
};
4 changes: 2 additions & 2 deletions packages/console/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@flyteorg/console",
"version": "0.0.19",
"version": "0.0.20",
"description": "Flyteconsole main app module",
"main": "./dist/index.js",
"module": "./lib/index.js",
Expand Down Expand Up @@ -56,7 +56,7 @@
"dependencies": {
"@date-io/moment": "1.3.9",
"@emotion/core": "10.1.1",
"@flyteorg/common": "^0.0.3",
"@flyteorg/common": "^0.0.4",
"@flyteorg/components": "^0.0.3",
"@flyteorg/flyte-api": "^0.0.2",
"@flyteorg/flyteidl-types": "^0.0.3",
Expand Down
1 change: 1 addition & 0 deletions packages/console/src/common/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export const contentContainerId = 'content-container';
export const detailsPanelId = 'details-panel';
export const navBarContentId = 'nav-bar-content';
export const subnavBarContentId = 'subnav-bar-content';

export const unknownValueString = '(unknown)';
export const dashedValueString = '----';
Expand Down
20 changes: 10 additions & 10 deletions packages/console/src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ import { ReactQueryDevtools } from 'react-query-devtools';
import { Router } from 'react-router-dom';
import { ApplicationRouter } from 'routes/ApplicationRouter';
import { history } from 'routes/history';
import { NavBarRouter } from 'routes/NavBarRouter';
import { LocalCacheProvider } from 'basics/LocalCache/ContextProvider';
import {
ExternalConfigurationProvider,
ExternalConfigurationProviderProps,
} from 'basics/ExternalConfigurationProvider';
import NavBar from 'components/Navigation/NavBar';

export type AppComponentProps = ExternalConfigurationProviderProps;

Expand All @@ -58,12 +58,12 @@ export const AppComponent: React.FC<AppComponentProps> = (
return (
<FeatureFlagsProvider>
<LocalCacheProvider>
<ThemeProvider theme={getMuiTheme(props.config)}>
<StylesProvider
generateClassName={createGenerateClassName({
seed: 'c-',
})}
>
<StylesProvider
generateClassName={createGenerateClassName({
seed: 'c-',
})}
>
<ThemeProvider theme={getMuiTheme(props.config)}>
<SnackbarProvider
// Notifications provider https://iamhosseindhv.com/notistack/demos
maxSnack={2}
Expand All @@ -82,7 +82,7 @@ export const AppComponent: React.FC<AppComponentProps> = (
<ExternalConfigurationProvider {...props}>
<Router history={history}>
<ErrorBoundary fixed={true}>
<NavBarRouter />
<NavBar />
<ApplicationRouter />
</ErrorBoundary>
</Router>
Expand All @@ -94,8 +94,8 @@ export const AppComponent: React.FC<AppComponentProps> = (
<ReactQueryDevtools initialIsOpen={false} />
</QueryClientProvider>
</SnackbarProvider>
</StylesProvider>
</ThemeProvider>
</ThemeProvider>
</StylesProvider>
</LocalCacheProvider>
</FeatureFlagsProvider>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import { Button, Dialog, Link, Typography } from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core/styles';
import ArrowBack from '@material-ui/icons/ArrowBack';
Expand All @@ -7,14 +8,12 @@ import { ButtonCircularProgress } from 'components/common/ButtonCircularProgress
import { MoreOptionsMenu } from 'components/common/MoreOptionsMenu';
import { useCommonStyles } from 'components/common/styles';
import { useLocationState } from 'components/hooks/useLocationState';
import { NavBarContent } from 'components/Navigation/NavBarContent';
import { interactiveTextDisabledColor } from 'components/Theme/constants';
import { Execution } from 'models/Execution/types';
import * as React from 'react';
import { Link as RouterLink } from 'react-router-dom';
import { history } from 'routes/history';
import { Routes } from 'routes/routes';
import { WorkflowExecutionPhase } from 'models/Execution/enums';
import { SubNavBarContent } from 'components/Navigation/SubNavBarContent';
import { ExecutionInputsOutputsModal } from '../ExecutionInputsOutputsModal';
import { ExecutionStatusBadge } from '../ExecutionStatusBadge';
import { TerminateExecutionButton } from '../TerminateExecution/TerminateExecutionButton';
Expand Down Expand Up @@ -48,7 +47,7 @@ const useStyles = makeStyles((theme: Theme) => {
maxWidth: '100%',
},
inputsOutputsLink: {
color: interactiveTextDisabledColor,
color: theme.palette.primary.main,
},
moreActions: {
marginLeft: theme.spacing(1),
Expand All @@ -74,7 +73,7 @@ const useStyles = makeStyles((theme: Theme) => {
});

/** Renders information about a given Execution into the NavBar */
export const ExecutionDetailsAppBarContent: React.FC<{
export const ExecutionDetailsAppBarContentInner: React.FC<{
execution: Execution;
}> = ({ execution }) => {
const commonStyles = useCommonStyles();
Expand Down Expand Up @@ -180,53 +179,64 @@ export const ExecutionDetailsAppBarContent: React.FC<{

return (
<>
<NavBarContent>
<div className={styles.container}>
<RouterLink
title={backLinkTitle}
className={styles.backLink}
to={backLink}
<div className={styles.container}>
<RouterLink
title={backLinkTitle}
className={classnames('backLink', styles.backLink)}
to={backLink}
>
<ArrowBack />
</RouterLink>
<ExecutionStatusBadge
phase={phase}
type="workflow"
className="subNavBadge"
/>
<div className={classnames('titleContainer', styles.titleContainer)}>
<Typography
variant="body1"
className={classnames(styles.title, commonStyles.textWrapped)}
>
<ArrowBack />
</RouterLink>
<ExecutionStatusBadge phase={phase} type="workflow" />
<div className={styles.titleContainer}>
<Typography
variant="body1"
className={classnames(styles.title, commonStyles.textWrapped)}
>
<span>
{`${project}/${domain}/${sourceId.name}/`}
<strong>{`${name}`}</strong>
</span>
</Typography>
</div>
<div className={styles.actions}>
<Link
className={styles.inputsOutputsLink}
component="button"
onClick={onClickShowInputsOutputs}
variant="body1"
>
View Inputs &amp; Outputs
</Link>
{actionContent}
{moreActionsContent}
</div>
<span>
{`${project}/${domain}/${sourceId.name}/`}
<strong>{`${name}`}</strong>
</span>
</Typography>
</div>
<Dialog
scroll="paper"
maxWidth="sm"
fullWidth={true}
open={showRelaunchForm}
>
<RelaunchExecutionForm
execution={execution}
onClose={onCloseRelaunch}
/>
</Dialog>
</NavBarContent>
<div className={styles.actions}>
<Link
className={styles.inputsOutputsLink}
component="button"
onClick={onClickShowInputsOutputs}
variant="body1"
>
View Inputs &amp; Outputs
</Link>
{actionContent}
{moreActionsContent}
</div>
</div>
<Dialog
scroll="paper"
maxWidth="sm"
fullWidth={true}
open={showRelaunchForm}
>
<RelaunchExecutionForm
execution={execution}
onClose={onCloseRelaunch}
/>
</Dialog>
{modalContent}
</>
);
};
export const ExecutionDetailsAppBarContent: React.FC<{
execution: Execution;
}> = ({ execution }) => {
return (
<SubNavBarContent>
<ExecutionDetailsAppBarContentInner execution={execution} />
</SubNavBarContent>
);
};
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as React from 'react';
import { Typography } from '@material-ui/core';
import { makeStyles, Theme } from '@material-ui/core/styles';
import classnames from 'classnames';
Expand All @@ -7,7 +8,6 @@ import { timestampToDate } from 'common/utils';
import { useCommonStyles } from 'components/common/styles';
import { secondaryBackgroundColor } from 'components/Theme/constants';
import { Execution } from 'models/Execution/types';
import * as React from 'react';
import { Link as RouterLink } from 'react-router-dom';
import { Routes } from 'routes/routes';
import { ExpandableExecutionError } from '../Tables/ExpandableExecutionError';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import { createTestQueryClient } from 'test/utils';
import { backLinkTitle, executionActionStrings } from '../constants';
import { ExecutionDetailsAppBarContent } from '../ExecutionDetailsAppBarContent';

jest.mock('components/Navigation/NavBarContent', () => ({
NavBarContent: ({ children }: React.Props<any>) => children,
jest.mock('components/Navigation/SubNavBarContent', () => ({
SubNavBarContent: ({ children }: React.Props<any>) => children,
}));

describe('ExecutionDetailsAppBarContent', () => {
Expand Down
13 changes: 10 additions & 3 deletions packages/console/src/components/Navigation/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import AppBar from '@material-ui/core/AppBar';
import Toolbar from '@material-ui/core/Toolbar';
import { navBarContentId } from 'common/constants';
import { FlyteNavigation } from '@flyteorg/common';
import { useExternalConfigurationContext } from 'basics/ExternalConfigurationProvider';
import { getFlyteNavigationData } from './utils';

export interface NavBarProps {
Expand All @@ -16,7 +17,7 @@ const DefaultAppBarContent = lazy(() => import('./DefaultAppBarContent'));
/** Contains all content in the top navbar of the application. */
export const NavBar = (props: NavBarProps) => {
const navData = props.navigationData ?? getFlyteNavigationData();
const content = props.useCustomContent ? (
const navBarContent = props.useCustomContent ? (
<div id={navBarContentId} />
) : (
<Suspense fallback={null}>
Expand All @@ -27,7 +28,13 @@ export const NavBar = (props: NavBarProps) => {
</Suspense>
);

return (
const { registry } = useExternalConfigurationContext();

const ExternalNav = registry?.nav;

return ExternalNav ? (
<ExternalNav />
) : (
<AppBar
color="secondary"
elevation={0}
Expand All @@ -38,7 +45,7 @@ export const NavBar = (props: NavBarProps) => {
position: 'fixed',
}}
>
<Toolbar id={navBarContentId}>{content}</Toolbar>
<Toolbar id={navBarContentId}>{navBarContent}</Toolbar>
</AppBar>
);
};
Expand Down
18 changes: 18 additions & 0 deletions packages/console/src/components/Navigation/SubNavBarContent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as React from 'react';
import ReactDOM from 'react-dom';
import { subnavBarContentId } from 'common/constants';
import { log } from 'common/log';

/** Complements NavBar, allowing pages to inject custom content. */
export const SubNavBarContent: React.FC<React.PropsWithChildren<{}>> = ({
children,
}) => {
const navBar = document.getElementById(subnavBarContentId);
if (navBar == null) {
log.warn(`
Attempting to mount content into NavBar, but failed to find the content component.
Did you mount an instance of NavBar with useCustomContent=true?`);
return null;
}
return ReactDOM.createPortal(children, navBar);
};
3 changes: 2 additions & 1 deletion packages/console/src/components/Navigation/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './UserInformation';
export { NavBarContent } from './NavBarContent';
export * from './NavBarContent';
export * from './SubNavBarContent';
3 changes: 0 additions & 3 deletions packages/console/src/components/Navigation/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { env } from '@flyteorg/common';
import { flyteNavigation } from 'components/Theme/constants';

export interface FlyteNavItem {
title: string;
Expand All @@ -14,7 +13,5 @@ export interface FlyteNavigation {
}

export const getFlyteNavigationData = (): FlyteNavigation | undefined => {
if (flyteNavigation) return flyteNavigation;

return env.FLYTE_NAVIGATION ? JSON.parse(env.FLYTE_NAVIGATION) : undefined;
};
7 changes: 6 additions & 1 deletion packages/console/src/components/Theme/colorSpectrum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export type ColorSpectrumType =
| 'rose100'
| 'gray0'
| 'gray5'
| 'gray7'
| 'gray10'
| 'gray15'
| 'gray20'
Expand Down Expand Up @@ -992,9 +993,13 @@ export const COLOR_SPECTRUM: {
value: 0,
},
gray5: {
color: '#F4F4FA',
color: '#F2F3F3',
value: 5,
},
gray7: {
color: '#E6E7E8',
value: 7,
},
gray10: {
color: '#E7E7EF',
value: 10,
Expand Down
Loading

0 comments on commit 33ee52a

Please sign in to comment.