Skip to content

Commit afaa20e

Browse files
chore: add proxy provider decorator for storybook (#18023)
1 parent f678f92 commit afaa20e

File tree

9 files changed

+79
-260
lines changed

9 files changed

+79
-260
lines changed

site/src/modules/resources/AgentRow.stories.tsx

Lines changed: 14 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2-
import { ProxyContext, getPreferredProxy } from "contexts/ProxyContext";
2+
import { getPreferredProxy } from "contexts/ProxyContext";
33
import { chromatic } from "testHelpers/chromatic";
44
import * as M from "testHelpers/entities";
5-
import { withDashboardProvider, withWebSocket } from "testHelpers/storybook";
5+
import {
6+
withDashboardProvider,
7+
withProxyProvider,
8+
withWebSocket,
9+
} from "testHelpers/storybook";
610
import { AgentRow } from "./AgentRow";
711

812
const defaultAgentMetadata = [
@@ -94,32 +98,7 @@ const meta: Meta<typeof AgentRow> = {
9498
showApps: true,
9599
storybookAgentMetadata: defaultAgentMetadata,
96100
},
97-
decorators: [
98-
(Story) => (
99-
<ProxyContext.Provider
100-
value={{
101-
proxyLatencies: M.MockProxyLatencies,
102-
proxy: getPreferredProxy([], undefined),
103-
proxies: [],
104-
isLoading: false,
105-
isFetched: true,
106-
setProxy: () => {
107-
return;
108-
},
109-
clearProxy: () => {
110-
return;
111-
},
112-
refetchProxyLatencies: (): Date => {
113-
return new Date();
114-
},
115-
}}
116-
>
117-
<Story />
118-
</ProxyContext.Provider>
119-
),
120-
withDashboardProvider,
121-
withWebSocket,
122-
],
101+
decorators: [withProxyProvider(), withDashboardProvider, withWebSocket],
123102
parameters: {
124103
chromatic,
125104
queries: [
@@ -253,31 +232,13 @@ export const Off: Story = {
253232

254233
export const ShowingPortForward: Story = {
255234
decorators: [
256-
(Story) => (
257-
<ProxyContext.Provider
258-
value={{
259-
proxyLatencies: M.MockProxyLatencies,
260-
proxy: getPreferredProxy(
261-
M.MockWorkspaceProxies,
262-
M.MockPrimaryWorkspaceProxy,
263-
),
264-
proxies: M.MockWorkspaceProxies,
265-
isLoading: false,
266-
isFetched: true,
267-
setProxy: () => {
268-
return;
269-
},
270-
clearProxy: () => {
271-
return;
272-
},
273-
refetchProxyLatencies: (): Date => {
274-
return new Date();
275-
},
276-
}}
277-
>
278-
<Story />
279-
</ProxyContext.Provider>
280-
),
235+
withProxyProvider({
236+
proxy: getPreferredProxy(
237+
M.MockWorkspaceProxies,
238+
M.MockPrimaryWorkspaceProxy,
239+
),
240+
proxies: M.MockWorkspaceProxies,
241+
}),
281242
],
282243
};
283244

site/src/modules/resources/AppLink/AppLink.stories.tsx

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,25 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2-
import { ProxyContext, getPreferredProxy } from "contexts/ProxyContext";
2+
import { getPreferredProxy } from "contexts/ProxyContext";
33
import {
44
MockPrimaryWorkspaceProxy,
5-
MockProxyLatencies,
65
MockWorkspace,
76
MockWorkspaceAgent,
87
MockWorkspaceApp,
98
MockWorkspaceProxies,
109
} from "testHelpers/entities";
11-
import { withGlobalSnackbar } from "testHelpers/storybook";
10+
import { withGlobalSnackbar, withProxyProvider } from "testHelpers/storybook";
1211
import { AppLink } from "./AppLink";
1312

1413
const meta: Meta<typeof AppLink> = {
1514
title: "modules/resources/AppLink",
1615
component: AppLink,
1716
decorators: [
18-
(Story) => (
19-
<ProxyContext.Provider
20-
value={{
21-
proxyLatencies: MockProxyLatencies,
22-
proxy: {
23-
...getPreferredProxy(
24-
MockWorkspaceProxies,
25-
MockPrimaryWorkspaceProxy,
26-
),
27-
preferredWildcardHostname: "*.super_proxy.tld",
28-
},
29-
proxies: MockWorkspaceProxies,
30-
isLoading: false,
31-
isFetched: true,
32-
setProxy: () => {
33-
return;
34-
},
35-
clearProxy: () => {
36-
return;
37-
},
38-
refetchProxyLatencies: (): Date => {
39-
return new Date();
40-
},
41-
}}
42-
>
43-
<Story />
44-
</ProxyContext.Provider>
45-
),
17+
withProxyProvider({
18+
proxy: {
19+
...getPreferredProxy(MockWorkspaceProxies, MockPrimaryWorkspaceProxy),
20+
preferredWildcardHostname: "*.super_proxy.tld",
21+
},
22+
}),
4623
],
4724
};
4825

site/src/modules/resources/ResourceCard.stories.tsx

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2-
import type { WorkspaceAgent } from "api/typesGenerated";
3-
import { ProxyContext, getPreferredProxy } from "contexts/ProxyContext";
4-
import {
5-
MockProxyLatencies,
6-
MockWorkspaceResource,
7-
} from "testHelpers/entities";
2+
import { MockWorkspaceResource } from "testHelpers/entities";
3+
import { withProxyProvider } from "testHelpers/storybook";
84
import { AgentRowPreview } from "./AgentRowPreview";
95
import { ResourceCard } from "./ResourceCard";
106

117
const meta: Meta<typeof ResourceCard> = {
128
title: "modules/resources/ResourceCard",
139
component: ResourceCard,
10+
decorators: [withProxyProvider()],
1411
args: {
1512
resource: MockWorkspaceResource,
16-
agentRow: getAgentRow,
13+
agentRow: (agent) => <AgentRowPreview agent={agent} key={agent.id} />,
1714
},
1815
};
1916

@@ -67,31 +64,5 @@ export const BunchOfMetadata: Story = {
6764
},
6865
],
6966
},
70-
agentRow: getAgentRow,
7167
},
7268
};
73-
74-
function getAgentRow(agent: WorkspaceAgent): JSX.Element {
75-
return (
76-
<ProxyContext.Provider
77-
value={{
78-
proxyLatencies: MockProxyLatencies,
79-
proxy: getPreferredProxy([], undefined),
80-
proxies: [],
81-
isLoading: false,
82-
isFetched: true,
83-
setProxy: () => {
84-
return;
85-
},
86-
clearProxy: () => {
87-
return;
88-
},
89-
refetchProxyLatencies: (): Date => {
90-
return new Date();
91-
},
92-
}}
93-
>
94-
<AgentRowPreview agent={agent} key={agent.id} />
95-
</ProxyContext.Provider>
96-
);
97-
}

site/src/modules/resources/Resources.stories.tsx

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2-
import type { WorkspaceAgent } from "api/typesGenerated";
3-
import { ProxyContext, getPreferredProxy } from "contexts/ProxyContext";
42
import {
5-
MockProxyLatencies,
63
MockWorkspaceResource,
74
MockWorkspaceResourceMultipleAgents,
85
} from "testHelpers/entities";
6+
import { withProxyProvider } from "testHelpers/storybook";
97
import { AgentRowPreview } from "./AgentRowPreview";
108
import { Resources } from "./Resources";
119

1210
const meta: Meta<typeof Resources> = {
1311
title: "modules/resources/Resources",
1412
component: Resources,
13+
decorators: [withProxyProvider()],
1514
args: {
1615
resources: [MockWorkspaceResource],
17-
agentRow: getAgentRow,
16+
agentRow: (agent) => <AgentRowPreview key={agent.id} agent={agent} />,
1817
},
1918
};
2019

@@ -163,31 +162,5 @@ export const BunchOfDevicesWithMetadata: Story = {
163162
),
164163
},
165164
],
166-
agentRow: getAgentRow,
167165
},
168166
};
169-
170-
function getAgentRow(agent: WorkspaceAgent): JSX.Element {
171-
return (
172-
<ProxyContext.Provider
173-
value={{
174-
proxyLatencies: MockProxyLatencies,
175-
proxy: getPreferredProxy([], undefined),
176-
proxies: [],
177-
isLoading: false,
178-
isFetched: true,
179-
setProxy: () => {
180-
return;
181-
},
182-
clearProxy: () => {
183-
return;
184-
},
185-
refetchProxyLatencies: (): Date => {
186-
return new Date();
187-
},
188-
}}
189-
>
190-
<AgentRowPreview key={agent.id} agent={agent} />
191-
</ProxyContext.Provider>
192-
);
193-
}

