Skip to content

Commit af14dba

Browse files
committed
Add auto schedule button
1 parent 73e4fc7 commit af14dba

File tree

7 files changed

+117
-26
lines changed

7 files changed

+117
-26
lines changed

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

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
1-
import { Table, Typography } from '@equinor/eds-core-react'
1+
import { Button, Table, Typography } from '@equinor/eds-core-react'
22
import { useLanguageContext } from 'components/Contexts/LanguageContext'
33
import { useMissionDefinitionsContext } from 'components/Contexts/MissionDefinitionsContext'
4-
import { StyledTableBody, StyledTableCell } from 'components/Styles/StyledComponents'
4+
import { StyledDialog, StyledTableBody, StyledTableCell } from 'components/Styles/StyledComponents'
55
import { DaysOfWeek } from 'models/AutoScheduleFrequency'
66
import { config } from 'config'
77
import { useNavigate } from 'react-router-dom'
88
import styled from 'styled-components'
99
import { capitalizeFirstLetter } from 'utils/StringFormatting'
10+
import { StyledIcon } from 'components/Pages/InspectionPage/InspectionTable'
11+
import { Icons } from 'utils/icons'
12+
import { useState } from 'react'
13+
import { FormCard } from 'components/Pages/MissionDefinitionPage/MissionDefinitionStyledComponents'
14+
import { MissionDefinitionEditDialogContent } from 'components/Pages/MissionDefinitionPage/MissionDefinitionPage'
15+
import { MissionDefinition } from 'models/MissionDefinition'
16+
import { SelectMissionsComponent } from '../MissionOverview/ScheduleMissionDialog/SelectMissionsToScheduleDialog'
1017

1118
const StyledSection = styled.div`
1219
display: flex;
@@ -26,14 +33,46 @@ const StyledDayOverview = styled.div`
2633
display: grid;
2734
gap: 0px;
2835
`
36+
const StyledButtonSection = styled.div`
37+
display: flex;
38+
justify-content: flex-end;
39+
align-items: flex-start;
40+
gap: 8px;
41+
align-self: stretch;
42+
43+
@media (max-width: 600px) {
44+
justify-content: flex-start;
45+
}
46+
`
47+
const StyledButton = styled(Button)`
48+
display: flex;
49+
padding: 0px 16px;
50+
justify-content: center;
51+
align-items: center;
52+
gap: 8px;
53+
`
54+
55+
const StyledFormCard = styled(FormCard)`
56+
margin-top: 2px;
57+
`
2958

3059
const AutoScheduleList = () => {
3160
const { TranslateText } = useLanguageContext()
3261
const { missionDefinitions } = useMissionDefinitionsContext()
62+
const [dialogOpen, setDialogOpen] = useState<boolean>(false)
63+
const [selectedMissions, setSelectedMissions] = useState<MissionDefinition[]>([])
3364
const navigate = useNavigate()
3465

3566
const autoScheduleMissionDefinitions = missionDefinitions.filter((m) => m.autoScheduleFrequency)
3667

68+
const openDialog = () => {
69+
setDialogOpen(true)
70+
}
71+
const closeDialog = () => {
72+
setDialogOpen(false)
73+
setSelectedMissions([])
74+
}
75+
3776
const allDays = [
3877
DaysOfWeek.Monday,
3978
DaysOfWeek.Tuesday,
@@ -96,6 +135,12 @@ const AutoScheduleList = () => {
96135

97136
return (
98137
<>
138+
<StyledButtonSection>
139+
<StyledButton onClick={() => openDialog()}>
140+
<StyledIcon name={Icons.Add} size={24} />
141+
{TranslateText('New scheduled mission')}
142+
</StyledButton>
143+
</StyledButtonSection>
99144
{autoScheduleMissionDefinitions.length > 0 && (
100145
<StyledSection>
101146
<StyledHeader>
@@ -106,12 +151,37 @@ const AutoScheduleList = () => {
106151
<StyledDayOverview>
107152
<DayOverview />
108153
</StyledDayOverview>
154+
{dialogOpen && (
155+
<StyledDialog open={true}>
156+
<StyledDialog.Header>
157+
<StyledDialog.Title>
158+
<Typography variant="h3">{TranslateText('New scheduled mission')}</Typography>
159+
</StyledDialog.Title>
160+
</StyledDialog.Header>
161+
<StyledDialog.CustomContent>
162+
<SelectMissionsComponent
163+
missions={missionDefinitions}
164+
selectedMissions={selectedMissions}
165+
setSelectedMissions={setSelectedMissions}
166+
multiple={false}
167+
/>
168+
{dialogOpen && selectedMissions.length === 1 && (
169+
<StyledFormCard>
170+
<MissionDefinitionEditDialogContent
171+
missionDefinition={selectedMissions[0]}
172+
fieldName="autoScheduleFrequency"
173+
closeEditDialog={closeDialog}
174+
/>
175+
</StyledFormCard>
176+
)}
177+
</StyledDialog.CustomContent>
178+
</StyledDialog>
179+
)}
109180
</StyledSection>
110181
)}
111182
</>
112183
)
113184
}
114-
115185
export const AutoScheduleSection = () => {
116186
return AutoScheduleList()
117187
}

frontend/src/components/Pages/FrontPage/MissionOverview/ScheduleMissionDialog/SelectMissionsToScheduleDialog.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,17 @@ export const SelectMissionsToScheduleDialog = ({ missionsList, closeDialog }: Sc
122122
)
123123
}
124124

125-
const SelectMissionsComponent = memo(
125+
export const SelectMissionsComponent = memo(
126126
({
127127
missions,
128128
selectedMissions,
129129
setSelectedMissions,
130+
multiple = true,
130131
}: {
131132
missions: MissionDefinition[]
132133
selectedMissions: MissionDefinition[]
133134
setSelectedMissions: (missions: MissionDefinition[]) => void
135+
multiple?: boolean
134136
}) => {
135137
const { TranslateText } = useLanguageContext()
136138

@@ -141,7 +143,7 @@ const SelectMissionsComponent = memo(
141143
options={missions}
142144
onOptionsChange={(changes) => setSelectedMissions(changes.selectedItems)}
143145
label={TranslateText('Select missions')}
144-
multiple
146+
multiple={multiple}
145147
selectedOptions={selectedMissions}
146148
placeholder={`${selectedMissions.length}/${missions.length} ${TranslateText('selected')}`}
147149
autoWidth

frontend/src/components/Pages/InspectionPage/InspectionTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { useRobotContext } from 'components/Contexts/RobotContext'
1717
import { FrontPageSectionId } from 'models/FrontPageSectionId'
1818
import { SmallScreenInfoText } from 'utils/InfoText'
1919

20-
const StyledIcon = styled(Icon)`
20+
export const StyledIcon = styled(Icon)`
2121
display: flex;
2222
justify-content: center;
2323
height: 1.3rem;

frontend/src/components/Pages/MissionDefinitionPage/MissionDefinitionPage.tsx

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ import {
3434
TitleComponent,
3535
} from './MissionDefinitionStyledComponents'
3636

37+
const StyledFormCard = styled(FormCard)`
38+
max-width: 340px;
39+
`
40+
3741
const StyledCard = styled(Card)`
3842
display: flex;
3943
padding: 8px;
@@ -195,7 +199,7 @@ interface IMissionDefinitionEditDialogProps {
195199
closeEditDialog: () => void
196200
}
197201

198-
const MissionDefinitionEditDialog = ({
202+
export const MissionDefinitionEditDialogContent = ({
199203
missionDefinition,
200204
fieldName,
201205
closeEditDialog,
@@ -281,25 +285,38 @@ const MissionDefinitionEditDialog = ({
281285
}
282286
}
283287

288+
return (
289+
<>
290+
{getFormItem()}
291+
<ButtonSection>
292+
<Button onClick={() => closeEditDialog()} variant="outlined" color="primary">
293+
{TranslateText('Cancel')}
294+
</Button>
295+
<Button onClick={handleSubmit} disabled={isUpdateButtonDisabled()} variant="contained" color="primary">
296+
{TranslateText('Update')}
297+
</Button>
298+
</ButtonSection>
299+
</>
300+
)
301+
}
302+
303+
const MissionDefinitionEditDialog = ({
304+
missionDefinition,
305+
fieldName,
306+
closeEditDialog,
307+
}: IMissionDefinitionEditDialogProps) => {
308+
const { TranslateText } = useLanguageContext()
309+
284310
return (
285311
<StyledDialog open={true}>
286-
<FormCard>
312+
<StyledFormCard>
287313
<Typography variant="h2">{TranslateText('Edit') + ' ' + TranslateText(fieldName)}</Typography>
288-
{getFormItem()}
289-
<ButtonSection>
290-
<Button onClick={() => closeEditDialog()} variant="outlined" color="primary">
291-
{TranslateText('Cancel')}
292-
</Button>
293-
<Button
294-
onClick={handleSubmit}
295-
disabled={isUpdateButtonDisabled()}
296-
variant="contained"
297-
color="primary"
298-
>
299-
{TranslateText('Update')}
300-
</Button>
301-
</ButtonSection>
302-
</FormCard>
314+
<MissionDefinitionEditDialogContent
315+
missionDefinition={missionDefinition}
316+
fieldName={fieldName}
317+
closeEditDialog={closeEditDialog}
318+
/>
319+
</StyledFormCard>
303320
</StyledDialog>
304321
)
305322
}

frontend/src/components/Pages/MissionDefinitionPage/MissionDefinitionStyledComponents.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const FormCard = styled(Card)`
66
justify-content: center;
77
padding: 8px;
88
gap: 25px;
9-
max-width: 340px;
9+
box-shadow: none;
1010
`
1111

1212
export const ButtonSection = styled.div`

frontend/src/language/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,6 @@
319319
"Info: Updating mission tasks..": "Updating of mission tasks occur in 'Echo Mission planner'. If using inspection target from STID, the value will be fetched from STID when the mission is set to ready. If the position in STID is updated, the mission will not use the updated value unless the mission in the mission planner gets set to ready again.",
320320
"Remove all": "Remove all",
321321
"Remove all missions": "Remove all missions",
322-
"Remove all missions dialog text": "Please confirm that you want to remove all the missions from the queue."
322+
"Remove all missions dialog text": "Please confirm that you want to remove all the missions from the queue.",
323+
"New scheduled mission": "New scheduled mission"
323324
}

frontend/src/language/no.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,6 @@
319319
"Info: Updating mission tasks..": "Oppdatering av oppdragets oppgaver foregår i 'Echo Mission planner'. Hvis det brukes inspeksjonspunkt fra STID, vil verdien bli hentet fra STID når oppdraget er satt til 'Ready'. Hvis posisjonen i STID blir oppdatert, vil oppdraget ikke bruke den oppdaterte verdien med mindre oppdraget i oppdragsplanleggeren blir satt til 'Ready' igjen.",
320320
"Remove all": "Fjern alle",
321321
"Remove all missions": "Fjern alle oppdragene",
322-
"Remove all missions dialog text": "Vennligst bekreft at du ønsker å fjerne alle oppdragene fra køen."
322+
"Remove all missions dialog text": "Vennligst bekreft at du ønsker å fjerne alle oppdragene fra køen.",
323+
"New scheduled mission": "Ny planlagt kjøring"
323324
}

0 commit comments

Comments
 (0)