@payloadcms/ui 3.0.0-beta.58 → 3.0.0-beta.59

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.
@@ -20,13 +20,18 @@ const baseClass = 'where-builder';
20
20
  const { collectionPluralLabel, fieldMap } = props;
21
21
  const { i18n, t } = useTranslation();
22
22
  const { code: currentLocale } = useLocale();
23
- const [reducedFields, setReducedColumns] = useState(()=>reduceFieldMap(fieldMap, i18n));
23
+ const [reducedFields, setReducedColumns] = useState(()=>reduceFieldMap({
24
+ fieldMap,
25
+ i18n
26
+ }));
24
27
  useEffect(()=>{
25
- setReducedColumns(reduceFieldMap(fieldMap, i18n, undefined, undefined, currentLocale));
28
+ setReducedColumns(reduceFieldMap({
29
+ fieldMap,
30
+ i18n
31
+ }));
26
32
  }, [
27
33
  fieldMap,
28
- i18n,
29
- currentLocale
34
+ i18n
30
35
  ]);
31
36
  const { searchParams } = useSearchParams();
32
37
  const { handleWhereChange } = useListQuery();
@@ -1 +1 @@
1
- {"version":3,"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 { useLocale } from '../../providers/Locale/index.js'\nimport { useSearchParams } from '../../providers/SearchParams/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { Button } from '../Button/index.js'\nimport { Condition } from './Condition/index.js'\nimport './index.scss'\nimport { reduceFieldMap } from './reduceFieldMap.js'\nimport { transformWhereQuery } from './transformWhereQuery.js'\nimport validateWhereQuery from './validateWhereQuery.js'\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, fieldMap } = props\n const { i18n, t } = useTranslation()\n const { code: currentLocale } = useLocale()\n\n const [reducedFields, setReducedColumns] = useState(() => reduceFieldMap(fieldMap, i18n))\n\n useEffect(() => {\n setReducedColumns(reduceFieldMap(fieldMap, i18n, undefined, undefined, currentLocale))\n }, [fieldMap, i18n, currentLocale])\n\n const { searchParams } = useSearchParams()\n const { handleWhereChange } = 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 = searchParams.where\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)}`)\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 conditions[orIndex].and[andIndex] = newRowCondition\n setConditions(conditions)\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 handleWhereChange({ or: conditions })\n setShouldUpdateQuery(false)\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 ] || ''\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 fields={reducedFields}\n initialValue={initialValue}\n operator={initialOperator}\n orIndex={orIndex}\n removeCondition={removeCondition}\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: reducedFields[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 (reducedFields.length > 0) {\n addCondition({\n andIndex: 0,\n fieldName: reducedFields[0].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"],"names":["getTranslation","React","useEffect","useState","useListQuery","useLocale","useSearchParams","useTranslation","Button","Condition","reduceFieldMap","transformWhereQuery","validateWhereQuery","baseClass","WhereBuilder","props","collectionPluralLabel","fieldMap","i18n","t","code","currentLocale","reducedFields","setReducedColumns","undefined","searchParams","handleWhereChange","shouldUpdateQuery","setShouldUpdateQuery","conditions","setConditions","whereFromSearch","where","or","transformedWhere","console","warn","JSON","stringify","addCondition","useCallback","andIndex","fieldName","orIndex","relation","newConditions","and","splice","push","updateCondition","operator","value","valueArg","existingRowCondition","newRowCondition","includes","removeCondition","length","div","className","Fragment","label","ul","map","compoundOrKey","Array","isArray","li","_","initialFieldName","Object","keys","initialOperator","initialValue","fields","buttonStyle","icon","iconPosition","iconStyle","onClick"],"mappings":"AAAA;;AAGA,SAASA,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AAIC,WAAW,CAAC,EAAE9C,UAAU,OAAO,CAAC;kCAAGM,EAAE;;kCAC1C,KAACX;wBACCmE,aAAY;wBACZhB,WAAW,CAAC,EAAE9C,UAAU,kBAAkB,CAAC;wBAC3C+D,MAAK;wBACLC,cAAa;wBACbC,WAAU;wBACVC,SAAS;4BACP,IAAIzD,cAAcmC,MAAM,GAAG,GAAG;gCAC5BlB,aAAa;oCACXE,UAAU;oCACVC,WAAWpB,aAAa,CAAC,EAAE,CAAC6B,KAAK;oCACjCR,SAASd,WAAW4B,MAAM;oCAC1Bb,UAAU;gCACZ;4BACF;wBACF;kCAECzB,EAAE;;;;;;AAMf,EAAC"}
1
+ {"version":3,"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 { useLocale } from '../../providers/Locale/index.js'\nimport { useSearchParams } from '../../providers/SearchParams/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { Button } from '../Button/index.js'\nimport { Condition } from './Condition/index.js'\nimport './index.scss'\nimport { reduceFieldMap } from './reduceFieldMap.js'\nimport { transformWhereQuery } from './transformWhereQuery.js'\nimport validateWhereQuery from './validateWhereQuery.js'\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, fieldMap } = props\n const { i18n, t } = useTranslation()\n const { code: currentLocale } = useLocale()\n\n const [reducedFields, setReducedColumns] = useState(() => reduceFieldMap({ fieldMap, i18n }))\n\n useEffect(() => {\n setReducedColumns(reduceFieldMap({ fieldMap, i18n }))\n }, [fieldMap, i18n])\n\n const { searchParams } = useSearchParams()\n const { handleWhereChange } = 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 = searchParams.where\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)}`)\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 conditions[orIndex].and[andIndex] = newRowCondition\n setConditions(conditions)\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 handleWhereChange({ or: conditions })\n setShouldUpdateQuery(false)\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 ] || ''\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 fields={reducedFields}\n initialValue={initialValue}\n operator={initialOperator}\n orIndex={orIndex}\n removeCondition={removeCondition}\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: reducedFields[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 (reducedFields.length > 0) {\n addCondition({\n andIndex: 0,\n fieldName: reducedFields[0].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"],"names":["getTranslation","React","useEffect","useState","useListQuery","useLocale","useSearchParams","useTranslation","Button","Condition","reduceFieldMap","transformWhereQuery","validateWhereQuery","baseClass","WhereBuilder","props","collectionPluralLabel","fieldMap","i18n","t","code","currentLocale","reducedFields","setReducedColumns","searchParams","handleWhereChange","shouldUpdateQuery","setShouldUpdateQuery","conditions","setConditions","whereFromSearch","where","or","transformedWhere","console","warn","JSON","stringify","addCondition","useCallback","andIndex","fieldName","orIndex","relation","newConditions","and","splice","push","updateCondition","operator","value","valueArg","existingRowCondition","newRowCondition","undefined","includes","removeCondition","length","div","className","Fragment","label","ul","map","compoundOrKey","Array","isArray","li","_","initialFieldName","Object","keys","initialOperator","initialValue","fields","buttonStyle","icon","iconPosition","iconStyle","onClick"],"mappings":"AAAA;;AAGA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAIlD,SAASC,YAAY,QAAQ,qCAAoC;AACjE,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,eAAe,QAAQ,wCAAuC;AACvE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,MAAM,QAAQ,qBAAo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Aa;oCACXE,UAAU;oCACVC,WAAWnB,aAAa,CAAC,EAAE,CAAC4B,KAAK;oCACjCR,SAASd,WAAW6B,MAAM;oCAC1Bd,UAAU;gCACZ;4BACF;wBACF;kCAECxB,EAAE;;;;;;AAMf,EAAC"}
@@ -1,3 +1,14 @@
1
+ import type { I18nClient } from '@payloadcms/translations';
1
2
  import type { FieldMap } from '../../utilities/buildComponentMap.js';
