Skip to content

Commit 19987fb

Browse files
committed
fix: more fixes
1 parent df1c6c5 commit 19987fb

16 files changed

Lines changed: 299 additions & 294 deletions

File tree

packages/diracx-web-components/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
"./types": {
100100
"import": "./dist/types/index.js",
101101
"types": "./dist/types/index.d.ts"
102+
},
103+
"./services": {
104+
"import": "./dist/services/index.js",
105+
"types": "./dist/services/index.d.ts"
102106
}
103107
},
104108
"files": [

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ import Menu from "@mui/icons-material/Menu";
88
import Toolbar from "@mui/material/Toolbar";
99
import Stack from "@mui/material/Stack";
1010
import { Typography, useMediaQuery, useTheme } from "@mui/material";
11-
import {
12-
useApplicationTitle,
13-
useApplicationType,
14-
} from "../../hooks/application";
11+
import { useCurrentApplication } from "../../hooks/application";
1512
import { ProfileButton } from "./ProfileButton";
1613
import { ThemeToggleButton } from "./ThemeToggleButton";
1714
import DashboardDrawer from "./DashboardDrawer";
@@ -42,8 +39,9 @@ export default function Dashboard({
4239
logoURL,
4340
documentationURL,
4441
}: DashboardProps) {
45-
const appTitle = useApplicationTitle();
46-
const appType = useApplicationType();
42+
const currentApp = useCurrentApplication();
43+
const appTitle = currentApp?.title ?? null;
44+
const appType = currentApp?.type ?? null;
4745

4846
/** Theme and media query */
4947
const theme = useTheme();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import Delete from "@mui/icons-material/Delete";
1414
import Clear from "@mui/icons-material/Clear";
1515
import { useReactTable, getCoreRowModel } from "@tanstack/react-table";
1616
import { useOIDCContext } from "../../hooks/oidcConfiguration";
17-
import { DataTable, MenuItem } from "../shared/DataTable";
17+
import { DataTable, ContextMenuItem } from "../shared/DataTable";
1818
import type { ToolbarAction } from "../shared/DataTable/SplitActionButton";
1919
import { Job, JobHistory, SearchBody } from "../../types";
2020
import { useDiracxUrl } from "../../hooks/utils";
@@ -340,7 +340,7 @@ export const JobDataTable = memo(function JobDataTable({
340340
/**
341341
* The menu items
342342
*/
343-
const menuItems: MenuItem[] = useMemo(
343+
const menuItems: ContextMenuItem[] = useMemo(
344344
() => [
345345
{
346346
label: "Get history",

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

Lines changed: 94 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import useSWR from "swr";
44
import dayjs from "dayjs";
55
import utc from "dayjs/plugin/utc";
66

7-
import { fetcher } from "../../hooks/utils";
7+
import { fetcher } from "../../services/client";
88
import type { JobSummary } from "../../types";
99
import {
1010
Filter,
@@ -59,41 +59,6 @@ function processSearchBody(searchBody: SearchBody): SearchBody {
5959
};
6060
}
6161

62-
/**
63-
* Deletes jobs with the specified IDs.
64-
*
65-
* @param diracxUrl - The base URL of the DiracX API.
66-
* @param selectedIds - An array of job IDs to delete.
67-
* @param accessToken - The authentication token.
68-
* @param accessTokenPayload - Information about the user.
69-
*/
70-
export function deleteJobs(
71-
diracxUrl: string | null,
72-
selectedIds: readonly number[],
73-
accessToken: string,
74-
accessTokenPayload: Record<string, number | string>,
75-
) {
76-
if (!diracxUrl) {
77-
throw new Error("Invalid URL generated for deleting jobs.");
78-
}
79-
80-
const deleteUrl = `${diracxUrl}/api/jobs/status`;
81-
82-
const currentDate = dayjs().utc().toISOString();
83-
84-
const body = selectedIds.reduce((acc: StatusBody, jobId) => {
85-
acc[jobId] = {
86-
[currentDate]: {
87-
Status: "Deleted",
88-
MinorStatus: "Marked for deletion",
89-
Source: `User: ${accessTokenPayload["preferred_username"]}`,
90-
},
91-
};
92-
return acc;
93-
}, {});
94-
return fetcher([deleteUrl, accessToken, "PATCH", body]);
95-
}
96-
9762
type JobBulkResponse = {
9863
failed: {
9964
[jobId: number]: { detail: string };
@@ -114,45 +79,92 @@ type StatusBody = {
11479
};
11580

11681
/**
117-
* Kills the specified jobs.
82+
* Updates the status of jobs with the specified IDs.
11883
*
11984
* @param diracxUrl - The base URL of the DiracX API.
120-
* @param selectedIds - An array of job IDs to be killed.
85+
* @param selectedIds - An array of job IDs to update.
12186
* @param accessToken - The authentication token.
12287
* @param accessTokenPayload - Information about the user.
88+
* @param status - The new status to set (e.g. "Deleted", "Killed").
89+
* @param minorStatus - The minor status message.
12390
* @returns A Promise that resolves to an object containing the response headers and data.
12491
*/
125-
export function killJobs(
92+
function updateJobStatus(
12693
diracxUrl: string | null,
12794
selectedIds: readonly number[],
12895
accessToken: string,
12996
accessTokenPayload: Record<string, number | string>,
97+
status: string,
98+
minorStatus: string,
13099
): Promise<{ headers: Headers; data: JobBulkResponse }> {
131100
if (!diracxUrl) {
132-
throw new Error("Invalid URL generated for killing jobs.");
101+
throw new Error(`Invalid URL generated for setting jobs to ${status}.`);
133102
}
134-
const killUrl = `${diracxUrl}/api/jobs/status`;
103+
135104
const currentDate = dayjs().utc().toISOString();
136105

137106
const body = selectedIds.reduce((acc: StatusBody, jobId) => {
138107
acc[jobId] = {
139108
[currentDate]: {
140-
Status: "Killed",
141-
MinorStatus: "Marked for termination",
109+
Status: status,
110+
MinorStatus: minorStatus,
142111
Source: `User: ${accessTokenPayload["preferred_username"]}`,
143112
},
144113
};
145114
return acc;
146115
}, {});
147-
return fetcher([killUrl, accessToken, "PATCH", body]);
116+
return fetcher({
117+
url: `${diracxUrl}/api/jobs/status`,
118+
accessToken,
119+
method: "PATCH",
120+
body,
121+
});
122+
}
123+
124+
/**
125+
* Deletes jobs with the specified IDs.
126+
*/
127+
export function deleteJobs(
128+
diracxUrl: string | null,
129+
selectedIds: readonly number[],
130+
accessToken: string,
131+
accessTokenPayload: Record<string, number | string>,
132+
) {
133+
return updateJobStatus(
134+
diracxUrl,
135+
selectedIds,
136+
accessToken,
137+
accessTokenPayload,
138+
"Deleted",
139+
"Marked for deletion",
140+
);
141+
}
142+
143+
/**
144+
* Kills the specified jobs.
145+
*/
146+
export function killJobs(
147+
diracxUrl: string | null,
148+
selectedIds: readonly number[],
149+
accessToken: string,
150+
accessTokenPayload: Record<string, number | string>,
151+
): Promise<{ headers: Headers; data: JobBulkResponse }> {
152+
return updateJobStatus(
153+
diracxUrl,
154+
selectedIds,
155+
accessToken,
156+
accessTokenPayload,
157+
"Killed",
158+
"Marked for termination",
159+
);
148160
}
149161

150162
/**
151163
* Retrieves the job history for a given job ID.
152164
*
153165
* @param diracxUrl - The base URL of the DiracX API.
154166
* @param jobId - The ID of the job.
155-
* @param token - The authentication token.
167+
* @param accessToken - The authentication token.
156168
* @returns A Promise that resolves to an object containing the headers and data of the job history.
157169
*/
158170
export async function getJobHistory(
@@ -163,7 +175,6 @@ export async function getJobHistory(
163175
if (!diracxUrl) {
164176
throw new Error("Invalid URL generated for fetching job history.");
165177
}
166-
const historyUrl = `${diracxUrl}/api/jobs/search`;
167178
const body = {
168179
parameters: ["LoggingInfo"],
169180
search: [
@@ -174,16 +185,21 @@ export async function getJobHistory(
174185
},
175186
],
176187
};
177-
// Expect the response to be an array of objects with JobID and LoggingInfo
178188
const { data } = await fetcher<
179189
Array<{ JobID: number; LoggingInfo: JobHistory[] }>
180-
>([historyUrl, accessToken, "POST", body]);
190+
>({
191+
url: `${diracxUrl}/api/jobs/search`,
192+
accessToken,
193+
method: "POST",
194+
body,
195+
});
181196

182197
return { data: data[0].LoggingInfo };
183198
}
184199

185200
/**
186201
* Retrieves the sandbox information for a given job ID and sandbox type.
202+
* @param diracxUrl - The base URL of the DiracX API.
187203
* @param jobId - The ID of the job.
188204
* @param sbType - The type of the sandbox (input or output).
189205
* @param accessToken - The authentication token.
@@ -195,12 +211,15 @@ export function getJobSandbox(
195211
sbType: "input" | "output",
196212
accessToken: string,
197213
): Promise<{ headers: Headers; data: JobSandboxPFNResponse }> {
198-
const url = `${diracxUrl}/api/jobs/${jobId}/sandbox/${sbType}`;
199-
return fetcher([url, accessToken]);
214+
return fetcher({
215+
url: `${diracxUrl}/api/jobs/${jobId}/sandbox/${sbType}`,
216+
accessToken,
217+
});
200218
}
201219

202220
/**
203221
* Retrieves the sandbox URL for a given PFN.
222+
* @param diracxUrl - The base URL of the DiracX API.
204223
* @param pfn - The PFN of the job.
205224
* @param accessToken - The authentication token.
206225
* @returns A Promise that resolves to an object containing the headers and data of the sandbox URL.
@@ -216,8 +235,10 @@ export function getJobSandboxUrl(
216235
`Invalid PFN format: "${pfn}". Must start with / or a known protocol (http, https, s3, srm).`,
217236
);
218237
}
219-
const url = `${diracxUrl}/api/jobs/sandbox?pfn=${encodeURIComponent(pfn)}`;
220-
return fetcher([url, accessToken]);
238+
return fetcher({
239+
url: `${diracxUrl}/api/jobs/sandbox?pfn=${encodeURIComponent(pfn)}`,
240+
accessToken,
241+
});
221242
}
222243

223244
/**
@@ -241,18 +262,16 @@ export async function getJobSummary(
241262

242263
const processed = searchBody ? processSearchBody(searchBody) : searchBody;
243264

244-
const summaryUrl = `${diracxUrl}/api/jobs/summary`;
245265
const body = {
246266
grouping: grouping,
247267
search: processed?.search || [],
248268
};
249-
// Expect the response to be an array of objects with all the grouping fields
250-
const { data } = await fetcher<Array<JobSummary>>([
251-
summaryUrl,
269+
const { data } = await fetcher<Array<JobSummary>>({
270+
url: `${diracxUrl}/api/jobs/summary`,
252271
accessToken,
253-
"POST",
272+
method: "POST",
254273
body,
255-
]);
274+
});
256275

257276
return { data };
258277
}
@@ -293,7 +312,12 @@ export function useJobSummary(
293312
search: processed.search || [],
294313
};
295314

296-
return await fetcher<JobSummary[]>([url, accessToken!, "POST", body]);
315+
return await fetcher<JobSummary[]>({
316+
url,
317+
accessToken: accessToken!,
318+
method: "POST",
319+
body,
320+
});
297321
},
298322
{
299323
revalidateOnMount: true,
@@ -351,7 +375,12 @@ export function useJobs(
351375
sort: processed.sort || [],
352376
};
353377

354-
return await fetcher<Job[]>([url, accessToken, "POST", body]);
378+
return await fetcher<Job[]>({
379+
url,
380+
accessToken,
381+
method: "POST",
382+
body,
383+
});
355384
},
356385
{
357386
revalidateOnMount: true,
@@ -380,14 +409,6 @@ export function useJobs(
380409
};
381410
}
382411

383-
/**
384-
* Generates the URL for searching jobs.
385-
*
386-
* @param diracxUrl - The base URL of the DiracX API.
387-
* @param page - The page number for pagination.
388-
* @param rowsPerPage - The number of rows per page.
389-
* @returns The URL for the job search API endpoint.
390-
*/
391412
/** Maximum number of IDs that can be fetched in a single request */
392413
const MAX_IDS_PER_PAGE = 10000;
393414

@@ -409,7 +430,6 @@ export async function fetchMatchingJobIds(
409430
throw new Error("Invalid URL for fetching job IDs.");
410431
}
411432

412-
const url = `${diracxUrl}/api/jobs/search?page=1&per_page=${MAX_IDS_PER_PAGE}`;
413433
const body = {
414434
parameters: ["JobID"],
415435
search: searchBody.search || [],
@@ -422,12 +442,12 @@ export async function fetchMatchingJobIds(
422442
search: [...(body.search || [])],
423443
} as SearchBody);
424444

425-
const result = await fetcher<{ JobID: number }[]>([
426-
url,
445+
const result = await fetcher<{ JobID: number }[]>({
446+
url: `${diracxUrl}/api/jobs/search?page=1&per_page=${MAX_IDS_PER_PAGE}`,
427447
accessToken,
428-
"POST",
429-
processedBody,
430-
]);
448+
method: "POST",
449+
body: processedBody,
450+
});
431451

432452
return (result.data as { JobID: number }[]).map((item) => item.JobID);
433453
}

0 commit comments

Comments
 (0)