@genspectrum/dashboard-components 0.8.4 → 0.8.5

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.
@@ -1094,7 +1094,7 @@ declare global {
1094
1094
 
1095
1095
  declare global {
1096
1096
  interface HTMLElementTagNameMap {
1097
- 'gs-number-sequences-over-time': NumberSequencesOverTimeComponent;
1097
+ 'gs-aggregate-component': AggregateComponent;
1098
1098
  }
1099
1099
  }
1100
1100
 
@@ -1102,7 +1102,7 @@ declare global {
1102
1102
  declare global {
1103
1103
  namespace JSX {
1104
1104
  interface IntrinsicElements {
1105
- 'gs-number-sequences-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1105
+ 'gs-aggregate-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1106
1106
  }
1107
1107
  }
1108
1108
  }
@@ -1110,7 +1110,7 @@ declare global {
1110
1110
 
1111
1111
  declare global {
1112
1112
  interface HTMLElementTagNameMap {
1113
- 'gs-aggregate-component': AggregateComponent;
1113
+ 'gs-number-sequences-over-time': NumberSequencesOverTimeComponent;
1114
1114
  }
1115
1115
  }
1116
1116
 
@@ -1118,7 +1118,7 @@ declare global {
1118
1118
  declare global {
1119
1119
  namespace JSX {
1120
1120
  interface IntrinsicElements {
1121
- 'gs-aggregate-component': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1121
+ 'gs-number-sequences-over-time': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1122
1122
  }
1123
1123
  }
1124
1124
  }
@@ -1199,10 +1199,10 @@ declare global {
1199
1199
 
1200
1200
  declare global {
1201
1201
  interface HTMLElementTagNameMap {
1202
- 'gs-lineage-filter': LineageFilterComponent;
1202
+ 'gs-mutation-filter': MutationFilterComponent;
1203
1203
  }
1204
1204
  interface HTMLElementEventMap {
1205
- 'gs-lineage-filter-changed': CustomEvent<Record<string, string>>;
1205
+ 'gs-mutation-filter-changed': CustomEvent<SelectedMutationFilterStrings>;
1206
1206
  }
1207
1207
  }
1208
1208
 
@@ -1210,7 +1210,7 @@ declare global {
1210
1210
  declare global {
1211
1211
  namespace JSX {
1212
1212
  interface IntrinsicElements {
1213
- 'gs-lineage-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1213
+ 'gs-mutation-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1214
1214
  }
1215
1215
  }
1216
1216
  }
@@ -1218,10 +1218,10 @@ declare global {
1218
1218
 
1219
1219
  declare global {
1220
1220
  interface HTMLElementTagNameMap {
1221
- 'gs-mutation-filter': MutationFilterComponent;
1221
+ 'gs-lineage-filter': LineageFilterComponent;
1222
1222
  }
1223
1223
  interface HTMLElementEventMap {
1224
- 'gs-mutation-filter-changed': CustomEvent<SelectedMutationFilterStrings>;
1224
+ 'gs-lineage-filter-changed': CustomEvent<Record<string, string>>;
1225
1225
  }
1226
1226
  }
1227
1227
 
@@ -1229,7 +1229,7 @@ declare global {
1229
1229
  declare global {
1230
1230
  namespace JSX {
1231
1231
  interface IntrinsicElements {
1232
- 'gs-mutation-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1232
+ 'gs-lineage-filter': DetailedHTMLProps<HTMLAttributes<HTMLElement>, HTMLElement>;
1233
1233
  }
1234
1234
  }
1235
1235
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@genspectrum/dashboard-components",
3
- "version": "0.8.4",
3
+ "version": "0.8.5",
4
4
  "description": "GenSpectrum web components for building dashboards",
5
5
  "type": "module",
6
6
  "license": "AGPL-3.0-only",
@@ -1,31 +1,53 @@
1
1
  import { useEffect, useState } from 'preact/hooks';
2
2
 
3
+ import { UserFacingError } from '../components/error-display';
4
+
5
+ export type LoadingWorkerStatus = {
6
+ status: 'loading';
7
+ };
8
+ export type SuccessWorkerStatus<Response> = {
9
+ status: 'success';
10
+ data: Response;
11
+ };
12
+ export type ErrorWorkerStatus =
13
+ | {
14
+ status: 'error';
15
+ userFacing: false;
16
+ error: Error;
17
+ }
18
+ | {
19
+ status: 'error';
20
+ userFacing: true;
21
+ headline: string;
22
+ error: Error;
23
+ };
24
+ export type WorkerStatus<Response> = LoadingWorkerStatus | SuccessWorkerStatus<Response> | ErrorWorkerStatus;
25
+
3
26
  export function useWebWorker<Request, Response>(messageToWorker: Request, worker: Worker) {
4
27
  const [data, setData] = useState<Response | undefined>(undefined);
5
28
  const [error, setError] = useState<Error | undefined>(undefined);
6
29
  const [isLoading, setIsLoading] = useState(true);
7
30
 
8
31
  useEffect(() => {
9
- worker.onmessage = (
10
- event: MessageEvent<{
11
- status: 'loading' | 'success' | 'error';
12
- data?: Response;
13
- error?: Error;
14
- }>,
15
- ) => {
16
- const { status, data, error } = event.data;
32
+ worker.onmessage = (event: MessageEvent<WorkerStatus<Response>>) => {
33
+ const eventData = event.data;
34
+ const status = eventData.status;
17
35
 
18
36
  switch (status) {
19
37
  case 'loading':
20
38
  setIsLoading(true);
21
39
  break;
22
40
  case 'success':
23
- setData(data);
41
+ setData(eventData.data);
24
42
  setError(undefined);
25
43
  setIsLoading(false);
26
44
  break;
27
45
  case 'error':
28
- setError(error);
46
+ setError(
47
+ eventData.userFacing
48
+ ? new UserFacingError(eventData.headline, eventData.error.message)
49
+ : eventData.error,
50
+ );
29
51
  setIsLoading(false);
30
52
  break;
31
53
  default:
@@ -1,14 +1,30 @@
1
+ import { type ErrorWorkerStatus, type LoadingWorkerStatus, type SuccessWorkerStatus } from './useWebWorker';
2
+ import { UserFacingError } from '../components/error-display';
3
+
1
4
  export async function workerFunction<R>(queryFunction: () => R) {
2
5
  try {
3
- postMessage({ status: 'loading' });
6
+ postMessage({ status: 'loading' } satisfies LoadingWorkerStatus);
4
7
 
5
8
  const workerResponse = await queryFunction();
6
9
 
7
10
  postMessage({
8
11
  status: 'success',
9
12
  data: workerResponse,
10
- });
13
+ } satisfies SuccessWorkerStatus<R>);
11
14
  } catch (error) {
12
- postMessage({ status: 'error', error });
15
+ postMessage(
16
+ (error instanceof UserFacingError
17
+ ? {
18
+ status: 'error',
19
+ userFacing: true,
20
+ headline: error.headline,
21
+ error,
22
+ }
23
+ : {
24
+ status: 'error',
25
+ userFacing: false,
26
+ error: error instanceof Error ? error : new Error(`${error}`),
27
+ }) satisfies ErrorWorkerStatus,
28
+ );
13
29
  }
14
30
  }