@datagouv/components-next 1.0.2-dev.65 → 1.0.2-dev.67

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.
@@ -1,4 +1,4 @@
1
- import { c as Ke } from "./main-BoFCVekJ.js";
1
+ import { c as Ke } from "./main-vXPsdhWv.js";
2
2
  import We from "vue";
3
3
  function Fe(I, K) {
4
4
  for (var V = 0; V < K.length; V++) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@datagouv/components-next",
3
- "version": "1.0.2-dev.65",
3
+ "version": "1.0.2-dev.67",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -356,7 +356,7 @@ import { RiBookShelfLine, RiBuilding2Line, RiCloseCircleLine, RiDatabase2Line, R
356
356
  import magnifyingGlassSrc from '../../../assets/illustrations/magnifying_glass.svg?url'
357
357
  import { useTranslation } from '../../composables/useTranslation'
358
358
  import { useDebouncedRef } from '../../composables/useDebouncedRef'
359
- import { forEachActiveCustomFilter, isCustomFilterActive, searchFilterContextKey, type CustomFilterEntry } from '../../composables/useSearchFilter'
359
+ import { configKey, forEachActiveCustomFilter, isCustomFilterActive, searchFilterContextKey, type CustomFilterEntry } from '../../composables/useSearchFilter'
360
360
  import { useStableQueryParams } from '../../composables/useStableQueryParams'
361
361
  import { useComponentsConfig } from '../../config'
362
362
  import { useFetch } from '../../functions/api'
@@ -366,7 +366,7 @@ import type { Dataservice } from '../../types/dataservices'
366
366
  import type { Organization } from '../../types/organizations'
367
367
  import type { Reuse } from '../../types/reuses'
368
368
  import type { TopicV2 } from '../../types/topics'
369
- import type { GlobalSearchConfig, SearchResponseByClass, SearchType, SearchTypeConfig, SortOption, FacetItem } from '../../types/search'
369
+ import type { GlobalSearchConfig, SearchResponseByClass, SearchType, SortOption, FacetItem } from '../../types/search'
370
370
  import { getDefaultGlobalSearchConfig } from '../../types/search'
371
371
  import BrandedButton from '../BrandedButton.vue'
372
372
  import LoadingBlock from '../LoadingBlock.vue'
@@ -406,8 +406,6 @@ const props = withDefaults(defineProps<{
406
406
  hideSearchInput: false,
407
407
  })
408
408
 
409
- const configKey = (c: SearchTypeConfig) => c.key ?? c.class
410
-
411
409
  // defineModel's default is static and can't depend on props, so we cast and initialize manually
412
410
  const currentType = defineModel<string>('type') as Ref<string>
413
411
  if (!currentType.value) currentType.value = configKey(props.config[0] ?? { class: 'datasets' })
@@ -742,7 +740,7 @@ const rssUrl = computed(() => {
742
740
 
743
741
  forEachActiveCustomFilter(customFilterRegistry, (apiParam, value) => {
744
742
  params.set(apiParam, value)
745
- })
743
+ }, currentTypeConfig.value ? configKey(currentTypeConfig.value) : undefined)
746
744
 
747
745
  // Add sort if set
748
746
  if (sort.value) params.set('sort', sort.value)
@@ -1,11 +1,17 @@
1
1
  import { type InjectionKey, type Ref, inject, onMounted, onScopeDispose } from 'vue'
2
2
  import { useRoute, useRouter } from 'vue-router'
3
3
  import { useRouteQuery } from '@vueuse/router'
4
+ import type { SearchTypeConfig } from '../types/search'
5
+
6
+ export function configKey(c: SearchTypeConfig): string {
7
+ return c.key ?? c.class
8
+ }
4
9
 
5
10
  export interface CustomFilterEntry {
6
11
  apiParam: string
7
12
  ref: Ref<string | undefined>
8
13
  defaultValue: string | undefined
14
+ typeKeys?: string[] // undefined = applies to all types
9
15
  }
10
16
 
11
17
  export interface SearchFilterContext {
@@ -21,9 +27,11 @@ export function isCustomFilterActive(entry: CustomFilterEntry): boolean {
21
27
  export function forEachActiveCustomFilter(
22
28
  registry: Map<string, CustomFilterEntry>,
23
29
  apply: (apiParam: string, value: string) => void,
30
+ typeKey?: string,
24
31
  ): void {
25
32
  for (const entry of registry.values()) {
26
33
  if (!isCustomFilterActive(entry)) continue
34
+ if (typeKey && entry.typeKeys && !entry.typeKeys.includes(typeKey)) continue
27
35
  apply(entry.apiParam, String(entry.ref.value))
28
36
  }
29
37
  }
@@ -36,6 +44,8 @@ export interface UseSearchFilterOptions {
36
44
  apiParam?: string
37
45
  /** Default value when not present in URL. Defaults to undefined. */
38
46
  defaultValue?: string
47
+ /** One or more type config keys this filter applies to. Undefined means all types. */
48
+ typeKeys?: string | string[]
39
49
  }
40
50
 
41
51
  /**
@@ -68,7 +78,10 @@ export function useSearchFilter(
68
78
  )
69
79
  }
70
80
 
71
- const { apiParam = urlParam, defaultValue = undefined } = options
81
+ const { apiParam = urlParam, defaultValue = undefined, typeKeys } = options
82
+ const normalizedTypeKeys = typeKeys
83
+ ? (Array.isArray(typeKeys) ? typeKeys : [typeKeys])
84
+ : undefined
72
85
 
73
86
  const route = useRoute()
74
87
  const router = useRouter()
@@ -77,7 +90,7 @@ export function useSearchFilter(
77
90
  // Register in onMounted to avoid SSR/hydration mismatch: the registry must be
78
91
  // empty during SSR so server and client produce the same initial HTML.
79
92
  onMounted(() => {
80
- context.register(urlParam, { apiParam, ref: value, defaultValue })
93
+ context.register(urlParam, { apiParam, ref: value, defaultValue, typeKeys: normalizedTypeKeys })
81
94
  })
82
95
 
83
96
  onScopeDispose(() => {
@@ -1,6 +1,6 @@
1
1
  import { computed, ref, watch, type Ref } from 'vue'
2
2
  import type { SearchTypeConfig } from '../types/search'
3
- import { forEachActiveCustomFilter, type CustomFilterEntry } from './useSearchFilter'
3
+ import { configKey, forEachActiveCustomFilter, type CustomFilterEntry } from './useSearchFilter'
4
4
 
5
5
  type FilterRefs = Record<string, Ref<unknown>>
6
6
 
@@ -55,6 +55,9 @@ export function useStableQueryParams(options: StableQueryParamsOptions) {
55
55
  // 3.5. Apply custom filter values. Concatenate into an array on collision
56
56
  // so a custom filter mapped onto a built-in apiParam (e.g. theme → tag)
57
57
  // combines with an existing built-in value instead of overwriting it.
58
+ // Pass the current type key so filters scoped to specific types are excluded
59
+ // from background fetches for other types.
60
+ const currentTypeKey = typeConfig ? configKey(typeConfig) : undefined
58
61
  forEachActiveCustomFilter(customFilterRegistry, (apiParam, value) => {
59
62
  const existing = params[apiParam]
60
63
  if (existing === undefined) {
@@ -63,7 +66,7 @@ export function useStableQueryParams(options: StableQueryParamsOptions) {
63
66
  else {
64
67
  params[apiParam] = Array.isArray(existing) ? [...existing, value] : [existing, value]
65
68
  }
66
- })
69
+ }, currentTypeKey)
67
70
 
68
71
  // 4. Always include q, sort (if valid for this type), page, page_size
69
72
  if (q.value) {