@genspectrum/dashboard-components 0.12.0 → 0.13.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.
Files changed (37) hide show
  1. package/custom-elements.json +117 -28
  2. package/dist/{LocationChangedEvent-CORvQvXv.js → LineageFilterChangedEvent-GedKNGFI.js} +25 -3
  3. package/dist/LineageFilterChangedEvent-GedKNGFI.js.map +1 -0
  4. package/dist/components.d.ts +86 -52
  5. package/dist/components.js +251 -196
  6. package/dist/components.js.map +1 -1
  7. package/dist/util.d.ts +59 -45
  8. package/dist/util.js +3 -1
  9. package/package.json +1 -1
  10. package/src/preact/components/downshift-combobox.tsx +145 -0
  11. package/src/preact/lineageFilter/LineageFilterChangedEvent.ts +11 -0
  12. package/src/preact/lineageFilter/fetchLineageAutocompleteList.spec.ts +16 -2
  13. package/src/preact/lineageFilter/fetchLineageAutocompleteList.ts +13 -2
  14. package/src/preact/lineageFilter/lineage-filter.stories.tsx +110 -9
  15. package/src/preact/lineageFilter/lineage-filter.tsx +40 -50
  16. package/src/preact/locationFilter/LocationChangedEvent.ts +1 -1
  17. package/src/preact/locationFilter/fetchAutocompletionList.spec.ts +6 -2
  18. package/src/preact/locationFilter/fetchAutocompletionList.ts +16 -6
  19. package/src/preact/locationFilter/location-filter.stories.tsx +33 -30
  20. package/src/preact/locationFilter/location-filter.tsx +47 -144
  21. package/src/preact/map/sequences-by-location-map.tsx +3 -3
  22. package/src/preact/textInput/TextInputChangedEvent.ts +11 -0
  23. package/src/preact/textInput/fetchStringAutocompleteList.ts +20 -0
  24. package/src/preact/textInput/text-input.stories.tsx +34 -14
  25. package/src/preact/textInput/text-input.tsx +47 -45
  26. package/src/types.ts +3 -0
  27. package/src/utilEntrypoint.ts +2 -0
  28. package/src/web-components/input/gs-lineage-filter.stories.ts +120 -31
  29. package/src/web-components/input/gs-lineage-filter.tsx +24 -8
  30. package/src/web-components/input/gs-location-filter.stories.ts +9 -0
  31. package/src/web-components/input/gs-location-filter.tsx +21 -3
  32. package/src/web-components/input/gs-text-input.stories.ts +44 -12
  33. package/src/web-components/input/gs-text-input.tsx +23 -7
  34. package/standalone-bundle/dashboard-components.js +4931 -4863
  35. package/standalone-bundle/dashboard-components.js.map +1 -1
  36. package/dist/LocationChangedEvent-CORvQvXv.js.map +0 -1
  37. package/src/preact/textInput/fetchAutocompleteList.ts +0 -9
@@ -1,4 +1,4 @@
1
- import { expect, fn, userEvent, waitFor } from '@storybook/test';
1
+ import { expect, fireEvent, fn, userEvent, waitFor } from '@storybook/test';
2
2
  import type { Meta, StoryObj } from '@storybook/web-components';
3
3
  import { html } from 'lit';
4
4
 
@@ -14,8 +14,9 @@ import { withinShadowRoot } from '../withinShadowRoot.story';
14
14
  const codeExample = String.raw`
15
15
  <gs-text-input
16
16
  lapisField="host"
17
+ lapisFilter='{"country": "Germany"}'
17
18
  placeholderText="Enter host name"
18
- initialValue="Homo sapiens"
19
+ value="Homo sapiens"
19
20
  width="50%">
20
21
  </gs-text-input>`;
21
22
 
@@ -34,6 +35,7 @@ const meta: Meta<Required<TextInputProps>> = {
34
35
  url: AGGREGATED_ENDPOINT,
35
36
  body: {
36
37
  fields: ['host'],
38
+ country: 'Germany',
37
39
  },
38
40
  },
