`
/* This is the counterpart to the specific column in SecondaryNavigationColumn. */
@@ -39,18 +35,13 @@ const PrimaryColumn = styled.div<{ collapsed: boolean }>`
}
`;
-export default class PrimaryContentColumn extends React.Component
{
- static defaultProps = {
- collapsed: false
- };
+const PrimaryContentColumn: FC = ({ children }) => {
+ const context = useMenuContext();
+ return (
+
+ {children}
+
+ );
+};
- render() {
- const { children, collapsed } = this.props;
-
- return (
-
- {children}
-
- );
- }
-}
+export default PrimaryContentColumn;
diff --git a/scm-ui/ui-components/src/layout/SecondaryNavigationColumn.tsx b/scm-ui/ui-components/src/layout/SecondaryNavigationColumn.tsx
index aae722bbe3..a974c8d438 100644
--- a/scm-ui/ui-components/src/layout/SecondaryNavigationColumn.tsx
+++ b/scm-ui/ui-components/src/layout/SecondaryNavigationColumn.tsx
@@ -21,13 +21,9 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
-import React, { ReactNode } from "react";
+import React, { FC } from "react";
import styled from "styled-components";
-
-type Props = {
- children?: ReactNode;
- collapsed: boolean;
-};
+import useMenuContext from "../navigation/MenuContext";
const SecondaryColumn = styled.div<{ collapsed: boolean }>`
/* In Bulma there is unfortunately no intermediate step between .is-1 and .is-2, hence the size.
@@ -42,18 +38,13 @@ const SecondaryColumn = styled.div<{ collapsed: boolean }>`
}
`;
-export default class SecondaryNavigationColumn extends React.Component {
- static defaultProps = {
- collapsed: false
- };
+const SecondaryNavigationColumn: FC = ({ children }) => {
+ const context = useMenuContext();
+ return (
+
+ {children}
+
+ );
+};
- render() {
- const { children, collapsed } = this.props;
-
- return (
-
- {children}
-
- );
- }
-}
+export default SecondaryNavigationColumn;
diff --git a/scm-ui/ui-components/src/navigation/SecondaryNavigation.tsx b/scm-ui/ui-components/src/navigation/SecondaryNavigation.tsx
index efb925c679..61e0860a18 100644
--- a/scm-ui/ui-components/src/navigation/SecondaryNavigation.tsx
+++ b/scm-ui/ui-components/src/navigation/SecondaryNavigation.tsx
@@ -22,7 +22,7 @@
* SOFTWARE.
*/
-import React, { FC, ReactElement, ReactNode} from "react";
+import React, {FC, ReactElement, ReactNode, useEffect, useMemo} from "react";
import styled from "styled-components";
import SubNavigation from "./SubNavigation";
import { matchPath, useLocation } from "react-router-dom";
@@ -64,10 +64,27 @@ const SecondaryNavigation: FC = ({ label, children}) => {
const location = useLocation();
const binder = useBinder();
const menuContext = useMenuContext();
-
const subNavActive = isSubNavigationActive(binder, children, location.pathname);
const isCollapsed = menuContext.isCollapsed();
+ useEffect(() => {
+ if (isCollapsed && subNavActive) {
+ menuContext.setCollapsed(false);
+ }
+ }, [subNavActive, isCollapsed]);
+
+ const toggleCollapseState = () => {
+ if (!subNavActive) {
+ menuContext.setCollapsed(!isCollapsed);
+ }
+ };
+
+ const uncollapseMenu = () => {
+ if (isCollapsed) {
+ menuContext.setCollapsed(false);
+ }
+ };
+
const arrowIcon = isCollapsed ? : ;
return (
@@ -76,7 +93,7 @@ const SecondaryNavigation: FC = ({ label, children}) => {
menuContext.setCollapsed(!isCollapsed) : undefined}
+ onClick={toggleCollapseState}
>
{!subNavActive && (
@@ -85,7 +102,7 @@ const SecondaryNavigation: FC = ({ label, children}) => {
)}
{isCollapsed ? "" : label}
-
+
);
diff --git a/scm-ui/ui-components/src/navigation/index.ts b/scm-ui/ui-components/src/navigation/index.ts
index 942beb0080..4dcce4321b 100644
--- a/scm-ui/ui-components/src/navigation/index.ts
+++ b/scm-ui/ui-components/src/navigation/index.ts
@@ -31,5 +31,5 @@ export { default as SubNavigation } from "./SubNavigation";
export { default as PrimaryNavigation } from "./PrimaryNavigation";
export { default as PrimaryNavigationLink } from "./PrimaryNavigationLink";
export { default as SecondaryNavigation } from "./SecondaryNavigation";
-export { MenuContext, LocalStorageMenuContextProvider } from "./MenuContext";
+export { MenuContext, StateMenuContextProvider } from "./MenuContext";
export { default as SecondaryNavigationItem } from "./SecondaryNavigationItem";
diff --git a/scm-ui/ui-components/src/repos/DiffFile.tsx b/scm-ui/ui-components/src/repos/DiffFile.tsx
index 5d6381a971..981423fabe 100644
--- a/scm-ui/ui-components/src/repos/DiffFile.tsx
+++ b/scm-ui/ui-components/src/repos/DiffFile.tsx
@@ -34,7 +34,6 @@ import { Change, ChangeEvent, DiffObjectProps, File, Hunk as HunkType } from "./
import TokenizedDiffView from "./TokenizedDiffView";
import DiffButton from "./DiffButton";
import { MenuContext } from "@scm-manager/ui-components";
-import { storeMenuCollapsed } from "../navigation";
const EMPTY_ANNOTATION_FACTORY = {};
@@ -132,7 +131,6 @@ class DiffFile extends React.Component