@genspectrum/dashboard-components 0.7.2 → 0.8.0

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.
@@ -450,16 +450,6 @@ export declare class MutationComparisonComponent extends PreactLitAdapterWithGri
450
450
  * Fired when:
451
451
  * - The user has submitted a valid mutation or insertion
452
452
  * - The user has removed a mutation or insertion
453
- *
454
- * @fires {CustomEvent<{
455
- * nucleotideMutations: string[],
456
- * aminoAcidMutations: string[],
457
- * nucleotideInsertions: string[],
458
- * aminoAcidInsertions: string[]
459
- * }>} gs-mutation-filter-on-blur
460
- * Fired when:
461
- * - the mutation filter has lost focus
462
- * Contains the selected mutations in the format
463
453
  */
464
454
  export declare class MutationFilterComponent extends PreactLitAdapter {
465
455
  /**
@@ -1212,7 +1202,6 @@ declare global {
1212
1202
  }
1213
1203
  interface HTMLElementEventMap {
1214
1204
  'gs-mutation-filter-changed': CustomEvent<SelectedMutationFilterStrings>;
1215
- 'gs-mutation-filter-on-blur': CustomEvent<SelectedMutationFilterStrings>;
1216
1205
  }
1217
1206
  }
1218
1207
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genspectrum/dashboard-components",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "GenSpectrum web components for building dashboards",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
@@ -14,7 +14,7 @@ const meta: Meta<MutationFilterProps> = {
14
14
  component: MutationFilter,
15
15
  parameters: {
16
16
  actions: {
17
- handles: ['gs-mutation-filter-changed', 'gs-mutation-filter-on-blur', ...previewHandles],
17
+ handles: ['gs-mutation-filter-changed', ...previewHandles],
18
18
  },
19
19
  fetchMock: {},
20
20
  },
@@ -120,32 +120,6 @@ export const FiresFilterChangedEvents: StoryObj<MutationFilterProps> = {
120
120
  },
121
121
  };
122
122
 
123
- export const FiresFilterOnBlurEvent: StoryObj<MutationFilterProps> = {
124
- ...Default,
125
- play: async ({ canvasElement, step }) => {
126
- const { canvas, onBlurListenerMock } = await prepare(canvasElement, step);
127
-
128
- await step('Move outside of input', async () => {
129
- await submitMutation(canvas, 'A234T');
130
- await submitMutation(canvas, 'S:A123G');
131
- await submitMutation(canvas, 'ins_123:AAA');
132
- await submitMutation(canvas, 'ins_S:123:AAA');
133
- await userEvent.tab();
134
-
135
- await expect(onBlurListenerMock).toHaveBeenCalledWith(
136
- expect.objectContaining({
137
- detail: {
138
- nucleotideMutations: ['A234T'],
139
- aminoAcidMutations: ['S:A123G'],
140
- nucleotideInsertions: ['ins_123:AAA'],
141
- aminoAcidInsertions: ['ins_S:123:AAA'],
142
- },
143
- }),
144
- );
145
- });
146
- },
147
- };
148
-
149
123
  export const WithInitialValue: StoryObj<MutationFilterProps> = {
150
124
  render: (args) => (
151
125
  <LapisUrlContext.Provider value={LAPIS_URL}>
@@ -164,13 +138,12 @@ export const WithInitialValue: StoryObj<MutationFilterProps> = {
164
138
  width: '100%',
165
139
  },
166
140
  play: async ({ canvasElement, step }) => {
167
- const { canvas, onBlurListenerMock } = await prepare(canvasElement, step);
141
+ const { canvas, changedListenerMock } = await prepare(canvasElement, step);
168
142
 
169
- await step('Move outside of input', async () => {
143
+ await step('Enter additional input', async () => {
170
144
  await submitMutation(canvas, 'G500T');
171
- await userEvent.tab();
172
145
 
173
- await expect(onBlurListenerMock).toHaveBeenCalledWith(
146
+ await expect(changedListenerMock).toHaveBeenCalledWith(
174
147
  expect.objectContaining({
175
148
  detail: {
176
149
  nucleotideMutations: ['A234T', 'G500T'],
@@ -187,10 +160,8 @@ export const WithInitialValue: StoryObj<MutationFilterProps> = {
187
160
  async function prepare(canvasElement: HTMLElement, step: StepFunction<PreactRenderer, unknown>) {
188
161
  const canvas = within(canvasElement);
189
162
 
190
- const onBlurListenerMock = fn();
191
163
  const changedListenerMock = fn();
192
164
  await step('Setup event listener mock', async () => {
193
- canvasElement.addEventListener('gs-mutation-filter-on-blur', onBlurListenerMock);
194
165
  canvasElement.addEventListener('gs-mutation-filter-changed', changedListenerMock);
195
166
  });
196
167
 
@@ -200,7 +171,7 @@ async function prepare(canvasElement: HTMLElement, step: StepFunction<PreactRend
200
171
  });
201
172
  });
202
173
 
203
- return { canvas, onBlurListenerMock, changedListenerMock };
174
+ return { canvas, changedListenerMock };
204
175
  }
205
176
 
206
177
  const submitMutation = async (canvas: ReturnType<typeof within>, mutation: string) => {
@@ -87,18 +87,6 @@ export const MutationFilterInner: FunctionComponent<MutationFilterInnerProps> =
87
87
  );
88
88
  };
89
89
 
90
- const handleOnBlur = () => {
91
- const detail = mapToMutationFilterStrings(selectedFilters);
92
-
93
- formRef.current?.dispatchEvent(
94
- new CustomEvent<SelectedMutationFilterStrings>('gs-mutation-filter-on-blur', {
95
- detail,
96
- bubbles: true,
97
- composed: true,
98
- }),
99
- );
100
- };
101
-
102
90
  const handleInputChange = (event: Event) => {
103
91
  setInputValue((event.target as HTMLInputElement).value);
104
92
  setIsError(false);
@@ -124,7 +112,6 @@ export const MutationFilterInner: FunctionComponent<MutationFilterInnerProps> =
124
112
  value={inputValue}
125
113
  onInput={handleInputChange}
126
114
  placeholder={getPlaceholder(referenceGenome)}
127
- onBlur={handleOnBlur}
128
115
  />
129
116
  <button type='submit' className='btn btn-xs m-1'>
130
117
  +
@@ -63,15 +63,21 @@ export const MutationsOverTimeInner: FunctionComponent<MutationsOverTimeProps> =
63
63
  const lapis = useContext(LapisUrlContext);
64
64
  const { lapisFilter, sequenceType, granularity, lapisDateField } = componentProps;
65
65
 
66
- const { data, error, isLoading } = useWebWorker<MutationOverTimeQuery, MutationOverTimeWorkerResponse>(
67
- {
66
+ const messageToWorker = useMemo(() => {
67
+ return {
68
68
  lapisFilter,
69
69
  sequenceType,
70
70
  granularity,
71
71
  lapisDateField,
72
72
  lapis,
73
- },
74
- new MutationOverTimeWorker() as Worker,
73
+ };
74
+ }, [granularity, lapis, lapisDateField, lapisFilter, sequenceType]);
75
+
76
+ const worker = useMemo(() => new MutationOverTimeWorker(), []);
77
+
78
+ const { data, error, isLoading } = useWebWorker<MutationOverTimeQuery, MutationOverTimeWorkerResponse>(
79
+ messageToWorker,
80
+ worker,
75
81
  );
76
82
 
77
83
  if (isLoading) {
@@ -1,4 +1,4 @@
1
- import { useEffect, useMemo, useState } from 'preact/hooks';
1
+ import { useEffect, useState } from 'preact/hooks';
2
2
 
3
3
  export function useWebWorker<Request, Response>(messageToWorker: Request, worker: Worker) {
4
4
  const [data, setData] = useState<Response | undefined>(undefined);
@@ -37,15 +37,11 @@ export function useWebWorker<Request, Response>(messageToWorker: Request, worker
37
37
  setError(new Error(`Worker received a message that it cannot deserialize: ${event.data}`));
38
38
  setIsLoading(false);
39
39
  };
40
+ }, [worker]);
40
41
 
41
- return () => {
42
- worker.terminate();
43
- };
44
- }, []);
45
-
46
- useMemo(() => {
42
+ useEffect(() => {
47
43
  worker.postMessage(messageToWorker);
48
- }, [messageToWorker]);
44
+ }, [messageToWorker, worker]);
49
45
 
50
46
  return { data, error, isLoading };
51
47
  }
@@ -21,7 +21,7 @@ const meta: Meta<MutationFilterProps> = {
21
21
  component: 'gs-mutation-filter',
22
22
  parameters: withComponentDocs({
23
23
  actions: {
24
- handles: ['gs-mutation-filter-changed', 'gs-mutation-filter-on-blur', ...previewHandles],
24
+ handles: ['gs-mutation-filter-changed', ...previewHandles],
25
25
  },
26
26
  fetchMock: {},
27
27
  componentDocs: {
@@ -102,32 +102,6 @@ export const FiresFilterChangedEvent: StoryObj<MutationFilterProps> = {
102
102
  },
103
103
  };
104
104
 
105
- export const FiresFilterOnBlurEvent: StoryObj<MutationFilterProps> = {
106
- ...Template,
107
- play: async ({ canvasElement, step }) => {
108
- const canvas = await withinShadowRoot(canvasElement, 'gs-mutation-filter');
109
-
110
- const inputField = () => canvas.getByPlaceholderText('Enter a mutation', { exact: false });
111
- const listenerMock = fn();
112
- await step('Setup event listener mock', async () => {
113
- canvasElement.addEventListener('gs-mutation-filter-on-blur', listenerMock);
114
- });
115
-
116
- await step('wait until data is loaded', async () => {
117
- await waitFor(() => {
118
- return expect(inputField()).toBeEnabled();
119
- });
120
- });
121
-
122
- await step('Move outside of input', async () => {
123
- await userEvent.type(inputField(), 'A123T');
124
- await userEvent.tab();
125
-
126
- await expect(listenerMock).toHaveBeenCalled();
127
- });
128
- },
129
- };
130
-
131
105
  export const MultiSegmentedReferenceGenomes: StoryObj<MutationFilterProps> = {
132
106
  ...Template,
133
107
  args: {
@@ -53,16 +53,6 @@ import { PreactLitAdapter } from '../PreactLitAdapter';
53
53
  * Fired when:
54
54
  * - The user has submitted a valid mutation or insertion
55
55
  * - The user has removed a mutation or insertion
56
- *
57
- * @fires {CustomEvent<{
58
- * nucleotideMutations: string[],
59
- * aminoAcidMutations: string[],
60
- * nucleotideInsertions: string[],
61
- * aminoAcidInsertions: string[]
62
- * }>} gs-mutation-filter-on-blur
63
- * Fired when:
64
- * - the mutation filter has lost focus
65
- * Contains the selected mutations in the format
66
56
  */
67
57
  @customElement('gs-mutation-filter')
68
58
  export class MutationFilterComponent extends PreactLitAdapter {
@@ -108,7 +98,6 @@ declare global {
108
98
 
109
99
  interface HTMLElementEventMap {
110
100
  'gs-mutation-filter-changed': CustomEvent<SelectedMutationFilterStrings>;
111
- 'gs-mutation-filter-on-blur': CustomEvent<SelectedMutationFilterStrings>;
112
101
  }
113
102
  }
114
103