@genspectrum/dashboard-components 0.8.1 → 0.8.3

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.
@@ -1,5 +1,5 @@
1
1
  import { type Meta, type StoryObj } from '@storybook/preact';
2
- import { expect, waitFor } from '@storybook/test';
2
+ import { expect, userEvent, waitFor } from '@storybook/test';
3
3
 
4
4
  import { MutationsOverTime, type MutationsOverTimeProps } from './mutations-over-time';
5
5
  import { LAPIS_URL } from '../../constants';
@@ -85,3 +85,73 @@ export const ShowsMessageWhenTooManyMutations: StoryObj<MutationsOverTimeProps>
85
85
  });
86
86
  },
87
87
  };
88
+
89
+ export const ShowsNoDataWhenNoMutationsAreInFilter: StoryObj<MutationsOverTimeProps> = {
90
+ ...Template,
91
+ args: {
92
+ lapisFilter: { dateFrom: '1800-01-01', dateTo: '1800-01-02' },
93
+ sequenceType: 'nucleotide',
94
+ views: ['grid'],
95
+ width: '100%',
96
+ height: '700px',
97
+ granularity: 'year',
98
+ lapisDateField: 'date',
99
+ },
100
+ play: async ({ canvas }) => {
101
+ await waitFor(() => expect(canvas.getByText('No data available.', { exact: false })).toBeVisible(), {
102
+ timeout: 10000,
103
+ });
104
+ },
105
+ };
106
+
107
+ export const ShowsNoDataMessageWhenThereAreNoDatesInFilter: StoryObj<MutationsOverTimeProps> = {
108
+ ...Template,
109
+ args: {
110
+ lapisFilter: { dateFrom: '2345-01-01', dateTo: '2020-01-02' },
111
+ sequenceType: 'nucleotide',
112
+ views: ['grid'],
113
+ width: '100%',
114
+ height: '700px',
115
+ granularity: 'year',
116
+ lapisDateField: 'date',
117
+ },
118
+ play: async ({ canvas }) => {
119
+ await waitFor(() => expect(canvas.getByText('No data available.', { exact: false })).toBeVisible(), {
120
+ timeout: 10000,
121
+ });
122
+ },
123
+ };
124
+
125
+ export const ShowsNoDataMessageForStrictFilters: StoryObj<MutationsOverTimeProps> = {
126
+ ...Template,
127
+ args: {
128
+ lapisFilter: { pangoLineage: 'JN.1*', dateFrom: '2024-01-15', dateTo: '2024-07-10' },
129
+ sequenceType: 'nucleotide',
130
+ views: ['grid'],
131
+ width: '100%',
132
+ height: '700px',
133
+ granularity: 'month',
134
+ lapisDateField: 'date',
135
+ },
136
+ play: async ({ canvas }) => {
137
+ await waitFor(() => expect(canvas.getByText('Grid')).toBeVisible(), { timeout: 10000 });
138
+
139
+ const button = canvas.getByRole('button', { name: 'Mean proportion 5.0% - 90.0%' });
140
+ await userEvent.click(button);
141
+
142
+ const minInput = canvas.getAllByLabelText('%')[0];
143
+ await userEvent.clear(minInput);
144
+ await userEvent.type(minInput, '40');
145
+
146
+ const maxInput = canvas.getAllByLabelText('%')[1];
147
+ await userEvent.clear(maxInput);
148
+ await userEvent.type(maxInput, '41');
149
+
150
+ await waitFor(
151
+ () => expect(canvas.getByText('No data available for your filters.', { exact: false })).toBeVisible(),
152
+ {
153
+ timeout: 10000,
154
+ },
155
+ );
156
+ },
157
+ };
@@ -87,7 +87,7 @@ export const MutationsOverTimeInner: FunctionComponent<MutationsOverTimeProps> =
87
87
  throw error;
88
88
  }
89
89
 
