Skip to content
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
fmt
  • Loading branch information
coadler committed Oct 10, 2022
commit ae7b62fd3a3135152d51e62a89c2692dba4a2b2c
5 changes: 4 additions & 1 deletion site/src/pages/WorkspacesPage/WorkspacesPageView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ export const WorkspacesPageView: FC<
const presetFilters = [
{ query: workspaceFilterQuery.me, name: Language.yourWorkspacesButton },
{ query: workspaceFilterQuery.all, name: Language.allWorkspacesButton },
{ query: workspaceFilterQuery.running, name: Language.runningWorkspacesButton },
{
query: workspaceFilterQuery.running,
name: Language.runningWorkspacesButton,
},
]

return (
Expand Down
15 changes: 11 additions & 4 deletions site/src/xServices/workspaces/workspacesXService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,18 +321,24 @@ export const workspacesMachine = createMachine(
assignUpdatedWorkspaceRefs: assign({
workspaceRefs: (_, event) => {
const newWorkspaceRefs = event.data.newWorkspaces.map((workspace) =>
spawn(workspaceItemMachine.withContext({ data: workspace }), workspace.id),
spawn(
workspaceItemMachine.withContext({ data: workspace }),
workspace.id,
),
)
return event.data.refsToKeep.concat(newWorkspaceRefs)
},
}),
},
services: {
getWorkspaces: (context) => API.getWorkspaces(queryToFilter(context.filter)),
getWorkspaces: (context) =>
API.getWorkspaces(queryToFilter(context.filter)),
updateWorkspaceRefs: (context, event) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I can understand what is happening here but I would add a comment about the refsToKeep and what the ref.stop is doing. Also, do we need to make this a service since it does not run any async ops.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I made it a service because we don't want to do stop and send in an assign action, and it's okay in another action, but then it's harder to send data from one action to the next (which is by design, I think). I think I would need to save refsToKeep and newWorkspaces in context, and that felt like clutter.

const refsToKeep: WorkspaceItemMachineRef[] = []
context.workspaceRefs?.forEach((ref) => {
const matchingWorkspace = event.data.find((workspace) => ref.id === workspace.id)
const matchingWorkspace = event.data.find(
(workspace) => ref.id === workspace.id,
)
if (matchingWorkspace) {
// if a workspace machine reference describes a workspace that has not been deleted,
// update its data and mark it as a refToKeep
Expand All @@ -345,7 +351,8 @@ export const workspacesMachine = createMachine(
})

const newWorkspaces = event.data.filter(
(workspace) => !context.workspaceRefs?.find((ref) => ref.id === workspace.id),
(workspace) =>
!context.workspaceRefs?.find((ref) => ref.id === workspace.id),
)

return Promise.resolve({
Expand Down