Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out return to home from history #1995

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions frontend/src/components/Contexts/MissionFilterContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface IMissionFilterContext {
filterError: string
clearFilterError: () => void
filterState: {
excludeReturnToHome: boolean | undefined
missionName: string | undefined
statuses: MissionStatusFilterOptions[] | undefined
robotName: string | undefined
Expand All @@ -22,6 +23,7 @@ interface IMissionFilterContext {
maxEndTime: number | undefined
}
filterFunctions: {
switchExcludeReturnToHome: (newExcludeReturnToHome: boolean | undefined) => void
switchMissionName: (newMissionName: string | undefined) => void
switchStatuses: (newStatuses: MissionStatusFilterOptions[]) => void
switchRobotName: (newRobotName: string | undefined) => void
Expand Down Expand Up @@ -58,6 +60,7 @@ const defaultMissionFilterInterface: IMissionFilterContext = {
filterError: '',
clearFilterError: () => {},
filterState: {
excludeReturnToHome: true,
missionName: undefined,
statuses: [],
robotName: undefined,
Expand All @@ -69,6 +72,7 @@ const defaultMissionFilterInterface: IMissionFilterContext = {
maxEndTime: undefined,
},
filterFunctions: {
switchExcludeReturnToHome: () => {},
switchMissionName: () => {},
switchStatuses: () => {},
switchRobotName: () => {},
Expand Down Expand Up @@ -113,6 +117,10 @@ export const MissionFilterProvider: FC<Props> = ({ children }) => {

const filterFunctions = useMemo(
() => ({
switchExcludeReturnToHome: (newExcludeReturnToHome: boolean | undefined) => {
setFilterIsSet(true)
setFilterState({ ...filterState, excludeReturnToHome: newExcludeReturnToHome })
},
switchMissionName: (newMissionName: string | undefined) => {
setFilterIsSet(true)
setFilterState({ ...filterState, missionName: newMissionName })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Autocomplete,
AutocompleteChanges,
Button,
Checkbox,
Dialog,
Icon,
Search,
Expand Down Expand Up @@ -108,6 +109,13 @@ export const FilterSection = () => {
<Icon name={Icons.Clear} size={32} />
</Button>
</Dialog.Header>
<Checkbox
label={TranslateText('Only show inspection missions')}
defaultChecked={filterState.excludeReturnToHome}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
filterFunctions.switchExcludeReturnToHome(e.target.checked)
}}
/>
<Autocomplete
options={Array.from(missionStatusTranslationMap.keys())}
onOptionsChange={(changes: AutocompleteChanges<string>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ export const MissionHistoryView = ({ refreshInterval }: RefreshProps) => {

const toDisplayValue = (
filterName: string,
value: string | number | MissionStatusFilterOptions[] | InspectionType[]
value: boolean | string | number | MissionStatusFilterOptions[] | InspectionType[]
) => {
if (typeof value === 'string') {
if (typeof value === 'boolean') {
return ''
} else if (typeof value === 'string') {
return value
} else if (typeof value === 'number') {
// We currently assume these are dates. We may want
Expand Down Expand Up @@ -233,6 +235,29 @@ export const MissionHistoryView = ({ refreshInterval }: RefreshProps) => {
switchPage(newPage)
}

const ActiveFilterContent = () => {
return flatten(filterState)
.filter((filter) => !filterFunctions.isSet(filter.name, filter.value))
.map((filter) => {
const valueToDisplay = toDisplayValue(filter.name, filter.value!)
const filterName = valueToDisplay ? `${TranslateText(filter.name)}: ` : TranslateText(filter.name)
return (
<Chip
style={{
backgroundColor: checkBoxWhiteBackgroundColor,
borderColor: checkBoxBorderColour,
height: '2rem',
paddingLeft: '10px',
}}
key={filter.name}
onDelete={() => filterFunctions.removeFilter(filter.name)}
>
{filterName} {valueToDisplay}
</Chip>
)
})
}

return (
<TableWithHeader>
<Typography variant="h1">{TranslateText('Mission History')}</Typography>
Expand All @@ -244,22 +269,7 @@ export const MissionHistoryView = ({ refreshInterval }: RefreshProps) => {
{':'}
</Typography>
<ActiveFilterList>
{flatten(filterState)
.filter((filter) => !filterFunctions.isSet(filter.name, filter.value))
.map((filter) => (
<Chip
style={{
backgroundColor: checkBoxWhiteBackgroundColor,
borderColor: checkBoxBorderColour,
height: '2rem',
paddingLeft: '10px',
}}
key={filter.name}
onDelete={() => filterFunctions.removeFilter(filter.name)}
>
{TranslateText(filter.name)}: {toDisplayValue(filter.name, filter.value!)}
</Chip>
))}
<ActiveFilterContent />
</ActiveFilterList>
</StyledActiveFilterList>
)}
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/language/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"Search for a robot name": "Search for a robot name",
"Filter": "Filter",
"Clear all filters": "Clear all filters",
"Only show inspection missions": "Only show inspection missions",
"Mission status": "Mission status",
"Inspection type": "Inspection type",
"Select min start time": "Select min start time",
Expand All @@ -100,6 +101,7 @@
"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.",
"Close": "Close",
"Localizing": "Localizing",
"excludeReturnToHome": "Only inspection missions",
"statuses": "Statuses",
"tagId": "Tag ID",
"robotName": "Robot name",
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/language/no.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"Search for a robot name": "Søk etter robotnavn",
"Filter": "Filter",
"Clear all filters": "Fjern alle filtre",
"Only show inspection missions": "Vis kun inspeksjonsoppdrag",
"Mission status": "Oppdragsstatus",
"Inspection type": "Inspeksjonstype",
"Select min start time": "Velg min starttid",
Expand All @@ -100,6 +101,7 @@
"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.",
"Close": "Lukk",
"Localizing": "Lokaliserer",
"excludeReturnToHome": "Kun inspections oppdrag",
"statuses": "Statuser",
"tagId": "Tag ID",
"robotName": "Robotnavn",
Expand Down
Loading