{"version":3,"file":"index.js","names":["toWords","React","useMemo","useAuth","useConfig","useTranslation","reduceFieldsToOptions","QueryPresetsGroupByCell","cellData","rowData","i18n","permissions","config","relatedCollection","collectionConfig","collections","find","col","slug","reducedFields","fieldPermissions","fields","_jsx","isDescending","startsWith","fieldName","slice","direction","fieldOption","field","value","displayLabel","label","_jsxs"],"sources":["../../../../../src/elements/QueryPresets/cells/GroupByCell/index.tsx"],"sourcesContent":["import type { DefaultCellComponentProps } from 'payload'\n\nimport { toWords } from 'payload/shared'\nimport React, { useMemo } from 'react'\n\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'\n\nexport const QueryPresetsGroupByCell: React.FC = ({\n cellData,\n rowData,\n}) => {\n const { i18n } = useTranslation()\n const { permissions } = useAuth()\n const { config } = useConfig()\n\n // Get the related collection from the row data\n const relatedCollection = rowData?.relatedCollection 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 if (!cellData || typeof cellData !== 'string') {\n return
No group by selected
\n }\n\n const isDescending = cellData.startsWith('-')\n const fieldName = isDescending ? cellData.slice(1) : cellData\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
\n {displayLabel} ({direction})\n
\n )\n}\n"],"mappings":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