Skip to content

Commit

Permalink
feat: default layout supports user controls in title banner
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastia committed Nov 23, 2020
1 parent 0047155 commit 45610ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
17 changes: 12 additions & 5 deletions app/layouts/default-layout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Container} from 'react-bootstrap';
import {Container, Row, Col} from 'react-bootstrap';
import {graphql, createFragmentContainer} from 'react-relay';
import {defaultLayout_session} from '__generated__/defaultLayout_session.graphql';
import getConfig from 'next/config';
Expand All @@ -14,6 +14,7 @@ const runtimeConfig = getConfig()?.publicRuntimeConfig ?? {};

interface Props {
title?: string | JSX.Element;
titleControls?: JSX.Element;
showSubheader?: boolean;
session: defaultLayout_session;
width?: 'narrow' | 'wide';
Expand All @@ -26,6 +27,7 @@ interface Props {
const DefaultLayout: React.FunctionComponent<Props> = ({
children,
title,
titleControls,
showSubheader,
session,
width = 'narrow',
Expand All @@ -49,10 +51,15 @@ const DefaultLayout: React.FunctionComponent<Props> = ({
{title ? (
<div className="page-title">
<Container className={width}>
<h1>{title}</h1>
{help && (
<Help title={help.title} helpMessage={help.helpMessage} />
)}
<Row>
<Col>
<h1>{title}</h1>
{help && (
<Help title={help.title} helpMessage={help.helpMessage} />
)}
</Col>
<Col xs="auto">{titleControls}</Col>
</Row>
</Container>
</div>
) : null}
Expand Down
15 changes: 9 additions & 6 deletions app/pages/admin/products-benchmarks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,16 @@ class ProductsBenchmarks extends Component<Props> {
render() {
const {query} = this.props;
const {totalProductCount} = this.state;
const newProductButton = (
<Button onClick={this.toggleShowCreateForm}>New Product</Button>
);

return (
<DefaultLayout session={query.session} title="Manage Products">
<DefaultLayout
session={query.session}
title="Manage Products"
titleControls={newProductButton}
>
<Row>
<Col md={{span: 4, offset: 4}}>
<Toast
Expand All @@ -114,11 +122,6 @@ class ProductsBenchmarks extends Component<Props> {
<br />
</Col>
</Row>
<Row>
<Col>
<Button onClick={this.toggleShowCreateForm}>New Product</Button>
</Col>
</Row>
<Row>
<Col>
{this.state.expandCreateForm && (
Expand Down

0 comments on commit 45610ea

Please sign in to comment.