Skip to content

Commit 2110a52

Browse files
committed
chore(url): remove everything from the url
1 parent edbb3f2 commit 2110a52

8 files changed

Lines changed: 52 additions & 123 deletions

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ export default function DashboardDrawer({
7777

7878
// Define the applications that are accessible to users.
7979
// Each application has an associated icon and path.
80-
const [userDashboard, setUserDashboard] = useContext(ApplicationsContext);
80+
const [userDashboard, setUserDashboard, , , setCurrentAppId] =
81+
useContext(ApplicationsContext);
8182

8283
const theme = useTheme();
8384

@@ -247,6 +248,7 @@ export default function DashboardDrawer({
247248
userDashboard.map((g) => (g.title === group.title ? group : g)),
248249
);
249250
}
251+
setCurrentAppId(newApp.id);
250252
};
251253

252254
let isContextStateStable = true;

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

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

3-
import React, { useEffect, useRef, useState } from "react";
3+
import React, { useContext, useEffect, useRef, useState } from "react";
44
import { createRoot } from "react-dom/client";
55
import {
66
ListItemButton,
@@ -24,8 +24,7 @@ import {
2424
} from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
2525
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
2626
import { ThemeProvider } from "../../contexts/ThemeProvider";
27-
import { useSearchParamsUtils } from "../../hooks/searchParamsUtils";
28-
import { useApplicationId } from "../../hooks/application";
27+
import { ApplicationsContext } from "../../contexts/ApplicationsProvider";
2928
import { DashboardGroup } from "../../types";
3029

3130
interface DrawerItemProps {
@@ -67,11 +66,10 @@ export default function DrawerItem({
6766
// Ref to use for the handle of the draggable element, must be a child of the draggable element
6867
const handleRef = useRef(null);
6968
const theme = useTheme();
70-
const { setParam } = useSearchParamsUtils();
7169
// Represents the closest edge to the mouse cursor
7270
const [closestEdge, setClosestEdge] = useState<Edge | null>(null);
7371

74-
const appId = useApplicationId();
72+
const [, , , appId, setCurrentAppId] = useContext(ApplicationsContext);
7573

7674
useEffect(() => {
7775
if (!dragRef.current || !handleRef.current) return;
@@ -186,7 +184,7 @@ export default function DrawerItem({
186184
<ListItemButton
187185
disableGutters
188186
key={title}
189-
onClick={() => setParam("appId", id)}
187+
onClick={() => setCurrentAppId(id)} //setParam("appId", id)}
190188
sx={{ pl: 2, borderRadius: 2, pr: 1 }}
191189
ref={dragRef}
192190
selected={appId === id}

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

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

3-
import React, { useState, useEffect, useContext } from "react";
3+
import React, { useState, useEffect } from "react";
44
import Box from "@mui/material/Box";
55
import Typography from "@mui/material/Typography";
66
import FormControl from "@mui/material/FormControl";
@@ -15,8 +15,6 @@ 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";
2018
import { useDiracxUrl } from "../../hooks";
2119

2220
interface LoginFormProps {
@@ -32,16 +30,13 @@ interface LoginFormProps {
3230
export function LoginForm({
3331
logoURL = "/DIRAC-logo-minimal.png",
3432
}: LoginFormProps) {
35-
const { setPath } = useContext(NavigationContext);
3633
const diracxUrl = useDiracxUrl();
3734
const { metadata, error, isLoading } = useMetadata(diracxUrl);
3835
const [selectedVO, setSelectedVO] = useState<string | null>(null);
3936
const [selectedGroup, setSelectedGroup] = useState<string | null>(null);
4037
const { configuration, setConfiguration } = useOIDCContext();
4138
const { isAuthenticated, login } = useOidc(configuration?.scope);
4239

43-
const { getParam } = useSearchParamsUtils();
44-
4540
// Login if not authenticated
4641
useEffect(() => {
4742
if (configuration && configuration.scope && isAuthenticated === false) {
@@ -50,18 +45,18 @@ export function LoginForm({
5045
}
5146
}, [configuration, isAuthenticated, login]);
5247

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]);
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]);
6560

6661
// Get default group
6762
const getDefaultGroup = (

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

Lines changed: 25 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,21 @@
11
"use client";
22

3-
import React, {
4-
createContext,
5-
useCallback,
6-
useMemo,
7-
useEffect,
8-
useState,
9-
} from "react";
3+
import React, { createContext, useEffect, useState } from "react";
104
import { Monitor } from "@mui/icons-material";
11-
import JSONCrush from "jsoncrush";
12-
import { useSearchParamsUtils } from "../hooks/searchParamsUtils";
135
import { applicationList } from "../components/ApplicationList";
146
import { DashboardGroup } from "../types/DashboardGroup";
157
import ApplicationMetadata from "../types/ApplicationMetadata";
16-
import { DashboardItem } from "../types/DashboardItem";
178

189
// Create a context for the UserDashboard state
1910
export const ApplicationsContext = createContext<
2011
[
2112
DashboardGroup[],
2213
React.Dispatch<React.SetStateAction<DashboardGroup[]>>,
2314
ApplicationMetadata[],
15+
string, // Id of the current application
16+
React.Dispatch<React.SetStateAction<string>>,
2417
]
25-
>([[], () => {}, []]);
18+
>([[], () => {}, [], "", () => {}]);
2619

2720
interface ApplicationsProviderProps {
2821
children: React.ReactNode;
@@ -45,88 +38,39 @@ export const ApplicationsProvider = ({
4538
}: ApplicationsProviderProps) => {
4639
const [userDashboard, setUserDashboard] = useState<DashboardGroup[]>([]);
4740

48-
const { getParam, setParam } = useSearchParamsUtils();
49-
50-
// save user dashboard to searchParams (but not icons)
51-
const setUserDashboardParams = useCallback(
52-
(
53-
groups: DashboardGroup[] | ((prev: DashboardGroup[]) => DashboardGroup[]),
54-
) => {
55-
if (typeof groups === "function") {
56-
groups = groups(userDashboard);
57-
}
58-
const newSections = groups.map((group) => {
59-
return {
60-
...group,
61-
items: group.items.map((item) => {
62-
return {
63-
...item,
64-
icon: () => null,
65-
};
66-
}),
67-
};
68-
});
69-
setParam("dashboard", JSONCrush.crush(JSON.stringify(newSections)));
70-
},
71-
[setParam, userDashboard],
72-
);
73-
74-
// get user sections from searchParams
75-
const groupsParams = useMemo(() => getParam("dashboard"), [getParam]);
41+
const [currentAppId, setCurrentAppId] = useState<string>("");
7642

7743
useEffect(() => {
7844
if (userDashboard.length !== 0) return;
79-
if (groupsParams) {
80-
const uncrushed = JSONCrush.uncrush(groupsParams);
81-
try {
82-
const newSections: DashboardGroup[] = JSON.parse(uncrushed).map(
83-
(group: DashboardGroup) => {
84-
group.items = group.items.map((item: DashboardItem) => {
85-
return {
86-
...item,
87-
//get icon from appList
88-
icon:
89-
appList.find((app) => app.name === item.type)?.icon || null,
90-
};
91-
});
92-
return group;
93-
},
94-
);
95-
if (newSections !== userDashboard) {
96-
setUserDashboard(newSections);
97-
}
98-
} catch (e) {
99-
console.error("Error parsing user dashboard : ", uncrushed, e);
100-
}
101-
} else {
102-
setUserDashboard(
103-
defaultUserDashboard || [
104-
{
105-
title: "My dashboard",
106-
extended: true,
107-
items: [
108-
{
109-
title: "My Jobs",
110-
type: "Job Monitor",
111-
id: "JobMonitor0",
112-
icon: Monitor,
113-
},
114-
],
115-
},
116-
],
117-
);
118-
}
119-
}, [appList, defaultUserDashboard, groupsParams]);
45+
46+
setUserDashboard(
47+
defaultUserDashboard || [
48+
{
49+
title: "My dashboard",
50+
extended: true,
51+
items: [
52+
{
53+
title: "My Jobs",
54+
type: "Job Monitor",
55+
id: "JobMonitor0",
56+
icon: Monitor,
57+
},
58+
],
59+
},
60+
],
61+
);
62+
}, [appList, defaultUserDashboard]);
12063

12164
return (
12265
<ApplicationsContext.Provider
12366
value={[
12467
userDashboard,
12568
(group) => {
12669
setUserDashboard(group);
127-
setUserDashboardParams(group);
12870
},
12971
appList,
72+
currentAppId,
73+
setCurrentAppId,
13074
]}
13175
>
13276
{children}

packages/diracx-web-components/src/hooks/application.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,22 @@
22

33
import { useContext, useMemo } from "react";
44
import { ApplicationsContext } from "../contexts/ApplicationsProvider";
5-
import { useSearchParamsUtils } from "./searchParamsUtils";
65

76
/**
8-
* Custom hook to access the application id from the URL
7+
* Custom hook to access the application id from the context
98
* @returns the application id
109
*/
1110
export function useApplicationId() {
12-
const { getParam } = useSearchParamsUtils();
13-
14-
return useMemo(() => {
15-
return getParam("appId");
16-
}, [getParam]);
11+
const [, , , appId] = useContext(ApplicationsContext);
12+
return appId;
1713
}
1814

1915
/**
2016
* Custom hook to access the application title based on the application id
2117
* @returns the application title
2218
*/
2319
export function useApplicationTitle() {
24-
const [userDashboard] = useContext(ApplicationsContext);
25-
const appId = useApplicationId();
20+
const [userDashboard, , , appId] = useContext(ApplicationsContext);
2621

2722
return useMemo(() => {
2823
if (!userDashboard || !appId) return null;
@@ -40,7 +35,7 @@ export function useApplicationTitle() {
4035

4136
/**
4237
* Custom hook to access the application title based on the application id
43-
* @returns the application title
38+
* @returns the application type
4439
*/
4540
export function useApplicationType() {
4641
const [userDashboard] = useContext(ApplicationsContext);

packages/diracx-web-components/src/hooks/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ export * from "./oidcConfiguration";
33
export * from "./searchParamsUtils";
44
export * from "./theme";
55
export * from "./utils";
6-
export * from "./application";

packages/diracx-web-components/test/LoginForm.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { render, fireEvent, screen } from "@testing-library/react";
2-
import React from "react";
32
import { LoginForm } from "../src/components/Login/LoginForm";
43
import { ThemeProvider } from "../src/contexts/ThemeProvider";
54
import { useMetadata } from "../src/hooks/metadata";
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
"use client";
22
import { useContext, useMemo } from "react";
3-
import { useSearchParams } from "next/navigation";
43
import {
54
BaseApp,
65
applicationList,
76
} from "@dirac-grid/diracx-web-components/components";
87
import { ApplicationsContext } from "@dirac-grid/diracx-web-components/contexts";
98

109
export default function Page() {
11-
const searchParams = useSearchParams();
12-
const appId = searchParams.get("appId");
13-
const [userDashboard] = useContext(ApplicationsContext);
10+
const [userDashboard, , , appId] = useContext(ApplicationsContext);
1411

1512
const appType = useMemo(() => {
1613
const group = userDashboard.find((group) =>
@@ -23,5 +20,5 @@ export default function Page() {
2320
return applicationList.find((app) => app.name === appType)?.component;
2421
}, [appType]);
2522

26-
return Component ? <Component /> : <BaseApp />;
23+
return Component ? <Component key={appId} /> : <BaseApp />;
2724
}

0 commit comments

Comments
 (0)