Skip to content

Commit e804c1a

Browse files
committed
fix: review suggestions
1 parent e7535cc commit e804c1a

File tree

10 files changed

+59
-33
lines changed

10 files changed

+59
-33
lines changed

docs/user/monitor_jobs.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818

1919
## Use the table
20+
By default, the jobs are displayed in a table. If you are viewing them in another chart, you can click the table button next to the search bar to switch back to the table view.
2021
The table displays the jobs that match the criteria specified in the search bar. Each row represents a job, and the columns show various attributes of the job, such as its ID, status, type, and submission date.
2122

2223
### Actions on the table
@@ -32,3 +33,5 @@ You can select one or more jobs by clicking on the checkboxes next to each job.
3233
- **Kill**: This button will kill the selected jobs.
3334
- **Delete**: This button will delete the selected jobs.
3435

36+
## Use the Pie Chart
37+
You can change the visualization to use a pie chart with the button next to the search bar. The pie chart provides a hierarchical view of the jobs based on their attributes. The `Columns to plot` component lets you choose your criteria for visualizing the jobs. The chart can display two levels, and you can then click on a section of the chart to zoom into that category and see more details.

packages/diracx-web-components/src/components/JobMonitor/JobDataTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ export function JobDataTable({
405405
* Table instance
406406
*/
407407
const table = useReactTable({
408-
data: results || [],
408+
data: useMemo(() => results || [], [results]),
409409
columns,
410410
state: {
411411
columnVisibility,

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Box,
2222
ToggleButtonGroup,
2323
ToggleButton,
24+
Tooltip,
2425
} from "@mui/material";
2526

2627
import { TableChart, DonutSmall } from "@mui/icons-material";
@@ -108,7 +109,7 @@ export default function JobMonitor() {
108109
},
109110
);
110111

111-
const [chartType, setChartType] = useState("table");
112+
const [chartType, setChartType] = useState("CHART_TYPE_TABLE");
112113

113114
// Save the state of the app in local storage
114115
useEffect(() => {
@@ -292,7 +293,11 @@ export default function JobMonitor() {
292293
values,
293294
})),
294295
}));
295-
}, [filters, columns]);
296+
setPagination((prev) => ({
297+
...prev,
298+
pageIndex: 0, // Reset to the first page when applying filters
299+
}));
300+
}, [filters, columns, setSearchBody, setPagination]);
296301

