2018-09-03 16:17:36 +02:00
|
|
|
//@flow
|
|
|
|
|
import * as React from "react";
|
|
|
|
|
import Loading from "./../Loading";
|
|
|
|
|
import ErrorNotification from "./../ErrorNotification";
|
|
|
|
|
import Title from "./Title";
|
|
|
|
|
import Subtitle from "./Subtitle";
|
|
|
|
|
|
|
|
|
|
type Props = {
|
|
|
|
|
title?: string,
|
|
|
|
|
subtitle?: string,
|
|
|
|
|
loading?: boolean,
|
|
|
|
|
error?: Error,
|
|
|
|
|
showContentOnError?: boolean,
|
|
|
|
|
children: React.Node
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Page extends React.Component<Props> {
|
|
|
|
|
render() {
|
2019-02-20 13:47:17 +01:00
|
|
|
const { error } = this.props;
|
2018-09-03 16:17:36 +02:00
|
|
|
return (
|
|
|
|
|
<section className="section">
|
|
|
|
|
<div className="container">
|
2019-02-20 13:47:17 +01:00
|
|
|
{this.renderPageHeader()}
|
2018-09-03 16:17:36 +02:00
|
|
|
<ErrorNotification error={error} />
|
|
|
|
|
{this.renderContent()}
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-20 13:47:17 +01:00
|
|
|
renderPageHeader() {
|
|
|
|
|
const { title, subtitle, children } = this.props;
|
2019-02-20 11:53:38 +01:00
|
|
|
|
|
|
|
|
let content = null;
|
2019-02-20 13:47:17 +01:00
|
|
|
let pageActionsExists = false;
|
2019-02-20 11:53:38 +01:00
|
|
|
React.Children.forEach(children, child => {
|
|
|
|
|
if (child && child.type.name === "PageActions") {
|
|
|
|
|
content = child;
|
2019-02-20 13:47:17 +01:00
|
|
|
pageActionsExists = true;
|
2019-02-20 11:53:38 +01:00
|
|
|
}
|
|
|
|
|
});
|
2019-02-20 14:13:38 +01:00
|
|
|
let underline = pageActionsExists ? <hr className="header-with-actions" /> : null;
|
2019-02-20 13:47:17 +01:00
|
|
|
|
|
|
|
|
return (
|
2019-02-20 14:13:38 +01:00
|
|
|
<>
|
|
|
|
|
<div className="columns">
|
|
|
|
|
<div className="column">
|
|
|
|
|
<Title title={title} />
|
|
|
|
|
<Subtitle subtitle={subtitle} />
|
|
|
|
|
</div>
|
|
|
|
|
<div className="column is-two-fifths">
|
|
|
|
|
<div className="is-pulled-right">{content}</div>
|
|
|
|
|
</div>
|
2019-02-20 13:47:17 +01:00
|
|
|
</div>
|
2019-02-20 14:13:38 +01:00
|
|
|
{underline}
|
|
|
|
|
</>
|
2019-02-20 13:47:17 +01:00
|
|
|
);
|
2019-02-20 11:53:38 +01:00
|
|
|
}
|
|
|
|
|
|
2018-09-03 16:17:36 +02:00
|
|
|
renderContent() {
|
|
|
|
|
const { loading, children, showContentOnError, error } = this.props;
|
2019-02-20 11:53:38 +01:00
|
|
|
|
2018-09-03 16:17:36 +02:00
|
|
|
if (error && !showContentOnError) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
if (loading) {
|
|
|
|
|
return <Loading />;
|
|
|
|
|
}
|
2019-02-20 11:16:59 +01:00
|
|
|
|
|
|
|
|
let content = [];
|
|
|
|
|
React.Children.forEach(children, child => {
|
2019-02-20 11:53:38 +01:00
|
|
|
if (child && child.type.name !== "PageActions") {
|
2019-02-20 11:16:59 +01:00
|
|
|
content.push(child);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
return content;
|
|
|
|
|
}
|
2018-09-03 16:17:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default Page;
|