Skip to content

Commit

Permalink
Only display deck if relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Nov 29, 2024
1 parent 8bbe1b1 commit fbb8f50
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const InspectionOverviewSection = () => {
return (
<Tabs activeTab={activeTab} onChange={setActiveTab}>
<Tabs.List>
<Tabs.Tab>{TranslateText('Deck Overview')}</Tabs.Tab>
<Tabs.Tab>{TranslateText('Inspection Overview')}</Tabs.Tab>
<Tabs.Tab>{TranslateText('Predefined Missions')}</Tabs.Tab>
</Tabs.List>
<Tabs.Panels>
Expand Down
80 changes: 46 additions & 34 deletions frontend/src/components/Pages/InspectionPage/InspectionSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ interface DeckAreaTuple {
}

export const InspectionSection = () => {
const { ongoingMissions, missionQueue } = useMissionsContext()
const { installationDecks, installationAreas } = useInstallationContext()
const [selectedDeck, setSelectedDeck] = useState<Deck>()
const { missionDefinitions } = useMissionDefinitionsContext()
const [selectedMissions, setSelectedMissions] = useState<MissionDefinition[]>()
const [isDialogOpen, setIsDialogOpen] = useState<boolean>(false)
const [isAlreadyScheduled, setIsAlreadyScheduled] = useState<boolean>(false)
const [selectedDeck, setSelectedDeck] = useState<Deck>()
const [scrollOnToggle, setScrollOnToggle] = useState<boolean>(true)
const { ongoingMissions, missionQueue } = useMissionsContext()
const { missionDefinitions } = useMissionDefinitionsContext()

const decks: DeckAreaTuple[] = installationDecks.map((deck) => {
return {
Expand All @@ -44,24 +44,7 @@ export const InspectionSection = () => {
}
})

const closeDialog = () => {
setIsAlreadyScheduled(false)
setSelectedMissions([])
setIsDialogOpen(false)
}

const isScheduled = (mission: MissionDefinition) => missionQueue.map((m) => m.missionId).includes(mission.id)
const isOngoing = (mission: MissionDefinition) => ongoingMissions.map((m) => m.missionId).includes(mission.id)

const unscheduledMissions = selectedMissions?.filter((m) => !isOngoing(m) && !isScheduled(m))

useEffect(() => {
if (selectedMissions && selectedMissions.some((mission) => isOngoing(mission) || isScheduled(mission)))
setIsAlreadyScheduled(true)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ongoingMissions, missionQueue, selectedMissions])

const deckMissions: DeckInspectionTuple[] =
const deckInspections: DeckInspectionTuple[] =
decks?.map(({ areas, deck }) => {
const missionDefinitionsInDeck = missionDefinitions.filter((m) => m.area?.deckName === deck.deckName)
return {
Expand All @@ -78,33 +61,62 @@ export const InspectionSection = () => {
}
}) ?? []

const onClickDeck = (clickedDeck: Deck) => {
setSelectedDeck(clickedDeck)
setScrollOnToggle(!scrollOnToggle)
}

const isScheduled = (mission: MissionDefinition) => missionQueue.map((m) => m.missionId).includes(mission.id)
const isOngoing = (mission: MissionDefinition) => ongoingMissions.map((m) => m.missionId).includes(mission.id)

const closeDialog = () => {
setIsAlreadyScheduled(false)
setSelectedMissions([])
setIsDialogOpen(false)
}

const handleScheduleAll = (inspections: Inspection[]) => {
setIsDialogOpen(true)
const sortedInspections = inspections.sort(compareInspections)
setSelectedMissions(sortedInspections.map((i) => i.missionDefinition))
}

const onClickDeck = (clickedDeck: Deck) => {
setSelectedDeck(clickedDeck)
setScrollOnToggle(!scrollOnToggle)
}
useEffect(() => {
if (selectedMissions && selectedMissions.some((mission) => isOngoing(mission) || isScheduled(mission)))
setIsAlreadyScheduled(true)
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [ongoingMissions, missionQueue, selectedMissions])

const unscheduledMissions = selectedMissions?.filter((m) => !isOngoing(m) && !isScheduled(m))

const deck = installationDecks.length === 1 ? installationDecks[0] : selectedDeck
const inspections =
deckInspections.length === 1
? deckInspections[0].inspections
: deckInspections.find((d) => d.deck === deck)?.inspections

const DeckSelection = () => (
<StyledDict.DeckOverview>
<DeckCards
deckMissions={deckInspections}
onClickDeck={onClickDeck}
selectedDeck={selectedDeck}
handleScheduleAll={handleScheduleAll}
/>
</StyledDict.DeckOverview>
)

return (
<>
<StyledDict.DeckOverview>
<DeckCards
deckMissions={deckMissions}
onClickDeck={onClickDeck}
selectedDeck={selectedDeck}
handleScheduleAll={handleScheduleAll}
/>
{selectedDeck && (
{installationDecks.length !== 1 && <DeckSelection />}
{deck && inspections && (
<InspectionTable
deck={selectedDeck}
deck={deck}
scrollOnToggle={scrollOnToggle}
openDialog={() => setIsDialogOpen(true)}
setSelectedMissions={setSelectedMissions}
inspections={deckMissions.find((d) => d.deck.deckName === selectedDeck.deckName)!.inspections}
inspections={inspections}
/>
)}
</StyledDict.DeckOverview>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"lookout": "Lookout",
"transport": "Transport",
"Queue the missions": "Queue the missions",
"Deck Overview": "Deck Overview",
"Inspection Overview": "Inspection Overview",
"Predefined Missions": "Predefined Missions",
"Create new mission": "Create new mission",
"Must be inspected this week": "Must be inspected this week",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/language/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
"lookout": "Hevet posisjon",
"transport": "Transport",
"Queue the missions": "Legg oppdragene i kø",
"Deck Overview": "Dekkoversikt",
"Inspection Overview": "Inspeksjonsoversikt",
"Predefined Missions": "Forhåndsdefinerte oppdrag",
"Create new mission": "Lag nytt oppdrag",
"Must be inspected this week": "Må inspiseres denne uken",
Expand Down

0 comments on commit fbb8f50

Please sign in to comment.