@payloadcms/ui 3.23.0-canary.fa36283 → 3.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/dist/elements/ListControls/index.d.ts.map +1 -1
  2. package/dist/elements/ListControls/index.js +1 -1
  3. package/dist/elements/ListControls/index.js.map +1 -1
  4. package/dist/elements/ViewDescription/index.d.ts +0 -1
  5. package/dist/elements/ViewDescription/index.d.ts.map +1 -1
  6. package/dist/elements/ViewDescription/index.js +1 -2
  7. package/dist/elements/ViewDescription/index.js.map +1 -1
  8. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.d.ts +2 -2
  9. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.d.ts.map +1 -1
  10. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.js +1 -0
  11. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.js.map +1 -1
  12. package/dist/elements/WhereBuilder/Condition/Relationship/index.d.ts.map +1 -1
  13. package/dist/elements/WhereBuilder/Condition/Relationship/index.js +59 -43
  14. package/dist/elements/WhereBuilder/Condition/Relationship/index.js.map +1 -1
  15. package/dist/elements/WhereBuilder/Condition/Select/index.d.ts.map +1 -1
  16. package/dist/elements/WhereBuilder/Condition/Select/index.js +2 -0
  17. package/dist/elements/WhereBuilder/Condition/Select/index.js.map +1 -1
  18. package/dist/elements/WhereBuilder/Condition/Select/types.d.ts +1 -0
  19. package/dist/elements/WhereBuilder/Condition/Select/types.d.ts.map +1 -1
  20. package/dist/elements/WhereBuilder/Condition/Select/types.js.map +1 -1
  21. package/dist/elements/WhereBuilder/Condition/index.d.ts +5 -16
  22. package/dist/elements/WhereBuilder/Condition/index.d.ts.map +1 -1
  23. package/dist/elements/WhereBuilder/Condition/index.js +114 -276
  24. package/dist/elements/WhereBuilder/Condition/index.js.map +1 -1
  25. package/dist/elements/WhereBuilder/Condition/types.d.ts +2 -2
  26. package/dist/elements/WhereBuilder/Condition/types.d.ts.map +1 -1
  27. package/dist/elements/WhereBuilder/Condition/types.js.map +1 -1
  28. package/dist/elements/WhereBuilder/field-types.d.ts +1 -92
  29. package/dist/elements/WhereBuilder/field-types.d.ts.map +1 -1
  30. package/dist/elements/WhereBuilder/field-types.js.map +1 -1
  31. package/dist/elements/WhereBuilder/index.d.ts.map +1 -1
  32. package/dist/elements/WhereBuilder/index.js +168 -259
  33. package/dist/elements/WhereBuilder/index.js.map +1 -1
  34. package/dist/elements/WhereBuilder/{reduceClientFields.d.ts → reduceFields.d.ts} +5 -4
  35. package/dist/elements/WhereBuilder/reduceFields.d.ts.map +1 -0
  36. package/dist/elements/WhereBuilder/{reduceClientFields.js → reduceFields.js} +8 -8
  37. package/dist/elements/WhereBuilder/reduceFields.js.map +1 -0
  38. package/dist/elements/WhereBuilder/types.d.ts +15 -2
  39. package/dist/elements/WhereBuilder/types.d.ts.map +1 -1
  40. package/dist/elements/WhereBuilder/types.js.map +1 -1
  41. package/dist/elements/WhereBuilder/validateWhereQuery.d.ts.map +1 -1
  42. package/dist/elements/WhereBuilder/validateWhereQuery.js.map +1 -1
  43. package/dist/exports/client/index.js +11 -11
  44. package/dist/exports/client/index.js.map +4 -4
  45. package/dist/styles.css +1 -1
  46. package/package.json +4 -4
  47. package/dist/elements/ViewDescription/index.scss +0 -7
  48. package/dist/elements/WhereBuilder/reduceClientFields.d.ts.map +0 -1
  49. package/dist/elements/WhereBuilder/reduceClientFields.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"field-types.js","names":["boolean","label","value","base","numeric","geo","within","intersects","like","contains","fieldTypeConditions","checkbox","component","operators","code","date","email","json","number","point","radio","relationship","richText","select","text","textarea","upload"],"sources":["../../../src/elements/WhereBuilder/field-types.tsx"],"sourcesContent":["'use client'\nconst boolean = [\n {\n label: 'equals',\n value: 'equals',\n },\n {\n label: 'isNotEqualTo',\n value: 'not_equals',\n },\n]\n\nconst base = [\n ...boolean,\n {\n label: 'isIn',\n value: 'in',\n },\n {\n label: 'isNotIn',\n value: 'not_in',\n },\n {\n label: 'exists',\n value: 'exists',\n },\n]\n\nconst numeric = [\n ...base,\n {\n label: 'isGreaterThan',\n value: 'greater_than',\n },\n {\n label: 'isLessThan',\n value: 'less_than',\n },\n {\n label: 'isLessThanOrEqualTo',\n value: 'less_than_equal',\n },\n {\n label: 'isGreaterThanOrEqualTo',\n value: 'greater_than_equal',\n },\n]\n\nconst geo = [\n ...boolean,\n {\n label: 'exists',\n value: 'exists',\n },\n {\n label: 'near',\n value: 'near',\n },\n]\n\nconst within = {\n label: 'within',\n value: 'within',\n}\n\nconst intersects = {\n label: 'intersects',\n value: 'intersects',\n}\n\nconst like = {\n label: 'isLike',\n value: 'like',\n}\n\nconst contains = {\n label: 'contains',\n value: 'contains',\n}\n\nconst fieldTypeConditions = {\n checkbox: {\n component: 'Text',\n operators: boolean,\n },\n code: {\n component: 'Text',\n operators: [...base, like, contains],\n },\n date: {\n component: 'Date',\n operators: [...base, ...numeric],\n },\n email: {\n component: 'Text',\n operators: [...base, contains],\n },\n json: {\n component: 'Text',\n operators: [...base, like, contains, within, intersects],\n },\n number: {\n component: 'Number',\n operators: [...base, ...numeric],\n },\n point: {\n component: 'Point',\n operators: [...geo, within, intersects],\n },\n radio: {\n component: 'Select',\n operators: [...base],\n },\n relationship: {\n component: 'Relationship',\n operators: [...base],\n },\n richText: {\n component: 'Text',\n operators: [...base, like, contains],\n },\n select: {\n component: 'Select',\n operators: [...base],\n },\n text: {\n component: 'Text',\n operators: [...base, like, contains],\n },\n textarea: {\n component: 'Text',\n operators: [...base, like, contains],\n },\n upload: {\n component: 'Text',\n operators: [...base],\n },\n}\n\nexport default fieldTypeConditions\n"],"mappings":"AAAA;;AACA,MAAMA,OAAA,GAAU,CACd;EACEC,KAAA,EAAO;EACPC,KAAA,EAAO;AACT,GACA;EACED,KAAA,EAAO;EACPC,KAAA,EAAO;AACT,EACD;AAED,MAAMC,IAAA,GAAO,C,GACRH,OAAA,EACH;EACEC,K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A,EAAQC,UAAA;EAC/C;EACAW,MAAA,EAAQ;IACNN,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA,E,GAASC,OAAA;EAC1B;EACAe,KAAA,EAAO;IACLP,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIR,GAAA,EAAKC,MAAA,EAAQC,UAAA;EAC9B;EACAa,KAAA,EAAO;IACLR,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA;EACjB;EACAkB,YAAA,EAAc;IACZT,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA;EACjB;EACAmB,QAAA,EAAU;IACRV,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA,EAAMK,IAAA,EAAMC,QAAA;EAC7B;EACAc,MAAA,EAAQ;IACNX,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA;EACjB;EACAqB,IAAA,EAAM;IACJZ,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA,EAAMK,IAAA,EAAMC,QAAA;EAC7B;EACAgB,QAAA,EAAU;IACRb,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA,EAAMK,IAAA,EAAMC,QAAA;EAC7B;EACAiB,MAAA,EAAQ;IACNd,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA;EACjB;AACF;AAEA,eAAeO,mBAAA","ignoreList":[]}
