@databiosphere/findable-ui 16.0.0 → 17.0.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.
- package/.release-please-manifest.json +1 -1
- package/CHANGELOG.md +18 -0
- package/lib/components/Export/components/DownloadCurlCommand/downloadCurlCommand.d.ts +3 -2
- package/lib/components/Export/components/DownloadCurlCommand/downloadCurlCommand.js +6 -4
- package/lib/components/Export/components/ExportForm/components/ExportManifestDownloadFormatForm/exportManifestDownloadFormatForm.d.ts +3 -2
- package/lib/components/Export/components/ExportForm/components/ExportManifestDownloadFormatForm/exportManifestDownloadFormatForm.js +2 -12
- package/lib/components/Export/components/ExportToTerra/components/ExportToTerraForm/exportToTerraForm.d.ts +5 -2
- package/lib/components/Export/components/ExportToTerra/components/ExportToTerraForm/exportToTerraForm.js +2 -2
- package/lib/components/Export/components/ExportToTerra/components/ExportToTerraNotStarted/exportToTerraNotStarted.d.ts +3 -1
- package/lib/components/Export/components/ExportToTerra/components/ExportToTerraNotStarted/exportToTerraNotStarted.js +2 -2
- package/lib/components/Export/components/ExportToTerra/exportToTerra.d.ts +1 -1
- package/lib/components/Export/components/ExportToTerra/exportToTerra.js +9 -6
- package/lib/components/Export/components/ManifestDownload/components/ManifestDownloadEntity/manifestDownloadEntity.d.ts +3 -1
- package/lib/components/Export/components/ManifestDownload/components/ManifestDownloadEntity/manifestDownloadEntity.js +3 -4
- package/lib/components/Export/components/ManifestDownload/manifestDownload.d.ts +3 -2
- package/lib/components/Export/components/ManifestDownload/manifestDownload.js +6 -4
- package/lib/components/Links/components/Link/components/ExploreViewLink/exploreViewLink.js +4 -3
- package/lib/hooks/types.d.ts +4 -0
- package/lib/hooks/types.js +5 -0
- package/lib/hooks/useFileManifest/common/entities.d.ts +0 -5
- package/lib/hooks/useFileManifest/common/entities.js +0 -6
- package/lib/hooks/useFileManifest/useFileManifest.d.ts +8 -5
- package/lib/hooks/useFileManifest/useFileManifest.js +29 -8
- package/lib/hooks/useFileManifest/useFileManifestDownload.js +10 -9
- package/lib/hooks/useFileManifest/useFileManifestFormat.d.ts +12 -0
- package/lib/hooks/useFileManifest/useFileManifestFormat.js +10 -0
- package/lib/hooks/useRequestFileLocation.d.ts +1 -4
- package/lib/hooks/useRequestFileLocation.js +1 -5
- package/lib/hooks/useRequestManifest/constants.d.ts +2 -0
- package/lib/hooks/useRequestManifest/constants.js +4 -0
- package/lib/hooks/useRequestManifest/types.d.ts +6 -0
- package/lib/hooks/useRequestManifest/types.js +1 -0
- package/lib/hooks/useRequestManifest/useRequestManifest.d.ts +10 -0
- package/lib/hooks/useRequestManifest/useRequestManifest.js +30 -0
- package/lib/hooks/useRequestManifest/utils.d.ts +65 -0
- package/lib/hooks/useRequestManifest/utils.js +118 -0
- package/lib/mocks/useRequestFileManifest.mocks.d.ts +11 -0
- package/lib/mocks/useRequestFileManifest.mocks.js +100 -0
- package/lib/providers/fileManifestState/constants.d.ts +0 -2
- package/lib/providers/fileManifestState/constants.js +0 -11
- package/lib/providers/fileManifestState.d.ts +3 -25
- package/lib/providers/fileManifestState.js +3 -36
- package/lib/views/ExportView/exportView.js +2 -2
- package/package.json +1 -1
- package/src/components/Export/components/DownloadCurlCommand/downloadCurlCommand.tsx +17 -10
- package/src/components/Export/components/ExportForm/components/ExportManifestDownloadFormatForm/exportManifestDownloadFormatForm.tsx +7 -16
- package/src/components/Export/components/ExportToTerra/components/ExportToTerraForm/exportToTerraForm.tsx +8 -4
- package/src/components/Export/components/ExportToTerra/components/ExportToTerraNotStarted/exportToTerraNotStarted.tsx +4 -1
- package/src/components/Export/components/ExportToTerra/exportToTerra.tsx +13 -9
- package/src/components/Export/components/ManifestDownload/components/ManifestDownloadEntity/manifestDownloadEntity.tsx +4 -9
- package/src/components/Export/components/ManifestDownload/manifestDownload.tsx +17 -11
- package/src/components/Links/components/Link/components/ExploreViewLink/exploreViewLink.tsx +6 -3
- package/src/hooks/types.ts +4 -0
- package/src/hooks/useFileManifest/common/entities.ts +0 -6
- package/src/hooks/useFileManifest/useFileManifest.ts +34 -13
- package/src/hooks/useFileManifest/useFileManifestDownload.ts +21 -16
- package/src/hooks/useFileManifest/useFileManifestFormat.ts +23 -0
- package/src/hooks/useRequestFileLocation.ts +1 -5
- package/src/hooks/useRequestManifest/constants.ts +6 -0
- package/src/hooks/useRequestManifest/types.ts +7 -0
- package/src/hooks/useRequestManifest/useRequestManifest.ts +49 -0
- package/src/hooks/useRequestManifest/utils.ts +153 -0
- package/src/mocks/useRequestFileManifest.mocks.ts +121 -0
- package/src/providers/fileManifestState/constants.ts +0 -15
- package/src/providers/fileManifestState.tsx +5 -77
- package/src/views/ExportView/exportView.tsx +2 -2
- package/tests/buildRequestFilters.test.ts +68 -0
- package/tests/buildRequestManifest.test.ts +103 -0
- package/tests/useRequestManifest.test.ts +193 -0
- package/lib/hooks/useFileManifest/common/buildFileManifestRequestURL.d.ts +0 -15
- package/lib/hooks/useFileManifest/common/buildFileManifestRequestURL.js +0 -28
- package/lib/hooks/useFileManifest/useFileManifestURL.d.ts +0 -5
- package/lib/hooks/useFileManifest/useFileManifestURL.js +0 -11
- package/lib/hooks/useFileManifest/useRequestFileManifest.d.ts +0 -11
- package/lib/hooks/useFileManifest/useRequestFileManifest.js +0 -40
- package/lib/providers/fileManifestState/actions.d.ts +0 -9
- package/lib/providers/fileManifestState/actions.js +0 -19
- package/lib/providers/fileManifestState/utils.d.ts +0 -34
- package/lib/providers/fileManifestState/utils.js +0 -80
- package/src/hooks/useFileManifest/common/buildFileManifestRequestURL.ts +0 -44
- package/src/hooks/useFileManifest/useFileManifestURL.ts +0 -12
- package/src/hooks/useFileManifest/useRequestFileManifest.ts +0 -51
- package/src/providers/fileManifestState/actions.ts +0 -34
- package/src/providers/fileManifestState/utils.ts +0 -108
- package/tests/fileManifestRequestFilters.test.ts +0 -160
- package/tests/updateFilesFacetsStatus.test.ts +0 -84
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { Filters, SelectedFilter } from "../common/entities";
|
|
2
|
+
import { FormFacet } from "../components/Export/common/entities";
|
|
3
|
+
import { SiteConfig } from "../config/entities";
|
|
4
|
+
import { FileFacet } from "../hooks/useFileManifest/common/entities";
|
|
5
|
+
import { ConfigContextProps } from "../providers/config";
|
|
6
|
+
import { FileManifestState } from "../providers/fileManifestState";
|
|
7
|
+
|
|
8
|
+
export const CATALOG: string | undefined = "catalog";
|
|
9
|
+
|
|
10
|
+
const CATEGORY_KEY_NAME: Record<string, SelectedFilter["categoryKey"]> = {
|
|
11
|
+
CATEGORY_FILES: "files",
|
|
12
|
+
CATEGORY_OTHER: "other",
|
|
13
|
+
CATEGORY_SPECIES: "species",
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const CONFIG = {
|
|
17
|
+
config: { dataSource: { url: "https://mock-endpoint.com" } } as SiteConfig,
|
|
18
|
+
} as ConfigContextProps;
|
|
19
|
+
|
|
20
|
+
const FACET_PARTIAL: Pick<
|
|
21
|
+
FileFacet,
|
|
22
|
+
"selectedTerms" | "terms" | "termsByName" | "total"
|
|
23
|
+
> = {
|
|
24
|
+
selectedTerms: [],
|
|
25
|
+
terms: [],
|
|
26
|
+
termsByName: new Map(),
|
|
27
|
+
total: 0,
|
|
28
|
+
}; // `name`, `selected`, `selectedTermCount`, and `termCount` properties are not used in this test.
|
|
29
|
+
|
|
30
|
+
export const FILE_FACET: Record<string, FileFacet> = {
|
|
31
|
+
FACET_FILES: {
|
|
32
|
+
...FACET_PARTIAL,
|
|
33
|
+
name: CATEGORY_KEY_NAME.CATEGORY_FILES,
|
|
34
|
+
selected: false,
|
|
35
|
+
selectedTermCount: 0,
|
|
36
|
+
termCount: 2,
|
|
37
|
+
},
|
|
38
|
+
FACET_OTHER: {
|
|
39
|
+
...FACET_PARTIAL,
|
|
40
|
+
name: CATEGORY_KEY_NAME.CATEGORY_OTHER,
|
|
41
|
+
selected: false,
|
|
42
|
+
selectedTermCount: 0,
|
|
43
|
+
termCount: 1,
|
|
44
|
+
},
|
|
45
|
+
FACET_SPECIES: {
|
|
46
|
+
...FACET_PARTIAL,
|
|
47
|
+
name: CATEGORY_KEY_NAME.CATEGORY_SPECIES,
|
|
48
|
+
selected: false,
|
|
49
|
+
selectedTermCount: 0,
|
|
50
|
+
termCount: 3,
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const FILTER_FILES: SelectedFilter = {
|
|
55
|
+
categoryKey: CATEGORY_KEY_NAME.CATEGORY_FILES,
|
|
56
|
+
value: ["file01", "file02"],
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const FILTER_FILES_SUBSET: SelectedFilter = {
|
|
60
|
+
categoryKey: CATEGORY_KEY_NAME.CATEGORY_FILES,
|
|
61
|
+
value: ["file01"],
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const FILTER_OTHER: SelectedFilter = {
|
|
65
|
+
categoryKey: CATEGORY_KEY_NAME.CATEGORY_OTHER,
|
|
66
|
+
value: ["other"],
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
const FILTER_SPECIES: SelectedFilter = {
|
|
70
|
+
categoryKey: CATEGORY_KEY_NAME.CATEGORY_SPECIES,
|
|
71
|
+
value: ["species01", "species02", "species03"],
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
export const FILTERS: Record<string, Filters> = {
|
|
75
|
+
FORM_COMPLETE_SET: [FILTER_FILES, FILTER_OTHER, FILTER_SPECIES],
|
|
76
|
+
FORM_INCOMPLETE_SET: [FILTER_FILES, FILTER_OTHER],
|
|
77
|
+
FORM_INITIAL_SET: [FILTER_OTHER],
|
|
78
|
+
FORM_SUBSET: [FILTER_FILES_SUBSET, FILTER_OTHER, FILTER_SPECIES],
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export const FILE_MANIFEST_STATE = {
|
|
82
|
+
filters: FILTERS.FORM_INITIAL_SET,
|
|
83
|
+
isEnabled: true,
|
|
84
|
+
isLoading: false,
|
|
85
|
+
} as FileManifestState;
|
|
86
|
+
|
|
87
|
+
export const FORM_FACET: Record<string, FormFacet> = {
|
|
88
|
+
COMPLETE_SET: {
|
|
89
|
+
fileSummaryFacet: {
|
|
90
|
+
...FILE_FACET.FACET_FILES,
|
|
91
|
+
selected: true,
|
|
92
|
+
selectedTermCount: FILE_FACET.FACET_FILES.termCount, // All terms selected.
|
|
93
|
+
},
|
|
94
|
+
speciesFacet: {
|
|
95
|
+
...FILE_FACET.FACET_SPECIES,
|
|
96
|
+
selected: true,
|
|
97
|
+
selectedTermCount: FILE_FACET.FACET_SPECIES.termCount, // All terms selected.
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
INCOMPLETE_SET: {
|
|
101
|
+
fileSummaryFacet: {
|
|
102
|
+
...FILE_FACET.FACET_FILES,
|
|
103
|
+
selected: true,
|
|
104
|
+
selectedTermCount: FILE_FACET.FACET_FILES.termCount, // All terms selected.
|
|
105
|
+
},
|
|
106
|
+
speciesFacet: FILE_FACET.FACET_SPECIES, // Species facet is unselected.
|
|
107
|
+
},
|
|
108
|
+
INITIAL_SET: { fileSummaryFacet: undefined, speciesFacet: undefined },
|
|
109
|
+
SUBSET: {
|
|
110
|
+
fileSummaryFacet: {
|
|
111
|
+
...FILE_FACET.FACET_FILES,
|
|
112
|
+
selected: true,
|
|
113
|
+
selectedTermCount: 1, // One of a possible two terms selected.
|
|
114
|
+
},
|
|
115
|
+
speciesFacet: {
|
|
116
|
+
...FILE_FACET.FACET_SPECIES,
|
|
117
|
+
selected: true,
|
|
118
|
+
selectedTermCount: 1, // One of a possible three terms selected.
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
@@ -1,23 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
FILE_MANIFEST_TYPE,
|
|
3
|
-
FILES_FACETS_STATUS,
|
|
4
|
-
} from "../../hooks/useFileManifest/common/entities";
|
|
5
1
|
import { FileManifestState } from "../fileManifestState";
|
|
6
2
|
|
|
7
|
-
export const ENTITIES_FILE_MANIFEST_TYPES: FILE_MANIFEST_TYPE[] = [
|
|
8
|
-
FILE_MANIFEST_TYPE.BULK_DOWNLOAD,
|
|
9
|
-
FILE_MANIFEST_TYPE.DOWNLOAD_MANIFEST,
|
|
10
|
-
FILE_MANIFEST_TYPE.EXPORT_TO_TERRA,
|
|
11
|
-
];
|
|
12
|
-
|
|
13
3
|
export const FILE_MANIFEST_STATE: FileManifestState = {
|
|
14
|
-
fileManifestFormat: undefined,
|
|
15
|
-
fileManifestType: undefined,
|
|
16
4
|
fileSummary: undefined,
|
|
17
5
|
fileSummaryFacetName: undefined,
|
|
18
6
|
fileSummaryFilters: [],
|
|
19
7
|
filesFacets: [],
|
|
20
|
-
filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
|
|
21
8
|
filters: [],
|
|
22
9
|
isEnabled: false,
|
|
23
10
|
isFacetsLoading: false,
|
|
@@ -25,7 +12,5 @@ export const FILE_MANIFEST_STATE: FileManifestState = {
|
|
|
25
12
|
isFileSummaryLoading: false,
|
|
26
13
|
isLoading: false,
|
|
27
14
|
isSummaryLoading: false,
|
|
28
|
-
requestParams: undefined,
|
|
29
|
-
requestURL: undefined,
|
|
30
15
|
summary: undefined,
|
|
31
16
|
};
|
|
@@ -5,10 +5,7 @@ import React, {
|
|
|
5
5
|
useEffect,
|
|
6
6
|
useReducer,
|
|
7
7
|
} from "react";
|
|
8
|
-
import {
|
|
9
|
-
AzulSummaryResponse,
|
|
10
|
-
ManifestDownloadFormat,
|
|
11
|
-
} from "../apis/azul/common/entities";
|
|
8
|
+
import { AzulSummaryResponse } from "../apis/azul/common/entities";
|
|
12
9
|
import { getFilterParameterValue } from "../apis/azul/common/utils";
|
|
13
10
|
import {
|
|
14
11
|
CategoryKey,
|
|
@@ -18,27 +15,16 @@ import {
|
|
|
18
15
|
} from "../common/entities";
|
|
19
16
|
import { useCatalog } from "../hooks/useCatalog";
|
|
20
17
|
import { buildNextFilterState } from "../hooks/useCategoryFilter";
|
|
21
|
-
import {
|
|
22
|
-
import {
|
|
23
|
-
FileFacet,
|
|
24
|
-
FileManifestType,
|
|
25
|
-
FILES_FACETS_STATUS,
|
|
26
|
-
} from "../hooks/useFileManifest/common/entities";
|
|
18
|
+
import { FileFacet } from "../hooks/useFileManifest/common/entities";
|
|
27
19
|
import { useFetchFilesFacets } from "../hooks/useFileManifest/useFetchFilesFacets";
|
|
28
20
|
import { useFetchSummary } from "../hooks/useFileManifest/useFetchSummary";
|
|
29
|
-
import { useFileManifestURL } from "../hooks/useFileManifest/useFileManifestURL";
|
|
30
|
-
import { updateFileManifestAction } from "./fileManifestState/actions";
|
|
31
21
|
import { FILE_MANIFEST_STATE } from "./fileManifestState/constants";
|
|
32
|
-
import { getRequestFilters } from "./fileManifestState/utils";
|
|
33
22
|
|
|
34
23
|
/**
|
|
35
24
|
* File manifest state.
|
|
36
25
|
*/
|
|
37
26
|
export type FileManifestState = {
|
|
38
|
-
fileManifestFormat?: ManifestDownloadFormat;
|
|
39
|
-
fileManifestType?: FileManifestType;
|
|
40
27
|
filesFacets: FileFacet[];
|
|
41
|
-
filesFacetsStatus: FILES_FACETS_STATUS;
|
|
42
28
|
fileSummary?: AzulSummaryResponse;
|
|
43
29
|
fileSummaryFacetName?: string;
|
|
44
30
|
fileSummaryFilters: Filters;
|
|
@@ -49,8 +35,6 @@ export type FileManifestState = {
|
|
|
49
35
|
isFileSummaryLoading: boolean;
|
|
50
36
|
isLoading: boolean;
|
|
51
37
|
isSummaryLoading: boolean;
|
|
52
|
-
requestParams?: URLSearchParams;
|
|
53
|
-
requestURL?: string;
|
|
54
38
|
summary?: AzulSummaryResponse;
|
|
55
39
|
};
|
|
56
40
|
|
|
@@ -79,13 +63,9 @@ export function FileManifestStateProvider({
|
|
|
79
63
|
// Determine catalog.
|
|
80
64
|
const catalog = useCatalog() as string; // catalog should be defined.
|
|
81
65
|
|
|
82
|
-
// Determine file manifest request data URL.
|
|
83
|
-
const URL = useFileManifestURL();
|
|
84
|
-
|
|
85
66
|
// File manifest state.
|
|
86
67
|
const [fileManifestState, fileManifestDispatch] = useReducer(
|
|
87
|
-
(s: FileManifestState, a: FileManifestAction) =>
|
|
88
|
-
fileManifestReducer(s, a, { URL, catalog }),
|
|
68
|
+
(s: FileManifestState, a: FileManifestAction) => fileManifestReducer(s, a),
|
|
89
69
|
FILE_MANIFEST_STATE
|
|
90
70
|
);
|
|
91
71
|
|
|
@@ -154,7 +134,6 @@ export enum FileManifestActionKind {
|
|
|
154
134
|
ClearFileManifest = "CLEAR_FILE_MANIFEST",
|
|
155
135
|
FetchFileManifest = "FETCH_FILE_MANIFEST",
|
|
156
136
|
UpdateFileManifest = "UPDATE_FILE_MANIFEST",
|
|
157
|
-
UpdateFileManifestFormat = "UPDATE_FILE_MANIFEST_FORMAT",
|
|
158
137
|
UpdateFilter = "UPDATE_FILTER",
|
|
159
138
|
UpdateFiltersCategory = "UPDATE_FILTERS_CATEGORY",
|
|
160
139
|
}
|
|
@@ -166,7 +145,6 @@ export type FileManifestAction =
|
|
|
166
145
|
| ClearFileManifestAction
|
|
167
146
|
| FetchFileManifestAction
|
|
168
147
|
| UpdateFileManifestAction
|
|
169
|
-
| UpdateFileManifestFormatAction
|
|
170
148
|
| UpdateFilterAction
|
|
171
149
|
| UpdateFiltersCategoryAction;
|
|
172
150
|
|
|
@@ -194,14 +172,6 @@ type UpdateFileManifestAction = {
|
|
|
194
172
|
type: FileManifestActionKind.UpdateFileManifest;
|
|
195
173
|
};
|
|
196
174
|
|
|
197
|
-
/**
|
|
198
|
-
* Update file manifest format action.
|
|
199
|
-
*/
|
|
200
|
-
type UpdateFileManifestFormatAction = {
|
|
201
|
-
payload: ManifestDownloadFormat | undefined;
|
|
202
|
-
type: FileManifestActionKind.UpdateFileManifestFormat;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
175
|
/**
|
|
206
176
|
* Update filter action.
|
|
207
177
|
*/
|
|
@@ -222,8 +192,6 @@ type UpdateFiltersCategoryAction = {
|
|
|
222
192
|
* Initialize file manifest payload.
|
|
223
193
|
*/
|
|
224
194
|
type FetchFileManifestPayload = {
|
|
225
|
-
fileManifestFormat?: ManifestDownloadFormat;
|
|
226
|
-
fileManifestType?: FileManifestType;
|
|
227
195
|
fileSummaryFacetName?: string;
|
|
228
196
|
filters: Filters;
|
|
229
197
|
};
|
|
@@ -251,38 +219,23 @@ export type UpdateFilterPayload = {
|
|
|
251
219
|
selectedValue: CategoryValueKey;
|
|
252
220
|
};
|
|
253
221
|
|
|
254
|
-
/**
|
|
255
|
-
* File manifest context.
|
|
256
|
-
*/
|
|
257
|
-
export interface FileManifestContext {
|
|
258
|
-
catalog: string;
|
|
259
|
-
URL: string;
|
|
260
|
-
}
|
|
261
|
-
|
|
262
222
|
/**
|
|
263
223
|
* File manifest reducer.
|
|
264
224
|
* @param state - File manifest state.
|
|
265
225
|
* @param action - File manifest action.
|
|
266
|
-
* @param fileManifestContext - File manifest context.
|
|
267
226
|
* @returns file manifest state.
|
|
268
227
|
*/
|
|
269
228
|
function fileManifestReducer(
|
|
270
229
|
state: FileManifestState,
|
|
271
|
-
action: FileManifestAction
|
|
272
|
-
fileManifestContext: FileManifestContext
|
|
230
|
+
action: FileManifestAction
|
|
273
231
|
): FileManifestState {
|
|
274
232
|
const { payload, type } = action;
|
|
275
|
-
const { catalog, URL } = fileManifestContext;
|
|
276
233
|
switch (type) {
|
|
277
234
|
// Resets file manifest.
|
|
278
235
|
case FileManifestActionKind.ClearFileManifest: {
|
|
279
236
|
return {
|
|
280
237
|
...state,
|
|
281
|
-
fileManifestFormat: undefined,
|
|
282
|
-
filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
|
|
283
238
|
isEnabled: false,
|
|
284
|
-
requestParams: undefined,
|
|
285
|
-
requestURL: undefined,
|
|
286
239
|
};
|
|
287
240
|
}
|
|
288
241
|
// Fetches file manifest.
|
|
@@ -297,30 +250,11 @@ function fileManifestReducer(
|
|
|
297
250
|
...payload,
|
|
298
251
|
fileSummaryFilters,
|
|
299
252
|
isEnabled: true,
|
|
300
|
-
requestParams: undefined,
|
|
301
|
-
requestURL: undefined,
|
|
302
253
|
};
|
|
303
254
|
}
|
|
304
255
|
// Updates file manifest.
|
|
305
256
|
case FileManifestActionKind.UpdateFileManifest: {
|
|
306
|
-
return
|
|
307
|
-
}
|
|
308
|
-
// Updates file manifest format.
|
|
309
|
-
case FileManifestActionKind.UpdateFileManifestFormat: {
|
|
310
|
-
// Build request params and request URL.
|
|
311
|
-
const { requestParams, requestURL } =
|
|
312
|
-
buildFileManifestRequestURL(
|
|
313
|
-
URL,
|
|
314
|
-
getRequestFilters(state),
|
|
315
|
-
catalog,
|
|
316
|
-
payload
|
|
317
|
-
) || {};
|
|
318
|
-
return {
|
|
319
|
-
...state,
|
|
320
|
-
fileManifestFormat: payload,
|
|
321
|
-
requestParams,
|
|
322
|
-
requestURL,
|
|
323
|
-
};
|
|
257
|
+
return { ...state, ...payload };
|
|
324
258
|
}
|
|
325
259
|
// Updates selected file manifest filters with given selected category value.
|
|
326
260
|
case FileManifestActionKind.UpdateFilter: {
|
|
@@ -339,10 +273,7 @@ function fileManifestReducer(
|
|
|
339
273
|
return {
|
|
340
274
|
...state,
|
|
341
275
|
fileSummaryFilters,
|
|
342
|
-
filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
|
|
343
276
|
filters,
|
|
344
|
-
requestParams: undefined,
|
|
345
|
-
requestURL: undefined,
|
|
346
277
|
};
|
|
347
278
|
}
|
|
348
279
|
// Updates selected file manifest filters by category.
|
|
@@ -361,10 +292,7 @@ function fileManifestReducer(
|
|
|
361
292
|
return {
|
|
362
293
|
...state,
|
|
363
294
|
fileSummaryFilters,
|
|
364
|
-
filesFacetsStatus: FILES_FACETS_STATUS.NOT_STARTED,
|
|
365
295
|
filters,
|
|
366
|
-
requestParams: undefined,
|
|
367
|
-
requestURL: undefined,
|
|
368
296
|
};
|
|
369
297
|
}
|
|
370
298
|
default:
|
|
@@ -4,7 +4,7 @@ import { ComponentCreator } from "../../components/ComponentCreator/ComponentCre
|
|
|
4
4
|
import { BackPageView } from "../../components/Layout/components/BackPage/backPageView";
|
|
5
5
|
import { useExploreState } from "../../hooks/useExploreState";
|
|
6
6
|
import { useExportConfig } from "../../hooks/useExportConfig";
|
|
7
|
-
import {
|
|
7
|
+
import { useFileManifest } from "../../hooks/useFileManifest/useFileManifest";
|
|
8
8
|
import { useUpdateURLSearchParams } from "../../hooks/useUpdateURLSearchParams";
|
|
9
9
|
|
|
10
10
|
export type ExportViewProps = AzulEntityStaticResponse;
|
|
@@ -14,7 +14,7 @@ export const ExportView = (props: ExportViewProps): JSX.Element => {
|
|
|
14
14
|
exploreState: { filterState },
|
|
15
15
|
} = useExploreState();
|
|
16
16
|
useUpdateURLSearchParams();
|
|
17
|
-
|
|
17
|
+
useFileManifest(filterState, undefined);
|
|
18
18
|
const { tabs, top } = useExportConfig();
|
|
19
19
|
const currentTab = tabs[0];
|
|
20
20
|
const { mainColumn, sideColumn } = currentTab;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Filters } from "../src/common/entities";
|
|
2
|
+
import { buildRequestFilters } from "../src/hooks/useRequestManifest/utils";
|
|
3
|
+
import {
|
|
4
|
+
FILE_MANIFEST_STATE,
|
|
5
|
+
FILTERS,
|
|
6
|
+
FORM_FACET,
|
|
7
|
+
} from "../src/mocks/useRequestFileManifest.mocks";
|
|
8
|
+
import { FileManifestState } from "../src/providers/fileManifestState";
|
|
9
|
+
|
|
10
|
+
describe("buildRequestFilters", () => {
|
|
11
|
+
describe("should return filters from file manifest state", () => {
|
|
12
|
+
test("when form facet is not defined", () => {
|
|
13
|
+
const fileManifestState = getFileManifestState(FILTERS.FORM_INITIAL_SET);
|
|
14
|
+
const result = buildRequestFilters(fileManifestState, {});
|
|
15
|
+
expect(result).toEqual(fileManifestState.filters);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test("when form facet `fileSummaryFacet` and `speciesFacet` are not defined", () => {
|
|
19
|
+
const fileManifestState = getFileManifestState(FILTERS.FORM_INITIAL_SET);
|
|
20
|
+
const result = buildRequestFilters(
|
|
21
|
+
fileManifestState,
|
|
22
|
+
FORM_FACET.INITIAL_SET
|
|
23
|
+
);
|
|
24
|
+
expect(result).toEqual(fileManifestState.filters);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
test("when at least one form facet has no terms selected", () => {
|
|
28
|
+
const fileManifestState = getFileManifestState(
|
|
29
|
+
FILTERS.FORM_INCOMPLETE_SET
|
|
30
|
+
);
|
|
31
|
+
const result = buildRequestFilters(
|
|
32
|
+
fileManifestState,
|
|
33
|
+
FORM_FACET.INCOMPLETE_SET
|
|
34
|
+
);
|
|
35
|
+
expect(result).toEqual(fileManifestState.filters);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
test("when at least one form facet has an unselected term", () => {
|
|
39
|
+
const fileManifestState = getFileManifestState(FILTERS.FORM_SUBSET);
|
|
40
|
+
const result = buildRequestFilters(fileManifestState, FORM_FACET.SUBSET);
|
|
41
|
+
expect(result).toEqual(fileManifestState.filters);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe("should return filters excluding form related filters", () => {
|
|
46
|
+
test("when all form facets have all their terms selected", () => {
|
|
47
|
+
const fileManifestState = getFileManifestState(FILTERS.FORM_COMPLETE_SET);
|
|
48
|
+
const result = buildRequestFilters(
|
|
49
|
+
fileManifestState,
|
|
50
|
+
FORM_FACET.COMPLETE_SET
|
|
51
|
+
);
|
|
52
|
+
expect(result).not.toEqual(fileManifestState.filters);
|
|
53
|
+
expect(result).toEqual(FILTERS.FORM_INITIAL_SET);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns a file manifest state with the given filters.
|
|
60
|
+
* @param filters - Selected filters.
|
|
61
|
+
* @returns file manifest state.
|
|
62
|
+
*/
|
|
63
|
+
function getFileManifestState(filters: Filters): FileManifestState {
|
|
64
|
+
return {
|
|
65
|
+
...FILE_MANIFEST_STATE,
|
|
66
|
+
filters,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MANIFEST_DOWNLOAD_FORMAT,
|
|
3
|
+
ManifestDownloadFormat,
|
|
4
|
+
} from "../src/apis/azul/common/entities";
|
|
5
|
+
import { transformFilters } from "../src/apis/azul/common/filterTransformer";
|
|
6
|
+
import { Filters } from "../src/common/entities";
|
|
7
|
+
import { METHOD } from "../src/hooks/types";
|
|
8
|
+
import { buildRequestManifest } from "../src/hooks/useRequestManifest/utils";
|
|
9
|
+
import { FILTERS } from "../src/mocks/useRequestFileManifest.mocks";
|
|
10
|
+
|
|
11
|
+
const ENDPOINT_URL = "https://example.com/";
|
|
12
|
+
const CATALOG = "test-catalog";
|
|
13
|
+
const MANIFEST_FORMAT = MANIFEST_DOWNLOAD_FORMAT.VERBATIM_PFB;
|
|
14
|
+
|
|
15
|
+
describe("buildRequestManifest", () => {
|
|
16
|
+
test("should return request method 'PUT'", () => {
|
|
17
|
+
const result = buildRequestManifest(
|
|
18
|
+
ENDPOINT_URL,
|
|
19
|
+
CATALOG,
|
|
20
|
+
FILTERS.FORM_SUBSET,
|
|
21
|
+
MANIFEST_FORMAT
|
|
22
|
+
);
|
|
23
|
+
expect(result.requestMethod).toEqual(METHOD.PUT);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test("should return defined request params and request url", () => {
|
|
27
|
+
const result = buildRequestManifest(
|
|
28
|
+
ENDPOINT_URL,
|
|
29
|
+
CATALOG,
|
|
30
|
+
FILTERS.FORM_SUBSET,
|
|
31
|
+
MANIFEST_FORMAT
|
|
32
|
+
);
|
|
33
|
+
expect(result.requestParams).toBeDefined();
|
|
34
|
+
expect(result.requestUrl).toBeDefined();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test("should return request params with entries 'catalog', 'filters' and 'format'", () => {
|
|
38
|
+
const result = buildRequestManifest(
|
|
39
|
+
ENDPOINT_URL,
|
|
40
|
+
CATALOG,
|
|
41
|
+
FILTERS.FORM_SUBSET,
|
|
42
|
+
MANIFEST_FORMAT
|
|
43
|
+
);
|
|
44
|
+
// Assert that the requestParams contains the required keys.
|
|
45
|
+
expect(result.requestParams?.has("catalog")).toBeTruthy();
|
|
46
|
+
expect(result.requestParams?.has("filters")).toBeTruthy();
|
|
47
|
+
expect(result.requestParams?.has("format")).toBeTruthy();
|
|
48
|
+
// // Assert the values of these keys.
|
|
49
|
+
expect(result.requestParams?.get("catalog")).toEqual(CATALOG);
|
|
50
|
+
expect(result.requestParams?.get("filters")).toEqual(
|
|
51
|
+
transformFilters(FILTERS.FORM_SUBSET)
|
|
52
|
+
);
|
|
53
|
+
expect(result.requestParams?.get("format")).toEqual(MANIFEST_FORMAT);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("should return expected request URL", () => {
|
|
57
|
+
const result = buildRequestManifest(
|
|
58
|
+
ENDPOINT_URL,
|
|
59
|
+
CATALOG,
|
|
60
|
+
FILTERS.FORM_INITIAL_SET,
|
|
61
|
+
MANIFEST_FORMAT
|
|
62
|
+
);
|
|
63
|
+
const expectedParams = getExpectedParams(
|
|
64
|
+
CATALOG,
|
|
65
|
+
FILTERS.FORM_INITIAL_SET,
|
|
66
|
+
MANIFEST_FORMAT
|
|
67
|
+
);
|
|
68
|
+
const expectedUrl = getExpectedUrl(expectedParams);
|
|
69
|
+
expect(result.requestUrl).toEqual(expectedUrl);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* Returns the expected URLSearchParams for the given parameters.
|
|
75
|
+
* @param catalog - Catalog.
|
|
76
|
+
* @param filters - Selected filters.
|
|
77
|
+
* @param manifestFormat - Manifest format.
|
|
78
|
+
* @returns URLSearchParams.
|
|
79
|
+
*/
|
|
80
|
+
function getExpectedParams(
|
|
81
|
+
catalog: string,
|
|
82
|
+
filters: Filters,
|
|
83
|
+
manifestFormat: ManifestDownloadFormat
|
|
84
|
+
): URLSearchParams {
|
|
85
|
+
return new URLSearchParams({
|
|
86
|
+
catalog,
|
|
87
|
+
filters: transformFilters(filters),
|
|
88
|
+
format: manifestFormat,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Returns the expected URL for the given parameters.
|
|
94
|
+
* @param expectedParams - Expected URLSearchParams.
|
|
95
|
+
* @param endpointUrl - Data URL.
|
|
96
|
+
* @returns expected URL.
|
|
97
|
+
*/
|
|
98
|
+
function getExpectedUrl(
|
|
99
|
+
expectedParams: URLSearchParams,
|
|
100
|
+
endpointUrl: string = ENDPOINT_URL
|
|
101
|
+
): string {
|
|
102
|
+
return `${endpointUrl}fetch/manifest/files?${expectedParams.toString()}`;
|
|
103
|
+
}
|