@datagouv/components-next 1.0.2-dev.4 → 1.0.2-dev.41

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.
Files changed (57) hide show
  1. package/dist/Datafair.client-BAokThtJ.js +30 -0
  2. package/dist/JsonPreview.client-DGiaDxVv.js +40 -0
  3. package/dist/{MapContainer.client-DjjvdKBp.js → MapContainer.client-BKGsAP0Y.js} +35 -38
  4. package/dist/{PdfPreview.client-CsvKU0Aq.js → PdfPreview.client-CGjP5ZYb.js} +822 -865
  5. package/dist/{Pmtiles.client-uqg1fwOl.js → Pmtiles.client-C1I7pwT5.js} +574 -579
  6. package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-BlcvVwW8.js +61 -0
  7. package/dist/Swagger.client-U7ZDVUHL.js +4 -0
  8. package/dist/XmlPreview.client-CHUVVEH6.js +34 -0
  9. package/dist/components-next.css +3 -3
  10. package/dist/components-next.js +83 -86
  11. package/dist/components.css +1 -1
  12. package/dist/{index-PMeuFwWj.js → index-CzClB3i0.js} +1 -1
  13. package/dist/{main-ByqZlhiZ.js → main-CF7lWk6R.js} +31224 -30474
  14. package/dist/{vue3-xml-viewer.common-DFrGHXJC.js → vue3-xml-viewer.common-CAwAbUJl.js} +1 -1
  15. package/package.json +10 -8
  16. package/src/components/ActivityList/ActivityList.vue +0 -2
  17. package/src/components/Form/SearchableSelect.vue +2 -1
  18. package/src/components/Pagination.vue +8 -5
  19. package/src/components/ReadMore.vue +1 -1
  20. package/src/components/ResourceAccordion/Datafair.client.vue +4 -10
  21. package/src/components/ResourceAccordion/JsonPreview.client.vue +23 -121
  22. package/src/components/ResourceAccordion/MapContainer.client.vue +7 -11
  23. package/src/components/ResourceAccordion/Metadata.vue +1 -2
  24. package/src/components/ResourceAccordion/PdfPreview.client.vue +24 -103
  25. package/src/components/ResourceAccordion/Pmtiles.client.vue +5 -10
  26. package/src/components/ResourceAccordion/Preview.vue +6 -11
  27. package/src/components/ResourceAccordion/PreviewLoader.vue +1 -2
  28. package/src/components/ResourceAccordion/PreviewUnavailable.vue +22 -0
  29. package/src/components/ResourceAccordion/PreviewWrapper.vue +82 -0
  30. package/src/components/ResourceAccordion/ResourceAccordion.vue +1 -2
  31. package/src/components/ResourceAccordion/XmlPreview.client.vue +16 -115
  32. package/src/components/ResourceExplorer/ResourceExplorer.vue +21 -10
  33. package/src/components/ResourceExplorer/ResourceExplorerViewer.vue +24 -3
  34. package/src/components/Search/GlobalSearch.vue +29 -4
  35. package/src/composables/useResourceCapabilities.ts +1 -1
  36. package/src/config.ts +2 -0
  37. package/src/functions/datasets.ts +0 -17
  38. package/src/functions/resources.ts +56 -1
  39. package/src/functions/tabularApi.ts +7 -84
  40. package/src/main.ts +3 -24
  41. package/src/types/dataservices.ts +2 -0
  42. package/src/types/organizations.ts +1 -1
  43. package/src/types/pages.ts +0 -5
  44. package/src/types/posts.ts +2 -2
  45. package/src/types/reports.ts +3 -0
  46. package/src/types/search.ts +26 -1
  47. package/src/types/site.ts +5 -3
  48. package/src/types/users.ts +0 -1
  49. package/dist/Datafair.client-c1cUKkQR.js +0 -35
  50. package/dist/JsonPreview.client-CAs9XTCX.js +0 -87
  51. package/dist/Swagger.client-BGrkka3l.js +0 -4
  52. package/dist/XmlPreview.client-BWbKzLte.js +0 -79
  53. package/src/components/Chart/ChartViewer.vue +0 -152
  54. package/src/components/Chart/ChartViewerWrapper.vue +0 -194
  55. package/src/functions/pagination.ts +0 -9
  56. package/src/types/visualizations.ts +0 -84
  57. /package/assets/illustrations/{_microscope.svg → microscope.svg} +0 -0
