@payloadcms/ui 3.23.0-canary.f63b80a → 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 (118) 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/PublishButton/ScheduleDrawer/buildUpcomingColumns.d.ts.map +1 -1
  5. package/dist/elements/PublishButton/ScheduleDrawer/buildUpcomingColumns.js +17 -1
  6. package/dist/elements/PublishButton/ScheduleDrawer/buildUpcomingColumns.js.map +1 -1
  7. package/dist/elements/PublishButton/ScheduleDrawer/index.d.ts.map +1 -1
  8. package/dist/elements/PublishButton/ScheduleDrawer/index.js +52 -7
  9. package/dist/elements/PublishButton/ScheduleDrawer/index.js.map +1 -1
  10. package/dist/elements/PublishButton/ScheduleDrawer/types.d.ts +1 -0
  11. package/dist/elements/PublishButton/ScheduleDrawer/types.d.ts.map +1 -1
  12. package/dist/elements/PublishButton/ScheduleDrawer/types.js.map +1 -1
  13. package/dist/elements/Table/DefaultCell/fields/Blocks/index.d.ts.map +1 -1
  14. package/dist/elements/Table/DefaultCell/fields/Blocks/index.js +4 -11
  15. package/dist/elements/Table/DefaultCell/fields/Blocks/index.js.map +1 -1
  16. package/dist/elements/ViewDescription/index.d.ts +0 -1
  17. package/dist/elements/ViewDescription/index.d.ts.map +1 -1
  18. package/dist/elements/ViewDescription/index.js +1 -2
  19. package/dist/elements/ViewDescription/index.js.map +1 -1
  20. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.d.ts +2 -2
  21. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.d.ts.map +1 -1
  22. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.js +1 -0
  23. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.js.map +1 -1
  24. package/dist/elements/WhereBuilder/Condition/Relationship/index.d.ts.map +1 -1
  25. package/dist/elements/WhereBuilder/Condition/Relationship/index.js +59 -43
  26. package/dist/elements/WhereBuilder/Condition/Relationship/index.js.map +1 -1
  27. package/dist/elements/WhereBuilder/Condition/Select/index.d.ts.map +1 -1
  28. package/dist/elements/WhereBuilder/Condition/Select/index.js +2 -0
  29. package/dist/elements/WhereBuilder/Condition/Select/index.js.map +1 -1
  30. package/dist/elements/WhereBuilder/Condition/Select/types.d.ts +1 -0
  31. package/dist/elements/WhereBuilder/Condition/Select/types.d.ts.map +1 -1
  32. package/dist/elements/WhereBuilder/Condition/Select/types.js.map +1 -1
  33. package/dist/elements/WhereBuilder/Condition/index.d.ts +5 -16
  34. package/dist/elements/WhereBuilder/Condition/index.d.ts.map +1 -1
  35. package/dist/elements/WhereBuilder/Condition/index.js +114 -276
  36. package/dist/elements/WhereBuilder/Condition/index.js.map +1 -1
  37. package/dist/elements/WhereBuilder/Condition/types.d.ts +2 -2
  38. package/dist/elements/WhereBuilder/Condition/types.d.ts.map +1 -1
  39. package/dist/elements/WhereBuilder/Condition/types.js.map +1 -1
  40. package/dist/elements/WhereBuilder/field-types.d.ts +1 -92
  41. package/dist/elements/WhereBuilder/field-types.d.ts.map +1 -1
  42. package/dist/elements/WhereBuilder/field-types.js.map +1 -1
  43. package/dist/elements/WhereBuilder/index.d.ts.map +1 -1
  44. package/dist/elements/WhereBuilder/index.js +168 -259
  45. package/dist/elements/WhereBuilder/index.js.map +1 -1
  46. package/dist/elements/WhereBuilder/{reduceClientFields.d.ts → reduceFields.d.ts} +5 -4
  47. package/dist/elements/WhereBuilder/reduceFields.d.ts.map +1 -0
  48. package/dist/elements/WhereBuilder/{reduceClientFields.js → reduceFields.js} +8 -8
  49. package/dist/elements/WhereBuilder/reduceFields.js.map +1 -0
  50. package/dist/elements/WhereBuilder/types.d.ts +15 -2
  51. package/dist/elements/WhereBuilder/types.d.ts.map +1 -1
  52. package/dist/elements/WhereBuilder/types.js.map +1 -1
  53. package/dist/elements/WhereBuilder/validateWhereQuery.d.ts.map +1 -1
  54. package/dist/elements/WhereBuilder/validateWhereQuery.js.map +1 -1
  55. package/dist/exports/client/{CodeEditor-G3Y4UHC4.js → CodeEditor-BMYVMDNZ.js} +2 -2
  56. package/dist/exports/client/chunk-CQQHQHCB.js +26 -0
  57. package/dist/exports/client/{chunk-4L367VSB.js.map → chunk-CQQHQHCB.js.map} +3 -3
  58. package/dist/exports/client/index.js +23 -23
  59. package/dist/exports/client/index.js.map +4 -4
  60. package/dist/exports/shared/index.js +2 -2
  61. package/dist/exports/shared/index.js.map +4 -4
  62. package/dist/fields/Blocks/BlockRow.d.ts +1 -1
  63. package/dist/fields/Blocks/BlockRow.d.ts.map +1 -1
  64. package/dist/fields/Blocks/BlockRow.js.map +1 -1
  65. package/dist/fields/Blocks/BlocksDrawer/index.d.ts +1 -1
  66. package/dist/fields/Blocks/BlocksDrawer/index.d.ts.map +1 -1
  67. package/dist/fields/Blocks/BlocksDrawer/index.js +23 -31
  68. package/dist/fields/Blocks/BlocksDrawer/index.js.map +1 -1
  69. package/dist/fields/Blocks/RowActions.d.ts +1 -1
  70. package/dist/fields/Blocks/RowActions.d.ts.map +1 -1
  71. package/dist/fields/Blocks/RowActions.js.map +1 -1
  72. package/dist/fields/Blocks/index.d.ts.map +1 -1
  73. package/dist/fields/Blocks/index.js +4 -6
  74. package/dist/fields/Blocks/index.js.map +1 -1
  75. package/dist/fields/Join/index.d.ts.map +1 -1
  76. package/dist/fields/Join/index.js +2 -9
  77. package/dist/fields/Join/index.js.map +1 -1
  78. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.d.ts.map +1 -1
  79. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js +1 -2
  80. package/dist/forms/fieldSchemasToFormState/addFieldStatePromise.js.map +1 -1
  81. package/dist/forms/fieldSchemasToFormState/calculateDefaultValues/promise.d.ts.map +1 -1
  82. package/dist/forms/fieldSchemasToFormState/calculateDefaultValues/promise.js +1 -1
  83. package/dist/forms/fieldSchemasToFormState/calculateDefaultValues/promise.js.map +1 -1
  84. package/dist/forms/fieldSchemasToFormState/renderField.d.ts.map +1 -1
  85. package/dist/forms/fieldSchemasToFormState/renderField.js +1 -2
  86. package/dist/forms/fieldSchemasToFormState/renderField.js.map +1 -1
  87. package/dist/providers/Config/index.d.ts +2 -2
  88. package/dist/providers/Config/index.d.ts.map +1 -1
  89. package/dist/providers/Config/index.js +2 -17
  90. package/dist/providers/Config/index.js.map +1 -1
  91. package/dist/providers/DocumentInfo/index.d.ts.map +1 -1
  92. package/dist/providers/DocumentInfo/index.js +11 -2
  93. package/dist/providers/DocumentInfo/index.js.map +1 -1
  94. package/dist/styles.css +1 -1
  95. package/dist/utilities/buildClientFieldSchemaMap/traverseFields.d.ts.map +1 -1
  96. package/dist/utilities/buildClientFieldSchemaMap/traverseFields.js +1 -3
  97. package/dist/utilities/buildClientFieldSchemaMap/traverseFields.js.map +1 -1
  98. package/dist/utilities/buildFieldSchemaMap/traverseFields.d.ts.map +1 -1
  99. package/dist/utilities/buildFieldSchemaMap/traverseFields.js +1 -4
  100. package/dist/utilities/buildFieldSchemaMap/traverseFields.js.map +1 -1
  101. package/dist/utilities/copyDataFromLocale.d.ts.map +1 -1
  102. package/dist/utilities/copyDataFromLocale.js +15 -13
  103. package/dist/utilities/copyDataFromLocale.js.map +1 -1
  104. package/dist/utilities/formatDate.d.ts +2 -1
  105. package/dist/utilities/formatDate.d.ts.map +1 -1
  106. package/dist/utilities/formatDate.js +15 -3
  107. package/dist/utilities/formatDate.js.map +1 -1
  108. package/dist/utilities/getClientConfig.js.map +1 -1
  109. package/dist/utilities/schedulePublishHandler.d.ts +2 -1
  110. package/dist/utilities/schedulePublishHandler.d.ts.map +1 -1
  111. package/dist/utilities/schedulePublishHandler.js +3 -1
  112. package/dist/utilities/schedulePublishHandler.js.map +1 -1
  113. package/package.json +5 -5
  114. package/dist/elements/ViewDescription/index.scss +0 -7
  115. package/dist/elements/WhereBuilder/reduceClientFields.d.ts.map +0 -1
  116. package/dist/elements/WhereBuilder/reduceClientFields.js.map +0 -1
  117. package/dist/exports/client/chunk-4L367VSB.js +0 -26
  118. /package/dist/exports/client/{CodeEditor-G3Y4UHC4.js.map → CodeEditor-BMYVMDNZ.js.map} +0 -0
