@payloadcms/ui 3.78.0-canary.1 → 3.78.0-canary.2

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 (41) hide show
  1. package/dist/elements/GroupByBuilder/index.d.ts +4 -1
  2. package/dist/elements/GroupByBuilder/index.d.ts.map +1 -1
  3. package/dist/elements/GroupByBuilder/index.js +81 -39
  4. package/dist/elements/GroupByBuilder/index.js.map +1 -1
  5. package/dist/elements/QueryPresets/fields/ColumnsField/index.d.ts.map +1 -1
  6. package/dist/elements/QueryPresets/fields/ColumnsField/index.js +100 -37
  7. package/dist/elements/QueryPresets/fields/ColumnsField/index.js.map +1 -1
  8. package/dist/elements/QueryPresets/fields/GroupByField/index.d.ts.map +1 -1
  9. package/dist/elements/QueryPresets/fields/GroupByField/index.js +24 -48
  10. package/dist/elements/QueryPresets/fields/GroupByField/index.js.map +1 -1
  11. package/dist/elements/QueryPresets/fields/WhereField/index.d.ts.map +1 -1
  12. package/dist/elements/QueryPresets/fields/WhereField/index.js +73 -94
  13. package/dist/elements/QueryPresets/fields/WhereField/index.js.map +1 -1
  14. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.d.ts +1 -1
  15. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.d.ts.map +1 -1
  16. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.js +2 -2
  17. package/dist/elements/WhereBuilder/Condition/DefaultFilter/index.js.map +1 -1
  18. package/dist/elements/WhereBuilder/Condition/Text/index.d.ts.map +1 -1
  19. package/dist/elements/WhereBuilder/Condition/Text/index.js +30 -32
  20. package/dist/elements/WhereBuilder/Condition/Text/index.js.map +1 -1
  21. package/dist/elements/WhereBuilder/Condition/index.d.ts +2 -2
  22. package/dist/elements/WhereBuilder/Condition/index.d.ts.map +1 -1
  23. package/dist/elements/WhereBuilder/Condition/index.js.map +1 -1
  24. package/dist/elements/WhereBuilder/index.d.ts +3 -2
  25. package/dist/elements/WhereBuilder/index.d.ts.map +1 -1
  26. package/dist/elements/WhereBuilder/index.js +33 -18
  27. package/dist/elements/WhereBuilder/index.js.map +1 -1
  28. package/dist/elements/WhereBuilder/types.d.ts +4 -1
  29. package/dist/elements/WhereBuilder/types.d.ts.map +1 -1
  30. package/dist/elements/WhereBuilder/types.js.map +1 -1
  31. package/dist/exports/client/{DatePicker-YF5TBW3N.js → DatePicker-CL2EGBVQ.js} +2 -2
  32. package/dist/exports/client/{chunk-ZPLD37T2.js → chunk-SH42NW5R.js} +2 -2
  33. package/dist/exports/client/{chunk-ZPLD37T2.js.map → chunk-SH42NW5R.js.map} +4 -4
  34. package/dist/exports/client/index.js +12 -12
  35. package/dist/exports/client/index.js.map +4 -4
  36. package/dist/styles.css +1 -1
  37. package/dist/utilities/getColumns.d.ts.map +1 -1
  38. package/dist/utilities/getColumns.js +1 -2
  39. package/dist/utilities/getColumns.js.map +1 -1
  40. package/package.json +4 -4
  41. /package/dist/exports/client/{DatePicker-YF5TBW3N.js.map → DatePicker-CL2EGBVQ.js.map} +0 -0
@@ -3,7 +3,10 @@ import './index.scss';
3
3
  import React from 'react';
4
4
  export type Props = {
5
5
  readonly collectionSlug: SanitizedCollectionConfig['slug'];
6
- fields: ClientField[];
6
+ readonly fields: ClientField[];
7
+ /** When set, GroupByBuilder is controlled by the form (value + onChange) instead of list query. */
8
+ readonly onChange?: (groupBy: string) => void;
9
+ readonly value?: string;
7
10
  };
8
11
  export declare const GroupByBuilder: React.FC<Props>;
9
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/GroupByBuilder/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAS,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAE5E,OAAO,cAAc,CAAA;AAErB,OAAO,KAAkB,MAAM,OAAO,CAAA;AAStC,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,cAAc,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAA;IAC1D,MAAM,EAAE,WAAW,EAAE,CAAA;CACtB,CAAA;AAyBD,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAiH1C,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/elements/GroupByBuilder/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAS,yBAAyB,EAAE,MAAM,SAAS,CAAA;AAE5E,OAAO,cAAc,CAAA;AAErB,OAAO,KAAkB,MAAM,OAAO,CAAA;AAStC,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,CAAC,cAAc,EAAE,yBAAyB,CAAC,MAAM,CAAC,CAAA;IAC1D,QAAQ,CAAC,MAAM,EAAE,WAAW,EAAE,CAAA;IAC9B,mGAAmG;IACnG,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAC7C,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CACxB,CAAA;AAyBD,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CA6J1C,CAAA"}
@@ -20,7 +20,9 @@ const baseClass = 'group-by-builder';
20
20
  const supportedFieldTypes = ['text', 'textarea', 'number', 'select', 'relationship', 'date', 'checkbox', 'radio', 'email', 'number', 'upload'];
