@genspectrum/dashboard-components 0.10.2 → 0.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +19 -19
  2. package/custom-elements.json +377 -33
  3. package/dist/assets/mutationOverTimeWorker-BjjkMGzd.js.map +1 -0
  4. package/dist/components.d.ts +217 -59
  5. package/dist/components.js +1365 -177
  6. package/dist/components.js.map +1 -1
  7. package/dist/{dateRangeOption-du8H7LWu.js → dateRangeOption-Doo6WHKu.js} +17 -3
  8. package/dist/dateRangeOption-Doo6WHKu.js.map +1 -0
  9. package/dist/style.css +16 -6
  10. package/dist/util.d.ts +107 -41
  11. package/dist/util.js +1 -1
  12. package/package.json +10 -4
  13. package/src/preact/aggregatedData/aggregate.stories.tsx +14 -0
  14. package/src/preact/aggregatedData/aggregate.tsx +17 -15
  15. package/src/preact/components/error-boundary.stories.tsx +24 -3
  16. package/src/preact/components/error-boundary.tsx +3 -4
  17. package/src/preact/components/error-display.tsx +38 -17
  18. package/src/preact/components/tabs.tsx +2 -2
  19. package/src/preact/dateRangeSelector/date-range-selector.stories.tsx +1 -1
  20. package/src/preact/lineageFilter/lineage-filter.stories.tsx +1 -1
  21. package/src/preact/locationFilter/location-filter.stories.tsx +1 -1
  22. package/src/preact/map/__mockData__/aggregatedGermany.json +83 -0
  23. package/src/preact/map/__mockData__/aggregatedWorld.json +259 -0
  24. package/src/preact/map/__mockData__/germanyMap.json +9083 -0
  25. package/src/preact/map/__mockData__/howToGenerateWorldMap.md +9 -0
  26. package/src/preact/map/__mockData__/worldAtlas.json +497127 -0
  27. package/src/preact/map/leafletStyleModifications.css +3 -0
  28. package/src/preact/map/sequences-by-location-map.tsx +202 -0
  29. package/src/preact/map/sequences-by-location-table.tsx +18 -0
  30. package/src/preact/map/sequences-by-location.stories.tsx +144 -0
  31. package/src/preact/map/sequences-by-location.tsx +151 -0
  32. package/src/preact/map/useGeoJsonMap.tsx +62 -0
  33. package/src/preact/mutationComparison/mutation-comparison.tsx +1 -1
  34. package/src/preact/mutationFilter/mutation-filter.tsx +26 -13
  35. package/src/preact/mutations/mutations.tsx +16 -12
  36. package/src/preact/mutationsOverTime/mutations-over-time.stories.tsx +14 -0
  37. package/src/preact/mutationsOverTime/mutations-over-time.tsx +18 -14
  38. package/src/preact/numberSequencesOverTime/number-sequences-over-time.stories.tsx +14 -0
  39. package/src/preact/numberSequencesOverTime/number-sequences-over-time.tsx +22 -14
  40. package/src/preact/prevalenceOverTime/prevalence-over-time.stories.tsx +14 -0
  41. package/src/preact/prevalenceOverTime/prevalence-over-time.tsx +28 -19
  42. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.stories.tsx +14 -0
  43. package/src/preact/relativeGrowthAdvantage/relative-growth-advantage.tsx +18 -15
  44. package/src/preact/shared/charts/confideceInterval.ts +10 -8
  45. package/src/preact/shared/charts/getYAxisMax.ts +10 -5
  46. package/src/preact/shared/stories/expectErrorMessage.ts +21 -0
  47. package/src/preact/statistic/statistics.tsx +10 -8
  48. package/src/preact/textInput/text-input.stories.tsx +14 -0
  49. package/src/preact/textInput/text-input.tsx +16 -11
  50. package/src/preact/useQuery.ts +9 -1
  51. package/src/query/queryAggregateData.ts +2 -1
  52. package/src/styles/tailwind.css +1 -1
  53. package/src/types.ts +13 -1
  54. package/src/utilEntrypoint.ts +7 -0
  55. package/src/web-components/app.stories.ts +17 -2
  56. package/src/web-components/app.ts +17 -5
  57. package/src/web-components/input/gs-mutation-filter.stories.ts +2 -0
  58. package/src/web-components/input/gs-text-input.tsx +2 -2
  59. package/src/web-components/introduction.mdx +4 -4
  60. package/src/web-components/visualization/data_visualization_statistical_analysis.mdx +3 -3
  61. package/src/web-components/visualization/gs-mutations-over-time.tsx +1 -3
  62. package/src/web-components/visualization/gs-mutations.tsx +1 -3
  63. package/src/web-components/visualization/gs-number-sequences-over-time.tsx +1 -3
  64. package/src/web-components/visualization/gs-prevalence-over-time.tsx +3 -6
  65. package/src/web-components/visualization/gs-relative-growth-advantage.tsx +1 -5
  66. package/src/web-components/visualization/gs-sequences-by-location.stories.ts +234 -0
  67. package/src/web-components/visualization/gs-sequences-by-location.tsx +253 -0
  68. package/src/web-components/visualization/index.ts +1 -0
  69. package/standalone-bundle/assets/mutationOverTimeWorker-DoUBht2e.js.map +1 -0
  70. package/standalone-bundle/dashboard-components.js +16223 -9292
  71. package/standalone-bundle/dashboard-components.js.map +1 -1
  72. package/standalone-bundle/style.css +1 -1
  73. package/dist/assets/mutationOverTimeWorker-Di6yP1e6.js.map +0 -1
  74. package/dist/dateRangeOption-du8H7LWu.js.map +0 -1
  75. package/src/preact/shared/stories/expectInvalidAttributesErrorMessage.ts +0 -13
  76. package/standalone-bundle/assets/mutationOverTimeWorker-cIyshfj_.js.map +0 -1
