@genspectrum/dashboard-components 1.17.0 → 1.18.1

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.
@@ -332,15 +332,22 @@ function n$1(t2) {
332
332
  })(t2, e2, o2);
333
333
  }
334
334
  const lapisContext = createContext("lapis-context");
335
- const annotations = z$2.array(z$2.string());
335
+ const mutationEntrySchema = z$2.union([
336
+ z$2.string(),
337
+ z$2.object({ mutation: z$2.string(), name: z$2.string().optional(), description: z$2.string().optional() })
338
+ ]);
339
+ const positionEntrySchema = z$2.union([
340
+ z$2.string(),
341
+ z$2.object({ position: z$2.string(), name: z$2.string().optional(), description: z$2.string().optional() })
342
+ ]);
336
343
  const mutationAnnotationSchema = z$2.object({
337
344
  name: z$2.string(),
338
345
  description: z$2.string(),
339
346
  symbol: z$2.string(),
340
- nucleotideMutations: annotations.optional(),
341
- nucleotidePositions: annotations.optional(),
342
- aminoAcidMutations: annotations.optional(),
343
- aminoAcidPositions: annotations.optional()
347
+ nucleotideMutations: z$2.array(mutationEntrySchema).optional(),
348
+ nucleotidePositions: z$2.array(positionEntrySchema).optional(),
349
+ aminoAcidMutations: z$2.array(mutationEntrySchema).optional(),
350
+ aminoAcidPositions: z$2.array(positionEntrySchema).optional()
344
351
  });
