Skip to content

Commit

Permalink
Rename missionlistcontext to missionRunsContext
Browse files Browse the repository at this point in the history
  • Loading branch information
andchiind committed Jan 16, 2024
1 parent 28e4a7e commit da4e2cd
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 32 deletions.
10 changes: 5 additions & 5 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ 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 { MissionsProvider } from 'components/Contexts/MissionListsContext'
import { MissionRunsProvider } from 'components/Contexts/MissionRunsContext'
import { SafeZoneProvider } from 'components/Contexts/SafeZoneContext'
import { AlertProvider } from 'components/Contexts/AlertContext'
import { InstallationProvider } from 'components/Contexts/InstallationContext'
Expand All @@ -32,10 +32,10 @@ const App = () => (
<SignalRProvider>
<MissionDefinitionsProvider>
<RobotProvider>
<MissionsProvider>
<MissionRunsProvider>
<AlertProvider>
<SafeZoneProvider>
<MissionsProvider>
<MissionRunsProvider>
<LanguageProvider>
<MissionControlProvider>
<UnauthenticatedTemplate>
Expand All @@ -50,10 +50,10 @@ const App = () => (
</AuthenticatedTemplate>
</MissionControlProvider>
</LanguageProvider>
</MissionsProvider>
</MissionRunsProvider>
</SafeZoneProvider>
</AlertProvider>
</MissionsProvider>
</MissionRunsProvider>
</RobotProvider>
</MissionDefinitionsProvider>
</SignalRProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const upsertList = (list: Mission[], mission: Mission) => {
return newList
}

interface IMissionsContext {
interface IMissionRunsContext {
ongoingMissions: Mission[]
missionQueue: Mission[]
loadingMissionSet: Set<string>
Expand All @@ -23,21 +23,14 @@ interface Props {
children: React.ReactNode
}

const defaultMissionsContext: IMissionsContext = {
const defaultMissionRunsContext: IMissionRunsContext = {
ongoingMissions: [],
missionQueue: [],
loadingMissionSet: new Set(),
setLoadingMissionSet: (newLoadingMissionSet: Set<string> | ((mission: Set<string>) => Set<string>)) => {},
}

export const MissionsContext = createContext<IMissionsContext>(defaultMissionsContext)

interface MissionsResult {
ongoingMissions: Mission[]
missionQueue: Mission[]
loadingMissionSet: Set<string>
setLoadingMissionSet: (newLoadingMissionSet: Set<string> | ((mission: Set<string>) => Set<string>)) => void
}
export const MissionRunsContext = createContext<IMissionRunsContext>(defaultMissionRunsContext)

const updateQueueIfMissionAlreadyQueued = (oldQueue: Mission[], updatedMission: Mission) => {
const existingMissionIndex = oldQueue.findIndex((m) => m.id === updatedMission.id)
Expand Down Expand Up @@ -68,10 +61,13 @@ const updateOngoingMissionsWithUpdatedMission = (oldMissionList: Mission[], upda
return oldMissionList
}

const fetchMissions = (params: { statuses: MissionStatus[]; pageSize: number; orderBy: string }): Promise<Mission[]> =>
BackendAPICaller.getMissionRuns(params).then((response) => response.content)
const fetchMissionRuns = (params: {
statuses: MissionStatus[]
pageSize: number
orderBy: string
}): Promise<Mission[]> => BackendAPICaller.getMissionRuns(params).then((response) => response.content)

export const useMissions = (): MissionsResult => {
export const useMissionRuns = (): IMissionRunsContext => {
const [ongoingMissions, setOngoingMissions] = useState<Mission[]>([])
const [missionQueue, setMissionQueue] = useState<Mission[]>([])
const [loadingMissionSet, setLoadingMissionSet] = useState<Set<string>>(new Set())
Expand Down Expand Up @@ -124,14 +120,14 @@ export const useMissions = (): MissionsResult => {

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

const queue = await fetchMissions({
const queue = await fetchMissionRuns({
statuses: [MissionStatus.Pending],
pageSize: 100,
orderBy: 'DesiredStartTime',
Expand All @@ -145,13 +141,13 @@ export const useMissions = (): MissionsResult => {
return { ongoingMissions, missionQueue, loadingMissionSet, setLoadingMissionSet }
}

export const MissionsProvider: FC<Props> = ({ children }) => {
const { ongoingMissions, missionQueue, loadingMissionSet, setLoadingMissionSet } = useMissions()
export const MissionRunsProvider: FC<Props> = ({ children }) => {
const { ongoingMissions, missionQueue, loadingMissionSet, setLoadingMissionSet } = useMissionRuns()
return (
<MissionsContext.Provider value={{ ongoingMissions, missionQueue, loadingMissionSet, setLoadingMissionSet }}>
<MissionRunsContext.Provider value={{ ongoingMissions, missionQueue, loadingMissionSet, setLoadingMissionSet }}>
{children}
</MissionsContext.Provider>
</MissionRunsContext.Provider>
)
}

export const useMissionsContext = () => useContext(MissionsContext)
export const useMissionsContext = () => useContext(MissionRunsContext)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useEffect } from 'react'
import { Mission, placeholderMission } from 'models/Mission'
import { EmptyMissionQueuePlaceholder } from './NoMissionPlaceholder'
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { useMissionsContext } from 'components/Contexts/MissionListsContext'
import { useMissionsContext } from 'components/Contexts/MissionRunsContext'
import { useInstallationContext } from 'components/Contexts/InstallationContext'
import { AlertType, useAlertContext } from 'components/Contexts/AlertContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { useNavigate } from 'react-router-dom'
import { config } from 'config'
import { Icons } from 'utils/icons'
import { useMissionsContext } from 'components/Contexts/MissionListsContext'
import { useMissionsContext } from 'components/Contexts/MissionRunsContext'
import { useInstallationContext } from 'components/Contexts/InstallationContext'
import { useEffect, useState } from 'react'
import { Mission } from 'models/Mission'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Robot } from 'models/Robot'
import { EchoMissionDefinition } from 'models/MissionDefinition'
import { useRobotContext } from 'components/Contexts/RobotContext'
import { BackendAPICaller } from 'api/ApiCaller'
import { useMissionsContext } from 'components/Contexts/MissionListsContext'
import { useMissionsContext } from 'components/Contexts/MissionRunsContext'
import { AlertType, useAlertContext } from 'components/Contexts/AlertContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Pages/InspectionPage/DeckCards.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { Button, Icon, Tooltip, Typography } from '@equinor/eds-core-react'
import { Icons } from 'utils/icons'
import { tokens } from '@equinor/eds-tokens'
import { useMissionsContext } from 'components/Contexts/MissionListsContext'
import { useMissionsContext } from 'components/Contexts/MissionRunsContext'

interface IDeckCardProps {
deckMissions: DeckInspectionTuple[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { InspectionTable } from './InspectionTable'
import { StyledDict, compareInspections } from './InspectionUtilities'
import { DeckCards } from './DeckCards'
import { Area } from 'models/Area'
import { useMissionsContext } from 'components/Contexts/MissionListsContext'
import { useMissionsContext } from 'components/Contexts/MissionRunsContext'
import { useMissionDefinitionsContext } from 'components/Contexts/MissionDefinitionsContext'

export interface Inspection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { getDeadlineInDays } from 'utils/StringFormatting'
import { AlreadyScheduledMissionDialog, ScheduleMissionDialog } from './ScheduleMissionDialogs'
import { useEffect, useState } from 'react'
import { TranslateTextWithContext } from 'components/Contexts/LanguageContext'
import { useMissionsContext } from 'components/Contexts/MissionListsContext'
import { useMissionsContext } from 'components/Contexts/MissionRunsContext'

const StyledIcon = styled(Icon)`
display: flex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { BackendAPICaller } from 'api/ApiCaller'
import { Icons } from 'utils/icons'
import { useRobotContext } from 'components/Contexts/RobotContext'
import { StyledAutoComplete, StyledDialog } from 'components/Styles/StyledComponents'
import { useMissionsContext } from 'components/Contexts/MissionListsContext'
import { useMissionsContext } from 'components/Contexts/MissionRunsContext'
import { FailedRequestAlertContent } from 'components/Alerts/FailedRequestAlert'
import { AlertType, useAlertContext } from 'components/Contexts/AlertContext'
import { ScheduleMissionWithLocalizationVerificationDialog } from 'components/Displays/LocalizationVerification/ScheduleMissionWithLocalizationVerification'
Expand Down

0 comments on commit da4e2cd

Please sign in to comment.