@@ -1,5 +1,6 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { type Dispatch, type StateUpdater, useContext, useState } from 'preact/hooks';
3
+ import z from 'zod';
3
4
 
4
5
  import { getInsertionsTableData } from './getInsertionsTableData';
5
6
  import { getMutationsTableData } from './getMutationsTableData';
@@ -9,9 +10,10 @@ import MutationsTable from './mutations-table';
9
10
  import { filterMutationsData, queryMutationsData } from './queryMutations';
10
11
  import {
11
12
  type InsertionEntry,
12
- type LapisFilter,
13
- type SequenceType,
13
+ lapisFilterSchema,
14
+ sequenceTypeSchema,
14
15
  type SubstitutionOrDeletionEntry,
16
+ views,
15
17
  } from '../../types';
16
18
  import { LapisUrlContext } from '../LapisUrlContext';
17
19
  import { CsvDownloadButton } from '../components/csv-download-button';
@@ -28,23 +30,25 @@ import { type DisplayedSegment, SegmentSelector, useDisplayedSegments } from '..
28
30
  import Tabs from '../components/tabs';
29
31
  import { useQuery } from '../useQuery';
30
32
 
31
- export type View = 'table' | 'grid' | 'insertions';
33
+ const viewSchema = z.union([z.literal(views.table), z.literal(views.grid), z.literal(views.insertions)]);
34
+ export type View = z.infer<typeof viewSchema>;
32
35
 
33
- export interface MutationsProps {
34
- width: string;
35
- height: string;
36
- lapisFilter: LapisFilter;
37
- sequenceType: SequenceType;
38
- views: View[];
39
- pageSize: boolean | number;
40
- }
36
+ const mutationsPropsSchema = z.object({
37
+ lapisFilter: lapisFilterSchema,
38
+ sequenceType: sequenceTypeSchema,
39
+ views: viewSchema.array(),
40
+ pageSize: z.union([z.boolean(), z.number()]),
41
+ width: z.string(),
42
+ height: z.string(),
43
+ });
44
+ export type MutationsProps = z.infer<typeof mutationsPropsSchema>;
41
45
 
42
46
  export const Mutations: FunctionComponent<MutationsProps> = (componentProps) => {
43
47
  const { width, height } = componentProps;
44
48
  const size = { height, width };
45
49
 
46
50
  return (
47
- <ErrorBoundary size={size}>
51
+ <ErrorBoundary size={size} componentProps={componentProps} schema={mutationsPropsSchema}>
48
52
  <ResizeContainer size={size}>
49
53
  <MutationsInner {...componentProps} />
50
54
  </ResizeContainer>
@@ -6,6 +6,7 @@ import { LAPIS_URL } from '../../constants';
6
6
  import referenceGenome from '../../lapisApi/__mockData__/referenceGenome.json';
7
7
  import { LapisUrlContext } from '../LapisUrlContext';
8
8
  import { ReferenceGenomeContext } from '../ReferenceGenomeContext';
9
+ import { expectInvalidAttributesErrorMessage } from '../shared/stories/expectErrorMessage';
9
10
 
10
11
  const meta: Meta<MutationsOverTimeProps> = {
11
12
  title: 'Visualization/Mutation over time',
@@ -155,3 +156,16 @@ export const ShowsNoDataMessageForStrictFilters: StoryObj<MutationsOverTimeProps
155
156
  );
156
157
  },
157
158
  };
