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

Add mockmission for instant feedback in mission queue #915

Merged
merged 4 commits into from
Sep 20, 2023
Merged
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
6 changes: 3 additions & 3 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { FlotillaSite } from 'components/Pages/FlotillaSite'
import { LanguageProvider } from 'components/Contexts/LanguageContext'
import { MissionControlProvider } from 'components/Contexts/MissionControlContext'
import { MissionFilterProvider } from 'components/Contexts/MissionFilterContext'
import { MissionQueueProvider } from 'components/Contexts/MissionQueueContext'
import { MissionsProvider } from 'components/Contexts/MissionListsContext'

function App() {
return (
<MissionQueueProvider>
<MissionsProvider>
<LanguageProvider>
<MissionControlProvider>
<>
Expand All @@ -25,7 +25,7 @@ function App() {
</>
</MissionControlProvider>
</LanguageProvider>
</MissionQueueProvider>
</MissionsProvider>
)
}

Expand Down
70 changes: 70 additions & 0 deletions frontend/src/components/Contexts/MissionListsContext.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { createContext, FC, useContext, useEffect, useState } from 'react'
import { Mission, MissionStatus } from 'models/Mission'
import { refreshInterval } from 'components/Pages/FrontPage/FrontPage'
import { BackendAPICaller } from 'api/ApiCaller'

interface IMissionsContext {
ongoingMissions: Mission[]
missionQueue: Mission[]
}

interface Props {
children: React.ReactNode
}

const defaultMissionsContext: IMissionsContext = {
ongoingMissions: [],
missionQueue: [],
}

export const MissionsContext = createContext<IMissionsContext>(defaultMissionsContext)

interface MissionsResult {
ongoingMissions: Mission[]
missionQueue: Mission[]
}

const fetchMissions = (params: {
statuses: MissionStatus[]
pageSize: number
orderBy: string
}): Promise<Mission[]> => {
return BackendAPICaller.getMissionRuns(params).then((response) => response.content)
}
export const useMissions = (refreshInterval: number): MissionsResult => {
const [ongoingMissions, setOngoingMissions] = useState<Mission[]>([])
const [missionQueue, setMissionQueue] = useState<Mission[]>([])

useEffect(() => {
const fetchAndUpdateMissions = async () => {
const ongoing = await fetchMissions({
statuses: [MissionStatus.Ongoing, MissionStatus.Paused],
pageSize: 100,
orderBy: 'StartTime desc',
})
setOngoingMissions(ongoing)

const queue = await fetchMissions({
statuses: [MissionStatus.Pending],
pageSize: 100,
orderBy: 'DesiredStartTime',
})
setMissionQueue(queue)
}

fetchAndUpdateMissions()

const id = setInterval(fetchAndUpdateMissions, refreshInterval)

return () => clearInterval(id)
}, [refreshInterval])

return { ongoingMissions, missionQueue }
}
export const MissionsProvider: FC<Props> = ({ children }) => {
const { ongoingMissions, missionQueue } = useMissions(refreshInterval)

return <MissionsContext.Provider value={{ ongoingMissions, missionQueue }}>{children}</MissionsContext.Provider>
}

export const useMissionsContext = () => useContext(MissionsContext)
andchiind marked this conversation as resolved.
Show resolved Hide resolved
52 changes: 0 additions & 52 deletions frontend/src/components/Contexts/MissionQueueContext.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Card, Checkbox, Dialog, Icon, Typography } from '@equinor/eds-core-react'
import { Button, Card, Checkbox, Dialog, Icon, Typography, DotProgress } from '@equinor/eds-core-react'
import { config } from 'config'
import { tokens } from '@equinor/eds-tokens'
import { Mission } from 'models/Mission'
import { Mission, dummyMission } from 'models/Mission'
import styled from 'styled-components'
import { useNavigate } from 'react-router-dom'
import { useState } from 'react'
Expand Down Expand Up @@ -56,9 +56,14 @@ export function MissionQueueCard({ mission, onDeleteMission }: MissionQueueCardP
<HorizontalContent>
<HorizontalNonButtonContent onClick={routeChange}>
<Checkbox />
<Button variant="ghost" fullWidth>
<Typography variant="body_short_bold">{mission.name}</Typography>
</Button>

{mission === dummyMission ? (
<DotProgress size={64} color="primary" />
) : (
<Button variant="ghost" fullWidth>
<Typography variant="body_short_bold">{mission.name}</Typography>
</Button>
)}
<Typography variant="caption" color="#6F6F6F">
{TranslateText('Robot')}: {mission.robot.name}
</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import styled from 'styled-components'
import { MissionQueueCard } from './MissionQueueCard'
import { BackendAPICaller } from 'api/ApiCaller'
import { useEffect, useState } from 'react'
import { Mission } from 'models/Mission'
import { Mission, dummyMission } from 'models/Mission'
import { EmptyMissionQueuePlaceholder } from './NoMissionPlaceholder'
import { ScheduleMissionDialog } from './ScheduleMissionDialog'
import { Robot } from 'models/Robot'
Expand All @@ -12,7 +12,7 @@ import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { useInstallationContext } from 'components/Contexts/InstallationContext'
import { CreateMissionButton } from './CreateMissionButton'
import { EchoMissionDefinition } from 'models/MissionDefinition'
import { useMissionQueueContext } from 'components/Contexts/MissionQueueContext'
import { useMissionsContext } from 'components/Contexts/MissionListsContext'

const StyledMissionView = styled.div`
display: grid;
Expand Down Expand Up @@ -41,7 +41,8 @@ const mapEchoMissionToString = (missions: EchoMissionDefinition[]): Map<string,

export function MissionQueueView({ refreshInterval }: RefreshProps) {
const { TranslateText } = useLanguageContext()
const { missionQueue } = useMissionQueueContext()
const { missionQueue, ongoingMissions } = useMissionsContext()
const [loadingMissionNames, setLoadingMissionNames] = useState<Set<string>>(new Set())

const [selectedEchoMissions, setSelectedEchoMissions] = useState<EchoMissionDefinition[]>([])
const [selectedRobot, setSelectedRobot] = useState<Robot>()
Expand Down Expand Up @@ -74,7 +75,6 @@ export function MissionQueueView({ refreshInterval }: RefreshProps) {
}
const onSelectedRobot = (selectedRobot: Robot) => {
if (robotOptions === undefined) return

setSelectedRobot(selectedRobot)
}

Expand All @@ -83,6 +83,11 @@ export function MissionQueueView({ refreshInterval }: RefreshProps) {

selectedEchoMissions.forEach((mission: EchoMissionDefinition) => {
BackendAPICaller.postMission(mission.echoMissionId, selectedRobot.id, installationCode)
setLoadingMissionNames((prev) => {
const updatedSet = new Set(prev)
updatedSet.add(mission.name)
return updatedSet
})
})

setSelectedEchoMissions([])
Expand Down Expand Up @@ -118,18 +123,31 @@ export function MissionQueueView({ refreshInterval }: RefreshProps) {
}
}, [robotOptions, installationCode])

useEffect(() => {
setLoadingMissionNames((currentLoadingNames) => {
const updatedLoadingMissionIds = new Set(currentLoadingNames)
missionQueue.forEach((mission) => updatedLoadingMissionIds.delete(mission.name))
ongoingMissions.forEach((mission) => updatedLoadingMissionIds.delete(mission.name))
return updatedLoadingMissionIds
})
}, [missionQueue, ongoingMissions])

var missionQueueDisplay = missionQueue.map(function (mission, index) {
return <MissionQueueCard key={index} mission={mission} onDeleteMission={onDeleteMission} />
})
const loadingQueueDisplay = () => {
return <MissionQueueCard key={'test'} mission={dummyMission} onDeleteMission={() => {}} />
}

return (
<StyledMissionView>
<Typography variant="h1" color="resting">
{TranslateText('Mission Queue')}
</Typography>
<MissionTable>
{loadingMissionNames.size > 0 && loadingQueueDisplay()}
{missionQueue.length > 0 && missionQueueDisplay}
{missionQueue.length === 0 && <EmptyMissionQueuePlaceholder />}
{loadingMissionNames.size === 0 && missionQueue.length === 0 && <EmptyMissionQueuePlaceholder />}
</MissionTable>
<MissionButtonView>
<ScheduleMissionDialog
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { Button, Typography, Icon } from '@equinor/eds-core-react'
import { Mission, MissionStatus } from 'models/Mission'
import { useCallback, useEffect, useState } from 'react'
import styled from 'styled-components'
import { RefreshProps } from '../FrontPage'
import { NoOngoingMissionsPlaceholder } from './NoMissionPlaceholder'
Expand All @@ -9,7 +7,8 @@ import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { useNavigate } from 'react-router-dom'
import { config } from 'config'
import { Icons } from 'utils/icons'
import { BackendAPICaller } from 'api/ApiCaller'
/* import { useOngoingMissionsContext } from 'components/Contexts/OngoingMissionsContext' */
import { useMissionsContext } from 'components/Contexts/MissionListsContext'

const StyledOngoingMissionView = styled.div`
display: flex;
Expand All @@ -28,32 +27,11 @@ const ButtonStyle = styled.div`

export function OngoingMissionView({ refreshInterval }: RefreshProps) {
const { TranslateText } = useLanguageContext()
const missionPageSize = 100
const [missions, setMissions] = useState<Mission[]>([])

const updateOngoingAndPausedMissions = useCallback(() => {
BackendAPICaller.getMissionRuns({
statuses: [MissionStatus.Ongoing, MissionStatus.Paused],
pageSize: missionPageSize,
orderBy: 'StartTime desc',
}).then((missions) => {
setMissions(missions.content)
})
}, [])

useEffect(() => {
updateOngoingAndPausedMissions()
}, [updateOngoingAndPausedMissions])

useEffect(() => {
const id = setInterval(() => {
updateOngoingAndPausedMissions()
}, refreshInterval)
return () => clearInterval(id)
}, [refreshInterval, updateOngoingAndPausedMissions])

var missionDisplay = missions.map((mission, index) => <OngoingMissionCard key={index} mission={mission} />)
const { ongoingMissions } = useMissionsContext()

var ongoingMissionscard = ongoingMissions.map(function (mission, index) {
return <OngoingMissionCard key={index} mission={mission} />
})
let navigate = useNavigate()
const routeChange = () => {
let path = `${config.FRONTEND_BASE_ROUTE}/history`
Expand All @@ -66,8 +44,8 @@ export function OngoingMissionView({ refreshInterval }: RefreshProps) {
{TranslateText('Ongoing Missions')}
</Typography>
<OngoingMissionSection>
{missions.length > 0 && missionDisplay}
{missions.length === 0 && <NoOngoingMissionsPlaceholder />}
{ongoingMissions.length > 0 && ongoingMissionscard}
{ongoingMissions.length === 0 && <NoOngoingMissionsPlaceholder />}
</OngoingMissionSection>
<ButtonStyle>
<Button variant="outlined" onClick={routeChange}>
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/models/Mission.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { MapMetadata } from './MapMetadata'
import { Robot } from './Robot'
import { Robot, dummyRobot } from './Robot'
import { Task } from './Task'

export enum MissionStatus {
Expand Down Expand Up @@ -32,3 +32,12 @@ export interface Mission {
tasks: Task[]
map?: MapMetadata
}
export const dummyMission: Mission = {
id: 'dummyId',
name: 'dummyMission',
robot: dummyRobot,
status: MissionStatus.Pending,
isCompleted: false,
desiredStartTime: new Date(),
tasks: [],
}
8 changes: 7 additions & 1 deletion frontend/src/models/Robot.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Area } from './Area'
import { BatteryStatus } from './Battery'
import { Pose } from './Pose'
import { RobotModel } from './RobotModel'
import { RobotModel, dummyRobotModel } from './RobotModel'
import { VideoStream } from './VideoStream'

export enum RobotStatus {
Expand Down Expand Up @@ -29,3 +29,9 @@ export interface Robot {
isarUri?: string
currentArea?: Area
}
export const dummyRobot: Robot = {
id: 'dummyRobotId',
model: dummyRobotModel,
currentInstallation: 'DummyInstallation',
status: RobotStatus.Available,
}
6 changes: 6 additions & 0 deletions frontend/src/models/RobotModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ export interface RobotModel {
upperPressureWarningThreshold: number
lowerPressureWarningThreshold: number
}
export const dummyRobotModel: RobotModel = {
id: 'dummyModelId',
type: RobotType.Robot,
upperPressureWarningThreshold: 100,
lowerPressureWarningThreshold: 10,
}