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 { Paths , TaskDetailsAttachmentRoute } from "@app/Paths" ;
8
- import { PageHeader , PageHeaderProps } from "@app/components/PageHeader" ;
9
- import {
10
- DocumentId ,
11
- SimpleDocumentViewer ,
12
- } from "@app/components/simple-document-viewer" ;
13
- import { useFetchTaskByID } from "@app/queries/tasks" ;
14
6
import "@app/components/simple-document-viewer/SimpleDocumentViewer.css" ;
15
7
import { formatPath } from "@app/utils/utils" ;
16
-
17
- export const TaskDetailsBase : React . FC < {
18
- breadcrumbs : PageHeaderProps [ "breadcrumbs" ] ;
19
- formatTitle : ( taskName : string ) => string ;
20
- detailsPath : string ;
21
- formatAttachmentPath : ( attachmentId : number | string ) => string ;
22
- taskId : number ;
23
- attachmentId ?: string ;
24
- } > = ( {
25
- breadcrumbs,
26
- formatTitle,
27
- detailsPath,
28
- formatAttachmentPath,
29
- taskId,
30
- attachmentId,
31
- } ) => {
32
- const { t } = useTranslation ( ) ;
33
-
34
- const { search } = useLocation ( ) ;
35
- const hasMergedParam = new URLSearchParams ( search ) . has ( "merged" ) ;
36
-
37
- const history = useHistory ( ) ;
38
- const onDocumentChange = ( documentId : DocumentId ) =>
39
- typeof documentId === "number"
40
- ? history . push ( formatAttachmentPath ( documentId ) )
41
- : history . push ( {
42
- pathname : detailsPath ,
43
- search : documentId === "MERGED_VIEW" ? "?merged=true" : undefined ,
44
- } ) ;
45
-
46
- const { task } = useFetchTaskByID ( taskId ) ;
47
-
48
- const taskName : string = task ?. 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
-
57
- return (
58
- < >
59
- < PageSection variant = "light" >
60
- < PageHeader
61
- title = { formatTitle ( taskName ) }
62
- breadcrumbs = { [
63
- ...breadcrumbs ,
64
- ...( attachmentName && attachmentId
65
- ? [
66
- {
67
- title : t ( "terms.attachments" ) ,
68
- } ,
69
- {
70
- title : attachmentName ,
71
- path : formatAttachmentPath ( attachmentId ) ,
72
- } ,
73
- ]
74
- : [ ] ) ,
75
- ] }
76
- />
77
- </ PageSection >
78
- < PageSection >
79
- < div
80
- style = { {
81
- backgroundColor : "var(--pf-v5-global--BackgroundColor--100)" ,
82
- } }
83
- className = "simple-task-viewer-container"
84
- >
85
- < SimpleDocumentViewer
86
- // force re-creating viewer via keys
87
- key = { `${ task ?. id } /${ task ?. attached ?. length } ` }
88
- taskId = { task ? taskId : undefined }
89
- documentId = { resolvedAttachmentId || resolvedLogMode }
90
- attachments = { task ?. attached ?? [ ] }
91
- onDocumentChange = { onDocumentChange }
92
- height = "full"
93
- />
94
- </ div >
95
- </ PageSection >
96
- </ >
97
- ) ;
98
- } ;
8
+ import { TaskDetailsBase } from "./TaskDetailsBase" ;
99
9
100
10
export const TaskDetails = ( ) => {
101
11
const { t } = useTranslation ( ) ;
@@ -109,12 +19,12 @@ export const TaskDetails = () => {
109
19
path : Paths . tasks ,
110
20
} ,
111
21
{
112
- title : t ( "actions.taskDetails" ) ,
22
+ title : t ( "actions.taskDetails" , { taskId } ) ,
113
23
path : detailsPath ,
114
24
} ,
115
25
] }
116
26
detailsPath = { detailsPath }
117
- formatTitle = { ( taskName ) => `Details for ${ taskName } ` }
27
+ formatTitle = { ( taskName ) => `Task details for task ${ taskId } , ${ taskName } ` }
118
28
formatAttachmentPath = { ( attachmentId ) =>
119
29
formatPath ( Paths . taskDetailsAttachment , {
120
30
taskId,
0 commit comments