159
+
160
+ export const WithNoLapisDateFieldField: StoryObj<MutationsOverTimeProps> = {
161
+ ...Default,
162
+ args: {
163
+ ...Default.args,
164
+ lapisDateField: '',
165
+ },
166
+ play: async ({ canvasElement, step }) => {
167
+ step('expect error message', async () => {
168
+ await expectInvalidAttributesErrorMessage(canvasElement, 'String must contain at least 1 character(s)');
169
+ });
170
+ },
171
+ };
@@ -1,5 +1,6 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { type Dispatch, type StateUpdater, useContext, useMemo, useState } from 'preact/hooks';
3
+ import z from 'zod';
3
4
 
4
5
  // @ts-expect-error -- uses subpath imports and vite worker import
5
6
  import MutationOverTimeWorker from '#mutationOverTime?worker&inline';
@@ -9,10 +10,11 @@ import { type MutationOverTimeWorkerResponse } from './mutationOverTimeWorker';
9
10
  import MutationsOverTimeGrid from './mutations-over-time-grid';
10
11
  import { type MutationOverTimeQuery } from '../../query/queryMutationsOverTime';
11
12
  import {
12
- type LapisFilter,
13
- type SequenceType,
13
+ lapisFilterSchema,
14
+ sequenceTypeSchema,
14
15
  type SubstitutionOrDeletionEntry,
15
- type TemporalGranularity,
16
+ temporalGranularitySchema,
17
+ views,
16
18
  } from '../../types';
17
19
  import { type Deletion, type Substitution } from '../../utils/mutations';
18
20
  import { toTemporalClass } from '../../utils/temporalClass';
@@ -33,24 +35,26 @@ import { type DisplayedSegment, SegmentSelector, useDisplayedSegments } from '..
33
35
  import Tabs from '../components/tabs';
34
36
  import { useWebWorker } from '../webWorkers/useWebWorker';
35
37
 
36
- export type View = 'grid';
38
+ const viewSchema = z.literal(views.grid);
39
+ export type View = z.infer<typeof viewSchema>;
37
40
 
38
- export interface MutationsOverTimeProps {
39
- width: string;
40
- height: string;
41
- lapisFilter: LapisFilter;
42
- sequenceType: SequenceType;
43
- views: View[];
44
- granularity: TemporalGranularity;
45
- lapisDateField: string;
46
- }
41
+ const mutationOverTimeSchema = z.object({
42
+ lapisFilter: lapisFilterSchema,
43
+ sequenceType: sequenceTypeSchema,
44
+ views: z.array(viewSchema),
45
+ granularity: temporalGranularitySchema,
46
+ lapisDateField: z.string().min(1),
47
+ width: z.string(),
48
+ height: z.string(),
49
+ });
50
+ export type MutationsOverTimeProps = z.infer<typeof mutationOverTimeSchema>;
47
51
 