297302
return (
298303
<Box
@@ -319,7 +324,7 @@ export default function JobMonitor() {
319324
<PlotTypeSelector plotType={chartType} setPlotType={setChartType} />
320325
</Box>
321326

322-
{chartType === "table" && (
327+
{chartType === "CHART_TYPE_TABLE" && (
323328
<JobDataTable
324329
searchBody={searchBody}
325330
setSearchBody={setSearchBody}
@@ -335,7 +340,7 @@ export default function JobMonitor() {
335340
statusColors={statusColors}
336341
/>
337342
)}
338-
{chartType === "sunburst" && (
343+
{chartType === "CHART_TYPE_SUNBURST" && (
339344
<JobSunburst
340345
searchBody={searchBody}
341346
statusColors={statusColors}
@@ -434,12 +439,16 @@ export function PlotTypeSelector({
434439
}}
435440
aria-label="text alignment"
436441
>
437-
<ToggleButton value="table" aria-label="left aligned">
438-
<TableChart fontSize="large" />
439-
</ToggleButton>
440-
<ToggleButton value="sunburst" aria-label="centered">
441-
<DonutSmall fontSize="large" />
442-
</ToggleButton>
442+
<Tooltip title="Table view">
443+
<ToggleButton value="CHART_TYPE_TABLE" aria-label="left aligned">
444+
<TableChart fontSize="large" />
445+
</ToggleButton>
446+
</Tooltip>
447+
<Tooltip title="Sunburst view">
448+
<ToggleButton value="CHART_TYPE_SUNBURST" aria-label="centered">
449+
<DonutSmall fontSize="large" />
450+
</ToggleButton>
451+
</Tooltip>
443452
</ToggleButtonGroup>
444453
</>
445454
);

packages/diracx-web-components/src/components/JobMonitor/JobSunburst.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function JobSunburst({
8282
]);
8383

8484
const defaultColors = scaleOrdinal(
85-
quantize(interpolateRainbow, tree?.children?.length || 0 + 1),
85+
quantize(interpolateRainbow, (tree?.children?.length ?? 0) + 1),
8686
);
8787

8888
function colorScales(name: string, _size: number, _depth: number): string {
@@ -116,10 +116,11 @@ export function JobSunburst({
116116

117117
return (
118118
<ChartDisplayLayout
119-
Chart={Chart}
119+
chart={Chart}
120120
columnList={columnList}
121121
groupColumns={groupColumns}
122122
setGroupColumns={setGroupColumns}
123+
currentPath={currentPath}
123124
setCurrentPath={setCurrentPath}
124125
defaultColumns={["Status"]}
125126
title={"Columns to plot"}
@@ -262,17 +263,17 @@ function buildTree(
262263
function sizeToText(size: number, total?: number): string {
263264
if (size > 1e9)
264265
return (
265-
`${(size / 1e9).toFixed(1)} billion jobs` +
266+
`${(size / 1e9).toFixed(2)}B \njobs` +
266267
(total ? ` (${((size / total) * 100).toFixed(2)}%)` : "")
267268
);
268269
if (size > 1e6)
269270
return (
270-
`${(size / 1e6).toFixed(1)} million jobs` +
271+
`${(size / 1e6).toFixed(2)}M \njobs` +
271272
(total ? ` (${((size / total) * 100).toFixed(2)}%)` : "")
272273
);
273274
if (size > 1e3)
274275
return (
275-
`${(size / 1e3).toFixed(1)} thousand\njobs` +
276+
`${(size / 1e3).toFixed(2)}k \njobs` +
276277
(total ? ` (${((size / total) * 100).toFixed(2)}%)` : "")
277278
);
278279
if (size > 1)

packages/diracx-web-components/src/components/JobMonitor/jobDataService.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ export function useJobs(
252252
page: number,
253253
rowsPerPage: number,
254254
) {
255-
const [data, setData] = useState<Job[] | null>([]);
255+
const [data, setData] = useState<Job[] | null>(null);
256256
const [headers, setHeaders] = useState<Headers>(new Headers());
257257
const [isLoading, setIsLoading] = useState<boolean>(true);
258258
const [error, setError] = useState<Error | null>(null);
@@ -261,7 +261,7 @@ export function useJobs(
261261
if (!diracxUrl) {
262262
setData(null);
263263
setIsLoading(false);
264-
setError(Error("Invalid URL generated for fetching jobs."));
264+
setError(new Error("Invalid URL generated for fetching jobs."));
265265
return;
266266
}
267267

@@ -296,7 +296,7 @@ export function useJobs(
296296
} catch {
297297
setData(null);
298298
setIsLoading(false);
299-
setError(Error("Failed to fetch jobs"));
299+
setError(new Error("Failed to fetch jobs"));
300300
}
301301
}
302302
fetchJobs();

packages/diracx-web-components/src/components/shared/ChartDisplayLayout.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ import { ColumnSelector } from "./ColumnSelector";
66

77
interface ChartDisplayLayoutProps {
88
/** The chart to be displayed */
9-
Chart: JSX.Element;
9+
chart: JSX.Element;
1010
/** List of columns available for selection */
1111
columnList: string[];
1212
/** Currently selected group columns */
1313
groupColumns: string[];
1414
/** Function to set the group columns */
1515
setGroupColumns: React.Dispatch<React.SetStateAction<string[]>>;
16+
/** The current path in the chart */
17+
currentPath: string[];
1618
/** Function to set the current path in the chart */
1719
setCurrentPath: React.Dispatch<React.SetStateAction<string[]>>;
1820
/** Default group columns to be used */
@@ -29,10 +31,11 @@ interface ChartDisplayLayoutProps {
2931
* @returns
3032
*/
3133
export function ChartDisplayLayout({
32-
Chart,
34+
chart,
3335
columnList,
3436
groupColumns,
3537
setGroupColumns,
38+
currentPath,
3639
setCurrentPath,
3740
defaultColumns: defaultGroupColumns,
3841
title = "Level selector",
@@ -57,7 +60,7 @@ export function ChartDisplayLayout({
5760
overflow: "auto",
5861
}}
5962
>
60-
{Chart}
63+
{chart}
6164
</Box>
6265

6366
{/* Right Section: Column selection */}
@@ -75,6 +78,7 @@ export function ChartDisplayLayout({
7578
columnList={columnList}
7679
groupColumns={groupColumns}
7780
setGroupColumns={setGroupColumns}
81+
currentPath={currentPath}
7882
setCurrentPath={setCurrentPath}
7983
defaultColumns={defaultGroupColumns}
8084
title={title}

packages/diracx-web-components/src/components/shared/ColumnSelector.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ interface SelectColumnsProps {
3131
groupColumns: string[];
3232
/** Setter for groupColumns */
3333
setGroupColumns: React.Dispatch<React.SetStateAction<string[]>>;
34+
/** The current path in the tree */
35+
currentPath: string[];
3436
/** Setter for the current path in the tree */
3537
setCurrentPath: React.Dispatch<React.SetStateAction<string[]>>;
3638
/** Default columns to use */
@@ -50,6 +52,7 @@ export function ColumnSelector({
5052
columnList,
5153
groupColumns,
5254
setGroupColumns,
55+
currentPath,
5356
setCurrentPath,
5457
defaultColumns: defaultGroupColumns,
5558
title = "Column Selector",
@@ -65,14 +68,17 @@ export function ColumnSelector({
6568
if (event.target.value === "None") {
6669
// Delete a column
6770
newGroups = newGroups.filter((_elt, index) => index !== depth);
68-
if (newGroups.length > 0)
69-
setCurrentPath((currentPath) => currentPath.slice(0, depth - 1));
71+
if (newGroups.length > 0 && currentPath.length > depth)
72+
setCurrentPath((currentPath) =>
73+
currentPath.slice(0, Math.max(0, depth - 1)),
74+
);
7075
} else {
7176
// Add or change a column
7277
if (newGroups[depth]) {
7378
// Change the column
7479
newGroups[depth] = event.target.value;
75-
setCurrentPath((currentPath) => currentPath.slice(0, depth));
80+
if (currentPath.length > depth)
81+
setCurrentPath((currentPath) => currentPath.slice(0, depth));
7682
} else {
7783
// Add a column
7884
newGroups.push(event.target.value);

packages/diracx-web-components/stories/ChartDisplayLayout.stories.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ type Story = StoryObj<typeof meta>;
5959

6060
export const Default: Story = {
6161
args: {
62-
Chart: <div>Nothing</div>,
62+
chart: <div>Nothing</div>,
6363
columnList: ["Column 1", "Column 2", "Column 3"],
6464
groupColumns: ["Column 1"],
6565
setGroupColumns: () => {},
66+
currentPath: [],
6667
setCurrentPath: () => {},
6768
defaultColumns: ["Column 1"],
6869
title: "Select Columns",
6970
},
7071
argTypes: {
71-
Chart: {
72+
chart: {
7273
control: { type: "select" },
7374
options: ["Sunburst", "None"],
7475
mapping: {
@@ -85,15 +86,17 @@ export const Default: Story = {
8586
},
8687
render: (args) => {
8788
const [groupColumns, setGroupColumns] = useState(args.groupColumns);
89+
const [currentPath, setCurrentPath] = useState(args.currentPath);
8890

8991
return (
9092
<ThemeProvider>
9193
<ChartDisplayLayout
92-
Chart={args.Chart}
94+
chart={args.chart}
9395
columnList={args.columnList}
9496
groupColumns={groupColumns}
9597
setGroupColumns={setGroupColumns}
96-
setCurrentPath={args.setCurrentPath}
98+
currentPath={currentPath}
99+
setCurrentPath={setCurrentPath}
97100
defaultColumns={args.defaultColumns}
98101
title={args.title}
99102
/>

packages/diracx-web-components/stories/JobMonitor.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export const WithError: Story = {
149149
<JobMockProvider
150150
jobs={null}
151151
jobHistory={null}
152-
error={Error("Custom error message here")}
152+
error={new Error("Custom error message here")}
153153
isLoading={false}
154154
>
155155
<Story />

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ describe("ChartDisplayLayout", () => {
1919
});
2020

2121
it("renders with columns", () => {
22-
render(<Default groupColumns={["Custom Column 1", "Custom Column 2"]} />);
22+
render(<Default groupColumns={["Column 1", "Column 2"]} />);
2323

24-
expect(screen.getByDisplayValue("Custom Column 1")).toBeInTheDocument();
25-
expect(screen.getByDisplayValue("Custom Column 2")).toBeInTheDocument();
24+
expect(screen.getByDisplayValue("Column 1")).toBeInTheDocument();
25+
expect(screen.getByDisplayValue("Column 2")).toBeInTheDocument();
2626
});
2727
});

0 commit comments

Comments
 (0)