2
- export declare const reduceFieldMap: (fieldMap: FieldMap, i18n: any, labelPrefix?: string, pathPrefix?: string, locale?: string) => any[];
3
+ export type ReduceFieldMapArgs = {
4
+ fieldMap: FieldMap;
5
+ i18n: I18nClient;
6
+ labelPrefix?: string;
7
+ pathPrefix?: string;
8
+ };
9
+ /**
10
+ * Reduces a field map to a flat array of fields with labels and values.
11
+ * Used in the WhereBuilder component to render the fields in the dropdown.
12
+ */
13
+ export declare const reduceFieldMap: ({ fieldMap, i18n, labelPrefix, pathPrefix }: ReduceFieldMapArgs) => any[];
3
14
  //# sourceMappingURL=reduceFieldMap.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reduceFieldMap.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/reduceFieldMap.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AAMpE,eAAO,MAAM,cAAc,aACf,QAAQ,2BAEJ,MAAM,eACP,MAAM,WACV,MAAM,UAyEhB,CAAA"}
1
+ {"version":3,"file":"reduceFieldMap.d.ts","sourceRoot":"","sources":["../../../src/elements/WhereBuilder/reduceFieldMap.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAyB,UAAU,EAAG,MAAM,0BAA0B,CAAA;AAIlF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sCAAsC,CAAA;AAMpE,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,EAAE,QAAQ,CAAA;IAClB,IAAI,EAAE,UAAU,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,UAAU,CAAC,EAAE,MAAM,CAAA;CACpB,CAAA;AAED;;;GAGG;AACH,eAAO,MAAM,cAAc,gDAAiD,kBAAkB,UAwI7F,CAAA"}
@@ -1,21 +1,66 @@
1
1
  'use client';
2
+ import { getTranslation } from '@payloadcms/translations';
2
3
  import { createNestedClientFieldPath } from '../../forms/Form/createNestedFieldPath.js';
3
4
  import { combineLabel } from '../FieldSelect/index.js';
4
5
  import fieldTypes from './field-types.js';
5
- export const reduceFieldMap = (fieldMap, i18n, labelPrefix, pathPrefix, locale)=>{
6
+ /**
7
+ * Reduces a field map to a flat array of fields with labels and values.
8
+ * Used in the WhereBuilder component to render the fields in the dropdown.
9
+ */ export const reduceFieldMap = ({ fieldMap, i18n, labelPrefix, pathPrefix })=>{
6
10
  return fieldMap.reduce((reduced, field)=>{
7
11
  if (field.disableListFilter) return reduced;
8
12
  if (field.type === 'tabs' && 'tabs' in field.fieldComponentProps) {
9
13
  const tabs = field.fieldComponentProps.tabs;
10
14
  tabs.forEach((tab)=>{
11
- if (tab.name && typeof tab.label === 'string' && tab.fieldMap) {
12
- reduced.push(...reduceFieldMap(tab.fieldMap, i18n, tab.label, tab.name));
15
+ if (typeof tab.label !== 'boolean') {
16
+ const localizedTabLabel = getTranslation(tab.label, i18n);
17
+ const labelWithPrefix = labelPrefix ? labelPrefix + ' > ' + localizedTabLabel : localizedTabLabel;
18
+ // Make sure we handle nested tabs
19
+ const tabPathPrefix = tab.name ? pathPrefix ? pathPrefix + '.' + tab.name : tab.name : pathPrefix;
20
+ if (typeof localizedTabLabel === 'string') {
21
+ reduced.push(...reduceFieldMap({
22
+ fieldMap: tab.fieldMap,
23
+ i18n,
24
+ labelPrefix: labelWithPrefix,
25
+ pathPrefix: tabPathPrefix
26
+ }));
27
+ }
13
28
  }
14
29
  });
15
30
  return reduced;
16
31
  }
32
+ // Rows cant have labels, so we need to handle them differently
33
+ if (field.type === 'row' && 'fieldMap' in field.fieldComponentProps) {
34
+ reduced.push(...reduceFieldMap({
35
+ fieldMap: field.fieldComponentProps.fieldMap,
36
+ i18n,
37
+ labelPrefix,
38
+ pathPrefix
39
+ }));
40
+ return reduced;
41
+ }
42
+ if (field.type === 'collapsible' && 'fieldMap' in field.fieldComponentProps) {
43
+ const localizedTabLabel = getTranslation(field.fieldComponentProps.label, i18n);
44
+ const labelWithPrefix = labelPrefix ? labelPrefix + ' > ' + localizedTabLabel : localizedTabLabel;
45
+ reduced.push(...reduceFieldMap({
46
+ fieldMap: field.fieldComponentProps.fieldMap,
47
+ i18n,
48
+ labelPrefix: labelWithPrefix,
49
+ pathPrefix
50
+ }));
51
+ return reduced;
52
+ }
17
53
  if (field.type === 'group' && 'fieldMap' in field.fieldComponentProps) {
18
- reduced.push(...reduceFieldMap(field.fieldComponentProps.fieldMap, i18n, field.fieldComponentProps.label, field.name));
54
+ const translatedLabel = getTranslation(field.fieldComponentProps.label, i18n);
55
+ const labelWithPrefix = labelPrefix ? translatedLabel ? labelPrefix + ' > ' + translatedLabel : labelPrefix : translatedLabel;
56
+ // Make sure we handle deeply nested groups
57
+ const pathWithPrefix = field.name ? pathPrefix ? pathPrefix + '.' + field.name : field.name : pathPrefix;
58
+ reduced.push(...reduceFieldMap({
59
+ fieldMap: field.fieldComponentProps.fieldMap,
60
+ i18n,
61
+ labelPrefix: labelWithPrefix,
62
+ pathPrefix: pathWithPrefix
63
+ }));
19
64
  return reduced;
20
65
  }
21
66
  if (typeof fieldTypes[field.type] === 'object') {
@@ -23,14 +68,15 @@ export const reduceFieldMap = (fieldMap, i18n, labelPrefix, pathPrefix, locale)=
23
68
  const operators = fieldTypes[field.type].operators.reduce((acc, operator)=>{
24
69
  if (!operatorKeys.has(operator.value)) {
25
70
  operatorKeys.add(operator.value);
71
+ const operatorKey = `operators:${operator.label}`;
26
72
  acc.push({
27
73
  ...operator,
28
- label: i18n.t(`operators:${operator.label}`)
74
+ label: i18n.t(operatorKey)
29
75
  });
30
76
  }
31
77
  return acc;
32
78
  }, []);
33
- const localizedLabel = locale && typeof field.fieldComponentProps.label === 'object' ? field.fieldComponentProps.label[locale] : field.fieldComponentProps.label;
79
+ const localizedLabel = getTranslation(field.fieldComponentProps.label, i18n);
34
80
  const formattedLabel = labelPrefix ? combineLabel({
35
81
  field,
36
82
  prefix: labelPrefix
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/elements/WhereBuilder/reduceFieldMap.tsx"],"sourcesContent":["'use client'\nimport type { FieldMap } from '../../utilities/buildComponentMap.js'\n\nimport { createNestedClientFieldPath } from '../../forms/Form/createNestedFieldPath.js'\nimport { combineLabel } from '../FieldSelect/index.js'\nimport fieldTypes from './field-types.js'\n\nexport const reduceFieldMap = (\n fieldMap: FieldMap,\n i18n,\n labelPrefix?: string,\n pathPrefix?: string,\n locale?: string,\n) => {\n return fieldMap.reduce((reduced, field) => {\n if (field.disableListFilter) return reduced\n\n if (field.type === 'tabs' && 'tabs' in field.fieldComponentProps) {\n const tabs = field.fieldComponentProps.tabs\n tabs.forEach((tab) => {\n if (tab.name && typeof tab.label === 'string' && tab.fieldMap) {\n reduced.push(...reduceFieldMap(tab.fieldMap, i18n, tab.label, tab.name))\n }\n })\n return reduced\n }\n\n if (field.type === 'group' && 'fieldMap' in field.fieldComponentProps) {\n reduced.push(\n ...reduceFieldMap(\n field.fieldComponentProps.fieldMap,\n i18n,\n field.fieldComponentProps.label as string,\n field.name,\n ),\n )\n return reduced\n }\n\n if (typeof fieldTypes[field.type] === 'object') {\n const operatorKeys = new Set()\n const operators = fieldTypes[field.type].operators.reduce((acc, operator) => {\n if (!operatorKeys.has(operator.value)) {\n operatorKeys.add(operator.value)\n acc.push({\n ...operator,\n label: i18n.t(`operators:${operator.label}`),\n })\n }\n return acc\n }, [])\n\n const localizedLabel =\n locale && typeof field.fieldComponentProps.label === 'object'\n ? field.fieldComponentProps.label[locale]\n : field.fieldComponentProps.label\n\n const formattedLabel = labelPrefix\n ? combineLabel({\n field,\n prefix: labelPrefix,\n })\n : localizedLabel\n\n const formattedValue = pathPrefix\n ? createNestedClientFieldPath(pathPrefix, field)\n : field.name\n\n const formattedField = {\n label: formattedLabel,\n value: formattedValue,\n ...fieldTypes[field.type],\n operators,\n props: {\n ...field,\n ...(field?.cellComponentProps || {}),\n },\n }\n\n reduced.push(formattedField)\n return reduced\n }\n\n return reduced\n }, [])\n}\n"],"names":["createNestedClientFieldPath","combineLabel","fieldTypes","reduceFieldMap","fieldMap","i18n","labelPrefix","pathPrefix","locale","reduce","reduced","field","disableListFilter","type","fieldComponentProps","tabs","forEach","tab","name","label","push","operatorKeys","Set","operators","acc","operator","has","value","add","t","localizedLabel","formattedLabel","prefix","formattedValue","formattedField","props","cellComponentProps"],"mappings":"AAAA;AAGA,SAASA,2BAA2B,QAAQ,4CAA2C;AACvF,SAASC,YAAY,QAAQ,0BAAyB;AACtD,OAAOC,gBAAgB,mBAAkB;AAEzC,OAAO,MAAMC,iBAAiB,CAC5BC,UACAC,MACAC,aACAC,YACAC;IAEA,OAAOJ,SAASK,MAAM,CAAC,CAACC,SAASC;QAC/B,IAAIA,MAAMC,iBAAiB,EAAE,OAAOF;QAEpC,IAAIC,MAAME,IAAI,KAAK,UAAU,UAAUF,MAAMG,mBAAmB,EAAE;YAChE,MAAMC,OAAOJ,MAAMG,mBAAmB,CAACC,IAAI;YAC3CA,KAAKC,OAAO,CAAC,CAACC;gBACZ,IAAIA,IAAIC,IAAI,IAAI,OAAOD,IAAIE,KAAK,KAAK,YAAYF,IAAIb,QAAQ,EAAE;oBAC7DM,QAAQU,IAAI,IAAIjB,eAAec,IAAIb,QAAQ,EAAEC,MAAMY,IAAIE,KAAK,EAAEF,IAAIC,IAAI;gBACxE;YACF;YACA,OAAOR;QACT;QAEA,IAAIC,MAAME,IAAI,KAAK,WAAW,cAAcF,MAAMG,mBAAmB,EAAE;YACrEJ,QAAQU,IAAI,IACPjB,eACDQ,MAAMG,mBAAmB,CAACV,QAAQ,EAClCC,MACAM,MAAMG,mBAAmB,CAACK,KAAK,EAC/BR,MAAMO,IAAI;YAGd,OAAOR;QACT;QAEA,IAAI,OAAOR,UAAU,CAACS,MAAME,IAAI,CAAC,KAAK,UAAU;YAC9C,MAAMQ,eAAe,IAAIC;YACzB,MAAMC,YAAYrB,UAAU,CAACS,MAAME,IAAI,CAAC,CAACU,SAAS,CAACd,MAAM,CAAC,CAACe,KAAKC;gBAC9D,IAAI,CAACJ,aAAaK,GAAG,CAACD,SAASE,KAAK,GAAG;oBACrCN,aAAaO,GAAG,CAACH,SAASE,KAAK;oBAC/BH,IAAIJ,IAAI,CAAC;wBACP,GAAGK,QAAQ;wBACXN,OAAOd,KAAKwB,CAAC,CAAC,CAAC,UAAU,EAAEJ,SAASN,KAAK,CAAC,CAAC;oBAC7C;gBACF;gBACA,OAAOK;YACT,GAAG,EAAE;YAEL,MAAMM,iBACJtB,UAAU,OAAOG,MAAMG,mBAAmB,CAACK,KAAK,KAAK,WACjDR,MAAMG,mBAAmB,CAACK,KAAK,CAACX,OAAO,GACvCG,MAAMG,mBAAmB,CAACK,KAAK;YAErC,MAAMY,iBAAiBzB,cACnBL,aAAa;gBACXU;gBACAqB,QAAQ1B;YACV,KACAwB;YAEJ,MAAMG,iBAAiB1B,aACnBP,4BAA4BO,YAAYI,SACxCA,MAAMO,IAAI;YAEd,MAAMgB,iBAAiB;gBACrBf,OAAOY;gBACPJ,OAAOM;gBACP,GAAG/B,UAAU,CAACS,MAAME,IAAI,CAAC;gBACzBU;gBACAY,OAAO;oBACL,GAAGxB,KAAK;oBACR,GAAIA,OAAOyB,sBAAsB,CAAC,CAAC;gBACrC;YACF;YAEA1B,QAAQU,IAAI,CAACc;YACb,OAAOxB;QACT;QAEA,OAAOA;IACT,GAAG,EAAE;AACP,EAAC"}
1
+ {"version":3,"sources":["../../../src/elements/WhereBuilder/reduceFieldMap.tsx"],"sourcesContent":["'use client'\nimport type { ClientTranslationKeys, I18nClient } from '@payloadcms/translations'\n\nimport { getTranslation } from '@payloadcms/translations';\n\nimport type { FieldMap } from '../../utilities/buildComponentMap.js'\n\nimport { createNestedClientFieldPath } from '../../forms/Form/createNestedFieldPath.js'\nimport { combineLabel } from '../FieldSelect/index.js'\nimport fieldTypes from './field-types.js'\n\nexport type ReduceFieldMapArgs = {\n fieldMap: FieldMap\n i18n: I18nClient\n labelPrefix?: string\n pathPrefix?: string\n}\n\n/**\n * Reduces a field map to a flat array of fields with labels and values.\n * Used in the WhereBuilder component to render the fields in the dropdown.\n */\nexport const reduceFieldMap = ({ fieldMap, i18n, labelPrefix, pathPrefix }: ReduceFieldMapArgs) => {\n return fieldMap.reduce((reduced, field) => {\n if (field.disableListFilter) return reduced\n\n if (field.type === 'tabs' && 'tabs' in field.fieldComponentProps) {\n const tabs = field.fieldComponentProps.tabs\n tabs.forEach((tab) => {\n if (typeof tab.label !== 'boolean') {\n const localizedTabLabel = getTranslation(tab.label, i18n)\n const labelWithPrefix = labelPrefix\n ? labelPrefix + ' > ' + localizedTabLabel\n : localizedTabLabel\n\n // Make sure we handle nested tabs\n const tabPathPrefix = tab.name\n ? pathPrefix\n ? pathPrefix + '.' + tab.name\n : tab.name\n : pathPrefix\n\n if (typeof localizedTabLabel === 'string') {\n reduced.push(\n ...reduceFieldMap({\n fieldMap: tab.fieldMap,\n i18n,\n labelPrefix: labelWithPrefix,\n pathPrefix: tabPathPrefix,\n }),\n )\n }\n }\n })\n return reduced\n }\n\n // Rows cant have labels, so we need to handle them differently\n if (field.type === 'row' && 'fieldMap' in field.fieldComponentProps) {\n reduced.push(\n ...reduceFieldMap({\n fieldMap: field.fieldComponentProps.fieldMap,\n i18n,\n labelPrefix,\n pathPrefix,\n }),\n )\n return reduced\n }\n\n if (field.type === 'collapsible' && 'fieldMap' in field.fieldComponentProps) {\n const localizedTabLabel = getTranslation(field.fieldComponentProps.label, i18n)\n const labelWithPrefix = labelPrefix\n ? labelPrefix + ' > ' + localizedTabLabel\n : localizedTabLabel\n\n reduced.push(\n ...reduceFieldMap({\n fieldMap: field.fieldComponentProps.fieldMap,\n i18n,\n labelPrefix: labelWithPrefix,\n pathPrefix,\n }),\n )\n return reduced\n }\n\n if (field.type === 'group' && 'fieldMap' in field.fieldComponentProps) {\n const translatedLabel = getTranslation(field.fieldComponentProps.label, i18n)\n\n const labelWithPrefix = labelPrefix\n ? translatedLabel\n ? labelPrefix + ' > ' + translatedLabel\n : labelPrefix\n : translatedLabel\n\n // Make sure we handle deeply nested groups\n const pathWithPrefix = field.name\n ? pathPrefix\n ? pathPrefix + '.' + field.name\n : field.name\n : pathPrefix\n\n reduced.push(\n ...reduceFieldMap({\n fieldMap: field.fieldComponentProps.fieldMap,\n i18n,\n labelPrefix: labelWithPrefix,\n pathPrefix: pathWithPrefix,\n }),\n )\n return reduced\n }\n\n if (typeof fieldTypes[field.type] === 'object') {\n const operatorKeys = new Set()\n const operators = fieldTypes[field.type].operators.reduce((acc, operator) => {\n if (!operatorKeys.has(operator.value)) {\n operatorKeys.add(operator.value)\n const operatorKey = `operators:${operator.label}` as ClientTranslationKeys\n acc.push({\n ...operator,\n label: i18n.t(operatorKey),\n })\n }\n return acc\n }, [])\n\n const localizedLabel = getTranslation(field.fieldComponentProps.label, i18n)\n\n const formattedLabel = labelPrefix\n ? combineLabel({\n field,\n prefix: labelPrefix,\n })\n : localizedLabel\n\n const formattedValue = pathPrefix\n ? createNestedClientFieldPath(pathPrefix, field)\n : field.name\n\n const formattedField = {\n label: formattedLabel,\n value: formattedValue,\n ...fieldTypes[field.type],\n operators,\n props: {\n ...field,\n ...(field?.cellComponentProps || {}),\n },\n }\n\n reduced.push(formattedField)\n return reduced\n }\n\n return reduced\n }, [])\n}\n"],"names":["getTranslation","createNestedClientFieldPath","combineLabel","fieldTypes","reduceFieldMap","fieldMap","i18n","labelPrefix","pathPrefix","reduce","reduced","field","disableListFilter","type","fieldComponentProps","tabs","forEach","tab","label","localizedTabLabel","labelWithPrefix","tabPathPrefix","name","push","translatedLabel","pathWithPrefix","operatorKeys","Set","operators","acc","operator","has","value","add","operatorKey","t","localizedLabel","formattedLabel","prefix","formattedValue","formattedField","props","cellComponentProps"],"mappings":"AAAA;AAGA,SAASA,cAAc,QAAQ,2BAA2B;AAI1D,SAASC,2BAA2B,QAAQ,4CAA2C;AACvF,SAASC,YAAY,QAAQ,0BAAyB;AACtD,OAAOC,gBAAgB,mBAAkB;AASzC;;;CAGC,GACD,OAAO,MAAMC,iBAAiB,CAAC,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,WAAW,EAAEC,UAAU,EAAsB;IAC5F,OAAOH,SAASI,MAAM,CAAC,CAACC,SAASC;QAC/B,IAAIA,MAAMC,iBAAiB,EAAE,OAAOF;QAEpC,IAAIC,MAAME,IAAI,KAAK,UAAU,UAAUF,MAAMG,mBAAmB,EAAE;YAChE,MAAMC,OAAOJ,MAAMG,mBAAmB,CAACC,IAAI;YAC3CA,KAAKC,OAAO,CAAC,CAACC;gBACZ,IAAI,OAAOA,IAAIC,KAAK,KAAK,WAAW;oBAClC,MAAMC,oBAAoBnB,eAAeiB,IAAIC,KAAK,EAAEZ;oBACpD,MAAMc,kBAAkBb,cACpBA,cAAc,QAAQY,oBACtBA;oBAEJ,kCAAkC;oBAClC,MAAME,gBAAgBJ,IAAIK,IAAI,GAC1Bd,aACEA,aAAa,MAAMS,IAAIK,IAAI,GAC3BL,IAAIK,IAAI,GACVd;oBAEJ,IAAI,OAAOW,sBAAsB,UAAU;wBACzCT,QAAQa,IAAI,IACPnB,eAAe;4BAChBC,UAAUY,IAAIZ,QAAQ;4BACtBC;4BACAC,aAAaa;4BACbZ,YAAYa;wBACd;oBAEJ;gBACF;YACF;YACA,OAAOX;QACT;QAEA,+DAA+D;QAC/D,IAAIC,MAAME,IAAI,KAAK,SAAS,cAAcF,MAAMG,mBAAmB,EAAE;YACnEJ,QAAQa,IAAI,IACPnB,eAAe;gBAChBC,UAAUM,MAAMG,mBAAmB,CAACT,QAAQ;gBAC5CC;gBACAC;gBACAC;YACF;YAEF,OAAOE;QACT;QAEA,IAAIC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