48
52
  export const MutationsOverTime: FunctionComponent<MutationsOverTimeProps> = (componentProps) => {
49
53
  const { width, height } = componentProps;
50
54
  const size = { height, width };
51
55
 
52
56
  return (
53
- <ErrorBoundary size={size}>
57
+ <ErrorBoundary size={size} schema={mutationOverTimeSchema} componentProps={componentProps}>
54
58
  <ResizeContainer size={size}>
55
59
  <MutationsOverTimeInner {...componentProps} />
56
60
  </ResizeContainer>
@@ -6,6 +6,7 @@ import oneVariantEG from '../../preact/numberSequencesOverTime/__mockData__/oneV
6
6
  import twoVariantsEG from '../../preact/numberSequencesOverTime/__mockData__/twoVariantsEG.json';
7
7
  import twoVariantsJN1 from '../../preact/numberSequencesOverTime/__mockData__/twoVariantsJN1.json';
8
8
  import { LapisUrlContext } from '../LapisUrlContext';
9
+ import { expectInvalidAttributesErrorMessage } from '../shared/stories/expectErrorMessage';
9
10
 
10
11
  export default {
11
12
  title: 'Visualization/NumberSequencesOverTime',
@@ -129,3 +130,16 @@ export const TwoVariants = {
129
130
  },
130
131
  },
131
132
  };
133
+
134
+ export const WithNoLapisDateField: StoryObj<NumberSequencesOverTimeProps> = {
135
+ ...Template,
136
+ args: {
137
+ ...Template.args,
138
+ lapisDateField: '',
139
+ },
140
+ play: async ({ canvasElement, step }) => {
141
+ step('expect error message', async () => {
142
+ await expectInvalidAttributesErrorMessage(canvasElement, 'String must contain at least 1 character(s)');
143
+ });
144
+ },
145
+ };
@@ -1,5 +1,6 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { useContext, useState } from 'preact/hooks';
3
+ import z from 'zod';
3
4
 
4
5
  import { getNumberOfSequencesOverTimeTableData } from './getNumberOfSequencesOverTimeTableData';
5
6
  import { NumberSequencesOverTimeBarChart } from './number-sequences-over-time-bar-chart';
@@ -9,7 +10,7 @@ import {
9
10
  type NumberOfSequencesDatasets,
10
11
  queryNumberOfSequencesOverTime,
11
12
  } from '../../query/queryNumberOfSequencesOverTime';
12
- import type { NamedLapisFilter, TemporalGranularity } from '../../types';
13
+ import { namedLapisFilterSchema, temporalGranularitySchema, views } from '../../types';
13
14
  import { LapisUrlContext } from '../LapisUrlContext';
14
15
  import { CsvDownloadButton } from '../components/csv-download-button';
15
16
  import { ErrorBoundary } from '../components/error-boundary';
@@ -23,25 +24,32 @@ import Tabs from '../components/tabs';
23
24
  import type { ScaleType } from '../shared/charts/getYAxisScale';
24
25
  import { useQuery } from '../useQuery';
25
26
 
26
- type NumberSequencesOverTimeView = 'bar' | 'line' | 'table';
27
-
28
- export interface NumberSequencesOverTimeProps {
29
- width: string;
30
- height: string;
31
- lapisFilter: NamedLapisFilter | NamedLapisFilter[];
32
- lapisDateField: string;
33
- views: NumberSequencesOverTimeView[];
34
- granularity: TemporalGranularity;
35
- smoothingWindow: number;
36
- pageSize: boolean | number;
37
- }
27
+ const numberSequencesOverTimeViewSchema = z.union([
28
+ z.literal(views.bar),
29
+ z.literal(views.line),
30
+ z.literal(views.table),
31
+ ]);
32
+ export type NumberSequencesOverTimeView = z.infer<typeof numberSequencesOverTimeViewSchema>;
33
+
34
+ const numberSequencesOverTimePropsSchema = z.object({
35
+ width: z.string(),
36
+ height: z.string(),
37
+ lapisFilter: z.union([namedLapisFilterSchema, z.array(namedLapisFilterSchema)]),
38
+ lapisDateField: z.string().min(1),
39
+ views: z.array(numberSequencesOverTimeViewSchema),
40
+ granularity: temporalGranularitySchema,
41
+ smoothingWindow: z.number(),
42
+ pageSize: z.union([z.boolean(), z.number()]),
43
+ });
44
+
45
+ export type NumberSequencesOverTimeProps = z.infer<typeof numberSequencesOverTimePropsSchema>;
38
46
 
39
47
  export const NumberSequencesOverTime = (componentProps: NumberSequencesOverTimeProps) => {
40
48
  const { width, height } = componentProps;
41
49
  const size = { height, width };
42
50
 
43
51
  return (
44
- <ErrorBoundary size={size}>
52
+ <ErrorBoundary size={size} componentProps={componentProps} schema={numberSequencesOverTimePropsSchema}>
45
53
  <ResizeContainer size={size}>
46
54
  <NumberSequencesOverTimeInner {...componentProps} />
47
55
  </ResizeContainer>
@@ -10,6 +10,7 @@ import numeratorFilterNoData from './__mockData__/numeratorFilterNoData.json';
10
10
  import numeratorOneDataset from './__mockData__/numeratorFilterOneDataset.json';
11
11
  import { PrevalenceOverTime, type PrevalenceOverTimeProps } from './prevalence-over-time';
12
12
  import { AGGREGATED_ENDPOINT, LAPIS_URL } from '../../constants';
13
+ import { expectInvalidAttributesErrorMessage } from '../shared/stories/expectErrorMessage';
13
14
 
14
15
  export default {
15
16
  title: 'Visualization/PrevalenceOverTime',
@@ -256,3 +257,16 @@ export const ShowsNoDataBanner: StoryObj<PrevalenceOverTimeProps> = {
256
257
  });
257
258
  },
258
259
  };
260
+
261
+ export const WithNoLapisDateField: StoryObj<PrevalenceOverTimeProps> = {
262
+ ...OneVariant,
263
+ args: {
264
+ ...OneVariant.args,
265
+ lapisDateField: '',
266
+ },
267
+ play: async ({ canvasElement, step }) => {
268
+ step('expect error message', async () => {
269
+ await expectInvalidAttributesErrorMessage(canvasElement, 'String must contain at least 1 character(s)');
270
+ });
271
+ },
272
+ };
@@ -1,5 +1,6 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { useContext, useEffect, useState } from 'preact/hooks';
3
+ import z from 'zod';
3
4
 
4
5
  import { getPrevalenceOverTimeTableData } from './getPrevalenceOverTimeTableData';
5
6
  import PrevalenceOverTimeBarChart from './prevalence-over-time-bar-chart';
@@ -7,7 +8,7 @@ import PrevalenceOverTimeBubbleChart from './prevalence-over-time-bubble-chart';
7
8
  import PrevalenceOverTimeLineChart from './prevalence-over-time-line-chart';
8
9
  import PrevalenceOverTimeTable from './prevalence-over-time-table';
9
10
  import { type PrevalenceOverTimeData, queryPrevalenceOverTime } from '../../query/queryPrevalenceOverTime';
10
- import { type LapisFilter, type NamedLapisFilter, type TemporalGranularity } from '../../types';
11
+ import { lapisFilterSchema, namedLapisFilterSchema, temporalGranularitySchema, views } from '../../types';
11
12
  import { LapisUrlContext } from '../LapisUrlContext';
12
13
  import { ConfidenceIntervalSelector } from '../components/confidence-interval-selector';
13
14
  import { CsvDownloadButton } from '../components/csv-download-button';
@@ -19,34 +20,42 @@ import { NoDataDisplay } from '../components/no-data-display';
19
20
  import { ResizeContainer } from '../components/resize-container';
20
21
  import { ScalingSelector } from '../components/scaling-selector';
21
22
  import Tabs from '../components/tabs';
22
- import { type ConfidenceIntervalMethod } from '../shared/charts/confideceInterval';
23
- import { type AxisMax } from '../shared/charts/getYAxisMax';
23
+ import { type ConfidenceIntervalMethod, confidenceIntervalMethodSchema } from '../shared/charts/confideceInterval';
24
+ import { axisMaxSchema } from '../shared/charts/getYAxisMax';
24
25
  import { type ScaleType } from '../shared/charts/getYAxisScale';
25
26
  import { useQuery } from '../useQuery';
26
27
 
27
- export type View = 'bar' | 'line' | 'bubble' | 'table';
28
+ const viewSchema = z.union([
29
+ z.literal(views.table),
30
+ z.literal(views.bar),
31
+ z.literal(views.line),
32
+ z.literal(views.bubble),
33
+ ]);
34
+ export type View = z.infer<typeof viewSchema>;
28
35
 
29
- export interface PrevalenceOverTimeProps {
30
- width: string;
31
- height: string;
32
- numeratorFilter: NamedLapisFilter | NamedLapisFilter[];
33
- denominatorFilter: LapisFilter;
34
- granularity: TemporalGranularity;
35
- smoothingWindow: number;
36
- views: View[];
37
- confidenceIntervalMethods: ConfidenceIntervalMethod[];
38
- lapisDateField: string;
39
- pageSize: boolean | number;
40
- yAxisMaxLinear: AxisMax;
41
- yAxisMaxLogarithmic: AxisMax;
42
- }
36
+ const prevalenceOverTimePropsSchema = z.object({
37
+ width: z.string(),
38
+ height: z.string(),
39
+ numeratorFilter: z.union([namedLapisFilterSchema, z.array(namedLapisFilterSchema)]),
40
+ denominatorFilter: lapisFilterSchema,
41
+ granularity: temporalGranularitySchema,
42
+ smoothingWindow: z.number(),
43
+ views: z.array(viewSchema),
44
+ confidenceIntervalMethods: z.array(confidenceIntervalMethodSchema),
45
+ lapisDateField: z.string().min(1),
46
+ pageSize: z.union([z.boolean(), z.number()]),
47
+ yAxisMaxLinear: axisMaxSchema,
48
+ yAxisMaxLogarithmic: axisMaxSchema,
49
+ });
50
+
51
+ export type PrevalenceOverTimeProps = z.infer<typeof prevalenceOverTimePropsSchema>;
43
52
 
44
53
  export const PrevalenceOverTime: FunctionComponent<PrevalenceOverTimeProps> = (componentProps) => {
45
54
  const { width, height } = componentProps;
46
55
  const size = { height, width };
47
56
 
48
57
  return (
49
- <ErrorBoundary size={size}>
58
+ <ErrorBoundary size={size} schema={prevalenceOverTimePropsSchema} componentProps={componentProps}>
50
59
  <ResizeContainer size={size}>
51
60
  <PrevalenceOverTimeInner {...componentProps} />
52
61
  </ResizeContainer>
@@ -6,6 +6,7 @@ import numerator from './__mockData__/numeratorFilter.json';
6
6
  import { RelativeGrowthAdvantage, type RelativeGrowthAdvantageProps } from './relative-growth-advantage';
7
7
  import { AGGREGATED_ENDPOINT, LAPIS_URL } from '../../constants';
8
8
  import { LapisUrlContext } from '../LapisUrlContext';
9
+ import { expectInvalidAttributesErrorMessage } from '../shared/stories/expectErrorMessage';
9
10
 
10
11
  export default {
11
12
  title: 'Visualization/RelativeGrowthAdvantage',
@@ -190,3 +191,16 @@ export const TooFewDataToComputeGrowthAdvantage: StoryObj<RelativeGrowthAdvantag
190
191
  });
191
192
  },
192
193
  };
