Skip to content

Commit 9c36d77

Browse files
committed
fix: hooks dependencies
1 parent 714c191 commit 9c36d77

File tree

9 files changed

+81
-37
lines changed

9 files changed

+81
-37
lines changed

packages/diracx-web-components/eslint.config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const compat = new FlatCompat({
1919
export default [
2020
...fixupConfigRules(
2121
compat.extends(
22+
"next/core-web-vitals",
2223
"plugin:import/recommended",
2324
"plugin:import/typescript",
2425
"plugin:storybook/recommended",
@@ -57,6 +58,7 @@ export default [
5758
},
5859

5960
rules: {
61+
"@next/next/no-html-link-for-pages": "off", // We don't have pages, it's a library
6062
"import/order": ["error"],
6163
"import/no-unused-modules": ["error"],
6264
"import/no-useless-path-segments": ["error"],

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
} from "@mui/material";
1919
import { MenuBook, Add } from "@mui/icons-material";
2020
import React, { useContext, useEffect, useState } from "react";
21+
import Image from "next/image";
2122
import { monitorForElements } from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
2223
import { extractClosestEdge } from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
2324
import { ApplicationsContext } from "../../contexts/ApplicationsProvider";
@@ -412,7 +413,12 @@ export default function DashboardDrawer({
412413
backgroundColor: theme.palette.background.default,
413414
}}
414415
>
415-
<img src={logoURL} alt="DIRAC logo" style={{ maxWidth: "100%" }} />
416+
<Image
417+
src={logoURL}
418+
alt="DIRAC logo"
419+
fill
420+
style={{ objectFit: "contain" }}
421+
/>
416422
</Toolbar>
417423
{/* Map over user app instances and render them as list items in the drawer. */}
418424
<List>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export default function DrawerItem({
161161
},
162162
}),
163163
);
164-
}, [index, groupTitle, item, theme]);
164+
}, [index, groupTitle, item, theme, icon]);
165165