site/src/modules/workspaces/WorkspaceAppStatus/WorkspaceAppStatus.stories.tsx

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,12 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2-
import { ProxyContext, getPreferredProxy } from "contexts/ProxyContext";
3-
import {
4-
MockProxyLatencies,
5-
MockWorkspaceAppStatus,
6-
} from "testHelpers/entities";
2+
import { MockWorkspaceAppStatus } from "testHelpers/entities";
3+
import { withProxyProvider } from "testHelpers/storybook";
74
import { WorkspaceAppStatus } from "./WorkspaceAppStatus";
85

96
const meta: Meta<typeof WorkspaceAppStatus> = {
107
title: "modules/workspaces/WorkspaceAppStatus",
118
component: WorkspaceAppStatus,
12-
decorators: [
13-
(Story) => (
14-
<ProxyContext.Provider
15-
value={{
16-
proxyLatencies: MockProxyLatencies,
17-
proxy: getPreferredProxy([], undefined),
18-
proxies: [],
19-
isLoading: false,
20-
isFetched: true,
21-
clearProxy: () => {
22-
return;
23-
},
24-
setProxy: () => {
25-
return;
26-
},
27-
refetchProxyLatencies: (): Date => {
28-
return new Date();
29-
},
30-
}}
31-
>
32-
<Story />
33-
</ProxyContext.Provider>
34-
),
35-
],
9+
decorators: [withProxyProvider()],
3610
};
3711

