@genspectrum/dashboard-components 0.10.0 → 0.10.2

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 (59) hide show
  1. package/custom-elements.json +186 -23
  2. package/dist/assets/{mutationOverTimeWorker-CvZg52rf.js.map → mutationOverTimeWorker-Di6yP1e6.js.map} +1 -1
  3. package/dist/components.d.ts +95 -45
  4. package/dist/components.js +402 -182
  5. package/dist/components.js.map +1 -1
  6. package/dist/{utilEntrypoint-g4DsyhU7.js → dateRangeOption-du8H7LWu.js} +33 -2
  7. package/dist/dateRangeOption-du8H7LWu.js.map +1 -0
  8. package/dist/style.css +41 -0
  9. package/dist/util.d.ts +114 -56
  10. package/dist/util.js +3 -2
  11. package/package.json +2 -2
  12. package/src/preact/components/color-scale-selector.tsx +7 -3
  13. package/src/preact/components/error-boundary.tsx +39 -5
  14. package/src/preact/components/error-display.tsx +40 -5
  15. package/src/preact/components/min-max-range-slider.tsx +4 -4
  16. package/src/preact/components/percent-intput.tsx +2 -2
  17. package/src/preact/dateRangeSelector/computeInitialValues.spec.ts +8 -2
  18. package/src/preact/dateRangeSelector/computeInitialValues.ts +6 -0
  19. package/src/preact/dateRangeSelector/date-range-selector.stories.tsx +16 -2
  20. package/src/preact/dateRangeSelector/date-range-selector.tsx +20 -15
  21. package/src/preact/dateRangeSelector/dateRangeOption.ts +10 -5
  22. package/src/preact/lineageFilter/lineage-filter.stories.tsx +18 -4
  23. package/src/preact/lineageFilter/lineage-filter.tsx +15 -10
  24. package/src/preact/locationFilter/location-filter.stories.tsx +14 -0
  25. package/src/preact/locationFilter/location-filter.tsx +15 -10
  26. package/src/preact/mutationComparison/mutation-comparison-venn.tsx +17 -18
  27. package/src/preact/mutationComparison/mutation-comparison.tsx +18 -12
  28. package/src/preact/mutationFilter/mutation-filter.tsx +0 -1
  29. package/src/preact/mutationsOverTime/__mockData__/aminoAcidMutationsByDay.ts +1326 -9341
  30. package/src/preact/mutationsOverTime/__mockData__/byWeek.ts +615 -4920
  31. package/src/preact/mutationsOverTime/__mockData__/defaultMockData.ts +2203 -17624
  32. package/src/preact/mutationsOverTime/mutations-over-time-grid.tsx +16 -8
  33. package/src/preact/mutationsOverTime/mutations-over-time.tsx +1 -3
  34. package/src/preact/shared/stories/expectInvalidAttributesErrorMessage.ts +13 -0
  35. package/src/preact/statistic/__mockData__/denominator.json +13 -0
  36. package/src/preact/statistic/__mockData__/numerator.json +13 -0
  37. package/src/preact/statistic/statistics.stories.tsx +81 -0
  38. package/src/preact/statistic/statistics.tsx +78 -0
  39. package/src/preact/webWorkers/useWebWorker.ts +8 -4
  40. package/src/query/queryGeneralStatistics.ts +18 -0
  41. package/src/query/queryMutationsOverTime.spec.ts +12 -27
  42. package/src/query/queryMutationsOverTime.ts +2 -6
  43. package/src/types.ts +19 -6
  44. package/src/utilEntrypoint.ts +8 -0
  45. package/src/utils/map2d.spec.ts +10 -10
  46. package/src/utils/map2d.ts +10 -10
  47. package/src/web-components/input/gs-date-range-selector.stories.ts +2 -2
  48. package/src/web-components/input/gs-date-range-selector.tsx +3 -3
  49. package/src/web-components/input/gs-lineage-filter.tsx +1 -1
  50. package/src/web-components/input/gs-location-filter.tsx +2 -2
  51. package/src/web-components/visualization/gs-aggregate.tsx +2 -2
  52. package/src/web-components/visualization/gs-statistics.stories.ts +95 -0
  53. package/src/web-components/visualization/gs-statistics.tsx +83 -0
  54. package/src/web-components/visualization/index.ts +1 -0
  55. package/standalone-bundle/assets/{mutationOverTimeWorker-CypX_PYM.js.map → mutationOverTimeWorker-cIyshfj_.js.map} +1 -1
  56. package/standalone-bundle/dashboard-components.js +7747 -7592
  57. package/standalone-bundle/dashboard-components.js.map +1 -1
  58. package/standalone-bundle/style.css +1 -1
  59. package/dist/utilEntrypoint-g4DsyhU7.js.map +0 -1