@@ -0,0 +1,82 @@
1
+ <template>
2
+ <div class="text-xs">
3
+ <slot
4
+ v-if="data !== null"
5
+ :data="data"
6
+ />
7
+ <div
8
+ v-else-if="loading"
9
+ class="text-gray-medium"
10
+ >
11
+ {{ t("Chargement de l'aperçu {fileType}...", { fileType }) }}
12
+ </div>
13
+ <PreviewUnavailable v-else-if="!isSizeAllowed">
14
+ {{ fileSizeBytes
15
+ ? t("Le fichier {fileType} est trop volumineux pour être prévisualisé. Téléchargez-le depuis l'onglet Téléchargements.", { fileType })
16
+ : t("La taille du fichier est inconnue, l'aperçu n'est pas disponible. Téléchargez-le depuis l'onglet Téléchargements.")
17
+ }}
18
+ </PreviewUnavailable>
19
+ <PreviewUnavailable v-else-if="corsStatus === 'blocked'">
20
+ {{ t("Ce fichier {fileType} ne peut pas être prévisualisé car il est hébergé sur un site distant qui restreint l'accès (CORS). Téléchargez-le depuis l'onglet Téléchargements.", { fileType }) }}
21
+ </PreviewUnavailable>
22
+ <PreviewUnavailable v-else-if="error === 'network'">
23
+ {{ t("Ce fichier est hébergé sur un site externe qui ne permet pas la prévisualisation. Téléchargez-le depuis l'onglet Téléchargements.") }}
24
+ </PreviewUnavailable>
25
+ <PreviewUnavailable v-else-if="error">
26
+ {{ t("L'aperçu de ce fichier n'a pas pu être chargé. Téléchargez-le depuis l'onglet Téléchargements.") }}
27
+ </PreviewUnavailable>
28
+ </div>
29
+ </template>
30
+
31
+ <script setup lang="ts">
32
+ import { computed, nextTick, onMounted, ref } from 'vue'
33
+ import PreviewUnavailable from './PreviewUnavailable.vue'
34
+ import type { Resource } from '../../types/resources'
35
+ import { getResourceFilesize, getResourceCorsStatus } from '../../functions/resources'
36
+ import { useTranslation } from '../../composables/useTranslation'
37
+
38
+ const props = defineProps<{
39
+ fileType: string
40
+ resource: Resource
41
+ maxSize: number | undefined
42
+ load: () => Promise<unknown>
43
+ }>()
44
+
45
+ const emit = defineEmits<{
46
+ loaded: []
47
+ }>()
48
+
49
+ const { t } = useTranslation()
50
+
51
+ const data = ref<unknown>(null)
52
+ const loading = ref(false)
53
+ const error = ref<'network' | 'generic' | null>(null)
54
+
55
+ const fileSizeBytes = computed(() => getResourceFilesize(props.resource))
56
+ const corsStatus = computed(() => getResourceCorsStatus(props.resource))
57
+
58
+ const isSizeAllowed = computed(() => {
59
+ const size = fileSizeBytes.value
60
+ const max = props.maxSize
61
+ if (!size || !max) return false
62
+ return size <= max
63
+ })
64
+
65
+ onMounted(async () => {
66
+ if (!isSizeAllowed.value || corsStatus.value === 'blocked') return
67
+
68
+ loading.value = true
69
+ try {
70
+ data.value = await props.load()
71
+ await nextTick()
72
+ emit('loaded')
73
+ }
74
+ catch (err) {
75
+ console.error('Error loading preview:', err)
76
+ error.value = err instanceof TypeError ? 'network' : 'generic'
77
+ }
78
+ finally {
79
+ loading.value = false
80
+ }
81
+ })
82
+ </script>
@@ -387,9 +387,8 @@ import { trackEvent } from '../../functions/matomo'
387
387
  import CopyButton from '../CopyButton.vue'
