Skip to content

Commit cce6f1e

Browse files
pdesoyres-ccflorian-sanders-cc
authored andcommitted
refactor(cc-tile-metrics): refactor typechecking
1 parent 2f74dd6 commit cce6f1e

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

src/components/cc-tile-metrics/cc-tile-metrics.stories.js

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,42 @@ export default {
1111
const conf = {
1212
component: 'cc-tile-metrics',
1313
// language=CSS
14-
css: `cc-tile-metrics {
15-
margin-bottom: 1em;
16-
}`,
14+
css: `
15+
cc-tile-metrics {
16+
margin-bottom: 1em;
17+
}
18+
19+
cc-tile-metrics:nth-of-type(1) {
20+
max-width: 23.75em
21+
}
22+
23+
cc-tile-metrics:nth-of-type(2) {
24+
max-width: 33.75em
25+
}
26+
`,
1727
};
1828

1929
/**
2030
* @typedef {import('./cc-tile-metrics.js').CcTileMetrics} CcTileMetrics
2131
* @typedef {import('./cc-tile-metrics.types.js').TileMetricsMetricsStateLoaded} TileMetricsStateLoaded
22-
* @typedef {import('./cc-tile-metrics.types.js').TileMetricsMetricsStateEmpty} TileMetricsStateEmpty
23-
* @typedef {import('./cc-tile-metrics.types.js').TileMetricsMetricsStateLoading} TileMetricsStateLoading
24-
* @typedef {import('./cc-tile-metrics.types.js').TileMetricsMetricsStateError} TileMetricsStateError
25-
* @typedef {import('./cc-tile-metrics.types.js').TileMetricsGrafanaLinkStateLoaded} TileMetricsGrafanaLinkStateLoaded
26-
* @typedef {import('./cc-tile-metrics.types.js').TileMetricsGrafanaLinkStateLoading} TileMetricsGrafanaLinkStateLoading
2732
* @typedef {import('./cc-tile-metrics.types.js').Metric} Metric
2833
*/
2934

30-
/** @type {{ grafanaLinkState: TileMetricsGrafanaLinkStateLoaded, metricsLink: string, style?: string }[]} */
35+
/** @type {Array<Partial<CcTileMetrics>>} */
3136
const baseItems = [
3237
{
3338
grafanaLinkState: {
3439
type: 'loaded',
3540
link: 'https://grafana.example.com/small',
3641
},
37-
metricsLink: 'https://metrics.example.com/small',
38-
style: 'max-width: 23.75em',
42+
metricsLink: 'https://metrics.example.com',
3943
},
4044
{
4145
grafanaLinkState: {
4246
type: 'loaded',
4347
link: 'https://grafana.example.com/medium',
4448
},
4549
metricsLink: 'https://metrics.example.com/medium',
46-
style: 'max-width: 33.75em',
4750
},
4851
{
4952
grafanaLinkState: {
@@ -89,9 +92,9 @@ function addTimestamp(array) {
8992
}
9093

9194
export const defaultStory = makeStory(conf, {
95+
/** @type {Array<Partial<CcTileMetrics>>} */
9296
items: baseItems.map((item) => ({
9397
...item,
94-
/** @type {TileMetricsStateLoaded} */
9598
metricsState: {
9699
type: 'loaded',
97100
metricsData: {
@@ -103,7 +106,7 @@ export const defaultStory = makeStory(conf, {
103106
});
104107

105108
export const loading = makeStory(conf, {
106-
/** @type {{ metricsState: TileMetricsStateLoading, grafanaLinkState: TileMetricsGrafanaLinkStateLoading, style?: string }[]} */
109+
/** @type {Array<Partial<CcTileMetrics>>} */
107110
items: baseItems.map((item) => ({
108111
...item,
109112
metricsState: { type: 'loading' },
@@ -112,19 +115,19 @@ export const loading = makeStory(conf, {
112115
});
113116

114117
export const empty = makeStory(conf, {
115-
/** @type {{ metricsState: TileMetricsStateEmpty, style?: string }[]} */
118+
/** @type {Array<Partial<CcTileMetrics>>} */
116119
items: baseItems.map((item) => ({ ...item, metricsState: { type: 'empty' } })),
117120
});
118121

119122
export const error = makeStory(conf, {
120-
/** @type {{ metricsState: TileMetricsStateError, style?: string }[]} */
123+
/** @type {Array<Partial<CcTileMetrics>>} */
121124
items: baseItems.map((item) => ({ ...item, metricsState: { type: 'error' } })),
122125
});
123126

124127
export const dataLoadedWithHighValues = makeStory(conf, {
128+
/** @type {Array<Partial<CcTileMetrics>>} */
125129
items: baseItems.map((item) => ({
126130
...item,
127-
/** @type {TileMetricsStateLoaded} */
128131
metricsState: {
129132
type: 'loaded',
130133
metricsData: {
@@ -136,9 +139,9 @@ export const dataLoadedWithHighValues = makeStory(conf, {
136139
});
137140

138141
export const peaks = makeStory(conf, {
142+
/** @type {Array<Partial<CcTileMetrics>>} */
139143
items: baseItems.map((item) => ({
140144
...item,
141-
/** @type {TileMetricsStateLoaded} */
142145
metricsState: {
143146
type: 'loaded',
144147
metricsData: {
@@ -156,9 +159,9 @@ export const peaks = makeStory(conf, {
156159
});
157160

158161
export const linearIncrease = makeStory(conf, {
162+
/** @type {Array<Partial<CcTileMetrics>>} */
159163
items: baseItems.map((item) => ({
160164
...item,
161-
/** @type {TileMetricsStateLoaded} */
162165
metricsState: {
163166
type: 'loaded',
164167
metricsData: {
@@ -170,9 +173,9 @@ export const linearIncrease = makeStory(conf, {
170173
});
171174

172175
export const scaleUp = makeStory(conf, {
176+
/** @type {Array<Partial<CcTileMetrics>>} */
173177
items: baseItems.map((item) => ({
174178
...item,
175-
/** @type {TileMetricsStateLoaded} */
176179
metricsState: {
177180
type: 'loaded',
178181
metricsData: {
@@ -184,9 +187,9 @@ export const scaleUp = makeStory(conf, {
184187
});
185188

186189
export const scaleDown = makeStory(conf, {
190+
/** @type {Array<Partial<CcTileMetrics>>} */
187191
items: baseItems.map((item) => ({
188192
...item,
189-
/** @type {TileMetricsStateLoaded} */
190193
metricsState: {
191194
type: 'loaded',
192195
metricsData: {
@@ -198,9 +201,9 @@ export const scaleDown = makeStory(conf, {
198201
});
199202

200203
export const multipleScaleUp = makeStory(conf, {
204+
/** @type {Array<Partial<CcTileMetrics>>} */
201205
items: baseItems.map((item) => ({
202206
...item,
203-
/** @type {TileMetricsStateLoaded} */
204207
metricsState: {
205208
type: 'loaded',
206209
metricsData: {
@@ -216,9 +219,9 @@ export const multipleScaleUp = makeStory(conf, {
216219
});
217220

218221
export const multipleScaleDown = makeStory(conf, {
222+
/** @type {Array<Partial<CcTileMetrics>>} */
219223
items: baseItems.map((item) => ({
220224
...item,
221-
/** @type {TileMetricsStateLoaded} */
222225
metricsState: {
223226
type: 'loaded',
224227
metricsData: {
@@ -238,9 +241,9 @@ export const multipleScaleDown = makeStory(conf, {
238241
});
239242

240243
export const bigScaleUp = makeStory(conf, {
244+
/** @type {Array<Partial<CcTileMetrics>>} */
241245
items: baseItems.map((item) => ({
242246
...item,
243-
/** @type {TileMetricsStateLoaded} */
244247
metricsState: {
245248
type: 'loaded',
246249
metricsData: {
@@ -252,9 +255,9 @@ export const bigScaleUp = makeStory(conf, {
252255
});
253256

254257
export const bigScaleDown = makeStory(conf, {
258+
/** @type {Array<Partial<CcTileMetrics>>} */
255259
items: baseItems.map((item) => ({
256260
...item,
257-
/** @type {TileMetricsStateLoaded} */
258261
metricsState: {
259262
type: 'loaded',
260263
metricsData: {
@@ -266,9 +269,9 @@ export const bigScaleDown = makeStory(conf, {
266269
});
267270

268271
export const appDown = makeStory(conf, {
272+
/** @type {Array<Partial<CcTileMetrics>>} */
269273
items: baseItems.map((item) => ({
270274
...item,
271-
/** @type {TileMetricsStateLoaded} */
272275
metricsState: {
273276
type: 'loaded',
274277
metricsData: {
@@ -280,6 +283,7 @@ export const appDown = makeStory(conf, {
280283
});
281284

282285
export const simulationsWithData = makeStory(conf, {
286+
/** @type {Array<Partial<CcTileMetrics>>} */
283287
items: baseItems.map((baseItem) => ({
284288
...baseItem,
285289
metricsState: { type: 'loading' },

0 commit comments

Comments
 (0)