39
41
  response: {
@@ -60,7 +62,7 @@ const meta: Meta<Required<TextInputProps>> = {
60
62
  type: 'text',
61
63
  },
62
64
  },
63
- initialValue: {
65
+ value: {
64
66
  control: {
65
67
  type: 'text',
66
68
  },
@@ -70,6 +72,11 @@ const meta: Meta<Required<TextInputProps>> = {
70
72
  type: 'text',
71
73
  },
72
74
  },
75
+ lapisFilter: {
76
+ control: {
77
+ type: 'object',
78
+ },
79
+ },
73
80
  },
74
81
  tags: ['autodocs'],
75
82
  };
@@ -82,8 +89,9 @@ export const Default: StoryObj<Required<TextInputProps>> = {
82
89
  <div class="max-w-screen-lg">
83
90
  <gs-text-input
84
91
  .lapisField=${args.lapisField}
92
+ .lapisFilter=${args.lapisFilter}
85
93
  .placeholderText=${args.placeholderText}
86
- .initialValue=${args.initialValue}
94
+ .value=${args.value}
87
95
  .width=${args.width}
88
96
  ></gs-text-input>
89
97
  </div>
@@ -91,13 +99,14 @@ export const Default: StoryObj<Required<TextInputProps>> = {
91
99
  },
92
100
  args: {
93
101
  lapisField: 'host',
102
+ lapisFilter: { country: 'Germany' },
94
103
  placeholderText: 'Enter host name',
95
- initialValue: 'Homo sapiens',
104
+ value: 'Homo sapiens',
96
105
  width: '100%',
97
106
  },
98
107
  };
99
108
 
