@data-fair/lib-vue 1.22.0 → 1.23.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/concept-filters.d.ts +1 -0
- package/concept-filters.js +16 -12
- package/package.json +1 -1
package/concept-filters.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
export declare function getConceptFilters(searchParams: Record<string, string>, datasetId?: string): Record<string, string>;
|
|
1
2
|
export declare function useConceptFilters(reactiveSearchParams: Record<string, string>, datasetId?: string): Record<string, string>;
|
|
2
3
|
export default useConceptFilters;
|
package/concept-filters.js
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
// filter reactiveSearchParams to conceptFilters (params prefixed by _c_)
|
|
2
2
|
import { reactive, watch } from 'vue';
|
|
3
|
+
export function getConceptFilters(searchParams, datasetId) {
|
|
4
|
+
const conceptFilters = {};
|
|
5
|
+
const datasetFiltersPrefix = datasetId && `_d_${datasetId}_`;
|
|
6
|
+
for (const key of Object.keys(searchParams)) {
|
|
7
|
+
if (key.startsWith('_c_'))
|
|
8
|
+
conceptFilters[key] = searchParams[key];
|
|
9
|
+
if (datasetFiltersPrefix && key.startsWith(datasetFiltersPrefix)) {
|
|
10
|
+
conceptFilters[key.replace(datasetFiltersPrefix, '')] = searchParams[key];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return conceptFilters;
|
|
14
|
+
}
|
|
3
15
|
export function useConceptFilters(reactiveSearchParams, datasetId) {
|
|
4
16
|
const conceptFilters = reactive({});
|
|
5
|
-
|
|
17
|
+
// we use a watch and mutations on a reactive to prevent triggering reactivity on unrelated changes in reactive search params
|
|
6
18
|
watch(reactiveSearchParams, () => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
conceptFilters[key] = reactiveSearchParams[key];
|
|
10
|
-
if (datasetFiltersPrefix && key.startsWith(datasetFiltersPrefix)) {
|
|
11
|
-
conceptFilters[key.replace(datasetFiltersPrefix, '')] = reactiveSearchParams[key];
|
|
12
|
-
}
|
|
13
|
-
}
|
|
19
|
+
const newConceptFilters = getConceptFilters(reactiveSearchParams, datasetId);
|
|
20
|
+
Object.assign(conceptFilters, newConceptFilters);
|
|
14
21
|
for (const key of Object.keys(conceptFilters)) {
|
|
15
|
-
if (
|
|
16
|
-
delete conceptFilters[key];
|
|
17
|
-
if (datasetFiltersPrefix && !key.startsWith('_c_') && reactiveSearchParams[datasetFiltersPrefix + key] === undefined) {
|
|
22
|
+
if (!(key in newConceptFilters))
|
|
18
23
|
delete conceptFilters[key];
|
|
19
|
-
}
|
|
20
24
|
}
|
|
21
25
|
}, { immediate: true });
|
|
22
26
|
return conceptFilters;
|