diff --git a/CHANGELOG.md b/CHANGELOG.md
index daee9aa86b..97dff642cb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,11 +5,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## Unreleased
+### Changed
+- Simplified collapse state management of the secondary navigation ([#1086](https://github.com/scm-manager/scm-manager/pull/1086)
+
+### Fixed
+- Authentication for write requests for repositories with anonymous read access ([#108](https://github.com/scm-manager/scm-manager/pull/1081))
+
+
+## 2.0.0-rc6 - 2020-03-26
### Added
- Extension point to add links to the repository cards from plug ins ([#1041](https://github.com/scm-manager/scm-manager/pull/1041))
- Libc based restart strategy for posix operating systems ([#1079](https://github.com/scm-manager/scm-manager/pull/1079))
- Simple restart strategy with System.exit ([#1079](https://github.com/scm-manager/scm-manager/pull/1079))
- Notification if restart is not supported on the underlying platform ([#1079](https://github.com/scm-manager/scm-manager/pull/1079))
+- Extension point before title in repository cards ([#1080](https://github.com/scm-manager/scm-manager/pull/1080))
+- Extension point after title on repository detail page ([#1080](https://github.com/scm-manager/scm-manager/pull/1080))
### Changed
- Update resteasy to version 4.5.2.Final
diff --git a/Jenkinsfile b/Jenkinsfile
index 39173ab389..a6ca00bb51 100644
--- a/Jenkinsfile
+++ b/Jenkinsfile
@@ -48,7 +48,7 @@ node('docker') {
sh "git -c user.name='CES Marvin' -c user.email='cesmarvin@cloudogu.com' commit -m 'release version ${releaseVersion}'"
// we need to fetch all branches, so we can checkout master and develop later
- sh "git config 'remote.origin.fetch +refs/heads/*:refs/remotes/origin/*'"
+ sh "git config 'remote.origin.fetch' '+refs/heads/*:refs/remotes/origin/*'"
sh "git fetch --all"
// merge release branch into master
diff --git a/docs/v2/release-process.md b/docs/v2/release-process.md
index 3ebf091572..83f4db8ce2 100644
--- a/docs/v2/release-process.md
+++ b/docs/v2/release-process.md
@@ -7,7 +7,7 @@ To release a new version of SCM-Manager v2 you have to do the following steps (r
Make sure you have no changes you want to keep!
```
-git fetch && git checkout default && git reset --hard origin/default
+git fetch && git checkout develop && git reset --hard origin/develop
```
## Modify Changelog
@@ -114,3 +114,7 @@ Edit `package.json`: `version` has to be set to the new development version.
git commit -am "Prepare for next development iteration"
git push origin develop
```
+## Attention: Creating new plugins
+If you are creating a new plugin which doesn't exist in the SCM-Manager Plugin-Center yet, your plugin will not be shown after the release. First you have to create a `index.md` in the Plugin-Center Repository.
+
+Example: https://github.com/scm-manager/plugin-center/blob/master/src/plugins/scm-teamscale-plugin/index.md
diff --git a/pom.xml b/pom.xml
index 2054116a65..f806be11d7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -494,7 +494,7 @@
sonia.scm.mavensmp-maven-plugin
- 1.0.0-rc4
+ 1.0.0-rc5
@@ -912,7 +912,7 @@
2.1.14.5.2.Final1.19.4
- 2.10.2
+ 2.10.34.2.22.3.16.1.2.Final
@@ -944,7 +944,7 @@
8UTF-8SCM-MIT
-
+ 1.3.1.Final
diff --git a/scm-annotation-processor/pom.xml b/scm-annotation-processor/pom.xml
index 4881cf3110..eafc3f5c58 100644
--- a/scm-annotation-processor/pom.xml
+++ b/scm-annotation-processor/pom.xml
@@ -78,7 +78,7 @@
org.kohsuke.metainf-servicesmetainf-services
- 1.7
+ 1.8
diff --git a/scm-core/src/main/java/sonia/scm/web/api/RepositoryToHalMapper.java b/scm-core/src/main/java/sonia/scm/web/api/RepositoryToHalMapper.java
new file mode 100644
index 0000000000..b5184fb202
--- /dev/null
+++ b/scm-core/src/main/java/sonia/scm/web/api/RepositoryToHalMapper.java
@@ -0,0 +1,45 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package sonia.scm.web.api;
+
+import de.otto.edison.hal.HalRepresentation;
+import sonia.scm.repository.Repository;
+
+/**
+ * Maps a repository to a hal representation.
+ * This is especially useful if a plugin would deliver a repository to the frontend.
+ *
+ * @since 2.0.0
+ */
+public interface RepositoryToHalMapper {
+
+ /**
+ * Returns the hal representation of the repository.
+ *
+ * @param repository repository to map
+ * @return hal representation
+ */
+ HalRepresentation map(Repository repository);
+}
diff --git a/scm-core/src/main/java/sonia/scm/web/filter/PermissionFilter.java b/scm-core/src/main/java/sonia/scm/web/filter/PermissionFilter.java
index a254edcb41..9cfa95c1d5 100644
--- a/scm-core/src/main/java/sonia/scm/web/filter/PermissionFilter.java
+++ b/scm-core/src/main/java/sonia/scm/web/filter/PermissionFilter.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.web.filter;
import org.apache.shiro.SecurityUtils;
@@ -35,7 +35,7 @@ import sonia.scm.repository.Repository;
import sonia.scm.repository.RepositoryPermissions;
import sonia.scm.repository.spi.ScmProviderHttpServlet;
import sonia.scm.repository.spi.ScmProviderHttpServletDecorator;
-import sonia.scm.security.Role;
+import sonia.scm.security.Authentications;
import sonia.scm.security.ScmSecurityException;
import sonia.scm.util.HttpUtil;
@@ -177,7 +177,7 @@ public abstract class PermissionFilter extends ScmProviderHttpServletDecorator
HttpServletResponse response, Subject subject)
throws IOException
{
- if (subject.hasRole(Role.USER))
+ if (!Authentications.isAuthenticatedSubjectAnonymous())
{
sendNotEnoughPrivilegesError(request, response);
}
diff --git a/scm-core/src/test/java/sonia/scm/web/filter/PermissionFilterTest.java b/scm-core/src/test/java/sonia/scm/web/filter/PermissionFilterTest.java
index ad21e501e7..5ba99bd2f1 100644
--- a/scm-core/src/test/java/sonia/scm/web/filter/PermissionFilterTest.java
+++ b/scm-core/src/test/java/sonia/scm/web/filter/PermissionFilterTest.java
@@ -21,7 +21,7 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-
+
package sonia.scm.web.filter;
import com.github.sdorra.shiro.ShiroRule;
@@ -82,6 +82,17 @@ public class PermissionFilterTest {
permissionFilter.service(request, response, REPOSITORY);
+ verify(response).sendError(eq(403));
+ verify(delegateServlet, never()).service(request, response, REPOSITORY);
+ }
+
+ @Test
+ @SubjectAware(username = "_anonymous", password = "secret")
+ public void shouldBlockForAnonymousOnWriteRequestWithAuthenticationRequest() throws IOException, ServletException {
+ writeRequest = true;
+
+ permissionFilter.service(request, response, REPOSITORY);
+
verify(response).sendError(eq(401), anyString());
verify(delegateServlet, never()).service(request, response, REPOSITORY);
}
diff --git a/scm-core/src/test/resources/sonia/scm/shiro.ini b/scm-core/src/test/resources/sonia/scm/shiro.ini
index fda268ec83..4bd34d3a41 100644
--- a/scm-core/src/test/resources/sonia/scm/shiro.ini
+++ b/scm-core/src/test/resources/sonia/scm/shiro.ini
@@ -4,6 +4,7 @@ admin = secret, admin
writer = secret, repo_write
reader = secret, repo_read
unpriv = secret
+_anonymous = secret
[roles]
admin = *
diff --git a/scm-ui/tsconfig/tsconfig.json b/scm-ui/tsconfig/tsconfig.json
index a2450080eb..1c3acc4351 100644
--- a/scm-ui/tsconfig/tsconfig.json
+++ b/scm-ui/tsconfig/tsconfig.json
@@ -59,6 +59,10 @@
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
- "skipLibCheck": true
+ "skipLibCheck": true,
+ "lib": [
+ "dom",
+ "es2019"
+ ]
}
}
diff --git a/scm-ui/ui-components/.storybook/config.js b/scm-ui/ui-components/.storybook/config.js
index bfaea0245c..ae409e6478 100644
--- a/scm-ui/ui-components/.storybook/config.js
+++ b/scm-ui/ui-components/.storybook/config.js
@@ -70,7 +70,4 @@ addDecorator(
})
);
-const RoutingDecorator = (story) => {story()};
-addDecorator(RoutingDecorator);
-
configure(require.context("../src", true, /\.stories\.tsx?$/), module);
diff --git a/scm-ui/ui-components/src/CardColumn.tsx b/scm-ui/ui-components/src/CardColumn.tsx
index 8931fe6a1e..42c1512690 100644
--- a/scm-ui/ui-components/src/CardColumn.tsx
+++ b/scm-ui/ui-components/src/CardColumn.tsx
@@ -27,7 +27,7 @@ import styled from "styled-components";
import { Link } from "react-router-dom";
type Props = {
- title: string;
+ title: ReactNode;
description?: string;
avatar: ReactNode;
contentRight?: ReactNode;
@@ -99,9 +99,7 @@ export default class CardColumn extends React.Component {
-
- {title}
-
+
{title}
{description}
{contentRight}
diff --git a/scm-ui/ui-components/src/DateFromNow.test.ts b/scm-ui/ui-components/src/DateFromNow.test.ts
index 8571864639..19acc08fda 100644
--- a/scm-ui/ui-components/src/DateFromNow.test.ts
+++ b/scm-ui/ui-components/src/DateFromNow.test.ts
@@ -25,7 +25,6 @@
import { chooseLocale, supportedLocales } from "./DateFromNow";
describe("test choose locale", () => {
-
it("should choose de", () => {
const locale = chooseLocale("de_DE", ["de", "en"]);
expect(locale).toBe(supportedLocales.de);
@@ -45,5 +44,4 @@ describe("test choose locale", () => {
const locale = chooseLocale("af", ["af", "be"]);
expect(locale).toBe(supportedLocales.en);
});
-
});
diff --git a/scm-ui/ui-components/src/MarkdownView.stories.tsx b/scm-ui/ui-components/src/MarkdownView.stories.tsx
index 464efe42cc..e43f9afd75 100644
--- a/scm-ui/ui-components/src/MarkdownView.stories.tsx
+++ b/scm-ui/ui-components/src/MarkdownView.stories.tsx
@@ -32,12 +32,14 @@ import MarkdownXmlCodeBlock from "./__resources__/markdown-xml-codeblock.md";
import MarkdownInlineXml from "./__resources__/markdown-inline-xml.md";
import Title from "./layout/Title";
import { Subtitle } from "./layout";
+import { MemoryRouter } from "react-router-dom";
const Spacing = styled.div`
padding: 2em;
`;
storiesOf("MarkdownView", module)
+ .addDecorator(story => {story()})
.addDecorator(story => {story()})
.add("Default", () => )
.add("Code without Lang", () => )
diff --git a/scm-ui/ui-components/src/__resources__/git-logo.png b/scm-ui/ui-components/src/__resources__/git-logo.png
new file mode 100644
index 0000000000..ed9393dc36
Binary files /dev/null and b/scm-ui/ui-components/src/__resources__/git-logo.png differ
diff --git a/scm-ui/ui-components/src/__resources__/repository.ts b/scm-ui/ui-components/src/__resources__/repository.ts
new file mode 100644
index 0000000000..8facf86e57
--- /dev/null
+++ b/scm-ui/ui-components/src/__resources__/repository.ts
@@ -0,0 +1,67 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+export default {
+ contact: "heart-of-gold@hitchhiher.com",
+ creationDate: "2020-03-23T08:26:01.164Z",
+ description: "The starship Heart of Gold was the first spacecraft to make use of the Infinite Improbability Drive",
+ healthCheckFailures: [],
+ lastModified: "2020-03-23T08:26:01.876Z",
+ namespace: "hitchhiher",
+ name: "heartOfGold",
+ type: "git",
+ _links: {
+ self: { href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git" },
+ delete: { href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git" },
+ update: { href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git" },
+ permissions: { href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git/permissions/" },
+ protocol: [
+ { href: "ssh://scmadmin@localhost:4567/repo/scmadmin/Git", name: "ssh" },
+ { href: "http://localhost:8081/scm/repo/scmadmin/Git", name: "http" }
+ ],
+ tags: { href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git/tags/" },
+ branches: { href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git/branches/" },
+ incomingChangesets: {
+ href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git/incoming/{source}/{target}/changesets",
+ templated: true
+ },
+ incomingDiff: {
+ href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git/incoming/{source}/{target}/diff",
+ templated: true
+ },
+ incomingDiffParsed: {
+ href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git/incoming/{source}/{target}/diff/parsed",
+ templated: true
+ },
+ changesets: { href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git/changesets/" },
+ sources: { href: "http://localhost:8081/scm/api/v2/repositories/scmadmin/Git/sources/" },
+ authorMappingConfig: {
+ href: "http://localhost:8081/scm/api/v2/authormapping/configuration/scmadmin/Git"
+ },
+ unfavorize: { href: "http://localhost:8081/scm/api/v2/unfavorize/scmadmin/Git" },
+ favorites: [
+ { href: "http://localhost:8081/scm/api/v2/unfavorize/scmadmin/Git", name: "unfavorize" },
+ { href: "http://localhost:8081/scm/api/v2/favorize/scmadmin/Git", name: "favorize" }
+ ]
+ }
+};
diff --git a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap
index 790dc01249..0417014428 100644
--- a/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap
+++ b/scm-ui/ui-components/src/__snapshots__/storyshots.test.ts.snap
@@ -34188,6 +34188,684 @@ exports[`Storyshots MarkdownView Xml Code Block 1`] = `
diff --git a/scm-ui/ui-components/src/navigation/ExternalLink.tsx b/scm-ui/ui-components/src/navigation/ExternalLink.tsx
index a87b118ee3..1565f6fa79 100644
--- a/scm-ui/ui-components/src/navigation/ExternalLink.tsx
+++ b/scm-ui/ui-components/src/navigation/ExternalLink.tsx
@@ -30,6 +30,8 @@ type Props = {
label: string;
};
+// TODO is it used in the menu? should it use MenuContext for collapse state?
+
const ExternalLink: FC = ({ to, icon, label }) => {
let showIcon;
if (icon) {
diff --git a/scm-ui/ui-components/src/navigation/MenuContext.tsx b/scm-ui/ui-components/src/navigation/MenuContext.tsx
new file mode 100644
index 0000000000..f02e5ab8d2
--- /dev/null
+++ b/scm-ui/ui-components/src/navigation/MenuContext.tsx
@@ -0,0 +1,56 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import React, { FC, useContext, useState } from "react";
+
+export type MenuContext = {
+ isCollapsed: () => boolean;
+ setCollapsed: (collapsed: boolean) => void;
+};
+
+export const MenuContext = React.createContext({
+ isCollapsed() {
+ return false;
+ },
+ setCollapsed() {}
+});
+
+export const StateMenuContextProvider: FC = ({ children }) => {
+ const [collapsed, setCollapsed] = useState(false);
+
+ const context = {
+ isCollapsed() {
+ return collapsed;
+ },
+ setCollapsed
+ };
+
+ return {children};
+};
+
+const useMenuContext = () => {
+ return useContext(MenuContext);
+};
+
+export default useMenuContext;
diff --git a/scm-ui/ui-components/src/navigation/NavAction.tsx b/scm-ui/ui-components/src/navigation/NavAction.tsx
index dd350d1c71..394b30d961 100644
--- a/scm-ui/ui-components/src/navigation/NavAction.tsx
+++ b/scm-ui/ui-components/src/navigation/NavAction.tsx
@@ -29,6 +29,8 @@ type Props = {
action: () => void;
};
+// TODO is it used in the menu? should it use MenuContext for collapse state?
+
class NavAction extends React.Component {
render() {
const { label, icon, action } = this.props;
diff --git a/scm-ui/ui-components/src/navigation/NavLink.tsx b/scm-ui/ui-components/src/navigation/NavLink.tsx
index 7a527e5ab5..d9cb3c4e7e 100644
--- a/scm-ui/ui-components/src/navigation/NavLink.tsx
+++ b/scm-ui/ui-components/src/navigation/NavLink.tsx
@@ -23,60 +23,47 @@
*/
import * as React from "react";
import classNames from "classnames";
-import { Link, Route } from "react-router-dom";
+import { Link, useRouteMatch } from "react-router-dom";
+import { RoutingProps } from "./RoutingProps";
+import { FC } from "react";
+import useMenuContext from "./MenuContext";
-// TODO mostly copy of PrimaryNavigationLink
-
-type Props = {
- to: string;
- icon?: string;
+type Props = RoutingProps & {
label: string;
- activeOnlyWhenExact?: boolean;
- activeWhenMatch?: (route: any) => boolean;
- collapsed?: boolean;
title?: string;
+ icon?: string;
};
-class NavLink extends React.Component {
- static defaultProps = {
- activeOnlyWhenExact: true
- };
+const NavLink: FC = ({ to, activeOnlyWhenExact, icon, label, title }) => {
+ const match = useRouteMatch({
+ path: to,
+ exact: activeOnlyWhenExact
+ });
- isActive(route: any) {
- const { activeWhenMatch } = this.props;
- return route.match || (activeWhenMatch && activeWhenMatch(route));
- }
+ const context = useMenuContext();
+ const collapsed = context.isCollapsed();
- renderLink = (route: any) => {
- const { to, icon, label, collapsed, title } = this.props;
-
- let showIcon = null;
- if (icon) {
- showIcon = (
- <>
- {" "}
- >
- );
- }
-
- return (
-
+ );
+};
+
+NavLink.defaultProps = {
+ activeOnlyWhenExact: true
+};
export default NavLink;
diff --git a/scm-ui/ui-components/src/navigation/Navigation.tsx b/scm-ui/ui-components/src/navigation/Navigation.tsx
index dc848b4d24..0ccd94e7f7 100644
--- a/scm-ui/ui-components/src/navigation/Navigation.tsx
+++ b/scm-ui/ui-components/src/navigation/Navigation.tsx
@@ -27,6 +27,8 @@ type Props = {
children?: ReactNode;
};
+// TODO it is used?
+
class Navigation extends React.Component {
render() {
return ;
diff --git a/scm-ui/ui-components/src/navigation/MenuContext.ts b/scm-ui/ui-components/src/navigation/RoutingProps.ts
similarity index 73%
rename from scm-ui/ui-components/src/navigation/MenuContext.ts
rename to scm-ui/ui-components/src/navigation/RoutingProps.ts
index e2760da025..20f9d8d900 100644
--- a/scm-ui/ui-components/src/navigation/MenuContext.ts
+++ b/scm-ui/ui-components/src/navigation/RoutingProps.ts
@@ -22,18 +22,8 @@
* SOFTWARE.
*/
-import React from "react";
-
-const MENU_COLLAPSED = "secondary-menu-collapsed";
-
-export const MenuContext = React.createContext({
- menuCollapsed: isMenuCollapsed(),
- setMenuCollapsed: (collapsed: boolean) => {}
-});
-
-export function isMenuCollapsed() {
- return localStorage.getItem(MENU_COLLAPSED) === "true";
-}
-export function storeMenuCollapsed(status: boolean) {
- localStorage.setItem(MENU_COLLAPSED, String(status));
-}
+export type RoutingProps = {
+ to: string;
+ activeOnlyWhenExact?: boolean;
+ activeWhenMatch?: (route: any) => boolean;
+};
diff --git a/scm-ui/ui-components/src/navigation/SecondaryNavigation.stories.tsx b/scm-ui/ui-components/src/navigation/SecondaryNavigation.stories.tsx
new file mode 100644
index 0000000000..73531dcb18
--- /dev/null
+++ b/scm-ui/ui-components/src/navigation/SecondaryNavigation.stories.tsx
@@ -0,0 +1,89 @@
+/*
+ * MIT License
+ *
+ * Copyright (c) 2020-present Cloudogu GmbH and Contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+import { storiesOf } from "@storybook/react";
+import React, { ReactElement } from "react";
+import SecondaryNavigation from "./SecondaryNavigation";
+import SecondaryNavigationItem from "./SecondaryNavigationItem";
+import styled from "styled-components";
+import SubNavigation from "./SubNavigation";
+import { Binder, ExtensionPoint, BinderContext } from "@scm-manager/ui-extensions";
+import { MemoryRouter } from "react-router-dom";
+import { StateMenuContextProvider } from "./MenuContext";
+
+const Columns = styled.div`
+ margin: 2rem;
+`;
+
+const starships = (
+
+
+
+
+);
+
+const withRoute = (route: string) => {
+ return (story: ReactElement) => {story};
+};
+
+storiesOf("Navigation|Secondary", module)
+ .addDecorator(story => {story()})
+ .addDecorator(story => (
+
+
{story()}
+
+ ))
+ .add("Default", () =>
+ withRoute("/")(
+
+
+
+
+ )
+ )
+ .add("Sub Navigation", () =>
+ withRoute("/")(
+
+
+ {starships}
+
+ )
+ )
+ .add("Extension Point", () => {
+ const binder = new Binder("menu");
+ binder.bind("subnav.sample", starships);
+ return withRoute("/hitchhiker/starships/titanic")(
+
+
+
+
+
+
+ );
+ });
diff --git a/scm-ui/ui-components/src/navigation/SecondaryNavigation.tsx b/scm-ui/ui-components/src/navigation/SecondaryNavigation.tsx
index fd8e1dd3eb..59e3593ef2 100644
--- a/scm-ui/ui-components/src/navigation/SecondaryNavigation.tsx
+++ b/scm-ui/ui-components/src/navigation/SecondaryNavigation.tsx
@@ -21,17 +21,13 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-import React, { FC, ReactElement, ReactNode, useContext, useEffect } from "react";
+
+import React, { FC } from "react";
import styled from "styled-components";
-import SubNavigation from "./SubNavigation";
-import { matchPath, useLocation } from "react-router-dom";
-import { isMenuCollapsed, MenuContext } from "./MenuContext";
+import useMenuContext from "./MenuContext";
type Props = {
label: string;
- children: ReactElement[];
- collapsed: boolean;
- onCollapse?: (newStatus: boolean) => void;
};
type CollapsedProps = {
@@ -60,73 +56,37 @@ const MenuLabel = styled.p`
cursor: pointer;
`;
-const SecondaryNavigation: FC = ({ label, children, collapsed, onCollapse }) => {
- const location = useLocation();
- const menuContext = useContext(MenuContext);
+const SecondaryNavigation: FC = ({ label, children }) => {
+ const menuContext = useMenuContext();
+ const isCollapsed = menuContext.isCollapsed();
- const subNavActive = isSubNavigationActive(children, location.pathname);
- const isCollapsed = collapsed && !subNavActive;
+ const toggleCollapseState = () => {
+ menuContext.setCollapsed(!isCollapsed);
+ };
- useEffect(() => {
- if (isMenuCollapsed()) {
- menuContext.setMenuCollapsed(!subNavActive);
+ const uncollapseMenu = () => {
+ if (isCollapsed) {
+ menuContext.setCollapsed(false);
}
- }, [subNavActive]);
+ };
- const childrenWithProps = React.Children.map(children, (child: ReactElement) =>
- React.cloneElement(child, { collapsed: isCollapsed })
- );
const arrowIcon = isCollapsed ? : ;
return (