-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Add task detail links to tasks page (#1980)
1. extract base component to re-use for Analysis Details and Task Details 2. add 2 new routes: a) /tasks/:taskId b) /tasks/:taskId/attachments/:attachmentId 3. user can enter details screen by: a) task status name (link) b) "Task details" action (per row kebab actions) 4. persist page state in session storage for Applications and Task Manager pages to fix problems with returning from task details page. Resolves: #1975 --------- Signed-off-by: Radoslaw Szwajkowski <[email protected]>
- Loading branch information
Showing
9 changed files
with
244 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
138 changes: 39 additions & 99 deletions
138
client/src/app/pages/applications/analysis-details/AnalysisDetails.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,56 @@ | ||
import React from "react"; | ||
import { useHistory, useLocation, useParams } from "react-router-dom"; | ||
import { useParams } from "react-router-dom"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import { PageSection } from "@patternfly/react-core"; | ||
|
||
import { AnalysisDetailsAttachmentRoute, Paths } from "@app/Paths"; | ||
import { PageHeader } from "@app/components/PageHeader"; | ||
import { formatPath } from "@app/utils/utils"; | ||
import { | ||
DocumentId, | ||
SimpleDocumentViewer, | ||
} from "@app/components/simple-document-viewer"; | ||
import { useFetchApplicationById } from "@app/queries/applications"; | ||
import { useFetchTaskByID } from "@app/queries/tasks"; | ||
|
||
import "@app/components/simple-document-viewer/SimpleDocumentViewer.css"; | ||
import { TaskDetailsBase } from "@app/pages/tasks/TaskDetailsBase"; | ||
import { useFetchApplicationById } from "@app/queries/applications"; | ||
|
||
export const AnalysisDetails: React.FC = () => { | ||
export const AnalysisDetails = () => { | ||
const { t } = useTranslation(); | ||
|
||
const { applicationId, taskId, attachmentId } = | ||
useParams<AnalysisDetailsAttachmentRoute>(); | ||
const { search } = useLocation(); | ||
const hasMergedParam = new URLSearchParams(search).has("merged"); | ||
|
||
const history = useHistory(); | ||
const onDocumentChange = (documentId: DocumentId) => | ||
typeof documentId === "number" | ||
? history.push( | ||
formatPath(Paths.applicationsAnalysisDetailsAttachment, { | ||
applicationId: applicationId, | ||
taskId: taskId, | ||
attachmentId: documentId, | ||
}) | ||
) | ||
: history.push({ | ||
pathname: formatPath(Paths.applicationsAnalysisDetails, { | ||
applicationId: applicationId, | ||
taskId: taskId, | ||
}), | ||
search: documentId === "MERGED_VIEW" ? "?merged=true" : undefined, | ||
}); | ||
const detailsPath = formatPath(Paths.applicationsAnalysisDetails, { | ||
applicationId: applicationId, | ||
taskId: taskId, | ||
}); | ||
|
||
const { application } = useFetchApplicationById(applicationId); | ||
const { task } = useFetchTaskByID(Number(taskId)); | ||
|
||
const taskName = task?.name ?? t("terms.unknown"); | ||
const appName: string = application?.name ?? t("terms.unknown"); | ||
const attachmentName = task?.attached?.find( | ||
({ id }) => String(id) === attachmentId | ||
)?.name; | ||
const resolvedAttachmentId = attachmentName | ||
? Number(attachmentId) | ||
: undefined; | ||
const resolvedLogMode = hasMergedParam ? "MERGED_VIEW" : "LOG_VIEW"; | ||
|
||
return ( | ||
<> | ||
<PageSection variant="light"> | ||
<PageHeader | ||
title={`Analysis details for ${taskName}`} | ||
breadcrumbs={[ | ||
{ | ||
title: t("terms.applications"), | ||
path: Paths.applications, | ||
}, | ||
{ | ||
title: appName, | ||
path: `${Paths.applications}/?activeItem=${applicationId}`, | ||
}, | ||
{ | ||
title: t("actions.analysisDetails"), | ||
path: formatPath(Paths.applicationsAnalysisDetails, { | ||
applicationId: applicationId, | ||
taskId: taskId, | ||
}), | ||
}, | ||
...(attachmentName | ||
? [ | ||
{ | ||
title: t("terms.attachments"), | ||
}, | ||
{ | ||
title: attachmentName, | ||
path: formatPath(Paths.applicationsAnalysisDetails, { | ||
applicationId: applicationId, | ||
taskId: taskId, | ||
attachment: attachmentId, | ||
}), | ||
}, | ||
] | ||
: []), | ||
]} | ||
/> | ||
</PageSection> | ||
<PageSection> | ||
<div | ||
style={{ | ||
backgroundColor: "var(--pf-v5-global--BackgroundColor--100)", | ||
}} | ||
className="simple-task-viewer-container" | ||
> | ||
<SimpleDocumentViewer | ||
// force re-creating viewer via keys | ||
key={`${task?.id}/${task?.attached?.length}`} | ||
taskId={task ? Number(taskId) : undefined} | ||
documentId={resolvedAttachmentId || resolvedLogMode} | ||
attachments={task?.attached ?? []} | ||
onDocumentChange={onDocumentChange} | ||
height="full" | ||
/> | ||
</div> | ||
</PageSection> | ||
</> | ||
<TaskDetailsBase | ||
breadcrumbs={[ | ||
{ | ||
title: t("terms.applications"), | ||
path: Paths.applications, | ||
}, | ||
{ | ||
title: appName, | ||
path: `${Paths.applications}/?activeItem=${applicationId}`, | ||
}, | ||
{ | ||
title: t("actions.analysisDetails"), | ||
path: formatPath(Paths.applicationsAnalysisDetails, { | ||
applicationId, | ||
taskId, | ||
}), | ||
}, | ||
]} | ||
detailsPath={detailsPath} | ||
formatTitle={(taskName) => `Analysis details for ${taskName}`} | ||
formatAttachmentPath={(attachmentId) => | ||
formatPath(Paths.applicationsAnalysisDetailsAttachment, { | ||
applicationId, | ||
taskId, | ||
attachmentId, | ||
}) | ||
} | ||
taskId={Number(taskId)} | ||
attachmentId={attachmentId} | ||
/> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from "react"; | ||
import { useParams } from "react-router-dom"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import { Paths, TaskDetailsAttachmentRoute } from "@app/Paths"; | ||
import "@app/components/simple-document-viewer/SimpleDocumentViewer.css"; | ||
import { formatPath } from "@app/utils/utils"; | ||
import { TaskDetailsBase } from "./TaskDetailsBase"; | ||
|
||
export const TaskDetails = () => { | ||
const { t } = useTranslation(); | ||
const { taskId, attachmentId } = useParams<TaskDetailsAttachmentRoute>(); | ||
const detailsPath = formatPath(Paths.taskDetails, { taskId }); | ||
return ( | ||
<TaskDetailsBase | ||
breadcrumbs={[ | ||
{ | ||
title: t("terms.tasks"), | ||
path: Paths.tasks, | ||
}, | ||
{ | ||
title: t("titles.taskWithId", { taskId }), | ||
path: detailsPath, | ||
}, | ||
]} | ||
detailsPath={detailsPath} | ||
formatTitle={(taskName) => `Task details for task ${taskId}, ${taskName}`} | ||
formatAttachmentPath={(attachmentId) => | ||
formatPath(Paths.taskDetailsAttachment, { | ||
taskId, | ||
attachmentId, | ||
}) | ||
} | ||
taskId={Number(taskId)} | ||
attachmentId={attachmentId} | ||
/> | ||
); | ||
}; | ||
|
||
export default TaskDetails; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import React from "react"; | ||
import { useHistory, useLocation } from "react-router-dom"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import { PageSection } from "@patternfly/react-core"; | ||
|
||
import { PageHeader, PageHeaderProps } from "@app/components/PageHeader"; | ||
import { | ||
DocumentId, | ||
SimpleDocumentViewer, | ||
} from "@app/components/simple-document-viewer"; | ||
import { useFetchTaskByID } from "@app/queries/tasks"; | ||
import "@app/components/simple-document-viewer/SimpleDocumentViewer.css"; | ||
|
||
export const TaskDetailsBase: React.FC<{ | ||
breadcrumbs: PageHeaderProps["breadcrumbs"]; | ||
formatTitle: (taskName: string) => string; | ||
detailsPath: string; | ||
formatAttachmentPath: (attachmentId: number | string) => string; | ||
taskId: number; | ||
attachmentId?: string; | ||
}> = ({ | ||
breadcrumbs, | ||
formatTitle, | ||
detailsPath, | ||
formatAttachmentPath, | ||
taskId, | ||
attachmentId, | ||
}) => { | ||
const { t } = useTranslation(); | ||
|
||
const { search } = useLocation(); | ||
const hasMergedParam = new URLSearchParams(search).has("merged"); | ||
|
||
const history = useHistory(); | ||
const onDocumentChange = (documentId: DocumentId) => | ||
typeof documentId === "number" | ||
? history.push(formatAttachmentPath(documentId)) | ||
: history.push({ | ||
pathname: detailsPath, | ||
search: documentId === "MERGED_VIEW" ? "?merged=true" : undefined, | ||
}); | ||
|
||
const { task } = useFetchTaskByID(taskId); | ||
|
||
const taskName: string = task?.name ?? t("terms.unknown"); | ||
const attachmentName = task?.attached?.find( | ||
({ id }) => String(id) === attachmentId | ||
)?.name; | ||
const resolvedAttachmentId = attachmentName | ||
? Number(attachmentId) | ||
: undefined; | ||
const resolvedLogMode = hasMergedParam ? "MERGED_VIEW" : "LOG_VIEW"; | ||
|
||
return ( | ||
<> | ||
<PageSection variant="light"> | ||
<PageHeader | ||
title={formatTitle(taskName)} | ||
breadcrumbs={[ | ||
...breadcrumbs, | ||
...(attachmentName && attachmentId | ||
? [ | ||
{ | ||
title: t("terms.attachments"), | ||
}, | ||
{ | ||
title: attachmentName, | ||
path: formatAttachmentPath(attachmentId), | ||
}, | ||
] | ||
: []), | ||
]} | ||
/> | ||
</PageSection> | ||
<PageSection> | ||
<div | ||
style={{ | ||
backgroundColor: "var(--pf-v5-global--BackgroundColor--100)", | ||
}} | ||
className="simple-task-viewer-container" | ||
> | ||
<SimpleDocumentViewer | ||
// force re-creating viewer via keys | ||
key={`${task?.id}/${task?.attached?.length}`} | ||
taskId={task ? taskId : undefined} | ||
documentId={resolvedAttachmentId || resolvedLogMode} | ||
attachments={task?.attached ?? []} | ||
onDocumentChange={onDocumentChange} | ||
height="full" | ||
/> | ||
</div> | ||
</PageSection> | ||
</> | ||
); | ||
}; |
Oops, something went wrong.