194
+
195
+ export const WithNoLapisDateField: StoryObj<RelativeGrowthAdvantageProps> = {
196
+ ...Primary,
197
+ args: {
198
+ ...Primary.args,
199
+ lapisDateField: '',
200
+ },
201
+ play: async ({ canvasElement, step }) => {
202
+ step('expect error message', async () => {
203
+ await expectInvalidAttributesErrorMessage(canvasElement, 'String must contain at least 1 character(s)');
204
+ });
205
+ },
206
+ };
@@ -1,5 +1,6 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { useContext, useState } from 'preact/hooks';
3
+ import z from 'zod';
3
4
 
4
5
  import RelativeGrowthAdvantageChart from './relative-growth-advantage-chart';
5
6
  import {
@@ -7,7 +8,7 @@ import {
7
8
  queryRelativeGrowthAdvantage,
8
9
  type RelativeGrowthAdvantageData,
9
10
  } from '../../query/queryRelativeGrowthAdvantage';
10
- import { type LapisFilter } from '../../types';
11
+ import { lapisFilterSchema, views } from '../../types';
11
12
  import { LapisUrlContext } from '../LapisUrlContext';
12
13
  import { ErrorBoundary } from '../components/error-boundary';
13
14
  import { Fullscreen } from '../components/fullscreen';
@@ -17,29 +18,31 @@ import { NoDataDisplay } from '../components/no-data-display';
17
18
  import { ResizeContainer } from '../components/resize-container';
18
19
  import { ScalingSelector } from '../components/scaling-selector';
19
20
  import Tabs from '../components/tabs';
20
- import { type YAxisMaxConfig } from '../shared/charts/getYAxisMax';
21
+ import { yAxisMaxConfigSchema } from '../shared/charts/getYAxisMax';
21
22
  import { type ScaleType } from '../shared/charts/getYAxisScale';
22
23
  import { useQuery } from '../useQuery';
23
24
 
24
- export type View = 'line';
25
-
26
- export interface RelativeGrowthAdvantageProps {
27
- width: string;
28
- height: string;
29
- numeratorFilter: LapisFilter;
30
- denominatorFilter: LapisFilter;
31
- generationTime: number;
32
- views: View[];
33
- lapisDateField: string;
34
- yAxisMaxConfig: YAxisMaxConfig;
35
- }
25
+ const viewSchema = z.literal(views.line);
26
+ export type View = z.infer<typeof viewSchema>;
27
+
28
+ export const relativeGrowthAdvantagePropsSchema = z.object({
29
+ width: z.string(),
30
+ height: z.string(),
31
+ numeratorFilter: lapisFilterSchema,
32
+ denominatorFilter: lapisFilterSchema,
33
+ generationTime: z.number(),
34
+ views: z.array(viewSchema),
35
+ lapisDateField: z.string().min(1),
36
+ yAxisMaxConfig: yAxisMaxConfigSchema,
37
+ });
38
+ export type RelativeGrowthAdvantageProps = z.infer<typeof relativeGrowthAdvantagePropsSchema>;
36
39
 
37
40
  export const RelativeGrowthAdvantage: FunctionComponent<RelativeGrowthAdvantageProps> = (componentProps) => {
38
41
  const { width, height } = componentProps;
39
42
  const size = { height, width };
40
43
 
41
44
  return (
42
- <ErrorBoundary size={size}>
45
+ <ErrorBoundary size={size} schema={relativeGrowthAdvantagePropsSchema} componentProps={componentProps}>
43
46
  <ResizeContainer size={size}>
44
47
  <RelativeGrowthAdvantageInner {...componentProps} />
45
48
  </ResizeContainer>
@@ -1,10 +1,11 @@
1
- // calculateWilsonInterval calculates the Wilson score interval for 95% confidence.
2
- //
3
- // This function is based on https://github.com/erikfox/wilson-interval, but without
4
- // high precision math.
5
- //
6
- // observed - number of observed positive outcomes
7
- // sample - number of experiments or size of the sample
1
+ import z from 'zod';
2
+
3
+ /*
4
+ * calculateWilsonInterval calculates the Wilson score interval for 95% confidence.
5
+ *This function is based on https://github.com/erikfox/wilson-interval, but without high precision math.
6
+ * observed - number of observed positive outcomes
7
+ * sample - number of experiments or size of the sample
8
+ */
8
9
  export function wilson95PercentConfidenceInterval(observed: number, sample: number) {
9
10
  const p = observed / sample;
10
11
  const n = sample;
@@ -31,4 +32,5 @@ export const confidenceIntervalDataLabel = (
31
32
  return `${label}${value.toFixed(3)} (${lowerLimit?.toFixed(3)} - ${upperLimit?.toFixed(3)})`;
32
33
  };
33
34
 
34
- export type ConfidenceIntervalMethod = 'wilson' | 'none';
35
+ export const confidenceIntervalMethodSchema = z.union([z.literal('wilson'), z.literal('none')]);
36
+ export type ConfidenceIntervalMethod = z.infer<typeof confidenceIntervalMethodSchema>;
@@ -1,9 +1,14 @@
1
- export interface YAxisMaxConfig {
2
- linear?: AxisMax;
3
- logarithmic?: AxisMax;
4
- }
1
+ import z from 'zod';
5
2
 
6
- export type AxisMax = 'maxInData' | 'limitTo1' | number;
3
+ export const axisMaxSchema = z.union([z.literal('maxInData'), z.literal('limitTo1'), z.number()]);
4
+ export type AxisMax = z.infer<typeof axisMaxSchema>;
5
+
6
+ export const yAxisMaxConfigSchema = z.object({
7
+ linear: axisMaxSchema.optional(),
8
+ logarithmic: axisMaxSchema.optional(),
9
+ });
10
+
11
+ export type YAxisMaxConfig = z.infer<typeof yAxisMaxConfigSchema>;
7
12
 
8
13
  export const getYAxisMax = (maxInData: number, axisMax?: AxisMax) => {
9
14
  if (!axisMax) {
@@ -0,0 +1,21 @@
1
+ import { expect, waitFor, within } from '@storybook/test';
2
+
3
+ export function playThatExpectsErrorMessage(errorTitle: string, errorMessage: string) {
4
+ return async ({ canvasElement }: { canvasElement: HTMLElement }) => {
5
+ await expectErrorMessage(canvasElement, errorTitle, errorMessage);
6
+ };
7
+ }
8
+
9
+ export async function expectErrorMessage(canvasElement: HTMLElement, errorTitle: string, errorMessage: string) {
10
+ const canvas = within(canvasElement);
11
+
12
+ await waitFor(() => expect(canvas.getByText(errorTitle, { exact: false })).toBeInTheDocument());
13
+
14
+ canvas.getByRole('button', { name: 'Show details.' }).click();
15
+
16
+ await waitFor(() => expect(canvas.getByText(errorMessage, { exact: false })).toBeVisible());
17
+ }
18
+
19
+ export async function expectInvalidAttributesErrorMessage(canvasElement: HTMLElement, errorMessage: string) {
20
+ await expectErrorMessage(canvasElement, 'Error - Invalid component attributes', errorMessage);
21
+ }
@@ -1,8 +1,9 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { useContext } from 'preact/hooks';
3
+ import z from 'zod';
3
4
 
4
5
  import { queryGeneralStatistics } from '../../query/queryGeneralStatistics';
5
- import { type LapisFilter } from '../../types';
6
+ import { lapisFilterSchema } from '../../types';
6
7
  import { LapisUrlContext } from '../LapisUrlContext';
7
8
  import { ErrorBoundary } from '../components/error-boundary';
8
9
  import { LoadingDisplay } from '../components/loading-display';
@@ -11,19 +12,20 @@ import { ResizeContainer } from '../components/resize-container';
11
12
  import { formatProportion } from '../shared/table/formatProportion';
12
13
  import { useQuery } from '../useQuery';
13
14
 
14
- export type StatisticsProps = {
15
- width: string;
16
- height: string;
17
- numeratorFilter: LapisFilter;
18
- denominatorFilter: LapisFilter;
19
- };
15
+ const statisticsPropsSchema = z.object({
16
+ width: z.string(),
17
+ height: z.string(),
18
+ numeratorFilter: lapisFilterSchema,
19
+ denominatorFilter: lapisFilterSchema,
20
+ });
21
+ export type StatisticsProps = z.infer<typeof statisticsPropsSchema>;
20
22
 
21
23
  export const Statistics: FunctionComponent<StatisticsProps> = (componentProps) => {
22
24
  const { width, height } = componentProps;
23
25
  const size = { height, width };
24
26
 
25
27
  return (
26
- <ErrorBoundary size={size}>
28
+ <ErrorBoundary size={size} schema={statisticsPropsSchema} componentProps={componentProps}>
27
29
  <ResizeContainer size={size}>
28
30
  <StatisticsInner {...componentProps} />
29
31
  </ResizeContainer>
@@ -6,6 +6,7 @@ import { TextInput, type TextInputProps } from './text-input';
6
6
  import { previewHandles } from '../../../.storybook/preview';
7
7
  import { AGGREGATED_ENDPOINT, LAPIS_URL } from '../../constants';
8
8
  import { LapisUrlContext } from '../LapisUrlContext';
9
+ import { expectInvalidAttributesErrorMessage } from '../shared/stories/expectErrorMessage';
9
10
 
10
11
  const meta: Meta<TextInputProps> = {
11
12
  title: 'Input/TextInput',
@@ -93,3 +94,16 @@ export const WithInitialValue: StoryObj<TextInputProps> = {
93
94
  });
94
95
  },
95
96
  };
97
+
98
+ export const WithNoLapisField: StoryObj<TextInputProps> = {
99
+ ...Default,
100
+ args: {
101
+ ...Default.args,
102
+ lapisField: '',
103
+ },
104
+ play: async ({ canvasElement, step }) => {
105
+ step('expect error message', async () => {
106
+ await expectInvalidAttributesErrorMessage(canvasElement, 'String must contain at least 1 character(s)');
107
+ });
108
+ },
109
+ };
@@ -1,5 +1,6 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { useContext, useRef } from 'preact/hooks';
3
+ import z from 'zod';
3
4
 
4
5
  import { fetchAutocompleteList } from './fetchAutocompleteList';
5
6
  import { LapisUrlContext } from '../LapisUrlContext';
@@ -9,21 +10,25 @@ import { NoDataDisplay } from '../components/no-data-display';
9
10
  import { ResizeContainer } from '../components/resize-container';
10
11
  import { useQuery } from '../useQuery';
11
12
 
12
- export interface TextInputInnerProps {
13
- lapisField: string;
14
- placeholderText: string;
15
- initialValue: string;
16
- }
13
+ const textInputInnerPropsSchema = z.object({
14
+ lapisField: z.string().min(1),
15
+ placeholderText: z.string().optional(),
16
+ initialValue: z.string().optional(),
17
+ });
17
18
 
18
- export interface TextInputProps extends TextInputInnerProps {
19
- width: string;
20
- }
19
+ const textInputPropsSchema = textInputInnerPropsSchema.extend({
20
+ width: z.string(),
21
+ });
21
22
 
22
- export const TextInput: FunctionComponent<TextInputProps> = ({ width, ...innerProps }) => {
23
+ export type TextInputInnerProps = z.infer<typeof textInputInnerPropsSchema>;
24
+ export type TextInputProps = z.infer<typeof textInputPropsSchema>;
25
+
26
+ export const TextInput: FunctionComponent<TextInputProps> = (props) => {
27
+ const { width, ...innerProps } = props;
23
28
  const size = { width, height: '3rem' };
24
29
 
25
30
  return (
26
- <ErrorBoundary size={size} layout='horizontal'>
31
+ <ErrorBoundary size={size} layout='horizontal' componentProps={props} schema={textInputPropsSchema}>
27
32
  <ResizeContainer size={size}>
28
33
  <TextInputInner {...innerProps} />
29
34
  </ResizeContainer>
@@ -76,7 +81,7 @@ const TextInputInner: FunctionComponent<TextInputInnerProps> = ({ lapisField, pl
76
81
  <input
77
82
  type='text'
78
83
  class='input input-bordered w-full'
79
- placeholder={placeholderText !== undefined ? placeholderText : lapisField}
84
+ placeholder={placeholderText ?? lapisField}
80
85
  onInput={onInput}
81
86
  ref={inputRef}
82
87
  list={lapisField}
@@ -23,5 +23,13 @@ export function useQuery<Data>(fetchDataCallback: () => Promise<Data>, dependenc
23
23
  // eslint-disable-next-line react-hooks/exhaustive-deps
24
24
  }, [JSON.stringify(dependencies)]);
25
25
 
26
- return { data, error, isLoading };
26
+ if (isLoading) {
27
+ return { isLoading: true } as const;
28
+ }
29
+
30
+ if (error !== null) {
31
+ return { error, isLoading: false as const };
32
+ }
33
+
34
+ return { data: data!, error: null, isLoading: false as const };
27
35
  }
@@ -1,8 +1,9 @@
1
1
  import { FetchAggregatedOperator } from '../operator/FetchAggregatedOperator';
2
2
  import { SortOperator } from '../operator/SortOperator';
3
- import { type InitialSort } from '../preact/aggregatedData/aggregate';
4
3
  import { type LapisFilter } from '../types';
5
4
 
5
+ export type InitialSort = { field: string; direction: 'ascending' | 'descending' };
6
+
6
7
  export type AggregateData = (Record<string, string | null | number | boolean> & {
7
8
  count: number;
8
9
  proportion: number;
@@ -1,3 +1,3 @@
1
1
  @tailwind base;
2
2
  @tailwind components;
3
- @tailwind utilities;
3
+ @tailwind utilities;