( parentAgent: WorkspaceAgent, devcontainer: WorkspaceAgentDevcontainer, queryClient: QueryClient, )
| 568 | }; |
| 569 | |
| 570 | export const deleteWorkspaceAgentDevcontainer = ( |
| 571 | parentAgent: WorkspaceAgent, |
| 572 | devcontainer: WorkspaceAgentDevcontainer, |
| 573 | queryClient: QueryClient, |
| 574 | ) => { |
| 575 | const queryKey = workspaceAgentContainersKey(parentAgent.id); |
| 576 | |
| 577 | return { |
| 578 | mutationFn: async () => { |
| 579 | await API.deleteDevContainer({ |
| 580 | parentAgentId: parentAgent.id, |
| 581 | devcontainerId: devcontainer.id, |
| 582 | }); |
| 583 | }, |
| 584 | onMutate: async () => { |
| 585 | await queryClient.cancelQueries({ queryKey }); |
| 586 | const previousData = queryClient.getQueryData(queryKey); |
| 587 | |
| 588 | queryClient.setQueryData( |
| 589 | queryKey, |
| 590 | (oldData?: WorkspaceAgentListContainersResponse) => { |
| 591 | if (!oldData?.devcontainers) { |
| 592 | return oldData; |
| 593 | } |
| 594 | |
| 595 | return { |
| 596 | ...oldData, |
| 597 | devcontainers: oldData.devcontainers.map((dc) => { |
| 598 | if (dc.id === devcontainer.id) { |
| 599 | return { |
| 600 | ...dc, |
| 601 | status: "stopping", |
| 602 | container: undefined, |
| 603 | }; |
| 604 | } |
| 605 | return dc; |
| 606 | }), |
| 607 | }; |
| 608 | }, |
| 609 | ); |
| 610 | |
| 611 | return { previousData }; |
| 612 | }, |
| 613 | onError: (_error, _variables, context) => { |
| 614 | if (context?.previousData) { |
| 615 | queryClient.setQueryData(queryKey, context.previousData); |
| 616 | } |
| 617 | }, |
| 618 | } satisfies UseMutationOptions< |
| 619 | void, |
| 620 | Error, |
| 621 | void, |
| 622 | { |
| 623 | previousData: unknown; |
| 624 | } |
| 625 | >; |
| 626 | }; |
no test coverage detected