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

Implement alert list feature #1713

Merged
merged 3 commits into from
Aug 29, 2024
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
30 changes: 14 additions & 16 deletions frontend/src/components/Alerts/AlertsBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,21 +51,19 @@ export const AlertBanner = ({ children, dismissAlert, alertCategory }: AlertProp
const [buttonBackgroundColor, setButtonBackgroundColor] = useState<string>(bannerColor)

return (
<>
<StyledCard style={{ backgroundColor: bannerColor }}>
<Horizontal>
<Center>{children}</Center>
</Horizontal>
<Button
variant="ghost_icon"
onClick={dismissAlert}
style={{ backgroundColor: buttonBackgroundColor }}
onPointerEnter={() => setButtonBackgroundColor(hoverColor)}
onPointerLeave={() => setButtonBackgroundColor(bannerColor)}
>
<Icon name={Icons.Clear} style={{ color: tokens.colors.text.static_icons__default.hex }}></Icon>
</Button>
</StyledCard>
</>
<StyledCard style={{ backgroundColor: bannerColor }}>
<Horizontal>
<Center>{children}</Center>
</Horizontal>
<Button
variant="ghost_icon"
onClick={dismissAlert}
style={{ backgroundColor: buttonBackgroundColor }}
onPointerEnter={() => setButtonBackgroundColor(hoverColor)}
onPointerLeave={() => setButtonBackgroundColor(bannerColor)}
>
<Icon name={Icons.Clear} style={{ color: tokens.colors.text.static_icons__default.hex }}></Icon>
</Button>
</StyledCard>
)
}
123 changes: 123 additions & 0 deletions frontend/src/components/Alerts/AlertsListItem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
import { Button, Icon, Typography } from '@equinor/eds-core-react'
import { MissionRestartButton } from 'components/Displays/MissionButtons/MissionRestartButton'
import { Mission } from 'models/Mission'
import { TaskStatus, TaskType } from 'models/Task'
import { ReactNode } from 'react'
import styled from 'styled-components'
import { Icons } from 'utils/icons'
import { AlertCategory } from './AlertsBanner'

const StyledListContainer = styled.div`
isplay: flex;
width: 300px;
height: auto;
justify-content: space-between;
align-items: center;
padding: 3px 10px 2px 10px;
`

const outline = styled.div`
outline: solid;
outline-width: 1px;
outline-color: lightgray;
padding: 6px 10px 6px 10px;
`

const StyledListHeading = styled(outline)`
display: flex;
justify-content: space-between;
padding: 6px 5px 6px 5px;
`
const StyledListItem = styled(outline)`
display: flex;
flex-direction: column;
align-items: left;
row-gap: 10px;
`

const VerticalContent = styled.div`
display: flex;
flex-direction: row;
align-items: center;
column-gap: 4px;
`

const StyledIcon = styled(Icon)`
width: 24px;
min-width: 24px;
height: 24px;
`

const Horizontal = styled.div`
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: top;
`

const Right = styled.div`
display: flex;
align-items: right;
justify-content: right;
`

interface AlertListInfo {
icon: Icons
alertTitle: string
alertText: string
iconColor?: string
mission?: Mission
}

interface AlertProps {
children: ReactNode
dismissAlert: () => void
alertCategory: AlertCategory
}

export const AlertListContents = ({ icon, iconColor, alertTitle, alertText, mission }: AlertListInfo) => {
let missionHasFailedTasks = false
if (mission !== undefined)
missionHasFailedTasks = mission.tasks.some(
(t) => t.status !== TaskStatus.PartiallySuccessful && t.status !== TaskStatus.Successful
)
return (
<StyledListContainer>
<StyledListHeading>
<VerticalContent>
<StyledIcon name={icon} style={{ color: iconColor }} />
<Typography variant="h6">{alertTitle}</Typography>
</VerticalContent>
</StyledListHeading>
<StyledListItem>
<Typography variant="caption">{alertText}</Typography>
<Right>
{mission !== undefined &&
mission.tasks[0]?.type !== TaskType.ReturnHome &&
mission.tasks[0]?.type !== TaskType.Localization && (
<MissionRestartButton
mission={mission}
hasFailedTasks={missionHasFailedTasks}
smallButton={false}
/>
)}
</Right>
</StyledListItem>
</StyledListContainer>
)
}

export const AlertListItem = ({ children, dismissAlert }: AlertProps) => {
return (
<Horizontal>
{children}
<Button
variant="ghost_icon"
onClick={dismissAlert}
style={{ marginTop: '0px', right: '25px', position: 'absolute' }}
>
<Icon name={Icons.Clear}></Icon>
</Button>
</Horizontal>
)
}
17 changes: 17 additions & 0 deletions frontend/src/components/Alerts/BlockedRobotAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { Icons } from 'utils/icons'
import { tokens } from '@equinor/eds-tokens'
import { TextAlignedButton } from 'components/Styles/StyledComponents'
import { AlertListContents } from './AlertsListItem'