100
- export const FiresEvent: StoryObj<Required<TextInputProps>> = {
109
+ export const FiresEvents: StoryObj<Required<TextInputProps>> = {
101
110
  ...Default,
102
111
  play: async ({ canvasElement, step }) => {
103
112
  const canvas = await withinShadowRoot(canvasElement, 'gs-text-input');
@@ -121,25 +130,48 @@ export const FiresEvent: StoryObj<Required<TextInputProps>> = {
121
130
 
122
131
  await step('Empty input', async () => {
123
132
  await userEvent.type(inputField(), '{backspace>9/}');
124
- await expect(listenerMock.mock.calls.at(-1)![0].detail).toStrictEqual({
125
- host: undefined,
126
- });
127
133
  });
128
134
 
129
135
  await step('Enter a valid host name', async () => {
130
- await userEvent.type(inputField(), 'Homo');
136
+ await userEvent.type(inputField(), 'Homo s');
137
+
138
+ const dropdownOption = await canvas.findByText('Homo sapiens');
139
+ await userEvent.click(dropdownOption);
140
+ });
141
+
142
+ await step('Verify event is fired with correct detail', async () => {
143
+ await waitFor(() => {
144
+ expect(listenerMock).toHaveBeenCalledWith(
145
+ expect.objectContaining({
146
+ detail: {
147
+ host: 'Homo sapiens',
148
+ },
149
+ }),
150
+ );
151
+ });
152
+ });
153
+
154
+ await step('Remove initial value', async () => {
155
+ await fireEvent.click(canvas.getByRole('button', { name: 'clear selection' }));
131
156
 
132
157
  await expect(listenerMock).toHaveBeenCalledWith(
133
158
  expect.objectContaining({
134
159
  detail: {
135
- host: 'Homo',
160
+ host: undefined,
136
161
  },
137
162
  }),
138
163
  );
139
164
  });
165
+
166
+ await step('Empty input', async () => {
167
+ inputField().blur();
168
+ await expect(listenerMock.mock.calls.at(-1)![0].detail).toStrictEqual({
169
+ host: undefined,
170
+ });
171
+ });
140
172
  },
141
173
  args: {
142
174
  ...Default.args,
143
- initialValue: '',
175
+ value: '',
144
176
  },
145
177
  };
@@ -1,6 +1,7 @@
1
1
  import { customElement, property } from 'lit/decorators.js';
2
2
  import type { DetailedHTMLProps, HTMLAttributes } from 'react';
3
3
 
4
+ import { type TextInputChangedEvent } from '../../preact/textInput/TextInputChangedEvent';
4
5
  import { TextInput, type TextInputProps } from '../../preact/textInput/text-input';
5
6
  import type { Equals, Expect } from '../../utils/typeAssertions';
6
7
  import { PreactLitAdapter } from '../PreactLitAdapter';
@@ -11,7 +12,7 @@ import { PreactLitAdapter } from '../PreactLitAdapter';
11
12
  *
12
13
  * This component provides a text input field to specify filters for arbitrary fields of this LAPIS instance.
13
14
  *
14
- * @fires {CustomEvent<Record<string, string>>} gs-text-input-changed
15
+ * @fires {CustomEvent<Record<string, string | undefined>>} gs-text-input-changed
15
16
  * Fired when the input field is changed.
16
17
  * The `details` of this event contain an object with the `lapisField` as key and the input value as value.
17
18
  * Example:
@@ -27,7 +28,7 @@ export class TextInputComponent extends PreactLitAdapter {
27
28
  * The initial value to use for this text input.
28
29
  */
29
30
  @property()
30
- initialValue: string | undefined = undefined;
31
+ value: string | undefined = undefined;
31
32
 
32
33
  /**
33
34
  * Required.
@@ -38,6 +39,19 @@ export class TextInputComponent extends PreactLitAdapter {
38
39
  @property()
39
40
  lapisField = '';
40
41
 
42
+ /**
43
+ * The filter that is used to fetch the available the autocomplete options.
44
+ * If not set it fetches all available options.
45
+ * It must be a valid LAPIS filter object.
46
+ */
47
+ @property({ type: Object })
48
+ lapisFilter: Record<string, string | string[] | number | null | boolean | undefined> & {
49
+ nucleotideMutations?: string[];
50
+ aminoAcidMutations?: string[];
51
+ nucleotideInsertions?: string[];
52
+ aminoAcidInsertions?: string[];
53
+ } = {};
54
+
41
55
  /**
42
56
  * The placeholder text to display in the input field.
43
57
  */
@@ -56,8 +70,9 @@ export class TextInputComponent extends PreactLitAdapter {
56
70
  return (
57
71
  <TextInput
58
72
  lapisField={this.lapisField}
73
+ lapisFilter={this.lapisFilter}
59
74
  placeholderText={this.placeholderText}
60
- initialValue={this.initialValue}
75
+ value={this.value}
61
76
  width={this.width}
62
77
  />
63
78
  );
@@ -70,7 +85,7 @@ declare global {
70
85
  }
71
86
 
72
87
  interface HTMLElementEventMap {
73
- 'gs-text-input-changed': CustomEvent<Record<string, string>>;
88
+ 'gs-text-input-changed': TextInputChangedEvent;
74
89
  }
75
90
  }
76
91
 
@@ -84,10 +99,11 @@ declare global {
84
99
  }
85
100
 
86
101
  /* eslint-disable @typescript-eslint/no-unused-vars, no-unused-vars */
87
- type InitialValueMatches = Expect<
88
- Equals<typeof TextInputComponent.prototype.initialValue, TextInputProps['initialValue']>
89
- >;
102
+ type InitialValueMatches = Expect<Equals<typeof TextInputComponent.prototype.value, TextInputProps['value']>>;
90
103
  type LapisFieldMatches = Expect<Equals<typeof TextInputComponent.prototype.lapisField, TextInputProps['lapisField']>>;
104
+ type LapisFilterMatches = Expect<
105
+ Equals<typeof TextInputComponent.prototype.lapisFilter, TextInputProps['lapisFilter']>
106
+ >;
91
107
  type PlaceholderTextMatches = Expect<
92
108
  Equals<typeof TextInputComponent.prototype.placeholderText, TextInputProps['placeholderText']>
93
109
  >;