345
352
  const mutationAnnotationsSchema = z$2.array(mutationAnnotationSchema, {
346
353
  errorMap: () => ({ message: "invalid mutation annotations" })
@@ -2152,46 +2159,69 @@ const MutationAnnotationsContext = createContext$1({
2152
2159
  }
2153
2160
  });
2154
2161
  const MutationAnnotationsContextProvider = ({ value, children }) => {
2155
- const parseResult = T$1(() => {
2156
- const parseResult2 = mutationAnnotationsSchema.safeParse(value);
2157
- if (!parseResult2.success) {
2158
- return parseResult2;
2159
- }
2160
- return { success: true, value: getMutationAnnotationsContext(value) };
2161
- }, [value]);
2162
- if (!parseResult.success) {
2163
- return /* @__PURE__ */ u$1(ResizeContainer, { size: { width: "100%" }, children: /* @__PURE__ */ u$1(ErrorDisplay, { error: parseResult.error, layout: "vertical" }) });
2162
+ const parseResult = T$1(() => mutationAnnotationsSchema.safeParse(value), [value]);
2163
+ const contextValue = T$1(
2164
+ () => parseResult.success ? { success: true, value: buildAnnotationIndex(parseResult.data) } : { success: false, error: parseResult.error },
2165
+ [parseResult]
2166
+ );
2167
+ if (!contextValue.success) {
2168
+ return /* @__PURE__ */ u$1(ResizeContainer, { size: { width: "100%" }, children: /* @__PURE__ */ u$1(ErrorDisplay, { error: contextValue.error, layout: "vertical" }) });
2164
2169
  }
2165
- return /* @__PURE__ */ u$1(MutationAnnotationsContext.Provider, { value: parseResult.value, children });
2170
+ return /* @__PURE__ */ u$1(MutationAnnotationsContext.Provider, { value: contextValue.value, children });
2166
2171
  };
2167
- function getMutationAnnotationsContext(value) {
2168
- const nucleotideMap = /* @__PURE__ */ new Map();
2169
- const nucleotidePositions = /* @__PURE__ */ new Map();
2170
- const aminoAcidMap = /* @__PURE__ */ new Map();
2171
- const aminoAcidPositions = /* @__PURE__ */ new Map();
2172
+ function buildAnnotationIndex(value) {
2173
+ const nucleotideMutationMap = /* @__PURE__ */ new Map();
2174
+ const nucleotidePositionMap = /* @__PURE__ */ new Map();
2175
+ const aminoAcidMutationMap = /* @__PURE__ */ new Map();
2176
+ const aminoAcidPositionMap = /* @__PURE__ */ new Map();
2172
2177
  value.forEach((annotation) => {
2173
- new Set(annotation.nucleotideMutations).forEach((code) => {
2174
- addAnnotationToMap(nucleotideMap, code, annotation);
2178
+ var _a, _b, _c, _d;
2179
+ (_a = annotation.nucleotideMutations) == null ? void 0 : _a.forEach((entry) => {
2180
+ addToMap(
2181
+ nucleotideMutationMap,
2182
+ typeof entry === "string" ? entry : entry.mutation,
2183
+ resolve(annotation, entry)
2184
+ );
2175
2185
  });
2176
- new Set(annotation.aminoAcidMutations).forEach((code) => {
2177
- addAnnotationToMap(aminoAcidMap, code, annotation);
2186
+ (_b = annotation.aminoAcidMutations) == null ? void 0 : _b.forEach((entry) => {
2187
+ addToMap(
2188
+ aminoAcidMutationMap,
2189
+ typeof entry === "string" ? entry : entry.mutation,
2190
+ resolve(annotation, entry)
2191
+ );
2178
2192
  });
2179
- new Set(annotation.nucleotidePositions).forEach((position) => {
2180
- addAnnotationToMap(nucleotidePositions, position, annotation);
2193
+ (_c = annotation.nucleotidePositions) == null ? void 0 : _c.forEach((entry) => {
2194
+ addToMap(
2195
+ nucleotidePositionMap,
2196
+ typeof entry === "string" ? entry : entry.position,
2197
+ resolve(annotation, entry)
2198
+ );
2181
2199
  });
2182
- new Set(annotation.aminoAcidPositions).forEach((position) => {
2183
- addAnnotationToMap(aminoAcidPositions, position, annotation);
2200
+ (_d = annotation.aminoAcidPositions) == null ? void 0 : _d.forEach((entry) => {
2201
+ addToMap(
2202
+ aminoAcidPositionMap,
2203
+ typeof entry === "string" ? entry : entry.position,
2204
+ resolve(annotation, entry)
2205
+ );
2184
2206
  });
2185
2207
  });
2186
2208
  return {
2187
2209
  rawAnnotations: value,
2188
- nucleotide: { mutation: nucleotideMap, position: nucleotidePositions },
2189
- "amino acid": { mutation: aminoAcidMap, position: aminoAcidPositions }
2210
+ nucleotide: { mutation: nucleotideMutationMap, position: nucleotidePositionMap },
2211
+ "amino acid": { mutation: aminoAcidMutationMap, position: aminoAcidPositionMap }
2190
2212
  };
2191
2213
  }
2192
- function addAnnotationToMap(map2, code, annotation) {
2193
- const oldAnnotations = map2.get(code.toUpperCase()) ?? [];
2194
- map2.set(code.toUpperCase(), [...oldAnnotations, annotation]);
2214
+ function resolve(annotation, entry) {
2215
+ const overrides = typeof entry === "object" ? entry : void 0;
2216
+ return {
2217
+ annotation,
2218
+ name: (overrides == null ? void 0 : overrides.name) ?? annotation.name,
2219
+ description: (overrides == null ? void 0 : overrides.description) ?? annotation.description
2220
+ };
2221
+ }
2222
+ function addToMap(map2, code, resolved) {
2223
+ const existing = map2.get(code.toUpperCase()) ?? [];
2224
+ map2.set(code.toUpperCase(), [...existing, resolved]);
2195
2225
  }
2196
2226
  function useRawMutationAnnotations() {
2197
2227
  return x$1(MutationAnnotationsContext).rawAnnotations;
@@ -2203,15 +2233,15 @@ function useMutationAnnotationsProvider() {
2203
2233
  function getMutationAnnotationsProvider(mutationAnnotations) {
2204
2234
  return (mutation, sequenceType) => {
2205
2235
  const position = mutation.segment === void 0 ? `${mutation.position}` : `${mutation.segment.toUpperCase()}:${mutation.position}`;
2206
- const possiblePositionAnnotations = mutationAnnotations[sequenceType].position.get(position);
2207
- const possibleExactAnnotations = mutationAnnotations[sequenceType].mutation.get(mutation.code.toUpperCase());
2208
- const annotations2 = possiblePositionAnnotations && possibleExactAnnotations ? [...possiblePositionAnnotations, ...possibleExactAnnotations] : possiblePositionAnnotations ?? possibleExactAnnotations;
2209
- const uniqueNames = /* @__PURE__ */ new Set();
2210
- return annotations2 == null ? void 0 : annotations2.filter((annotation) => {
2211
- if (uniqueNames.has(annotation.name)) {
2236
+ const exactMatches = mutationAnnotations[sequenceType].mutation.get(mutation.code.toUpperCase());
2237
+ const positionMatches = mutationAnnotations[sequenceType].position.get(position);
2238
+ const combined = exactMatches && positionMatches ? [...exactMatches, ...positionMatches] : exactMatches ?? positionMatches;
2239
+ const seenNames = /* @__PURE__ */ new Set();
2240
+ return combined == null ? void 0 : combined.filter((resolved) => {
2241
+ if (seenNames.has(resolved.annotation.name)) {
2212
2242
  return false;
2213
2243
  }
2214
- uniqueNames.add(annotation.name);
2244
+ seenNames.add(resolved.annotation.name);
2215
2245
  return true;
2216
2246
  });
2217
2247
  };
@@ -2339,10 +2369,10 @@ const AnnotatedMutationWithoutContext = ({
2339
2369
  "Annotations for ",
2340
2370
  mutation.code
2341
2371
  ] }),
2342
- mutationAnnotations.map((annotation) => /* @__PURE__ */ u$1(Fragment, { children: [
2343
- /* @__PURE__ */ u$1(InfoHeadline2, { children: annotation.name }),
2344
- /* @__PURE__ */ u$1(InfoParagraph, { children: /* @__PURE__ */ u$1("div", { dangerouslySetInnerHTML: { __html: DOMPurify.sanitize(annotation.description) } }) })
2345
- ] }, annotation.name))
2372
+ mutationAnnotations.map((resolved) => /* @__PURE__ */ u$1(Fragment, { children: [
2373
+ /* @__PURE__ */ u$1(InfoHeadline2, { children: resolved.name }),
2374
+ /* @__PURE__ */ u$1(InfoParagraph, { children: /* @__PURE__ */ u$1("div", { dangerouslySetInnerHTML: { __html: DOMPurify.sanitize(resolved.description) } }) })
2375
+ ] }, resolved.annotation.name))
2346
2376
  ] });
2347
2377
  return /* @__PURE__ */ u$1(Fragment, { children: [
2348
2378
  innerLabel,
@@ -2352,7 +2382,7 @@ const AnnotatedMutationWithoutContext = ({
2352
2382
  buttonClassName: "select-text cursor-pointer",
2353
2383
  modalContent,
2354
2384
  modalRef,
2355
- children: /* @__PURE__ */ u$1("sup", { className: "hover:underline focus-visible:underline decoration-red-600", children: mutationAnnotations.map((annotation) => annotation.symbol).map((symbol, index) => /* @__PURE__ */ u$1(Fragment, { children: [
2385
+ children: /* @__PURE__ */ u$1("sup", { className: "hover:underline focus-visible:underline decoration-red-600", children: mutationAnnotations.map((resolved) => resolved.annotation.symbol).map((symbol, index) => /* @__PURE__ */ u$1(Fragment, { children: [
2356
2386
  /* @__PURE__ */ u$1("span", { className: "text-red-600", children: symbol }),
2357
2387
  index !== mutationAnnotations.length - 1 && ","
2358
2388
  ] }, symbol)) })
@@ -7289,7 +7319,7 @@ function mutationOrAnnotationMatchesTextFilter(mutation, sequenceType, textFilte
7289
7319
  return false;
7290
7320
  }
7291
7321
  return mutationAnnotations.some(
7292
- (annotation) => annotation.description.includes(textFilter) || annotation.name.includes(textFilter) || annotation.symbol.includes(textFilter)
7322
+ (resolved) => resolved.annotation.description.includes(textFilter) || resolved.annotation.name.includes(textFilter) || resolved.annotation.symbol.includes(textFilter)
7293
7323
  );
7294
7324
  }
7295
7325
  function mutationMatchesAnnotationFilter(mutation, sequenceType, annotationNameFilter, annotationProvider) {
@@ -7300,7 +7330,7 @@ function mutationMatchesAnnotationFilter(mutation, sequenceType, annotationNameF
7300
7330
  if (mutationAnnotations === void 0 || mutationAnnotations.length === 0) {
7301
7331
  return false;
7302
7332
  }
7303
- return mutationAnnotations.some((annotation) => annotationNameFilter.has(annotation.name));
7333
+ return mutationAnnotations.some((resolved) => annotationNameFilter.has(resolved.annotation.name));
7304
7334
  }
7305
7335
  async function queryDatesInDataset(lapisFilter, lapis, granularity, lapisDateField, signal) {
7306
7336
  const { dateFrom, dateTo } = getDateRangeFromFilter(lapisFilter, lapisDateField, granularity);
@@ -15394,7 +15424,16 @@ function DownshiftMultiCombobox({
15394
15424
  },
15395
15425
  environment
15396
15426
  });
15397
- const { isOpen, getToggleButtonProps, getMenuProps, getInputProps, highlightedIndex, getItemProps, closeMenu } = useCombobox({
15427
+ const {
15428
+ isOpen,
15429
+ getToggleButtonProps,
15430
+ getMenuProps,
15431
+ getInputProps,
15432
+ highlightedIndex,
15433
+ getItemProps,
15434
+ closeMenu,
15435
+ selectItem
15436
+ } = useCombobox({
15398
15437
  items: availableItems,
15399
15438
  itemToString(item) {
15400
15439
  return itemToString2(item);
@@ -15434,6 +15473,7 @@ function DownshiftMultiCombobox({
15434
15473
  const clearAll = () => {
15435
15474
  dispatchEvent([]);
15436
15475
  setItemsFilter("");
15476
+ selectItem(null);
15437
15477
  };
15438
15478
  const buttonRef = A$1(null);
15439
15479
  return /* @__PURE__ */ u$1("div", { ref: divRef, className: "relative w-full", children: [
@@ -15459,7 +15499,10 @@ function DownshiftMultiCombobox({
15459
15499
  "aria-label": `remove ${itemToString2(selectedItem)}`,
15460
15500
  className: "cursor-pointer hover:text-red-600",
15461
15501
  type: "button",
15462
- onClick: () => removeSelectedItem(selectedItem),
15502
+ onClick: () => {
15503
+ removeSelectedItem(selectedItem);
15504
+ selectItem(null);
15505
+ },
15463
15506
  tabIndex: -1,
15464
15507
  children: "×"
15465
15508
  }