@@ -75,8 +75,8 @@ export const MinMaxRangeSlider: FunctionComponent<MinMaxPercentSliderProps> = ({
75
75
  type='range'
76
76
  value={min}
77
77
  onInput={onMinChange}
78
- min={rangeMin}
79
- max={rangeMax}
78
+ min={`${rangeMin}`}
79
+ max={`${rangeMax}`}
80
80
  step={step}
81
81
  style={{ background, zIndex: 1, height: 0 }}
82
82
  />
@@ -84,8 +84,8 @@ export const MinMaxRangeSlider: FunctionComponent<MinMaxPercentSliderProps> = ({
84
84
  id='toSlider'
85
85
  type='range'
86
86
  value={max}
87
- min={rangeMin}
88
- max={rangeMax}
87
+ min={`${rangeMin}`}
88
+ max={`${rangeMax}`}
89
89
  step={step}
90
90
  onInput={onMaxChange}
91
91
  style={{ background, zIndex: zIndexTo }}
@@ -44,8 +44,8 @@ export const PercentInput: FunctionComponent<PercentInputProps> = ({
44
44
  <input
45
45
  type='number'
46
46
  step={0.1}
47
- min={0}
48
- max={100}
47
+ min='0'
48
+ max='100'
49
49
  value={internalPercentage}
50
50
  onInput={handleInputChange}
51
51
  lang='en'
@@ -50,9 +50,15 @@ describe('computeInitialValues', () => {
50
50
  expectDateMatches(result.initialSelectedDateTo, today);
51
51
  });
52
52
 
53
- it('should fall back to default when initial value is unknown', () => {
53
+ it('should throw when initial value is unknown', () => {
54
+ expect(() =>
55
+ computeInitialValues('not a known value', undefined, undefined, earliestDate, dateRangeOptions),
56
+ ).toThrowError(/Invalid initialValue "not a known value", It must be one of/);
57
+ });
58
+
59
+ it('should throw when initial value is set but no options are provided', () => {
54
60
  expect(() => computeInitialValues('not a known value', undefined, undefined, earliestDate, [])).toThrowError(
55
- /Invalid initialValue "not a known value", It must be one of/,
61
+ /There are no selectable options/,
56
62
  );
57
63
  });
58
64
 
@@ -18,6 +18,12 @@ export function computeInitialValues(
18
18
  const initialSelectedDateRange = selectableOptions.find((option) => option.value === initialValue)?.value;
19
19
 
20
20
  if (initialValue !== undefined && initialSelectedDateRange === undefined) {
21
+ if (selectableOptions.length === 0) {
22
+ throw new UserFacingError(
23
+ 'Invalid initialValue',
24
+ 'There are no selectable options, but initialValue is set.',
25
+ );
26
+ }
21
27
  throw new UserFacingError(
22
28
  'Invalid initialValue',
23
29
  `Invalid initialValue "${initialValue}", It must be one of ${selectableOptions.map((option) => `'${option.value}'`).join(', ')}`,
@@ -8,6 +8,7 @@ import { previewHandles } from '../../../.storybook/preview';
8
8
  import { LAPIS_URL } from '../../constants';
9
9
  import { LapisUrlContext } from '../LapisUrlContext';
10
10
  import { dateRangeOptionPresets } from './dateRangeOption';
11
+ import { expectInvalidAttributesErrorMessage } from '../shared/stories/expectInvalidAttributesErrorMessage';
11
12
 
12
13
  const earliestDate = '1970-01-01';
13
14
 
@@ -55,8 +56,8 @@ const meta: Meta<DateRangeSelectorProps> = {
55
56
  initialValue: dateRangeOptionPresets.lastMonth.label,
56
57
  dateColumn: 'aDateColumn',
57
58
  width: '100%',
58
- initialDateFrom: '',
59
- initialDateTo: '',
59
+ initialDateFrom: undefined,
60
+ initialDateTo: undefined,
60
61
  },
61
62
  };
62
63
 
@@ -221,6 +222,19 @@ export const HandlesInvalidInitialDateFrom: StoryObj<DateRangeSelectorProps> = {
221
222
  },
222
223
  };
223
224
 
225
+ export const WithNoDateColumn: StoryObj<DateRangeSelectorProps> = {
226
+ ...Primary,
227
+ args: {
228
+ ...Primary.args,
229
+ dateColumn: '',
230
+ },
231
+ play: async ({ canvasElement, step }) => {
232
+ step('expect error message', async () => {
233
+ await expectInvalidAttributesErrorMessage(canvasElement, 'String must contain at least 1 character(s)');
234
+ });
235
+ },
236
+ };
237
+
224
238
  async function prepare(canvasElement: HTMLElement, step: StepFunction<PreactRenderer, unknown>) {
225
239
  const canvas = within(canvasElement);
226
240
 
@@ -1,10 +1,11 @@
1
1
  import flatpickr from 'flatpickr';
2
2
  import 'flatpickr/dist/flatpickr.min.css';
3
3
  import { useEffect, useRef, useState } from 'preact/hooks';
4
+ import z from 'zod';
4
5
 
5
6
  import { computeInitialValues } from './computeInitialValues';
6
7
  import { toYYYYMMDD } from './dateConversion';
7
- import { type DateRangeOption, DateRangeOptionChangedEvent, type DateRangeSelectOption } from './dateRangeOption';
8
+ import { DateRangeOptionChangedEvent, dateRangeOptionSchema, type DateRangeSelectOption } from './dateRangeOption';
8
9
  import { getDatesForSelectorValue, getSelectableOptions } from './selectableOptions';
9
10
  import { ErrorBoundary } from '../components/error-boundary';
10
11
  import { Select } from '../components/select';
@@ -12,24 +13,28 @@ import type { ScaleType } from '../shared/charts/getYAxisScale';
12
13
 
13
14
  const customOption = 'Custom';
14
15
 
15
- export interface DateRangeSelectorProps extends DateRangeSelectorPropsInner {
16
- width: string;
17
- }
16
+ const dateRangeSelectorInnerPropsSchema = z.object({
17
+ dateRangeOptions: z.array(dateRangeOptionSchema),
18
+ earliestDate: z.string().date(),
19
+ initialValue: z.string().optional(),
20
+ initialDateFrom: z.string().date().optional(),
21
+ initialDateTo: z.string().date().optional(),
22
+ dateColumn: z.string().min(1),
23
+ });
18
24
 
19
- export interface DateRangeSelectorPropsInner {
20
- dateRangeOptions: DateRangeOption[];
21
- earliestDate: string;
22
- initialValue: string | undefined;
23
- initialDateFrom: string;
24
- initialDateTo: string;
25
- dateColumn: string;
26
- }
25
+ const dateRangeSelectorPropsSchema = dateRangeSelectorInnerPropsSchema.extend({
26
+ width: z.string(),
27
+ });
27
28
 
28
- export const DateRangeSelector = ({ width, ...innerProps }: DateRangeSelectorProps) => {
29
+ export type DateRangeSelectorProps = z.infer<typeof dateRangeSelectorPropsSchema>;
30
+ export type DateRangeSelectorInnerProps = z.infer<typeof dateRangeSelectorInnerPropsSchema>;
31
+
32
+ export const DateRangeSelector = (props: DateRangeSelectorProps) => {
33
+ const { width, ...innerProps } = props;
29
34
  const size = { width, height: '3rem' };
30
35
 
31
36
  return (
32
- <ErrorBoundary size={size} layout='horizontal'>
37
+ <ErrorBoundary size={size} layout='horizontal' componentProps={props} schema={dateRangeSelectorPropsSchema}>
33
38
  <div style={{ width }}>
34
39
  <DateRangeSelectorInner {...innerProps} />
35
40
  </div>
@@ -44,7 +49,7 @@ export const DateRangeSelectorInner = ({
44
49
  dateColumn,
45
50
  initialDateFrom,
46
51
  initialDateTo,
47
- }: DateRangeSelectorPropsInner) => {
52
+ }: DateRangeSelectorInnerProps) => {
48
53
  const initialValues = computeInitialValues(
49
54
  initialValue,
50
55
  initialDateFrom,
@@ -1,24 +1,29 @@
1
+ import z from 'zod';
2
+
1
3
  import { toYYYYMMDD } from './dateConversion';
2
4
 
3
5
  /**
4
6
  * A date range option that can be used in the `gs-date-range-selector` component.
5
7
  */
6
- export type DateRangeOption = {
8
+ export const dateRangeOptionSchema = z.object({
7
9
  /** The label of the date range option that will be shown to the user */
8
- label: string;
10
+ label: z.string(),
9
11
  /**
10
12
  * The start date of the date range in the format `YYYY-MM-DD`.
11
13
  * If not set, the date range selector will default to the `earliestDate` property.
12
14
  */
13
- dateFrom?: string;
15
+ dateFrom: z.string().date().optional(),
14
16
  /**
15
17
  * The end date of the date range in the format `YYYY-MM-DD`.
16
18
  * If not set, the date range selector will default to the current date.
17
19
  */
18
- dateTo?: string;
19
- };
20
+ dateTo: z.string().date().optional(),
21
+ });
22
+
23
+ export type DateRangeOption = z.infer<typeof dateRangeOptionSchema>;
20
24
 
21
25
  export type DateRangeSelectOption = string | { dateFrom: string; dateTo: string };
26
+
22
27
  export class DateRangeOptionChangedEvent extends CustomEvent<DateRangeSelectOption> {
23
28
  constructor(detail: DateRangeSelectOption) {
24
29
  super('gs-date-range-option-changed', {
@@ -5,6 +5,7 @@ import { previewHandles } from '../../../.storybook/preview';
5
5
  import { AGGREGATED_ENDPOINT, LAPIS_URL } from '../../constants';
6
6
  import aggregatedData from '../../preact/lineageFilter/__mockData__/aggregated.json';
7
7
  import { LapisUrlContext } from '../LapisUrlContext';
8
+ import { expectInvalidAttributesErrorMessage } from '../shared/stories/expectInvalidAttributesErrorMessage';
8
9
 
9
10
  const meta: Meta = {
10
11
  title: 'Input/LineageFilter',
@@ -31,6 +32,12 @@ const meta: Meta = {
31
32
  ],
32
33
  },
33
34
  },
35
+ args: {
36
+ lapisField: 'pangoLineage',
37
+ placeholderText: 'Enter lineage',
38
+ initialValue: '',
39
+ width: '100%',
40
+ },
34
41
  };
35
42
 
36
43
  export default meta;
@@ -46,10 +53,17 @@ export const Default: StoryObj<LineageFilterProps> = {
46
53
  />
47
54
  </LapisUrlContext.Provider>
48
55
  ),
56
+ };
57
+
58
+ export const WithNoLapisField: StoryObj<LineageFilterProps> = {
59
+ ...Default,
49
60
  args: {
50
- lapisField: 'pangoLineage',
51
- placeholderText: 'Enter lineage',
52
- initialValue: '',
53
- width: '100%',
61
+ ...Default.args,
62
+ lapisField: '',
63
+ },
64
+ play: async ({ canvasElement, step }) => {
65
+ step('expect error message', async () => {
66
+ await expectInvalidAttributesErrorMessage(canvasElement, 'String must contain at least 1 character(s)');
67
+ });
54
68
  },
55
69
  };
@@ -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 { fetchLineageAutocompleteList } from './fetchLineageAutocompleteList';
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 LineageFilterInnerProps {
13
- lapisField: string;
14
- placeholderText: string;
15
- initialValue: string;
16
- }
13
+ const lineageFilterInnerPropsSchema = z.object({
14
+ lapisField: z.string().min(1),
15
+ placeholderText: z.string().optional(),
16
+ initialValue: z.string(),
17
+ });
17
18
 
18
- export interface LineageFilterProps extends LineageFilterInnerProps {
19
- width: string;
20
- }
19
+ const lineageFilterPropsSchema = lineageFilterInnerPropsSchema.extend({
20
+ width: z.string(),
21
+ });
21
22
 
22
- export const LineageFilter: FunctionComponent<LineageFilterProps> = ({ width, ...innerProps }) => {
23
+ export type LineageFilterInnerProps = z.infer<typeof lineageFilterInnerPropsSchema>;
24
+ export type LineageFilterProps = z.infer<typeof lineageFilterPropsSchema>;
25
+
26
+ export const LineageFilter: FunctionComponent<LineageFilterProps> = (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={lineageFilterPropsSchema}>
27
32
  <ResizeContainer size={size}>
28
33
  <LineageFilterInner {...innerProps} />
29
34
  </ResizeContainer>
@@ -5,6 +5,7 @@ import { LocationFilter, type LocationFilterProps } from './location-filter';
5
5
  import { previewHandles } from '../../../.storybook/preview';
6
6
  import { AGGREGATED_ENDPOINT, LAPIS_URL } from '../../constants';
7
7
  import { LapisUrlContext } from '../LapisUrlContext';
8
+ import { expectInvalidAttributesErrorMessage } from '../shared/stories/expectInvalidAttributesErrorMessage';
8
9
 
9
10
  const meta: Meta<LocationFilterProps> = {
10
11
  title: 'Input/LocationFilter',
@@ -75,3 +76,16 @@ export const Primary: StoryObj<LocationFilterProps> = {
75
76
  </LapisUrlContext.Provider>
76
77
  ),
77
78
  };
79
+
80
+ export const WithNoFields: StoryObj<LocationFilterProps> = {
81
+ ...Primary,
82
+ args: {
83
+ ...Primary.args,
84
+ fields: [],
85
+ },
86
+ play: async ({ canvasElement, step }) => {
87
+ step('expect error message', async () => {
88
+ await expectInvalidAttributesErrorMessage(canvasElement, 'Array must contain at least 1 element(s)');
89
+ });
90
+ },
91
+ };
@@ -1,6 +1,7 @@
1
1
  import { type FunctionComponent } from 'preact';
2
2
  import { useContext, useRef, useState } from 'preact/hooks';
3
3
  import { type JSXInternal } from 'preact/src/jsx';
4
+ import z from 'zod';
4
5
 
5
6
  import { fetchAutocompletionList } from './fetchAutocompletionList';
6
7
  import { LapisUrlContext } from '../LapisUrlContext';
@@ -9,21 +10,25 @@ import { LoadingDisplay } from '../components/loading-display';
9
10
  import { ResizeContainer } from '../components/resize-container';
10
11
  import { useQuery } from '../useQuery';
11
12
 
12
- export interface LocationFilterInnerProps {
13
- initialValue: string;
14
- placeholderText: string;
15
- fields: string[];
16
- }
13
+ const lineageFilterInnerPropsSchema = z.object({
14
+ initialValue: z.string().optional(),
15
+ placeholderText: z.string().optional(),
16
+ fields: z.array(z.string()).min(1),
17
+ });
17
18
 
18
- export interface LocationFilterProps extends LocationFilterInnerProps {
19
- width: string;
20
- }
19
+ const lineageFilterPropsSchema = lineageFilterInnerPropsSchema.extend({
20
+ width: z.string(),
21
+ });
21
22
 
22
- export const LocationFilter: FunctionComponent<LocationFilterProps> = ({ width, ...innerProps }) => {
23
+ export type LocationFilterInnerProps = z.infer<typeof lineageFilterInnerPropsSchema>;
24
+ export type LocationFilterProps = z.infer<typeof lineageFilterPropsSchema>;
25
+
26
+ export const LocationFilter: FunctionComponent<LocationFilterProps> = (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={lineageFilterPropsSchema}>
27
32
  <ResizeContainer size={size}>
28
33
  <LocationFilterInner {...innerProps} />
29
34
  </ResizeContainer>
@@ -1,7 +1,7 @@
1
1
  import { type ActiveElement, Chart, type ChartConfiguration, type ChartEvent, registerables } from 'chart.js';
2
2
  import { ArcSlice, extractSets, VennDiagramController } from 'chartjs-chart-venn';
3
3
  import { type FunctionComponent } from 'preact';
4
- import { useEffect, useMemo, useRef, useState } from 'preact/hooks';
4
+ import { useMemo, useState } from 'preact/hooks';
5
5
 
6
6
  import { type MutationData } from './queryMutationData';
7
7
  import { type Dataset } from '../../operator/Dataset';
@@ -19,8 +19,6 @@ export const MutationComparisonVenn: FunctionComponent<MutationComparisonVennPro
19
19
  data,
20
20
  proportionInterval,
21
21
  }) => {
22
- const divRef = useRef<HTMLDivElement>(null);
23
- const noElementSelectedMessage = 'You have no elements selected. Click in the venn diagram to select.';
24
22
  const [selectedDatasetIndex, setSelectedDatasetIndex] = useState<null | number>(null);
25
23
 
26
24
  const sets = useMemo(
@@ -45,20 +43,6 @@ export const MutationComparisonVenn: FunctionComponent<MutationComparisonVennPro
45
43
  [data, proportionInterval],
46
44
  );
47
45
 
48
- useEffect(() => {
49
- if (divRef.current === null) {
50
- return;
51
- }
52
- if (selectedDatasetIndex === null) {
53
- divRef.current.innerText = noElementSelectedMessage;
54
- return;
55
- }
56
-
57
- const values = sets.datasets[0].data[selectedDatasetIndex].values;
58
- const label = sets.datasets[0].data[selectedDatasetIndex].label;
59
- divRef.current!.innerText = `${label}: ${values.join(', ')}` || '';
60
- }, [divRef, selectedDatasetIndex, sets]);
61
-
62
46
  const config: ChartConfiguration = useMemo(
63
47
  () => ({
64
48
  type: 'venn',
@@ -119,7 +103,22 @@ export const MutationComparisonVenn: FunctionComponent<MutationComparisonVennPro
119
103
  <div className='flex-1'>
120
104
  <GsChart configuration={config} />
121
105
  </div>
122
- <div class='flex flex-wrap break-words m-2' ref={divRef} />
106
+ <p class='flex flex-wrap break-words m-2'>{getSelectedMutationsDescription(selectedDatasetIndex, sets)}</p>
123
107
  </div>
124
108
  );
125
109
  };
110
+
111
+ const noElementSelectedMessage = 'You have no elements selected. Click in the venn diagram to select.';
112
+
113
+ function getSelectedMutationsDescription(
114
+ selectedDatasetIndex: number | null,
115
+ sets: ReturnType<typeof extractSets<string>>,
116
+ ) {
117
+ if (selectedDatasetIndex === null) {
118
+ return noElementSelectedMessage;
119
+ }
120
+
121
+ const values = sets.datasets[0].data[selectedDatasetIndex].values;
122
+ const label = sets.datasets[0].data[selectedDatasetIndex].label;
123
+ return `${label}: ${values.join(', ')}` || '';
124
+ }
@@ -1,11 +1,17 @@
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
  import { getMutationComparisonTableData } from './getMutationComparisonTableData';
5
6
  import { MutationComparisonTable } from './mutation-comparison-table';
6
7
  import { MutationComparisonVenn } from './mutation-comparison-venn';
7
8
  import { filterMutationData, type MutationData, queryMutationData } from './queryMutationData';
8
- import { type NamedLapisFilter, type SequenceType } from '../../types';
9
+ import {
10
+ type MutationComparisonView,
11
+ mutationComparisonViewSchema,
12
+ namedLapisFilterSchema,
13
+ sequenceTypeSchema,
14
+ } from '../../types';
9
15
  import { LapisUrlContext } from '../LapisUrlContext';
10
16
  import { CsvDownloadButton } from '../components/csv-download-button';
11
17
  import { ErrorBoundary } from '../components/error-boundary';
@@ -21,23 +27,23 @@ import { type DisplayedSegment, SegmentSelector, useDisplayedSegments } from '..
21
27
  import Tabs from '../components/tabs';
22
28
  import { useQuery } from '../useQuery';
23
29
 
24
- export type View = 'table' | 'venn';
30
+ const mutationComparisonPropsSchema = z.object({
31
+ width: z.string(),
32
+ height: z.string(),
33
+ lapisFilters: z.array(namedLapisFilterSchema).min(1),
34
+ sequenceType: sequenceTypeSchema,
35
+ views: z.array(mutationComparisonViewSchema),
36
+ pageSize: z.union([z.boolean(), z.number()]),
37
+ });
25
38
 
26
- export interface MutationComparisonProps {
27
- width: string;
28
- height: string;
29
- lapisFilters: NamedLapisFilter[];
30
- sequenceType: SequenceType;
31
- views: View[];
32
- pageSize: boolean | number;
33
- }
39
+ export type MutationComparisonProps = z.infer<typeof mutationComparisonPropsSchema>;
34
40
 
35
41
  export const MutationComparison: FunctionComponent<MutationComparisonProps> = (componentProps) => {
36
42
  const { width, height } = componentProps;
37
43
  const size = { height, width };
38
44
 
39
45
  return (
40
- <ErrorBoundary size={size}>
46
+ <ErrorBoundary size={size} componentProps={componentProps} schema={mutationComparisonPropsSchema}>
41
47
  <ResizeContainer size={size}>
42
48
  <MutationComparisonInner {...componentProps} />
43
49
  </ResizeContainer>
@@ -86,7 +92,7 @@ const MutationComparisonTabs: FunctionComponent<MutationComparisonTabsProps> = (
86
92
  [data, displayedSegments, displayedMutationTypes],
87
93
  );
88
94
 
89
- const getTab = (view: View) => {
95
+ const getTab = (view: MutationComparisonView) => {
90
96
  switch (view) {
91
97
  case 'table':
92
98
  return {
@@ -303,7 +303,6 @@ const SelectedFilter = ({ handleRemoveValue, mutationFilter }: SelectedFilterPro
303
303
  return (
304
304
  <span
305
305
  key={mutationFilter.value.toString()}
306
- name={mutationFilter.value.toString()}
307
306
  className='center p-2 m-1 inline-flex text-black rounded-md'
308
307
  style={{
309
308
  backgroundColor: backgroundColorMap(mutationFilter),