166166
// Handle renaming of the item
167167
const handleItemRename = () => {

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ export function JobDataTable({
137137
totalJobs = results.length;
138138
}
139139

140-
const clearSelected = () => setRowSelection({});
140+
const clearSelected = useCallback(
141+
() => setRowSelection({}),
142+
[setRowSelection],
143+
);
141144

142145
/**
143146
* Handle the deletion of the selected jobs
@@ -174,11 +177,11 @@ export function JobDataTable({
174177
}
175178
}, [
176179
accessToken,
180+
accessTokenPayload,
177181
diracxUrl,
178182
rowSelection,
179-
searchBody,
180-
pagination.pageIndex,
181-
pagination.pageSize,
183+
clearSelected,
184+
setSearchBody,
182185
]);
183186

184187
/**
@@ -244,11 +247,11 @@ export function JobDataTable({
244247
}
245248
}, [
246249
accessToken,
250+
accessTokenPayload,
247251
diracxUrl,
248252
rowSelection,
249-
searchBody,
250-
pagination.pageIndex,
251-
pagination.pageSize,
253+
clearSelected,
254+
setSearchBody,
252255
]);
253256

254257
/**
@@ -309,14 +312,7 @@ export function JobDataTable({
309312
} finally {
310313
setBackdropOpen(false);
311314
}
312-
}, [
313-
accessToken,
314-
diracxUrl,
315-
rowSelection,
316-
searchBody,
317-
pagination.pageIndex,
318-
pagination.pageSize,
319-
]);
315+
}, [accessToken, diracxUrl, rowSelection, clearSelected, setSearchBody]);
320316

321317
/**
322318
* Handle the history of the selected job

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { useState, useEffect } from "react";
1+
import { useState, useEffect, useRef } from "react";
22

33
import { scaleOrdinal, quantize, interpolateRainbow } from "d3";
44

@@ -42,6 +42,8 @@ export function JobSunburst({
4242
const [tree, setTree] = useState<SunburstTree | undefined>(undefined);
4343
const [isLoading, setIsLoading] = useState<boolean>(false);
4444

45+
const lastUsedGroupColumnsRef = useRef("");
46+
4547
useEffect(() => {
4648
const newSearch = currentPath.map((elt, index) => {
4749
return {
@@ -71,10 +73,22 @@ export function JobSunburst({
7173
});
7274
setIsLoading(false);
7375
}
74-
load();
76+
// For optimization, only load when the used groupColumns change
77+
if (
78+
lastUsedGroupColumnsRef.current !==
79+
groupColumns.slice(0, currentPath.length + 1).join(",") &&
80+
diracxUrl &&
81+
accessToken
82+
) {
83+
lastUsedGroupColumnsRef.current = groupColumns
84+
.slice(0, currentPath.length + 1)
85+
.join(",");
86+
load();
87+
}
7588
}, [
76-
groupColumns[currentPath.length],
77-
groupColumns[currentPath.length + 1],
89+
columns,
90+
groupColumns,
91+
lastUsedGroupColumnsRef,
7892
currentPath,
7993
searchBody,
8094
diracxUrl,

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

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

33
import React, { useState, useEffect, useContext } from "react";
4-
import Box from "@mui/material/Box";
5-
import Typography from "@mui/material/Typography";
6-
import FormControl from "@mui/material/FormControl";
7-
import InputLabel from "@mui/material/InputLabel";
8-
import Select, { SelectChangeEvent } from "@mui/material/Select";
9-
import MenuItem from "@mui/material/MenuItem";
10-
import Button from "@mui/material/Button";
11-
import Autocomplete from "@mui/material/Autocomplete";
12-
import TextField from "@mui/material/TextField";
13-
import { Stack } from "@mui/material";
4+
5+
import {
6+
Box,
7+
Typography,
8+
FormControl,
9+
InputLabel,
10+
Select,
11+
MenuItem,
12+
Button,
13+
Stack,
14+
Autocomplete,
15+
TextField,
16+
SelectChangeEvent,
17+
} from "@mui/material";
18+
19+
import Image from "next/image";
20+
1421
import { useOidc } from "@axa-fr/react-oidc";
1522
import { useMetadata, Metadata } from "../../hooks/metadata";
1623
import { useOIDCContext } from "../../hooks/oidcConfiguration";
@@ -146,7 +153,7 @@ export function LoginForm({
146153
paddingBottom: "10%",
147154
}}
148155
>
149-
<img src={logoURL} alt="DIRAC logo" width={150} height={150} />
156+
<Image src={logoURL} alt="DIRAC logo" width={150} height={150} />
150157
</Box>
151158
{singleVO ? (
152159
<Typography

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ export function SearchBar<T extends string>({
9494
const [tokenEquations, setTokenEquations] = useState<
9595
SearchBarTokenEquation[]
9696
>([]);
97+
/** A ref to store the current filters to avoid reloading the token equations */
98+
const currentFilters = useRef<string | null>(null);
99+
/** A ref to store a boolean indicating if the component is updating from search */
100+
const isUpdatingFromSearch = useRef<boolean>(false);
97101

98102
const [suggestions, setSuggestions] = useState<SearchBarSuggestions>({
99103
items: [],
@@ -118,7 +122,16 @@ export function SearchBar<T extends string>({
118122

119123
// Effect to initialize the token equations from filters
120124
useEffect(() => {
121-
if (tokenEquations.length !== 0) return; // Avoid reloading if already loaded
125+
const newFiltersString = String(
126+
filters.map((filter) => JSON.stringify(filter)),
127+
);
128+
129+
if (isUpdatingFromSearch.current) {
130+
isUpdatingFromSearch.current = false; // Reset the flag after updating from search
131+
currentFilters.current = newFiltersString; // Update the current filters to the new filters
132+
return;
133+
}
134+
if (currentFilters && currentFilters.current === newFiltersString) return; // Avoid reloading if already loaded
122135

123136
async function load() {
124137
const promises = filters.map(async (filter, filterIndex) =>
@@ -128,8 +141,11 @@ export function SearchBar<T extends string>({
128141
setTokenEquations(newTokenEquations);
129142
}
130143

131-
if (filters.length !== 0 && tokenEquations.length === 0) load();
132-
}, []);
144+
if (filters.length !== 0) {
145+
load();
146+
currentFilters.current = newFiltersString;
147+
}
148+
}, [filters, createSuggestions, currentFilters, tokenEquations.length]);
133149

134150
// Create a list of options based on the current tokens and data
135151
useEffect(() => {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export function Sunburst({
6767
quantize(interpolateRainbow, tree.children.length + 1),
6868
);
6969
return (name: string, _size: number, _depth: number) => colorScale(name);
70-
}, [tree?.children?.length]);
70+
}, [tree.children]);
7171

7272
// Use the provided colorScales or the default one
7373
const finalColorScales = colorScales || defaultColorScale;
@@ -310,6 +310,9 @@ export function Sunburst({
310310
theme,
311311
finalColorScales,
312312
sizeToText,
313+
error,
314+
hasHiddenLevels,
315+
isLoading,
313316
]);
314317

315318
if (error) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const ApplicationsProvider = ({
5353
if (userDashboard.length !== 0) return;
5454

5555
setUserDashboard(defaultUserDashboard);
56-
}, [appList, defaultUserDashboard]);
56+
}, [userDashboard.length, defaultUserDashboard]);
5757

5858
// Save the dashboard in session storage
5959
useEffect(() => {

0 commit comments

Comments
 (0)