Skip to content

Commit 046fc6b

Browse files
committed
feat: clean the URL and save the dashboard in the sessionStorage
1 parent 2110a52 commit 046fc6b

5 files changed

Lines changed: 57 additions & 39 deletions

File tree

packages/diracx-web-components/src/components/DashboardLayout/DrawerItem.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
useTheme,
1111
TextField,
1212
} from "@mui/material";
13-
import { DragIndicator } from "@mui/icons-material";
13+
import { DragIndicator, Apps } from "@mui/icons-material";
1414
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
1515
import {
1616
draggable,
@@ -28,8 +28,8 @@ import { ApplicationsContext } from "../../contexts/ApplicationsProvider";
2828
import { DashboardGroup } from "../../types";
2929

3030
interface DrawerItemProps {
31-
/** The item object containing the title, id, and icon. */
32-
item: { title: string; id: string; icon: React.ComponentType };
31+
/** The item object containing the title, id, and the appType. */
32+
item: { title: string; id: string; type: string };
3333
/** The index of the item. */
3434
index: number;
3535
/** The title of the group. */
@@ -52,7 +52,7 @@ interface DrawerItemProps {
5252
* @returns The rendered JSX for the drawer item.
5353
*/
5454
export default function DrawerItem({
55-
item: { title, id, icon },
55+
item: { title, id, type },
5656
index,
5757
groupTitle,
5858
renamingItemId,
@@ -69,7 +69,10 @@ export default function DrawerItem({
6969
// Represents the closest edge to the mouse cursor
7070
const [closestEdge, setClosestEdge] = useState<Edge | null>(null);
7171

72-
const [, , , appId, setCurrentAppId] = useContext(ApplicationsContext);
72+
const [, , appList, appId, setCurrentAppId] = useContext(ApplicationsContext);
73+
const { icon } = appList.find((app) => app.name === type) || {
74+
icon: Apps,
75+
};
7376

7477
useEffect(() => {
7578
if (!dragRef.current || !handleRef.current) return;
@@ -184,7 +187,7 @@ export default function DrawerItem({
184187
<ListItemButton
185188
disableGutters
186189
key={title}
187-
onClick={() => setCurrentAppId(id)} //setParam("appId", id)}
190+
onClick={() => setCurrentAppId(id)}
188191
sx={{ pl: 2, borderRadius: 2, pr: 1 }}
189192
ref={dragRef}
190193
selected={appId === id}

packages/diracx-web-components/src/components/DashboardLayout/DrawerItemGroup.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
AccordionSummary,
77
TextField,
88
} from "@mui/material";
9-
import { ExpandMore, Apps } from "@mui/icons-material";
9+
import { ExpandMore } from "@mui/icons-material";
1010
import React, { useEffect, useRef, useState } from "react";
1111
import { dropTargetForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
1212
import { DashboardGroup } from "../../types/DashboardGroup";
@@ -139,20 +139,22 @@ export default function DrawerItemGroup({
139139
</AccordionSummary>
140140
{/* Accordion details */}
141141
<AccordionDetails>
142-
{items.map(({ title: itemTitle, id, icon }, index) => (
143-
<div onContextMenu={handleContextMenu("item", id)} key={id}>
144-
<DrawerItem
145-
item={{ title: itemTitle, id, icon: icon || Apps }}
146-
index={index}
147-
groupTitle={title}
148-
renamingItemId={renamingItemId}
149-
setRenamingItemId={setRenamingItemId}
150-
renameValue={renameValue}
151-
setRenameValue={setRenameValue}
152-
setUserDashboard={setUserDashboard}
153-
/>
154-
</div>
155-
))}
142+
{items.map(({ title: itemTitle, id, type }, index) => {
143+
return (
144+
<div onContextMenu={handleContextMenu("item", id)} key={id}>
145+
<DrawerItem
146+
item={{ title: itemTitle, id, type }}
147+
index={index}
148+
groupTitle={title}
149+
renamingItemId={renamingItemId}
150+
setRenamingItemId={setRenamingItemId}
151+
renameValue={renameValue}
152+
setRenameValue={setRenameValue}
153+
setUserDashboard={setUserDashboard}
154+
/>
155+
</div>
156+
);
157+
})}
156158
</AccordionDetails>
157159
</Accordion>
158160
);

packages/diracx-web-components/src/components/Login/LoginForm.tsx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import React, { useState, useEffect } from "react";
3+
import React, { useState, useEffect, useContext } from "react";
44
import Box from "@mui/material/Box";
55
import Typography from "@mui/material/Typography";
66
import FormControl from "@mui/material/FormControl";
@@ -15,6 +15,8 @@ import { useOidc } from "@axa-fr/react-oidc";
1515
import { useMetadata, Metadata } from "../../hooks/metadata";
1616
import { useOIDCContext } from "../../hooks/oidcConfiguration";
1717

18+
import { useSearchParamsUtils } from "../../hooks/searchParamsUtils";
19+
import { NavigationContext } from "../../contexts/NavigationProvider";
1820
import { useDiracxUrl } from "../../hooks";
1921

2022
interface LoginFormProps {
@@ -37,6 +39,9 @@ export function LoginForm({
3739
const { configuration, setConfiguration } = useOIDCContext();
3840
const { isAuthenticated, login } = useOidc(configuration?.scope);
3941

42+
const { getParam } = useSearchParamsUtils();
43+
const { setPath } = useContext(NavigationContext);
44+
4045
// Login if not authenticated
4146
useEffect(() => {
4247
if (configuration && configuration.scope && isAuthenticated === false) {
@@ -45,18 +50,18 @@ export function LoginForm({
4550
}
4651
}, [configuration, isAuthenticated, login]);
4752

48-
// useEffect(() => {
49-
// // Redirect to dashboard if already authenticated
50-
// if (isAuthenticated) {
51-
// const redirect = getParam("redirect");
52-
// console.log("Redirecting to:", redirect);
53-
// if (redirect) {
54-
// setPath(redirect);
55-
// } else {
56-
// setPath("/");
57-
// }
58-
// }
59-
// }, [getParam, isAuthenticated, setPath]);
53+
useEffect(() => {
54+
// Redirect to dashboard if already authenticated
55+
if (isAuthenticated) {
56+
const redirect = getParam("redirect");
57+
console.log("Redirecting to:", redirect);
58+
if (redirect) {
59+
setPath(redirect);
60+
} else {
61+
setPath("/");
62+
}
63+
}
64+
}, [getParam, isAuthenticated, setPath]);
6065

6166
// Get default group
6267
const getDefaultGroup = (

packages/diracx-web-components/src/contexts/ApplicationsProvider.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use client";
22

33
import React, { createContext, useEffect, useState } from "react";
4-
import { Monitor } from "@mui/icons-material";
54
import { applicationList } from "../components/ApplicationList";
65
import { DashboardGroup } from "../types/DashboardGroup";
76
import ApplicationMetadata from "../types/ApplicationMetadata";
@@ -36,7 +35,14 @@ export const ApplicationsProvider = ({
3635
appList = applicationList,
3736
defaultUserDashboard,
3837
}: ApplicationsProviderProps) => {
39-
const [userDashboard, setUserDashboard] = useState<DashboardGroup[]>([]);
38+
const loadedDashboard = sessionStorage.getItem("savedDashboard");
39+
const parsedDashboard: DashboardGroup[] = loadedDashboard
40+
? JSON.parse(loadedDashboard)
41+
: null;
42+
43+
const [userDashboard, setUserDashboard] = useState<DashboardGroup[]>(
44+
parsedDashboard || [],
45+
);
4046

4147
const [currentAppId, setCurrentAppId] = useState<string>("");
4248

@@ -53,14 +59,18 @@ export const ApplicationsProvider = ({
5359
title: "My Jobs",
5460
type: "Job Monitor",
5561
id: "JobMonitor0",
56-
icon: Monitor,
5762
},
5863
],
5964
},
6065
],
6166
);
6267
}, [appList, defaultUserDashboard]);
6368

69+
// Save the dashboard in session storage
70+
useEffect(() => {
71+
sessionStorage.setItem("savedDashboard", JSON.stringify(userDashboard));
72+
}, [userDashboard]);
73+
6474
return (
6575
<ApplicationsContext.Provider
6676
value={[
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
"use client";
22

3-
import { SvgIconComponent } from "@mui/icons-material";
43
import { InternalFilter } from "./Filter";
54

65
// Define the type for the Dashboard Item state
76
export interface DashboardItem {
87
title: string;
98
type: string;
109
id: string;
11-
icon: SvgIconComponent | null;
1210
data?: InternalFilter[];
1311
}

0 commit comments

Comments
 (0)