caught uncaught child error and added PageAction Button to Repo Overview

This commit is contained in:
Florian Scholdei
2019-02-20 11:53:38 +01:00
parent ef6259da58
commit b8dd00fc09
2 changed files with 29 additions and 18 deletions

View File

@@ -36,8 +36,21 @@ class Page extends React.Component<Props> {
); );
} }
renderPageActions() {
const { children } = this.props;
let content = null;
React.Children.forEach(children, child => {
if (child && child.type.name === "PageActions") {
content = child;
}
});
return content;
}
renderContent() { renderContent() {
const { loading, children, showContentOnError, error } = this.props; const { loading, children, showContentOnError, error } = this.props;
if (error && !showContentOnError) { if (error && !showContentOnError) {
return null; return null;
} }
@@ -47,24 +60,12 @@ class Page extends React.Component<Props> {
let content = []; let content = [];
React.Children.forEach(children, child => { React.Children.forEach(children, child => {
if (child.type.name !== "PageActions") { if (child && child.type.name !== "PageActions") {
content.push(child); content.push(child);
} }
}); });
return content; return content;
} }
renderPageActions() {
const { children } = this.props;
let content = null;
React.Children.forEach(children, child => {
if (child.type.name === "PageActions") {
content = child;
}
});
return content;
}
} }
export default Page; export default Page;

View File

@@ -14,7 +14,13 @@ import {
isFetchReposPending isFetchReposPending
} from "../modules/repos"; } from "../modules/repos";
import { translate } from "react-i18next"; import { translate } from "react-i18next";
import { CreateButton, Page, Paginator } from "@scm-manager/ui-components"; import {
Page,
PageActions,
Button,
CreateButton,
Paginator
} from "@scm-manager/ui-components";
import RepositoryList from "../components/list"; import RepositoryList from "../components/list";
import { withRouter } from "react-router-dom"; import { withRouter } from "react-router-dom";
import type { History } from "history"; import type { History } from "history";
@@ -67,6 +73,13 @@ class Overview extends React.Component<Props> {
error={error} error={error}
> >
{this.renderList()} {this.renderList()}
<PageActions>
<Button
label={t("overview.createButton")}
link="/repos/create"
color="primary"
/>
</PageActions>
</Page> </Page>
); );
} }
@@ -89,10 +102,7 @@ class Overview extends React.Component<Props> {
const { showCreateButton, t } = this.props; const { showCreateButton, t } = this.props;
if (showCreateButton) { if (showCreateButton) {
return ( return (
<CreateButton <CreateButton label={t("overview.createButton")} link="/repos/create" />
label={t("overview.createButton")}
link="/repos/create"
/>
); );
} }
return null; return null;