Skip to content

Commit e429b91

Browse files
authored
Merge pull request #357 from TheauW/twartel-clear-url
fix: remove the dashboard from the url and remove the BaseApp
2 parents e789a58 + 2116630 commit e429b91

31 files changed

Lines changed: 336 additions & 568 deletions

docs/user/list_and_share_applications.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,6 @@ When managing multiple instances of the same application, grouping can help you
9494

9595
### Share and import the settings of an application
9696

97-
1. **Share**: You can share the status of an app by clicking on the share button in the top-right corner of the screen. After clicking, you can select which group and app you want to share and then copy a text corresponding to the states of the selected applications.
97+
1. **Share**: You can export the status of an app by clicking on the share button in the top-right corner of the screen. After clicking, you can select which group and app you want to share and then copy a text corresponding to the states of the selected applications.
9898

99-
2. **Import**: Next to the share button you can find the import button. You can paste into the window opened by the button the text corresponding to one or multiple shared apps. This will create a new group named *Imported App* with the imported applications and their settings.
99+
2. **Import**: Next to the export button you can find the import button. You can paste into the window opened by the button the text corresponding to one or multiple shared apps. This will create a new group named *Imported App* with the imported applications and their settings.

package-lock.json

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/diracx-web-components/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
"@types/react": "^18.3.12",
3636
"@types/react-dom": "^18.3.1",
3737
"dayjs": "^1.11.13",
38-
"jsoncrush": "^1.1.8",
3938
"react": "^18.3.1",
4039
"react-dom": "^18.3.1",
4140
"react-virtuoso": "^4.12.3",

packages/diracx-web-components/src/components/ApplicationList.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
"use client";
22

3-
import { Dashboard, FolderCopy, Monitor } from "@mui/icons-material";
3+
import { FolderCopy, Monitor } from "@mui/icons-material";
44
import ApplicationMetadata from "../types/ApplicationMetadata";
55
import JobMonitor from "./JobMonitor/JobMonitor";
6-
import BaseApp from "./BaseApp/BaseApp";
76

