forked from equinor/flotilla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInspectionReportImage.tsx
More file actions
181 lines (164 loc) · 5.86 KB
/
Copy pathInspectionReportImage.tsx
File metadata and controls
181 lines (164 loc) · 5.86 KB
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
172
173
174
175
176
177
178
179
180
181
import { useInspectionsContext } from 'components/Contexts/InspectionsContext'
import { StyledInspection, StyledInspectionImage } from './InspectionStyles'
import { tokens } from '@equinor/eds-tokens'
import { CircularProgress, Typography } from '@equinor/eds-core-react'
import styled from 'styled-components'
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { VideoPlaceholder, VideoPlayer } from './InspectionVideoPlayer'
import { FileType, InspectionData } from 'models/InspectionRecord'
const StyledSmallImagePlaceholder = styled.div`
display: flex;
justify-content: center;
align-items: flex-start;
padding: 16px 8px;
height: 100%;
`
const StyledLargeImagePlaceholder = styled.div`
display: flex;
flex-direction: column;
align-items: center;
padding: 16px;
gap: 16px;
`
const StyledCircularProgress = styled.div`
display: flex;
align-items: center;
align-self: center;
padding: 16px;
height: 100%;
`
export const TextAsImage = ({
isLargeImage,
text,
textArgs,
}: {
isLargeImage: boolean
text: string
textArgs?: string[]
}) => {
const { TranslateText } = useLanguageContext()
if (isLargeImage) {
return (
<StyledLargeImagePlaceholder>
<Typography variant="h3" color={tokens.colors.text.static_icons__tertiary.hex}>
{TranslateText(text, textArgs)}
</Typography>
</StyledLargeImagePlaceholder>
)
}
return (
<StyledSmallImagePlaceholder>
<Typography color={tokens.colors.text.static_icons__tertiary.hex}>
{TranslateText(text, textArgs)}
</Typography>
</StyledSmallImagePlaceholder>
)
}
export const PendingResultPlaceholder = ({ isLargeImage }: { isLargeImage: boolean }) => {
const { TranslateText } = useLanguageContext()
if (isLargeImage) {
return (
<StyledLargeImagePlaceholder>
<Typography variant="h3" color={tokens.colors.text.static_icons__tertiary.hex}>
{TranslateText('Waiting for inspection result')}
</Typography>
<CircularProgress size={48} />
</StyledLargeImagePlaceholder>
)
}
return (
<StyledCircularProgress>
<CircularProgress />
</StyledCircularProgress>
)
}
export const InspectionImageWithPlaceholder = ({
inspection,
isLargeImage,
}: {
inspection: InspectionData
isLargeImage: boolean
}) =>
isLargeImage ? (
<StyledInspection $otherContentHeight={'174px'} src={inspection.anonymizedSAS} />
) : (
<StyledInspectionImage src={inspection.anonymizedSAS} />
)
const InspectionValueWithPlaceholder = ({
inspection,
isLargeImage,
}: {
inspection: InspectionData
isLargeImage: boolean
}) => {
if (!inspection.value) {
const errorMsg = 'No inspection could be found'
return <TextAsImage isLargeImage={isLargeImage} text={errorMsg} />
} else {
return (
<TextAsImage
isLargeImage={isLargeImage}
text={`${inspection.inspectionDescription}: {0} ${inspection.unit}`}
textArgs={[parseFloat(inspection.value).toFixed(3).toString()]}
/>
)
}
}
const InspectionVideoWithPlaceholder = ({
inspection,
isLargeImage,
}: {
inspection: InspectionData
isLargeImage: boolean
}) => (isLargeImage ? <LargeVideoWithPlaceholder inspection={inspection} /> : <VideoPlaceholder />)
const LargeVideoWithPlaceholder = ({ inspection }: { inspection: InspectionData }) =>
inspection.anonymizedSAS ? <VideoPlayer src={inspection.anonymizedSAS} /> : <VideoPlaceholder />
const InspectionResultWithPlaceholder = ({
inspection,
isLargeImage,
}: {
inspection: InspectionData
isLargeImage: boolean
}) => {
if (inspection.fileType === FileType.SOUND) {
const errorMsg = 'Viewing of the inspection type is not supported'
return <TextAsImage isLargeImage={isLargeImage} text={errorMsg} />
} else if (inspection.fileType === FileType.VALUE) {
return <InspectionValueWithPlaceholder inspection={inspection} isLargeImage={isLargeImage} />
} else if (inspection.fileType === FileType.IMAGE) {
return <InspectionImageWithPlaceholder inspection={inspection} isLargeImage={isLargeImage} />
} else if (inspection.fileType === FileType.VIDEO) {
return <InspectionVideoWithPlaceholder inspection={inspection} isLargeImage={isLargeImage} />
}
}
export const LargeDialogInspectionResult = ({ inspection }: { inspection: InspectionData }) => (
<InspectionResultWithPlaceholder inspection={inspection} isLargeImage={true} />
)
export const SmallInspectionResult = ({ inspection }: { inspection: InspectionData }) => (
<InspectionResultWithPlaceholder inspection={inspection} isLargeImage={false} />
)
const AnalysisImageWithPlaceholder = ({
inspectionId,
isLargeImage,
}: {
inspectionId: string
isLargeImage: boolean
}) => {
const { useSaraData } = useInspectionsContext()
const { data, isPending, isError } = useSaraData(inspectionId)
if (!data?.visualizedSAS) {
return <TextAsImage isLargeImage={isLargeImage} text={'No analysis available'} />
} else if (isPending) {
return <PendingResultPlaceholder isLargeImage={isLargeImage} />
} else if (isError || !data) {
return <TextAsImage isLargeImage={isLargeImage} text={'No analysis could be found'} />
} else
return isLargeImage ? (
<StyledInspection $otherContentHeight={'174px'} src={data.visualizedSAS} />
) : (
<StyledInspectionImage src={data.visualizedSAS} />
)
}
export const SmallAnalysisResult = ({ inspectionId }: { inspectionId: string }) => (
<AnalysisImageWithPlaceholder inspectionId={inspectionId} isLargeImage={false} />
)