const StyledDiv = styled.div`
align-items: center;
Expand Down Expand Up @@ -43,3 +44,19 @@ export const BlockedRobotAlertContent = ({ robotNames }: AlertProps) => {
</StyledDiv>
)
}

export const BlockedRobotAlertListContent = ({ robotNames }: AlertProps) => {
const { TranslateText } = useLanguageContext()
let message = `${TranslateText('The robot')} ${robotNames[0]} ${TranslateText('is blocked and cannot perform tasks')}.`

if (robotNames.length > 1) message = `${TranslateText('Several robots are blocked and cannot perform tasks')}.`

return (
<AlertListContents
icon={Icons.Warning}
iconColor={tokens.colors.interactive.danger__resting.rgba}
alertTitle={TranslateText('Robot is blocked')}
alertText={message}
/>
)
}
13 changes: 13 additions & 0 deletions frontend/src/components/Alerts/FailedAlertContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { Icons } from 'utils/icons'
import { tokens } from '@equinor/eds-tokens'
import { TextAlignedButton } from 'components/Styles/StyledComponents'
import { AlertListContents } from './AlertsListItem'

const StyledDiv = styled.div`
align-items: center;
Expand Down Expand Up @@ -38,3 +39,15 @@ export const FailedAlertContent = ({ title, message }: { title: string; message:
</StyledDiv>
)
}

export const FailedAlertListContent = ({ title, message }: { title: string; message: string }) => {
const { TranslateText } = useLanguageContext()
return (
<AlertListContents
icon={Icons.Failed}
iconColor={tokens.colors.interactive.danger__resting.rgba}
alertTitle={TranslateText(title)}
alertText={TranslateText(message)}
/>
)
}
29 changes: 29 additions & 0 deletions frontend/src/components/Alerts/FailedMissionAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { MissionStatusDisplay } from 'components/Displays/MissionDisplays/Missio
import { useNavigate } from 'react-router-dom'
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { TextAlignedButton } from 'components/Styles/StyledComponents'
import { AlertListContents } from './AlertsListItem'
import { Icons } from 'utils/icons'
import { tokens } from '@equinor/eds-tokens'

const Indent = styled.div`
padding: 0px 0px 0px 5px;
Expand Down Expand Up @@ -63,3 +66,29 @@ export const FailedMissionAlertContent = ({ missions }: MissionsProps) => {
</Indent>
)
}

export const FailedMissionAlertListContent = ({ missions }: MissionsProps) => {
const { TranslateText } = useLanguageContext()
const mission = missions[0]
let message = `${mission.name} ${TranslateText('failed on robot')} ${mission.robot.name}: ${mission.statusReason}`
if (mission.statusReason === null)
message = `${mission.name} ${TranslateText('failed on robot')} ${mission.robot.name}`
if (missions.length > 1)
message = `${missions.length.toString()} ${TranslateText("missions failed recently. See 'Mission History' for more information.")}.`
return missions.length === 1 ? (
<AlertListContents
icon={Icons.Failed}
alertTitle={TranslateText(MissionStatus.Failed)}
alertText={message}
iconColor={tokens.colors.interactive.danger__resting.rgba}
mission={mission}
/>
) : (
<AlertListContents
icon={Icons.Failed}
alertTitle={TranslateText(MissionStatus.Failed)}
alertText={message}
iconColor={tokens.colors.interactive.danger__resting.rgba}
/>
)
}
13 changes: 13 additions & 0 deletions frontend/src/components/Alerts/FailedRequestAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { Icons } from 'utils/icons'
import { tokens } from '@equinor/eds-tokens'
import { TextAlignedButton } from 'components/Styles/StyledComponents'
import { AlertListContents } from './AlertsListItem'

const StyledDiv = styled.div`
flex-direction: column;
Expand Down Expand Up @@ -33,3 +34,15 @@ export const FailedRequestAlertContent = ({ translatedMessage }: { translatedMes
</StyledDiv>
)
}

export const FailedRequestAlertListContent = ({ translatedMessage }: { translatedMessage: string }) => {
const { TranslateText } = useLanguageContext()
return (
<AlertListContents
icon={Icons.Failed}
alertTitle={TranslateText('Request error')}
alertText={translatedMessage}
iconColor={tokens.colors.interactive.danger__resting.rgba}
/>
)
}
25 changes: 25 additions & 0 deletions frontend/src/components/Alerts/SafeZoneAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { AlertType } from 'components/Contexts/AlertContext'
import { useLanguageContext } from 'components/Contexts/LanguageContext'
import { TextAlignedButton } from 'components/Styles/StyledComponents'
import styled from 'styled-components'
import { AlertListContents } from './AlertsListItem'
import { Icons } from 'utils/icons'

const StyledDiv = styled.div`
flex-direction: column;
Expand Down Expand Up @@ -47,3 +49,26 @@ export const SafeZoneAlertContent = ({ alertType, alertCategory }: SafeZoneBanne
</StyledDiv>
)
}

export const SafeZoneAlertListContent = ({ alertType, alertCategory }: SafeZoneBannerProps): JSX.Element => {
const { TranslateText } = useLanguageContext()
let titleMessage = TranslateText('INFO')
let message = TranslateText('Safe zone banner text')
let icon = Icons.Warning
let iconColor = tokens.colors.interactive.danger__resting.rgba
if (alertCategory === AlertCategory.WARNING) titleMessage = TranslateText('WARNING')
if (alertCategory === AlertCategory.INFO && alertType === AlertType.SafeZoneSuccess)
[message, icon, iconColor] = [
TranslateText('Safe Zone successful text'),
Icons.Info,
tokens.colors.text.static_icons__default.rgba,
]
if (alertCategory === AlertCategory.INFO && alertType === AlertType.DismissSafeZone)
[message, icon, iconColor] = [
TranslateText('Dismiss safe zone banner text'),
Icons.Info,
tokens.colors.text.static_icons__default.rgba,
]

return <AlertListContents icon={icon} alertTitle={titleMessage} alertText={message} iconColor={iconColor} />
}
Loading
Loading