@datagouv/components-next 1.0.2-dev.126 → 1.0.2-dev.128

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,5 +1,5 @@
1
1
  /** Response from /api/resources/{rid}/data/ */
2
- export interface TabularDataResponse {
2
+ export type TabularDataResponse = {
3
3
  data: TabularRow[]
4
4
  meta: {
5
5
  page: number
@@ -17,11 +17,11 @@ export interface TabularDataResponse {
17
17
  export type TabularRow = Record<string, unknown> & { __id: number }
18
18
 
19
19
  /** Response from /api/resources/{rid}/profile/ */
20
- export interface TabularProfileResponse {
20
+ export type TabularProfileResponse = {
21
21
  profile: TabularProfile
22
22
  }
23
23
 
24
- export interface TabularProfile {
24
+ export type TabularProfile = {
25
25
  header: string[]
26
26
  columns: Record<string, TabularColumnInfo>
27
27
  formats: Record<string, string[]>
@@ -38,13 +38,13 @@ export interface TabularProfile {
38
38
  trailing_columns: number
39
39
  }
40
40
 
41
- export interface TabularColumnInfo {
41
+ export type TabularColumnInfo = {
42
42
  score: number
43
43
  format: string
44
44
  python_type: string
45
45
  }
46
46
 
47
- export interface TabularColumnProfile {
47
+ export type TabularColumnProfile = {
48
48
  tops: TabularTopValue[]
49
49
  nb_distinct: number
50
50
  nb_missing_values: number
@@ -54,14 +54,14 @@ export interface TabularColumnProfile {
54
54
  mean?: number
55
55
  }
56
56
 
57
- export interface TabularTopValue {
57
+ export type TabularTopValue = {
58
58
  value: string
59
59
  count: number
60
60
  }
61
61
 
62
62
  export type ColumnType = 'number' | 'categorical' | 'text' | 'date' | 'boolean'
63
63
 
64
- export interface ColumnFilters {
64
+ export type ColumnFilters = {
65
65
  in?: string[]
66
66
  exact?: string
67
67
  min?: number
@@ -72,12 +72,12 @@ export interface ColumnFilters {
72
72
 
73
73
  export type SortDirection = 'asc' | 'desc'
74
74
 
75
- export interface SortConfig {
75
+ export type SortConfig = {
76
76
  column: string
77
77
  direction: SortDirection
78
78
  }
79
79
 
80
- export interface BadgeStyle {
80
+ export type BadgeStyle = {
81
81
  backgroundColor: string
82
82
  color: string
83
83
  }
@@ -4,9 +4,24 @@ import {
4
4
  RiPriceTag3Line,
5
5
  RiText,
6
6
  RiCalendarLine,
7
+ RiCalendarEventLine,
8
+ RiTimeLine,
7
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,
8
22
  } from '@remixicon/vue'
9
23
  import { useTranslation } from '../composables/useTranslation'
24
+ import type { TranslationFunction } from '../composables/useTranslation'
10
25
  import type { ColumnFilters, ColumnType } from '../components/TabularExplorer/types'
11
26
 
12
27
  export function hasFilterForColumn(filters: Record<string, ColumnFilters>, column: string): boolean {
@@ -15,7 +30,12 @@ export function hasFilterForColumn(filters: Record<string, ColumnFilters>, colum
15
30
  return !!(f.in?.length || f.exact != null || f.contains || f.null || f.min != null || f.max != null)
16
31
  }
17
32
 
18
- export function buildTypeConfig(t: (s: string) => string): Record<ColumnType, { icon: Component, label: string }> {
33
+ export type TypeDisplay = {
34
+ icon: Component
35
+ label: string
36
+ }
37
+
38
+ export function buildTypeConfig(t: TranslationFunction): Record<ColumnType, TypeDisplay> {
19
39
  return {
20
40
  number: { icon: RiHashtag, label: t('Nombre') },
21
41
  categorical: { icon: RiPriceTag3Line, label: t('Catégoriel') },
@@ -25,6 +45,88 @@ export function buildTypeConfig(t: (s: string) => string): Record<ColumnType, {
25
45
  }
26
46
  }
27
47
 
48
+ // csv-detective formats that carry no semantic meaning beyond the generic
49
+ // display type already resolved by `ColumnType` — these fall back to
50
+ // `buildTypeConfig` (Texte / Nombre / Date / Booléen) in the header.
51
+ export const GENERIC_FORMATS = new Set(['string', 'int', 'float', 'date', 'bool', 'booleen'])
52
+
53
+ // Semantic types detected by csv-detective (see ../../../csv-detective/csv_detective/formats).
54
+ // The list is intentionally exhaustive, but unknown formats are tolerated:
55
+ // `getColumnDisplay` humanizes any format missing from this map.
56
+ export function buildFormatConfig(t: TranslationFunction): Record<string, TypeDisplay> {
57
+ return {
58
+ // Geo — territories & addresses
59
+ adresse: { icon: RiMapPin2Line, label: t('Adresse') },
60
+ commune: { icon: RiMapPin2Line, label: t('Commune') },
61
+ code_commune: { icon: RiMapPin2Line, label: t('Code INSEE commune') },
62
+ code_commune_insee: { icon: RiMapPin2Line, label: t('Code INSEE commune') },
63
+ departement: { icon: RiMapPin2Line, label: t('Département') },
64
+ code_departement: { icon: RiMapPin2Line, label: t('Code département') },
65
+ region: { icon: RiMapPin2Line, label: t('Région') },
66
+ code_region: { icon: RiMapPin2Line, label: t('Code région') },
67
+ code_epci: { icon: RiMapPin2Line, label: t('Code EPCI') },
68
+ code_postal: { icon: RiMapPin2Line, label: t('Code postal') },
69
+ insee_canton: { icon: RiMapPin2Line, label: t('Canton') },
70
+ code_fantoir: { icon: RiMapPin2Line, label: t('Code FANTOIR') },
71
+ id_rnb: { icon: RiMapPin2Line, label: t('Identifiant RNB') },
72
+ // Geo — countries
73
+ pays: { icon: RiGlobalLine, label: t('Pays') },
74
+ iso_country_code_alpha2: { icon: RiGlobalLine, label: t('Code pays (ISO α-2)') },
75
+ iso_country_code_alpha3: { icon: RiGlobalLine, label: t('Code pays (ISO α-3)') },
76
+ iso_country_code_numeric: { icon: RiGlobalLine, label: t('Code pays (ISO num.)') },
77
+ // Geo — coordinates
78
+ latitude_wgs: { icon: RiFocus3Line, label: t('Latitude') },
79
+ latitude_wgs_fr_metropole: { icon: RiFocus3Line, label: t('Latitude') },
80
+ longitude_wgs: { icon: RiFocus3Line, label: t('Longitude') },
81
+ longitude_wgs_fr_metropole: { icon: RiFocus3Line, label: t('Longitude') },
82
+ latitude_l93: { icon: RiFocus3Line, label: t('Latitude (Lambert 93)') },
83
+ longitude_l93: { icon: RiFocus3Line, label: t('Longitude (Lambert 93)') },
84
+ latlon_wgs: { icon: RiFocus3Line, label: t('Latitude / longitude') },
85
+ lonlat_wgs: { icon: RiFocus3Line, label: t('Longitude / latitude') },
86
+ // Identifiers
87
+ siren: { icon: RiFingerprintLine, label: t('SIREN') },
88
+ siret: { icon: RiFingerprintLine, label: t('SIRET') },
89
+ code_rna: { icon: RiFingerprintLine, label: t('Identifiant RNA') },
90
+ code_waldec: { icon: RiFingerprintLine, label: t('Identifiant WALDEC') },
91
+ code_import: { icon: RiFingerprintLine, label: t('Code Import') },
92
+ uai: { icon: RiFingerprintLine, label: t('UAI') },
93
+ insee_ape700: { icon: RiFingerprintLine, label: t('Code APE') },
94
+ code_csp_insee: { icon: RiFingerprintLine, label: t('Code CSP') },
95
+ uuid: { icon: RiFingerprintLine, label: t('UUID') },
96
+ mongo_object_id: { icon: RiFingerprintLine, label: t('Identifiant Mongo') },
97
+ // Contact
98
+ email: { icon: RiMailLine, label: t('Email') },
99
+ url: { icon: RiLinksLine, label: t('URL') },
100
+ tel_fr: { icon: RiPhoneLine, label: t('Téléphone') },
101
+ username: { icon: RiUserLine, label: t('Nom d\'utilisateur') },
102
+ // People
103
+ sexe: { icon: RiUserLine, label: t('Sexe') },
104
+ csp_insee: { icon: RiUserLine, label: t('Catégorie socio-pro.') },
105
+ // Quantities
106
+ money: { icon: RiMoneyEuroCircleLine, label: t('Montant') },
107
+ percent: { icon: RiPercentLine, label: t('Pourcentage') },
108
+ // Temporal
109
+ year: { icon: RiCalendarLine, label: t('Année') },
110
+ date_fr: { icon: RiCalendarLine, label: t('Date') },
111
+ jour_de_la_semaine: { icon: RiCalendarEventLine, label: t('Jour de la semaine') },
112
+ mois_de_lannee: { icon: RiCalendarEventLine, label: t('Mois de l\'année') },
113
+ datetime_naive: { icon: RiTimeLine, label: t('Date et heure') },
114
+ datetime_aware: { icon: RiTimeLine, label: t('Date et heure') },
115
+ datetime_rfc822: { icon: RiTimeLine, label: t('Date et heure') },
116
+ // Structured
117
+ json: { icon: RiBracesLine, label: t('JSON') },
118
+ geojson: { icon: RiBracesLine, label: t('GeoJSON') },
119
+ binary: { icon: RiCodeLine, label: t('Binaire') },
120
+ }
121
+ }
122
+
123
+ // Tolerant fallback for a semantic format we don't explicitly know about:
124
+ // "code_truc_machin" -> "Code truc machin".
125
+ export function humanizeFormat(format: string): string {
126
+ const spaced = format.replace(/_/g, ' ').trim()
127
+ return spaced.charAt(0).toUpperCase() + spaced.slice(1)
128
+ }
129
+
28
130
  export function useFormatTabular() {
29
131
  const { locale } = useTranslation()
30
132