1
+ {"version":3,"file":"field-types.js","names":["boolean","label","value","base","numeric","geo","within","intersects","like","contains","fieldTypeConditions","checkbox","component","operators","code","date","email","json","number","point","radio","relationship","richText","select","text","textarea","upload"],"sources":["../../../src/elements/WhereBuilder/field-types.tsx"],"sourcesContent":["'use client'\nconst boolean = [\n {\n label: 'equals',\n value: 'equals',\n },\n {\n label: 'isNotEqualTo',\n value: 'not_equals',\n },\n]\n\nconst base = [\n ...boolean,\n {\n label: 'isIn',\n value: 'in',\n },\n {\n label: 'isNotIn',\n value: 'not_in',\n },\n {\n label: 'exists',\n value: 'exists',\n },\n]\n\nconst numeric = [\n ...base,\n {\n label: 'isGreaterThan',\n value: 'greater_than',\n },\n {\n label: 'isLessThan',\n value: 'less_than',\n },\n {\n label: 'isLessThanOrEqualTo',\n value: 'less_than_equal',\n },\n {\n label: 'isGreaterThanOrEqualTo',\n value: 'greater_than_equal',\n },\n]\n\nconst geo = [\n ...boolean,\n {\n label: 'exists',\n value: 'exists',\n },\n {\n label: 'near',\n value: 'near',\n },\n]\n\nconst within = {\n label: 'within',\n value: 'within',\n}\n\nconst intersects = {\n label: 'intersects',\n value: 'intersects',\n}\n\nconst like = {\n label: 'isLike',\n value: 'like',\n}\n\nconst contains = {\n label: 'contains',\n value: 'contains',\n}\n\nconst fieldTypeConditions: {\n [key: string]: {\n component: string\n operators: { label: string; value: string }[]\n }\n} = {\n checkbox: {\n component: 'Text',\n operators: boolean,\n },\n code: {\n component: 'Text',\n operators: [...base, like, contains],\n },\n date: {\n component: 'Date',\n operators: [...base, ...numeric],\n },\n email: {\n component: 'Text',\n operators: [...base, contains],\n },\n json: {\n component: 'Text',\n operators: [...base, like, contains, within, intersects],\n },\n number: {\n component: 'Number',\n operators: [...base, ...numeric],\n },\n point: {\n component: 'Point',\n operators: [...geo, within, intersects],\n },\n radio: {\n component: 'Select',\n operators: [...base],\n },\n relationship: {\n component: 'Relationship',\n operators: [...base],\n },\n richText: {\n component: 'Text',\n operators: [...base, like, contains],\n },\n select: {\n component: 'Select',\n operators: [...base],\n },\n text: {\n component: 'Text',\n operators: [...base, like, contains],\n },\n textarea: {\n component: 'Text',\n operators: [...base, like, contains],\n },\n upload: {\n component: 'Text',\n operators: [...base],\n },\n}\n\nexport default fieldTypeConditions\n"],"mappings":"AAAA;;AACA,MAAMA,OAAA,GAAU,CACd;EACEC,KAAA,EAAO;EACPC,KAAA,EAAO;AACT,GACA;EACED,KAAA,EAAO;EACPC,KAAA,EAAO;AACT,EACD;AAED,MAAMC,IAAA,GAAO,C,GACRH,OAAA,EACH;EACE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A,EAAQC,UAAA;EAC/C;EACAW,MAAA,EAAQ;IACNN,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA,E,GAASC,OAAA;EAC1B;EACAe,KAAA,EAAO;IACLP,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIR,GAAA,EAAKC,MAAA,EAAQC,UAAA;EAC9B;EACAa,KAAA,EAAO;IACLR,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA;EACjB;EACAkB,YAAA,EAAc;IACZT,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA;EACjB;EACAmB,QAAA,EAAU;IACRV,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA,EAAMK,IAAA,EAAMC,QAAA;EAC7B;EACAc,MAAA,EAAQ;IACNX,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA;EACjB;EACAqB,IAAA,EAAM;IACJZ,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA,EAAMK,IAAA,EAAMC,QAAA;EAC7B;EACAgB,QAAA,EAAU;IACRb,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA,EAAMK,IAAA,EAAMC,QAAA;EAC7B;EACAiB,MAAA,EAAQ;IACNd,SAAA,EAAW;IACXC,SAAA,EAAW,C,GAAIV,IAAA;EACjB;AACF;AAEA,eAAeO,mBAAA","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AASnD,OAAO,cAAc,CAAA;AAIrB,OAAO,EAAE,iBAAiB,EAAE,CAAA;AAE5B;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA+NpD,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/index.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAEtC,OAAO,KAAK,EAAiC,iBAAiB,EAAE,MAAM,YAAY,CAAA;AAUlF,OAAO,cAAc,CAAA;AAIrB,OAAO,EAAE,iBAAiB,EAAE,CAAA;AAE5B;;;GAGG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA2MpD,CAAA"}
@@ -1,14 +1,14 @@
1
1
  'use client';