388
388
  import { useComponentsConfig } from '../../config'
389
389
  import { getOwnerName } from '../../functions/owned'
390
- import { getResourceFormatIcon, getResourceTitleId, detectOgcService } from '../../functions/resources'
390
+ import { getResourceFormatIcon, getResourceTitleId, detectOgcService, getResourceExternalUrl, getResourceFilesize } from '../../functions/resources'
391
391
  import BrandedButton from '../BrandedButton.vue'
392
- import { getResourceExternalUrl, getResourceFilesize } from '../../functions/datasets'
393
392
  import { useTranslation } from '../../composables/useTranslation'
394
393
  import { useHasTabularData } from '../../composables/useHasTabularData'
395
394
  import Metadata from './Metadata.vue'
@@ -1,59 +1,24 @@
1
1
  <template>
2
- <div class="fr-text--xs">
3
- <div v-if="xmlData">
4
- <XmlViewer :xml="xmlData" />
5
- </div>
6
- <div
7
- v-else-if="loading"
8
- class="text-gray-medium"
9
- >
10
- {{ t("Chargement de l'aperçu XML...") }}
11
- </div>
12
- <SimpleBanner
13
- v-else-if="fileTooLarge"
14
- type="warning"
15
- class="flex items-center space-x-2"
16
- >
17
- <RiErrorWarningLine class="shrink-0 size-6" />
18
- <span>{{ fileSizeBytes
19
- ? t("Fichier XML trop volumineux pour l'aperçu. Pour consulter le fichier complet, téléchargez-le en cliquant sur le bouton bleu ou depuis l'onglet Téléchargements.")
20
- : t("L'aperçu n'est pas disponible car la taille du fichier est inconnue. Pour consulter le fichier complet, téléchargez-le en cliquant sur le bouton bleu ou depuis l'onglet Téléchargements.")
21
- }}</span>
22
- </SimpleBanner>
23
- <SimpleBanner
24
- v-else-if="error === 'network'"
25
- type="warning"
26
- class="flex items-center space-x-2"
27
- >
28
- <RiErrorWarningLine class="shrink-0 size-6" />
29
- <span>{{ t("Ce fichier XML ne peut pas être prévisualisé, peut-être parce qu'il est hébergé sur un autre site qui ne l'autorise pas. Pour le consulter, téléchargez-le en cliquant sur le bouton bleu ou depuis l'onglet Téléchargements.") }}</span>
30
- </SimpleBanner>
31
- <SimpleBanner
32
- v-else-if="error"
33
- type="warning"
34
- class="flex items-center space-x-2"
35
- >
36
- <RiErrorWarningLine class="shrink-0 size-6" />
37
- <span>{{ t("Erreur lors du chargement de l'aperçu XML.") }}</span>
38
- </SimpleBanner>
39
- </div>
2
+ <PreviewWrapper
3
+ v-slot="{ data }"
4
+ file-type="XML"
5
+ :resource="resource"
6
+ :max-size="config.maxXmlPreviewCharSize"
7
+ :load="load"
8
+ >
9
+ <XmlViewer :xml="(data as string)" />
10
+ </PreviewWrapper>
40
11
  </template>
41
12
 
42
13
  <script setup lang="ts">
43
- import { computed, defineAsyncComponent, onMounted, ref } from 'vue'
44
- import { RiErrorWarningLine } from '@remixicon/vue'
45
-
14
+ import { defineAsyncComponent } from 'vue'
46
15
  import { useComponentsConfig } from '../../config'
47
- import SimpleBanner from '../SimpleBanner.vue'
16
+ import PreviewWrapper from './PreviewWrapper.vue'
48
17
  import type { Resource } from '../../types/resources'
49
- import { useTranslation } from '../../composables/useTranslation'
50
18
  import '../../types/vue3-xml-viewer.d'
51
- import { getResourceFilesize } from '../../main'
52
19
 
53
20
  const XmlViewer = defineAsyncComponent(() =>
54
- import('vue3-xml-viewer').then((module) => {
55
- return module.default || module.XmlViewer
56
- }),
21
+ import('vue3-xml-viewer').then(module => module.default || module.XmlViewer),
57
22
  )
