@datagouv/components-next 1.0.2-dev.17 → 1.0.2-dev.170
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/README.md +7 -6
- package/assets/main.css +4 -0
- package/dist/{Control-DuZJdKV_.js → Control-B9WQxlpJ.js} +1 -1
- package/dist/{Datafair.client-Ds3VQrRi.js → Datafair.client-B-OG5WtK.js} +4 -4
- package/dist/{Event--kp8kMdJ.js → Event-iXDrp-fy.js} +31 -31
- package/dist/{Image-34hvypZI.js → Image-mNMBOofs.js} +9 -9
- package/dist/ImagePreview.client-D0c-ifUi.js +36 -0
- package/dist/JsonPreview.client-Dwh9sW9M.js +40 -0
- package/dist/{Map-BjUnLyj8.js → Map-BfqKMw0S.js} +1739 -1599
- package/dist/{MapContainer.client-B2BijMx5.js → MapContainer.client-C2AZ7sOB.js} +38 -39
- package/dist/{OSM-s40W6sQ2.js → OSM-CcrUhItr.js} +15 -23
- package/dist/{PdfPreview.client-DJBMzrlC.js → PdfPreview.client-8NzNfW8b.js} +823 -855
- package/dist/Pmtiles.client-BFH4rTB7.js +26324 -0
- package/dist/PreviewWrapper.vue_vue_type_script_setup_true_lang-BOgE441d.js +58 -0
- package/dist/{ScaleLine-KW-nXqp3.js → ScaleLine-VGQ7nkMS.js} +2 -2
- package/dist/{Tile-DbNFNPfU.js → Tile-CSpn0Ca8.js} +160 -163
- package/dist/{TileImage-BsXBxMtq.js → TileImage-CpbaEFwd.js} +143 -131
- package/dist/{View-BR92hTWP.js → View-BYBpt-AU.js} +483 -422
- package/dist/XmlPreview.client-DMOUO508.js +34 -0
- package/dist/{common-PJfpC179.js → common-BoeTUnDZ.js} +52 -52
- package/dist/components-next.css +1 -52
- package/dist/components-next.js +183 -146
- package/dist/components.css +2 -2
- package/dist/{index-BFQX7Ccz.js → index-C9obT9DJ.js} +21834 -15810
- package/dist/{leaflet-src-7m1mB8LI.js → leaflet-src-B4AZU0vr.js} +185 -187
- package/dist/{main-vqhkVhVS.js → main-DNoYWfit.js} +40723 -73240
- package/dist/{proj-DsetBcW7.js → proj-DxGbobp7.js} +662 -626
- package/dist/{text-clamp.esm-B5kW_XMt.js → text-clamp.esm-DVseBqZZ.js} +4 -4
- package/dist/{tilecoord-Db24Px13.js → tilecoord-DvX7WWiA.js} +273 -264
- package/dist/{vue3-json-viewer-BXwup7nO.js → vue3-json-viewer-CJLQFzXZ.js} +10 -16
- package/dist/{vue3-xml-viewer.common-BcNJo35o.js → vue3-xml-viewer.common-Cp7Cu5ME.js} +16 -16
- package/package.json +47 -38
- package/src/chart.ts +5 -0
- package/src/components/ActivityList/ActivityList.vue +3 -2
- package/src/components/Chart/ChartViewer.vue +320 -0
- package/src/components/Chart/ChartViewerWrapper.vue +182 -0
- package/src/components/DataserviceCard.vue +9 -0
- package/src/components/DataserviceQuality.vue +82 -0
- package/src/components/DataserviceQualityInline.vue +31 -0
- package/src/components/DataserviceQualityTooltipContent.vue +79 -0
- package/src/components/DatasetCard.vue +9 -4
- package/src/components/DatasetQuality.vue +11 -11
- package/src/components/DatasetQualityInline.vue +2 -2
- package/src/components/DatasetQualityTooltipContent.vue +1 -1
- package/src/components/Form/Listbox.vue +101 -0
- package/src/components/InfiniteLoader.vue +53 -0
- package/src/components/ObjectCardHeader.vue +11 -4
- package/src/components/OpenApiViewer/ContentTypeSelect.vue +48 -0
- package/src/components/OpenApiViewer/EndpointRequest.vue +164 -0
- package/src/components/OpenApiViewer/EndpointResponses.vue +149 -0
- package/src/components/OpenApiViewer/OpenApiViewer.vue +308 -0
- package/src/components/OpenApiViewer/SchemaPanel.vue +53 -0
- package/src/components/OpenApiViewer/SchemaTree.vue +77 -0
- package/src/components/OpenApiViewer/openapi.ts +150 -0
- package/src/components/OrganizationNameWithCertificate.vue +3 -2
- package/src/components/Pagination.vue +8 -5
- package/src/components/RadioInput.vue +7 -2
- package/src/components/ResourceAccordion/DataStructure.vue +11 -33
- package/src/components/ResourceAccordion/Downloads.vue +160 -0
- package/src/components/ResourceAccordion/ImagePreview.client.vue +48 -0
- package/src/components/ResourceAccordion/JsonPreview.client.vue +23 -104
- package/src/components/ResourceAccordion/MapContainer.client.vue +1 -3
- package/src/components/ResourceAccordion/Metadata.vue +1 -2
- package/src/components/ResourceAccordion/PdfPreview.client.vue +24 -87
- package/src/components/ResourceAccordion/Pmtiles.client.vue +3 -1
- package/src/components/ResourceAccordion/Preview.vue +11 -11
- package/src/components/ResourceAccordion/PreviewWrapper.vue +82 -0
- package/src/components/ResourceAccordion/ResourceAccordion.vue +19 -113
- package/src/components/ResourceAccordion/XmlPreview.client.vue +16 -98
- package/src/components/ResourceExplorer/ResourceExplorer.vue +22 -19
- package/src/components/ResourceExplorer/ResourceExplorerSidebar.vue +2 -2
- package/src/components/ResourceExplorer/ResourceExplorerViewer.vue +64 -148
- package/src/components/ResourceExplorer/ResourceSelector.vue +113 -0
- package/src/components/ReuseCard.vue +14 -6
- package/src/components/ReuseDetails.vue +2 -2
- package/src/components/ReuseHorizontalCard.vue +2 -2
- package/src/components/Search/GlobalSearch.vue +219 -117
- package/src/components/Search/SearchInput.vue +5 -4
- package/src/components/TabularExplorer/TabularCell.vue +52 -0
- package/src/components/TabularExplorer/TabularCellPopover.vue +170 -0
- package/src/components/TabularExplorer/TabularExplorer.vue +1225 -0
- package/src/components/TabularExplorer/TabularFilterContent.vue +370 -0
- package/src/components/TabularExplorer/TabularFilterPopover.vue +107 -0
- package/src/components/TabularExplorer/types.ts +86 -0
- package/src/composables/useHasTabularData.ts +15 -1
- package/src/composables/useMetrics.ts +1 -1
- package/src/composables/useResourceCapabilities.ts +28 -15
- package/src/composables/useSearchFilter.ts +120 -0
- package/src/composables/useStableQueryParams.ts +38 -6
- package/src/composables/useTabularProfile.ts +70 -0
- package/src/config.ts +21 -3
- package/src/functions/activities.ts +3 -3
- package/src/functions/api.ts +20 -42
- package/src/functions/api.types.ts +1 -0
- package/src/functions/charts.ts +99 -0
- package/src/functions/datasets.ts +0 -17
- package/src/functions/dates.ts +3 -2
- package/src/functions/metrics.ts +6 -4
- package/src/functions/resources.ts +117 -1
- package/src/functions/tabular.ts +214 -0
- package/src/functions/tabularApi.ts +96 -11
- package/src/main.ts +109 -14
- package/src/types/dataservices.ts +17 -0
- package/src/types/organizations.ts +10 -0
- package/src/types/pages.ts +0 -5
- package/src/types/posts.ts +2 -2
- package/src/types/reports.ts +5 -1
- package/src/types/resources.ts +0 -1
- package/src/types/reuses.ts +12 -1
- package/src/types/search.ts +63 -1
- package/src/types/site.ts +5 -3
- package/src/types/ui.ts +2 -0
- package/src/types/users.ts +2 -1
- package/src/types/visualizations.ts +93 -0
- package/assets/swagger-themes/newspaper.css +0 -1670
- package/dist/JsonPreview.client-CYxmz0yV.js +0 -72
- package/dist/Pmtiles.client-C_hvRDuy.js +0 -25185
- package/dist/Swagger.client-B4y0hXME.js +0 -4
- package/dist/XmlPreview.client-LETEfNBH.js +0 -64
- package/src/components/ResourceAccordion/Swagger.client.vue +0 -48
- package/src/functions/pagination.ts +0 -9
- /package/src/components/{DatasetQualityItem.vue → QualityItem.vue} +0 -0
- /package/src/components/{DatasetQualityItemWarning.vue → QualityItemWarning.vue} +0 -0
- /package/src/components/{DatasetQualityScore.vue → QualityScore.vue} +0 -0
|
@@ -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
|
-
}
|
package/src/functions/dates.ts
CHANGED
|
@@ -77,8 +77,9 @@ export function useFormatDate() {
|
|
|
77
77
|
dateWithoutTime.setHours(0)
|
|
78
78
|
dateWithoutTime.setMinutes(0)
|
|
79
79
|
dateWithoutTime.setSeconds(0)
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
// `getTime()` returns milliseconds, `SECONDS_IN_A_DAY` is in seconds
|
|
81
|
+
const diffInSeconds = Math.abs(dateWithoutTime.getTime() - today.getTime()) / 1000
|
|
82
|
+
if (diffInSeconds >= SECONDS_IN_A_DAY * 30) {
|
|
82
83
|
return t('le {date}', { date: formatDate(date, options) })
|
|
83
84
|
}
|
|
84
85
|
return formatFromNow(date)
|
package/src/functions/metrics.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { escapeCsvValue } from './helpers'
|
|
2
|
-
import { ofetch } from 'ofetch'
|
|
2
|
+
import { ofetch, type $Fetch } from 'ofetch'
|
|
3
3
|
import type { DatasetV2 } from '../types/datasets'
|
|
4
4
|
import type { PaginatedArray } from '../types/api'
|
|
5
5
|
|
|
@@ -119,14 +119,16 @@ export async function getDatasetMetrics(datasetId: string, metricsApi: string):
|
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
|
|
122
|
-
export async function createDatasetsForOrganizationMetricsUrl(organizationId: string, metricsApi: string, apiBase: string) {
|
|
122
|
+
export async function createDatasetsForOrganizationMetricsUrl(organizationId: string, metricsApi: string, apiBase: string, apiFetch: $Fetch) {
|
|
123
123
|
let data = 'dataset_title,dataset_id,month,monthly_visit,monthly_download_resource\n'
|
|
124
124
|
|
|
125
|
-
// fetch datasets info from organization datasets
|
|
125
|
+
// fetch datasets info from organization datasets through the configured fetch, so it carries the
|
|
126
|
+
// consumer's auth (cookie for cdata via `$api`, Bearer for verticals) instead of a hardcoded
|
|
127
|
+
// `credentials: 'include'`, which breaks CORS cross-origin on the verticals.
|
|
126
128
|
const datasets: Record<string, Record<string, string>> = {}
|
|
127
129
|
let datasetsUrl: string | null = `/api/2/datasets/?organization=${organizationId}&page_size=200`
|
|
128
130
|
while (datasetsUrl) {
|
|
129
|
-
const body: PaginatedArray<DatasetV2> = await
|
|
131
|
+
const body: PaginatedArray<DatasetV2> = await apiFetch(datasetsUrl, { baseURL: apiBase })
|
|
130
132
|
datasetsUrl = body.next_page
|
|
131
133
|
for (const row of body.data) {
|
|
132
134
|
datasets[row.id] = { title: row.title }
|
|
@@ -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 {
|
|
@@ -89,6 +91,11 @@ export function getResourceTitleId(resource: Resource) {
|
|
|
89
91
|
export const RESOURCE_TYPE = readonly(['main', 'documentation', 'update', 'api', 'code', 'other'] as const)
|
|
90
92
|
export type ResourceType = typeof RESOURCE_TYPE[number]
|
|
91
93
|
|
|
94
|
+
// Page size used by ResourceExplorer for its per-type resource fetches.
|
|
95
|
+
// Exported so consumers (e.g. the dataset page's `main` prefetch) can build a
|
|
96
|
+
// byte-for-byte identical cache key and let Nuxt dedupe the request.
|
|
97
|
+
export const RESOURCE_EXPLORER_PAGE_SIZE = 10
|
|
98
|
+
|
|
92
99
|
export const getResourceLabel = (type: ResourceType, count?: number) => {
|
|
93
100
|
const { t } = useTranslation()
|
|
94
101
|
switch (type) {
|
|
@@ -98,14 +105,29 @@ export const getResourceLabel = (type: ResourceType, count?: number) => {
|
|
|
98
105
|
}
|
|
99
106
|
return t('Fichiers principaux')
|
|
100
107
|
case 'documentation':
|
|
108
|
+
if (typeof count === 'number') {
|
|
109
|
+
return t('Aucun fichier de documentation | 1 fichier de documentation | {n} fichiers de documentation', count)
|
|
110
|
+
}
|
|
101
111
|
return t('Documentation')
|
|
102
112
|
case 'update':
|
|
113
|
+
if (typeof count === 'number') {
|
|
114
|
+
return t('Aucune mise à jour | 1 mise à jour | {n} mises à jour', count)
|
|
115
|
+
}
|
|
103
116
|
return t('Mise à jour')
|
|
104
117
|
case 'api':
|
|
118
|
+
if (typeof count === 'number') {
|
|
119
|
+
return t('Aucune API | 1 API | {n} API', count)
|
|
120
|
+
}
|
|
105
121
|
return t('API')
|
|
106
122
|
case 'code':
|
|
123
|
+
if (typeof count === 'number') {
|
|
124
|
+
return t('Aucun fichier de code source | 1 fichier de code source | {n} fichiers de code source', count)
|
|
125
|
+
}
|
|
107
126
|
return t('Code source')
|
|
108
127
|
case 'other':
|
|
128
|
+
if (typeof count === 'number') {
|
|
129
|
+
return t('Aucun autre fichier | 1 autre fichier | {n} autres fichiers', count)
|
|
130
|
+
}
|
|
109
131
|
return t('Autre')
|
|
110
132
|
}
|
|
111
133
|
}
|
|
@@ -129,3 +151,97 @@ export const detectOgcService = (resource: Resource) => {
|
|
|
129
151
|
}
|
|
130
152
|
return false
|
|
131
153
|
}
|
|
154
|
+
|
|
155
|
+
export function isCommunityResource(resource: Resource | CommunityResource): boolean {
|
|
156
|
+
return 'organization' in resource || 'owner' in resource
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function getResourceExternalUrl(dataset: Dataset | DatasetV2 | Omit<Dataset, 'resources' | 'community_resources'>, resource: Resource | CommunityResource): string {
|
|
160
|
+
return `${dataset.page}${isCommunityResource(resource) ? '/community-resources' : ''}?resource_id=${resource.id}`
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function getResourceFilesize(resource: Resource): null | number {
|
|
164
|
+
if (resource.filesize) return resource.filesize
|
|
165
|
+
if ('analysis:content-length' in resource.extras) return resource.extras['analysis:content-length'] as number
|
|
166
|
+
|
|
167
|
+
return null
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const IMAGE_PREVIEW_FORMATS = ['png', 'jpg', 'jpeg', 'jpe', 'gif', 'webp'] as const
|
|
171
|
+
|
|
172
|
+
export function isImagePreviewFormat(format: string | undefined | null): boolean {
|
|
173
|
+
if (!format) return false
|
|
174
|
+
return IMAGE_PREVIEW_FORMATS.includes(format.toLowerCase() as typeof IMAGE_PREVIEW_FORMATS[number])
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Parsing errors are stored as `<step>:<message>`, where `<step>` names the
|
|
178
|
+
// analysis step that failed (e.g. `pmtiles_export`, `geojson_export`).
|
|
179
|
+
|
|
180
|
+
/** The analysis step that failed, or null when there is no parsing error. */
|
|
181
|
+
export function getParsingErrorStep(resource: Resource): string | null {
|
|
182
|
+
const error = resource.extras['analysis:parsing:error']
|
|
183
|
+
if (typeof error !== 'string' || !error) return null
|
|
184
|
+
const [step] = error.split(':', 1)
|
|
185
|
+
return step ?? null
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** The parsing error message without its `<step>:` prefix, or null when there is none. */
|
|
189
|
+
export function getParsingErrorMessage(resource: Resource): string | null {
|
|
190
|
+
const error = resource.extras['analysis:parsing:error']
|
|
191
|
+
if (typeof error !== 'string' || !error) return null
|
|
192
|
+
const colon = error.indexOf(':')
|
|
193
|
+
return colon === -1 ? error : error.slice(colon + 1)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Geo/format export steps run *after* the tabular table has been built, so a
|
|
197
|
+
// failure here (e.g. a huge geometry timing out the pmtiles export) leaves the
|
|
198
|
+
// tabular data fully usable and must not disable the tabular explorer.
|
|
199
|
+
const NON_TABULAR_PARSING_ERROR_STEPS = ['pmtiles_export', 'geojson_export']
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Whether the resource's parsing error prevents reading its tabular data.
|
|
203
|
+
* Only errors from the tabular parsing itself are fatal; downstream geo/format
|
|
204
|
+
* export failures are not.
|
|
205
|
+
*/
|
|
206
|
+
export function hasTabularParsingError(resource: Resource): boolean {
|
|
207
|
+
const step = getParsingErrorStep(resource)
|
|
208
|
+
return step !== null && !NON_TABULAR_PARSING_ERROR_STEPS.includes(step)
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
type CorsStatus = 'allowed' | 'blocked' | 'unknown'
|
|
212
|
+
|
|
213
|
+
export const getResourceCorsStatus = (resource: Resource): CorsStatus => {
|
|
214
|
+
const extras = resource.extras
|
|
215
|
+
if (!extras || !('check:cors:allow-origin' in extras)) {
|
|
216
|
+
return 'unknown'
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const allowOrigin = extras['check:cors:allow-origin'] as string | undefined
|
|
220
|
+
const rawMethods = extras['check:cors:allow-methods'] as string | undefined
|
|
221
|
+
|
|
222
|
+
// Check if allow-origin is '*' or contains one of our trusted domains
|
|
223
|
+
const config = useComponentsConfig()
|
|
224
|
+
const trustedDomains = config.trustedDomains ?? []
|
|
225
|
+
const hasPublicCors = allowOrigin === '*'
|
|
226
|
+
const hasSpecificCors = allowOrigin
|
|
227
|
+
? trustedDomains.some((domain) => {
|
|
228
|
+
try {
|
|
229
|
+
const hostname = new URL(allowOrigin).hostname
|
|
230
|
+
return hostname === domain || hostname.endsWith(`.${domain}`)
|
|
231
|
+
}
|
|
232
|
+
catch {
|
|
233
|
+
return false
|
|
234
|
+
}
|
|
235
|
+
})
|
|
236
|
+
: false
|
|
237
|
+
|
|
238
|
+
const isOriginAllowed = hasPublicCors || hasSpecificCors
|
|
239
|
+
|
|
240
|
+
// Ensure GET method is allowed
|
|
241
|
+
const allowedMethods = rawMethods
|
|
242
|
+
? rawMethods.split(',').map(m => m.trim().toUpperCase())
|
|
243
|
+
: []
|
|
244
|
+
const supportsGet = allowedMethods.length === 0 || allowedMethods.includes('GET')
|
|
245
|
+
|
|
246
|
+
return isOriginAllowed && supportsGet ? 'allowed' : 'blocked'
|
|
247
|
+
}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { Component } from 'vue'
|
|
2
|
+
import {
|
|
3
|
+
RiHashtag,
|
|
4
|
+
RiPriceTag3Line,
|
|
5
|
+
RiText,
|
|
6
|
+
RiCalendarLine,
|
|
7
|
+
RiCalendarEventLine,
|
|
8
|
+
RiTimeLine,
|
|
9
|
+
RiCheckboxLine,
|
|
10
|
+
RiMapPin2Line,
|
|
11
|
+
RiGlobalLine,
|
|
12
|
+
RiFocus3Line,
|
|
13
|
+
RiFingerprintLine,
|
|
14
|
+
RiMailLine,
|
|
15
|
+
RiLinksLine,
|
|
16
|
+
RiPhoneLine,
|
|
17
|
+
RiUserLine,
|
|
18
|
+
RiMoneyEuroCircleLine,
|
|
19
|
+
RiPercentLine,
|
|
20
|
+
RiBracesLine,
|
|
21
|
+
RiCodeLine,
|
|
22
|
+
} from '@remixicon/vue'
|
|
23
|
+
import { useTranslation } from '../composables/useTranslation'
|
|
24
|
+
import type { TranslationFunction } from '../composables/useTranslation'
|
|
25
|
+
import type { ColumnFilters, ColumnType } from '../components/TabularExplorer/types'
|
|
26
|
+
|
|
27
|
+
export function hasFilterForColumn(filters: Record<string, ColumnFilters>, column: string): boolean {
|
|
28
|
+
const f = filters[column]
|
|
29
|
+
if (!f) return false
|
|
30
|
+
return !!(f.in?.length || f.exact != null || f.contains || f.null || f.min != null || f.max != null)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type TypeDisplay = {
|
|
34
|
+
icon: Component
|
|
35
|
+
label: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function buildTypeConfig(t: TranslationFunction): Record<ColumnType, TypeDisplay> {
|
|
39
|
+
return {
|
|
40
|
+
number: { icon: RiHashtag, label: t('Nombre') },
|
|
41
|
+
categorical: { icon: RiPriceTag3Line, label: t('Catégoriel') },
|
|
42
|
+
text: { icon: RiText, label: t('Texte') },
|
|
43
|
+
date: { icon: RiCalendarLine, label: t('Date') },
|
|
44
|
+
boolean: { icon: RiCheckboxLine, label: t('Booléen') },
|
|
45
|
+
year: { icon: RiCalendarLine, label: t('Année') },
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function resolveColumnType(colInfo: { python_type: string, format?: string }, isCategorical: boolean): ColumnType {
|
|
50
|
+
if (colInfo.format === 'year') return 'year'
|
|
51
|
+
if (['int', 'float'].includes(colInfo.python_type)) return 'number'
|
|
52
|
+
if (['date', 'datetime'].includes(colInfo.python_type)) return 'date'
|
|
53
|
+
if (colInfo.python_type === 'bool') return 'boolean'
|
|
54
|
+
if (isCategorical) return 'categorical'
|
|
55
|
+
return 'text'
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// csv-detective formats that carry no semantic meaning beyond the generic
|
|
59
|
+
// display type already resolved by `ColumnType` — these fall back to
|
|
60
|
+
// `buildTypeConfig` (Texte / Nombre / Date / Booléen) in the header.
|
|
61
|
+
export const GENERIC_FORMATS = new Set(['string', 'int', 'float', 'date', 'bool', 'booleen'])
|
|
62
|
+
|
|
63
|
+
// Semantic types detected by csv-detective (see ../../../csv-detective/csv_detective/formats).
|
|
64
|
+
// The list is intentionally exhaustive, but unknown formats are tolerated:
|
|
65
|
+
// `getColumnDisplay` humanizes any format missing from this map.
|
|
66
|
+
export function buildFormatConfig(t: TranslationFunction): Record<string, TypeDisplay> {
|
|
67
|
+
return {
|
|
68
|
+
// Geo — territories & addresses
|
|
69
|
+
adresse: { icon: RiMapPin2Line, label: t('Adresse') },
|
|
70
|
+
commune: { icon: RiMapPin2Line, label: t('Commune') },
|
|
71
|
+
code_commune: { icon: RiMapPin2Line, label: t('Code INSEE commune') },
|
|
72
|
+
code_commune_insee: { icon: RiMapPin2Line, label: t('Code INSEE commune') },
|
|
73
|
+
departement: { icon: RiMapPin2Line, label: t('Département') },
|
|
74
|
+
code_departement: { icon: RiMapPin2Line, label: t('Code département') },
|
|
75
|
+
region: { icon: RiMapPin2Line, label: t('Région') },
|
|
76
|
+
code_region: { icon: RiMapPin2Line, label: t('Code région') },
|
|
77
|
+
code_epci: { icon: RiMapPin2Line, label: t('Code EPCI') },
|
|
78
|
+
code_postal: { icon: RiMapPin2Line, label: t('Code postal') },
|
|
79
|
+
insee_canton: { icon: RiMapPin2Line, label: t('Canton') },
|
|
80
|
+
code_fantoir: { icon: RiMapPin2Line, label: t('Code FANTOIR') },
|
|
81
|
+
id_rnb: { icon: RiMapPin2Line, label: t('Identifiant RNB') },
|
|
82
|
+
// Geo — countries
|
|
83
|
+
pays: { icon: RiGlobalLine, label: t('Pays') },
|
|
84
|
+
iso_country_code_alpha2: { icon: RiGlobalLine, label: t('Code pays (ISO α-2)') },
|
|
85
|
+
iso_country_code_alpha3: { icon: RiGlobalLine, label: t('Code pays (ISO α-3)') },
|
|
86
|
+
iso_country_code_numeric: { icon: RiGlobalLine, label: t('Code pays (ISO num.)') },
|
|
87
|
+
// Geo — coordinates
|
|
88
|
+
latitude_wgs: { icon: RiFocus3Line, label: t('Latitude') },
|
|
89
|
+
latitude_wgs_fr_metropole: { icon: RiFocus3Line, label: t('Latitude') },
|
|
90
|
+
longitude_wgs: { icon: RiFocus3Line, label: t('Longitude') },
|
|
91
|
+
longitude_wgs_fr_metropole: { icon: RiFocus3Line, label: t('Longitude') },
|
|
92
|
+
latitude_l93: { icon: RiFocus3Line, label: t('Latitude (Lambert 93)') },
|
|
93
|
+
longitude_l93: { icon: RiFocus3Line, label: t('Longitude (Lambert 93)') },
|
|
94
|
+
latlon_wgs: { icon: RiFocus3Line, label: t('Latitude / longitude') },
|
|
95
|
+
lonlat_wgs: { icon: RiFocus3Line, label: t('Longitude / latitude') },
|
|
96
|
+
// Identifiers
|
|
97
|
+
siren: { icon: RiFingerprintLine, label: t('SIREN') },
|
|
98
|
+
siret: { icon: RiFingerprintLine, label: t('SIRET') },
|
|
99
|
+
code_rna: { icon: RiFingerprintLine, label: t('Identifiant RNA') },
|
|
100
|
+
code_waldec: { icon: RiFingerprintLine, label: t('Identifiant WALDEC') },
|
|
101
|
+
code_import: { icon: RiFingerprintLine, label: t('Code Import') },
|
|
102
|
+
uai: { icon: RiFingerprintLine, label: t('UAI') },
|
|
103
|
+
insee_ape700: { icon: RiFingerprintLine, label: t('Code APE') },
|
|
104
|
+
code_csp_insee: { icon: RiFingerprintLine, label: t('Code CSP') },
|
|
105
|
+
uuid: { icon: RiFingerprintLine, label: t('UUID') },
|
|
106
|
+
mongo_object_id: { icon: RiFingerprintLine, label: t('Identifiant Mongo') },
|
|
107
|
+
// Contact
|
|
108
|
+
email: { icon: RiMailLine, label: t('Email') },
|
|
109
|
+
url: { icon: RiLinksLine, label: t('URL') },
|
|
110
|
+
tel_fr: { icon: RiPhoneLine, label: t('Téléphone') },
|
|
111
|
+
username: { icon: RiUserLine, label: t('Nom d\'utilisateur') },
|
|
112
|
+
// People
|
|
113
|
+
sexe: { icon: RiUserLine, label: t('Sexe') },
|
|
114
|
+
csp_insee: { icon: RiUserLine, label: t('Catégorie socio-pro.') },
|
|
115
|
+
// Quantities
|
|
116
|
+
money: { icon: RiMoneyEuroCircleLine, label: t('Montant') },
|
|
117
|
+
percent: { icon: RiPercentLine, label: t('Pourcentage') },
|
|
118
|
+
// Temporal
|
|
119
|
+
year: { icon: RiCalendarLine, label: t('Année') },
|
|
120
|
+
date_fr: { icon: RiCalendarLine, label: t('Date') },
|
|
121
|
+
jour_de_la_semaine: { icon: RiCalendarEventLine, label: t('Jour de la semaine') },
|
|
122
|
+
mois_de_lannee: { icon: RiCalendarEventLine, label: t('Mois de l\'année') },
|
|
123
|
+
datetime_naive: { icon: RiTimeLine, label: t('Date et heure') },
|
|
124
|
+
datetime_aware: { icon: RiTimeLine, label: t('Date et heure') },
|
|
125
|
+
datetime_rfc822: { icon: RiTimeLine, label: t('Date et heure') },
|
|
126
|
+
// Structured
|
|
127
|
+
json: { icon: RiBracesLine, label: t('JSON') },
|
|
128
|
+
geojson: { icon: RiBracesLine, label: t('GeoJSON') },
|
|
129
|
+
binary: { icon: RiCodeLine, label: t('Binaire') },
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Tolerant fallback for a semantic format we don't explicitly know about:
|
|
134
|
+
// "code_truc_machin" -> "Code truc machin".
|
|
135
|
+
export function humanizeFormat(format: string): string {
|
|
136
|
+
const spaced = format.replace(/_/g, ' ').trim()
|
|
137
|
+
return spaced.charAt(0).toUpperCase() + spaced.slice(1)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function useFormatTabular() {
|
|
141
|
+
const { locale } = useTranslation()
|
|
142
|
+
|
|
143
|
+
function formatNumber(value: unknown): string {
|
|
144
|
+
const num = Number(value)
|
|
145
|
+
if (Number.isNaN(num)) return String(value)
|
|
146
|
+
return num.toLocaleString(locale)
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function formatCellDate(value: unknown): string {
|
|
150
|
+
if (value == null || value === '') return '–'
|
|
151
|
+
const d = new Date(String(value))
|
|
152
|
+
if (Number.isNaN(d.getTime())) return String(value)
|
|
153
|
+
return new Intl.DateTimeFormat(locale, { day: '2-digit', month: '2-digit', year: 'numeric' }).format(d)
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
return { formatNumber, formatCellDate }
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const TRUTHY_VALUES = ['true', '1', 'oui', 'yes']
|
|
160
|
+
const FALSY_VALUES = ['false', '0', 'non', 'no']
|
|
161
|
+
|
|
162
|
+
// `encodeURIComponent` leaves `.`, `(` and `)` as-is, but they are the operator
|
|
163
|
+
// separator and the delimiters of the API's `or(...)` grammar: a search value
|
|
164
|
+
// containing one makes the parser reject the whole query with a 400. Wrapping
|
|
165
|
+
// the value in double quotes (as the API README suggests) does not work here —
|
|
166
|
+
// the API keeps them as part of the searched string and returns no result. It
|
|
167
|
+
// does percent-decode the value after parsing, so encoding them is enough.
|
|
168
|
+
function encodeConditionValue(value: string): string {
|
|
169
|
+
return encodeURIComponent(value)
|
|
170
|
+
.replace(/\./g, '%2E')
|
|
171
|
+
.replace(/\(/g, '%28')
|
|
172
|
+
.replace(/\)/g, '%29')
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// A decimal literal, not `Number()`: the API compares against a number column,
|
|
176
|
+
// and it answers an error for the whole `or(...)` when it is handed something it
|
|
177
|
+
// cannot parse as one — which `Number()` happily accepts (`0x10`, `1e5`, ` `).
|
|
178
|
+
const NUMBER_LITERAL_RE = /^-?\d+(\.\d+)?$/
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Builds the OR conditions for global search across all columns.
|
|
182
|
+
* Text and categorical columns get a `__contains` filter; number columns
|
|
183
|
+
* get a `__exact` filter only when the search value is numeric.
|
|
184
|
+
* Year, date and boolean columns are excluded.
|
|
185
|
+
*/
|
|
186
|
+
export function buildGlobalSearchConditions(
|
|
187
|
+
allColumns: string[],
|
|
188
|
+
getColumnType: (col: string) => ColumnType,
|
|
189
|
+
searchValue: string,
|
|
190
|
+
): string[] {
|
|
191
|
+
const conditions: string[] = []
|
|
192
|
+
for (const col of allColumns) {
|
|
193
|
+
const type = getColumnType(col)
|
|
194
|
+
if (type === 'text' || type === 'categorical') {
|
|
195
|
+
conditions.push(col + '__contains.' + encodeConditionValue(searchValue))
|
|
196
|
+
}
|
|
197
|
+
else if (type === 'number' && NUMBER_LITERAL_RE.test(searchValue)) {
|
|
198
|
+
conditions.push(col + '__exact.' + encodeConditionValue(searchValue))
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
return conditions
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export function isTruthy(value: unknown): boolean {
|
|
205
|
+
if (typeof value === 'boolean') return value
|
|
206
|
+
if (typeof value === 'string') return TRUTHY_VALUES.includes(value.toLowerCase())
|
|
207
|
+
return Boolean(value)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function isFalsy(value: unknown): boolean {
|
|
211
|
+
if (typeof value === 'boolean') return !value
|
|
212
|
+
if (typeof value === 'string') return FALSY_VALUES.includes(value.toLowerCase())
|
|
213
|
+
return !value
|
|
214
|
+
}
|
|
@@ -1,20 +1,105 @@
|
|
|
1
1
|
import { ofetch } from 'ofetch'
|
|
2
2
|
import { useComponentsConfig, type PluginConfig } from '../config'
|
|
3
|
+
import type { GenericFilter } from '../types/visualizations'
|
|
4
|
+
import type { SortConfig, TabularProfileResponse } from '../components/TabularExplorer/types'
|
|
3
5
|
|
|
4
|
-
export type SortConfig
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
export type { SortConfig }
|
|
7
|
+
|
|
8
|
+
export type TabularDataResponse = {
|
|
9
|
+
data: Array<Record<string, unknown>>
|
|
10
|
+
links: {
|
|
11
|
+
profile: string
|
|
12
|
+
swagger: string
|
|
13
|
+
next: string
|
|
14
|
+
}
|
|
15
|
+
meta: { total: number }
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type TabularAggregateType = 'avg' | 'sum' | 'count' | 'min' | 'max'
|
|
19
|
+
|
|
20
|
+
export type FetchTabularDataOptions = {
|
|
21
|
+
resourceId: string
|
|
22
|
+
page?: number
|
|
23
|
+
pageSize?: number
|
|
24
|
+
columns?: Array<string> | undefined
|
|
25
|
+
sort?: SortConfig
|
|
26
|
+
groupBy?: string | undefined
|
|
27
|
+
aggregation?: {
|
|
28
|
+
column: string
|
|
29
|
+
type: TabularAggregateType
|
|
30
|
+
} | undefined
|
|
31
|
+
filters?: GenericFilter | undefined
|
|
32
|
+
}
|
|
8
33
|
|
|
9
34
|
/**
|
|
10
|
-
* Call Tabular-api to get table content
|
|
35
|
+
* Call Tabular-api to get table content with options object
|
|
11
36
|
*/
|
|
12
|
-
export async function
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
37
|
+
export async function fetchTabularData(config: PluginConfig, options: FetchTabularDataOptions): Promise<TabularDataResponse> {
|
|
38
|
+
const page = options.page ?? 1
|
|
39
|
+
const pageSize = options.pageSize ?? config.tabularApiPageSize ?? 15
|
|
40
|
+
let url = `${config.tabularApiUrl}/api/resources/${options.resourceId}/data/?page=${page}&page_size=${pageSize}`
|
|
41
|
+
if (options.columns) {
|
|
42
|
+
url += `&columns=${options.columns.map(col => encodeURIComponent(col)).join(',')}`
|
|
43
|
+
}
|
|
44
|
+
if (options.sort) {
|
|
45
|
+
url += `&${encodeURIComponent(options.sort.column)}__sort=${encodeURIComponent(options.sort.direction)}`
|
|
46
|
+
}
|
|
47
|
+
if (options.groupBy && options.aggregation?.type) {
|
|
48
|
+
url += `&${encodeURIComponent(options.groupBy)}__groupby&${encodeURIComponent(options.aggregation.column)}__${encodeURIComponent(options.aggregation.type)}`
|
|
49
|
+
}
|
|
50
|
+
if (options.filters) {
|
|
51
|
+
const filterQuery = buildFilterQuery(options.filters)
|
|
52
|
+
if (filterQuery) {
|
|
53
|
+
url += `&${filterQuery}`
|
|
54
|
+
}
|
|
16
55
|
}
|
|
17
|
-
return await ofetch(url)
|
|
56
|
+
return await ofetch<TabularDataResponse>(url)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function buildFilterQuery(filters: GenericFilter): string {
|
|
60
|
+
const params: Array<string> = []
|
|
61
|
+
if ('filters' in filters) {
|
|
62
|
+
for (const filter of filters.filters) {
|
|
63
|
+
if ('filters' in filter) {
|
|
64
|
+
params.push(buildFilterQuery(filter))
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
if (filter.condition === 'is_null') {
|
|
68
|
+
params.push(`${encodeURIComponent(filter.column)}__isnull`)
|
|
69
|
+
}
|
|
70
|
+
else if (filter.condition === 'is_not_null') {
|
|
71
|
+
params.push(`${encodeURIComponent(filter.column)}__isnotnull`)
|
|
72
|
+
}
|
|
73
|
+
else if (filter.value !== null && filter.value !== undefined && filter.value !== '') {
|
|
74
|
+
params.push(`${encodeURIComponent(filter.column)}__${encodeURIComponent(filter.condition)}=${encodeURIComponent(filter.value)}`)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
const filter = filters
|
|
81
|
+
if (filter.condition === 'is_null') {
|
|
82
|
+
params.push(`${encodeURIComponent(filter.column)}__isnull`)
|
|
83
|
+
}
|
|
84
|
+
else if (filter.condition === 'is_not_null') {
|
|
85
|
+
params.push(`${encodeURIComponent(filter.column)}__isnotnull`)
|
|
86
|
+
}
|
|
87
|
+
else if (filter.value !== null && filter.value !== undefined && filter.value !== '') {
|
|
88
|
+
params.push(`${encodeURIComponent(filter.column)}__${encodeURIComponent(filter.condition)}=${encodeURIComponent(filter.value)}`)
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return params.join('&')
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Call Tabular-api to get table content
|
|
96
|
+
*/
|
|
97
|
+
export async function getData(config: PluginConfig, id: string, page: number, sortConfig?: SortConfig | null): Promise<TabularDataResponse> {
|
|
98
|
+
return fetchTabularData(config, {
|
|
99
|
+
resourceId: id,
|
|
100
|
+
page,
|
|
101
|
+
sort: sortConfig ?? undefined,
|
|
102
|
+
})
|
|
18
103
|
}
|
|
19
104
|
|
|
20
105
|
/**
|
|
@@ -22,5 +107,5 @@ export async function getData(config: PluginConfig, id: string, page: number, so
|
|
|
22
107
|
*/
|
|
23
108
|
export function useGetProfile() {
|
|
24
109
|
const config = useComponentsConfig()
|
|
25
|
-
return (id: string) => ofetch(`${config.tabularApiUrl}/api/resources/${id}/profile/`)
|
|
110
|
+
return (id: string) => ofetch<TabularProfileResponse>(`${config.tabularApiUrl}/api/resources/${id}/profile/`)
|
|
26
111
|
}
|