21
21
  export const GroupByBuilder = ({
22
22
  collectionSlug,
23
- fields
23
+ fields,
24
+ onChange,
25
+ value: valueProp
24
26
  }) => {
25
27
  const {
26
28
  i18n,
@@ -29,18 +31,85 @@ export const GroupByBuilder = ({
29
31
  const {
30
32
  permissions
31
33
  } = useAuth();
34
+ const listQuery = useListQuery();
35
+ const isFormMode = typeof onChange === 'function';
36
+ const groupByRaw = isFormMode ? valueProp : listQuery.query?.groupBy;
37
+ const groupByFieldName = groupByRaw?.replace(/^-/, '');
32
38
  const fieldPermissions = permissions?.collections?.[collectionSlug]?.fields;
33
39
  const reducedFields = useMemo(() => reduceFieldsToOptions({
34
40
  fieldPermissions,
35
41
  fields,
36
42
  i18n
37
43
  }), [fields, fieldPermissions, i18n]);
38
- const {
39
- query,
40
- refineListData
41
- } = useListQuery();
42
- const groupByFieldName = query.groupBy?.replace(/^-/, '');
43
44
  const groupByField = reducedFields.find(field => field.value === groupByFieldName);
45
+ const handleFieldChange = useMemo(() => {
46
+ if (isFormMode) {
47
+ return v => {
48
+ const value = v === null ? undefined : v.value;
49
+ const newGroupBy = value ? groupByRaw?.startsWith('-') ? `-${value}` : value : '';
50
+ onChange?.(newGroupBy);
51
+ };
52
+ }
53
+ return v_0 => {
54
+ void (async () => {
55
+ if (typeof listQuery.refineListData !== 'function') {
56
+ return;
57
+ }
58
+ const value_0 = v_0 === null ? undefined : v_0.value;
59
+ if (v_0 === null) {
60
+ await listQuery.refineListData({
61
+ groupBy: '',
62
+ page: 1
63
+ });
64
+ } else {
65
+ await listQuery.refineListData({
66
+ groupBy: value_0 ? listQuery.query?.groupBy?.startsWith('-') ? `-${value_0}` : value_0 : undefined,
67
+ page: 1
68
+ });
69
+ }
70
+ })();
71
+ };
72
+ }, [isFormMode, groupByRaw, listQuery, onChange]);
73
+ const handleClear = useMemo(() => {
74
+ if (isFormMode) {
75
+ return () => onChange?.('');
76
+ }
77
+ return () => {
78
+ void (async () => {
79
+ if (typeof listQuery.refineListData === 'function') {
80
+ await listQuery.refineListData({
81
+ groupBy: ''
82
+ });
83
+ }
84
+ })();
85
+ };
86
+ }, [isFormMode, listQuery, onChange]);
87
+ const handleDirectionChange = useMemo(() => {
88
+ if (isFormMode) {
89
+ return ({
90
+ value: value_1
91
+ }) => {
92
+ if (!groupByFieldName) {
93
+ return;
94
+ }
95
+ onChange?.(value_1 === 'asc' ? groupByFieldName : `-${groupByFieldName}`);
96
+ };
97
+ }
98
+ return ({
99
+ value: value_2
100
+ }) => {
101
+ void (async () => {
102
+ if (!groupByFieldName || typeof listQuery.refineListData !== 'function') {
103
+ return;
104
+ }
105
+ await listQuery.refineListData({
106
+ groupBy: value_2 === 'asc' ? groupByFieldName : `-${groupByFieldName}`,
107
+ page: 1
108
+ });
109
+ })();
110
+ };
111
+ }, [groupByFieldName, isFormMode, listQuery, onChange]);
112
+ const directionValue = !groupByRaw || typeof groupByRaw !== 'string' ? 'asc' : groupByRaw.startsWith('-') ? 'desc' : 'asc';
44
113
  return /*#__PURE__*/_jsxs("div", {
45
114
  className: baseClass,
46
115
  children: [/*#__PURE__*/_jsxs("div", {
@@ -49,14 +118,10 @@ export const GroupByBuilder = ({
49
118
  children: t('general:groupByLabel', {
50
119
  label: ''
51
120
  })
52
- }), query.groupBy && /*#__PURE__*/_jsx("button", {
121
+ }), groupByRaw && /*#__PURE__*/_jsx("button", {
53
122
  className: `${baseClass}__clear-button`,
54
123
  id: "group-by--reset",
55
- onClick: async () => {
56
- await refineListData({
57
- groupBy: ''
58
- });
59
- },
124
+ onClick: () => void handleClear(),
60
125
  type: "button",
61
126
  children: t('general:clear')
62
127
  })]
@@ -67,21 +132,8 @@ export const GroupByBuilder = ({
67
132
  id: "group-by--field-select",
68
133
  isClearable: true,
69
134
  isMulti: false,
70
- onChange: async v => {
71
- const value = v === null ? undefined : v.value;
72
- // value is being cleared
73
- if (v === null) {
74
- await refineListData({
75
- groupBy: '',
76
- page: 1
77
- });
78
- }
79
- await refineListData({
80
- groupBy: value ? query.groupBy?.startsWith('-') ? `-${value}` : value : undefined,
81
- page: 1
82
- });
83
- },
84
- options: reducedFields.filter(field_0 => !field_0.field.admin.disableGroupBy && field_0.value !== 'id' && supportedFieldTypes.includes(field_0.field.type)),
135
+ onChange: handleFieldChange,
136
+ options: reducedFields.filter(field_0 => !field_0.field.admin?.disableGroupBy && field_0.value !== 'id' && supportedFieldTypes.includes(field_0.field.type)),
85
137
  value: {
86
138
  label: groupByField?.label || t('general:selectValue'),
87
139
  value: groupByFieldName || ''
@@ -90,17 +142,7 @@ export const GroupByBuilder = ({
90
142
  id: "group-by--sort",
91
143
  isClearable: false,
92
144
  name: "direction",
93
- onChange: async ({
94
- value: value_0
95
- }) => {
96
- if (!groupByFieldName) {
97
- return;
98
- }
99
- await refineListData({
100
- groupBy: value_0 === 'asc' ? groupByFieldName : `-${groupByFieldName}`,
101
- page: 1
102
- });
103
- },
145
+ onChange: handleDirectionChange,
104
146
  options: [{
105
147
  label: t('general:ascending'),
106
148
  value: 'asc'
@@ -110,7 +152,7 @@ export const GroupByBuilder = ({
110
152
  }],
111
153
  path: "direction",
112
154
  readOnly: !groupByFieldName,
113
- value: !query.groupBy ? 'asc' : typeof query.groupBy === 'string' ? `${query.groupBy.startsWith('-') ? 'desc' : 'asc'}` : ''
155
+ value: directionValue
114
156
  })]
115
157
  })]
116
158
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["React","useMemo","SelectInput","useAuth","useListQuery","useTranslation","reduceFieldsToOptions","ReactSelect","baseClass","supportedFieldTypes","GroupByBuilder","collectionSlug","fields","i18n","t","permissions","fieldPermissions","collections","reducedFields","query","refineListData","groupByFieldName","groupBy","replace","groupByField","find","field","value","_jsxs","className","_jsx","label","id","onClick","type","filterOption","option","inputValue","data","plainTextLabel","toLowerCase","includes","isClearable","isMulti","onChange","v","undefined","page","startsWith","options","filter","admin","disableGroupBy","name","path","readOnly"],"sources":["../../../src/elements/GroupByBuilder/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, Field, SanitizedCollectionConfig } from 'payload'\n\nimport './index.scss'\n\nimport React, { useMemo } from 'react'\n\nimport { SelectInput } from '../../fields/Select/Input.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { useListQuery } from '../../providers/ListQuery/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { reduceFieldsToOptions } from '../../utilities/reduceFieldsToOptions.js'\nimport { ReactSelect } from '../ReactSelect/index.js'\n\nexport type Props = {\n readonly collectionSlug: SanitizedCollectionConfig['slug']\n fields: ClientField[]\n}\n\nconst baseClass = 'group-by-builder'\n\n/**\n * Note: Some fields are already omitted from the list of fields:\n * - fields with nested field, e.g. `tabs`, `groups`, etc.\n * - fields that don't affect data, i.e. `row`, `collapsible`, `ui`, etc.\n * So we don't technically need to omit them here, but do anyway.\n * But some remaining fields still need an additional check, e.g. `richText`, etc.\n */\nconst supportedFieldTypes: Field['type'][] = [\n 'text',\n 'textarea',\n 'number',\n 'select',\n 'relationship',\n 'date',\n 'checkbox',\n 'radio',\n 'email',\n 'number',\n 'upload',\n]\n\nexport const GroupByBuilder: React.FC<Props> = ({ collectionSlug, fields }) => {\n const { i18n, t } = useTranslation()\n const { permissions } = useAuth()\n\n const fieldPermissions = permissions?.collections?.[collectionSlug]?.fields\n\n const reducedFields = useMemo(\n () =>\n reduceFieldsToOptions({\n fieldPermissions,\n fields,\n i18n,\n }),\n [fields, fieldPermissions, i18n],\n )\n\n const { query, refineListData } = useListQuery()\n\n const groupByFieldName = query.groupBy?.replace(/^-/, '')\n\n const groupByField = reducedFields.find((field) => field.value === groupByFieldName)\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <p>\n {t('general:groupByLabel', {\n label: '',\n })}\n </p>\n {query.groupBy && (\n <button\n className={`${baseClass}__clear-button`}\n id=\"group-by--reset\"\n onClick={async () => {\n await refineListData({\n groupBy: '',\n })\n }}\n type=\"button\"\n >\n {t('general:clear')}\n </button>\n )}\n </div>\n <div className={`${baseClass}__inputs`}>\n <ReactSelect\n filterOption={(option, inputValue) =>\n ((option?.data?.plainTextLabel as string) || option.label)\n .toLowerCase()\n .includes(inputValue.toLowerCase())\n }\n id=\"group-by--field-select\"\n isClearable\n isMulti={false}\n onChange={async (v: { value: string } | null) => {\n const value = v === null ? undefined : v.value\n\n // value is being cleared\n if (v === null) {\n await refineListData({\n groupBy: '',\n page: 1,\n })\n }\n\n await refineListData({\n groupBy: value ? (query.groupBy?.startsWith('-') ? `-${value}` : value) : undefined,\n page: 1,\n })\n }}\n options={reducedFields.filter(\n (field) =>\n !field.field.admin.disableGroupBy &&\n field.value !== 'id' &&\n supportedFieldTypes.includes(field.field.type),\n )}\n value={{\n label: groupByField?.label || t('general:selectValue'),\n value: groupByFieldName || '',\n }}\n />\n <SelectInput\n id=\"group-by--sort\"\n isClearable={false}\n name=\"direction\"\n onChange={async ({ value }: { value: string }) => {\n if (!groupByFieldName) {\n return\n }\n\n await refineListData({\n groupBy: value === 'asc' ? groupByFieldName : `-${groupByFieldName}`,\n page: 1,\n })\n }}\n options={[\n { label: t('general:ascending'), value: 'asc' },\n { label: t('general:descending'), value: 'desc' },\n ]}\n path=\"direction\"\n readOnly={!groupByFieldName}\n value={\n !query.groupBy\n ? 'asc'\n : typeof query.groupBy === 'string'\n ? `${query.groupBy.startsWith('-') ? 'desc' : 'asc'}`\n : ''\n }\n />\n </div>\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,OAAO;AAEP,OAAOA,KAAA,IAASC,OAAO,QAAQ;AAE/B,SAASC,WAAW,QAAQ;AAC5B,SAASC,OAAO,QAAQ;AACxB,SAASC,YAAY,QAAQ;AAC7B,SAASC,cAAc,QAAQ;AAC/B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,WAAW,QAAQ;AAO5B,MAAMC,SAAA,GAAY;AAElB;;;;;;;AAOA,MAAMC,mBAAA,GAAuC,CAC3C,QACA,YACA,UACA,UACA,gBACA,QACA,YACA,SACA,SACA,UACA,SACD;AAED,OAAO,MAAMC,cAAA,GAAkCA,CAAC;EAAEC,cAAc;EAAEC;AAAM,CAAE;EACxE,MAAM;IAAEC,IAAI;IAAEC;EAAC,CAAE,GAAGT,cAAA;EACpB,MAAM;IAAEU;EAAW,CAAE,GAAGZ,OAAA;EAExB,MAAMa,gBAAA,GAAmBD,WAAA,EAAaE,WAAA,GAAcN,cAAA,CAAe,EAAEC,MAAA;EAErE,MAAMM,aAAA,GAAgBjB,OAAA,CACpB,MACEK,qBAAA,CAAsB;IACpBU,gBAAA;IACAJ,MAAA;IACAC;EACF,IACF,CAACD,M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]}
1
+ {"version":3,"file":"index.js","names":["React","useMemo","SelectInput","useAuth","useListQuery","useTranslation","reduceFieldsToOptions","ReactSelect","baseClass","supportedFieldTypes","GroupByBuilder","collectionSlug","fields","onChange","value","valueProp","i18n","t","permissions","listQuery","isFormMode","groupByRaw","query","groupBy","groupByFieldName","replace","fieldPermissions","collections","reducedFields","groupByField","find","field","handleFieldChange","v","undefined","newGroupBy","startsWith","refineListData","page","handleClear","handleDirectionChange","directionValue","_jsxs","className","_jsx","label","id","onClick","type","filterOption","option","inputValue","data","plainTextLabel","toLowerCase","includes","isClearable","isMulti","options","filter","admin","disableGroupBy","name","path","readOnly"],"sources":["../../../src/elements/GroupByBuilder/index.tsx"],"sourcesContent":["'use client'\nimport type { ClientField, Field, SanitizedCollectionConfig } from 'payload'\n\nimport './index.scss'\n\nimport React, { useMemo } from 'react'\n\nimport { SelectInput } from '../../fields/Select/Input.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { useListQuery } from '../../providers/ListQuery/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { reduceFieldsToOptions } from '../../utilities/reduceFieldsToOptions.js'\nimport { ReactSelect } from '../ReactSelect/index.js'\n\nexport type Props = {\n readonly collectionSlug: SanitizedCollectionConfig['slug']\n readonly fields: ClientField[]\n /** When set, GroupByBuilder is controlled by the form (value + onChange) instead of list query. */\n readonly onChange?: (groupBy: string) => void\n readonly value?: string\n}\n\nconst baseClass = 'group-by-builder'\n\n/**\n * Note: Some fields are already omitted from the list of fields:\n * - fields with nested field, e.g. `tabs`, `groups`, etc.\n * - fields that don't affect data, i.e. `row`, `collapsible`, `ui`, etc.\n * So we don't technically need to omit them here, but do anyway.\n * But some remaining fields still need an additional check, e.g. `richText`, etc.\n */\nconst supportedFieldTypes: Field['type'][] = [\n 'text',\n 'textarea',\n 'number',\n 'select',\n 'relationship',\n 'date',\n 'checkbox',\n 'radio',\n 'email',\n 'number',\n 'upload',\n]\n\nexport const GroupByBuilder: React.FC<Props> = ({\n collectionSlug,\n fields,\n onChange,\n value: valueProp,\n}) => {\n const { i18n, t } = useTranslation()\n const { permissions } = useAuth()\n const listQuery = useListQuery()\n\n const isFormMode = typeof onChange === 'function'\n const groupByRaw = isFormMode ? valueProp : listQuery.query?.groupBy\n const groupByFieldName = groupByRaw?.replace(/^-/, '')\n\n const fieldPermissions = permissions?.collections?.[collectionSlug]?.fields\n\n const reducedFields = useMemo(\n () =>\n reduceFieldsToOptions({\n fieldPermissions,\n fields,\n i18n,\n }),\n [fields, fieldPermissions, i18n],\n )\n\n const groupByField = reducedFields.find((field) => field.value === groupByFieldName)\n\n const handleFieldChange = useMemo(() => {\n if (isFormMode) {\n return (v: { value: string } | null) => {\n const value = v === null ? undefined : v.value\n const newGroupBy = value ? (groupByRaw?.startsWith('-') ? `-${value}` : value) : ''\n onChange?.(newGroupBy)\n }\n }\n return (v: { value: string } | null) => {\n void (async () => {\n if (typeof listQuery.refineListData !== 'function') {\n return\n }\n const value = v === null ? undefined : v.value\n if (v === null) {\n await listQuery.refineListData({ groupBy: '', page: 1 })\n } else {\n await listQuery.refineListData({\n groupBy: value\n ? listQuery.query?.groupBy?.startsWith('-')\n ? `-${value}`\n : value\n : undefined,\n page: 1,\n })\n }\n })()\n }\n }, [isFormMode, groupByRaw, listQuery, onChange])\n\n const handleClear = useMemo(() => {\n if (isFormMode) {\n return () => onChange?.('')\n }\n return () => {\n void (async () => {\n if (typeof listQuery.refineListData === 'function') {\n await listQuery.refineListData({ groupBy: '' })\n }\n })()\n }\n }, [isFormMode, listQuery, onChange])\n\n const handleDirectionChange = useMemo(() => {\n if (isFormMode) {\n return ({ value }: { value: string }) => {\n if (!groupByFieldName) {\n return\n }\n onChange?.(value === 'asc' ? groupByFieldName : `-${groupByFieldName}`)\n }\n }\n return ({ value }: { value: string }) => {\n void (async () => {\n if (!groupByFieldName || typeof listQuery.refineListData !== 'function') {\n return\n }\n await listQuery.refineListData({\n groupBy: value === 'asc' ? groupByFieldName : `-${groupByFieldName}`,\n page: 1,\n })\n })()\n }\n }, [groupByFieldName, isFormMode, listQuery, onChange])\n\n const directionValue =\n !groupByRaw || typeof groupByRaw !== 'string'\n ? 'asc'\n : groupByRaw.startsWith('-')\n ? 'desc'\n : 'asc'\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__header`}>\n <p>\n {t('general:groupByLabel', {\n label: '',\n })}\n </p>\n {groupByRaw && (\n <button\n className={`${baseClass}__clear-button`}\n id=\"group-by--reset\"\n onClick={() => void handleClear()}\n type=\"button\"\n >\n {t('general:clear')}\n </button>\n )}\n </div>\n <div className={`${baseClass}__inputs`}>\n <ReactSelect\n filterOption={(option, inputValue) =>\n ((option?.data?.plainTextLabel as string) || option.label)\n .toLowerCase()\n .includes(inputValue.toLowerCase())\n }\n id=\"group-by--field-select\"\n isClearable\n isMulti={false}\n onChange={handleFieldChange}\n options={reducedFields.filter(\n (field) =>\n !field.field.admin?.disableGroupBy &&\n field.value !== 'id' &&\n supportedFieldTypes.includes(field.field.type),\n )}\n value={{\n label: groupByField?.label || t('general:selectValue'),\n value: groupByFieldName || '',\n }}\n />\n <SelectInput\n id=\"group-by--sort\"\n isClearable={false}\n name=\"direction\"\n onChange={handleDirectionChange}\n options={[\n { label: t('general:ascending'), value: 'asc' },\n { label: t('general:descending'), value: 'desc' },\n ]}\n path=\"direction\"\n readOnly={!groupByFieldName}\n value={directionValue}\n />\n </div>\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,OAAO;AAEP,OAAOA,KAAA,IAASC,OAAO,QAAQ;AAE/B,SAASC,WAAW,QAAQ;AAC5B,SAASC,OAAO,QAAQ;AACxB,SAASC,YAAY,QAAQ;AAC7B,SAASC,cAAc,QAAQ;AAC/B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,WAAW,QAAQ;AAU5B,MAAMC,SAAA,GAAY;AAElB;;;;;;;AAOA,MAAMC,mBAAA,GAAuC,CAC3C,QACA,YACA,UACA,UACA,gBACA,QACA,YACA,SACA,SACA,U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AA,EAAO;UACL+B,KAAA,EAAOhB,YAAA,EAAcgB,KAAA,IAAS5B,CAAA,CAAE;UAChCH,KAAA,EAAOU,gBAAA,IAAoB;QAC7B;uBAEFoB,IAAA,CAAC1C,WAAA;QACC4C,EAAA,EAAG;QACHU,WAAA,EAAa;QACbM,IAAA,EAAK;QACLjD,QAAA,EAAU2B,qBAAA;QACVkB,OAAA,EAAS,CACP;UAAEb,KAAA,EAAO5B,CAAA,CAAE;UAAsBH,KAAA,EAAO;QAAM,GAC9C;UAAE+B,KAAA,EAAO5B,CAAA,CAAE;UAAuBH,KAAA,EAAO;QAAO,EACjD;QACDiD,IAAA,EAAK;QACLC,QAAA,EAAU,CAACxC,gBAAA;QACXV,KAAA,EAAO2B;;;;AAKjB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/elements/QueryPresets/fields/ColumnsField/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAQzE,OAAO,cAAc,CAAA;AAErB,eAAO,MAAM,uBAAuB,EAAE,wBA2BrC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/elements/QueryPresets/fields/ColumnsField/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAYzE,OAAO,cAAc,CAAA;AAErB,eAAO,MAAM,uBAAuB,EAAE,wBA+FrC,CAAA"}
@@ -1,56 +1,119 @@
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
- import { toWords, transformColumnsToSearchParams } from 'payload/shared';
6
- import React from 'react';
4
+ import React, { useId, useMemo } from 'react';
7
5
  import { FieldLabel } from '../../../../fields/FieldLabel/index.js';
8
6
  import { useField } from '../../../../forms/useField/index.js';
9
- import { Pill } from '../../../Pill/index.js';
7
+ import { useAuth } from '../../../../providers/Auth/index.js';
8
+ import { useConfig } from '../../../../providers/Config/index.js';
9
+ import { useTranslation } from '../../../../providers/Translation/index.js';
10
+ import { getColumns } from '../../../../utilities/getColumns.js';
11
+ import { reduceFieldsToOptions } from '../../../../utilities/reduceFieldsToOptions.js';
12
+ import { PillSelector } from '../../../PillSelector/index.js';
10
13
  import './index.scss';
11
- export const QueryPresetsColumnField = t0 => {
12
- const $ = _c(5);
13
- const {
14
- field: t1
15
- } = t0;
16
- const {
14
+ export const QueryPresetsColumnField = ({
15
+ field: {
17
16
  label,
18
17
  required
19
- } = t1;
18
+ }
19
+ }) => {
20
20
  const {
21
21
  path,
22
+ setValue,
22
23
  value
23
24
  } = useField();
24
- let t2;
25
- if ($[0] !== label || $[1] !== path || $[2] !== required || $[3] !== value) {
26
- t2 = _jsxs("div", {
25
+ const relatedCollectionField = useField({
26
+ path: 'relatedCollection'
27
+ });
28
+ const relatedCollection = relatedCollectionField.value;
29
+ const {
30
+ config,
31
+ getEntityConfig
32
+ } = useConfig();
33
+ const {
34
+ i18n
35
+ } = useTranslation();
36
+ const {
37
+ permissions
38
+ } = useAuth();
39
+ const uuid = useId();
40
+ const collectionConfig = useMemo(() => relatedCollection ? getEntityConfig({
41
+ collectionSlug: relatedCollection
42
+ }) : null, [relatedCollection, getEntityConfig]);
43
+ const columns = useMemo(() => {
44
+ if (!relatedCollection || !collectionConfig) {
45
+ return [];
46
+ }
47
+ return getColumns({
48
+ clientConfig: config,
49
+ collectionConfig,
50
+ collectionSlug: relatedCollection,
51
+ columns: value ?? [],
52
+ i18n,
53
+ permissions
54
+ });
55
+ }, [config, collectionConfig, relatedCollection, value, i18n, permissions]);
56
+ const reducedFields = useMemo(() => {
57
+ if (!collectionConfig?.fields) {
58
+ return [];
59
+ }
60
+ return reduceFieldsToOptions({
61
+ fieldPermissions: permissions?.collections?.[relatedCollection]?.fields ?? true,
62
+ fields: collectionConfig.fields,
63
+ i18n
64
+ });
65
+ }, [collectionConfig, i18n, permissions, relatedCollection]);
66
+ const accessorToLabel = useMemo(() => {
67
+ const map = {};
68
+ for (const f of reducedFields) {
69
+ map[String(f.value)] = f.label;
70
+ }
71
+ return map;
72
+ }, [reducedFields]);
73
+ const pills = useMemo(() => columns.map((col, i) => ({
74
+ name: col.accessor,
75
+ key: `${relatedCollection}-${col.accessor}-${i}-${uuid}`,
76
+ Label: accessorToLabel[col.accessor] ?? col.accessor,
77
+ selected: col.active
78
+ })), [accessorToLabel, columns, relatedCollection, uuid]);
79
+ const currentColumns = value ?? columns;
80
+ const handleClick = React.useCallback(({
81
+ pill
82
+ }) => {
83
+ const newColumns = currentColumns.map(col_0 => col_0.accessor === pill.name ? {
84
+ ...col_0,
85
+ active: !col_0.active
86
+ } : col_0);
87
+ setValue(newColumns.length ? newColumns : undefined);
88
+ }, [currentColumns, setValue]);
89
+ if (!relatedCollection) {
90
+ return /*#__PURE__*/_jsxs("div", {
27
91
  className: "field-type query-preset-columns-field",
28
- children: [_jsx(FieldLabel, {
92
+ children: [/*#__PURE__*/_jsx(FieldLabel, {
29
93
  as: "h3",
30
- label,
31
- path,
32
- required
33
- }), _jsx("div", {
34
- className: "value-wrapper",
35
- children: value ? transformColumnsToSearchParams(value).map(_temp) : "No columns selected"
94
+ label: label,
95
+ path: path,
96
+ required: required
97
+ }), /*#__PURE__*/_jsx("p", {
98
+ className: "query-preset-columns-field__hint",
99
+ children: "Select the related collection to configure columns."
36
100
  })]
37
101
  });
38
- $[0] = label;
39
- $[1] = path;
40
- $[2] = required;
41
- $[3] = value;
42
- $[4] = t2;
43
- } else {
44
- t2 = $[4];
45
102
  }
46
- return t2;
103
+ return /*#__PURE__*/_jsxs("div", {
104
+ className: "field-type query-preset-columns-field",
105
+ children: [/*#__PURE__*/_jsx(FieldLabel, {
106
+ as: "h3",
107
+ label: label,
108
+ path: path,
109
+ required: required
110
+ }), pills.length > 0 ? /*#__PURE__*/_jsx(PillSelector, {
111
+ onClick: handleClick,
112
+ pills: pills
113
+ }) : /*#__PURE__*/_jsx("p", {
114
+ className: "query-preset-columns-field__hint",
115
+ children: "No columns available for this collection."
116
+ })]
117
+ });
47
118
  };
48
- function _temp(column, i) {
49
- const isColumnActive = !column.startsWith("-");
50
- return _jsx(Pill, {
51
- pillStyle: isColumnActive ? "always-white" : "light-gray",
52
- size: "small",
53
- children: toWords(column)
54
- }, i);
55
- }
56
119
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["c","_c","toWords","transformColumnsToSearchParams","React","FieldLabel","useField","Pill","QueryPresetsColumnField","t0","$","field","t1","label","required","path","value","t2","_jsxs","className","children","_jsx","as","map","_temp","column","i","isColumnActive","startsWith","pillStyle","size"],"sources":["../../../../../src/elements/QueryPresets/fields/ColumnsField/index.tsx"],"sourcesContent":["'use client'\nimport type { ColumnPreference, JSONFieldClientComponent } from 'payload'\n\nimport { toWords, transformColumnsToSearchParams } from 'payload/shared'\nimport React from 'react'\n\nimport { FieldLabel } from '../../../../fields/FieldLabel/index.js'\nimport { useField } from '../../../../forms/useField/index.js'\nimport { Pill } from '../../../Pill/index.js'\nimport './index.scss'\n\nexport const QueryPresetsColumnField: JSONFieldClientComponent = ({\n field: { label, required },\n}) => {\n const { path, value } = useField()\n\n return (\n <div className=\"field-type query-preset-columns-field\">\n <FieldLabel as=\"h3\" label={label} path={path} required={required} />\n <div className=\"value-wrapper\">\n {value\n ? transformColumnsToSearchParams(value as ColumnPreference[]).map((column, i) => {\n const isColumnActive = !column.startsWith('-')\n\n return (\n <Pill\n key={i}\n pillStyle={isColumnActive ? 'always-white' : 'light-gray'}\n size=\"small\"\n >\n {toWords(column)}\n </Pill>\n )\n })\n : 'No columns selected'}\n </div>\n </div>\n )\n}\n"],"mappings":"AAAA;;AAAA,SAAAA,CAAA,IAAAC,EAAA;;AAGA,SAASC,OAAO,EAAEC,8BAA8B,QAAQ;AACxD,OAAOC,KAAA,MAAW;AAElB,SAASC,UAAU,QAAQ;AAC3B,SAASC,QAAQ,QAAQ;AACzB,SAASC,IAAI,QAAQ;AACrB,OAAO;AAEP,OAAO,MAAMC,uBAAA,GAAoDC,EAAA;EAAA,MAAAC,CAAA,GAAAT,EAAA;EAAC;IAAAU,KAAA,EAAAC;EAAA,IAAAH,EAEjE;EADQ;IAAAI,KAAA;IAAAC;EAAA,IAAAF,EAAmB;EAE1B;IAAAG,IAAA;IAAAC;EAAA,IAAwBV,QAAA;EAAA,IAAAW,EAAA;EAAA,IAAAP,CAAA,QAAAG,KAAA,IAAAH,CAAA,QAAAK,IAAA,IAAAL,CAAA,QAAAI,QAAA,IAAAJ,CAAA,QAAAM,KAAA;IAGtBC,EAAA,GAAAC,KAAA,CAAC;MAAAC,SAAA,EAAc;MAAAC,QAAA,GACbC,IAAA,CAAAhB,UAAA;QAAAiB,EAAA,EAAe;QAAAT,KAAA;QAAAE,IAAA;QAAAD;MAAA,C,GACfO,IAAA,CAAC;QAAAF,SAAA,EAAc;QAAAC,QAAA,EACZJ,KAAA,GACGb,8BAAA,CAA+Ba,KAAA,EAAAO,GAAA,CAAAC,KAY/B,IACA;MAAA,C;;;;;;;;;;SAjBRP,E;CAqBJ;AA3BiE,SAAAO,MAAAC,MAAA,EAAAC,CAAA;EAWnD,MAAAC,cAAA,IAAwBF,MAAA,CAAAG,UAAA,CAAkB;EAAA,OAGxCP,IAAA,CAAAd,IAAA;IAAAsB,SAAA,EAEaF,cAAA,GAAiB,iBAAiB;IAAAG,IAAA,EACxC;IAAAV,QAAA,EAEJlB,OAAA,CAAQuB,MAAA;EAAA,GAJJC,CAAA;AAAA","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["React","useId","useMemo","FieldLabel","useField","useAuth","useConfig","useTranslation","getColumns","reduceFieldsToOptions","PillSelector","QueryPresetsColumnField","field","label","required","path","setValue","value","relatedCollectionField","relatedCollection","config","getEntityConfig","i18n","permissions","uuid","collectionConfig","collectionSlug","columns","clientConfig","reducedFields","fields","fieldPermissions","collections","accessorToLabel","map","f","String","pills","col","i","name","accessor","key","Label","selected","active","currentColumns","handleClick","useCallback","pill","newColumns","length","undefined","_jsxs","className","_jsx","as","onClick"],"sources":["../../../../../src/elements/QueryPresets/fields/ColumnsField/index.tsx"],"sourcesContent":["'use client'\nimport type { ColumnPreference, JSONFieldClientComponent } from 'payload'\n\nimport React, { useId, useMemo } from 'react'\n\nimport { FieldLabel } from '../../../../fields/FieldLabel/index.js'\nimport { useField } from '../../../../forms/useField/index.js'\nimport { useAuth } from '../../../../providers/Auth/index.js'\nimport { useConfig } from '../../../../providers/Config/index.js'\nimport { useTranslation } from '../../../../providers/Translation/index.js'\nimport { getColumns } from '../../../../utilities/getColumns.js'\nimport { reduceFieldsToOptions } from '../../../../utilities/reduceFieldsToOptions.js'\nimport { PillSelector, type SelectablePill } from '../../../PillSelector/index.js'\nimport './index.scss'\n\nexport const QueryPresetsColumnField: JSONFieldClientComponent = ({\n field: { label, required },\n}) => {\n const { path, setValue, value } = useField<ColumnPreference[]>()\n const relatedCollectionField = useField({ path: 'relatedCollection' })\n const relatedCollection = relatedCollectionField.value as string | undefined\n const { config, getEntityConfig } = useConfig()\n const { i18n } = useTranslation()\n const { permissions } = useAuth()\n const uuid = useId()\n\n const collectionConfig = useMemo(\n () => (relatedCollection ? getEntityConfig({ collectionSlug: relatedCollection }) : null),\n [relatedCollection, getEntityConfig],\n )\n\n const columns = useMemo(() => {\n if (!relatedCollection || !collectionConfig) {\n return []\n }\n return getColumns({\n clientConfig: config,\n collectionConfig,\n collectionSlug: relatedCollection,\n columns: value ?? [],\n i18n,\n permissions,\n })\n }, [config, collectionConfig, relatedCollection, value, i18n, permissions])\n\n const reducedFields = useMemo(() => {\n if (!collectionConfig?.fields) {\n return []\n }\n return reduceFieldsToOptions({\n fieldPermissions: permissions?.collections?.[relatedCollection]?.fields ?? true,\n fields: collectionConfig.fields,\n i18n,\n })\n }, [collectionConfig, i18n, permissions, relatedCollection])\n\n const accessorToLabel = useMemo(() => {\n const map: Record<string, React.ReactNode> = {}\n for (const f of reducedFields) {\n map[String(f.value)] = f.label\n }\n return map\n }, [reducedFields])\n\n const pills: SelectablePill[] = useMemo(\n () =>\n columns.map((col, i) => ({\n name: col.accessor,\n key: `${relatedCollection}-${col.accessor}-${i}-${uuid}`,\n Label: accessorToLabel[col.accessor] ?? col.accessor,\n selected: col.active,\n })),\n [accessorToLabel, columns, relatedCollection, uuid],\n )\n\n const currentColumns = value ?? columns\n\n const handleClick = React.useCallback(\n ({ pill }: { pill: SelectablePill }) => {\n const newColumns = currentColumns.map((col) =>\n col.accessor === pill.name ? { ...col, active: !col.active } : col,\n )\n setValue(newColumns.length ? newColumns : undefined)\n },\n [currentColumns, setValue],\n )\n\n if (!relatedCollection) {\n return (\n <div className=\"field-type query-preset-columns-field\">\n <FieldLabel as=\"h3\" label={label} path={path} required={required} />\n <p className=\"query-preset-columns-field__hint\">\n Select the related collection to configure columns.\n </p>\n </div>\n )\n }\n\n return (\n <div className=\"field-type query-preset-columns-field\">\n <FieldLabel as=\"h3\" label={label} path={path} required={required} />\n {pills.length > 0 ? (\n <PillSelector onClick={handleClick} pills={pills} />\n ) : (\n <p className=\"query-preset-columns-field__hint\">\n No columns available for this collection.\n </p>\n )}\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,OAAOA,KAAA,IAASC,KAAK,EAAEC,OAAO,QAAQ;AAEtC,SAASC,UAAU,QAAQ;AAC3B,SAASC,QAAQ,QAAQ;AACzB,SAASC,OAAO,QAAQ;AACxB,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,SAASC,UAAU,QAAQ;AAC3B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,YAAY,QAA6B;AAClD,OAAO;AAEP,OAAO,MAAMC,uBAAA,GAAoDA,CAAC;EAChEC,KAAA,EAAO;IAAEC,KAAK;IAAEC;EAAQ;AAAE,CAC3B;EACC,MAAM;IAAEC,IAAI;IAAEC,QAAQ;IAAEC;EAAK,CA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D,UAAA;QAAWqD,EAAA,EAAG;QAAK3C,KAAA,EAAOA,KAAA;QAAOE,IAAA,EAAMA,IAAA;QAAMD,QAAA,EAAUA;uBACxDyC,IAAA,CAAC;QAAED,SAAA,EAAU;kBAAmC;;;EAKtD;EAEA,oBACED,KAAA,CAAC;IAAIC,SAAA,EAAU;4BACbC,IAAA,CAACpD,UAAA;MAAWqD,EAAA,EAAG;MAAK3C,KAAA,EAAOA,KAAA;MAAOE,IAAA,EAAMA,IAAA;MAAMD,QAAA,EAAUA;QACvDuB,KAAA,CAAMc,MAAM,GAAG,iBACdI,IAAA,CAAC7C,YAAA;MAAa+C,OAAA,EAASV,WAAA;MAAaV,KAAA,EAAOA;sBAE3CkB,IAAA,CAAC;MAAED,SAAA,EAAU;gBAAmC;;;AAMxD","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/elements/QueryPresets/fields/GroupByField/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAYvD,OAAO,cAAc,CAAA;AAErB,eAAO,MAAM,wBAAwB,EAAE,wBA8DtC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/elements/QueryPresets/fields/GroupByField/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,SAAS,CAAA;AAQvD,OAAO,cAAc,CAAA;AAErB,eAAO,MAAM,wBAAwB,EAAE,wBAuCtC,CAAA"}
@@ -1,15 +1,11 @@
1
1
  'use client';
2
2
 
3
3
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
- import { toWords } from 'payload/shared';
5
4
  import React, { useMemo } from 'react';
6
5
  import { FieldLabel } from '../../../../fields/FieldLabel/index.js';
7
6
  import { useField } from '../../../../forms/useField/index.js';
8
- import { useAuth } from '../../../../providers/Auth/index.js';
9
7
  import { useConfig } from '../../../../providers/Config/index.js';
10
- import { useTranslation } from '../../../../providers/Translation/index.js';
11
- import { reduceFieldsToOptions } from '../../../../utilities/reduceFieldsToOptions.js';
12
- import { Pill } from '../../../Pill/index.js';
8
+ import { GroupByBuilder } from '../../../GroupByBuilder/index.js';
13
9
  import './index.scss';
14
10
  export const QueryPresetsGroupByField = ({
15
11
  field: {
@@ -19,59 +15,37 @@ export const QueryPresetsGroupByField = ({
19
15
  }) => {
20
16
  const {
21
17
  path,
18
+ setValue,
22
19
  value
23
20
  } = useField();
24
- const {
25
- i18n
26
- } = useTranslation();
27
- const {
28
- permissions
29
- } = useAuth();
30
- const {
31
- config
32
- } = useConfig();
33
- // Get the relatedCollection from the document data
34
21
  const relatedCollectionField = useField({
35
22
  path: 'relatedCollection'
36
23
  });
37
24
  const relatedCollection = relatedCollectionField.value;
38
- // Get the collection config for the related collection
25
+ const {
26
+ config
27
+ } = useConfig();
39
28
  const collectionConfig = useMemo(() => {
40
29
  if (!relatedCollection) {
41
30
  return null;
42
31
  }
43
32
  return config.collections?.find(col => col.slug === relatedCollection);
44
33
  }, [relatedCollection, config.collections]);
45
- // Reduce fields to options to get proper labels
46
- const reducedFields = useMemo(() => {
47
- if (!collectionConfig) {
48
- return [];
49
- }
50
- const fieldPermissions = permissions?.collections?.[relatedCollection]?.fields;
51
- return reduceFieldsToOptions({
52
- fieldPermissions,
53
- fields: collectionConfig.fields,
54
- i18n
34
+ const fields = collectionConfig?.fields ?? [];
35
+ if (!relatedCollection) {
36
+ return /*#__PURE__*/_jsxs("div", {
37
+ className: "field-type query-preset-group-by-field",
38
+ children: [/*#__PURE__*/_jsx(FieldLabel, {
39
+ as: "h3",
40
+ label: label,
41
+ path: path,
42
+ required: required
43
+ }), /*#__PURE__*/_jsx("p", {
44
+ className: "query-preset-group-by-field__hint",
45
+ children: "Select the related collection to configure group by."
46
+ })]
55
47
  });
56
- }, [collectionConfig, permissions, relatedCollection, i18n]);
57
- const renderGroupBy = groupByValue => {
58
- if (!groupByValue) {
59
- return 'No group by selected';
60
- }
61
- const isDescending = groupByValue.startsWith('-');
62
- const fieldName = isDescending ? groupByValue.slice(1) : groupByValue;
63
- const direction = isDescending ? 'descending' : 'ascending';
64
- // Find the field option to get the proper label
65
- const fieldOption = reducedFields.find(field => field.value === fieldName);
66
- const displayLabel = fieldOption?.label || toWords(fieldName);
67
- return /*#__PURE__*/_jsxs(Pill, {
68
- pillStyle: "always-white",
69
- size: "small",
70
- children: [/*#__PURE__*/_jsx("b", {
71
- children: displayLabel
72
- }), " (", direction, ")"]
73
- });
74
- };
48
+ }
75
49
  return /*#__PURE__*/_jsxs("div", {
76
50
  className: "field-type query-preset-group-by-field",
77
51
  children: [/*#__PURE__*/_jsx(FieldLabel, {
@@ -79,9 +53,11 @@ export const QueryPresetsGroupByField = ({
79
53
  label: label,
80
54
  path: path,
81
55
  required: required
82
- }), /*#__PURE__*/_jsx("div", {
83
- className: "value-wrapper",
84
- children: renderGroupBy(value)
56
+ }), /*#__PURE__*/_jsx(GroupByBuilder, {
57
+ collectionSlug: relatedCollection,
58
+ fields: fields,
59
+ onChange: groupBy => setValue(groupBy || null),
60
+ value: value ?? undefined
85
61
  })]
86
62
  });
87
63
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["toWords","React","useMemo","FieldLabel","useField","useAuth","useConfig","useTranslation","reduceFieldsToOptions","Pill","QueryPresetsGroupByField","field","label","required","path","value","i18n","permissions","config","relatedCollectionField","relatedCollection","collectionConfig","collections","find","col","slug","reducedFields","fieldPermissions","fields","renderGroupBy","groupByValue","isDescending","startsWith","fieldName","slice","direction","fieldOption","displayLabel","_jsxs","pillStyle","size","_jsx","className","as"],"sources":["../../../../../src/elements/QueryPresets/fields/GroupByField/index.tsx"],"sourcesContent":["'use client'\nimport type { TextFieldClientComponent } from 'payload'\n\nimport { toWords } from 'payload/shared'\nimport React, { useMemo } from 'react'\n\nimport { FieldLabel } from '../../../../fields/FieldLabel/index.js'\nimport { useField } from '../../../../forms/useField/index.js'\nimport { useAuth } from '../../../../providers/Auth/index.js'\nimport { useConfig } from '../../../../providers/Config/index.js'\nimport { useTranslation } from '../../../../providers/Translation/index.js'\nimport { reduceFieldsToOptions } from '../../../../utilities/reduceFieldsToOptions.js'\nimport { Pill } from '../../../Pill/index.js'\nimport './index.scss'\n\nexport const QueryPresetsGroupByField: TextFieldClientComponent = ({\n field: { label, required },\n}) => {\n const { path, value } = useField()\n const { i18n } = useTranslation()\n const { permissions } = useAuth()\n const { config } = useConfig()\n\n // Get the relatedCollection from the document data\n const relatedCollectionField = useField({ path: 'relatedCollection' })\n const relatedCollection = relatedCollectionField.value as string\n\n // Get the collection config for the related collection\n const collectionConfig = useMemo(() => {\n if (!relatedCollection) {\n return null\n }\n\n return config.collections?.find((col) => col.slug === relatedCollection)\n }, [relatedCollection, config.collections])\n\n // Reduce fields to options to get proper labels\n const reducedFields = useMemo(() => {\n if (!collectionConfig) {\n return []\n }\n\n const fieldPermissions = permissions?.collections?.[relatedCollection]?.fields\n\n return reduceFieldsToOptions({\n fieldPermissions,\n fields: collectionConfig.fields,\n i18n,\n })\n }, [collectionConfig, permissions, relatedCollection, i18n])\n\n const renderGroupBy = (groupByValue: string) => {\n if (!groupByValue) {\n return 'No group by selected'\n }\n\n const isDescending = groupByValue.startsWith('-')\n const fieldName = isDescending ? groupByValue.slice(1) : groupByValue\n const direction = isDescending ? 'descending' : 'ascending'\n\n // Find the field option to get the proper label\n const fieldOption = reducedFields.find((field) => field.value === fieldName)\n const displayLabel = fieldOption?.label || toWords(fieldName)\n\n return (\n <Pill pillStyle=\"always-white\" size=\"small\">\n <b>{displayLabel}</b> ({direction})\n </Pill>\n )\n }\n\n return (\n <div className=\"field-type query-preset-group-by-field\">\n <FieldLabel as=\"h3\" label={label} path={path} required={required} />\n <div className=\"value-wrapper\">{renderGroupBy(value as string)}</div>\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,SAASA,OAAO,QAAQ;AACxB,OAAOC,KAAA,IAASC,OAAO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AmBJ,IAAA,CAAK;EAE3D,MAAMa,aAAA,GAAiBC,YAAA;IACrB,IAAI,CAACA,YAAA,EAAc;MACjB,OAAO;IACT;IAEA,MAAMC,YAAA,GAAeD,YAAA,CAAaE,UAAU,CAAC;IAC7C,MAAMC,SAAA,GAAYF,YAAA,GAAeD,YAAA,CAAaI,KAAK,CAAC,KAAKJ,YAAA;IACzD,MAAMK,SAAA,GAAYJ,YAAA,GAAe,eAAe;IAEhD;IACA,MAAMK,WAAA,GAAcV,aAAA,CAAcH,IAAI,CAAEZ,KAAA,IAAUA,KAAA,CAAMI,KAAK,KAAKkB,SAAA;IAClE,MAAMI,YAAA,GAAeD,WAAA,EAAaxB,KAAA,IAASZ,OAAA,CAAQiC,SAAA;IAEnD,oBACEK,KAAA,CAAC7B,IAAA;MAAK8B,SAAA,EAAU;MAAeC,IAAA,EAAK;8BAClCC,IAAA,CAAC;kBAAGJ;UAAiB,MAAGF,SAAA,EAAU;;EAGxC;EAEA,oBACEG,KAAA,CAAC;IAAII,SAAA,EAAU;4BACbD,IAAA,CAACtC,UAAA;MAAWwC,EAAA,EAAG;MAAK/B,KAAA,EAAOA,KAAA;MAAOE,IAAA,EAAMA,IAAA;MAAMD,QAAA,EAAUA;qBACxD4B,IAAA,CAAC;MAAIC,SAAA,EAAU;gBAAiBb,aAAA,CAAcd,KAAA;;;AAGpD","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["React","useMemo","FieldLabel","useField","useConfig","GroupByBuilder","QueryPresetsGroupByField","field","label","required","path","setValue","value","relatedCollectionField","relatedCollection","config","collectionConfig","collections","find","col","slug","fields","_jsxs","className","_jsx","as","collectionSlug","onChange","groupBy","undefined"],"sources":["../../../../../src/elements/QueryPresets/fields/GroupByField/index.tsx"],"sourcesContent":["'use client'\nimport type { TextFieldClientComponent } from 'payload'\n\nimport React, { useMemo } from 'react'\n\nimport { FieldLabel } from '../../../../fields/FieldLabel/index.js'\nimport { useField } from '../../../../forms/useField/index.js'\nimport { useConfig } from '../../../../providers/Config/index.js'\nimport { GroupByBuilder } from '../../../GroupByBuilder/index.js'\nimport './index.scss'\n\nexport const QueryPresetsGroupByField: TextFieldClientComponent = ({\n field: { label, required },\n}) => {\n const { path, setValue, value } = useField<string>()\n const relatedCollectionField = useField({ path: 'relatedCollection' })\n const relatedCollection = relatedCollectionField.value as string | undefined\n const { config } = useConfig()\n\n const collectionConfig = useMemo(() => {\n if (!relatedCollection) {\n return null\n }\n return config.collections?.find((col) => col.slug === relatedCollection)\n }, [relatedCollection, config.collections])\n\n const fields = collectionConfig?.fields ?? []\n\n if (!relatedCollection) {\n return (\n <div className=\"field-type query-preset-group-by-field\">\n <FieldLabel as=\"h3\" label={label} path={path} required={required} />\n <p className=\"query-preset-group-by-field__hint\">\n Select the related collection to configure group by.\n </p>\n </div>\n )\n }\n\n return (\n <div className=\"field-type query-preset-group-by-field\">\n <FieldLabel as=\"h3\" label={label} path={path} required={required} />\n <GroupByBuilder\n collectionSlug={relatedCollection}\n fields={fields}\n onChange={(groupBy) => setValue(groupBy || null)}\n value={value ?? undefined}\n />\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,OAAOA,KAAA,IAASC,OAAO,QAAQ;AAE/B,SAASC,UAAU,QAAQ;AAC3B,SAASC,QAAQ,QAAQ;AACzB,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,OAAO;AAEP,OAAO,MAAMC,wBAAA,GAAqDA,CAAC;EACjEC,KAAA,EAAO;IAAEC,KAAK;IAAEC;EAAQ;AAAE,CAC3B;EACC,MAAM;IAAEC,IAAI;IAAEC,QAAQ;IAAEC;EAAK,CAAE,GAAGT,QAAA;EAClC,MAAMU,sBAAA,GAAyBV,QAAA,CAAS;IAAEO,IAAA,EAAM;EAAoB;EACpE,MAAMI,iBAAA,GAAoBD,sBAAA,CAAuBD,KAAK;EACtD,MAAM;IAAEG;EAAM,CAAE,GAAGX,SAAA;EAEnB,MAAMY,gBAAA,GAAmBf,OAAA,CAAQ;IAC/B,IAAI,CAACa,iBAAA,EAAmB;MACtB,OAAO;IACT;IACA,OAAOC,MAAA,CAAOE,WAAW,EAAEC,IAAA,CAAMC,GAAA,IAAQA,GAAA,CAAIC,IAAI,KAAKN,iBAAA;EACxD,GAAG,CAACA,iBAAA,EAAmBC,MAAA,CAAOE,WAAW,CAAC;EAE1C,MAAMI,MAAA,GAASL,gBAAA,EAAkBK,MAAA,IAAU,EAAE;EAE7C,IAAI,CAACP,iBAAA,EAAmB;IACtB,oBACEQ,KAAA,CAAC;MAAIC,SAAA,EAAU;8BACbC,IAAA,CAACtB,UAAA;QAAWuB,EAAA,EAAG;QAAKjB,KAAA,EAAOA,KAAA;QAAOE,IAAA,EAAMA,IAAA;QAAMD,QAAA,EAAUA;uBACxDe,IAAA,CAAC;QAAED,SAAA,EAAU;kBAAoC;;;EAKvD;EAEA,oBACED,KAAA,CAAC;IAAIC,SAAA,EAAU;4BACbC,IAAA,CAACtB,UAAA;MAAWuB,EAAA,EAAG;MAAKjB,KAAA,EAAOA,KAAA;MAAOE,IAAA,EAAMA,IAAA;MAAMD,QAAA,EAAUA;qBACxDe,IAAA,CAACnB,cAAA;MACCqB,cAAA,EAAgBZ,iBAAA;MAChBO,MAAA,EAAQA,MAAA;MACRM,QAAA,EAAWC,OAAA,IAAYjB,QAAA,CAASiB,OAAA,IAAW;MAC3ChB,KAAA,EAAOA,KAAA,IAASiB;;;AAIxB","ignoreList":[]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/elements/QueryPresets/fields/WhereField/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAS,MAAM,SAAS,CAAA;AAY9D,OAAO,cAAc,CAAA;AAoFrB,eAAO,MAAM,sBAAsB,EAAE,wBAwBpC,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/elements/QueryPresets/fields/WhereField/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,wBAAwB,EAAS,MAAM,SAAS,CAAA;AAO9D,OAAO,cAAc,CAAA;AAErB,eAAO,MAAM,sBAAsB,EAAE,wBA4BpC,CAAA"}