Skip to content

feat: add impending deletion banner to workspace page #7634

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 5 commits into from
May 25, 2023
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
fix prettier and lint
  • Loading branch information
Kira-Pilot committed May 22, 2023
commit c62d297eecb3df43886ccfa567a1cea16e7741d7
36 changes: 19 additions & 17 deletions site/src/components/WorkspaceDeletion/ImpendingDeletionBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export const ImpendingDeletionBanner = ({
workspace?: Workspace
onDismiss: () => void
displayImpendingDeletionBanner: boolean
count?: Count,
count?: Count
}): JSX.Element | null => {
const { entitlements, experiments } = useDashboard()
const allowAdvancedScheduling =
Expand All @@ -27,23 +27,25 @@ export const ImpendingDeletionBanner = ({
// is merged up
const allowWorkspaceActions = experiments.includes("workspace_actions")

if (
!workspace ||
!displayImpendingDeletion(
workspace,
allowAdvancedScheduling,
allowWorkspaceActions,
) ||
!displayImpendingDeletionBanner
) {
return null
}
if (
!workspace ||
!displayImpendingDeletion(
workspace,
allowAdvancedScheduling,
allowWorkspaceActions,
) ||
!displayImpendingDeletionBanner
) {
return null
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found it hard to read/understand this "display or not" logic here. I think the names displayImpendingDeletion and displayImpendingDeletionBanner are very similar and I took some time to understand they are different but not sure how to improve this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, let me improve that


return (
<Alert severity="info" onDismiss={onDismiss} dismissible>
{count === Count.Singular
? `This workspace has been unused for ${formatDistanceToNow(Date.parse(workspace.last_used_at))} and is scheduled for deletion. To keep it, connect via SSH or the web terminal.`
: "You have workspaces that will be deleted soon due to inactivity. To keep these workspaces, connect to them via SSH or the web terminal."}
</Alert>
<Alert severity="info" onDismiss={onDismiss} dismissible>
{count === Count.Singular
? `This workspace has been unused for ${formatDistanceToNow(
Date.parse(workspace.last_used_at),
)} and is scheduled for deletion. To keep it, connect via SSH or the web terminal.`
: "You have workspaces that will be deleted soon due to inactivity. To keep these workspaces, connect to them via SSH or the web terminal."}
</Alert>
)
}
2 changes: 1 addition & 1 deletion site/src/pages/WorkspacesPage/WorkspacesPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe("WorkspacesPage", () => {
renderWithAuth(<WorkspacesPage />)

const banner = await screen.findByText(
"You have workspaces that will be deleted soon.",
"You have workspaces that will be deleted soon due to inactivity. To keep these workspaces, connect to them via SSH or the web terminal.",
)
const user = userEvent.setup()
await user.click(screen.getByTestId("dismiss-banner-btn"))
Expand Down