Skip to content

Commit ca11cd2

Browse files
committed
Fix storybook
1 parent da70544 commit ca11cd2

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

site/src/api/queries/debug.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@ import * as API from "api/api";
22
import { HealthSettings } from "api/typesGenerated";
33
import { QueryClient, UseMutationOptions } from "react-query";
44

5+
export const HEALTH_QUERY_KEY = ["health"];
6+
export const HEALTH_QUERY_SETTINGS_KEY = ["health", "settings"];
7+
58
export const health = () => ({
6-
queryKey: ["health"],
9+
queryKey: HEALTH_QUERY_KEY,
710
queryFn: async () => API.getHealth(),
811
});
912

1013
export const refreshHealth = (queryClient: QueryClient) => {
1114
return {
1215
mutationFn: async () => {
13-
await queryClient.cancelQueries(["health"]);
16+
await queryClient.cancelQueries(HEALTH_QUERY_KEY);
1417
const newHealthData = await API.getHealth(true);
15-
queryClient.setQueryData(["health"], newHealthData);
18+
queryClient.setQueryData(HEALTH_QUERY_KEY, newHealthData);
1619
},
1720
};
1821
};
1922

2023
export const healthSettings = () => {
2124
return {
22-
queryKey: ["health", "settings"],
25+
queryKey: HEALTH_QUERY_SETTINGS_KEY,
2326
queryFn: API.getHealthSettings,
2427
};
2528
};
@@ -30,8 +33,8 @@ export const updateHealthSettings = (
3033
return {
3134
mutationFn: API.updateHealthSettings,
3235
onSuccess: async (_, newSettings) => {
33-
await queryClient.invalidateQueries(["health"]);
34-
queryClient.setQueryData(["health", "settings"], newSettings);
36+
await queryClient.invalidateQueries(HEALTH_QUERY_KEY);
37+
queryClient.setQueryData(HEALTH_QUERY_SETTINGS_KEY, newSettings);
3538
},
3639
};
3740
};
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useQueryClient } from "react-query";
2+
import {
3+
reactRouterParameters,
4+
reactRouterOutlet,
5+
RouteDefinition,
6+
} from "storybook-addon-react-router-v6";
7+
import { MockHealth, MockHealthSettings } from "testHelpers/entities";
8+
import { Meta } from "@storybook/react";
9+
import { HEALTH_QUERY_KEY, HEALTH_QUERY_SETTINGS_KEY } from "api/queries/debug";
10+
11+
type MetaOptions = {
12+
element: RouteDefinition;
13+
path: string;
14+
};
15+
16+
export const generateMeta = ({ element, path }: MetaOptions): Meta => {
17+
return {
18+
parameters: {
19+
layout: "fullscreen",
20+
reactRouter: reactRouterParameters({
21+
routing: reactRouterOutlet({ path: `/health/${path}` }, element),
22+
}),
23+
},
24+
decorators: [
25+
(Story) => {
26+
const queryClient = useQueryClient();
27+
queryClient.setQueryData(HEALTH_QUERY_KEY, MockHealth);
28+
queryClient.setQueryData(HEALTH_QUERY_SETTINGS_KEY, MockHealthSettings);
29+
return <Story />;
30+
},
31+
],
32+
};
33+
};

site/src/testHelpers/entities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3148,3 +3148,7 @@ export const DeploymentHealthUnhealthy: TypesGen.HealthcheckReport = {
31483148
},
31493149
},
31503150
};
3151+
3152+
export const MockHealthSettings: TypesGen.HealthSettings = {
3153+
dismissed_healthchecks: [],
3154+
};

0 commit comments

Comments
 (0)