Skip to content

Commit

Permalink
Refactor auth routes with <Outlet />s (#6334)
Browse files Browse the repository at this point in the history
* Refactor auth routes with <Outlet />s
* Eliminate all route components except the index routing tree
  • Loading branch information
eladlachmi committed Nov 15, 2023
1 parent 48470a8 commit 60b98cb
Show file tree
Hide file tree
Showing 34 changed files with 360 additions and 522 deletions.
90 changes: 46 additions & 44 deletions webui/src/lib/components/auth/layout.jsx
@@ -1,59 +1,61 @@
import React from "react";

import React, {useEffect, useState} from "react";
import {Outlet, useOutletContext} from "react-router-dom";
import Container from "react-bootstrap/Container";
import Row from "react-bootstrap/Row";
import Col from "react-bootstrap/Col";
import Nav from "react-bootstrap/Nav";
import Card from "react-bootstrap/Card";

import Layout from "../layout";
import {Link} from "../nav";
import {useLoginConfigContext} from "../../hooks/conf";


export const AuthLayout = ({ children, activeTab }) => {
export const AuthLayout = () => {
const [activeTab, setActiveTab] = useState("credentials");
const {RBAC: rbac} = useLoginConfigContext();
const [setIsLogged] = useOutletContext();
useEffect(() => {
setIsLogged(true);
}, [setIsLogged]);
return (
<Layout>
<Container fluid="xl">
<Row className="mt-5">
<Col md={{span: 3}}>
<Card>
<Card.Header>
<Card.Title>Access Control</Card.Title>
</Card.Header>
<Card.Body>
<Nav variant="pills" className="flex-column">
<Link component={Nav.Link} href="/auth/credentials" active={activeTab === 'credentials'}>
My Credentials
</Link>
</Nav>

<hr/>

<Nav variant="pills" className="flex-column">
<Link component={Nav.Link} href="/auth/users" active={activeTab === 'users'}>
Users
</Link>

<Link component={Nav.Link} href="/auth/groups" active={activeTab === 'groups'}>
Groups
</Link>
{rbac !== 'simplified' &&
<Link component={Nav.Link} href="/auth/policies" active={activeTab === 'policies'}>
Policies
</Link>}
</Nav>
</Card.Body>
</Card>

</Col>
<Col md={{span: 9}}>
{children}
</Col>
</Row>
</Container>
</Layout>
<Container fluid="xl">
<Row className="mt-5">
<Col md={{span: 3}}>
<Card>
<Card.Header>
<Card.Title>Access Control</Card.Title>
</Card.Header>
<Card.Body>
<Nav variant="pills" className="flex-column">
<Link component={Nav.Link} href="/auth/credentials" active={activeTab === 'credentials'}>
My Credentials
</Link>
</Nav>

<hr/>

<Nav variant="pills" className="flex-column">
<Link component={Nav.Link} href="/auth/users" active={activeTab === 'users'}>
Users
</Link>

<Link component={Nav.Link} href="/auth/groups" active={activeTab === 'groups'}>
Groups
</Link>
{rbac !== 'simplified' &&
<Link component={Nav.Link} href="/auth/policies" active={activeTab === 'policies'}>
Policies
</Link>}
</Nav>
</Card.Body>
</Card>

</Col>
<Col md={{span: 9}}>
<Outlet context={[setActiveTab]} />
</Col>
</Row>
</Container>
);
};

15 changes: 10 additions & 5 deletions webui/src/lib/components/layout.jsx
@@ -1,16 +1,21 @@
import React from "react";
import React, {useState} from "react";
import { Outlet } from "react-router-dom";
import { StorageConfigProvider } from "../hooks/storageConfig";

import TopNav from './navbar';

const Layout = ({ logged = true, children }) => {
const Layout = ({ logged }) => {
const [isLogged, setIsLogged] = useState(logged ?? true);
return (
<>
<TopNav logged={logged}/>
<TopNav logged={isLogged}/>
<div className="main-app">
{children}
<StorageConfigProvider>
<Outlet context={[setIsLogged]} />
</StorageConfigProvider>
</div>
</>
);
};

export default Layout;
export default Layout;
26 changes: 17 additions & 9 deletions webui/src/lib/components/repository/layout.jsx
Expand Up @@ -5,17 +5,23 @@ import Container from "react-bootstrap/Container";
import Breadcrumb from "react-bootstrap/Breadcrumb";

import {useRefs} from "../../hooks/repo";
import Layout from "../layout";
import { Outlet } from "react-router-dom";
import {RepositoryNavTabs} from "./tabs";
import {Link} from "../nav";
import { config } from "../../api";
import { useAPI } from "../../hooks/api";
import RepoOnboardingChecklistSlider from "./repoOnboardingChecklistSlider";
import { RefContextProvider } from "../../hooks/repo";

const RepoNav = () => {
const { repo } = useRefs();
const repoId = (repo) ? repo.id : '#';

const [repoId, setRepoId] = useState("");
useEffect(() => {
if (repo) {
setRepoId(repo.id);
}
}, [repo]);

return (
<Breadcrumb>
<Link href={{pathname: '/repositories'}} component={Breadcrumb.Item}>
Expand All @@ -25,11 +31,11 @@ const RepoNav = () => {
{repoId}
</Link>
</Breadcrumb>

)
);
};

export const RepositoryPageLayout = ({ activePage, children, fluid = "sm" }) => {
export const RepositoryPageLayout = ({ fluid = "sm" }) => {
const [activePage, setActivePage] = useState("objects");
const [showChecklist, setShowChecklist] = useLocalStorage(
"showChecklist",
false
Expand All @@ -53,7 +59,7 @@ export const RepositoryPageLayout = ({ activePage, children, fluid = "sm" }) =>
}, [response, setConfigRes]);

return (
<Layout>
<RefContextProvider>
<div>
{configRes && !dismissedChecklistForRepo && (
<RepoOnboardingChecklistSlider
Expand All @@ -68,9 +74,11 @@ export const RepositoryPageLayout = ({ activePage, children, fluid = "sm" }) =>
<RepositoryNavTabs active={activePage}/>

<Container fluid={fluid}>
<div className="mt-4">{children}</div>
<div className="mt-4">
<Outlet context={[setActivePage]} />
</div>
</Container>
</div>
</Layout>
</RefContextProvider>
);
};
13 changes: 5 additions & 8 deletions webui/src/pages/auth/credentials.jsx
@@ -1,6 +1,5 @@
import React from "react";

import {AuthLayout} from "../../lib/components/auth/layout";
import React, {useEffect} from "react";
import { useOutletContext } from "react-router-dom";
import {
ActionGroup,
ActionsBar,
Expand Down Expand Up @@ -81,11 +80,9 @@ const CredentialsContainer = () => {
};

const CredentialsPage = () => {
return (
<AuthLayout activeTab="credentials">
<CredentialsContainer/>
</AuthLayout>
);
const [setActiveTab] = useOutletContext();
useEffect(() => setActiveTab("credentials"), [setActiveTab]);
return <CredentialsContainer/>;
};


Expand Down
23 changes: 0 additions & 23 deletions webui/src/pages/auth/groups/group/index.jsx

This file was deleted.

11 changes: 4 additions & 7 deletions webui/src/pages/auth/groups/group/members.jsx
@@ -1,9 +1,8 @@
import React, {useEffect, useState} from "react";

import { useOutletContext } from "react-router-dom";
import Button from "react-bootstrap/Button";

import {GroupHeader} from "../../../../lib/components/auth/nav";
import {AuthLayout} from "../../../../lib/components/auth/layout";
import {useAPIWithPagination} from "../../../../lib/hooks/api";
import {auth} from "../../../../lib/api";
import {Paginator} from "../../../../lib/components/pagination";
Expand Down Expand Up @@ -120,11 +119,9 @@ const GroupMembersContainer = () => {
};

const GroupMembersPage = () => {
return (
<AuthLayout activeTab="groups">
<GroupMembersContainer/>
</AuthLayout>
);
const [setActiveTab] = useOutletContext();
useEffect(() => setActiveTab('groups'), [setActiveTab]);
return <GroupMembersContainer/>;
};

export default GroupMembersPage;
11 changes: 4 additions & 7 deletions webui/src/pages/auth/groups/group/policies.jsx
@@ -1,8 +1,7 @@
import React, {useEffect, useState} from "react";

import { useOutletContext } from "react-router-dom";
import Button from "react-bootstrap/Button";

import {AuthLayout} from "../../../../lib/components/auth/layout";
import {GroupHeader} from "../../../../lib/components/auth/nav";
import {useAPIWithPagination} from "../../../../lib/hooks/api";
import {auth} from "../../../../lib/api";
Expand Down Expand Up @@ -120,11 +119,9 @@ const GroupPoliciesContainer = () => {
};

const GroupPoliciesPage = () => {
return (
<AuthLayout activeTab="groups">
<GroupPoliciesContainer/>
</AuthLayout>
);
const [setActiveTab] = useOutletContext();
useEffect(() => setActiveTab('groups'), [setActiveTab]);
return <GroupPoliciesContainer/>;
};

export default GroupPoliciesPage;
26 changes: 6 additions & 20 deletions webui/src/pages/auth/groups/index.tsx
@@ -1,9 +1,8 @@
import React, {useEffect, useState} from "react";

import { useOutletContext } from "react-router-dom";
import Button from "react-bootstrap/Button";
import Dropdown from "react-bootstrap/Dropdown";

import {AuthLayout} from "../../../lib/components/auth/layout";
import {useAPIWithPagination} from "../../../lib/hooks/api";
import {auth} from "../../../lib/api";
import {ConfirmationButton} from "../../../lib/components/modals";
Expand All @@ -18,10 +17,8 @@ import {
Loading,
RefreshButton
} from "../../../lib/components/controls";
import {Route, Routes} from "react-router-dom";
import {useRouter} from "../../../lib/hooks/router";
import {Link} from "../../../lib/components/nav";
import GroupPage from "./group";
import {EntityActionModal} from "../../../lib/components/auth/forms";
import { disallowPercentSign, INVALID_GROUP_NAME_ERROR_MESSAGE } from "../validation";
import {useLoginConfigContext} from "../../../lib/hooks/conf";
Expand Down Expand Up @@ -184,21 +181,10 @@ const GroupsContainer = () => {
);
};

const GroupsPage = () => {
return (
<AuthLayout activeTab="groups">
<GroupsContainer/>
</AuthLayout>
);
export const GroupsPage = () => {
const [setActiveTab] = useOutletContext();
useEffect(() => setActiveTab('groups'), [setActiveTab]);
return <GroupsContainer/>;
};

const GroupsIndexPage = () => {
return (
<Routes>
<Route path=":groupId/*" element={<GroupPage/>} />
<Route path="" element={<GroupsPage/>} />
</Routes>
)
}

export default GroupsIndexPage;
export default GroupsPage;
25 changes: 0 additions & 25 deletions webui/src/pages/auth/index.jsx

This file was deleted.

5 changes: 1 addition & 4 deletions webui/src/pages/auth/login.tsx
@@ -1,5 +1,4 @@
import React, {useState} from "react";
import Layout from "../../lib/components/layout";
import Row from "react-bootstrap/Row";
import Card from "react-bootstrap/Card";
import Form from "react-bootstrap/Form";
Expand Down Expand Up @@ -100,9 +99,7 @@ const LoginPage = () => {
router.push({pathname: '/auth/login', query: router.query})
}
return (
<Layout logged={false}>
<LoginForm loginConfig={loginConfig}/>
</Layout>
<LoginForm loginConfig={loginConfig}/>
);
};

Expand Down

0 comments on commit 60b98cb

Please sign in to comment.