90
- if (data === null || data === undefined) {
90
+ if (data === null || data === undefined || data.overallMutationData.length === 0) {
91
91
  return <NoDataDisplay />;
92
92
  }
93
93
 
@@ -231,8 +231,14 @@ const MutationsOverTimeInfo: FunctionComponent<MutationsOverTimeInfoProps> = ({
231
231
  const lapis = useContext(LapisUrlContext);
232
232
  return (
233
233
  <Info>
234
- <InfoHeadline1>Info for mutations over time</InfoHeadline1>
235
- <InfoParagraph>TODO: https://github.com/GenSpectrum/dashboard-components/issues/441</InfoParagraph>
234
+ <InfoHeadline1>Mutations over time</InfoHeadline1>
235
+ <InfoParagraph>
236
+ This presents the proportions of {originalComponentProps.sequenceType} mutations per{' '}
237
+ {originalComponentProps.granularity}. In the toolbar, you can configure which mutations are displayed by
238
+ selecting the mutation type (substitution or deletion), choosing specific segments/genes (if the
239
+ organism has multiple segments/genes), and applying a filter based on the proportion of the mutation's
240
+ occurrence over the entire time range.
241
+ </InfoParagraph>
236
242
  <InfoComponentCode componentName='mutations-over-time' params={originalComponentProps} lapisUrl={lapis} />
237
243
  </Info>
238
244
  );
@@ -719,6 +719,36 @@ describe('queryMutationsOverTime', () => {
719
719
  expect(dates[1].dateString).toBe('2023-02');
720
720
  });
721
721
 
722
+ it('should return empty data when there are no dates in filter', async () => {
723
+ const lapisFilter = { field1: 'value1', field2: 'value2' };
724
+ const dateField = 'dateField';
725
+
726
+ lapisRequestMocks.multipleAggregated([
727
+ {
728
+ body: { ...lapisFilter, fields: [dateField] },
729
+ response: {
730
+ data: [],
731
+ },
732
+ },
733
+ ]);
734
+
735
+ const { mutationOverTimeData } = await queryMutationsOverTimeData({
736
+ lapisFilter,
737
+ sequenceType: 'nucleotide',
738
+ lapis: DUMMY_LAPIS_URL,
739
+ lapisDateField: dateField,
740
+ granularity: 'month',
741
+ });
742
+
743
+ expect(mutationOverTimeData.getAsArray({ count: 0, proportion: 0, totalCount: 0 })).to.deep.equal([]);
744
+
745
+ const sequences = mutationOverTimeData.getFirstAxisKeys();
746
+ expect(sequences.length).toBe(0);
747
+
748
+ const dates = mutationOverTimeData.getSecondAxisKeys();
749
+ expect(dates.length).toBe(0);
750
+ });
751
+
722
752
  function getSomeTestMutation(proportion: number, count: number) {
723
753
  return {
724
754
  mutation: 'sequenceName:A123T',
@@ -66,6 +66,13 @@ export async function queryOverallMutationData({
66
66
  signal?: AbortSignal;
67
67
  }) {
68
68
  const allDates = await getDatesInDataset(lapisFilter, lapis, granularity, lapisDateField, signal);
69
+
70
+ if (allDates.length === 0) {
71
+ return {
72
+ content: [],
73
+ };
74
+ }
75
+
69
76
  const filter = {
70
77
  ...lapisFilter,
71
78
  [`${lapisDateField}From`]: allDates[0].firstDay.toString(),
@@ -18,8 +18,8 @@ import { PreactLitAdapterWithGridJsStyles } from '../PreactLitAdapterWithGridJsS
18
18
  *
19
19
  * The grid view shows the proportion for each mutation over date ranges.
20
20
  *
21
- * The grid limits the number of rows columns for browser performance reasons.
22
- * Too much data might make the browser unresponsive.
21
+ * The grid limits the number of rows and columns for browser performance reasons as
22
+ * too much data might make the browser unresponsive.
23
23
  *
24
24
  * The number of columns is limited to 200.
25
25
  * If this number are exceeded, an error message will be shown.