Skip to content

Commit

Permalink
Check for both null and undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddasol committed Nov 2, 2023
1 parent 4ebac2e commit 5dd8bcc
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 21 deletions.
2 changes: 1 addition & 1 deletion frontend/src/api/ApiCaller.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class BackendAPICaller {

/** API is not ready until access token has been set for the first time */
private static async ApiReady() {
while (this.accessToken === null || this.accessToken === '') {
while (!this.accessToken || this.accessToken === '') {
await timeout(500)
}
}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/components/Contexts/MissionFilterContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,11 @@ export const MissionFilterProvider: FC<Props> = ({ children }) => {
return !value || value.length === 0
},
dateTimeStringToInt: (dateTimeString: string | undefined) => {
if (dateTimeString === '' || dateTimeString === undefined) return undefined
if (dateTimeString === '' || !dateTimeString) return undefined
return new Date(dateTimeString).getTime() / 1000
},
dateTimeIntToString: (dateTimeNumber: number | undefined) => {
if (dateTimeNumber === 0 || dateTimeNumber === undefined) return undefined
if (dateTimeNumber === 0 || !dateTimeNumber) return undefined
const t = new Date(dateTimeNumber * 1000)
const z = new Date(t.getTimezoneOffset() * 60 * 1000)
const tLocal = new Date(t.getTime() - z.getTime())
Expand All @@ -257,7 +257,7 @@ export const MissionFilterProvider: FC<Props> = ({ children }) => {
return iso.slice(0, -3) // Removes :00 at the end
},
dateTimeIntToPrettyString: (dateTimeNumber: number | undefined) => {
if (dateTimeNumber === 0 || dateTimeNumber === undefined) return undefined
if (dateTimeNumber === 0 || !dateTimeNumber) return undefined
const t = new Date(dateTimeNumber * 1000)
const z = new Date(t.getTimezoneOffset() * 60 * 1000)
const tLocal = new Date(t.getTime() - z.getTime())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function FailedMissionAlertView({ refreshInterval }: RefreshProps) {
const sessionValue = sessionStorage.getItem(DismissalTimeSessionKeyName)

var lastTime: Date
if (sessionValue === null || sessionValue === '') {
if (!sessionValue || sessionValue === '') {
lastTime = addMinutes(Date.now(), -DefaultTimeInterval)
} else {
lastTime = JSON.parse(sessionValue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,12 @@ export function MissionQueueView({ refreshInterval }: RefreshProps) {
setSelectedEchoMissions(echoMissionsToSchedule)
}
const onSelectedRobot = (selectedRobot: Robot) => {
if (robotOptions === undefined) return
if (!robotOptions) return
setSelectedRobot(selectedRobot)
}

const onScheduleButtonPress = () => {
if (selectedRobot === undefined) return
if (!selectedRobot) return

selectedEchoMissions.forEach((mission: EchoMissionDefinition) => {
BackendAPICaller.postMission(mission.echoMissionId, selectedRobot.id, installationCode)
Expand Down Expand Up @@ -108,7 +108,7 @@ export function MissionQueueView({ refreshInterval }: RefreshProps) {
}, [refreshInterval])

useEffect(() => {
if (selectedRobot === undefined || selectedEchoMissions.length === 0) {
if (!selectedRobot || selectedEchoMissions.length === 0) {
setScheduleButtonDisabled(true)
} else {
setScheduleButtonDisabled(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function RobotStatusSection({ refreshInterval }: RefreshProps) {
return (
robot.currentInstallation.toLocaleLowerCase() === installationCode.toLocaleLowerCase() ||
(typeof robot.currentInstallation === 'string' && robot.currentInstallation.includes('default')) ||
robot.currentInstallation === undefined
!robot.currentInstallation
)
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@ export const ScheduleMissionDialog = (props: IProps): JSX.Element => {
let timer: ReturnType<typeof setTimeout>

const onSelectedRobot = (selectedRobot: Robot) => {
if (robotOptions === undefined) return
if (!robotOptions) return

setSelectedRobot(selectedRobot)
}

const onScheduleButtonPress = () => {
if (selectedRobot === undefined) return
if (!selectedRobot) return

props.missions.forEach((mission) => BackendAPICaller.scheduleMissionDefinition(mission.id, selectedRobot.id))

Expand All @@ -104,7 +104,7 @@ export const ScheduleMissionDialog = (props: IProps): JSX.Element => {
}

const onScheduleOnlyButtonPress = () => {
if (selectedRobot === undefined) return
if (!selectedRobot) return

props.unscheduledMissions.forEach((mission) =>
BackendAPICaller.scheduleMissionDefinition(mission.id, selectedRobot.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ function MissionDefinitionEditButtons({ missionDefinition, updateMissionDefiniti

const inspectionFrequency = getDayAndHoursFromInspectionFrequency(form.inspectionFrequency)
const inspectionFrequencyDays =
inspectionFrequency[0] === null || inspectionFrequency[0] === 0 ? '' : String(inspectionFrequency[0])
!inspectionFrequency[0] || inspectionFrequency[0] === 0 ? '' : String(inspectionFrequency[0])
const inspectionFrequencyHours =
inspectionFrequency[1] === null || inspectionFrequency[1] === 0 ? '' : String(inspectionFrequency[1])
!inspectionFrequency[1] || inspectionFrequency[1] === 0 ? '' : String(inspectionFrequency[1])

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/Pages/MissionPage/StatusReason.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface MissionProps {
}

export function StatusReason({ mission }: MissionProps) {
if (mission.statusReason === null) return <></>
if (!mission.statusReason) return <></>

var warningLevel: 'default' | 'info' | 'warning' | 'danger' = 'info'
switch (mission.status) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function GetEnvVariable(name: string): string {
// If global value equals its placeholder value 'placeholderValue', it is considered undefined
const placeholderValue: string = '${' + name + '}'

if (globalValue === placeholderValue || globalValue === undefined)
if (globalValue === placeholderValue || !globalValue)
throw new Error(
`Global variable "${name}" is not set. Verify that your .env file is up to date with .env.example`
)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/utils/MapMarkers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const PlaceTagsInMap = (mission: Mission, map: HTMLCanvasElement, current
return task.taskOrder
})
)
if (currentTaskOrder === undefined) {
if (!currentTaskOrder) {
currentTaskOrder = mission.isCompleted ? maxTaskOrder + 1 : 0
}

Expand Down
5 changes: 1 addition & 4 deletions frontend/src/utils/filtersAndSorts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,5 @@ export const filterRobots = (robots: Robot[], id: string): Robot[] => {
}

export const compareByDate = (timeA?: Date, timeB?: Date): number => {
return compareDesc(
timeA === undefined ? new Date(0) : new Date(timeA),
timeB === undefined ? new Date(0) : new Date(timeB)
)
return compareDesc(!timeA ? new Date(0) : new Date(timeA), !timeB ? new Date(0) : new Date(timeB))
}

0 comments on commit 5dd8bcc

Please sign in to comment.