mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-15 09:46:16 +01:00
Added EditGroupNavLink
This commit is contained in:
@@ -26,6 +26,9 @@
|
||||
"create-group-button": {
|
||||
"label": "Create group"
|
||||
},
|
||||
"edit-group-button": {
|
||||
"label": "Edit"
|
||||
},
|
||||
"group-form": {
|
||||
"submit": "Submit"
|
||||
}
|
||||
|
||||
31
scm-ui/src/groups/components/navLinks/EditGroupNavLink.js
Normal file
31
scm-ui/src/groups/components/navLinks/EditGroupNavLink.js
Normal file
@@ -0,0 +1,31 @@
|
||||
//@flow
|
||||
import React from 'react';
|
||||
import NavLink from "../../../components/navigation/NavLink";
|
||||
import { translate } from "react-i18next";
|
||||
import type { Group } from "../../types/Group";
|
||||
|
||||
type Props = {
|
||||
t: string => string,
|
||||
editUrl: string,
|
||||
group: Group
|
||||
}
|
||||
|
||||
type State = {
|
||||
}
|
||||
|
||||
class EditGroupNavLink extends React.Component<Props, State> {
|
||||
|
||||
render() {
|
||||
const { t, editUrl } = this.props;
|
||||
if (!this.isEditable()) {
|
||||
return null;
|
||||
}
|
||||
return <NavLink label={t("edit-group-button.label")} to={editUrl} />;
|
||||
}
|
||||
|
||||
isEditable = () => {
|
||||
return this.props.group._links.update;
|
||||
}
|
||||
}
|
||||
|
||||
export default translate("groups")(EditGroupNavLink);
|
||||
@@ -0,0 +1,29 @@
|
||||
//@flow
|
||||
|
||||
import React from "react";
|
||||
import { shallow } from "enzyme";
|
||||
import "../../../tests/enzyme";
|
||||
import "../../../tests/i18n";
|
||||
import EditGroupNavLink from "./EditGroupNavLink";
|
||||
|
||||
it("should render nothing, if the edit link is missing", () => {
|
||||
const group = {
|
||||
_links: {}
|
||||
};
|
||||
|
||||
const navLink = shallow(<EditGroupNavLink group={group} editUrl='/group/edit'/>);
|
||||
expect(navLink.text()).toBe("");
|
||||
});
|
||||
|
||||
it("should render the navLink", () => {
|
||||
const group = {
|
||||
_links: {
|
||||
update: {
|
||||
href: "/groups"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const navLink = shallow(<EditGroupNavLink group={group} editUrl='/group/edit'/>);
|
||||
expect(navLink.text()).not.toBe("");
|
||||
});
|
||||
@@ -17,6 +17,7 @@ import Loading from "../../components/Loading";
|
||||
import { Navigation, Section, NavLink } from "../../components/navigation";
|
||||
import ErrorPage from "../../components/ErrorPage";
|
||||
import { translate } from "react-i18next";
|
||||
import EditGroupNavLink from "../components/navLinks/EditGroupNavLink";
|
||||
|
||||
type Props = {
|
||||
name: string,
|
||||
@@ -83,6 +84,7 @@ class SingleGroup extends React.Component<Props> {
|
||||
/>
|
||||
</Section>
|
||||
<Section label={t("single-group.actions-label")}>
|
||||
<EditGroupNavLink group={group} editUrl={`${url}/edit`}/>
|
||||
<NavLink to="/groups" label={t("single-group.back-label")} />
|
||||
</Section>
|
||||
</Navigation>
|
||||
|
||||
Reference in New Issue
Block a user