-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathMetadataSection.tsx
171 lines (163 loc) · 5.11 KB
/
MetadataSection.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// SPDX-FileCopyrightText: 2017-2024 City of Espoo
//
// SPDX-License-Identifier: LGPL-2.1-or-later
import React from 'react'
import styled from 'styled-components'
import { Result } from 'lib-common/api'
import { useBoolean } from 'lib-common/form/hooks'
import {
DocumentMetadata,
ProcessMetadataResponse
} from 'lib-common/generated/api-types/process'
import { Button } from 'lib-components/atoms/buttons/Button'
import { CollapsibleContentArea as Collapsible } from 'lib-components/layout/Container'
import {
FixedSpaceColumn,
FixedSpaceRow
} from 'lib-components/layout/flex-helpers'
import { H2, H3 } from 'lib-components/typography'
import { Gap } from 'lib-components/white-space'
import { faArrowDownToLine } from 'lib-icons'
import { useTranslation } from '../../state/i18n'
import { renderResult } from '../async-rendering'
import LabelValueList from '../common/LabelValueList'
const DocumentMetadata = React.memo(function DocumentMetadata({
document
}: {
document: DocumentMetadata
}) {
const { i18n } = useTranslation()
return (
<div>
<LabelValueList
spacing="small"
contents={[
{
label: i18n.metadata.name,
value: (
<FixedSpaceRow>
<span>{document.name}</span>
{document.downloadPath !== null && (
<Button
appearance="inline"
icon={faArrowDownToLine}
text={i18n.metadata.downloadPdf}
onClick={() => {
window.open(
`/api${document.downloadPath}`,
'_blank',
'noopener,noreferrer'
)
}}
/>
)}
</FixedSpaceRow>
)
},
{
label: i18n.metadata.documentId,
value: document.documentId
},
{
label: i18n.metadata.createdAt,
value: document.createdAt?.format() ?? '-'
},
{
label: i18n.metadata.createdBy,
value: document.createdBy
? `${document.createdBy.name} (${i18n.common.userTypes[document.createdBy.type]}) `
: '-'
},
...(document.receivedBy
? [
{
label: i18n.metadata.receivedBy.label,
value: i18n.metadata.receivedBy[document.receivedBy]
}
]
: []),
{
label: i18n.metadata.confidentiality,
value:
document.confidential === true
? i18n.metadata.confidential
: document.confidential === false
? i18n.metadata.public
: i18n.metadata.notSet
}
]}
/>
</div>
)
})
export default React.memo(function MetadataSection({
metadataResult
}: {
metadataResult: Result<ProcessMetadataResponse>
}) {
const { i18n } = useTranslation()
const [sectionOpen, { toggle: toggleOpen }] = useBoolean(false)
return (
<CollapsibleContentArea
title={<H2 noMargin>{i18n.metadata.title}</H2>}
open={sectionOpen}
toggleOpen={toggleOpen}
opaque
>
{renderResult(metadataResult, ({ data: metadata }) => {
if (metadata === null) return <div>{i18n.metadata.notFound}</div>
return (
<div>
<LabelValueList
spacing="small"
contents={[
{
label: i18n.metadata.processNumber,
value: metadata.process.processNumber
},
{
label: i18n.metadata.organization,
value: metadata.process.organization
},
{
label: i18n.metadata.archiveDurationMonths,
value: `${metadata.process.archiveDurationMonths} ${i18n.metadata.monthsUnit}`
}
]}
/>
<Gap />
<H3>{i18n.metadata.primaryDocument}</H3>
<DocumentMetadata document={metadata.primaryDocument} />
{metadata.secondaryDocuments.length > 0 && (
<>
<Gap />
<H3>{i18n.metadata.secondaryDocuments}</H3>
<FixedSpaceColumn>
{metadata.secondaryDocuments.map((doc, i) => (
<DocumentMetadata key={i} document={doc} />
))}
</FixedSpaceColumn>
</>
)}
<Gap />
<H3>{i18n.metadata.history}</H3>
<ul>
{metadata.process.history.map((row) => (
<li key={row.rowIndex}>
{row.enteredAt.format()}: {i18n.metadata.states[row.state]},{' '}
{row.enteredBy.name} (
{i18n.common.userTypes[row.enteredBy.type]})
</li>
))}
</ul>
</div>
)
})}
</CollapsibleContentArea>
)
})
const CollapsibleContentArea = styled(Collapsible)`
@media print {
display: none;
}
`