Files
klz-cables.com/.pnpm-store/v10/files/4b/5d60fe8dfb700f470f08baebede7905588c279655f863060cb90ae2c45436c047cf652aec3bf592c0838bcdfc42611720237d8d75d655f1b23aaeedcf1e4d3
Marc Mintel 5397309103
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
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

1 line
15 KiB
Plaintext

{"version":3,"file":"index.js","names":["getTranslation","dequal","transformWhereQuery","validateWhereQuery","React","useMemo","useAuth","useListQuery","useTranslation","reduceFieldsToOptions","Button","Condition","fieldTypeConditions","getValidFieldOperators","baseClass","WhereBuilder","props","collectionPluralLabel","collectionSlug","fields","renderedFilters","resolvedFilterOptions","i18n","t","permissions","fieldPermissions","collections","reducedFields","handleWhereChange","query","conditions","whereFromSearch","where","or","transformedWhere","console","warn","JSON","stringify","addCondition","useCallback","andIndex","field","orIndex","relation","newConditions","defaultOperator","type","operators","value","and","splice","String","undefined","push","updateCondition","operator","incomingOperator","existingCondition","validOperator","existingValue","newRowCondition","removeCondition","length","_jsxs","className","Fragment","_jsx","label","map","compoundOrKey","Array","isArray","_","condition","fieldPath","Object","keys","filterOptions","get","RenderedFilter","buttonStyle","icon","iconPosition","iconStyle","onClick","find","admin","disableListFilter"],"sources":["../../../src/elements/WhereBuilder/index.tsx"],"sourcesContent":["'use client'\nimport type { Operator } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\nimport { dequal } from 'dequal/lite'\nimport { transformWhereQuery, validateWhereQuery } from 'payload/shared'\nimport React, { useMemo } from 'react'\n\nimport type { AddCondition, RemoveCondition, UpdateCondition, WhereBuilderProps } from './types.js'\n\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 { Button } from '../Button/index.js'\nimport { Condition } from './Condition/index.js'\nimport './index.scss'\nimport { fieldTypeConditions, getValidFieldOperators } from './field-types.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, collectionSlug, fields, renderedFilters, resolvedFilterOptions } =\n props\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 [fieldPermissions, fields, i18n],\n )\n\n const { handleWhereChange, query } = useListQuery()\n\n const conditions = useMemo(() => {\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 }, [query.where])\n\n const addCondition: AddCondition = React.useCallback(\n async ({ andIndex, field, orIndex, relation }) => {\n const newConditions = [...conditions]\n\n const defaultOperator = fieldTypeConditions[field.field.type].operators[0].value\n\n if (relation === 'and') {\n newConditions[orIndex].and.splice(andIndex, 0, {\n [String(field.value)]: {\n [defaultOperator]: undefined,\n },\n })\n } else {\n newConditions.push({\n and: [\n {\n [String(field.value)]: {\n [defaultOperator]: undefined,\n },\n },\n ],\n })\n }\n\n await handleWhereChange({ or: newConditions })\n },\n [conditions, handleWhereChange],\n )\n\n const updateCondition: UpdateCondition = React.useCallback(\n async ({ andIndex, field, operator: incomingOperator, orIndex, value }) => {\n const existingCondition = conditions[orIndex].and[andIndex]\n\n if (typeof existingCondition === 'object' && field.value) {\n const { validOperator } = getValidFieldOperators({\n field: field.field,\n operator: incomingOperator,\n })\n\n // Skip if nothing changed\n const existingValue = existingCondition[String(field.value)]?.[validOperator]\n if (typeof existingValue !== 'undefined' && existingValue === value) {\n return\n }\n\n const newRowCondition = {\n [String(field.value)]: { [validOperator]: value },\n }\n\n if (dequal(existingCondition, newRowCondition)) {\n return\n }\n\n const newConditions = [...conditions]\n newConditions[orIndex].and[andIndex] = newRowCondition\n\n await handleWhereChange({ or: newConditions })\n }\n },\n [conditions, handleWhereChange],\n )\n\n const removeCondition: RemoveCondition = React.useCallback(\n async ({ 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 await handleWhereChange({ or: newConditions })\n },\n [conditions, handleWhereChange],\n )\n\n return (\n <div className={baseClass}>\n {conditions.length > 0 && (\n <React.Fragment>\n <p className={`${baseClass}__label`}>\n {t('general:filterWhere', { label: getTranslation(collectionPluralLabel, i18n) })}\n </p>\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 fieldPath = Object.keys(condition)[0]\n\n const operator =\n (Object.keys(condition?.[fieldPath] || {})?.[0] as Operator) || undefined\n\n const value = condition?.[fieldPath]?.[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 fieldPath={fieldPath}\n filterOptions={resolvedFilterOptions?.get(fieldPath)}\n operator={operator}\n orIndex={orIndex}\n reducedFields={reducedFields}\n removeCondition={removeCondition}\n RenderedFilter={renderedFilters?.get(fieldPath)}\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={async () => {\n await addCondition({\n andIndex: 0,\n field: reducedFields.find((field) => !field.field.admin?.disableListFilter),\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={async () => {\n if (reducedFields.length > 0) {\n await 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,SAASC,MAAM,QAAQ;AACvB,SAASC,mBAAmB,EAAEC,kBAAkB,QAAQ;AACxD,OAAOC,KAAA,IAASC,OAAO,QAAQ;AAI/B,SAASC,OAAO,QAAQ;AACxB,SAASC,YAAY,QAAQ;AAC7B,SAASC,cAAc,QAAQ;AAC/B,SAASC,qBAAqB,QAAQ;AACtC,SAASC,MAAM,QAA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