|
1 | | -import { |
2 | | - assertArrayShape, |
3 | | - assertDefined, |
4 | | - hasNumericType, |
5 | | -} from '@h5web/shared/guards'; |
| 1 | +import { assertArrayShape, assertDefined } from '@h5web/shared/guards'; |
6 | 2 | import { |
7 | 3 | type ArrayShape, |
8 | | - type ArrayValue, |
9 | 4 | type AttributeValues, |
10 | 5 | type Dataset, |
11 | 6 | type Entity, |
12 | 7 | type GroupWithChildren, |
13 | | - type NumericType, |
14 | 8 | type ProvidedEntity, |
15 | | - type Value, |
16 | 9 | } from '@h5web/shared/hdf5-models'; |
17 | 10 | import { |
18 | 11 | assertMockAttribute, |
19 | 12 | assertMockDataset, |
20 | 13 | } from '@h5web/shared/mock-utils'; |
21 | | - |
22 | | -import { DataProviderApi } from '../api'; |
23 | 14 | import { |
| 15 | + type BuiltInExporter, |
24 | 16 | type ExportFormat, |
25 | 17 | type ExportURL, |
26 | | - type ValuesStoreParams, |
27 | | -} from '../models'; |
| 18 | +} from '@h5web/shared/vis-models'; |
| 19 | + |
| 20 | +import { DataProviderApi } from '../api'; |
| 21 | +import { type ValuesStoreParams } from '../models'; |
28 | 22 | import { makeMockFile } from './mock-file'; |
29 | 23 | import { |
30 | 24 | cancellableDelay, |
@@ -99,45 +93,35 @@ export class MockApi extends DataProviderApi { |
99 | 93 | ); |
100 | 94 | } |
101 | 95 |
|
102 | | - public override getExportURL<D extends Dataset<ArrayShape>>( |
| 96 | + public override getExportURL( |
103 | 97 | format: ExportFormat, |
104 | | - dataset: D, |
105 | | - selection: string | undefined, |
106 | | - value: Value<D>, |
107 | | - ): ExportURL { |
108 | | - const url = this._getExportURL?.(format, dataset, selection, value); |
| 98 | + dataset: Dataset<ArrayShape>, |
| 99 | + selection?: string, |
| 100 | + builtInExporter?: BuiltInExporter, |
| 101 | + ): ExportURL | undefined { |
| 102 | + const url = this._getExportURL?.( |
| 103 | + format, |
| 104 | + dataset, |
| 105 | + selection, |
| 106 | + builtInExporter, |
| 107 | + ); |
| 108 | + |
109 | 109 | if (url) { |
110 | 110 | return url; |
111 | 111 | } |
112 | 112 |
|
113 | | - if (format === 'json') { |
114 | | - return async () => { |
115 | | - const json = JSON.stringify(value, null, 2); |
116 | | - return new Blob([json]); |
117 | | - }; |
| 113 | + if (!builtInExporter) { |
| 114 | + return undefined; |
118 | 115 | } |
119 | 116 |
|
120 | | - if ( |
121 | | - hasNumericType(dataset) && |
122 | | - selection === undefined && |
123 | | - format === 'csv' |
124 | | - ) { |
125 | | - return async () => { |
126 | | - let csv = ''; |
127 | | - (value as ArrayValue<NumericType>).forEach((val) => { |
128 | | - csv += `${val.toString()}\n`; |
129 | | - }); |
130 | | - |
131 | | - const finalCsv = csv.slice(0, -2); |
132 | | - |
133 | | - // Demonstrate both `Blob` and `URL` techniques (cf. `src/providers/api.ts`) |
134 | | - return dataset.name === 'oneD' |
135 | | - ? new Blob([finalCsv]) |
136 | | - : new URL(`data:text/plain,${encodeURIComponent(finalCsv)}`); |
137 | | - }; |
138 | | - } |
| 117 | + return async () => { |
| 118 | + const csv = builtInExporter(); |
139 | 119 |
|
140 | | - return undefined; |
| 120 | + // Demonstrate both `Blob` and `URL` techniques (cf. `src/providers/api.ts`) |
| 121 | + return dataset.name === 'oneD' |
| 122 | + ? new Blob([csv]) |
| 123 | + : new URL(`data:text/plain,${encodeURIComponent(csv)}`); |
| 124 | + }; |
141 | 125 | } |
142 | 126 |
|
143 | 127 | public override async getSearchablePaths(path: string): Promise<string[]> { |
|
0 commit comments