@datagouv/components-next 1.0.2-dev.218 → 1.0.2-dev.219

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 { g as Ke } from "./main-hDFmYneb.js";
1
+ import { g as Ke } from "./main-HU94LBny.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.218",
3
+ "version": "1.0.2-dev.219",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "engines": {
@@ -80,7 +80,7 @@ import {
80
80
  } from '@remixicon/vue'
81
81
  import { toast } from 'vue-sonner'
82
82
  import { useTranslation } from '../../composables/useTranslation'
83
- import { buildTypeConfig, toIsoDay } from '../../functions/tabular'
83
+ import { buildCellValueFilter, buildTypeConfig } from '../../functions/tabular'
84
84
  import ClientOnly from '../ClientOnly.vue'
85
85
  import type { ColumnType, ColumnFilters } from './types'
86
86
 
@@ -128,36 +128,10 @@ function close() {
128
128
 
129
129
  function filterByValue() {
130
130
  if (!cell.value) return
131
- const val = String(cell.value.value ?? '')
132
131
  const col = cell.value.column
133
- const existing = filters.value[col] ?? {}
134
- // A date goes through the same `date` filter the column panel writes, so the
135
- // calendar opens on the day that was clicked instead of on an empty month.
136
- if (cell.value.columnType === 'date') {
137
- const day = toIsoDay(cell.value.value)
138
- if (day) {
139
- filters.value = { ...filters.value, [col]: { ...existing, date: { operator: 'is', start: day } } }
140
- }
141
- // An empty cell has no day to select: filtering on the missing values is
142
- // what "this value" means there, and the panel shows it as such.
143
- else if (cell.value.value == null || cell.value.value === '') {
144
- filters.value = { ...filters.value, [col]: { ...existing, null: 'only' } }
145
- }
146
- }
147
- else if (cell.value.columnType === 'categorical' || cell.value.columnType === 'text' || cell.value.columnType === 'year') {
148
- const current = existing.in ?? []
149
- if (!current.includes(val)) {
150
- filters.value = { ...filters.value, [col]: { ...existing, in: [...current, val] } }
151
- }
152
- }
153
- else if (cell.value.columnType === 'number') {
154
- const num = Number(cell.value.value)
155
- if (Number.isFinite(num)) {
156
- filters.value = { ...filters.value, [col]: { ...existing, min: num, max: num } }
157
- }
158
- }
159
- else if (cell.value.columnType === 'boolean') {
160
- filters.value = { ...filters.value, [col]: { ...existing, exact: val } }
132
+ filters.value = {
133
+ ...filters.value,
134
+ [col]: buildCellValueFilter(cell.value.columnType, cell.value.value, filters.value[col] ?? {}),
161
135
  }
162
136
  close()
163
137
  }
@@ -93,6 +93,39 @@ export function buildDateFilterParams(column: string, filter: DateFilter): Recor
93
93
  return params
94
94
  }
95
95
 
96
+ /**
97
+ * The filter "filter by this value" sets on a column for the cell that was
98
+ * clicked, merged into the filters already set on that column.
99
+ *
100
+ * An empty cell holds no value to match on: whatever the column type, filtering
101
+ * on the missing values is what "this value" means there — and it is the filter
102
+ * the column panel offers for them.
103
+ */
104
+ export function buildCellValueFilter(columnType: ColumnType, value: unknown, existing: ColumnFilters): ColumnFilters {
105
+ if (value == null || value === '') return { ...existing, null: 'only' }
106
+ switch (columnType) {
107
+ // A date goes through the same `date` filter the column panel writes, so the
108
+ // calendar opens on the day that was clicked instead of on an empty month.
109
+ case 'date': {
110
+ const day = toIsoDay(value)
111
+ return day ? { ...existing, date: { operator: 'is', start: day } } : existing
112
+ }
113
+ case 'number': {
114
+ const num = Number(value)
115
+ return Number.isFinite(num) ? { ...existing, min: num, max: num } : existing
116
+ }
117
+ case 'boolean':
118
+ return { ...existing, exact: String(value) }
119
+ case 'categorical':
120
+ case 'text':
121
+ case 'year': {
122
+ const val = String(value)
123
+ const selected = existing.in ?? []
124
+ return selected.includes(val) ? existing : { ...existing, in: [...selected, val] }
125
+ }
126
+ }
127
+ }
128
+
96
129
  export type TypeDisplay = {
97
130
  icon: Component
98
131
  label: string