Skip to content

Commit 4c37164

Browse files
committed
chore: start applying feedback
1 parent 6a9a37b commit 4c37164

File tree

1 file changed

+37
-32
lines changed

1 file changed

+37
-32
lines changed

site/src/pages/WorkspacesPage/BatchUpdateModalForm.stories.tsx

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import type { Meta, Parameters, StoryObj } from "@storybook/react-vite";
2-
import { expect, screen, userEvent, within } from "storybook/test";
32
import { templateVersionRoot } from "api/queries/templates";
43
import type {
54
TemplateVersion,
65
Workspace,
76
WorkspaceBuild,
87
} from "api/typesGenerated";
98
import { useQueryClient } from "react-query";
9+
import { action } from "storybook/internal/actions";
10+
import { expect, screen, userEvent, within } from "storybook/test";
1011
import { MockTemplateVersion, MockWorkspace } from "testHelpers/entities";
1112
import { BatchUpdateModalForm } from "./BatchUpdateModalForm";
1213
import { ACTIVE_BUILD_STATUSES } from "./WorkspacesPage";
13-
import { action } from "storybook/internal/actions";
1414

1515
type Writeable<T> = { -readonly [Key in keyof T]: T[Key] };
1616
type MutableWorkspace = Writeable<Omit<Workspace, "latest_build">> & {
@@ -81,20 +81,19 @@ export const OnlyReadyToUpdate: Story = {
8181
beforeEach: (ctx) => {
8282
const { workspaces, queries } = createPatchedDependencies(3);
8383
ctx.args = { ...ctx.args, workspacesToUpdate: workspaces };
84-
ctx.parameters = { ...ctx.parameters, queries };
84+
ctx.parameters.queries = queries;
8585
},
8686
};
8787

8888
export const NoWorkspacesToUpdate: Story = {
8989
beforeEach: (ctx) => {
9090
const { workspaces, queries } = createPatchedDependencies(3);
91-
for (const ws of workspaces) {
92-
const writable = ws as MutableWorkspace;
93-
writable.outdated = false;
94-
}
91+
const notOutdated = workspaces.map<Workspace>((ws) => {
92+
return { ...ws, outdated: false };
93+
});
9594

96-
ctx.args = { ...ctx.args, workspacesToUpdate: workspaces };
97-
ctx.parameters = { ...ctx.parameters, queries };
95+
ctx.args = { ...ctx.args, workspacesToUpdate: notOutdated };
96+
ctx.parameters.queries = queries;
9897
},
9998
};
10099

@@ -103,7 +102,7 @@ export const CurrentlyProcessing: Story = {
103102
beforeEach: (ctx) => {
104103
const { workspaces, queries } = createPatchedDependencies(3);
105104
ctx.args = { ...ctx.args, workspacesToUpdate: workspaces };
106-
ctx.parameters = { ...ctx.parameters, queries };
105+
ctx.parameters.queries = queries;
107106
},
108107
};
109108

@@ -120,15 +119,15 @@ export const OnlyDormantWorkspaces: Story = {
120119
writable.dormant_at = new Date().toISOString();
121120
}
122121
ctx.args = { ...ctx.args, workspacesToUpdate: workspaces };
123-
ctx.parameters = { ...ctx.parameters, queries };
122+
ctx.parameters.queries = queries;
124123
},
125124
};
126125

127126
export const FetchError: Story = {
128127
beforeEach: (ctx) => {
129128
const { workspaces, queries } = createPatchedDependencies(3);
130129
ctx.args = { ...ctx.args, workspacesToUpdate: workspaces };
131-
ctx.parameters = { ...ctx.parameters, queries };
130+
ctx.parameters.queries = queries;
132131
},
133132
decorators: [
134133
(Story, ctx) => {
@@ -155,39 +154,45 @@ export const TransitioningWorkspaces: Story = {
155154
const { workspaces, queries } = createPatchedDependencies(
156155
2 * ACTIVE_BUILD_STATUSES.length,
157156
);
158-
for (const [i, ws] of workspaces.entries()) {
157+
const withUpdatedStatuses = workspaces.map<Workspace>((ws, i) => {
159158
if (i % 2 === 0) {
160-
continue;
159+
return ws;
161160
}
162-
const writable = ws.latest_build as Writeable<WorkspaceBuild>;
163-
writable.status = ACTIVE_BUILD_STATUSES[i % ACTIVE_BUILD_STATUSES.length];
164-
}
165-
ctx.args = { ...ctx.args, workspacesToUpdate: workspaces };
166-
ctx.parameters = { ...ctx.parameters, queries };
161+
return {
162+
...ws,
163+
latest_build: {
164+
...ws.latest_build,
165+
status: ACTIVE_BUILD_STATUSES[i % ACTIVE_BUILD_STATUSES.length],
166+
},
167+
};
168+
});
169+
170+
ctx.args = { ...ctx.args, workspacesToUpdate: withUpdatedStatuses };
171+
ctx.parameters.queries = queries;
167172
},
168173
};
169174

170175
export const RunningWorkspaces: Story = {
171176
beforeEach: (ctx) => {
172177
const { workspaces, queries } = createPatchedDependencies(3);
173-
for (const ws of workspaces) {
174-
const writable = ws.latest_build as Writeable<WorkspaceBuild>;
175-
writable.status = "running";
176-
}
177-
ctx.args = { ...ctx.args, workspacesToUpdate: workspaces };
178-
ctx.parameters = { ...ctx.parameters, queries };
178+
const allRunning = workspaces.map<Workspace>((ws) => {
179+
return { ...ws, status: "running" };
180+
});
181+
182+
ctx.args = { ...ctx.args, workspacesToUpdate: allRunning };
183+
ctx.parameters.queries = queries;
179184
},
180185
};
181186

182187
export const RunningWorkspacesFailedValidation: Story = {
183188
beforeEach: (ctx) => {
184189
const { workspaces, queries } = createPatchedDependencies(3);
185-
for (const ws of workspaces) {
186-
const writable = ws.latest_build as Writeable<WorkspaceBuild>;
187-
writable.status = "running";
188-
}
189-
ctx.args = { ...ctx.args, workspacesToUpdate: workspaces };
190-
ctx.parameters = { ...ctx.parameters, queries };
190+
const allRunning = workspaces.map<Workspace>((ws) => {
191+
return { ...ws, status: "running" };
192+
});
193+
194+
ctx.args = { ...ctx.args, workspacesToUpdate: allRunning };
195+
ctx.parameters.queries = queries;
191196
},
192197
play: async () => {
193198
// Can't use canvasElement from the play function's context because the
@@ -270,6 +275,6 @@ export const MixOfWorkspaces: Story = {
270275
noUpdatesNeededTransitioning.latest_build.status = "starting";
271276

272277
ctx.args = { ...ctx.args, workspacesToUpdate: workspaces };
273-
ctx.parameters = { ...ctx.parameters, queries };
278+
ctx.parameters.queries = queries;
274279
},
275280
};

0 commit comments

Comments
 (0)