Skip to content

Commit 9781ae9

Browse files
committed
Visualize auto scheduled missions
1 parent b510d91 commit 9781ae9

File tree

4 files changed

+129
-2
lines changed

4 files changed

+129
-2
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
import { Table, Typography } from '@equinor/eds-core-react'
2+
import { useLanguageContext } from 'components/Contexts/LanguageContext'
3+
import { useMissionDefinitionsContext } from 'components/Contexts/MissionDefinitionsContext'
4+
import { StyledTableBody, StyledTableCell } from 'components/Styles/StyledComponents'
5+
import { DaysOfWeek } from 'models/AutoScheduleFrequency'
6+
import { config } from 'config'
7+
import { useNavigate } from 'react-router-dom'
8+
import styled from 'styled-components'
9+
10+
const StyledSection = styled.div`
11+
display: flex;
12+
flex-direction: column;
13+
max-width: 960px;
14+
gap: 1rem;
15+
`
16+
const StyledTableRow = styled.div`
17+
display: flex;
18+
flex-direction: row;
19+
gap: 1rem;
20+
`
21+
const StyledHeader = styled.div`
22+
gap: 0px;
23+
`
24+
const StyledDayOverview = styled.div`
25+
display: grid;
26+
gap: 0px;
27+
`
28+
29+
const AutoScheduleList = () => {
30+
const { TranslateText } = useLanguageContext()
31+
const { missionDefinitions } = useMissionDefinitionsContext()
32+
const navigate = useNavigate()
33+
34+
const autoScheduleMissionDefinitions = missionDefinitions.filter((m) => m.autoScheduleFrequency)
35+
36+
const allDays = [
37+
DaysOfWeek.Monday,
38+
DaysOfWeek.Tuesday,
39+
DaysOfWeek.Wednesday,
40+
DaysOfWeek.Thursday,
41+
DaysOfWeek.Friday,
42+
DaysOfWeek.Saturday,
43+
DaysOfWeek.Sunday,
44+
]
45+
46+
const DayOverview = () =>
47+
allDays.map((day) => {
48+
const missionDefinitions = autoScheduleMissionDefinitions.filter((m) =>
49+
m.autoScheduleFrequency!.daysOfWeek.includes(day)
50+
)
51+
const timeMissionPairs = missionDefinitions
52+
.map((mission) =>
53+
mission.autoScheduleFrequency!.timesOfDay.map((time) => {
54+
return { time, mission }
55+
})
56+
)
57+
.flat()
58+
.sort((a, b) => (a.time > b.time ? 1 : -1))
59+
60+
return (
61+
<Table key={day}>
62+
<Table.Head>
63+
<Table.Row>
64+
<StyledTableCell>{TranslateText(day)}</StyledTableCell>
65+
</Table.Row>
66+
</Table.Head>
67+
<StyledTableBody>
68+
{timeMissionPairs.length > 0 ? (
69+
timeMissionPairs.map(({ time, mission }) => (
70+
<Table.Row
71+
key={mission.id + time}
72+
onClick={() =>
73+
navigate(`${config.FRONTEND_BASE_ROUTE}/mission-definition/${mission.id}`)
74+
}
75+
>
76+
<Table.Cell>
77+
<StyledTableRow>
78+
<Typography>{`${time.substring(0, 5)}`}</Typography>
79+
<Typography link>{mission.name}</Typography>
80+
</StyledTableRow>
81+
</Table.Cell>
82+
</Table.Row>
83+
))
84+
) : (
85+
<Table.Row>
86+
<Table.Cell>
87+
<Typography>{TranslateText('No missions')}</Typography>
88+
</Table.Cell>
89+
</Table.Row>
90+
)}
91+
</StyledTableBody>
92+
</Table>
93+
)
94+
})
95+
96+
return (
97+
<>
98+
{autoScheduleMissionDefinitions.length > 0 && (
99+
<StyledSection>
100+
<StyledHeader>
101+
<Typography variant="h1" color="resting">
102+
{TranslateText('Auto Scheduling')}
103+
</Typography>
104+
<Typography>
105+
{TranslateText('These missions will be automatically scheduled at the specified time')}
106+
</Typography>
107+
</StyledHeader>
108+
<StyledDayOverview>
109+
<DayOverview />
110+
</StyledDayOverview>
111+
</StyledSection>
112+
)}
113+
</>
114+
)
115+
}
116+
117+
export const AutoScheduleSection = () => {
118+
return AutoScheduleList()
119+
}

frontend/src/components/Pages/FrontPage/FrontPage.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { StopRobotDialog } from './MissionOverview/StopDialogs'
55
import { tokens } from '@equinor/eds-tokens'
66
import { MissionControlSection } from './MissionOverview/MissionControlSection'
77
import { redirectIfNoInstallationSelected } from 'utils/RedirectIfNoInstallationSelected'
8+
import { AutoScheduleSection } from './AutoScheduleSection/AutoScheduleSection'
89

910
const StyledFrontPage = styled.div`
1011
display: flex;
@@ -24,6 +25,7 @@ export const FrontPage = () => {
2425
<StyledFrontPage>
2526
<StopRobotDialog />
2627
<MissionControlSection />
28+
<AutoScheduleSection />
2729
<InspectionOverviewSection />
2830
</StyledFrontPage>
2931
</>

frontend/src/language/en.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,8 @@
299299
"No days have been selected. Please select days": "No days have been selected. Please select days",
300300
"No times have been selected. Please add time": "No times have been selected. Please add time",
301301
"Mission source id": "Mission source id",
302-
"Skip": "Skip"
302+
"Skip": "Skip",
303+
"No missions": "No missions",
304+
"Auto Scheduling": "Auto Scheduling",
305+
"These missions will be automatically scheduled at the specified time": "These missions will be automatically scheduled at the specified time"
303306
}

frontend/src/language/no.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,5 +299,8 @@
299299
"No days have been selected. Please select days": "Ingen dager er valgt. Vennligst velg dager",
300300
"No times have been selected. Please add time": "Ingen tidspunkt er valgt. Vennligst legg til tidspunkt",
301301
"Mission source id": "Mission source id",
302-
"Skip": "Neste"
302+
"Skip": "Neste",
303+
"No missions": "Ingen oppdrag",
304+
"Auto Scheduling": "Automatisk kjøring",
305+
"These missions will be automatically scheduled at the specified time": "Disse oppdragene vil automatisk bli kjørt på de spesifiserte tidspunktene"
303306
}

0 commit comments

Comments
 (0)