3812
export default meta;

site/src/pages/WorkspacePage/AppStatuses.stories.tsx

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2-
import { ProxyContext, getPreferredProxy } from "contexts/ProxyContext";
32
import {
4-
MockProxyLatencies,
53
MockWorkspace,
64
MockWorkspaceAgent,
75
MockWorkspaceApp,
86
MockWorkspaceAppStatus,
97
} from "testHelpers/entities";
8+
import { withProxyProvider } from "testHelpers/storybook";
109
import { AppStatuses } from "./AppStatuses";
1110

1211
const meta: Meta<typeof AppStatuses> = {
@@ -15,31 +14,7 @@ const meta: Meta<typeof AppStatuses> = {
1514
args: {
1615
referenceDate: new Date("2024-03-26T15:15:00Z"),
1716
},
18-
// Add decorator for ProxyContext
19-
decorators: [
20-
(Story) => (
21-
<ProxyContext.Provider
22-
value={{
23-
proxyLatencies: MockProxyLatencies,
24-
proxy: getPreferredProxy([], undefined),
25-
proxies: [],
26-
isLoading: false,
27-
isFetched: true,
28-
clearProxy: () => {
29-
return;
30-
},
31-
setProxy: () => {
32-
return;
33-
},
34-
refetchProxyLatencies: (): Date => {
35-
return new Date();
36-
},
37-
}}
38-
>
39-
<Story />
40-
</ProxyContext.Provider>
41-
),
42-
],
17+
decorators: [withProxyProvider()],
4318
};
4419

4520
export default meta;

site/src/pages/WorkspacePage/Workspace.stories.tsx

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import { action } from "@storybook/addon-actions";
22
import type { Meta, StoryObj } from "@storybook/react";
33
import type { ProvisionerJobLog } from "api/typesGenerated";
4-
import { ProxyContext, getPreferredProxy } from "contexts/ProxyContext";
54
import * as Mocks from "testHelpers/entities";
6-
import { withAuthProvider, withDashboardProvider } from "testHelpers/storybook";
5+
import {
6+
withAuthProvider,
7+
withDashboardProvider,
8+
withProxyProvider,
9+
} from "testHelpers/storybook";
710
import type { WorkspacePermissions } from "../../modules/workspaces/permissions";
811
import { Workspace } from "./Workspace";
912

@@ -43,32 +46,7 @@ const meta: Meta<typeof Workspace> = {
4346
],
4447
user: Mocks.MockUserOwner,
4548
},
46-
decorators: [
47-
withAuthProvider,
48-
withDashboardProvider,
49-
(Story) => (
50-
<ProxyContext.Provider
51-
value={{
52-
proxyLatencies: Mocks.MockProxyLatencies,
53-
proxy: getPreferredProxy([], undefined),
54-
proxies: [],
55-
isLoading: false,
56-
isFetched: true,
57-
clearProxy: () => {
58-
return;
59-
},
60-
setProxy: () => {
61-
return;
62-
},
63-
refetchProxyLatencies: (): Date => {
64-
return new Date();
65-
},
66-
}}
67-
>
68-
<Story />
69-
</ProxyContext.Provider>
70-
),
71-
],
49+
decorators: [withAuthProvider, withDashboardProvider, withProxyProvider()],
7250
};
7351

7452
export default meta;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy