Skip to content

Commit ea60731

Browse files
committed
Filter out return to home from history
1 parent 32f09d2 commit ea60731

File tree

5 files changed

+48
-18
lines changed

5 files changed

+48
-18
lines changed

frontend/src/components/Contexts/MissionFilterContext.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ interface IMissionFilterContext {
1111
filterError: string
1212
clearFilterError: () => void
1313
filterState: {
14+
excludeReturnToHome: boolean | undefined
1415
missionName: string | undefined
1516
statuses: MissionStatusFilterOptions[] | undefined
1617
robotName: string | undefined
@@ -22,6 +23,7 @@ interface IMissionFilterContext {
2223
maxEndTime: number | undefined
2324
}
2425
filterFunctions: {
26+
switchExcludeReturnToHome: (newExcludeReturnToHome: boolean | undefined) => void
2527
switchMissionName: (newMissionName: string | undefined) => void
2628
switchStatuses: (newStatuses: MissionStatusFilterOptions[]) => void
2729
switchRobotName: (newRobotName: string | undefined) => void
@@ -58,6 +60,7 @@ const defaultMissionFilterInterface: IMissionFilterContext = {
5860
filterError: '',
5961
clearFilterError: () => {},
6062
filterState: {
63+
excludeReturnToHome: true,
6164
missionName: undefined,
6265
statuses: [],
6366
robotName: undefined,
@@ -69,6 +72,7 @@ const defaultMissionFilterInterface: IMissionFilterContext = {
6972
maxEndTime: undefined,
7073
},
7174
filterFunctions: {
75+
switchExcludeReturnToHome: () => {},
7276
switchMissionName: () => {},
7377
switchStatuses: () => {},
7478
switchRobotName: () => {},
@@ -113,6 +117,10 @@ export const MissionFilterProvider: FC<Props> = ({ children }) => {
113117

114118
const filterFunctions = useMemo(
115119
() => ({
120+
switchExcludeReturnToHome: (newExcludeReturnToHome: boolean | undefined) => {
121+
setFilterIsSet(true)
122+
setFilterState({ ...filterState, excludeReturnToHome: newExcludeReturnToHome })
123+
},
116124
switchMissionName: (newMissionName: string | undefined) => {
117125
setFilterIsSet(true)
118126
setFilterState({ ...filterState, missionName: newMissionName })

frontend/src/components/Pages/MissionHistoryPage/FilterSection.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
Autocomplete,
33
AutocompleteChanges,
44
Button,
5+
Checkbox,
56
Dialog,
67
Icon,
78
Search,
@@ -108,6 +109,13 @@ export const FilterSection = () => {
108109
<Icon name={Icons.Clear} size={32} />
109110
</Button>
110111
</Dialog.Header>
112+
<Checkbox
113+
label={TranslateText('Only show inspection missions')}
114+
defaultChecked={filterState.excludeReturnToHome}
115+
onChange={(e: ChangeEvent<HTMLInputElement>) => {
116+
filterFunctions.switchExcludeReturnToHome(e.target.checked)
117+
}}
118+
/>
111119
<Autocomplete
112120
options={Array.from(missionStatusTranslationMap.keys())}
113121
onOptionsChange={(changes: AutocompleteChanges<string>) => {

frontend/src/components/Pages/MissionHistoryPage/MissionHistoryView.tsx

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,11 @@ export const MissionHistoryView = ({ refreshInterval }: RefreshProps) => {
138138

139139
const toDisplayValue = (
140140
filterName: string,
141-
value: string | number | MissionStatusFilterOptions[] | InspectionType[]
141+
value: boolean | string | number | MissionStatusFilterOptions[] | InspectionType[]
142142
) => {
143-
if (typeof value === 'string') {
143+
if (typeof value === 'boolean') {
144+
return ''
145+
} else if (typeof value === 'string') {
144146
return value
145147
} else if (typeof value === 'number') {
146148
// We currently assume these are dates. We may want
@@ -233,6 +235,29 @@ export const MissionHistoryView = ({ refreshInterval }: RefreshProps) => {
233235
switchPage(newPage)
234236
}
235237

238+
const ActiveFilterContent = () => {
239+
return flatten(filterState)
240+
.filter((filter) => !filterFunctions.isSet(filter.name, filter.value))
241+
.map((filter) => {
242+
const valueToDisplay = toDisplayValue(filter.name, filter.value!)
243+
const filterName = valueToDisplay ? `${TranslateText(filter.name)}: ` : TranslateText(filter.name)
244+
return (
245+
<Chip
246+
style={{
247+
backgroundColor: checkBoxWhiteBackgroundColor,
248+
borderColor: checkBoxBorderColour,
249+
height: '2rem',
250+
paddingLeft: '10px',
251+
}}
252+
key={filter.name}
253+
onDelete={() => filterFunctions.removeFilter(filter.name)}
254+
>
255+
{filterName} {valueToDisplay}
256+
</Chip>
257+
)
258+
})
259+
}
260+
236261
return (
237262
<TableWithHeader>
238263
<Typography variant="h1">{TranslateText('Mission History')}</Typography>
@@ -244,22 +269,7 @@ export const MissionHistoryView = ({ refreshInterval }: RefreshProps) => {
244269
{':'}
245270
</Typography>
246271
<ActiveFilterList>
247-
{flatten(filterState)
248-
.filter((filter) => !filterFunctions.isSet(filter.name, filter.value))
249-
.map((filter) => (
250-
<Chip
251-
style={{
252-
backgroundColor: checkBoxWhiteBackgroundColor,
253-
borderColor: checkBoxBorderColour,
254-
height: '2rem',
255-
paddingLeft: '10px',
256-
}}
257-
key={filter.name}
258-
onDelete={() => filterFunctions.removeFilter(filter.name)}
259-
>
260-
{TranslateText(filter.name)}: {toDisplayValue(filter.name, filter.value!)}
261-
</Chip>
262-
))}
272+
<ActiveFilterContent />
263273
</ActiveFilterList>
264274
</StyledActiveFilterList>
265275
)}

frontend/src/language/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"Search for a robot name": "Search for a robot name",
9191
"Filter": "Filter",
9292
"Clear all filters": "Clear all filters",
93+
"Only show inspection missions": "Only show inspection missions",
9394
"Mission status": "Mission status",
9495
"Inspection type": "Inspection type",
9596
"Select min start time": "Select min start time",
@@ -100,6 +101,7 @@
100101
"This button is disabled because the robot is not available. Check that the robot is on, and are not doing any other activities.": "This button is disabled because the robot is not available. Check that the robot is on, and are not doing any other activities.",
101102
"Close": "Close",
102103
"Localizing": "Localizing",
104+
"excludeReturnToHome": "Only inspection missions",
103105
"statuses": "Statuses",
104106
"tagId": "Tag ID",
105107
"robotName": "Robot name",

frontend/src/language/no.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
"Search for a robot name": "Søk etter robotnavn",
9191
"Filter": "Filter",
9292
"Clear all filters": "Fjern alle filtre",
93+
"Only show inspection missions": "Vis kun inspeksjonsoppdrag",
9394
"Mission status": "Oppdragsstatus",
9495
"Inspection type": "Inspeksjonstype",
9596
"Select min start time": "Velg min starttid",
@@ -100,6 +101,7 @@
100101
"This button is disabled because the robot is not available. Check that the robot is on, and are not doing any other activities.": "Denne knappen er deaktivert fordi roboten ikke er tilgjengelig. Sjekk at roboten er på og ikke gjør noen andre aktiviteter.",
101102
"Close": "Lukk",
102103
"Localizing": "Lokaliserer",
104+
"excludeReturnToHome": "Kun inspections oppdrag",
103105
"statuses": "Statuser",
104106
"tagId": "Tag ID",
105107
"robotName": "Robotnavn",

0 commit comments

Comments
 (0)