2
2
 
3
- import { c as _c } from "react/compiler-runtime";
4
3
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
5
4
  import { getTranslation } from '@payloadcms/translations';
6
- import React, { useEffect, useState } from 'react';
5
+ import React, { useMemo } from 'react';
7
6
  import { useListQuery } from '../../providers/ListQuery/index.js';
8
7
  import { useTranslation } from '../../providers/Translation/index.js';
9
8
  import { Button } from '../Button/index.js';
10
9
  import { Condition } from './Condition/index.js';
11
- import { reduceClientFields } from './reduceClientFields.js';
10
+ import fieldTypes from './field-types.js';
11
+ import { reduceFields } from './reduceFields.js';
12
12
  import { transformWhereQuery } from './transformWhereQuery.js';
13
13
  import validateWhereQuery from './validateWhereQuery.js';
14
14
  import './index.scss';
@@ -18,7 +18,6 @@ const baseClass = 'where-builder';
18
18
  * It is part of the {@link ListControls} component which is used to render the controls (search, filter, where).
19
19
  */
20
20
  export const WhereBuilder = props => {
21
- const $ = _c(30);
22
21
  const {
23
22
  collectionPluralLabel,
24
23
  fields,
@@ -28,276 +27,186 @@ export const WhereBuilder = props => {
28
27
  i18n,
29
28
  t
30
29
  } = useTranslation();
31
- let t0;
32
- if ($[0] !== fields || $[1] !== i18n) {
33
- t0 = () => reduceClientFields({
34
- fields,
35
- i18n
36
- });
37
- $[0] = fields;
38
- $[1] = i18n;
39
- $[2] = t0;
40
- } else {
41
- t0 = $[2];
42
- }
43
- const [options, setOptions] = useState(t0);
44
- let t1;
45
- let t2;
46
- if ($[3] !== fields || $[4] !== i18n) {
47
- t1 = () => {
48
- setOptions(reduceClientFields({
49
- fields,
50
- i18n
51
- }));
52
- };
53
- t2 = [fields, i18n];
54
- $[3] = fields;
55
- $[4] = i18n;
56
- $[5] = t1;
57
- $[6] = t2;
58
- } else {
59
- t1 = $[5];
60
- t2 = $[6];
61
- }
62
- useEffect(t1, t2);
30
+ const reducedFields = useMemo(() => reduceFields({
31
+ fields,
32
+ i18n
33
+ }), [fields, i18n]);
63
34
  const {
64
35
  handleWhereChange,
65
36
  query
66
37
  } = useListQuery();
67
38
  const [shouldUpdateQuery, setShouldUpdateQuery] = React.useState(false);
68
- let t3;
69
- if ($[7] !== query.where) {
70
- t3 = () => {
71
- const whereFromSearch = query.where;
72
- if (whereFromSearch) {
73
- if (validateWhereQuery(whereFromSearch)) {
74
- return whereFromSearch.or;
75
- }
76
- const transformedWhere = transformWhereQuery(whereFromSearch);
77
- if (validateWhereQuery(transformedWhere)) {
78
- return transformedWhere.or;
79
- }
80
- console.warn(`Invalid where query in URL: ${JSON.stringify(whereFromSearch)}`);
39
+ const [conditions, setConditions] = React.useState(() => {
40
+ const whereFromSearch = query.where;
41
+ if (whereFromSearch) {
42
+ if (validateWhereQuery(whereFromSearch)) {
43
+ return whereFromSearch.or;
81
44
  }
82
- return [];
83
- };
84
- $[7] = query.where;
85
- $[8] = t3;
86
- } else {
87
- t3 = $[8];
88
- }
89
- const [conditions, setConditions] = React.useState(t3);
90
- let t4;
91
- if ($[9] !== conditions) {
92
- t4 = t5 => {
93
- const {
94
- andIndex,
95
- fieldName,
96
- orIndex,
97
- relation
98
- } = t5;
99
- const newConditions = [...conditions];
100
- if (relation === "and") {
101
- newConditions[orIndex].and.splice(andIndex, 0, {
102
- [fieldName]: {}
103
- });
104
- } else {
105
- newConditions.push({
106
- and: [{
107
- [fieldName]: {}
108
- }]
109
- });
45
+ // Transform the where query to be in the right format. This will transform something simple like [text][equals]=example%20post to the right format
46
+ const transformedWhere = transformWhereQuery(whereFromSearch);
47
+ if (validateWhereQuery(transformedWhere)) {
48
+ return transformedWhere.or;
110
49
  }
111
- setConditions(newConditions);
112
- };
113
- $[9] = conditions;
114
- $[10] = t4;
115
- } else {
116
- t4 = $[10];
117
- }
118
- const addCondition = t4;
119
- let t5;
120
- if ($[11] !== conditions) {
121
- t5 = t6 => {
122
- const {
123
- andIndex: andIndex_0,
124
- fieldName: fieldName_0,
125
- operator,
126
- orIndex: orIndex_0,
127
- value: valueArg
128
- } = t6;
129
- const existingRowCondition = conditions[orIndex_0].and[andIndex_0];
130
- if (typeof existingRowCondition === "object" && fieldName_0 && operator) {
131
- const value = valueArg ?? (operator ? existingRowCondition[operator] : "");
132
- const newRowCondition = {
133
- [fieldName_0]: operator ? {
134
- [operator]: value
135
- } : {}
136
- };
137
- if (JSON.stringify(existingRowCondition) !== JSON.stringify(newRowCondition)) {
138
- const newConditions_0 = [...conditions];
139
- newConditions_0[orIndex_0].and[andIndex_0] = newRowCondition;
140
- setConditions(newConditions_0);
141
- if (![null, undefined].includes(value)) {
142
- setShouldUpdateQuery(true);
50
+ console.warn(`Invalid where query in URL: ${JSON.stringify(whereFromSearch)}`) // eslint-disable-line no-console
51
+ ;
52
+ }
53
+ return [];
54
+ });
55
+ const addCondition = React.useCallback(({
56
+ andIndex,
57
+ field,
58
+ orIndex,
59
+ relation
60
+ }) => {
61
+ const newConditions = [...conditions];
62
+ const defaultOperator = fieldTypes[field.field.type].operators[0].value;
63
+ if (relation === 'and') {
64
+ newConditions[orIndex].and.splice(andIndex, 0, {
65
+ [field.value]: {
66
+ [defaultOperator]: undefined
67
+ }
68
+ });
69
+ } else {
70
+ newConditions.push({
71
+ and: [{
72
+ [field.value]: {
73
+ [defaultOperator]: undefined
143
74
  }
75
+ }]
76
+ });
77
+ }
78
+ setConditions(newConditions);
79
+ }, [conditions]);
80
+ const updateCondition = React.useCallback(({
81
+ andIndex: andIndex_0,
82
+ field: field_0,
83
+ operator: incomingOperator,
84
+ orIndex: orIndex_0,
85
+ value: valueArg
86
+ }) => {
87
+ const existingRowCondition = conditions[orIndex_0].and[andIndex_0];
88
+ const defaults = fieldTypes[field_0.field.type];
89
+ const operator = incomingOperator || defaults.operators[0].value;
90
+ if (typeof existingRowCondition === 'object' && field_0.value) {
91
+ const value = valueArg ?? existingRowCondition?.[operator];
92
+ const newRowCondition = {
93
+ [field_0.value]: {
94
+ [operator]: value
144
95
  }
145
- }
146
- };
147
- $[11] = conditions;
148
- $[12] = t5;
149
- } else {
150
- t5 = $[12];
151
- }
152
- const updateCondition = t5;
153
- let t6;
154
- if ($[13] !== conditions) {
155
- t6 = t7 => {
156
- const {
157
- andIndex: andIndex_1,
158
- orIndex: orIndex_1
159
- } = t7;
160
- const newConditions_1 = [...conditions];
161
- newConditions_1[orIndex_1].and.splice(andIndex_1, 1);
162
- if (newConditions_1[orIndex_1].and.length === 0) {
163
- newConditions_1.splice(orIndex_1, 1);
164
- }
165
- setConditions(newConditions_1);
96
+ };
97
+ const newConditions_0 = [...conditions];
98
+ newConditions_0[orIndex_0].and[andIndex_0] = newRowCondition;
99
+ setConditions(newConditions_0);
166
100
  setShouldUpdateQuery(true);
167
- };
168
- $[13] = conditions;
169
- $[14] = t6;
170
- } else {
171
- t6 = $[14];
172
- }
173
- const removeCondition = t6;
174
- let t7;
175
- let t8;
176
- if ($[15] !== conditions || $[16] !== handleWhereChange || $[17] !== shouldUpdateQuery) {
177
- t7 = () => {
178
- if (shouldUpdateQuery) {
179
- const handleChange = async function handleChange() {
180
- await handleWhereChange({
181
- or: conditions
182
- });
183
- setShouldUpdateQuery(false);
184
- };
185
- handleChange();
101
+ }
102
+ }, [conditions]);
103
+ const removeCondition = React.useCallback(({
104
+ andIndex: andIndex_1,
105
+ orIndex: orIndex_1
106
+ }) => {
107
+ const newConditions_1 = [...conditions];
108
+ newConditions_1[orIndex_1].and.splice(andIndex_1, 1);
109
+ if (newConditions_1[orIndex_1].and.length === 0) {
110
+ newConditions_1.splice(orIndex_1, 1);
111
+ }
112
+ setConditions(newConditions_1);
113
+ setShouldUpdateQuery(true);
114
+ }, [conditions]);
115
+ React.useEffect(() => {
116
+ if (shouldUpdateQuery) {
117
+ async function handleChange() {
118
+ await handleWhereChange({
119
+ or: conditions
120
+ });
121
+ setShouldUpdateQuery(false);
186
122
  }
187
- };
188
- t8 = [conditions, handleWhereChange, shouldUpdateQuery];
189
- $[15] = conditions;
190
- $[16] = handleWhereChange;
191
- $[17] = shouldUpdateQuery;
192
- $[18] = t7;
193
- $[19] = t8;
194
- } else {
195
- t7 = $[18];
196
- t8 = $[19];
197
- }
198
- React.useEffect(t7, t8);
199
- let t9;
200
- if ($[20] !== addCondition || $[21] !== collectionPluralLabel || $[22] !== conditions || $[23] !== i18n || $[24] !== options || $[25] !== removeCondition || $[26] !== renderedFilters || $[27] !== t || $[28] !== updateCondition) {
201
- t9 = _jsxs("div", {
202
- className: baseClass,
203
- children: [conditions.length > 0 && _jsxs(React.Fragment, {
204
- children: [_jsx("div", {
205
- className: `${baseClass}__label`,
206
- children: t("general:filterWhere", {
207
- label: getTranslation(collectionPluralLabel, i18n)
208
- })
209
- }), _jsx("ul", {
210
- className: `${baseClass}__or-filters`,
211
- children: conditions.map((or, orIndex_2) => {
212
- const compoundOrKey = `${orIndex_2}_${Array.isArray(or?.and) ? or.and.length : ""}`;
213
- return _jsxs("li", {
214
- children: [orIndex_2 !== 0 && _jsx("div", {
215
- className: `${baseClass}__label`,
216
- children: t("general:or")
217
- }), _jsx("ul", {
218
- className: `${baseClass}__and-filters`,
219
- children: Array.isArray(or?.and) && or.and.map((_, andIndex_2) => {
220
- const initialFieldName = Object.keys(conditions[orIndex_2].and[andIndex_2])[0];
221
- const initialOperator = Object.keys(conditions[orIndex_2].and[andIndex_2]?.[initialFieldName] || {})?.[0] || undefined;
222
- const initialValue = conditions[orIndex_2].and[andIndex_2]?.[initialFieldName]?.[initialOperator] || undefined;
223
- return _jsxs("li", {
224
- children: [andIndex_2 !== 0 && _jsx("div", {
225
- className: `${baseClass}__label`,
226
- children: t("general:and")
227
- }), _jsx(Condition, {
228
- addCondition,
229
- andIndex: andIndex_2,
230
- fieldName: initialFieldName,
231
- initialValue,
232
- operator: initialOperator,
233
- options,
234
- orIndex: orIndex_2,
235
- removeCondition,
236
- RenderedFilter: renderedFilters?.get(initialFieldName),
237
- updateCondition
238
- })]
239
- }, andIndex_2);
240
- })
241
- })]
242
- }, compoundOrKey);
243
- })
244
- }), _jsx(Button, {
245
- buttonStyle: "icon-label",
246
- className: `${baseClass}__add-or`,
247
- icon: "plus",
248
- iconPosition: "left",
249
- iconStyle: "with-border",
250
- onClick: () => {
123
+ void handleChange();
124
+ }
125
+ }, [conditions, handleWhereChange, shouldUpdateQuery]);
126
+ return /*#__PURE__*/_jsxs("div", {
127
+ className: baseClass,
128
+ children: [conditions.length > 0 && /*#__PURE__*/_jsxs(React.Fragment, {
129
+ children: [/*#__PURE__*/_jsx("div", {
130
+ className: `${baseClass}__label`,
131
+ children: t('general:filterWhere', {
132
+ label: getTranslation(collectionPluralLabel, i18n)
133
+ })
134
+ }), /*#__PURE__*/_jsx("ul", {
135
+ className: `${baseClass}__or-filters`,
136
+ children: conditions.map((or, orIndex_2) => {
137
+ const compoundOrKey = `${orIndex_2}_${Array.isArray(or?.and) ? or.and.length : ''}`;
138
+ return /*#__PURE__*/_jsxs("li", {
139
+ children: [orIndex_2 !== 0 && /*#__PURE__*/_jsx("div", {
140
+ className: `${baseClass}__label`,
141
+ children: t('general:or')
142
+ }), /*#__PURE__*/_jsx("ul", {
143
+ className: `${baseClass}__and-filters`,
144
+ children: Array.isArray(or?.and) && or.and.map((_, andIndex_2) => {
145
+ const condition = conditions[orIndex_2].and[andIndex_2];
146
+ const fieldName = Object.keys(condition)[0];
147
+ const operator_0 = Object.keys(condition?.[fieldName] || {})?.[0] || undefined;
148
+ const value_0 = condition?.[fieldName]?.[operator_0] || undefined;
149
+ return /*#__PURE__*/_jsxs("li", {
150
+ children: [andIndex_2 !== 0 && /*#__PURE__*/_jsx("div", {
151
+ className: `${baseClass}__label`,
152
+ children: t('general:and')
153
+ }), /*#__PURE__*/_jsx(Condition, {
154
+ addCondition: addCondition,
155
+ andIndex: andIndex_2,
156
+ fieldName: fieldName,
157
+ operator: operator_0,
158
+ orIndex: orIndex_2,
159
+ reducedFields: reducedFields,
160
+ removeCondition: removeCondition,
161
+ RenderedFilter: renderedFilters?.get(fieldName),
162
+ updateCondition: updateCondition,
163
+ value: value_0
164
+ })]
165
+ }, andIndex_2);
166
+ })
167
+ })]
168
+ }, compoundOrKey);
169
+ })
170
+ }), /*#__PURE__*/_jsx(Button, {
171
+ buttonStyle: "icon-label",
172
+ className: `${baseClass}__add-or`,
173
+ icon: "plus",
174
+ iconPosition: "left",
175
+ iconStyle: "with-border",
176
+ onClick: () => {
177
+ addCondition({
178
+ andIndex: 0,
179
+ field: reducedFields[0],
180
+ orIndex: conditions.length,
181
+ relation: 'or'
182
+ });
183
+ },
184
+ children: t('general:or')
185
+ })]
186
+ }), conditions.length === 0 && /*#__PURE__*/_jsxs("div", {
187
+ className: `${baseClass}__no-filters`,
188
+ children: [/*#__PURE__*/_jsx("div", {
189
+ className: `${baseClass}__label`,
190
+ children: t('general:noFiltersSet')
191
+ }), /*#__PURE__*/_jsx(Button, {
192
+ buttonStyle: "icon-label",
193
+ className: `${baseClass}__add-first-filter`,
194
+ icon: "plus",
195
+ iconPosition: "left",
196
+ iconStyle: "with-border",
197
+ onClick: () => {
198
+ if (reducedFields.length > 0) {
251
199
  addCondition({
252
200
  andIndex: 0,
253
- fieldName: options[0].value,
201
+ field: reducedFields.find(field_1 => !field_1.field.admin?.disableListFilter),
254
202
  orIndex: conditions.length,
255
- relation: "or"
203
+ relation: 'or'
256
204
  });
257
- },
258
- children: t("general:or")
259
- })]
260
- }), conditions.length === 0 && _jsxs("div", {
261
- className: `${baseClass}__no-filters`,
262
- children: [_jsx("div", {
263
- className: `${baseClass}__label`,
264
- children: t("general:noFiltersSet")
265
- }), _jsx(Button, {
266
- buttonStyle: "icon-label",
267
- className: `${baseClass}__add-first-filter`,
268
- icon: "plus",
269
- iconPosition: "left",
270
- iconStyle: "with-border",
271
- onClick: () => {
272
- if (options.length > 0) {
273
- addCondition({
274
- andIndex: 0,
275
- fieldName: options.find(_temp).value,
276
- orIndex: conditions.length,
277
- relation: "or"
278
- });
279
- }
280
- },
281
- children: t("general:addFilter")
282
- })]
205
+ }
206
+ },
207
+ children: t('general:addFilter')
283
208
  })]
284
- });
285
- $[20] = addCondition;
286
- $[21] = collectionPluralLabel;
287
- $[22] = conditions;
288
- $[23] = i18n;
289
- $[24] = options;
290
- $[25] = removeCondition;
291
- $[26] = renderedFilters;
292
- $[27] = t;
293
- $[28] = updateCondition;
294
- $[29] = t9;
295
- } else {
296
- t9 = $[29];
297
- }
298
- return t9;
209
+ })]
210
+ });
299
211
  };
300
- function _temp(field) {
301
- return !field.field.admin?.disableListFilter;
302
- }
303
212
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","getTranslation","React","useEffect","useState","useListQuery","useTranslation","Button","Condition","reduceClientFields","transformWhereQuery","validateWhereQuery","baseClass","WhereBuilder","props","$","collectionPluralLabel","fields","renderedFilters","i18n","t","t0","options","setOptions","t1","t2","handleWhereChange","query","shouldUpdateQuery","setShouldUpdateQuery","t3","where","whereFromSearch","or","transformedWhere","console","warn","JSON","stringify","conditions","setConditions","t4","t5","andIndex","fieldName","orIndex","relation","newConditions","and","splice","push","addCondition","t6","andIndex_0","fieldName_0","operator","orIndex_0","value","valueArg","existingRowCondition","newRowCondition","newConditions_0","undefined","includes","updateCondition","t7","andIndex_1","orIndex_1","newConditions_1","length","removeCondition","t8","handleChange","t9","_jsxs","className","children","Fragment","_jsx","label","map","orIndex_2","compoundOrKey","Array","isArray","_","andIndex_2","initialFieldName","Object","keys","initialOperator","initialValue","RenderedFilter","get","buttonStyle","icon","iconPosition","iconStyle","onClick","find","_temp","field","admin","disableListFilter"],"sources":["../../../src/elements/WhereBuilder/index.tsx"],"sourcesContent":["'use client'\nimport type { Operator } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useEffect, useState } from 'react'\n\nimport type { WhereBuilderProps } from './types.js'\n\nimport { useListQuery } from '../../providers/ListQuery/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { Button } from '../Button/index.js'\nimport { Condition } from './Condition/index.js'\nimport { reduceClientFields } from './reduceClientFields.js'\nimport { transformWhereQuery } from './transformWhereQuery.js'\nimport validateWhereQuery from './validateWhereQuery.js'\nimport './index.scss'\n\nconst baseClass = 'where-builder'\n\nexport { WhereBuilderProps }\n\n/**\n * The WhereBuilder component is used to render the filter controls for a collection's list view.\n * It is part of the {@link ListControls} component which is used to render the controls (search, filter, where).\n */\nexport const WhereBuilder: React.FC<WhereBuilderProps> = (props) => {\n const { collectionPluralLabel, fields, renderedFilters } = props\n const { i18n, t } = useTranslation()\n\n const [options, setOptions] = useState(() => reduceClientFields({ fields, i18n }))\n\n useEffect(() => {\n setOptions(reduceClientFields({ fields, i18n }))\n }, [fields, i18n])\n\n const { handleWhereChange, query } = useListQuery()\n const [shouldUpdateQuery, setShouldUpdateQuery] = React.useState(false)\n\n // This handles initializing the where conditions from the search query (URL). That way, if you pass in\n // query params to the URL, the where conditions will be initialized from those and displayed in the UI.\n // Example: /admin/collections/posts?where[or][0][and][0][text][equals]=example%20post\n /*\n stored conditions look like this:\n [\n _or_ & _and_ queries have the same shape:\n {\n and: [{\n category: {\n equals: 'category-a'\n }\n }]\n },\n\n {\n and:[{\n category: {\n equals: 'category-b'\n },\n text: {\n not_equals: 'oranges'\n },\n }]\n }\n ]\n */\n\n const [conditions, setConditions] = React.useState(() => {\n const whereFromSearch = query.where\n\n if (whereFromSearch) {\n if (validateWhereQuery(whereFromSearch)) {\n return whereFromSearch.or\n }\n // Transform the where query to be in the right format. This will transform something simple like [text][equals]=example%20post to the right format\n const transformedWhere = transformWhereQuery(whereFromSearch)\n\n if (validateWhereQuery(transformedWhere)) {\n return transformedWhere.or\n }\n\n console.warn(`Invalid where query in URL: ${JSON.stringify(whereFromSearch)}`) // eslint-disable-line no-console\n }\n\n return []\n })\n\n const addCondition = React.useCallback(\n ({ andIndex, fieldName, orIndex, relation }) => {\n const newConditions = [...conditions]\n if (relation === 'and') {\n newConditions[orIndex].and.splice(andIndex, 0, { [fieldName]: {} })\n } else {\n newConditions.push({\n and: [\n {\n [fieldName]: {},\n },\n ],\n })\n }\n setConditions(newConditions)\n },\n [conditions],\n )\n\n const updateCondition = React.useCallback(\n ({ andIndex, fieldName, operator, orIndex, value: valueArg }) => {\n const existingRowCondition = conditions[orIndex].and[andIndex]\n if (typeof existingRowCondition === 'object' && fieldName && operator) {\n const value = valueArg ?? (operator ? existingRowCondition[operator] : '')\n const newRowCondition = {\n [fieldName]: operator ? { [operator]: value } : {},\n }\n\n if (JSON.stringify(existingRowCondition) !== JSON.stringify(newRowCondition)) {\n const newConditions = [...conditions]\n newConditions[orIndex].and[andIndex] = newRowCondition\n setConditions(newConditions)\n if (![null, undefined].includes(value)) {\n // only update query when field/operator/value are filled out\n setShouldUpdateQuery(true)\n }\n }\n }\n },\n [conditions],\n )\n\n const removeCondition = React.useCallback(\n ({ andIndex, orIndex }) => {\n const newConditions = [...conditions]\n newConditions[orIndex].and.splice(andIndex, 1)\n if (newConditions[orIndex].and.length === 0) {\n newConditions.splice(orIndex, 1)\n }\n setConditions(newConditions)\n setShouldUpdateQuery(true)\n },\n [conditions],\n )\n\n React.useEffect(() => {\n if (shouldUpdateQuery) {\n async function handleChange() {\n await handleWhereChange({ or: conditions })\n setShouldUpdateQuery(false)\n }\n void handleChange()\n }\n }, [conditions, handleWhereChange, shouldUpdateQuery])\n\n return (\n <div className={baseClass}>\n {conditions.length > 0 && (\n <React.Fragment>\n <div className={`${baseClass}__label`}>\n {t('general:filterWhere', { label: getTranslation(collectionPluralLabel, i18n) })}\n </div>\n <ul className={`${baseClass}__or-filters`}>\n {conditions.map((or, orIndex) => {\n const compoundOrKey = `${orIndex}_${Array.isArray(or?.and) ? or.and.length : ''}`\n\n return (\n <li key={compoundOrKey}>\n {orIndex !== 0 && <div className={`${baseClass}__label`}>{t('general:or')}</div>}\n <ul className={`${baseClass}__and-filters`}>\n {Array.isArray(or?.and) &&\n or.and.map((_, andIndex) => {\n const initialFieldName = Object.keys(conditions[orIndex].and[andIndex])[0]\n const initialOperator =\n (Object.keys(\n conditions[orIndex].and[andIndex]?.[initialFieldName] || {},\n )?.[0] as Operator) || undefined\n const initialValue =\n conditions[orIndex].and[andIndex]?.[initialFieldName]?.[\n initialOperator\n ] || undefined\n\n return (\n <li key={andIndex}>\n {andIndex !== 0 && (\n <div className={`${baseClass}__label`}>{t('general:and')}</div>\n )}\n <Condition\n addCondition={addCondition}\n andIndex={andIndex}\n fieldName={initialFieldName}\n initialValue={initialValue}\n operator={initialOperator}\n options={options}\n orIndex={orIndex}\n removeCondition={removeCondition}\n RenderedFilter={renderedFilters?.get(initialFieldName)}\n updateCondition={updateCondition}\n />\n </li>\n )\n })}\n </ul>\n </li>\n )\n })}\n </ul>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-or`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => {\n addCondition({\n andIndex: 0,\n fieldName: options[0].value,\n orIndex: conditions.length,\n relation: 'or',\n })\n }}\n >\n {t('general:or')}\n </Button>\n </React.Fragment>\n )}\n {conditions.length === 0 && (\n <div className={`${baseClass}__no-filters`}>\n <div className={`${baseClass}__label`}>{t('general:noFiltersSet')}</div>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-first-filter`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => {\n if (options.length > 0) {\n addCondition({\n andIndex: 0,\n fieldName: options.find((field) => !field.field.admin?.disableListFilter).value,\n orIndex: conditions.length,\n relation: 'or',\n })\n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AA;cAAAvB,QAAA,EACC;YAAA,CACZ;UAAA;UAAA8B,QAAA,EAGDxD,CAAA,CAAE;QAAA,C;UAIRmB,UAAA,CAAA8B,MAAA,MAAsB,IACrBK,KAAA,CAAC;QAAAC,SAAA,EAAe,GAAA/D,SAAA,cAA0B;QAAAgE,QAAA,GACxCE,IAAA,CAAC;UAAAH,SAAA,EAAe,GAAA/D,SAAA,SAAqB;UAAAgE,QAAA,EAAGxD,CAAA,CAAE;QAAA,C,GAC1C0D,IAAA,CAAAvE,MAAA;UAAAuF,WAAA,EACc;UAAAnB,SAAA,EACD,GAAA/D,SAAA,oBAAgC;UAAAmF,IAAA,EACtC;UAAAC,YAAA,EACQ;UAAAC,SAAA,EACH;UAAAC,OAAA,EAAAA,CAAA;YAAA,IAEJ5E,OAAA,CAAA+C,MAAA,IAAiB;cACnBlB,YAAA;gBAAAR,QAAA;gBAAAC,SAAA,EAEatB,OAAA,CAAA6E,IAAA,CAAAC,KAA4C,EAAA3C,KAAA;gBAAAZ,OAAA,EAC9CN,UAAA,CAAA8B,MAAA;gBAAAvB,QAAA,EACC;cAAA,CACZ;YAAA;UAAA;UAAA8B,QAAA,EAIHxD,CAAA,CAAE;QAAA,C;;;;;;;;;;;;;;;;SA1FXqD,E;CAgGJ;AA/NyD,SAAA2B,MAAAC,KAAA;EAAA,QAkNHA,KAAA,CAAAA,KAAA,CAAAC,KAAA,EAAAC,iBAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["getTranslation","React","useMemo","useListQuery","useTranslation","Button","Condition","fieldTypes","reduceFields","transformWhereQuery","validateWhereQuery","baseClass","WhereBuilder","props","collectionPluralLabel","fields","renderedFilters","i18n","t","reducedFields","handleWhereChange","query","shouldUpdateQuery","setShouldUpdateQuery","useState","conditions","setConditions","whereFromSearch","where","or","transformedWhere","console","warn","JSON","stringify","addCondition","useCallback","andIndex","field","orIndex","relation","newConditions","defaultOperator","type","operators","value","and","splice","undefined","push","updateCondition","operator","incomingOperator","valueArg","existingRowCondition","defaults","newRowCondition","removeCondition","length","useEffect","handleChange","_jsxs","className","Fragment","_jsx","label","map","compoundOrKey","Array","isArray","_","condition","fieldName","Object","keys","RenderedFilter","get","buttonStyle","icon","iconPosition","iconStyle","onClick","find","admin","disableListFilter"],"sources":["../../../src/elements/WhereBuilder/index.tsx"],"sourcesContent":["'use client'\nimport type { Operator, Where } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport React, { useMemo } from 'react'\n\nimport type { AddCondition, UpdateCondition, WhereBuilderProps } from './types.js'\n\nimport { useListQuery } from '../../providers/ListQuery/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { Button } from '../Button/index.js'\nimport { Condition } from './Condition/index.js'\nimport fieldTypes from './field-types.js'\nimport { reduceFields } from './reduceFields.js'\nimport { transformWhereQuery } from './transformWhereQuery.js'\nimport validateWhereQuery from './validateWhereQuery.js'\nimport './index.scss'\n\nconst baseClass = 'where-builder'\n\nexport { WhereBuilderProps }\n\n/**\n * The WhereBuilder component is used to render the filter controls for a collection's list view.\n * It is part of the {@link ListControls} component which is used to render the controls (search, filter, where).\n */\nexport const WhereBuilder: React.FC<WhereBuilderProps> = (props) => {\n const { collectionPluralLabel, fields, renderedFilters } = props\n const { i18n, t } = useTranslation()\n\n const reducedFields = useMemo(() => reduceFields({ fields, i18n }), [fields, i18n])\n\n const { handleWhereChange, query } = useListQuery()\n const [shouldUpdateQuery, setShouldUpdateQuery] = React.useState(false)\n\n const [conditions, setConditions] = React.useState<Where[]>(() => {\n const whereFromSearch = query.where\n\n if (whereFromSearch) {\n if (validateWhereQuery(whereFromSearch)) {\n return whereFromSearch.or\n }\n\n // Transform the where query to be in the right format. This will transform something simple like [text][equals]=example%20post to the right format\n const transformedWhere = transformWhereQuery(whereFromSearch)\n\n if (validateWhereQuery(transformedWhere)) {\n return transformedWhere.or\n }\n\n console.warn(`Invalid where query in URL: ${JSON.stringify(whereFromSearch)}`) // eslint-disable-line no-console\n }\n\n return []\n })\n\n const addCondition: AddCondition = React.useCallback(\n ({ andIndex, field, orIndex, relation }) => {\n const newConditions = [...conditions]\n\n const defaultOperator = fieldTypes[field.field.type].operators[0].value\n\n if (relation === 'and') {\n newConditions[orIndex].and.splice(andIndex, 0, {\n [field.value]: {\n [defaultOperator]: undefined,\n },\n })\n } else {\n newConditions.push({\n and: [\n {\n [field.value]: {\n [defaultOperator]: undefined,\n },\n },\n ],\n })\n }\n\n setConditions(newConditions)\n },\n [conditions],\n )\n\n const updateCondition: UpdateCondition = React.useCallback(\n ({ andIndex, field, operator: incomingOperator, orIndex, value: valueArg }) => {\n const existingRowCondition = conditions[orIndex].and[andIndex]\n\n const defaults = fieldTypes[field.field.type]\n const operator = incomingOperator || defaults.operators[0].value\n\n if (typeof existingRowCondition === 'object' && field.value) {\n const value = valueArg ?? existingRowCondition?.[operator]\n\n const newRowCondition = {\n [field.value]: { [operator]: value },\n }\n\n const newConditions = [...conditions]\n newConditions[orIndex].and[andIndex] = newRowCondition\n\n setConditions(newConditions)\n setShouldUpdateQuery(true)\n }\n },\n [conditions],\n )\n\n const removeCondition = React.useCallback(\n ({ andIndex, orIndex }) => {\n const newConditions = [...conditions]\n newConditions[orIndex].and.splice(andIndex, 1)\n\n if (newConditions[orIndex].and.length === 0) {\n newConditions.splice(orIndex, 1)\n }\n\n setConditions(newConditions)\n setShouldUpdateQuery(true)\n },\n [conditions],\n )\n\n React.useEffect(() => {\n if (shouldUpdateQuery) {\n async function handleChange() {\n await handleWhereChange({ or: conditions })\n setShouldUpdateQuery(false)\n }\n void handleChange()\n }\n }, [conditions, handleWhereChange, shouldUpdateQuery])\n\n return (\n <div className={baseClass}>\n {conditions.length > 0 && (\n <React.Fragment>\n <div className={`${baseClass}__label`}>\n {t('general:filterWhere', { label: getTranslation(collectionPluralLabel, i18n) })}\n </div>\n <ul className={`${baseClass}__or-filters`}>\n {conditions.map((or, orIndex) => {\n const compoundOrKey = `${orIndex}_${Array.isArray(or?.and) ? or.and.length : ''}`\n\n return (\n <li key={compoundOrKey}>\n {orIndex !== 0 && <div className={`${baseClass}__label`}>{t('general:or')}</div>}\n <ul className={`${baseClass}__and-filters`}>\n {Array.isArray(or?.and) &&\n or.and.map((_, andIndex) => {\n const condition = conditions[orIndex].and[andIndex]\n const fieldName = Object.keys(condition)[0]\n\n const operator =\n (Object.keys(condition?.[fieldName] || {})?.[0] as Operator) || undefined\n\n const value = condition?.[fieldName]?.[operator] || undefined\n\n return (\n <li key={andIndex}>\n {andIndex !== 0 && (\n <div className={`${baseClass}__label`}>{t('general:and')}</div>\n )}\n <Condition\n addCondition={addCondition}\n andIndex={andIndex}\n fieldName={fieldName}\n operator={operator}\n orIndex={orIndex}\n reducedFields={reducedFields}\n removeCondition={removeCondition}\n RenderedFilter={renderedFilters?.get(fieldName)}\n updateCondition={updateCondition}\n value={value}\n />\n </li>\n )\n })}\n </ul>\n </li>\n )\n })}\n </ul>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-or`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => {\n addCondition({\n andIndex: 0,\n field: reducedFields[0],\n orIndex: conditions.length,\n relation: 'or',\n })\n }}\n >\n {t('general:or')}\n </Button>\n </React.Fragment>\n )}\n {conditions.length === 0 && (\n <div className={`${baseClass}__no-filters`}>\n <div className={`${baseClass}__label`}>{t('general:noFiltersSet')}</div>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__add-first-filter`}\n icon=\"plus\"\n iconPosition=\"left\"\n iconStyle=\"with-border\"\n onClick={() => {\n if (reducedFields.length > 0) {\n addCondition({\n andIndex: 0,\n field: reducedFields.find((field) => !field.field.admin?.disableListFilter),\n orIndex: conditions.length,\n relation: 'or',\n })\n }\n }}\n >\n {t('general:addFilter')}\n </Button>\n </div>\n )}\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,OAAO,QAAQ;AA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,EAAEC,iBAAA;cACzD7C,OAAA,EAASd,UAAA,CAAWiC,MAAM;cAC1BlB,QAAA,EAAU;YACZ;UACF;QACF;kBAECtB,CAAA,CAAE;;;;AAMf","ignoreList":[]}
@@ -1,7 +1,7 @@
1
1
  import type { I18nClient } from '@payloadcms/translations';
2
2
  import type { ClientField } from 'payload';
3
- import type { FieldCondition } from './types.js';
4
- export type ReduceClientFieldsArgs = {
3
+ import type { ReducedField } from './types.js';
4
+ type ReduceFieldOptionsArgs = {
5
5
  fields: ClientField[];
6
6
  i18n: I18nClient;
7
7
  labelPrefix?: string;
@@ -11,5 +11,6 @@ export type ReduceClientFieldsArgs = {
11
11
  * Reduces a field map to a flat array of fields with labels and values.
12
12
  * Used in the WhereBuilder component to render the fields in the dropdown.
13
13
  */
14
- export declare const reduceClientFields: ({ fields, i18n, labelPrefix, pathPrefix, }: ReduceClientFieldsArgs) => FieldCondition[];
15
- //# sourceMappingURL=reduceClientFields.d.ts.map
14
+ export declare const reduceFields: ({ fields, i18n, labelPrefix, pathPrefix, }: ReduceFieldOptionsArgs) => ReducedField[];
15
+ export {};
16
+ //# sourceMappingURL=reduceFields.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reduceFields.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/reduceFields.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,UAAU,EAAE,MAAM,0BAA0B,CAAA;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAK1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAM9C,KAAK,sBAAsB,GAAG;IAC5B,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,IAAI,EAAE,UAAU,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,+CAKtB,sBAAsB,KAAG,YAAY,EA4IvC,CAAA"}