|
1 | 1 | import React from "react";
|
2 |
| -import { useHistory, useLocation, useParams } from "react-router-dom"; |
| 2 | +import { useParams } from "react-router-dom"; |
3 | 3 | import { useTranslation } from "react-i18next";
|
4 | 4 |
|
5 |
| -import { PageSection } from "@patternfly/react-core"; |
6 |
| - |
7 | 5 | import { AnalysisDetailsAttachmentRoute, Paths } from "@app/Paths";
|
8 |
| -import { PageHeader } from "@app/components/PageHeader"; |
9 | 6 | import { formatPath } from "@app/utils/utils";
|
10 |
| -import { |
11 |
| - DocumentId, |
12 |
| - SimpleDocumentViewer, |
13 |
| -} from "@app/components/simple-document-viewer"; |
14 |
| -import { useFetchApplicationById } from "@app/queries/applications"; |
15 |
| -import { useFetchTaskByID } from "@app/queries/tasks"; |
| 7 | + |
16 | 8 | import "@app/components/simple-document-viewer/SimpleDocumentViewer.css";
|
| 9 | +import { TaskDetailsBase } from "@app/pages/tasks/TaskDetails"; |
| 10 | +import { useFetchApplicationById } from "@app/queries/applications"; |
17 | 11 |
|
18 |
| -export const AnalysisDetails: React.FC = () => { |
| 12 | +export const AnalysisDetails = () => { |
19 | 13 | const { t } = useTranslation();
|
20 |
| - |
21 | 14 | const { applicationId, taskId, attachmentId } =
|
22 | 15 | useParams<AnalysisDetailsAttachmentRoute>();
|
23 |
| - const { search } = useLocation(); |
24 |
| - const hasMergedParam = new URLSearchParams(search).has("merged"); |
25 |
| - |
26 |
| - const history = useHistory(); |
27 |
| - const onDocumentChange = (documentId: DocumentId) => |
28 |
| - typeof documentId === "number" |
29 |
| - ? history.push( |
30 |
| - formatPath(Paths.applicationsAnalysisDetailsAttachment, { |
31 |
| - applicationId: applicationId, |
32 |
| - taskId: taskId, |
33 |
| - attachmentId: documentId, |
34 |
| - }) |
35 |
| - ) |
36 |
| - : history.push({ |
37 |
| - pathname: formatPath(Paths.applicationsAnalysisDetails, { |
38 |
| - applicationId: applicationId, |
39 |
| - taskId: taskId, |
40 |
| - }), |
41 |
| - search: documentId === "MERGED_VIEW" ? "?merged=true" : undefined, |
42 |
| - }); |
| 16 | + const detailsPath = formatPath(Paths.applicationsAnalysisDetails, { |
| 17 | + applicationId: applicationId, |
| 18 | + taskId: taskId, |
| 19 | + }); |
43 | 20 |
|
44 | 21 | const { application } = useFetchApplicationById(applicationId);
|
45 |
| - const { task } = useFetchTaskByID(Number(taskId)); |
46 |
| - |
47 |
| - const taskName = task?.name ?? t("terms.unknown"); |
48 | 22 | const appName: string = application?.name ?? t("terms.unknown");
|
49 |
| - const attachmentName = task?.attached?.find( |
50 |
| - ({ id }) => String(id) === attachmentId |
51 |
| - )?.name; |
52 |
| - const resolvedAttachmentId = attachmentName |
53 |
| - ? Number(attachmentId) |
54 |
| - : undefined; |
55 |
| - const resolvedLogMode = hasMergedParam ? "MERGED_VIEW" : "LOG_VIEW"; |
56 | 23 |
|
57 | 24 | return (
|
58 |
| - <> |
59 |
| - <PageSection variant="light"> |
60 |
| - <PageHeader |
61 |
| - title={`Analysis details for ${taskName}`} |
62 |
| - breadcrumbs={[ |
63 |
| - { |
64 |
| - title: t("terms.applications"), |
65 |
| - path: Paths.applications, |
66 |
| - }, |
67 |
| - { |
68 |
| - title: appName, |
69 |
| - path: `${Paths.applications}/?activeItem=${applicationId}`, |
70 |
| - }, |
71 |
| - { |
72 |
| - title: t("actions.analysisDetails"), |
73 |
| - path: formatPath(Paths.applicationsAnalysisDetails, { |
74 |
| - applicationId: applicationId, |
75 |
| - taskId: taskId, |
76 |
| - }), |
77 |
| - }, |
78 |
| - ...(attachmentName |
79 |
| - ? [ |
80 |
| - { |
81 |
| - title: t("terms.attachments"), |
82 |
| - }, |
83 |
| - { |
84 |
| - title: attachmentName, |
85 |
| - path: formatPath(Paths.applicationsAnalysisDetails, { |
86 |
| - applicationId: applicationId, |
87 |
| - taskId: taskId, |
88 |
| - attachment: attachmentId, |
89 |
| - }), |
90 |
| - }, |
91 |
| - ] |
92 |
| - : []), |
93 |
| - ]} |
94 |
| - /> |
95 |
| - </PageSection> |
96 |
| - <PageSection> |
97 |
| - <div |
98 |
| - style={{ |
99 |
| - backgroundColor: "var(--pf-v5-global--BackgroundColor--100)", |
100 |
| - }} |
101 |
| - className="simple-task-viewer-container" |
102 |
| - > |
103 |
| - <SimpleDocumentViewer |
104 |
| - // force re-creating viewer via keys |
105 |
| - key={`${task?.id}/${task?.attached?.length}`} |
106 |
| - taskId={task ? Number(taskId) : undefined} |
107 |
| - documentId={resolvedAttachmentId || resolvedLogMode} |
108 |
| - attachments={task?.attached ?? []} |
109 |
| - onDocumentChange={onDocumentChange} |
110 |
| - height="full" |
111 |
| - /> |
112 |
| - </div> |
113 |
| - </PageSection> |
114 |
| - </> |
| 25 | + <TaskDetailsBase |
| 26 | + breadcrumbs={[ |
| 27 | + { |
| 28 | + title: t("terms.applications"), |
| 29 | + path: Paths.applications, |
| 30 | + }, |
| 31 | + { |
| 32 | + title: appName, |
| 33 | + path: `${Paths.applications}/?activeItem=${applicationId}`, |
| 34 | + }, |
| 35 | + { |
| 36 | + title: t("actions.analysisDetails"), |
| 37 | + path: formatPath(Paths.applicationsAnalysisDetails, { |
| 38 | + applicationId, |
| 39 | + taskId, |
| 40 | + }), |
| 41 | + }, |
| 42 | + ]} |
| 43 | + detailsPath={detailsPath} |
| 44 | + formatTitle={(taskName) => `Analysis details for ${taskName}`} |
| 45 | + formatAttachmentPath={(attachmentId) => |
| 46 | + formatPath(Paths.applicationsAnalysisDetailsAttachment, { |
| 47 | + applicationId, |
| 48 | + taskId, |
| 49 | + attachmentId, |
| 50 | + }) |
| 51 | + } |
| 52 | + taskId={Number(taskId)} |
| 53 | + attachmentId={attachmentId} |
| 54 | + /> |
115 | 55 | );
|
116 | 56 | };
|
0 commit comments