Skip to content

Commit 19f2efa

Browse files
committed
multiple persona
1. state.user.role. 2. add file-browser.
1 parent d02c7ee commit 19f2efa

File tree

11 files changed

+121
-10
lines changed

11 files changed

+121
-10
lines changed

src/App.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import "./app.css";
2-
import "@patternfly/react-core/dist/styles/base.css";
32
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
43
import { App as AntdApp, ConfigProvider, theme } from "antd";
54
import { useContext } from "react";

src/api/api.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import config from "config";
2-
import { keyBy } from "lodash";
32
import { Cookies } from "react-cookie";
4-
import { T } from "vitest/dist/chunks/environment.C5eAp3K6.js";
53

64
export type Query = Record<string, any>;
75

src/components/Wrapper/Sidebar.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,7 @@
1414
border: none;
1515
font-weight: 400;
1616
}
17+
18+
.hide {
19+
display: none;
20+
}

src/components/Wrapper/Sidebar.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
PageSidebarBody,
88
Brand,
99
NavExpandable,
10+
NavItemSeparator,
1011
} from "@patternfly/react-core";
1112
import { type DefaultError, useQueryClient } from "@tanstack/react-query";
1213
import { isEmpty } from "lodash";
@@ -33,6 +34,7 @@ const Sidebar: React.FC<AllProps> = (props: AllProps) => {
3334
const { sidebarActiveItem, isNavOpen, isTagExpanded, isPackageTagExpanded } =
3435
useAppSelector((state) => state.ui);
3536
const isLoggedIn = useAppSelector((state) => state.user.isLoggedIn);
37+
const role = useAppSelector((state) => state.user.role);
3638
const dispatch = useAppDispatch();
3739

3840
const { onTagToggle, onPackageTagToggle } = props;
@@ -165,6 +167,10 @@ const Sidebar: React.FC<AllProps> = (props: AllProps) => {
165167
{renderLink("/shared", "Shared Data", "shared")}
166168
</NavItem>
167169

170+
<NavItem itemId="lib" isActive={sidebarActiveItem === "lib"}>
171+
{renderLink("/library", "Library", "lib")}
172+
</NavItem>
173+
168174
<NavExpandable
169175
title="Tags"
170176
buttonProps={{ className: styles["tags-expand"] }}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.role-prompt {
2+
margin-right: 5px;
3+
}

src/components/Wrapper/Toolbar.tsx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,17 @@ import {
2323
useAppSelector,
2424
useSignUpAllowed,
2525
} from "../../store/hooks";
26-
import { setLogoutSuccess } from "../../store/user/userSlice";
26+
import {
27+
setLogoutSuccess,
28+
Roles,
29+
StaffRoles,
30+
type Role,
31+
setRole,
32+
} from "../../store/user/userSlice";
2733
import { ThemeContext } from "../DarkTheme/useTheme";
2834
import FeedDetails from "../FeedDetails";
2935
import CartNotify from "./CartNotify";
36+
import styles from "./Toolbar.module.css";
3037

3138
type ToolbarComponentProps = {
3239
showToolbar: boolean;
@@ -47,8 +54,12 @@ const ToolbarComponent: React.FC<ToolbarComponentProps> = (
4754
const { isDarkTheme, toggleTheme } = React.useContext(ThemeContext);
4855
const queryClient = useQueryClient();
4956
const username = useAppSelector((state) => state.user.username);
57+
const role = useAppSelector((state) => state.user.role);
58+
const isStaff = useAppSelector((state) => state.user.isStaff);
5059
const [dropdownOpen, setIsDropdownOpen] = React.useState(false);
60+
const [roleDropdownOpen, setIsRoleDropdownOpen] = React.useState(false);
5161
const [trayOpen, setTrayOpen] = React.useState(false); // State for tray visibility
62+
const roles = isStaff ? StaffRoles : Roles;
5263

5364
const handleChange = () => {
5465
toggleTheme();
@@ -74,6 +85,10 @@ const ToolbarComponent: React.FC<ToolbarComponentProps> = (
7485
setIsDropdownOpen(!dropdownOpen);
7586
};
7687

88+
const onRoleDropdownToggle = () => {
89+
setIsRoleDropdownOpen(!roleDropdownOpen);
90+
};
91+
7792
const copyLoginCommand = () => {
7893
const url = `${window.location.protocol}://${window.location.host}`;
7994
const command = `chrs login --ui "${url}" --cube "${
@@ -92,6 +107,17 @@ const ToolbarComponent: React.FC<ToolbarComponentProps> = (
92107
</DropdownItem>,
93108
];
94109

110+
const renderRoleDropdownItem = (role: Role, idx: number) => {
111+
return (
112+
<DropdownItem
113+
key={`role-${idx}`}
114+
onClick={() => dispatch(setRole({ role }))}
115+
>
116+
{role}
117+
</DropdownItem>
118+
);
119+
};
120+
95121
const toggleTray = () => {
96122
setTrayOpen(!trayOpen);
97123
};
@@ -141,6 +167,22 @@ const ToolbarComponent: React.FC<ToolbarComponentProps> = (
141167
ouiaId="Basic Switch"
142168
/>
143169
</FlexItem>
170+
<FlexItem>
171+
<span className={styles["role-prompt"]}>I am: </span>
172+
<Dropdown
173+
onSelect={onRoleDropdownToggle}
174+
isOpen={roleDropdownOpen}
175+
toggle={(toggleRef) => (
176+
<MenuToggle ref={toggleRef} onClick={onRoleDropdownToggle}>
177+
{role}
178+
</MenuToggle>
179+
)}
180+
>
181+
<DropdownList>
182+
{roles.map((each, idx) => renderRoleDropdownItem(each, idx))}
183+
</DropdownList>
184+
</Dropdown>
185+
</FlexItem>
144186
<FlexItem>
145187
{token ? (
146188
<Dropdown

src/components/Wrapper/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ const Wrapper = (props: WrapperProps) => {
8080
}
8181
sidebar={sidebar}
8282
>
83-
{" "}
8483
{children}
8584
</Page>
8685
);

src/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
font-size: var(--pf-v5-c-nav__section-title--FontSize);
88
color: #eeaa00;
99
border-block-end: var(--pf-v5-c-nav__section-title--BorderBottomWidth) solid var(--pf-v5-c-nav__section-title--BorderBottomColor);
10-
}
10+
}

src/main.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import App from "./App.tsx";
44
import { setupStore } from "./store/configureStore.ts";
55
import { ThemeContextProvider } from "./components/DarkTheme/useTheme.tsx";
66
import { enableMapSet } from "immer";
7+
8+
import "@patternfly/react-core/dist/styles/base.css";
9+
710
import "./main.css";
811

912
enableMapSet();

src/routes.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Store from "./components/NewStore";
2828
import { useAppDispatch, useAppSelector } from "./store/hooks";
2929
import { setSidebarActive } from "./store/ui/uiSlice";
3030
import { OperationsProvider } from "./components/NewLibrary/context";
31+
import GnomeLibrary from "./components/GnomeLibrary";
3132

3233
interface IState {
3334
selectData?: Series;
@@ -127,7 +128,21 @@ export const MainRouter: React.FC = () => {
127128
path: "/",
128129
element: <Dashboard />,
129130
},
130-
131+
{
132+
path: "library/*",
133+
element: (
134+
<PrivateRoute>
135+
<RouterProvider
136+
{...{ actions, state, route, setRoute }}
137+
context={MainRouterContext}
138+
>
139+
<OperationsProvider>
140+
<GnomeLibrary />
141+
</OperationsProvider>
142+
</RouterProvider>
143+
</PrivateRoute>
144+
),
145+
},
131146
{
132147
path: "data/*",
133148
element: (

0 commit comments

Comments
 (0)