Skip to content

Commit

Permalink
Add placeholders to inspection report
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Jan 31, 2025
1 parent c96f76f commit 7608eaf
Show file tree
Hide file tree
Showing 9 changed files with 176 additions and 72 deletions.
9 changes: 6 additions & 3 deletions frontend/src/components/Contexts/InpectionsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ export const InspectionsProvider: FC<Props> = ({ children }) => {
setSelectedInspectionTask(selectedTask)
}

const fetchImageData = (inspectionId: string) => {
const data = useQuery({
const fetchImageData = (
inspectionId: string
): { data: string | undefined; isPending: boolean; isError: Boolean } => {
const result = useQuery({
queryKey: ['fetchInspectionData', inspectionId],
queryFn: async () => {
const imageBlob = await BackendAPICaller.getInspection(inspectionId)
Expand All @@ -55,7 +57,8 @@ export const InspectionsProvider: FC<Props> = ({ children }) => {
staleTime: 10 * 60 * 1000, // If data is received, stale time is 10 min before making new API call
enabled: inspectionId !== undefined,
})
return data

return { data: result.data, isPending: result.isPending, isError: result.isError }
}

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import {
StyledInspectionOverviewSection,
} from './InspectionStyles'
import { Typography } from '@equinor/eds-core-react'
import { GetInspectionImage } from './InspectionReportUtilities'
import { formatDateTime } from 'utils/StringFormatting'
import { SmallInspectionImage } from 'components/Pages/InspectionReportPage/InspectionReportImage'

const InspectionOverview = ({ tasks }: { tasks: Task[] }) => {
const { TranslateText } = useLanguageContext()
Expand All @@ -29,7 +29,7 @@ const InspectionOverview = ({ tasks }: { tasks: Task[] }) => {
key={task.isarTaskId}
onClick={() => switchSelectedInspectionTask(task)}
>
<GetInspectionImage task={task} />
<SmallInspectionImage task={task} />
<StyledInspectionData>
{task.tagId && (
<StyledInspectionContent>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
import { useInspectionsContext } from 'components/Contexts/InpectionsContext'
import { Task } from 'models/Task'
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 { ValidInspectionReportInspectionTypes } from 'models/Inspection'
import { useLanguageContext } from 'components/Contexts/LanguageContext'

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%;
`

const LargeImageErrorPlaceholder = ({ errorMessage }: { errorMessage: string }) => {
const { TranslateText } = useLanguageContext()

return (
<StyledLargeImagePlaceholder>
<Typography variant="h3" color={tokens.colors.text.static_icons__tertiary.hex}>
{TranslateText(errorMessage)}
</Typography>
</StyledLargeImagePlaceholder>
)
}

const SmallImageErrorPlaceholder = ({ errorMessage }: { errorMessage: string }) => {
const { TranslateText } = useLanguageContext()

return (
<StyledSmallImagePlaceholder>
<Typography color={tokens.colors.text.static_icons__tertiary.hex}>{TranslateText(errorMessage)}</Typography>
</StyledSmallImagePlaceholder>
)
}

const LargeImagePendingPlaceholder = () => {
const { TranslateText } = useLanguageContext()

return (
<StyledLargeImagePlaceholder>
<Typography variant="h3" color={tokens.colors.text.static_icons__tertiary.hex}>
{TranslateText('Waiting for inspection result')}
</Typography>
<CircularProgress size={48} />
</StyledLargeImagePlaceholder>
)
}

const SmallImagePendingPlaceholder = () => {
return (
<StyledCircularProgress>
<CircularProgress />
</StyledCircularProgress>
)
}

const InspectionImageWithPlaceholder = ({ task, isLargeImage }: { task: Task; isLargeImage: boolean }) => {
const { fetchImageData } = useInspectionsContext()
const { data, isPending, isError } = fetchImageData(task.inspection.isarInspectionId)

if (!ValidInspectionReportInspectionTypes.includes(task.inspection.inspectionType)) {
const errorMsg = 'Inspection type not supported'
return isLargeImage ? (
<LargeImageErrorPlaceholder errorMessage={errorMsg} />
) : (
<SmallImageErrorPlaceholder errorMessage={errorMsg} />
)
} else if (isError) {
const errorMsg = 'No inspection could be found'
return isLargeImage ? (
<LargeImageErrorPlaceholder errorMessage={errorMsg} />
) : (
<SmallImageErrorPlaceholder errorMessage={errorMsg} />
)
} else if (isPending) {
return isLargeImage ? <LargeImagePendingPlaceholder /> : <SmallImagePendingPlaceholder />
} else
return isLargeImage ? (
<StyledInspection $otherContentHeight={'174px'} src={data} />
) : (
<StyledInspectionImage src={data} />
)
}

export const LargeDialogInspectionImage = ({ task }: { task: Task }) => {
return <InspectionImageWithPlaceholder task={task} isLargeImage={true} />
}

export const SmallInspectionImage = ({ task }: { task: Task }) => {
return <InspectionImageWithPlaceholder task={task} isLargeImage={false} />
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export const StyledDialogHeader = styled.div`
export const StyledBottomContent = styled.div`
display: flex;
padding: 16px;
gap: 16px;
justify-content: space-between;
align-items: center;
align-self: stretch;
Expand Down
104 changes: 48 additions & 56 deletions frontend/src/components/Pages/InspectionReportPage/InspectionView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
StyledDialogHeader,
StyledDialogInspectionView,
StyledInfoContent,
StyledInspection,
} from './InspectionStyles'
import { InspectionOverviewDialogView } from './InspectionOverview'
import { useState } from 'react'
import { LargeDialogInspectionImage } from './InspectionReportImage'
interface InspectionDialogViewProps {
selectedTask: Task
tasks: Task[]
Expand All @@ -26,10 +26,10 @@ export const InspectionDialogView = ({ selectedTask, tasks }: InspectionDialogVi
const { TranslateText } = useLanguageContext()
const { installationName } = useInstallationContext()
const { switchSelectedInspectionTask } = useInspectionsContext()
const { fetchImageData } = useInspectionsContext()
const { data } = fetchImageData(selectedTask.inspection.isarInspectionId)
const [switchImageDirection, setSwitchImageDirection] = useState<number>(0)

const successfullyCompletedTasks = tasks.filter((task) => task.status === 'Successful')

const closeDialog = () => {
switchSelectedInspectionTask(undefined)
}
Expand All @@ -47,64 +47,56 @@ export const InspectionDialogView = ({ selectedTask, tasks }: InspectionDialogVi
(event.code === 'ArrowLeft' && switchImageDirection === -1) ||
(event.code === 'ArrowRight' && switchImageDirection === 1)
) {
const nextTask = tasks.indexOf(selectedTask) + switchImageDirection
if (nextTask >= 0 && nextTask < tasks.length) {
switchSelectedInspectionTask(tasks[nextTask])
const nextTask = successfullyCompletedTasks.indexOf(selectedTask) + switchImageDirection
if (nextTask >= 0 && nextTask < successfullyCompletedTasks.length) {
switchSelectedInspectionTask(successfullyCompletedTasks[nextTask])
}
setSwitchImageDirection(0)
}
})

return (
<>
{data !== undefined && (
<StyledDialog open={true} isDismissable onClose={closeDialog}>
<StyledDialogContent>
<StyledDialogHeader>
<Typography variant="accordion_header" group="ui">
{TranslateText('Inspection report')}
</Typography>
<StyledCloseButton variant="ghost" onClick={closeDialog}>
<Icon name={Icons.Clear} size={24} />
</StyledCloseButton>
</StyledDialogHeader>
<StyledDialogInspectionView>
<div>
<StyledInspection $otherContentHeight={'174px'} src={data} />
<StyledBottomContent>
<StyledInfoContent>
<Typography variant="caption">{TranslateText('Installation') + ':'}</Typography>
<Typography variant="body_short">{installationName}</Typography>
</StyledInfoContent>
<StyledInfoContent>
<Typography variant="caption">{TranslateText('Tag') + ':'}</Typography>
<Typography variant="body_short">{selectedTask.tagId}</Typography>
</StyledInfoContent>
{selectedTask.description && (
<StyledInfoContent>
<Typography variant="caption">
{TranslateText('Description') + ':'}
</Typography>
<Typography variant="body_short">{selectedTask.description}</Typography>
</StyledInfoContent>
)}
{selectedTask.endTime && (
<StyledInfoContent>
<Typography variant="caption">
{TranslateText('Timestamp') + ':'}
</Typography>
<Typography variant="body_short">
{formatDateTime(selectedTask.endTime, 'dd.MM.yy - HH:mm')}
</Typography>
</StyledInfoContent>
)}
</StyledBottomContent>
</div>
<InspectionOverviewDialogView tasks={tasks} />
</StyledDialogInspectionView>
</StyledDialogContent>
</StyledDialog>
)}
</>
<StyledDialog open={true} isDismissable onClose={closeDialog}>
<StyledDialogContent>
<StyledDialogHeader>
<Typography variant="accordion_header" group="ui">
{TranslateText('Inspection report')}
</Typography>
<StyledCloseButton variant="ghost" onClick={closeDialog}>
<Icon name={Icons.Clear} size={24} />
</StyledCloseButton>
</StyledDialogHeader>
<StyledDialogInspectionView>
<div>
<LargeDialogInspectionImage task={selectedTask} />
<StyledBottomContent>
<StyledInfoContent>
<Typography variant="caption">{TranslateText('Installation') + ':'}</Typography>
<Typography variant="body_short">{installationName}</Typography>
</StyledInfoContent>
<StyledInfoContent>
<Typography variant="caption">{TranslateText('Tag') + ':'}</Typography>
<Typography variant="body_short">{selectedTask.tagId}</Typography>
</StyledInfoContent>
{selectedTask.description && (
<StyledInfoContent>
<Typography variant="caption">{TranslateText('Description') + ':'}</Typography>
<Typography variant="body_short">{selectedTask.description}</Typography>
</StyledInfoContent>
)}
{selectedTask.endTime && (
<StyledInfoContent>
<Typography variant="caption">{TranslateText('Timestamp') + ':'}</Typography>
<Typography variant="body_short">
{formatDateTime(selectedTask.endTime, 'dd.MM.yy - HH:mm')}
</Typography>
</StyledInfoContent>
)}
</StyledBottomContent>
</div>
<InspectionOverviewDialogView tasks={tasks} />
</StyledDialogInspectionView>
</StyledDialogContent>
</StyledDialog>
)
}
5 changes: 4 additions & 1 deletion frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,8 @@
"Pressure is too high to start a mission.": "Pressure is too high to start a mission.",
"Pressure is too low to start a mission. Queued missions will start when the pressure is over {0}mBar.": "Pressure is too low to start a mission. Queued missions will start when the pressure is over {0}mBar.",
"Pressure is too low to start a mission.": "Pressure is too low to start a mission.",
"Queued Missions": "Queued Missions"
"Queued Missions": "Queued Missions",
"Waiting for inspection result": "Waiting for inspection result",
"Inspection type not supported": "Inspection type not supported",
"No inspection could be found": "No inspection could be found"
}
5 changes: 4 additions & 1 deletion frontend/src/language/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,5 +276,8 @@
"Pressure is too high to start a mission.": "Trykket er for høyt til å starte oppdrag.",
"Pressure is too low to start a mission. Queued missions will start when the pressure is over {0}mBar.": "Trykket er for lavt til å starte oppdrag. Oppdrag i kø vil starte når trykket er over {0}mBar.",
"Pressure is too low to start a mission.": "Trykket er for lavt til å starte oppdrag.",
"Queued Missions": "Oppdragskø"
"Queued Missions": "Oppdragskø",
"Waiting for inspection result": "Venter på inspeksjonsresultat",
"Inspection type not supported": "Inspeksjonstypen støttes ikke",
"No inspection could be found": "Ingen inspeksjon ble funnet"
}
2 changes: 2 additions & 0 deletions frontend/src/models/Inspection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export enum InspectionType {
Audio = 'Audio',
}

export const ValidInspectionReportInspectionTypes: InspectionType[] = [InspectionType.Image]

export interface IdaInspectionVisualizationReady {
inspectionId: string
storageAccount: string
Expand Down

0 comments on commit 7608eaf

Please sign in to comment.