Skip to content

feat: add warning if workspace page becomes stale #4375

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

Merged
merged 6 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
updated design
  • Loading branch information
Kira-Pilot committed Oct 5, 2022
commit 5aeb6e2bc0af8f9d672c99acd9d972ed20fb294d
16 changes: 12 additions & 4 deletions site/src/components/WarningAlert/WarningAlert.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,27 @@ export default {

const Template: Story<WarningAlertProps> = (args) => <WarningAlert {...args} />

export const ExampleWithClose = Template.bind({})
ExampleWithClose.args = {
export const ExampleWithDismiss = Template.bind({})
ExampleWithDismiss.args = {
text: "This is a warning",
dismissible: true,
}

const ExampleAction = (
<Button color="inherit" onClick={() => null} size="small">
<Button onClick={() => null} size="small">
Button
</Button>
)

export const ExampleWithAction = Template.bind({})
ExampleWithAction.args = {
text: "This is a warning",
action: ExampleAction,
actions: [ExampleAction],
}

export const ExampleWithActionAndDismiss = Template.bind({})
ExampleWithActionAndDismiss.args = {
text: "This is a warning",
actions: [ExampleAction],
dismissible: true,
}
76 changes: 47 additions & 29 deletions site/src/components/WarningAlert/WarningAlert.tsx
Original file line number Diff line number Diff line change
@@ -1,43 +1,61 @@
import { useState, FC, ReactElement } from "react"
import Alert from "@material-ui/lab/Alert"
import IconButton from "@material-ui/core/IconButton"
import Collapse from "@material-ui/core/Collapse"
import { Stack } from "components/Stack/Stack"
import CloseIcon from "@material-ui/icons/Close"
import { makeStyles, Theme } from "@material-ui/core/styles"
import { colors } from "theme/colors"
import ReportProblemOutlinedIcon from "@material-ui/icons/ReportProblemOutlined"
import Button from "@material-ui/core/Button"
import { useTranslation } from "react-i18next"

export interface WarningAlertProps {
text: string
action?: ReactElement
dismissible?: boolean
actions?: ReactElement[]
}

export const WarningAlert: FC<WarningAlertProps> = ({ text, action }) => {
export const WarningAlert: FC<WarningAlertProps> = ({
text,
dismissible = false,
actions = [],
}) => {
const { t } = useTranslation("common")
const [open, setOpen] = useState(true)
const classes = useStyles()

return (
<Stack>
<Collapse in={open}>
<Alert
severity="warning"
action={
action ? (
action
) : (
<IconButton
aria-label="close"
color="inherit"
size="small"
onClick={() => {
setOpen(false)
}}
>
<CloseIcon fontSize="inherit" />
</IconButton>
)
}
>
<Collapse in={open}>
<Stack
className={classes.alertContainer}
direction="row"
alignItems="center"
spacing={0}
justifyContent="space-between"
>
<Stack direction="row" spacing={1}>
<ReportProblemOutlinedIcon fontSize="small" className={classes.alertIcon} />
{text}
</Alert>
</Collapse>
</Stack>
</Stack>
<Stack direction="row">
{actions.length > 0 && actions.map((action) => <div key={String(action)}>{action}</div>)}
{dismissible && (
<Button size="small" onClick={() => setOpen(false)} variant="outlined">
{t("ctas.dismissCta")}
</Button>
)}
</Stack>
</Stack>
</Collapse>
)
}

const useStyles = makeStyles<Theme>((theme) => ({
alertContainer: {
border: `1px solid ${colors.orange[7]}`,
borderRadius: theme.shape.borderRadius,
padding: `${theme.spacing(1)}px ${theme.spacing(2)}px`,
backgroundColor: `${colors.gray[16]}`,
},
alertIcon: {
color: `${colors.orange[7]}`,
},
}))
2 changes: 1 addition & 1 deletion site/src/components/Workspace/Workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const Workspace: FC<React.PropsWithChildren<WorkspaceProps>> = ({
)

const workspaceRefreshWarning = Boolean(workspaceErrors[WorkspaceErrors.GET_RESOURCES_ERROR]) && (
<WarningAlert text={t("warningsAndErrors.workspaceRefreshWarning")} />
<WarningAlert text={t("warningsAndErrors.workspaceRefreshWarning")} dismissible />
)

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ export const WorkspaceDeletedBanner: FC<React.PropsWithChildren<WorkspaceDeleted
}

const NewWorkspaceButton = (
<Button color="inherit" onClick={handleClick} size="small">
<Button onClick={handleClick} size="small">
{t("ctas.createWorkspaceCta")}
</Button>
)

return (
<WarningAlert
text={t("warningsAndErrors.workspaceDeletedWarning")}
action={NewWorkspaceButton}
actions={[NewWorkspaceButton]}
/>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,15 @@ export const WorkspaceScheduleBanner: FC<React.PropsWithChildren<WorkspaceSchedu
}

const ScheduleButton = (
<Button variant="outlined" color="inherit" disabled={isLoading} onClick={onExtend} size="small">
<Button variant="outlined" disabled={isLoading} onClick={onExtend} size="small">
{t("ctas.extendScheduleCta")}
</Button>
)

return (
<WarningAlert text={t("warningsAndErrors.workspaceShutdownWarning")} action={ScheduleButton} />
<WarningAlert
text={t("warningsAndErrors.workspaceShutdownWarning")}
actions={[ScheduleButton]}
/>
)
}
3 changes: 3 additions & 0 deletions site/src/i18n/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,8 @@
"confirm": "Are you sure you want to proceed? Type the name of this {{entity}} below to confirm.",
"confirmLabel": "Name of {{entity}} to delete",
"incorrectName": "Incorrect {{entity}} name."
},
"ctas": {
"dismissCta": "Dismiss"
}
}