pulled out PageActions from OverviewPageActions because otherwise you can not check for name of OverviewPageActions because the component exported injectSheet -> jss

simplified CreateUser/GroupButton by not being used as external component
This commit is contained in:
Florian Scholdei
2019-04-24 09:46:22 +02:00
parent d56dc22efc
commit 7450c9bea2
7 changed files with 43 additions and 72 deletions

View File

@@ -32,7 +32,7 @@ class OverviewPageActions extends React.Component<Props> {
const { history, location, link } = this.props; const { history, location, link } = this.props;
let directory = link.substring(0, link.indexOf("/")); let directory = link.substring(0, link.indexOf("/"));
return ( return (
<PageActions> <>
<FilterInput <FilterInput
value={urls.getQueryStringFromLocation(location)} value={urls.getQueryStringFromLocation(location)}
filter={filter => { filter={filter => {
@@ -40,7 +40,7 @@ class OverviewPageActions extends React.Component<Props> {
}} }}
/> />
{this.renderCreateButton()} {this.renderCreateButton()}
</PageActions> </>
); );
} }

View File

@@ -7,7 +7,6 @@ import ErrorNotification from "./../ErrorNotification";
import Title from "./Title"; import Title from "./Title";
import Subtitle from "./Subtitle"; import Subtitle from "./Subtitle";
import PageActions from "./PageActions"; import PageActions from "./PageActions";
import OverviewPageActions from "../OverviewPageActions";
import ErrorBoundary from "../ErrorBoundary"; import ErrorBoundary from "../ErrorBoundary";
type Props = { type Props = {
@@ -52,10 +51,7 @@ class Page extends React.Component<Props> {
let pageActionsExists = false; let pageActionsExists = false;
React.Children.forEach(children, child => { React.Children.forEach(children, child => {
if (child && !error) { if (child && !error) {
if ( if (child.type.name === PageActions.name)
child.type.name === PageActions.name ||
child.type.name === OverviewPageActions.name
)
pageActions = ( pageActions = (
<div <div
className={classNames( className={classNames(
@@ -100,10 +96,7 @@ class Page extends React.Component<Props> {
let content = []; let content = [];
React.Children.forEach(children, child => { React.Children.forEach(children, child => {
if (child) { if (child) {
if ( if (child.type.name !== PageActions.name) {
child.type.name !== PageActions.name &&
child.type.name !== OverviewPageActions.name
) {
content.push(child); content.push(child);
} }
} }

View File

@@ -1,19 +0,0 @@
//@flow
import React from "react";
import { translate } from "react-i18next";
import { CreateButton } from "@scm-manager/ui-components";
type Props = {
t: string => string
};
class CreateGroupButton extends React.Component<Props> {
render() {
const { t } = this.props;
return (
<CreateButton label={t("create-group-button.label")} link="/groups/add" />
);
}
}
export default translate("groups")(CreateGroupButton);

View File

@@ -14,13 +14,14 @@ import {
} from "../modules/groups"; } from "../modules/groups";
import { import {
Page, Page,
PageActions,
OverviewPageActions, OverviewPageActions,
Notification, Notification,
LinkPaginator, LinkPaginator,
urls urls,
CreateButton
} from "@scm-manager/ui-components"; } from "@scm-manager/ui-components";
import { GroupTable } from "./../components/table"; import { GroupTable } from "./../components/table";
import CreateGroupButton from "../components/buttons/CreateGroupButton";
import { getGroupsLink } from "../../modules/indexResource"; import { getGroupsLink } from "../../modules/indexResource";
type Props = { type Props = {
@@ -83,11 +84,13 @@ class Groups extends React.Component<Props> {
> >
{this.renderGroupTable()} {this.renderGroupTable()}
{this.renderCreateButton()} {this.renderCreateButton()}
<PageActions>
<OverviewPageActions <OverviewPageActions
showCreateButton={canAddGroups} showCreateButton={canAddGroups}
link="groups/add" link="groups/add"
label={t("create-group-button.label")} label={t("create-group-button.label")}
/> />
</PageActions>
</Page> </Page>
); );
} }
@@ -110,8 +113,14 @@ class Groups extends React.Component<Props> {
} }
renderCreateButton() { renderCreateButton() {
if (this.props.canAddGroups) { const { canAddGroups, t } = this.props;
return <CreateGroupButton />; if (canAddGroups) {
return (
<CreateButton
label={t("create-group-button.label")}
link="/groups/add"
/>
);
} }
return null; return null;
} }

View File

@@ -14,6 +14,7 @@ import {
} from "../modules/repos"; } from "../modules/repos";
import { import {
Page, Page,
PageActions,
OverviewPageActions, OverviewPageActions,
CreateButton, CreateButton,
Notification, Notification,
@@ -81,11 +82,13 @@ class Overview extends React.Component<Props> {
error={error} error={error}
> >
{this.renderOverview()} {this.renderOverview()}
<PageActions>
<OverviewPageActions <OverviewPageActions
showCreateButton={showCreateButton} showCreateButton={showCreateButton}
link="repos/create" link="repos/create"
label={t("overview.createButton")} label={t("overview.createButton")}
/> />
</PageActions>
</Page> </Page>
); );
} }

View File

@@ -1,19 +0,0 @@
//@flow
import React from "react";
import { translate } from "react-i18next";
import { CreateButton } from "@scm-manager/ui-components";
type Props = {
t: string => string
};
class CreateUserButton extends React.Component<Props> {
render() {
const { t } = this.props;
return (
<CreateButton label={t("users.createButton")} link="/users/add" />
);
}
}
export default translate("users")(CreateUserButton);

View File

@@ -14,13 +14,14 @@ import {
} from "../modules/users"; } from "../modules/users";
import { import {
Page, Page,
PageActions,
OverviewPageActions, OverviewPageActions,
Notification, Notification,
LinkPaginator, LinkPaginator,
urls urls,
CreateButton
} from "@scm-manager/ui-components"; } from "@scm-manager/ui-components";
import { UserTable } from "./../components/table"; import { UserTable } from "./../components/table";
import CreateUserButton from "../components/buttons/CreateUserButton";
import { getUsersLink } from "../../modules/indexResource"; import { getUsersLink } from "../../modules/indexResource";
type Props = { type Props = {
@@ -83,11 +84,13 @@ class Users extends React.Component<Props> {
> >
{this.renderUserTable()} {this.renderUserTable()}
{this.renderCreateButton()} {this.renderCreateButton()}
<PageActions>
<OverviewPageActions <OverviewPageActions
showCreateButton={canAddUsers} showCreateButton={canAddUsers}
link="users/add" link="users/add"
label={t("users.createButton")} label={t("users.createButton")}
/> />
</PageActions>
</Page> </Page>
); );
} }
@@ -110,8 +113,9 @@ class Users extends React.Component<Props> {
} }
renderCreateButton() { renderCreateButton() {
if (this.props.canAddUsers) { const { canAddUsers, t } = this.props;
return <CreateUserButton />; if (canAddUsers) {
return <CreateButton label={t("users.createButton")} link="/users/add" />;
} }
return null; return null;
} }