@@ -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 }\n }}\n >\n {t('general:addFilter')}\n </Button>\n </div>\n )}\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,cAAc,QAAQ;AAC/B,OAAOC,KAAA,IAASC,SAAS,EAAEC,QAAQ,QAAQ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E,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;AAI/B,SAASC,YAAY,QAAQ;AAC7B,SAASC,cAAc,QAAQ;AAC/B,SAASC,MAAM,QAAQ;AACvB,SAASC,SAAS,QAAQ;AAC1B,OAAOC,UAAA,MAAgB;AACvB,SAASC,YAAY,QAAQ;AAC7B,SAASC,mBAAmB,QAAQ;AAC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
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"}
@@ -9,7 +9,7 @@ import fieldTypes from './field-types.js';
9
9
  * Reduces a field map to a flat array of fields with labels and values.
10
10
  * Used in the WhereBuilder component to render the fields in the dropdown.
11
11
  */
12
- export const reduceClientFields = ({
12
+ export const reduceFields = ({
13
13
  fields,
14
14
  i18n,
15
15
  labelPrefix,
@@ -29,7 +29,7 @@ export const reduceClientFields = ({
29
29
  // Make sure we handle nested tabs
30
30
  const tabPathPrefix = tabHasName(tab) && tab.name ? pathPrefix ? pathPrefix + '.' + tab.name : tab.name : pathPrefix;
31
31
  if (typeof localizedTabLabel === 'string') {
32
- reduced.push(...reduceClientFields({
32
+ reduced.push(...reduceFields({
33
33
  fields: tab.fields,
34
34
  i18n,
35
35
  labelPrefix: labelWithPrefix,
@@ -42,7 +42,7 @@ export const reduceClientFields = ({
42
42
  }
43
43
  // Rows cant have labels, so we need to handle them differently
44
44
  if (field.type === 'row' && 'fields' in field) {
45
- reduced.push(...reduceClientFields({
45
+ reduced.push(...reduceFields({
46
46
  fields: field.fields,
47
47
  i18n,
48
48
  labelPrefix,
@@ -53,7 +53,7 @@ export const reduceClientFields = ({
53
53
  if (field.type === 'collapsible' && 'fields' in field) {
54
54
  const localizedTabLabel = getTranslation(field.label || '', i18n);
55
55
  const labelWithPrefix = labelPrefix ? labelPrefix + ' > ' + localizedTabLabel : localizedTabLabel;
56
- reduced.push(...reduceClientFields({
56
+ reduced.push(...reduceFields({
57
57
  fields: field.fields,
58
58
  i18n,
59
59
  labelPrefix: labelWithPrefix,
@@ -66,7 +66,7 @@ export const reduceClientFields = ({
66
66
  const labelWithPrefix = labelPrefix ? translatedLabel ? labelPrefix + ' > ' + translatedLabel : labelPrefix : translatedLabel;
67
67
  // Make sure we handle deeply nested groups
68
68
  const pathWithPrefix = field.name ? pathPrefix ? pathPrefix + '.' + field.name : field.name : pathPrefix;
69
- reduced.push(...reduceClientFields({
69
+ reduced.push(...reduceFields({
70
70
  fields: field.fields,
71
71
  i18n,
72
72
  labelPrefix: labelWithPrefix,
@@ -92,10 +92,10 @@ export const reduceClientFields = ({
92
92
  field,
93
93
  prefix: labelPrefix
94
94
  }) : localizedLabel;
95
- const formattedValue = pathPrefix ? createNestedClientFieldPath(pathPrefix, field) : field.name;
95
+ const fieldPath = pathPrefix ? createNestedClientFieldPath(pathPrefix, field) : field.name;
96
96
  const formattedField = {
97
97
  label: formattedLabel,
98
- value: formattedValue,
98
+ value: fieldPath,
99
99
  ...fieldTypes[field.type],
100
100
  field,
101
101
  operators
@@ -106,4 +106,4 @@ export const reduceClientFields = ({
106
106
  return reduced;
107
107
  }, []);
108
108
  };
109
- //# sourceMappingURL=reduceClientFields.js.map
109
+ //# sourceMappingURL=reduceFields.js.map