87
export const applicationList: ApplicationMetadata[] = [
9-
{ name: "Base Application", component: BaseApp, icon: Dashboard },
108
{
119
name: "Job Monitor",
1210
component: JobMonitor,

packages/diracx-web-components/src/components/BaseApp/BaseApp.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

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

Lines changed: 0 additions & 1 deletion
This file was deleted.

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

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

3-
import { useState, useContext } from "react";
3+
import { useContext } from "react";
44
import {
55
Dialog,
66
DialogTitle,
@@ -11,7 +11,7 @@ import {
1111
Icon,
1212
IconButton,
1313
} from "@mui/material";
14-
import { Close, SvgIconComponent } from "@mui/icons-material";
14+
import { Close } from "@mui/icons-material";
1515
import { ApplicationsContext } from "../../contexts/ApplicationsProvider";
1616

1717
interface AppDialogProps {
@@ -20,7 +20,7 @@ interface AppDialogProps {
2020
/** Function to set the open state of the dialog. */
2121
setAppDialogOpen: React.Dispatch<React.SetStateAction<boolean>>;
2222
/** Function to handle the creation of a new application. */
23-
handleCreateApp: (name: string, icon: SvgIconComponent) => void;
23+
handleCreateApp: (name: string) => void;
2424
}
2525

2626
/**
@@ -34,31 +34,12 @@ export default function AppDialog({
3434
setAppDialogOpen,
3535
handleCreateApp,
3636
}: AppDialogProps) {
37-
const [appType, setAppType] = useState("");
3837
const applicationList = useContext(ApplicationsContext)[2];
3938
return (
4039
<Dialog
4140
open={appDialogOpen}
4241
onClose={() => setAppDialogOpen(false)}
4342
aria-labelledby="application-dialog-label"
44-
PaperProps={{
45-
component: "form",
46-
onSubmit: (event: React.FormEvent<HTMLFormElement>) => {
47-
event.preventDefault();
48-
49-
const icon = applicationList.find(
50-
(app) => app.name === appType,
51-
)?.icon;
52-
if (!icon) {
53-
console.error("Icon not found for application type", appType);
54-
return;
55-
}
56-
57-
handleCreateApp(appType, icon);
58-
59-
setAppDialogOpen(false);
60-
},
61-
}}
6243
fullWidth
6344
maxWidth="sm"
6445
>
@@ -90,9 +71,10 @@ export default function AppDialog({
9071
fullWidth
9172
variant="outlined"
9273
onClick={() => {
93-
setAppType(app.name);
74+
handleCreateApp(app.name);
75+
setAppDialogOpen(false);
9476
}}
95-
type="submit"
77+
data-testid="create-application-button"
9678
>
9779
<Icon component={app.icon} sx={{ mr: 1 }} />
9880
{app.name}

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

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
Toolbar,
1717
useTheme,
1818
} from "@mui/material";
19-
import { MenuBook, Add, SvgIconComponent } from "@mui/icons-material";
19+
import { MenuBook, Add } from "@mui/icons-material";
2020
import React, { useContext, useEffect, useState } from "react";
2121
import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
2222
import { extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
@@ -80,7 +80,8 @@ export default function DashboardDrawer({
8080

8181
// Define the applications that are accessible to users.
8282
// Each application has an associated icon and path.
83-
const [userDashboard, setUserDashboard] = useContext(ApplicationsContext);
83+
const [userDashboard, setUserDashboard, , , setCurrentAppId] =
84+
useContext(ApplicationsContext);
8485

8586
const theme = useTheme();
8687

@@ -210,9 +211,8 @@ export default function DashboardDrawer({
210211
* Handles the creation of a new app in the dashboard drawer.
211212
*
212213
* @param appType - The type of the app to be created.
213-
* @param icon - The icon component for the app.
214214
*/
215-
const handleAppCreation = (appType: string, icon: SvgIconComponent) => {
215+
const handleAppCreation = (appType: string) => {
216216
let group = userDashboard[userDashboard.length - 1];
217217
const empty = !group;
218218
if (empty) {
@@ -224,14 +224,13 @@ export default function DashboardDrawer({
224224
};
225225
}
226226

227-
let title = `${appType} ${userDashboard.reduce(
227+
const count = userDashboard.reduce(
228228
(sum, group) =>
229229
sum + group.items.filter((item) => item.type === appType).length,
230-
1,
231-
)}`;
232-
while (group.items.some((item) => item.title === title)) {
233-
title = `${appType} ${parseInt(title.split(" ")[1]) + 1}`;
234-
}
230+
0,
231+
);
232+
233+
const title = count > 0 ? `${appType} ${count + 1}` : `${appType}`;
235234

236235
const newApp = {
237236
title,
@@ -240,7 +239,6 @@ export default function DashboardDrawer({
240239
0,
241240
)}`,
242241
type: appType,
243-
icon: icon,
244242
};
245243
group.items.push(newApp);
246244
if (empty) {
@@ -250,6 +248,7 @@ export default function DashboardDrawer({
250248
userDashboard.map((g) => (g.title === group.title ? group : g)),
251249
);
252250
}
251+
setCurrentAppId(newApp.id);
253252
};
254253

255254
let isContextStateStable = true;

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

Lines changed: 10 additions & 9 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,
@@ -10,7 +10,7 @@ import {
1010
useTheme,
1111
TextField,
1212
} from "@mui/material";
13-
import { DragIndicator, SvgIconComponent } from "@mui/icons-material";
13+
import { DragIndicator, SvgIconComponent, Apps } from "@mui/icons-material";
1414
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
1515
import {
1616
draggable,
@@ -25,8 +25,7 @@ import {
2525
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
2626
import EggIcon from "@mui/icons-material/Egg";
2727
import { ThemeProvider } from "../../contexts/ThemeProvider";
28-
import { useSearchParamsUtils } from "../../hooks/searchParamsUtils";
29-
import { useApplicationId } from "../../hooks/application";
28+
import { ApplicationsContext } from "../../contexts/ApplicationsProvider";
3029
import { DashboardGroup, DashboardItem } from "../../types";
3130

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

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

7778
useEffect(() => {
7879
if (!dragRef.current || !handleRef.current) return;
@@ -101,7 +102,7 @@ export default function DrawerItem({
101102
width: source.element.getBoundingClientRect().width,
102103
}}
103104
>
104-
<ItemPreview title={item.title} icon={item.icon} />
105+
<ItemPreview title={item.title} icon={icon} />
105106
</div>
106107
</ThemeProvider>,
107108
);
@@ -187,13 +188,13 @@ export default function DrawerItem({
187188
<ListItemButton
188189
disableGutters
189190
key={item.title}
190-
onClick={() => setParam("appId", item.id)}
191+
onClick={() => setCurrentAppId(item.id)}
191192
sx={{ pl: 2, borderRadius: 2, pr: 1 }}
192193
ref={dragRef}
193194
selected={appId === item.id}
194195
>
195196
<ListItemIcon>
196-
<Icon component={item.icon ?? EggIcon} />
197+
<Icon component={icon ?? EggIcon} />
197198
</ListItemIcon>
198199
{renamingItemId === item.id ? (
199200
<TextField

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ export function ImportButton() {
144144
* Handles the creation of a new app in the dashboard drawer.
145145
*
146146
* @param appType - The type of the app to be created.
147-
* @param icon - The icon component for the app.
147+
* @param appTitle - The title of the app to be created.
148+
* @param appList - The list of applications with their metadata.
149+
* @param userDashboard - The current state of the user's dashboard.
150+
* @param setUserDashboard - The function to update the user's dashboard state.
151+
* @returns The ID of the newly created app.
148152
*/
149153
function handleAppCreation(
150154
appType: string,
@@ -172,7 +176,6 @@ function handleAppCreation(
172176
title: title,
173177
id: appId,
174178
type: appType,
175-
icon: appList.find((app) => app.name === appType)?.icon || null,
176179
};
177180
group.items.push(newApp);
178181
setUserDashboard((userDashboard) =>

0 commit comments

Comments
 (0)