-
Notifications
You must be signed in to change notification settings - Fork 875
chore: refactor frontend to use workspace status directly #4361
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
Changes from 1 commit
330f2af
c38352d
7dc2ef2
56f927e
a363534
1992e08
5072691
d06c432
b9829b5
23c607e
5e10ddf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { WorkspaceStatus } from "api/typesGenerated" | ||
import { ReactNode } from "react" | ||
import { WorkspaceStateEnum } from "util/workspace" | ||
|
||
// the button types we have | ||
export enum ButtonTypesEnum { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume these are based on the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are similar to |
||
|
@@ -14,82 +14,77 @@ export enum ButtonTypesEnum { | |
// disabled buttons | ||
canceling = "canceling", | ||
disabled = "disabled", | ||
queued = "queued", | ||
loading = "loading", | ||
pending = "pending", | ||
} | ||
|
||
export type ButtonMapping = { | ||
[key in ButtonTypesEnum]: ReactNode | ||
} | ||
|
||
type StateActionsType = { | ||
[key in WorkspaceStateEnum]: { | ||
type StateActionsType = Record< | ||
WorkspaceStatus, | ||
{ | ||
primary: ButtonTypesEnum | ||
secondary: ButtonTypesEnum[] | ||
canCancel: boolean | ||
} | ||
} | ||
> | ||
|
||
// A mapping of workspace state to button type | ||
// 'Primary' actions are the main ctas | ||
// 'Secondary' actions are ctas housed within the popover | ||
export const WorkspaceStateActions: StateActionsType = { | ||
[WorkspaceStateEnum.starting]: { | ||
starting: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One of the reasons we made There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's still typesafe because the keys have to be values of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhhhh, I didn't even see that. You're right - still typesafe! Feel free to ignore the clarify part of my comment - I'm just still figuring out where I land on this whole enum literal debate :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Me too honestly! Just following the generated type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point! I left a comment above related to this. |
||
primary: ButtonTypesEnum.starting, | ||
secondary: [], | ||
canCancel: true, | ||
}, | ||
[WorkspaceStateEnum.started]: { | ||
running: { | ||
primary: ButtonTypesEnum.stop, | ||
secondary: [ButtonTypesEnum.delete], | ||
canCancel: false, | ||
}, | ||
[WorkspaceStateEnum.stopping]: { | ||
stopping: { | ||
primary: ButtonTypesEnum.stopping, | ||
secondary: [], | ||
canCancel: true, | ||
}, | ||
[WorkspaceStateEnum.stopped]: { | ||
stopped: { | ||
primary: ButtonTypesEnum.start, | ||
secondary: [ButtonTypesEnum.delete], | ||
canCancel: false, | ||
}, | ||
[WorkspaceStateEnum.canceled]: { | ||
canceled: { | ||
primary: ButtonTypesEnum.start, | ||
secondary: [ButtonTypesEnum.stop, ButtonTypesEnum.delete], | ||
canCancel: false, | ||
}, | ||
// in the case of an error | ||
[WorkspaceStateEnum.error]: { | ||
failed: { | ||
primary: ButtonTypesEnum.start, // give the user the ability to start a workspace again | ||
secondary: [ButtonTypesEnum.delete], // allows the user to delete | ||
canCancel: false, | ||
}, | ||
/** | ||
* disabled states | ||
*/ | ||
[WorkspaceStateEnum.canceling]: { | ||
canceling: { | ||
primary: ButtonTypesEnum.canceling, | ||
secondary: [], | ||
canCancel: false, | ||
}, | ||
[WorkspaceStateEnum.deleting]: { | ||
deleting: { | ||
primary: ButtonTypesEnum.deleting, | ||
secondary: [], | ||
canCancel: true, | ||
}, | ||
[WorkspaceStateEnum.deleted]: { | ||
deleted: { | ||
primary: ButtonTypesEnum.disabled, | ||
secondary: [], | ||
canCancel: false, | ||
}, | ||
[WorkspaceStateEnum.queued]: { | ||
primary: ButtonTypesEnum.queued, | ||
secondary: [], | ||
canCancel: false, | ||
}, | ||
[WorkspaceStateEnum.loading]: { | ||
primary: ButtonTypesEnum.loading, | ||
pending: { | ||
primary: ButtonTypesEnum.pending, | ||
secondary: [], | ||
canCancel: false, | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch! This approach makes it easy to fall out of sync with valid
WorkspaceStatus
values. Here's one way we could fix this:TypeScript Playground
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually fixing this in a future refactor, thanks for pointing it out!