Skip to content

Commit 15198f5

Browse files
committed
Add flexible unit display for data view
1 parent 712abfa commit 15198f5

4 files changed

Lines changed: 15 additions & 8 deletions

File tree

frontend/src/pages/DataViewPage/CloeDataViewPage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,5 @@ export const CloeDataViewPage = () => (
1919
plotYLabel="Fill [%]"
2020
plotYMin={0}
2121
plotYMax={100}
22-
latestValueUnit="%"
2322
/>
2423
)

frontend/src/pages/DataViewPage/DataView.tsx

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ interface DataViewProps {
5151
plotYLabel: string
5252
plotYMin: number
5353
plotYMax: number
54-
latestValueUnit: string
5554
}
5655

5756
export const DataView = ({
@@ -63,7 +62,6 @@ export const DataView = ({
6362
plotYLabel,
6463
plotYMin,
6564
plotYMax,
66-
latestValueUnit,
6765
}: DataViewProps) => {
6866
const { TranslateText } = useLanguageContext()
6967
const { installation } = useContext(InstallationContext)
@@ -209,7 +207,6 @@ export const DataView = ({
209207
setSelectedTagId(tagId)
210208
setSelectedDataPoint(null)
211209
}}
212-
latestValueUnit={latestValueUnit}
213210
/>
214211
)}
215212
{plantCode && mapMission && (

frontend/src/pages/DataViewPage/DataViewTable.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@ import { DescriptionDisplay, TagIdDisplay } from 'components/Displays/TaskDispla
66
import { Task } from 'models/Task'
77
import { formatDateTime } from 'utils/StringFormatting'
88

9+
const unitDisplaySymbols: Record<string, string> = {
10+
celsius: '°C',
11+
percentage: '%',
12+
}
13+
14+
const formatUnit = (unit?: string): string => {
15+
if (!unit) return ''
16+
const normalizedUnit = unit
17+
.toLowerCase()
18+
.replace(/\s*\[.*\]\s*/, '')
19+
.trim()
20+
return unitDisplaySymbols[normalizedUnit] ?? unit
21+
}
22+
923
export const DataViewTable = ({
1024
tasks,
1125
selectedTagId,
1226
onSelectTag,
13-
latestValueUnit,
1427
}: {
1528
tasks: Task[]
1629
selectedTagId: string | null
1730
onSelectTag: (tagId: string | null) => void
18-
latestValueUnit: string
1931
}) => {
2032
const { TranslateText } = useLanguageContext()
2133

@@ -68,7 +80,7 @@ export const DataViewTable = ({
6880
<Table.Cell>
6981
<Typography>
7082
{Math.round(parseFloat(task.inspection.analysisResult?.value)) +
71-
latestValueUnit}
83+
formatUnit(task.inspection.analysisResult?.unit)}
7284
</Typography>
7385
</Table.Cell>
7486
) : (

frontend/src/pages/DataViewPage/ThermalReadingViewPage.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const ThermalReadingViewPage = () => {
2121
plotYLabel="Temperature [°C]"
2222
plotYMin={-20}
2323
plotYMax={100}
24-
latestValueUnit="°C"
2524
/>
2625
)
2726
}

0 commit comments

Comments
 (0)