Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
1 line
5.1 KiB
Plaintext
1 line
5.1 KiB
Plaintext
{"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,QAAQ;AAE/B,SAASC,UAAU,QAAQ;AAC3B,SAASC,QAAQ,QAAQ;AACzB,SAASC,OAAO,QAAQ;AACxB,SAASC,SAAS,QAAQ;AAC1B,SAASC,cAAc,QAAQ;AAC/B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,IAAI,QAAQ;AACrB,OAAO;AAEP,OAAO,MAAMC,wBAAA,GAAqDA,CAAC;EACjEC,KAAA,EAAO;IAAEC,KAAK;IAAEC;EAAQ;AAAE,CAC3B;EACC,MAAM;IAAEC,IAAI;IAAEC;EAAK,CAAE,GAAGX,QAAA;EACxB,MAAM;IAAEY;EAAI,CAAE,GAAGT,cAAA;EACjB,MAAM;IAAEU;EAAW,CAAE,GAAGZ,OAAA;EACxB,MAAM;IAAEa;EAAM,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