-
Notifications
You must be signed in to change notification settings - Fork 989
feat: Add "Outdated" tooltip and "Update version" button in the Workspaces page #2322
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
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e5cbcd8
Add version tooltup
BrunoQuaresma 9d92df2
Add update action
BrunoQuaresma 58d6a6a
Add pooling
BrunoQuaresma b4bc684
Fix pooling
BrunoQuaresma ca18646
Fix pulling and workspace data update
BrunoQuaresma d982d55
Update site/src/pages/WorkspacesPage/WorkspacesPageView.tsx
BrunoQuaresma e6145bd
Fix formatting and add more context
BrunoQuaresma File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add pooling
- Loading branch information
commit 58d6a6a69903265abc9bcd0c2b26ae8081e56663
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,15 @@ import { ActorRefFrom, assign, createMachine, spawn } from "xstate" | |
import * as API from "../../api/api" | ||
import { getErrorMessage } from "../../api/errors" | ||
import * as TypesGen from "../../api/typesGenerated" | ||
import { displayError, displayMsg } from "../../components/GlobalSnackbar/utils" | ||
import { displayError, displayMsg, displaySuccess } from "../../components/GlobalSnackbar/utils" | ||
import { workspaceQueryToFilter } from "../../util/workspace" | ||
|
||
/** | ||
* Workspace item machine | ||
* | ||
* It is used to control the state and actions of each workspace in the | ||
* workspaces page view | ||
**/ | ||
interface WorkspaceItemContext { | ||
data: TypesGen.Workspace | ||
updatedTemplate?: TypesGen.Template | ||
|
@@ -30,18 +36,22 @@ export const workspaceItemMachine = createMachine( | |
}, | ||
}, | ||
tsTypes: {} as import("./workspacesXService.typegen").Typegen0, | ||
initial: "idle", | ||
type: "parallel", | ||
states: { | ||
idle: { | ||
on: { | ||
UPDATE_VERSION: "updatingVersion", | ||
}, | ||
}, | ||
updatingVersion: { | ||
entry: "displayUpdatingVersionMessage", | ||
initial: "gettingUpdatedTemplate", | ||
onDone: "idle", | ||
updateVersion: { | ||
initial: "idle", | ||
states: { | ||
idle: { | ||
on: { | ||
UPDATE_VERSION: { | ||
target: "gettingUpdatedTemplate", | ||
// We can improve the UI by optimistically updating the workspace status | ||
// to "Queued" so the UI can display the updated state right away and we | ||
// don't need to display an extra spinner. | ||
actions: ["assignQueuedStatus", "displayUpdatingVersionMessage"], | ||
}, | ||
}, | ||
}, | ||
gettingUpdatedTemplate: { | ||
invoke: { | ||
id: "getTemplate", | ||
|
@@ -62,14 +72,35 @@ export const workspaceItemMachine = createMachine( | |
src: "startWorkspace", | ||
onDone: { | ||
actions: "assignLatestBuild", | ||
target: "success", | ||
target: "waitingToBeUpdated", | ||
}, | ||
onError: { | ||
target: "error", | ||
actions: "displayUpdateVersionError", | ||
}, | ||
}, | ||
}, | ||
waitingToBeUpdated: { | ||
after: { | ||
5000: "gettingUpdatedWorkspaceData", | ||
}, | ||
}, | ||
gettingUpdatedWorkspaceData: { | ||
invoke: { | ||
id: "getWorkspace", | ||
src: "getWorkspace", | ||
onDone: [ | ||
{ | ||
target: "waitingToBeUpdated", | ||
cond: "isOutdated", | ||
}, | ||
{ | ||
target: "success", | ||
actions: "displayUpdatedSuccessMessage", | ||
}, | ||
], | ||
}, | ||
}, | ||
error: { | ||
type: "final", | ||
}, | ||
|
@@ -81,6 +112,9 @@ export const workspaceItemMachine = createMachine( | |
}, | ||
}, | ||
{ | ||
guards: { | ||
isOutdated: (ctx) => !ctx.data.outdated, | ||
}, | ||
services: { | ||
getTemplate: (context) => API.getTemplate(context.data.template_id), | ||
startWorkspace: (context) => { | ||
|
@@ -108,15 +142,38 @@ export const workspaceItemMachine = createMachine( | |
displayError(message) | ||
}, | ||
displayUpdatingVersionMessage: () => { | ||
displayMsg("Updating workspace version", "When it is done, the workspace will be updated in the list.") | ||
displayMsg("Updating your workspace", "It will be running in a few seconds.") | ||
}, | ||
assignQueuedStatus: assign({ | ||
data: (ctx) => { | ||
return { | ||
...ctx.data, | ||
latest_build: { | ||
...ctx.data.latest_build, | ||
job: { | ||
...ctx.data.latest_build.job, | ||
status: "pending" as TypesGen.ProvisionerJobStatus, | ||
}, | ||
}, | ||
} | ||
}, | ||
}), | ||
displayUpdatedSuccessMessage: () => { | ||
displaySuccess("Workspace updated successfully.") | ||
}, | ||
}, | ||
}, | ||
) | ||
|
||
/** | ||
* Workspaces machine | ||
* | ||
* It is used to control the state of the workspace list | ||
**/ | ||
|
||
export type WorkspaceItemMachineRef = ActorRefFrom<typeof workspaceItemMachine> | ||
|
||
interface WorkspaceContext { | ||
interface WorkspacesContext { | ||
workspaceRefs?: WorkspaceItemMachineRef[] | ||
filter?: string | ||
getWorkspacesError?: Error | unknown | ||
|
@@ -128,7 +185,7 @@ export const workspacesMachine = createMachine( | |
{ | ||
tsTypes: {} as import("./workspacesXService.typegen").Typegen1, | ||
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. What's this 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. It is auto-generated by XState types: https://xstate.js.org/docs/guides/typescript.html#typegen |
||
schema: { | ||
context: {} as WorkspaceContext, | ||
context: {} as WorkspacesContext, | ||
events: {} as WorkspacesEvent, | ||
services: {} as { | ||
getWorkspaces: { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.