@shefing/quickfilter 1.0.31 → 1.0.33
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 +62 -4
- package/dist/QuickFilter.d.ts.map +1 -1
- package/dist/QuickFilter.js +33 -231
- package/dist/QuickFilter.js.map +1 -1
- package/dist/filters/components/select-filter.js +2 -2
- package/dist/filters/components/select-filter.js.map +1 -1
- package/dist/filters/constants/date-filter-options.d.ts +2 -2
- package/dist/filters/constants/date-filter-options.d.ts.map +1 -1
- package/dist/filters/constants/date-filter-options.js +4 -1
- package/dist/filters/constants/date-filter-options.js.map +1 -1
- package/dist/filters/utils/date-helpers.d.ts.map +1 -1
- package/dist/filters/utils/date-helpers.js +26 -0
- package/dist/filters/utils/date-helpers.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/labels.d.ts +38 -2
- package/dist/labels.d.ts.map +1 -1
- package/dist/labels.js +19 -1
- package/dist/labels.js.map +1 -1
- package/dist/lib/utils.d.ts +4 -0
- package/dist/lib/utils.d.ts.map +1 -1
- package/dist/lib/utils.js +186 -0
- package/dist/lib/utils.js.map +1 -1
- package/dist/nav/NavHamburger/index.d.ts +5 -0
- package/dist/nav/NavHamburger/index.d.ts.map +1 -0
- package/dist/nav/NavHamburger/index.js +20 -0
- package/dist/nav/NavHamburger/index.js.map +1 -0
- package/dist/nav/NavWrapper/index.d.ts +7 -0
- package/dist/nav/NavWrapper/index.d.ts.map +1 -0
- package/dist/nav/NavWrapper/index.js +25 -0
- package/dist/nav/NavWrapper/index.js.map +1 -0
- package/dist/nav/NavWrapper/index.scss +27 -0
- package/dist/nav/getNavPrefs.d.ts +3 -0
- package/dist/nav/getNavPrefs.d.ts.map +1 -0
- package/dist/nav/getNavPrefs.js +31 -0
- package/dist/nav/getNavPrefs.js.map +1 -0
- package/dist/nav/index.client.d.ts +8 -0
- package/dist/nav/index.client.d.ts.map +1 -0
- package/dist/nav/index.client.js +93 -0
- package/dist/nav/index.client.js.map +1 -0
- package/dist/nav/index.d.ts +9 -0
- package/dist/nav/index.d.ts.map +1 -0
- package/dist/nav/index.js +200 -0
- package/dist/nav/index.js.map +1 -0
- package/dist/nav/index.scss +163 -0
- package/dist/ui/button.d.ts +1 -1
- package/dist/ui/command.d.ts +7 -7
- package/package.json +6 -1
package/README.md
CHANGED
|
@@ -12,7 +12,6 @@ Transform your PayloadCMS admin experience with instant, intuitive filters that
|
|
|
12
12
|
| **🎛️ Multiple Filter Types** | Date, select, checkbox, and small select filters |  |
|
|
13
13
|
| **📱 Responsive Layout** | Configurable row-based layout with custom widths |  |
|
|
14
14
|
| **🌍 Internationalization** | Full i18n support with RTL language compatibility |  |
|
|
15
|
-
| **💾 Persistent State** | Filters persist in localStorage and URL parameters |  |
|
|
16
15
|
| **📅 Smart Date Filtering** | Predefined ranges + custom date picker |  |
|
|
17
16
|
|
|
18
17
|
### 🎥 See It In Action
|
|
@@ -188,8 +187,8 @@ filterList: [
|
|
|
188
187
|
|
|
189
188
|
**✨ What you get:**
|
|
190
189
|
|
|
191
|
-
- 🕐 **Predefined time ranges**: Yesterday, Last Week, Last Month, All Past
|
|
192
|
-
- 🔮 **Future options**: Today,
|
|
190
|
+
- 🕐 **Predefined time ranges**: Yesterday, Last Week, Last Month, Last 7 Days, Last 30 Days, Last Year, Last 2 Years, All Past
|
|
191
|
+
- 🔮 **Future options**: Today, This Week, This Month, Next 7 Days, Next 30 Days, Today And Future, All Future
|
|
193
192
|
- 🎯 **Custom range**: Pick any from/to dates
|
|
194
193
|
- 🌍 **Localized**: Date formats adapt to user's language
|
|
195
194
|
|
|
@@ -352,7 +351,6 @@ Perfect for boolean fields like:
|
|
|
352
351
|
| **🎯 Simplicity** | Click and filter | Navigate to filter page, fill form, submit |
|
|
353
352
|
| **⚡ Speed** | Instant results as you click | Wait for page reload every time |
|
|
354
353
|
| **👀 Clarity** | `🔍 3 Active filters: Status • Role • Date` | Guess what filters are active |
|
|
355
|
-
| **💾 Persistent** | Filters persist across sessions | Start over every time |
|
|
356
354
|
|
|
357
355
|
|
|
358
356
|
</details>
|
|
@@ -479,6 +477,66 @@ CollectionQuickFilterPlugin({
|
|
|
479
477
|
|
|
480
478
|
</details>
|
|
481
479
|
|
|
480
|
+
### 🧭 NavDefaultFilter Component
|
|
481
|
+
|
|
482
|
+
<details>
|
|
483
|
+
<summary>⚙️ <strong>Using NavDefaultFilter in your admin UI</strong></summary>
|
|
484
|
+
|
|
485
|
+
The NavDefaultFilter component allows you to apply default filters to collection views directly from the navigation menu. This means users will see filtered data immediately when they click on a collection.
|
|
486
|
+
|
|
487
|
+
```typescript
|
|
488
|
+
// payload.config.ts
|
|
489
|
+
export default buildConfig({
|
|
490
|
+
admin: {
|
|
491
|
+
components: {
|
|
492
|
+
Nav: '@shefing/quickfilter/nav',
|
|
493
|
+
},
|
|
494
|
+
},
|
|
495
|
+
// ... rest of your config
|
|
496
|
+
});
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
**🎯 Collection Configuration Examples:**
|
|
500
|
+
|
|
501
|
+
1. Filter to show only today's and future meetings:
|
|
502
|
+
|
|
503
|
+
```typescript
|
|
504
|
+
export const Meetings: CollectionConfig = {
|
|
505
|
+
slug: 'meetings',
|
|
506
|
+
custom: {
|
|
507
|
+
defaultFilter: {
|
|
508
|
+
'meetingDate': 'todayAndFuture'
|
|
509
|
+
},
|
|
510
|
+
},
|
|
511
|
+
// ... rest of your collection config
|
|
512
|
+
};
|
|
513
|
+
```
|
|
514
|
+
|
|
515
|
+
2. Filter to show only unhandled items:
|
|
516
|
+
|
|
517
|
+
```typescript
|
|
518
|
+
export const Tasks: CollectionConfig = {
|
|
519
|
+
slug: 'tasks',
|
|
520
|
+
custom: {
|
|
521
|
+
filterList: [['type', 'createdAt', 'meetingDate', 'holdingsLimit', 'handled', 'acquireTask']],
|
|
522
|
+
defaultFilter: {
|
|
523
|
+
'handled': {
|
|
524
|
+
equals: false
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
},
|
|
528
|
+
// ... rest of your collection config
|
|
529
|
+
};
|
|
530
|
+
```
|
|
531
|
+
|
|
532
|
+
**✨ Benefits:**
|
|
533
|
+
|
|
534
|
+
- 🎯 **Context-aware navigation**: Users see the most relevant data immediately
|
|
535
|
+
- ⏱️ **Time-saving**: No need to manually apply filters after navigation
|
|
536
|
+
- 🧠 **Smart defaults**: Configure different default views for different collections
|
|
537
|
+
|
|
538
|
+
</details>
|
|
539
|
+
|
|
482
540
|
|
|
483
541
|
|
|
484
542
|
## Contributing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QuickFilter.d.ts","sourceRoot":"","sources":["../src/QuickFilter.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"QuickFilter.d.ts","sourceRoot":"","sources":["../src/QuickFilter.tsx"],"names":[],"mappings":"AAsGA,QAAA,MAAM,WAAW,0BAGd;IACD,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,CAAC,MAAM,GAAG;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,EAAE,EAAE,CAAA;CAC3D,gCA0RA,CAAA;AAED,eAAe,WAAW,CAAA"}
|
package/dist/QuickFilter.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useCallback, useEffect, useMemo,
|
|
3
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
4
4
|
import { useConfig, useListQuery, useTranslation } from '@payloadcms/ui';
|
|
5
5
|
import { getTranslation } from '@payloadcms/translations';
|
|
6
6
|
import FilterField from './FilterField';
|
|
7
7
|
import { getLabel } from './labels';
|
|
8
|
-
import { groupFiltersByRow
|
|
9
|
-
import { ChevronDown, ChevronUp, Filter, X } from 'lucide-react';
|
|
10
|
-
import { getDateRangeForOption } from './filters/utils/date-helpers';
|
|
8
|
+
import { groupFiltersByRow } from './filters/utils/layout-helpers';
|
|
9
|
+
import { ChevronDown, ChevronUp, Filter, RefreshCw, X } from 'lucide-react';
|
|
11
10
|
import { isEqual } from 'lodash';
|
|
12
|
-
import {
|
|
11
|
+
import { getDateFilterOptions } from './filters/constants/date-filter-options';
|
|
13
12
|
import { Button } from './ui/button';
|
|
13
|
+
import { buildQuickFilterConditions, parseWhereClauseToFilterValues } from './lib/utils';
|
|
14
14
|
// Helper function to get localized label
|
|
15
15
|
const getLocalizedLabel = (label, locale)=>{
|
|
16
16
|
if (typeof label === 'object' && label !== null) {
|
|
@@ -45,85 +45,6 @@ function findFieldsByName(fields, fieldNames) {
|
|
|
45
45
|
recursiveSearch(fields);
|
|
46
46
|
return results;
|
|
47
47
|
}
|
|
48
|
-
// Builds an array of condition objects from the quick filter values
|
|
49
|
-
const buildQuickFilterConditions = (values, fieldDefs, locale)=>{
|
|
50
|
-
const conditions = [];
|
|
51
|
-
Object.entries(values).forEach(([fieldName, value])=>{
|
|
52
|
-
if (!value) return;
|
|
53
|
-
const fieldDef = fieldDefs.find((f)=>f.name === fieldName);
|
|
54
|
-
if (!fieldDef) return;
|
|
55
|
-
let condition = null;
|
|
56
|
-
switch(fieldDef.type){
|
|
57
|
-
case 'date':
|
|
58
|
-
{
|
|
59
|
-
const dateValue = value;
|
|
60
|
-
let from;
|
|
61
|
-
let to;
|
|
62
|
-
if (dateValue.predefinedValue) {
|
|
63
|
-
const range = getDateRangeForOption(dateValue.predefinedValue, locale);
|
|
64
|
-
from = range.from;
|
|
65
|
-
to = range.to;
|
|
66
|
-
} else if (dateValue.customRange) {
|
|
67
|
-
if (dateValue.customRange.from) from = new Date(dateValue.customRange.from);
|
|
68
|
-
if (dateValue.customRange.to) to = new Date(dateValue.customRange.to);
|
|
69
|
-
}
|
|
70
|
-
if (from || to) {
|
|
71
|
-
const dateQuery = {};
|
|
72
|
-
if (from) dateQuery.greater_than_equal = from;
|
|
73
|
-
if (to) dateQuery.less_than_equal = to;
|
|
74
|
-
if (Object.keys(dateQuery).length > 0) {
|
|
75
|
-
condition = {
|
|
76
|
-
[fieldName]: dateQuery
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
case 'select':
|
|
83
|
-
{
|
|
84
|
-
const selectValue = value;
|
|
85
|
-
if (selectValue.selectedValues && selectValue.selectedValues.length > 0) {
|
|
86
|
-
if (selectValue.selectedValues.length === 1) {
|
|
87
|
-
condition = {
|
|
88
|
-
[fieldName]: {
|
|
89
|
-
equals: selectValue.selectedValues[0]
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
} else {
|
|
93
|
-
condition = {
|
|
94
|
-
[fieldName]: {
|
|
95
|
-
in: selectValue.selectedValues
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
break;
|
|
101
|
-
}
|
|
102
|
-
case 'checkbox':
|
|
103
|
-
{
|
|
104
|
-
const checkboxState = value;
|
|
105
|
-
if (checkboxState === 'checked') {
|
|
106
|
-
condition = {
|
|
107
|
-
[fieldName]: {
|
|
108
|
-
equals: 'true'
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
} else if (checkboxState === 'unchecked') {
|
|
112
|
-
condition = {
|
|
113
|
-
[fieldName]: {
|
|
114
|
-
equals: 'false'
|
|
115
|
-
}
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
break;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (condition) {
|
|
122
|
-
conditions.push(condition);
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
return conditions;
|
|
126
|
-
};
|
|
127
48
|
// Helper function to remove quick filter conditions from a 'where' clause
|
|
128
49
|
const cleanWhereClause = (clause, fieldsToClean)=>{
|
|
129
50
|
if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {
|
|
@@ -151,98 +72,7 @@ const cleanWhereClause = (clause, fieldsToClean)=>{
|
|
|
151
72
|
}
|
|
152
73
|
return newClause;
|
|
153
74
|
};
|
|
154
|
-
// Translates URL query conditions to the quick filter's internal state
|
|
155
|
-
const parseWhereClauseToFilterValues = (where, fields, locale)=>{
|
|
156
|
-
const values = {};
|
|
157
|
-
const fieldNames = new Set(fields.map((f)=>f.name));
|
|
158
|
-
const recursiveParse = (clause)=>{
|
|
159
|
-
if (!clause || typeof clause !== 'object') return;
|
|
160
|
-
if (clause.and) {
|
|
161
|
-
clause.and.forEach(recursiveParse);
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
if (clause.or) {
|
|
165
|
-
clause.or.forEach(recursiveParse);
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
for(const fieldName in clause){
|
|
169
|
-
if (fieldNames.has(fieldName)) {
|
|
170
|
-
const fieldDef = fields.find((f)=>f.name === fieldName);
|
|
171
|
-
const condition = clause[fieldName];
|
|
172
|
-
if (fieldDef && condition && typeof condition === 'object') {
|
|
173
|
-
if ('equals' in condition) {
|
|
174
|
-
if (fieldDef.type === 'checkbox') {
|
|
175
|
-
values[fieldName] = condition.equals == 'true' ? 'checked' : 'unchecked';
|
|
176
|
-
} else if (fieldDef.type === 'select') {
|
|
177
|
-
values[fieldName] = {
|
|
178
|
-
selectedValues: [
|
|
179
|
-
condition.equals
|
|
180
|
-
]
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
} else if ('in' in condition && Array.isArray(condition.in)) {
|
|
184
|
-
if (fieldDef.type === 'select') {
|
|
185
|
-
values[fieldName] = {
|
|
186
|
-
selectedValues: condition.in
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
} else if ('greater_than_equal' in condition || 'less_than_equal' in condition) {
|
|
190
|
-
if (fieldDef.type === 'date') {
|
|
191
|
-
const fromDate = condition.greater_than_equal ? new Date(condition.greater_than_equal) : null;
|
|
192
|
-
const toDate = condition.less_than_equal ? new Date(condition.less_than_equal) : null;
|
|
193
|
-
const allDateOptions = [
|
|
194
|
-
...pastOptionKeys,
|
|
195
|
-
...futureOptionKeys
|
|
196
|
-
];
|
|
197
|
-
let matchedOption = null;
|
|
198
|
-
for (const option of allDateOptions){
|
|
199
|
-
const range = getDateRangeForOption(option, locale);
|
|
200
|
-
let isFromMatch;
|
|
201
|
-
if (fromDate) {
|
|
202
|
-
isFromMatch = range.from?.toDateString() === fromDate.toDateString();
|
|
203
|
-
} else if (fromDate == null && range.to == undefined) {
|
|
204
|
-
// all future: fromDate == null & range.to == undefined
|
|
205
|
-
isFromMatch = true;
|
|
206
|
-
}
|
|
207
|
-
let isToMatch;
|
|
208
|
-
if (toDate) {
|
|
209
|
-
isToMatch = range.to?.toDateString() === toDate.toDateString();
|
|
210
|
-
} else if (toDate == null && range.to == undefined) {
|
|
211
|
-
// all future: fromDate == null & range.to == undefined
|
|
212
|
-
isToMatch = true;
|
|
213
|
-
}
|
|
214
|
-
if (isFromMatch && isToMatch) {
|
|
215
|
-
matchedOption = option;
|
|
216
|
-
break;
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
if (matchedOption) {
|
|
220
|
-
values[fieldName] = {
|
|
221
|
-
type: 'predefined',
|
|
222
|
-
predefinedValue: matchedOption
|
|
223
|
-
};
|
|
224
|
-
} else {
|
|
225
|
-
values[fieldName] = {
|
|
226
|
-
type: 'custom',
|
|
227
|
-
customRange: {
|
|
228
|
-
from: fromDate,
|
|
229
|
-
to: toDate
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
};
|
|
239
|
-
recursiveParse(where);
|
|
240
|
-
return values;
|
|
241
|
-
};
|
|
242
75
|
const QuickFilter = ({ slug, filterList })=>{
|
|
243
|
-
const localStorageKey = useMemo(()=>`direct-filter-${slug}`, [
|
|
244
|
-
slug
|
|
245
|
-
]);
|
|
246
76
|
const [fields, setFields] = useState([]);
|
|
247
77
|
const [filterRows, setFilterRows] = useState([]);
|
|
248
78
|
const [showFilters, setShowFilters] = useState(false);
|
|
@@ -250,25 +80,7 @@ const QuickFilter = ({ slug, filterList })=>{
|
|
|
250
80
|
const { getEntityConfig } = useConfig();
|
|
251
81
|
const { i18n } = useTranslation();
|
|
252
82
|
const locale = i18n.language;
|
|
253
|
-
const
|
|
254
|
-
const [filterValues, setFilterValues] = useState(()=>{
|
|
255
|
-
if (typeof window == 'undefined') return {};
|
|
256
|
-
try {
|
|
257
|
-
const item = window.localStorage.getItem(localStorageKey);
|
|
258
|
-
if (!item) return {};
|
|
259
|
-
const dateTimeReviver = (key, value)=>{
|
|
260
|
-
const isoDateRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?Z$/;
|
|
261
|
-
if (typeof value === 'string' && isoDateRegex.test(value)) {
|
|
262
|
-
return new Date(value);
|
|
263
|
-
}
|
|
264
|
-
return value;
|
|
265
|
-
};
|
|
266
|
-
return JSON.parse(item, dateTimeReviver);
|
|
267
|
-
} catch (error) {
|
|
268
|
-
console.error('Error reading and parsing filters from localStorage.', error);
|
|
269
|
-
return {};
|
|
270
|
-
}
|
|
271
|
-
});
|
|
83
|
+
const [filterValues, setFilterValues] = useState({});
|
|
272
84
|
// Build the list of filter fields from config
|
|
273
85
|
useEffect(()=>{
|
|
274
86
|
const collection = getEntityConfig({
|
|
@@ -311,9 +123,8 @@ const QuickFilter = ({ slug, filterList })=>{
|
|
|
311
123
|
useEffect(()=>{
|
|
312
124
|
if (fields.length === 0) return;
|
|
313
125
|
const valuesFromQuery = parseWhereClauseToFilterValues(query.where, fields, locale);
|
|
314
|
-
if (!isEqual(
|
|
126
|
+
if (!isEqual(filterValues, valuesFromQuery)) {
|
|
315
127
|
// Lock to prevent feedback loop when internal state changes
|
|
316
|
-
isSyncingFromQuery.current = true;
|
|
317
128
|
setFilterValues(valuesFromQuery);
|
|
318
129
|
}
|
|
319
130
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -323,12 +134,12 @@ const QuickFilter = ({ slug, filterList })=>{
|
|
|
323
134
|
]);
|
|
324
135
|
// Sync internal state (filterValues) back into the URL
|
|
325
136
|
useEffect(()=>{
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
137
|
+
if (fields.length === 0) return;
|
|
138
|
+
const valuesFromQuery = parseWhereClauseToFilterValues(query.where, fields, locale);
|
|
139
|
+
if (Object.keys(filterValues).length == 0 && !query.where) {}
|
|
140
|
+
if (isEqual(filterValues, valuesFromQuery)) {
|
|
329
141
|
return;
|
|
330
142
|
}
|
|
331
|
-
if (fields.length === 0) return;
|
|
332
143
|
const quickFilterConditions = buildQuickFilterConditions(filterValues, fields, locale);
|
|
333
144
|
const quickFilterFieldNames = new Set(fields.map((f)=>f.name));
|
|
334
145
|
const otherFilters = cleanWhereClause(query.where, quickFilterFieldNames);
|
|
@@ -351,40 +162,18 @@ const QuickFilter = ({ slug, filterList })=>{
|
|
|
351
162
|
newWhere = allConditions[0];
|
|
352
163
|
}
|
|
353
164
|
// Only update if the query has actually changed to avoid unnecessary updates
|
|
354
|
-
if (!isEqual(newWhere, query.where)) {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
refineListData(refinedData).then((r)=>{
|
|
364
|
-
console.log("Query refreshed", refinedData);
|
|
365
|
-
});
|
|
366
|
-
}
|
|
165
|
+
if (!(isEqual(newWhere, query.where) || Object.keys(newWhere).length == 0 && !query.where)) {
|
|
166
|
+
const refinedData = {
|
|
167
|
+
where: newWhere,
|
|
168
|
+
page: 1
|
|
169
|
+
};
|
|
170
|
+
refineListData(refinedData).then((r)=>{
|
|
171
|
+
console.log('Query refreshed', refinedData);
|
|
172
|
+
});
|
|
367
173
|
}
|
|
368
174
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
369
175
|
}, [
|
|
370
|
-
filterValues
|
|
371
|
-
fields,
|
|
372
|
-
i18n.language
|
|
373
|
-
]);
|
|
374
|
-
// Effect for persisting to localStorage
|
|
375
|
-
useEffect(()=>{
|
|
376
|
-
try {
|
|
377
|
-
if (Object.keys(filterValues).length > 0) {
|
|
378
|
-
localStorage.setItem(localStorageKey, JSON.stringify(filterValues));
|
|
379
|
-
} else {
|
|
380
|
-
localStorage.removeItem(localStorageKey);
|
|
381
|
-
}
|
|
382
|
-
} catch (error) {
|
|
383
|
-
console.error('Failed to save filters to localStorage', error);
|
|
384
|
-
}
|
|
385
|
-
}, [
|
|
386
|
-
filterValues,
|
|
387
|
-
localStorageKey
|
|
176
|
+
filterValues
|
|
388
177
|
]);
|
|
389
178
|
// Updates only the internal state
|
|
390
179
|
const handleFilterChange = useCallback((fieldName, value)=>{
|
|
@@ -460,6 +249,9 @@ const QuickFilter = ({ slug, filterList })=>{
|
|
|
460
249
|
const clearAllFilters = ()=>{
|
|
461
250
|
setFilterValues({});
|
|
462
251
|
};
|
|
252
|
+
const refreshFilters = ()=>{
|
|
253
|
+
refineListData(query);
|
|
254
|
+
};
|
|
463
255
|
const memoizedFilterRows = useMemo(()=>{
|
|
464
256
|
return filterRows.map((row)=>/*#__PURE__*/ _jsx("div", {
|
|
465
257
|
children: /*#__PURE__*/ _jsx("div", {
|
|
@@ -521,6 +313,16 @@ const QuickFilter = ({ slug, filterList })=>{
|
|
|
521
313
|
children: /*#__PURE__*/ _jsx(X, {
|
|
522
314
|
className: "h-3 w-3 text-gray-500"
|
|
523
315
|
})
|
|
316
|
+
}),
|
|
317
|
+
/*#__PURE__*/ _jsx("span", {
|
|
318
|
+
onClick: (e)=>{
|
|
319
|
+
e.stopPropagation();
|
|
320
|
+
refreshFilters();
|
|
321
|
+
},
|
|
322
|
+
className: "ml-1 p-0.5 hover:bg-muted rounded-sm transition-colors flex-shrink-0",
|
|
323
|
+
children: /*#__PURE__*/ _jsx(RefreshCw, {
|
|
324
|
+
className: "h-3 w-3 text-gray-500"
|
|
325
|
+
})
|
|
524
326
|
})
|
|
525
327
|
]
|
|
526
328
|
}) : /*#__PURE__*/ _jsx("span", {
|
package/dist/QuickFilter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/QuickFilter.tsx"],"sourcesContent":["'use client';\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { useConfig, useListQuery, useTranslation } from '@payloadcms/ui';\nimport type { ClientField, FieldAffectingData, ListQuery, OptionObject, SelectField } from 'payload'\nimport { getTranslation } from '@payloadcms/translations';\nimport FilterField from './FilterField';\nimport { getLabel, SupportedLocale } from './labels';\nimport type {\n CheckboxFilterState,\n DateFilterValue,\n FilterDetaild,\n FilterRow,\n SelectFilterValue,\n} from './filters/types/filters-type';\nimport { groupFiltersByRow, parseColumns } from './filters/utils/layout-helpers';\nimport { ChevronDown, ChevronUp, Filter, X } from 'lucide-react';\n\nimport { getDateRangeForOption } from './filters/utils/date-helpers';\nimport { isEqual } from 'lodash';\nimport {\n futureOptionKeys,\n getDateFilterOptions,\n pastOptionKeys,\n} from './filters/constants/date-filter-options';\nimport { Button } from './ui/button';\n\n// Helper function to get localized label\nconst getLocalizedLabel = (label: any, locale: SupportedLocale): string => {\n if (typeof label === 'object' && label !== null) {\n return label[locale] || label['en'] || Object.values(label)[0] || ''\n }\n return label || ''\n}\n\n// Recursive function to find fields by name\nfunction findFieldsByName(fields: ClientField[], fieldNames: string[]): ClientField[] {\n const results: ClientField[] = [];\n function recursiveSearch(currentFields: ClientField[]) {\n const filteredFields = currentFields.filter(\n (field) => 'name' in field && fieldNames.includes(field.name as string),\n );\n results.push(...filteredFields);\n currentFields.forEach((item) => {\n if (\n (item.type === 'array' || item.type === 'row' || item.type === 'collapsible') &&\n 'fields' in item &&\n Array.isArray(item.fields)\n ) {\n recursiveSearch(item.fields);\n } else if (item.type === 'tabs' && Array.isArray(item.tabs)) {\n item.tabs.forEach((tab) => {\n if ('fields' in tab && Array.isArray(tab.fields)) {\n recursiveSearch(tab.fields);\n }\n });\n } else if (item.type === 'blocks' && Array.isArray(item.blocks)) {\n item.blocks.forEach((block) => {\n if ('fields' in block && Array.isArray(block.fields)) {\n recursiveSearch(block.fields);\n }\n });\n }\n });\n }\n recursiveSearch(fields);\n return results;\n}\n\n// Builds an array of condition objects from the quick filter values\nconst buildQuickFilterConditions = (\n values: Record<string, any>,\n fieldDefs: FilterDetaild[],\n locale: SupportedLocale,\n): Record<string, any>[] => {\n const conditions: Record<string, any>[] = [];\n\n Object.entries(values).forEach(([fieldName, value]) => {\n if (!value) return;\n const fieldDef = fieldDefs.find((f) => f.name === fieldName);\n if (!fieldDef) return;\n\n let condition: Record<string, any> | null = null;\n\n switch (fieldDef.type) {\n case 'date': {\n const dateValue = value as DateFilterValue;\n let from: Date | undefined;\n let to: Date | undefined;\n\n if (dateValue.predefinedValue) {\n const range = getDateRangeForOption(dateValue.predefinedValue, locale);\n from = range.from;\n to = range.to;\n } else if (dateValue.customRange) {\n if (dateValue.customRange.from) from = new Date(dateValue.customRange.from);\n if (dateValue.customRange.to) to = new Date(dateValue.customRange.to);\n }\n\n if (from || to) {\n const dateQuery: any = {};\n if (from) dateQuery.greater_than_equal = from;\n if (to) dateQuery.less_than_equal = to;\n if (Object.keys(dateQuery).length > 0) {\n condition = { [fieldName]: dateQuery };\n }\n }\n break;\n }\n case 'select': {\n const selectValue = value as SelectFilterValue;\n if (selectValue.selectedValues && selectValue.selectedValues.length > 0) {\n if (selectValue.selectedValues.length === 1) {\n condition = { [fieldName]: { equals: selectValue.selectedValues[0] } };\n } else {\n condition = { [fieldName]: { in: selectValue.selectedValues } };\n }\n }\n break;\n }\n case 'checkbox': {\n const checkboxState = value as CheckboxFilterState;\n if (checkboxState === 'checked') {\n condition = { [fieldName]: { equals: 'true' } };\n } else if (checkboxState === 'unchecked') {\n condition = { [fieldName]: { equals: 'false' } };\n }\n break;\n }\n }\n if (condition) {\n conditions.push(condition);\n }\n });\n return conditions;\n};\n\n// Helper function to remove quick filter conditions from a 'where' clause\nconst cleanWhereClause = (clause: any, fieldsToClean: Set<string>): any => {\n if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {\n return clause;\n }\n\n const newClause: Record<string, any> = {};\n\n for (const key in clause) {\n if (key === 'and' || key === 'or') {\n const cleanedSubClauses = clause[key]\n .map((subClause: any) => cleanWhereClause(subClause, fieldsToClean))\n .filter(Boolean);\n\n if (cleanedSubClauses.length > 0) {\n newClause[key] = cleanedSubClauses;\n }\n } else if (!fieldsToClean.has(key)) {\n newClause[key] = clause[key];\n }\n }\n\n if (Object.keys(newClause).length === 0) {\n return null;\n }\n\n if (newClause.and?.length === 1 && Object.keys(newClause).length === 1) {\n return newClause.and[0];\n }\n if (newClause.or?.length === 1 && Object.keys(newClause).length === 1) {\n return newClause.or[0];\n }\n\n return newClause;\n};\n\n// Translates URL query conditions to the quick filter's internal state\nconst parseWhereClauseToFilterValues = (\n where: any,\n fields: FilterDetaild[],\n locale: SupportedLocale,\n): Record<string, any> => {\n const values: Record<string, any> = {};\n const fieldNames = new Set(fields.map((f) => f.name));\n\n const recursiveParse = (clause: any) => {\n if (!clause || typeof clause !== 'object') return;\n\n if (clause.and) {\n clause.and.forEach(recursiveParse);\n return;\n }\n if (clause.or) {\n clause.or.forEach(recursiveParse);\n return;\n }\n\n for (const fieldName in clause) {\n if (fieldNames.has(fieldName)) {\n const fieldDef = fields.find((f) => f.name === fieldName);\n const condition = clause[fieldName];\n\n if (fieldDef && condition && typeof condition === 'object') {\n if ('equals' in condition) {\n if (fieldDef.type === 'checkbox') {\n values[fieldName] = condition.equals == 'true' ? 'checked' : 'unchecked';\n } else if (fieldDef.type === 'select') {\n values[fieldName] = { selectedValues: [condition.equals] };\n }\n } else if ('in' in condition && Array.isArray(condition.in)) {\n if (fieldDef.type === 'select') {\n values[fieldName] = { selectedValues: condition.in };\n }\n } else if ('greater_than_equal' in condition || 'less_than_equal' in condition) {\n if (fieldDef.type === 'date') {\n const fromDate = condition.greater_than_equal\n ? new Date(condition.greater_than_equal)\n : null;\n const toDate = condition.less_than_equal ? new Date(condition.less_than_equal) : null;\n const allDateOptions = [...pastOptionKeys, ...futureOptionKeys];\n let matchedOption = null;\n\n for (const option of allDateOptions) {\n const range = getDateRangeForOption(option, locale);\n let isFromMatch;\n if (fromDate) {\n isFromMatch = range.from?.toDateString() === fromDate.toDateString();\n } else if (fromDate == null && range.to == undefined) {\n // all future: fromDate == null & range.to == undefined\n isFromMatch = true;\n }\n let isToMatch;\n if (toDate) {\n isToMatch = range.to?.toDateString() === toDate.toDateString();\n } else if (toDate == null && range.to == undefined) {\n // all future: fromDate == null & range.to == undefined\n isToMatch = true;\n }\n\n if (isFromMatch && isToMatch) {\n matchedOption = option;\n break;\n }\n }\n\n if (matchedOption) {\n values[fieldName] = {\n type: 'predefined',\n predefinedValue: matchedOption,\n };\n } else {\n values[fieldName] = {\n type: 'custom',\n customRange: {\n from: fromDate,\n to: toDate,\n },\n };\n }\n }\n }\n }\n }\n }\n };\n\n recursiveParse(where);\n return values;\n};\n\nconst QuickFilter = ({\n slug,\n filterList,\n }: {\n slug: string;\n filterList: (string | { name: string; width: string })[][];\n}) => {\n const localStorageKey = useMemo(() => `direct-filter-${slug}`, [slug]);\n\n const [fields, setFields] = useState<FilterDetaild[]>([]);\n const [filterRows, setFilterRows] = useState<FilterRow[]>([]);\n const [showFilters, setShowFilters] = useState(false);\n const { refineListData, query } = useListQuery();\n const { getEntityConfig } = useConfig();\n const { i18n } = useTranslation();\n const locale = i18n.language as SupportedLocale;\n const isSyncingFromQuery = useRef(false);\n\n const [filterValues, setFilterValues] = useState<Record<string, any>>(() => {\n if (typeof window == 'undefined') return {};\n try {\n const item = window.localStorage.getItem(localStorageKey);\n if (!item) return {};\n const dateTimeReviver = (key: string, value: any) => {\n const isoDateRegex = /^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$/;\n if (typeof value === 'string' && isoDateRegex.test(value)) {\n return new Date(value);\n }\n return value;\n };\n return JSON.parse(item, dateTimeReviver);\n } catch (error) {\n console.error('Error reading and parsing filters from localStorage.', error);\n return {};\n }\n });\n\n // Build the list of filter fields from config\n useEffect(() => {\n const collection = getEntityConfig({ collectionSlug: slug });\n const flattenedFieldConfigs = filterList.flatMap((row, rowIndex) =>\n row.map((field, fieldIndex) => ({\n field,\n rowIndex,\n fieldIndex,\n })),\n );\n const fieldNames = flattenedFieldConfigs.map(({ field }) =>\n typeof field === 'string' ? field : field.name,\n );\n const matchedFields = findFieldsByName(collection?.fields || [], fieldNames);\n const simplifiedFields: FilterDetaild[] = matchedFields.map((field) => {\n const label = (field as FieldAffectingData).label;\n const translatedLabel = getTranslation(label as string, i18n);\n const fieldName = (field as FieldAffectingData).name as string;\n const fieldConfig = flattenedFieldConfigs.find(({ field: f }) =>\n typeof f === 'string' ? f === fieldName : f.name === fieldName,\n );\n return {\n name: fieldName,\n label: translatedLabel as string,\n type: field.type,\n options: (field as SelectField).options as OptionObject[],\n row: fieldConfig ? fieldConfig.rowIndex : 0,\n width:\n typeof fieldConfig?.field === 'object' && 'width' in fieldConfig.field\n ? fieldConfig.field.width\n : undefined,\n };\n });\n const sortedFields = flattenedFieldConfigs\n .map(({ field }) => {\n const fieldName = typeof field === 'string' ? field : field.name;\n return simplifiedFields.find((f) => f.name === fieldName);\n })\n .filter((f): f is FilterDetaild => !!f);\n setFields(sortedFields);\n setFilterRows(groupFiltersByRow(sortedFields));\n }, [slug, filterList, getEntityConfig, i18n]);\n // Sync from URL (query.where) into internal state\n useEffect(() => {\n if (fields.length === 0) return;\n\n const valuesFromQuery: Record<string, any> = parseWhereClauseToFilterValues(\n query.where,\n fields,\n locale,\n );\n\n if (!isEqual(valuesFromQuery, filterValues)) {\n // Lock to prevent feedback loop when internal state changes\n isSyncingFromQuery.current = true;\n setFilterValues(valuesFromQuery);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [query.where, fields]);\n\n // Sync internal state (filterValues) back into the URL\n useEffect(() => {\n // If the change originated from the first effect, skip to avoid infinite loop\n if (isSyncingFromQuery.current) {\n isSyncingFromQuery.current = false;\n return;\n }\n\n if (fields.length === 0) return;\n\n const quickFilterConditions = buildQuickFilterConditions(filterValues, fields, locale);\n const quickFilterFieldNames = new Set(fields.map((f) => f.name));\n const otherFilters = cleanWhereClause(query.where, quickFilterFieldNames);\n\n const allConditions = [...quickFilterConditions];\n if (otherFilters) {\n if (otherFilters.and && Array.isArray(otherFilters.and)) {\n allConditions.push(...otherFilters.and);\n } else if (Object.keys(otherFilters).length > 0) {\n allConditions.push(otherFilters);\n }\n }\n\n let newWhere: Record<string, any> = {};\n if (allConditions.length > 1) {\n newWhere = { and: allConditions };\n } else if (allConditions.length === 1) {\n newWhere = allConditions[0];\n }\n\n // Only update if the query has actually changed to avoid unnecessary updates\n if (!isEqual(newWhere, query.where)) {\n if(newWhere && Object.keys(newWhere).length > 0){\n const refinedData = {\n where: newWhere,\n page: 1,\n } as ListQuery;\n\n if (query.columns) {\n refinedData.columns = parseColumns(query.columns);\n }\n\n refineListData(refinedData).then(r => {\n console.log(\"Query refreshed\",refinedData)\n });\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [filterValues, fields, i18n.language]);\n // Effect for persisting to localStorage\n useEffect(() => {\n try {\n if (Object.keys(filterValues).length > 0) {\n localStorage.setItem(localStorageKey, JSON.stringify(filterValues));\n } else {\n localStorage.removeItem(localStorageKey);\n }\n } catch (error) {\n console.error('Failed to save filters to localStorage', error);\n }\n }, [filterValues, localStorageKey]);\n\n // Updates only the internal state\n const handleFilterChange = useCallback((fieldName: string, value: any) => {\n setFilterValues((prev) => {\n const newValues = { ...prev };\n if (\n value === undefined ||\n value === null ||\n value === 'indeterminate' ||\n (value && value.type === 'none')\n ) {\n delete newValues[fieldName];\n } else {\n newValues[fieldName] = value;\n }\n return newValues;\n });\n }, []);\n\n // This function remains largely the same.\n const getActiveFiltersDetails = () => {\n const activeFilters: string[] = [];\n const locale = i18n.language as SupportedLocale;\n Object.entries(filterValues).forEach(([fieldName, value]) => {\n const field = fields.find((f) => f.name === fieldName);\n if (!field) return;\n\n switch (field.type) {\n case 'date':\n if (value !== undefined) {\n const dateValue = value as DateFilterValue;\n let dateDescription = '';\n\n if (dateValue.type === 'predefined' && dateValue.predefinedValue) {\n const { pastOptions, futureOptions } = getDateFilterOptions(locale);\n const allOptions = [...pastOptions, ...futureOptions];\n const option = allOptions.find((opt) => opt.value === dateValue.predefinedValue);\n dateDescription = option ? option.label : getLabel('custom', locale);\n } else if (dateValue.type === 'custom' || dateValue.customRange) {\n dateDescription = getLabel('custom', locale);\n }\n\n if (dateDescription) {\n activeFilters.push(`${field.label} (${dateDescription})`);\n }\n }\n break;\n case 'select': {\n const selectValue = value as SelectFilterValue;\n if (selectValue && selectValue.selectedValues && selectValue.selectedValues.length > 0) {\n const totalOptions = field.options?.length || 0;\n\n if (selectValue.selectedValues.length === totalOptions) {\n activeFilters.push(`${field.label} (${getLabel('all', locale)})`);\n } else if (selectValue.selectedValues.length === 1) {\n // Show the actual option name when only one is selected\n const selectedOption = field.options?.find(\n (opt: any) => opt.value === selectValue.selectedValues[0],\n );\n const optionLabel = selectedOption\n ? getLocalizedLabel(selectedOption.label, locale)\n : selectValue.selectedValues[0];\n activeFilters.push(`${field.label} (${optionLabel})`);\n } else {\n // Show count for multiple selections\n activeFilters.push(`${field.label} (${selectValue.selectedValues.length})`);\n }\n }\n break;\n }\n case 'checkbox':\n if (value !== 'indeterminate') {\n const checkboxValue =\n value === 'checked' ? getLabel('yes', locale) : getLabel('no', locale);\n activeFilters.push(`${field.label} (${checkboxValue})`);\n }\n break;\n }\n });\n\n return activeFilters;\n };\n\n const clearAllFilters = () => {\n setFilterValues({});\n };\n\n const memoizedFilterRows = useMemo(() => {\n return filterRows.map((row) => (\n <div key={row.rowNumber}>\n <div className='flex flex-wrap gap-6 mb-4'>\n {row.filters.map((field) => (\n <FilterField\n key={field.name}\n field={field}\n onFilterChange={handleFilterChange}\n value={filterValues[field.name]}\n />\n ))}\n </div>\n </div>\n ));\n }, [filterRows, handleFilterChange, filterValues]);\n\n const toggleFilters = () => {\n setShowFilters((prev) => !prev);\n };\n\n const activeFiltersDetails = getActiveFiltersDetails();\n const hasActiveFilters = activeFiltersDetails.length > 0;\n\n if (!fields.length) return null;\n\n return (\n <div className='filter-container useTw'>\n <div style={{ position: 'relative', top: '-24px', height: '0px' }}>\n <Button\n variant='outline'\n size='sm'\n onClick={toggleFilters}\n className={`flex items-center gap-2 bg-background border-muted-muted hover:bg-muted ${\n hasActiveFilters ? 'w-auto min-w-fit' : ''\n }`}\n >\n <Filter className={`h-4 w-4 ${hasActiveFilters ? 'fill-current' : ''}`} />\n\n {hasActiveFilters ? (\n <>\n <span className='text-sm truncate'>\n <strong>\n {`${activeFiltersDetails.length === 1 ? getLabel('activeFilterSingular', locale) : getLabel('activeFilterPlural', locale)}: `}\n </strong>{' '}\n {activeFiltersDetails.join(' • ')}\n </span>\n\n <span\n onClick={(e) => {\n e.stopPropagation();\n clearAllFilters();\n }}\n className='ml-1 p-0.5 hover:bg-muted rounded-sm transition-colors flex-shrink-0'\n >\n <X className='h-3 w-3 text-gray-500' />\n </span>\n </>\n ) : (\n <span className='text-sm truncate'>{getLabel('quickFilters', locale)}</span>\n )}\n\n {showFilters ? <ChevronUp className='h-4 w-4' /> : <ChevronDown className='h-4 w-4' />}\n </Button>\n </div>\n {showFilters && <div className={'p-4 pb-2 bg-muted'}>{memoizedFilterRows}</div>}\n </div>\n );\n};\n\nexport default QuickFilter;\n"],"names":["useCallback","useEffect","useMemo","useRef","useState","useConfig","useListQuery","useTranslation","getTranslation","FilterField","getLabel","groupFiltersByRow","parseColumns","ChevronDown","ChevronUp","Filter","X","getDateRangeForOption","isEqual","futureOptionKeys","getDateFilterOptions","pastOptionKeys","Button","getLocalizedLabel","label","locale","Object","values","findFieldsByName","fields","fieldNames","results","recursiveSearch","currentFields","filteredFields","filter","field","includes","name","push","forEach","item","type","Array","isArray","tabs","tab","blocks","block","buildQuickFilterConditions","fieldDefs","conditions","entries","fieldName","value","fieldDef","find","f","condition","dateValue","from","to","predefinedValue","range","customRange","Date","dateQuery","greater_than_equal","less_than_equal","keys","length","selectValue","selectedValues","equals","in","checkboxState","cleanWhereClause","clause","fieldsToClean","newClause","key","cleanedSubClauses","map","subClause","Boolean","has","and","or","parseWhereClauseToFilterValues","where","Set","recursiveParse","fromDate","toDate","allDateOptions","matchedOption","option","isFromMatch","toDateString","undefined","isToMatch","QuickFilter","slug","filterList","localStorageKey","setFields","filterRows","setFilterRows","showFilters","setShowFilters","refineListData","query","getEntityConfig","i18n","language","isSyncingFromQuery","filterValues","setFilterValues","window","localStorage","getItem","dateTimeReviver","isoDateRegex","test","JSON","parse","error","console","collection","collectionSlug","flattenedFieldConfigs","flatMap","row","rowIndex","fieldIndex","matchedFields","simplifiedFields","translatedLabel","fieldConfig","options","width","sortedFields","valuesFromQuery","current","quickFilterConditions","quickFilterFieldNames","otherFilters","allConditions","newWhere","refinedData","page","columns","then","r","log","setItem","stringify","removeItem","handleFilterChange","prev","newValues","getActiveFiltersDetails","activeFilters","dateDescription","pastOptions","futureOptions","allOptions","opt","totalOptions","selectedOption","optionLabel","checkboxValue","clearAllFilters","memoizedFilterRows","div","className","filters","onFilterChange","rowNumber","toggleFilters","activeFiltersDetails","hasActiveFilters","style","position","top","height","variant","size","onClick","span","strong","join","e","stopPropagation"],"mappings":"AAAA;;AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAC1E,SAASC,SAAS,EAAEC,YAAY,EAAEC,cAAc,QAAQ,iBAAiB;AAEzE,SAASC,cAAc,QAAQ,2BAA2B;AAC1D,OAAOC,iBAAiB,gBAAgB;AACxC,SAASC,QAAQ,QAAyB,W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|
|
1
|
+
{"version":3,"sources":["../src/QuickFilter.tsx"],"sourcesContent":["'use client'\n\nimport { useCallback, useEffect, useMemo, useState } from 'react'\nimport { useConfig, useListQuery, useTranslation } from '@payloadcms/ui'\nimport type { ClientField, FieldAffectingData, ListQuery, OptionObject, SelectField } from 'payload'\nimport { getTranslation } from '@payloadcms/translations'\nimport FilterField from './FilterField'\nimport { getLabel, SupportedLocale } from './labels'\nimport type {\n DateFilterValue,\n FilterDetaild,\n FilterRow,\n SelectFilterValue,\n} from './filters/types/filters-type'\nimport { groupFiltersByRow } from './filters/utils/layout-helpers'\nimport { ChevronDown, ChevronUp, Filter, RefreshCw, X } from 'lucide-react'\nimport { isEqual } from 'lodash'\nimport { getDateFilterOptions } from './filters/constants/date-filter-options'\nimport { Button } from './ui/button'\nimport {\n buildQuickFilterConditions,\n parseWhereClauseToFilterValues,\n} from './lib/utils'\n\n// Helper function to get localized label\nconst getLocalizedLabel = (label: any, locale: SupportedLocale): string => {\n if (typeof label === 'object' && label !== null) {\n return label[locale] || label['en'] || Object.values(label)[0] || ''\n }\n return label || ''\n}\n\n// Recursive function to find fields by name\nfunction findFieldsByName(fields: ClientField[], fieldNames: string[]): ClientField[] {\n const results: ClientField[] = []\n function recursiveSearch(currentFields: ClientField[]) {\n const filteredFields = currentFields.filter(\n (field) => 'name' in field && fieldNames.includes(field.name as string),\n )\n results.push(...filteredFields)\n currentFields.forEach((item) => {\n if (\n (item.type === 'array' || item.type === 'row' || item.type === 'collapsible') &&\n 'fields' in item &&\n Array.isArray(item.fields)\n ) {\n recursiveSearch(item.fields)\n } else if (item.type === 'tabs' && Array.isArray(item.tabs)) {\n item.tabs.forEach((tab) => {\n if ('fields' in tab && Array.isArray(tab.fields)) {\n recursiveSearch(tab.fields)\n }\n })\n } else if (item.type === 'blocks' && Array.isArray(item.blocks)) {\n item.blocks.forEach((block) => {\n if ('fields' in block && Array.isArray(block.fields)) {\n recursiveSearch(block.fields)\n }\n })\n }\n })\n }\n recursiveSearch(fields)\n return results\n}\n\n// Helper function to remove quick filter conditions from a 'where' clause\nconst cleanWhereClause = (clause: any, fieldsToClean: Set<string>): any => {\n if (!clause || typeof clause !== 'object' || Array.isArray(clause)) {\n return clause\n }\n\n const newClause: Record<string, any> = {}\n\n for (const key in clause) {\n if (key === 'and' || key === 'or') {\n const cleanedSubClauses = clause[key]\n .map((subClause: any) => cleanWhereClause(subClause, fieldsToClean))\n .filter(Boolean)\n\n if (cleanedSubClauses.length > 0) {\n newClause[key] = cleanedSubClauses\n }\n } else if (!fieldsToClean.has(key)) {\n newClause[key] = clause[key]\n }\n }\n\n if (Object.keys(newClause).length === 0) {\n return null\n }\n\n if (newClause.and?.length === 1 && Object.keys(newClause).length === 1) {\n return newClause.and[0]\n }\n if (newClause.or?.length === 1 && Object.keys(newClause).length === 1) {\n return newClause.or[0]\n }\n\n return newClause\n}\n\nconst QuickFilter = ({\n slug,\n filterList,\n}: {\n slug: string\n filterList: (string | { name: string; width: string })[][]\n}) => {\n const [fields, setFields] = useState<FilterDetaild[]>([])\n const [filterRows, setFilterRows] = useState<FilterRow[]>([])\n const [showFilters, setShowFilters] = useState(false)\n const { refineListData, query } = useListQuery()\n const { getEntityConfig } = useConfig()\n const { i18n } = useTranslation()\n const locale = i18n.language as SupportedLocale\n\n const [filterValues, setFilterValues] = useState<Record<string, any>>({})\n\n // Build the list of filter fields from config\n useEffect(() => {\n const collection = getEntityConfig({ collectionSlug: slug })\n const flattenedFieldConfigs = filterList.flatMap((row, rowIndex) =>\n row.map((field, fieldIndex) => ({\n field,\n rowIndex,\n fieldIndex,\n })),\n )\n const fieldNames = flattenedFieldConfigs.map(({ field }) =>\n typeof field === 'string' ? field : field.name,\n )\n const matchedFields = findFieldsByName(collection?.fields || [], fieldNames)\n const simplifiedFields: FilterDetaild[] = matchedFields.map((field) => {\n const label = (field as FieldAffectingData).label\n const translatedLabel = getTranslation(label as string, i18n)\n const fieldName = (field as FieldAffectingData).name as string\n const fieldConfig = flattenedFieldConfigs.find(({ field: f }) =>\n typeof f === 'string' ? f === fieldName : f.name === fieldName,\n )\n return {\n name: fieldName,\n label: translatedLabel as string,\n type: field.type,\n options: (field as SelectField).options as OptionObject[],\n row: fieldConfig ? fieldConfig.rowIndex : 0,\n width:\n typeof fieldConfig?.field === 'object' && 'width' in fieldConfig.field\n ? fieldConfig.field.width\n : undefined,\n }\n })\n const sortedFields = flattenedFieldConfigs\n .map(({ field }) => {\n const fieldName = typeof field === 'string' ? field : field.name\n return simplifiedFields.find((f) => f.name === fieldName)\n })\n .filter((f): f is FilterDetaild => !!f)\n setFields(sortedFields)\n setFilterRows(groupFiltersByRow(sortedFields))\n }, [slug, filterList, getEntityConfig, i18n])\n // Sync from URL (query.where) into internal state\n useEffect(() => {\n if (fields.length === 0) return\n const valuesFromQuery: Record<string, any> = parseWhereClauseToFilterValues(\n query.where,\n fields,\n locale,\n )\n if (!isEqual(filterValues, valuesFromQuery)) {\n // Lock to prevent feedback loop when internal state changes\n setFilterValues(valuesFromQuery)\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [query.where, fields])\n\n // Sync internal state (filterValues) back into the URL\n useEffect(() => {\n if (fields.length === 0) return\n const valuesFromQuery: Record<string, any> = parseWhereClauseToFilterValues(\n query.where,\n fields,\n locale,\n )\n if (Object.keys(filterValues).length == 0 && !query.where) {\n }\n if (isEqual(filterValues, valuesFromQuery)) {\n return\n }\n const quickFilterConditions = buildQuickFilterConditions(filterValues, fields, locale)\n const quickFilterFieldNames = new Set(fields.map((f) => f.name))\n const otherFilters = cleanWhereClause(query.where, quickFilterFieldNames)\n\n const allConditions = [...quickFilterConditions]\n if (otherFilters) {\n if (otherFilters.and && Array.isArray(otherFilters.and)) {\n allConditions.push(...otherFilters.and)\n } else if (Object.keys(otherFilters).length > 0) {\n allConditions.push(otherFilters)\n }\n }\n\n let newWhere: Record<string, any> = {}\n if (allConditions.length > 1) {\n newWhere = { and: allConditions }\n } else if (allConditions.length === 1) {\n newWhere = allConditions[0]\n }\n\n // Only update if the query has actually changed to avoid unnecessary updates\n if (!(isEqual(newWhere, query.where) || (Object.keys(newWhere).length == 0 && !query.where))) {\n const refinedData = {\n where: newWhere,\n page: 1,\n } as ListQuery\n\n refineListData(refinedData).then((r) => {\n console.log('Query refreshed', refinedData)\n })\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [filterValues])\n\n // Updates only the internal state\n const handleFilterChange = useCallback((fieldName: string, value: any) => {\n setFilterValues((prev) => {\n const newValues = { ...prev }\n if (\n value === undefined ||\n value === null ||\n value === 'indeterminate' ||\n (value && value.type === 'none')\n ) {\n delete newValues[fieldName]\n } else {\n newValues[fieldName] = value\n }\n return newValues\n })\n }, [])\n\n // This function remains largely the same.\n const getActiveFiltersDetails = () => {\n const activeFilters: string[] = []\n const locale = i18n.language as SupportedLocale\n Object.entries(filterValues).forEach(([fieldName, value]) => {\n const field = fields.find((f) => f.name === fieldName)\n if (!field) return\n\n switch (field.type) {\n case 'date':\n if (value !== undefined) {\n const dateValue = value as DateFilterValue\n let dateDescription = ''\n\n if (dateValue.type === 'predefined' && dateValue.predefinedValue) {\n const { pastOptions, futureOptions } = getDateFilterOptions(locale)\n const allOptions = [...pastOptions, ...futureOptions]\n const option = allOptions.find((opt) => opt.value === dateValue.predefinedValue)\n dateDescription = option ? option.label : getLabel('custom', locale)\n } else if (dateValue.type === 'custom' || dateValue.customRange) {\n dateDescription = getLabel('custom', locale)\n }\n\n if (dateDescription) {\n activeFilters.push(`${field.label} (${dateDescription})`)\n }\n }\n break\n case 'select': {\n const selectValue = value as SelectFilterValue\n if (selectValue && selectValue.selectedValues && selectValue.selectedValues.length > 0) {\n const totalOptions = field.options?.length || 0\n\n if (selectValue.selectedValues.length === totalOptions) {\n activeFilters.push(`${field.label} (${getLabel('all', locale)})`)\n } else if (selectValue.selectedValues.length === 1) {\n // Show the actual option name when only one is selected\n const selectedOption = field.options?.find(\n (opt: any) => opt.value === selectValue.selectedValues[0],\n )\n const optionLabel = selectedOption\n ? getLocalizedLabel(selectedOption.label, locale)\n : selectValue.selectedValues[0]\n activeFilters.push(`${field.label} (${optionLabel})`)\n } else {\n // Show count for multiple selections\n activeFilters.push(`${field.label} (${selectValue.selectedValues.length})`)\n }\n }\n break\n }\n case 'checkbox':\n if (value !== 'indeterminate') {\n const checkboxValue =\n value === 'checked' ? getLabel('yes', locale) : getLabel('no', locale)\n activeFilters.push(`${field.label} (${checkboxValue})`)\n }\n break\n }\n })\n\n return activeFilters\n }\n\n const clearAllFilters = () => {\n setFilterValues({})\n }\n\n const refreshFilters = () => {\n refineListData(query)\n }\n\n const memoizedFilterRows = useMemo(() => {\n return filterRows.map((row) => (\n <div key={row.rowNumber}>\n <div className=\"flex flex-wrap gap-6 mb-4\">\n {row.filters.map((field) => (\n <FilterField\n key={field.name}\n field={field}\n onFilterChange={handleFilterChange}\n value={filterValues[field.name]}\n />\n ))}\n </div>\n </div>\n ))\n }, [filterRows, handleFilterChange, filterValues])\n\n const toggleFilters = () => {\n setShowFilters((prev) => !prev)\n }\n\n const activeFiltersDetails = getActiveFiltersDetails()\n const hasActiveFilters = activeFiltersDetails.length > 0\n\n if (!fields.length) return null\n\n return (\n <div className=\"filter-container useTw\">\n <div style={{ position: 'relative', top: '-24px', height: '0px' }}>\n <Button\n variant=\"outline\"\n size=\"sm\"\n onClick={toggleFilters}\n className={`flex items-center gap-2 bg-background border-muted-muted hover:bg-muted ${\n hasActiveFilters ? 'w-auto min-w-fit' : ''\n }`}\n >\n <Filter className={`h-4 w-4 ${hasActiveFilters ? 'fill-current' : ''}`} />\n\n {hasActiveFilters ? (\n <>\n <span className=\"text-sm truncate\">\n <strong>\n {`${activeFiltersDetails.length === 1 ? getLabel('activeFilterSingular', locale) : getLabel('activeFilterPlural', locale)}: `}\n </strong>{' '}\n {activeFiltersDetails.join(' • ')}\n </span>\n\n <span\n onClick={(e) => {\n e.stopPropagation()\n clearAllFilters()\n }}\n className=\"ml-1 p-0.5 hover:bg-muted rounded-sm transition-colors flex-shrink-0\"\n >\n <X className=\"h-3 w-3 text-gray-500\" />\n </span>\n <span\n onClick={(e) => {\n e.stopPropagation()\n refreshFilters()\n }}\n className=\"ml-1 p-0.5 hover:bg-muted rounded-sm transition-colors flex-shrink-0\"\n >\n <RefreshCw className=\"h-3 w-3 text-gray-500\" />\n </span>\n </>\n ) : (\n <span className=\"text-sm truncate\">{getLabel('quickFilters', locale)}</span>\n )}\n\n {showFilters ? <ChevronUp className=\"h-4 w-4\" /> : <ChevronDown className=\"h-4 w-4\" />}\n </Button>\n </div>\n {showFilters && <div className={'p-4 pb-2 bg-muted'}>{memoizedFilterRows}</div>}\n </div>\n )\n}\n\nexport default QuickFilter\n"],"names":["useCallback","useEffect","useMemo","useState","useConfig","useListQuery","useTranslation","getTranslation","FilterField","getLabel","groupFiltersByRow","ChevronDown","ChevronUp","Filter","RefreshCw","X","isEqual","getDateFilterOptions","Button","buildQuickFilterConditions","parseWhereClauseToFilterValues","getLocalizedLabel","label","locale","Object","values","findFieldsByName","fields","fieldNames","results","recursiveSearch","currentFields","filteredFields","filter","field","includes","name","push","forEach","item","type","Array","isArray","tabs","tab","blocks","block","cleanWhereClause","clause","fieldsToClean","newClause","key","cleanedSubClauses","map","subClause","Boolean","length","has","keys","and","or","QuickFilter","slug","filterList","setFields","filterRows","setFilterRows","showFilters","setShowFilters","refineListData","query","getEntityConfig","i18n","language","filterValues","setFilterValues","collection","collectionSlug","flattenedFieldConfigs","flatMap","row","rowIndex","fieldIndex","matchedFields","simplifiedFields","translatedLabel","fieldName","fieldConfig","find","f","options","width","undefined","sortedFields","valuesFromQuery","where","quickFilterConditions","quickFilterFieldNames","Set","otherFilters","allConditions","newWhere","refinedData","page","then","r","console","log","handleFilterChange","value","prev","newValues","getActiveFiltersDetails","activeFilters","entries","dateValue","dateDescription","predefinedValue","pastOptions","futureOptions","allOptions","option","opt","customRange","selectValue","selectedValues","totalOptions","selectedOption","optionLabel","checkboxValue","clearAllFilters","refreshFilters","memoizedFilterRows","div","className","filters","onFilterChange","rowNumber","toggleFilters","activeFiltersDetails","hasActiveFilters","style","position","top","height","variant","size","onClick","span","strong","join","e","stopPropagation"],"mappings":"AAAA;;AAEA,SAASA,WAAW,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AACjE,SAASC,SAAS,EAAEC,YAAY,EAAEC,cAAc,QAAQ,iBAAgB;AAExE,SAASC,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,iBAAiB,gBAAe;AACvC,SAASC,QAAQ,QAAyB,WAAU;AAOpD,SAASC,iBAAiB,QAAQ,iCAAgC;AAClE,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,SAAS,EAAEC,CAAC,QAAQ,eAAc;AAC3E,SAASC,OAAO,QAAQ,SAAQ;AAChC,SAASC,oBAAoB,QAAQ,0CAAyC;AAC9E,SAASC,MAAM,QAAQ,cAAa;AACpC,SACEC,0BAA0B,EAC1BC,8BAA8B,QACzB,cAAa;AAEpB,yCAAyC;AACzC,MAAMC,oBAAoB,CAACC,OAAYC;IACrC,IAAI,OAAOD,UAAU,YAAYA,UAAU,MAAM;QAC/C,OAAOA,KAAK,CAACC,OAAO,IAAID,KAAK,CAAC,KAAK,IAAIE,OAAOC,MAAM,CAACH,MAAM,CAAC,EAAE,IAAI;IACpE;IACA,OAAOA,SAAS;AAClB;AAEA,4CAA4C;AAC5C,SAASI,iBAAiBC,MAAqB,EAAEC,UAAoB;IACnE,MAAMC,UAAyB,EAAE;IACjC,SAASC,gBAAgBC,aAA4B;QACnD,MAAMC,iBAAiBD,cAAcE,MAAM,CACzC,CAACC,QAAU,UAAUA,SAASN,WAAWO,QAAQ,CAACD,MAAME,IAAI;QAE9DP,QAAQQ,IAAI,IAAIL;QAChBD,cAAcO,OAAO,CAAC,CAACC;YACrB,IACE,AAACA,CAAAA,KAAKC,IAAI,KAAK,WAAWD,KAAKC,IAAI,KAAK,SAASD,KAAKC,IAAI,KAAK,aAAY,KAC3E,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ACvH;wCAAEuH,WAAU;;;8CAEf,KAACc;oCACCD,SAAS,CAACI;wCACRA,EAAEC,eAAe;wCACjBrB;oCACF;oCACAG,WAAU;8CAEV,cAAA,KAACxH;wCAAUwH,WAAU;;;;2CAIzB,KAACc;4BAAKd,WAAU;sCAAoB7H,SAAS,gBAAgBc;;wBAG9D4C,4BAAc,KAACvD;4BAAU0H,WAAU;2CAAe,KAAC3H;4BAAY2H,WAAU;;;;;YAG7EnE,6BAAe,KAACkE;gBAAIC,WAAW;0BAAsBF;;;;AAG5D;AAEA,eAAevE,YAAW"}
|
|
@@ -203,7 +203,7 @@ export function SelectFilter({ label, options, value, onChange, placeholder, loc
|
|
|
203
203
|
}),
|
|
204
204
|
multiSelect && selectedValues.length > 0 && selectedValues.length < options.length && /*#__PURE__*/ _jsx("div", {
|
|
205
205
|
className: "flex flex-wrap gap-1 mt-2",
|
|
206
|
-
children: selectedValues.map((value)=>{
|
|
206
|
+
children: selectedValues.map((value, index)=>{
|
|
207
207
|
const option = options.find((opt)=>opt.value === value);
|
|
208
208
|
return /*#__PURE__*/ _jsxs(Badge, {
|
|
209
209
|
variant: "secondary",
|
|
@@ -216,7 +216,7 @@ export function SelectFilter({ label, options, value, onChange, placeholder, loc
|
|
|
216
216
|
children: "×"
|
|
217
217
|
})
|
|
218
218
|
]
|
|
219
|
-
}, value);
|
|
219
|
+
}, value + index);
|
|
220
220
|
})
|
|
221
221
|
})
|
|
222
222
|
]
|