58
23
 
59
24
  const props = defineProps<{
@@ -61,74 +26,10 @@ const props = defineProps<{
61
26
  }>()
62
27
 
63
28
  const config = useComponentsConfig()
64
- const { t } = useTranslation()
65
-
66
- const xmlData = ref<string | null>(null)
67
- const loading = ref(false)
68
- const error = ref<string | null>(null)
69
- const fileTooLarge = ref(false)
70
-
71
- const fileSizeBytes = computed(() => getResourceFilesize(props.resource))
72
-
73
- const shouldLoadXml = computed(() => {
74
- const size = fileSizeBytes.value
75
- if (!size) {
76
- // If we don't know the size, don't risk loading a potentially huge file
77
- return false
78
- }
79
-
80
- // Check if maxXmlPreviewCharSize is configured
81
- if (!config.maxXmlPreviewCharSize) {
82
- // If no limit is set, don't load unknown files
83
- return false
84
- }
85
-
86
- // Convert maxXmlPreviewCharSize from characters to bytes (rough estimate)
87
- // Assuming average 1 byte per character for XML
88
- const maxByteSize = config.maxXmlPreviewCharSize
89
-
90
- return size <= maxByteSize
91
- })
92
29
 
93
- const fetchXmlData = async () => {
94
- // Check if file is too large or size is unknown before making the request
95
- if (!shouldLoadXml.value) {
96
- fileTooLarge.value = true
97
- return
98
- }
99
-
100
- loading.value = true
101
- error.value = null
102
-
103
- try {
104
- const response = await fetch(props.resource.url)
105
- // const response = await fetch('/test-data.xml') // For testing locally without CORS issues
106
- if (!response.ok) {
107
- throw new Error(`HTTP error! status: ${response.status}`)
108
- }
109
- const data = await response.text()
110
-
111
- // Use the XML data as string - let the XML viewer handle large files
112
- xmlData.value = data
113
- }
114
- catch (err) {
115
- console.error('Error loading XML:', err)
116
-
117
- if (err instanceof TypeError) {
118
- error.value = 'network'
119
- }
120
- else {
121
- error.value = 'generic'
122
- }
123
-
124
- xmlData.value = null
125
- }
126
- finally {
127
- loading.value = false
128
- }
30
+ const load = async () => {
31
+ const response = await fetch(props.resource.url)
32
+ if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`)
33
+ return response.text()
129
34
  }
130
-
131
- onMounted(() => {
132
- fetchXmlData()
133
- })
134
35
  </script>
@@ -159,6 +159,22 @@ watch(searchDebounced, () => {
159
159
  }
160
160
  })
161
161
 
162
+ // Separate useFetch for loadMore, initialized at setup time with immediate: false
163
+ // so that it doesn't fetch until execute() is called from the event handler.
164
+ const loadMoreType = ref<ResourceType>('main')
165
+ const loadMorePage = ref(1)
166
+ const loadMoreParams = computed(() => ({
167
+ type: loadMoreType.value,
168
+ page_size: PAGE_SIZE,
169
+ page: loadMorePage.value,
170
+ q: searchDebounced.value || undefined,
171
+ }))
172
+ const { data: loadMoreData, execute: executeLoadMore } = await useFetch<PaginatedArray<Resource>>(url, {
173
+ params: loadMoreParams,
174
+ immediate: false,
175
+ watch: false,
176
+ })
177
+
162
178
  const loadMore = async (type: ResourceType) => {
163
179
  const index = RESOURCE_TYPE.indexOf(type)
164
180
  if (index === -1) return
@@ -166,17 +182,12 @@ const loadMore = async (type: ResourceType) => {
166
182
  const extraRef = extraResourcesByType[index]!
167
183
  pageRef.value++
168
184
 
169
- const { data } = await useFetch<PaginatedArray<Resource>>(url, {
170
- params: {
171
- type,
172
- page_size: PAGE_SIZE,
173
- page: pageRef.value,
174
- q: searchDebounced.value || undefined,
175
- },
176
- })
185
+ loadMoreType.value = type
186
+ loadMorePage.value = pageRef.value
187
+ await executeLoadMore()
177
188
 
178
- if (data.value) {
179
- extraRef.value = [...extraRef.value, ...data.value.data]
189
+ if (loadMoreData.value) {
190
+ extraRef.value = [...extraRef.value, ...loadMoreData.value.data]
180
191
  }
181
192
  }
182
193
 
@@ -17,6 +17,12 @@
17
17
  />
18
18
  </div>
19
19
  <div class="text-gray-medium text-xs flex items-center gap-1">
20
+ <SchemaBadge :resource />
21
+ <RiSubtractLine
22
+ v-if="resource.schema"
23
+ aria-hidden="true"
24
+ class="size-3 fill-gray-medium"
25
+ />
20
26
  <span>{{ t('mis à jour {date}', { date: formatRelativeIfRecentDate(resource.last_modified) }) }}</span>
21
27
  <RiSubtractLine
22
28
  aria-hidden="true"
@@ -133,9 +139,23 @@
133
139
  :url="resource.extras['apidocUrl'] as string"
134
140
  />
135
141
  <Preview
136
- v-else
142
+ v-else-if="hasTabularData"
137
143
  :resource="resource"
138
144
  />
145
+ <PreviewUnavailable v-else>
146
+ <!-- "File too large to download" is the only analysis:error value from hydra for now -->
147
+ <template v-if="resource.extras['analysis:error'] === 'File too large to download'">
148
+ {{ t("Ce fichier est trop volumineux pour être analysé et prévisualisé. Téléchargez-le depuis l'onglet Téléchargements.") }}
149
+ </template>
150
+ <template v-else-if="resource.extras['analysis:parsing:error']">
151
+ {{ t("L'analyse de ce fichier a rencontré une erreur, l'aperçu n'est pas disponible. Téléchargez-le depuis l'onglet Téléchargements.") }}
152
+ <br>
153
+ <span class="text-gray-medium text-xs">{{ resource.extras['analysis:parsing:error'] }}</span>
154
+ </template>
155
+ <template v-else>
156
+ {{ t("Ce fichier ne peut pas être prévisualisé. Téléchargez-le depuis l'onglet Téléchargements.") }}
157
+ </template>
158
+ </PreviewUnavailable>
139
159
  </div>
140
160
  <div v-if="tab.key === 'description'">
141
161
  <MarkdownViewer
@@ -298,6 +318,7 @@
298
318
  <script setup lang="ts">
299
319
  import { computed, defineAsyncComponent } from 'vue'
300
320
  import { RiDownloadLine, RiFileCopyLine, RiFileWarningLine, RiInformationLine, RiSubtractLine } from '@remixicon/vue'
321
+ import PreviewUnavailable from '../ResourceAccordion/PreviewUnavailable.vue'
301
322
  import { toast } from 'vue-sonner'
302
323
  import BrandedButton from '../BrandedButton.vue'
303
324
  import CopyButton from '../CopyButton.vue'
@@ -313,9 +334,9 @@ import Tooltip from '../Tooltip.vue'
313
334
  import Preview from '../ResourceAccordion/Preview.vue'
314
335
  import DataStructure from '../ResourceAccordion/DataStructure.vue'
315
336
  import Metadata from '../ResourceAccordion/Metadata.vue'
337
+ import SchemaBadge from '../ResourceAccordion/SchemaBadge.vue'
316
338
  import { filesize, summarize } from '../../functions/helpers'
317
- import { getResourceFormatIcon } from '../../functions/resources'
318
- import { getResourceExternalUrl, getResourceFilesize } from '../../functions/datasets'
339
+ import { getResourceFormatIcon, getResourceExternalUrl, getResourceFilesize } from '../../functions/resources'
319
340
  import { trackEvent } from '../../functions/matomo'
320
341
  import { useComponentsConfig } from '../../config'
321
342
  import { useFormatDate } from '../../functions/dates'
@@ -263,6 +263,14 @@
263
263
  <OrganizationHorizontalCard :organization="(result as Organization)" />
264
264
  </slot>
265
265
  </template>
266
+ <template v-else-if="currentType === 'topics'">
267
+ <slot
268
+ name="topic"
269
+ :topic="result"
270
+ >
271
+ <TopicCard :topic="(result as TopicV2)" />
272
+ </slot>
273
+ </template>
266
274
  </li>
267
275
  </ul>
268
276
  <Pagination
@@ -271,7 +279,6 @@
271
279
  :page-size
272
280
  :total-results="results.total"
273
281
  class="mt-4"
274
- :link="getLink"
275
282
  @change="changePage"
276
283
  />
277
284
  </div>
@@ -335,19 +342,19 @@
335
342
  <script setup lang="ts">
336
343
  import { computed, watch, useTemplateRef, type Ref } from 'vue'
337
344
  import { useRouteQuery } from '@vueuse/router'
338
- import { RiBuilding2Line, RiCloseCircleLine, RiDatabase2Line, RiLightbulbLine, RiLineChartLine, RiRssLine, RiTerminalLine } from '@remixicon/vue'
345
+ import { RiBookShelfLine, RiBuilding2Line, RiCloseCircleLine, RiDatabase2Line, RiLightbulbLine, RiLineChartLine, RiRssLine, RiTerminalLine } from '@remixicon/vue'
339
346
  import magnifyingGlassSrc from '../../../assets/illustrations/magnifying_glass.svg?url'
340
347
  import { useTranslation } from '../../composables/useTranslation'
341
348
  import { useDebouncedRef } from '../../composables/useDebouncedRef'
342
349
  import { useStableQueryParams } from '../../composables/useStableQueryParams'
343
350
  import { useComponentsConfig } from '../../config'
344
351
  import { useFetch } from '../../functions/api'
345
- import { getLink } from '../../functions/pagination'
346
352
  import type { Dataset } from '../../types/datasets'
347
353
  import type { Dataservice } from '../../types/dataservices'
348
354
  import type { Organization } from '../../types/organizations'
349
355
  import type { Reuse } from '../../types/reuses'
350
- import type { GlobalSearchConfig, SearchType, SortOption, DatasetSearchResponse, DataserviceSearchResponse, ReuseSearchResponse, OrganizationSearchResponse, FacetItem } from '../../types/search'
356
+ import type { TopicV2 } from '../../types/topics'
357
+ import type { GlobalSearchConfig, SearchType, SortOption, DatasetSearchResponse, DataserviceSearchResponse, ReuseSearchResponse, OrganizationSearchResponse, TopicSearchResponse, FacetItem } from '../../types/search'
351
358
  import { getDefaultGlobalSearchConfig } from '../../types/search'
352
359
  import BrandedButton from '../BrandedButton.vue'
353
360
  import LoadingBlock from '../LoadingBlock.vue'
@@ -358,6 +365,7 @@ import DatasetCard from '../DatasetCard.vue'
358
365
  import DataserviceCard from '../DataserviceCard.vue'
359
366
  import OrganizationHorizontalCard from '../OrganizationHorizontalCard.vue'
360
367
  import ReuseHorizontalCard from '../ReuseHorizontalCard.vue'
368
+ import TopicCard from '../TopicCard.vue'
361
369
  import SearchInput from './SearchInput.vue'
362
370
  import Sidemenu from './Sidemenu.vue'
363
371
  import BasicAndAdvancedFilters from './BasicAndAdvancedFilters.vue'
@@ -500,6 +508,7 @@ const datasetsEnabled = computed(() => props.config.some(c => c.class === 'datas
500
508
  const dataservicesEnabled = computed(() => props.config.some(c => c.class === 'dataservices'))
501
509
  const reusesEnabled = computed(() => props.config.some(c => c.class === 'reuses'))
502
510
  const organizationsEnabled = computed(() => props.config.some(c => c.class === 'organizations'))
511
+ const topicsEnabled = computed(() => props.config.some(c => c.class === 'topics'))
503
512
 
504
513
  // Create stable params for each type
505
514
  const stableParamsOptions = {
@@ -526,12 +535,17 @@ const organizationsParams = useStableQueryParams({
526
535
  ...stableParamsOptions,
527
536
  typeConfig: props.config.find(c => c.class === 'organizations'),
528
537
  })
538
+ const topicsParams = useStableQueryParams({
539
+ ...stableParamsOptions,
540
+ typeConfig: props.config.find(c => c.class === 'topics'),
541
+ })
529
542
 
530
543
  // URLs that return null when type is not enabled
531
544
  const datasetsUrl = computed(() => datasetsEnabled.value ? '/api/2/datasets/search/' : null)
532
545
  const dataservicesUrl = computed(() => dataservicesEnabled.value ? '/api/2/dataservices/search/' : null)
533
546
  const reusesUrl = computed(() => reusesEnabled.value ? '/api/2/reuses/search/' : null)
534
547
  const organizationsUrl = computed(() => organizationsEnabled.value ? '/api/2/organizations/search/' : null)
548
+ const topicsUrl = computed(() => topicsEnabled.value ? '/api/2/topics/search/' : null)
535
549
 
536
550
  // Reset page on filter/sort change
537
551
  const filtersForReset = computed(() => ({
@@ -615,6 +629,10 @@ const { data: organizationsResults, status: organizationsStatus } = await useFet
615
629
  organizationsUrl,
616
630
  { params: organizationsParams, lazy: true, server: initialType === 'organizations' },
617
631
  )
632
+ const { data: topicsResults, status: topicsStatus } = await useFetch<TopicSearchResponse<TopicV2>>(
633
+ topicsUrl,
634
+ { params: topicsParams, lazy: true, server: initialType === 'topics' },
635
+ )
618
636
 
619
637
  const typesMeta = {
620
638
  datasets: {
@@ -645,6 +663,13 @@ const typesMeta = {
645
663
  results: organizationsResults,
646
664
  status: organizationsStatus,
647
665
  },
666
+ topics: {
667
+ icon: RiBookShelfLine,
668
+ name: t('Thématiques'),
669
+ placeholder: t('Rechercher une thématique'),
670
+ results: topicsResults,
671
+ status: topicsStatus,
672
+ },
648
673
  } as const
649
674
 
650
675
  const searchResults = computed(() => typesMeta[currentType.value].results.value)
@@ -88,7 +88,7 @@ export function useResourceCapabilities(
88
88
  if (hasTabularData.value) {
89
89
  options.push({ key: 'data', label: t('Données') })
90
90
  }
91
- else if (hasPreview.value || hasDatafairPreview.value || hasOpenAPIPreview.value) {
91
+ else {
92
92
  options.push({ key: 'data', label: t('Aperçu') })
93
93
  }
94
94
 
package/src/config.ts CHANGED
@@ -5,6 +5,8 @@ import type { FetchOptions } from 'ofetch'
5
5
  export type PluginConfig = {
6
6
  name: string // Name of the application (ex: data.gouv.fr)
7
7
  baseUrl: string
8
+ /** Hostnames allowed in Access-Control-Allow-Origin for resource preview CORS checks (e.g. data.gouv.fr). */
9
+ trustedDomains?: string[]
8
10
  apiBase: string
9
11
  devApiKey?: string | null
10
12
  datasetQualityGuideUrl?: string
@@ -1,6 +1,4 @@
1
1
  import { useComponentsConfig } from '../config'
2
- import type { Dataset, DatasetV2 } from '../types/datasets'
3
- import type { CommunityResource, Resource } from '../types/resources'
4
2
 
5
3
  function constructUrl(baseUrl: string, path: string): string {
6
4
  const url = new URL(baseUrl)
@@ -14,18 +12,3 @@ export function getDatasetOEmbedHtml(type: string, id: string): string {
14
12
  const staticUrl = constructUrl(config.baseUrl, 'oembed.js')
15
13
  return `<div data-udata-${type}="${id}"></div><script data-udata="${config.baseUrl}" src="${staticUrl}" async defer></script>`
16
14
  }
17
-
18
- export function isCommunityResource(resource: Resource | CommunityResource): boolean {
19
- return 'organization' in resource || 'owner' in resource
20
- }
21
-
22
- export function getResourceExternalUrl(dataset: Dataset | DatasetV2 | Omit<Dataset, 'resources' | 'community_resources'>, resource: Resource | CommunityResource): string {
23
- return `${dataset.page}${isCommunityResource(resource) ? '/community-resources' : ''}?resource_id=${resource.id}`
24
- }
25
-
26
- export function getResourceFilesize(resource: Resource): null | number {
27
- if (resource.filesize) return resource.filesize
28
- if ('analysis:content-length' in resource.extras) return resource.extras['analysis:content-length'] as number
29
-
30
- return null
31
- }
@@ -1,13 +1,15 @@
1
1
  import { readonly, type Component } from 'vue'
2
2
 
3
3
  import { RiEarthLine, RiMap2Line } from '@remixicon/vue'
4
+ import { useComponentsConfig } from '../config'
4
5
  import Archive from '../components/Icons/Archive.vue'
5
6
  import Code from '../components/Icons/Code.vue'
7
+ import type { Dataset, DatasetV2 } from '../types/datasets'
6
8
  import Documentation from '../components/Icons/Documentation.vue'
7
9
  import Image from '../components/Icons/Image.vue'
8
10
  import Link from '../components/Icons/Link.vue'
9
11
  import Table from '../components/Icons/Table.vue'
10
- import type { Resource } from '../types/resources'
12
+ import type { CommunityResource, Resource } from '../types/resources'
11
13
  import { useTranslation } from '../composables/useTranslation'
12
14
 
13
15
  export function getResourceFormatIcon(format: string): Component | null {
@@ -129,3 +131,56 @@ export const detectOgcService = (resource: Resource) => {
129
131
  }
130
132
  return false
131
133
  }
134
+
135
+ export function isCommunityResource(resource: Resource | CommunityResource): boolean {
136
+ return 'organization' in resource || 'owner' in resource
137
+ }
138
+
139
+ export function getResourceExternalUrl(dataset: Dataset | DatasetV2 | Omit<Dataset, 'resources' | 'community_resources'>, resource: Resource | CommunityResource): string {
140
+ return `${dataset.page}${isCommunityResource(resource) ? '/community-resources' : ''}?resource_id=${resource.id}`
141
+ }
142
+
143
+ export function getResourceFilesize(resource: Resource): null | number {
144
+ if (resource.filesize) return resource.filesize
145
+ if ('analysis:content-length' in resource.extras) return resource.extras['analysis:content-length'] as number
146
+
147
+ return null
148
+ }
149
+
150
+ type CorsStatus = 'allowed' | 'blocked' | 'unknown'
151
+
152
+ export const getResourceCorsStatus = (resource: Resource): CorsStatus => {
153
+ const extras = resource.extras
154
+ if (!extras || !('check:cors:allow-origin' in extras)) {
155
+ return 'unknown'
156
+ }
157
+
158
+ const allowOrigin = extras['check:cors:allow-origin'] as string | undefined
159
+ const rawMethods = extras['check:cors:allow-methods'] as string | undefined
160
+
161
+ // Check if allow-origin is '*' or contains one of our trusted domains
162
+ const config = useComponentsConfig()
163
+ const trustedDomains = config.trustedDomains ?? []
164
+ const hasPublicCors = allowOrigin === '*'
165
+ const hasSpecificCors = allowOrigin
166
+ ? trustedDomains.some((domain) => {
167
+ try {
168
+ const hostname = new URL(allowOrigin).hostname
169
+ return hostname === domain || hostname.endsWith(`.${domain}`)
170
+ }
171
+ catch {
172
+ return false
173
+ }
174
+ })
175
+ : false
176
+
177
+ const isOriginAllowed = hasPublicCors || hasSpecificCors
178
+
179
+ // Ensure GET method is allowed
180
+ const allowedMethods = rawMethods
181
+ ? rawMethods.split(',').map(m => m.trim().toUpperCase())
182
+ : []
183
+ const supportsGet = allowedMethods.length === 0 || allowedMethods.includes('GET')
184
+
185
+ return isOriginAllowed && supportsGet ? 'allowed' : 'blocked'
186
+ }