@genspectrum/dashboard-components 0.13.1 → 0.13.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.
package/dist/util.d.ts CHANGED
@@ -838,7 +838,7 @@ declare global {
838
838
 
839
839
  declare global {
840
840
  interface HTMLElementTagNameMap {
841
- 'gs-wastewater-mutations-over-time': WastewaterMutationsOverTimeComponent;
841
+ 'gs-mutation-comparison-component': MutationComparisonComponent;
842
842
  }
843
843
  }
844
844
 
@@ -846,7 +846,7 @@ declare global {
846
846
  declare global {
847
847
  namespace JSX {
848
848
  interface IntrinsicElements {
849
- 'gs-wastewater-mutations-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
849
+ 'gs-mutation-comparison-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
850
850
  }
851
851
  }
852
852
  }
@@ -854,7 +854,7 @@ declare global {
854
854
 
855
855
  declare global {
856
856
  interface HTMLElementTagNameMap {
857
- 'gs-mutation-comparison-component': MutationComparisonComponent;
857
+ 'gs-prevalence-over-time': PrevalenceOverTimeComponent;
858
858
  }
859
859
  }
860
860
 
@@ -862,7 +862,7 @@ declare global {
862
862
  declare global {
863
863
  namespace JSX {
864
864
  interface IntrinsicElements {
865
- 'gs-mutation-comparison-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
865
+ 'gs-prevalence-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
866
866
  }
867
867
  }
868
868
  }
@@ -886,7 +886,7 @@ declare global {
886
886
 
887
887
  declare global {
888
888
  interface HTMLElementTagNameMap {
889
- 'gs-prevalence-over-time': PrevalenceOverTimeComponent;
889
+ 'gs-relative-growth-advantage': RelativeGrowthAdvantageComponent;
890
890
  }
891
891
  }
892
892
 
@@ -894,7 +894,7 @@ declare global {
894
894
  declare global {
895
895
  namespace JSX {
896
896
  interface IntrinsicElements {
897
- 'gs-prevalence-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
897
+ 'gs-relative-growth-advantage': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
898
898
  }
899
899
  }
900
900
  }
@@ -902,7 +902,7 @@ declare global {
902
902
 
903
903
  declare global {
904
904
  interface HTMLElementTagNameMap {
905
- 'gs-relative-growth-advantage': RelativeGrowthAdvantageComponent;
905
+ 'gs-aggregate': AggregateComponent;
906
906
  }
907
907
  }
908
908
 
@@ -910,7 +910,7 @@ declare global {
910
910
  declare global {
911
911
  namespace JSX {
912
912
  interface IntrinsicElements {
913
- 'gs-relative-growth-advantage': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
913
+ 'gs-aggregate': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
914
914
  }
915
915
  }
916
916
  }
@@ -918,7 +918,7 @@ declare global {
918
918
 
919
919
  declare global {
920
920
  interface HTMLElementTagNameMap {
921
- 'gs-aggregate': AggregateComponent;
921
+ 'gs-number-sequences-over-time': NumberSequencesOverTimeComponent;
922
922
  }
923
923
  }
924
924
 
@@ -926,7 +926,7 @@ declare global {
926
926
  declare global {
927
927
  namespace JSX {
928
928
  interface IntrinsicElements {
929
- 'gs-aggregate': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
929
+ 'gs-number-sequences-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
930
930
  }
931
931
  }
932
932
  }
@@ -934,7 +934,7 @@ declare global {
934
934
 
935
935
  declare global {
936
936
  interface HTMLElementTagNameMap {
937
- 'gs-number-sequences-over-time': NumberSequencesOverTimeComponent;
937
+ 'gs-mutations-over-time': MutationsOverTimeComponent;
938
938
  }
939
939
  }
940
940
 
@@ -942,7 +942,7 @@ declare global {
942
942
  declare global {
943
943
  namespace JSX {
944
944
  interface IntrinsicElements {
945
- 'gs-number-sequences-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
945
+ 'gs-mutations-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
946
946
  }
947
947
  }
948
948
  }
@@ -966,7 +966,7 @@ declare global {
966
966
 
967
967
  declare global {
968
968
  interface HTMLElementTagNameMap {
969
- 'gs-mutations-over-time': MutationsOverTimeComponent;
969
+ 'gs-statistics': StatisticsComponent;
970
970
  }
971
971
  }
972
972
 
@@ -974,7 +974,7 @@ declare global {
974
974
  declare global {
975
975
  namespace JSX {
976
976
  interface IntrinsicElements {
977
- 'gs-mutations-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
977
+ 'gs-statistics': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
978
978
  }
979
979
  }
980
980
  }
@@ -982,7 +982,7 @@ declare global {
982
982
 
983
983
  declare global {
984
984
  interface HTMLElementTagNameMap {
985
- 'gs-statistics': StatisticsComponent;
985
+ 'gs-wastewater-mutations-over-time': WastewaterMutationsOverTimeComponent;
986
986
  }
987
987
  }
988
988
 
@@ -990,7 +990,7 @@ declare global {
990
990
  declare global {
991
991
  namespace JSX {
992
992
  interface IntrinsicElements {
993
- 'gs-statistics': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
993
+ 'gs-wastewater-mutations-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
994
994
  }
995
995
  }
996
996
  }
@@ -1037,10 +1037,10 @@ declare global {
1037
1037
 
1038
1038
  declare global {
1039
1039
  interface HTMLElementTagNameMap {
1040
- 'gs-text-input': TextInputComponent;
1040
+ 'gs-lineage-filter': LineageFilterComponent;
1041
1041
  }
1042
1042
  interface HTMLElementEventMap {
1043
- 'gs-text-input-changed': TextInputChangedEvent;
1043
+ 'gs-lineage-filter-changed': LineageFilterChangedEvent;
1044
1044
  }
1045
1045
  }
1046
1046
 
@@ -1048,7 +1048,7 @@ declare global {
1048
1048
  declare global {
1049
1049
  namespace JSX {
1050
1050
  interface IntrinsicElements {
1051
- 'gs-text-input': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1051
+ 'gs-lineage-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1052
1052
  }
1053
1053
  }
1054
1054
  }
@@ -1056,10 +1056,10 @@ declare global {
1056
1056
 
1057
1057
  declare global {
1058
1058
  interface HTMLElementTagNameMap {
1059
- 'gs-mutation-filter': MutationFilterComponent;
1059
+ 'gs-text-input': TextInputComponent;
1060
1060
  }
1061
1061
  interface HTMLElementEventMap {
1062
- 'gs-mutation-filter-changed': CustomEvent<MutationsFilter>;
1062
+ 'gs-text-input-changed': TextInputChangedEvent;
1063
1063
  }
1064
1064
  }
1065
1065
 
@@ -1067,7 +1067,7 @@ declare global {
1067
1067
  declare global {
1068
1068
  namespace JSX {
1069
1069
  interface IntrinsicElements {
1070
- 'gs-mutation-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1070
+ 'gs-text-input': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1071
1071
  }
1072
1072
  }
1073
1073
  }
@@ -1075,10 +1075,10 @@ declare global {
1075
1075
 
1076
1076
  declare global {
1077
1077
  interface HTMLElementTagNameMap {
1078
- 'gs-lineage-filter': LineageFilterComponent;
1078
+ 'gs-mutation-filter': MutationFilterComponent;
1079
1079
  }
1080
1080
  interface HTMLElementEventMap {
1081
- 'gs-lineage-filter-changed': LineageFilterChangedEvent;
1081
+ 'gs-mutation-filter-changed': CustomEvent<MutationsFilter>;
1082
1082
  }
1083
1083
  }
1084
1084
 
@@ -1086,7 +1086,7 @@ declare global {
1086
1086
  declare global {
1087
1087
  namespace JSX {
1088
1088
  interface IntrinsicElements {
1089
- 'gs-lineage-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1089
+ 'gs-mutation-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1090
1090
  }
1091
1091
  }
1092
1092
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genspectrum/dashboard-components",
3
- "version": "0.13.1",
3
+ "version": "0.13.3",
4
4
  "description": "GenSpectrum web components for building dashboards",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
@@ -120,26 +120,24 @@ export function DownshiftCombobox<Item>({
120
120
  </button>
121
121
  </div>
122
122
  </div>
123
- {isOpen && (
124
- <ul
125
- className='absolute bg-white mt-1 shadow-md max-h-80 overflow-scroll z-10 w-full min-w-32'
126
- {...getMenuProps()}
127
- >
128
- {items.length > 0 ? (
129
- items.map((item, index) => (
130
- <li
131
- className={`${highlightedIndex === index ? 'bg-blue-300' : ''} ${selectedItem !== null && itemToString(selectedItem) === itemToString(item) ? 'font-bold' : ''} py-2 px-3 shadow-sm flex flex-col`}
132
- key={itemToString(item)}
133
- {...getItemProps({ item, index })}
134
- >
135
- {formatItemInList(item)}
136
- </li>
137
- ))
138
- ) : (
139
- <li className='py-2 px-3 shadow-sm flex flex-col'>No elements to select.</li>
140
- )}
141
- </ul>
142
- )}
123
+ <ul
124
+ className={`absolute bg-white mt-1 shadow-md max-h-80 overflow-scroll z-10 w-full min-w-32 ${isOpen ? '' : 'hidden'}`}
125
+ {...getMenuProps()}
126
+ >
127
+ {items.length > 0 ? (
128
+ items.map((item, index) => (
129
+ <li
130
+ className={`${highlightedIndex === index ? 'bg-blue-300' : ''} ${selectedItem !== null && itemToString(selectedItem) === itemToString(item) ? 'font-bold' : ''} py-2 px-3 shadow-sm flex flex-col`}
131
+ key={itemToString(item)}
132
+ {...getItemProps({ item, index })}
133
+ >
134
+ {formatItemInList(item)}
135
+ </li>
136
+ ))
137
+ ) : (
138
+ <li className='py-2 px-3 shadow-sm flex flex-col'>No elements to select.</li>
139
+ )}
140
+ </ul>
143
141
  </div>
144
142
  );
145
143
  }
@@ -0,0 +1,34 @@
1
+ import { describe, expect, test } from 'vitest';
2
+
3
+ import { fetchStringAutocompleteList } from './fetchStringAutocompleteList';
4
+ import { DUMMY_LAPIS_URL, lapisRequestMocks } from '../../../vitest.setup';
5
+
6
+ describe('fetchStringAutocompleteList', () => {
7
+ test('should fetch autocompletion list and sort by field value', async () => {
8
+ const field = 'host';
9
+
10
+ lapisRequestMocks.aggregated(
11
+ { fields: [field], country: 'Germany' },
12
+ {
13
+ data: [
14
+ { count: 1, host: 'host_c' },
15
+ { count: 2, host: 'host_b' },
16
+ { count: 3, host: null },
17
+ { count: 4, host: 'host_a' },
18
+ ],
19
+ },
20
+ );
21
+
22
+ const result = await fetchStringAutocompleteList({
23
+ field,
24
+ lapis: DUMMY_LAPIS_URL,
25
+ lapisFilter: { country: 'Germany' },
26
+ });
27
+
28
+ expect(result).to.deep.equal([
29
+ { count: 4, value: 'host_a' },
30
+ { count: 2, value: 'host_b' },
31
+ { count: 1, value: 'host_c' },
32
+ ]);
33
+ });
34
+ });
@@ -12,9 +12,23 @@ export async function fetchStringAutocompleteList({
12
12
  lapisFilter?: LapisFilter;
13
13
  signal?: AbortSignal;
14
14
  }) {
15
- const fetchAggregatedOperator = new FetchAggregatedOperator<Record<string, string>>(lapisFilter ?? {}, [field]);
15
+ const fetchAggregatedOperator = new FetchAggregatedOperator<Record<string, string | null>>(lapisFilter ?? {}, [
16
+ field,
17
+ ]);
16
18
 
17
19
  const data = (await fetchAggregatedOperator.evaluate(lapis, signal)).content;
18
20
 
19
- return data.map((item) => item[field]).sort();
21
+ return data
22
+ .map((item) => ({ count: item.count, value: item[field] }))
23
+ .filter((item): item is { count: number; value: string } => item.value !== null)
24
+ .sort((a, b) => {
25
+ if (a.value === null) {
26
+ return 1;
27
+ }
28
+ if (b.value === null) {
29
+ return -1;
30
+ }
31
+
32
+ return a.value.localeCompare(b.value);
33
+ });
20
34
  }
@@ -68,32 +68,46 @@ const TextInputInner: FunctionComponent<TextInputInnerProps> = ({
68
68
  return <TextSelector lapisField={lapisField} value={value} placeholderText={placeholderText} data={data} />;
69
69
  };
70
70
 
71
+ type SelectItem = {
72
+ count: number;
73
+ value: string;
74
+ };
75
+
71
76
  const TextSelector = ({
72
77
  lapisField,
73
78
  value,
74
79
  placeholderText,
75
80
  data,
76
81
  }: TextSelectorProps & {
77
- data: string[];
82
+ data: SelectItem[];
78
83
  }) => {
84
+ const initialSelectedItem = data.find((candidate) => candidate.value == value);
85
+
79
86
  return (
80
87
  <DownshiftCombobox
81
88
  allItems={data}
82
- value={value}
89
+ value={initialSelectedItem}
83
90
  filterItemsByInputValue={filterByInputValue}
84
- createEvent={(item: string | null) => new TextInputChangedEvent({ [lapisField]: item ?? undefined })}
85
- itemToString={(item: string | undefined | null) => item ?? ''}
91
+ createEvent={(item: SelectItem | null) =>
92
+ new TextInputChangedEvent({ [lapisField]: item?.value ?? undefined })
93
+ }
94
+ itemToString={(item: SelectItem | undefined | null) => item?.value ?? ''}
86
95
  placeholderText={placeholderText}
87
- formatItemInList={(item: string) => {
88
- return <span>{item}</span>;
96
+ formatItemInList={(item: SelectItem) => {
97
+ return (
98
+ <p>
99
+ <span>{item.value}</span>
100
+ <span className='ml-2 text-gray-500'>({item.count})</span>
101
+ </p>
102
+ );
89
103
  }}
90
104
  />
91
105
  );
92
106
  };
93
107
 
94
- function filterByInputValue(item: string, inputValue: string | undefined | null) {
108
+ function filterByInputValue(item: SelectItem, inputValue: string | undefined | null) {
95
109
  if (inputValue === undefined || inputValue === null || inputValue === '') {
96
110
  return true;
97
111
  }
98
- return item?.toLowerCase().includes(inputValue?.toLowerCase() || '');
112
+ return item.value?.toLowerCase().includes(inputValue?.toLowerCase() || '');
99
113
  }
@@ -14,7 +14,7 @@ export interface MutationClass extends Mutation {
14
14
  }
15
15
 
16
16
  export const substitutionRegex =
17
- /^((?<segment>[A-Z0-9_-]+)(?=:):)?(?<valueAtReference>[A-Z])?(?<position>\d+)(?<substitutionValue>[A-Z.])?$/i;
17
+ /^((?<segment>[A-Z0-9_-]+)(?=:):)?(?<valueAtReference>[A-Z])?(?<position>\d+)(?<substitutionValue>[A-Z.*])?$/i;
18
18
 
19
19
  export interface Substitution extends Mutation {
20
20
  type: 'substitution';