Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add run status to page title #287

Merged
merged 6 commits into from
Nov 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions frontend/src/components/Router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Router extends React.Component<{}, RouteComponentState> {
updateBanner: this._updateBanner.bind(this),
updateDialog: this._updateDialog.bind(this),
updateSnackbar: this._updateSnackbar.bind(this),
updateToolbar: this._setToolbarActions.bind(this),
updateToolbar: this._updateToolbar.bind(this),
};

const routes: Array<{ path: string, Component: React.ComponentClass, view?: any }> = [
Expand Down Expand Up @@ -195,7 +195,8 @@ class Router extends React.Component<{}, RouteComponentState> {
}
}

private _setToolbarActions(toolbarProps: ToolbarProps): void {
private _updateToolbar(newToolbarProps: Partial<ToolbarProps>): void {
const toolbarProps = Object.assign(this.state.toolbarProps, newToolbarProps);
this.setState({ toolbarProps });
}

Expand Down
41 changes: 31 additions & 10 deletions frontend/src/components/Toolbar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,32 +58,49 @@ const history = createBrowserHistory({});

describe('Toolbar', () => {
it('renders nothing when there are no breadcrumbs or actions', () => {
const tree = shallow(<Toolbar breadcrumbs={[]} actions={[]} history={history} />);
const tree = shallow(<Toolbar breadcrumbs={[]} actions={[]} history={history} pageTitle='' />);
expect(tree).toMatchSnapshot();
});

it('renders without breadcrumbs and a string page title', () => {
const tree = shallow(<Toolbar breadcrumbs={[]} actions={[actions[0]]} history={history}
pageTitle='test page title' />);
expect(tree).toMatchSnapshot();
});

it('renders without breadcrumbs and a component page title', () => {
const tree = shallow(<Toolbar breadcrumbs={[]} actions={[actions[0]]} history={history}
pageTitle={<div id='myComponent'>test page title</div>} />);
expect(tree).toMatchSnapshot();
});

it('renders without breadcrumbs and one action', () => {
const tree = shallow(<Toolbar breadcrumbs={[]} actions={[actions[0]]} history={history} />);
const tree = shallow(<Toolbar breadcrumbs={[]} actions={[actions[0]]} history={history}
pageTitle='' />);
expect(tree).toMatchSnapshot();
});

it('renders without actions and one breadcrumb', () => {
const tree = shallow(<Toolbar breadcrumbs={[breadcrumbs[0]]} actions={[]} history={history} />);
const tree = shallow(<Toolbar breadcrumbs={[breadcrumbs[0]]} actions={[]} history={history}
pageTitle='' />);
expect(tree).toMatchSnapshot();
});

it('renders without actions, one breadcrumb, and a page name', () => {
const tree = shallow(<Toolbar breadcrumbs={breadcrumbs} actions={[]} history={history} />);
const tree = shallow(<Toolbar breadcrumbs={[breadcrumbs[0]]} actions={[]} history={history}
pageTitle='test page title' />);
expect(tree).toMatchSnapshot();
});

it('renders without breadcrumbs and two actions', () => {
const tree = shallow(<Toolbar breadcrumbs={[]} actions={actions} history={history} />);
const tree = shallow(<Toolbar breadcrumbs={[]} actions={actions} history={history}
pageTitle='' />);
expect(tree).toMatchSnapshot();
});

it('fires the right action function when button is clicked', () => {
const tree = shallow(<Toolbar breadcrumbs={[]} actions={actions} history={history} />);
const tree = shallow(<Toolbar breadcrumbs={[]} actions={actions} history={history}
pageTitle='' />);
tree.find('BusyButton').at(0).simulate('click');
expect(action1).toHaveBeenCalled();
action2.mockClear();
Expand All @@ -98,7 +115,8 @@ describe('Toolbar', () => {
tooltip: 'test tooltip',
}];

const tree = shallow(<Toolbar breadcrumbs={breadcrumbs} actions={outlinedActions} history={history} />);
const tree = shallow(<Toolbar breadcrumbs={breadcrumbs} actions={outlinedActions} pageTitle=''
history={history} />);
expect(tree).toMatchSnapshot();
});

Expand All @@ -111,7 +129,8 @@ describe('Toolbar', () => {
tooltip: 'test tooltip',
}];

const tree = shallow(<Toolbar breadcrumbs={breadcrumbs} actions={outlinedActions} history={history} />);
const tree = shallow(<Toolbar breadcrumbs={breadcrumbs} actions={outlinedActions} pageTitle=''
history={history} />);
expect(tree).toMatchSnapshot();
});

Expand All @@ -125,12 +144,14 @@ describe('Toolbar', () => {
tooltip: 'test tooltip',
}];

const tree = shallow(<Toolbar breadcrumbs={breadcrumbs} actions={outlinedActions} history={history} />);
const tree = shallow(<Toolbar breadcrumbs={breadcrumbs} actions={outlinedActions} pageTitle=''
history={history} />);
expect(tree).toMatchSnapshot();
});

it('renders with two breadcrumbs and two actions', () => {
const tree = shallow(<Toolbar breadcrumbs={breadcrumbs} actions={actions} history={history} />);
const tree = shallow(<Toolbar breadcrumbs={breadcrumbs} actions={actions} pageTitle=''
history={history} />);
expect(tree).toMatchSnapshot();
});
});
14 changes: 7 additions & 7 deletions frontend/src/components/Toolbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,17 +102,17 @@ export interface ToolbarProps {
actions: ToolbarActionConfig[];
breadcrumbs: Breadcrumb[];
history?: History;
pageTitle: string | JSX.Element;
pageTitleTooltip?: string;
topLevelToolbar?: boolean;
}

class Toolbar extends React.Component<ToolbarProps> {

public render(): JSX.Element | null {
const currentPage = this.props.breadcrumbs.length ?
this.props.breadcrumbs[this.props.breadcrumbs.length - 1].displayName : '';
const breadcrumbs = this.props.breadcrumbs.slice(0, this.props.breadcrumbs.length - 1);
const { breadcrumbs, pageTitle, pageTitleTooltip } = { ...this.props };

if (!this.props.actions.length && !this.props.breadcrumbs.length) {
if (!this.props.actions.length && !this.props.breadcrumbs.length && !this.props.pageTitle) {
return null;
}

Expand Down Expand Up @@ -143,8 +143,8 @@ class Toolbar extends React.Component<ToolbarProps> {
</IconButton>
</Tooltip>}
{/* Resource Name */}
<span className={classes(css.pageName, commonCss.ellipsis)} title={currentPage}>
{currentPage}
<span className={classes(css.pageName, commonCss.ellipsis)} title={pageTitleTooltip}>
{pageTitle}
</span>
</div>
</div>
Expand All @@ -157,7 +157,7 @@ class Toolbar extends React.Component<ToolbarProps> {
<BusyButton id={b.id} color='secondary' onClick={b.action} disabled={b.disabled}
title={b.title} icon={b.icon} busy={b.busy || false}
outlined={(b.outlined && !b.primary) || false}
className={b.primary ? commonCss.buttonAction : ''}/>
className={b.primary ? commonCss.buttonAction : ''} />
</div>
</Tooltip>
))}
Expand Down
Loading