@payloadcms/ui 3.0.0-beta.68 → 3.0.0-beta.69
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.
- package/dist/elements/AppHeader/index.d.ts.map +1 -1
- package/dist/elements/AppHeader/index.js +5 -1
- package/dist/elements/AppHeader/index.js.map +1 -1
- package/dist/elements/DeleteDocument/index.d.ts.map +1 -1
- package/dist/elements/DeleteDocument/index.js +7 -3
- package/dist/elements/DeleteDocument/index.js.map +1 -1
- package/dist/elements/DocumentControls/index.d.ts.map +1 -1
- package/dist/elements/DocumentControls/index.js +5 -1
- package/dist/elements/DocumentControls/index.js.map +1 -1
- package/dist/elements/DocumentFields/index.d.ts.map +1 -1
- package/dist/elements/DocumentFields/index.js +46 -48
- package/dist/elements/DocumentFields/index.js.map +1 -1
- package/dist/elements/DuplicateDocument/index.d.ts.map +1 -1
- package/dist/elements/DuplicateDocument/index.js +10 -6
- package/dist/elements/DuplicateDocument/index.js.map +1 -1
- package/dist/elements/Logout/index.d.ts.map +1 -1
- package/dist/elements/Logout/index.js +6 -3
- package/dist/elements/Logout/index.js.map +1 -1
- package/dist/elements/StayLoggedIn/index.d.ts.map +1 -1
- package/dist/elements/StayLoggedIn/index.js +6 -2
- package/dist/elements/StayLoggedIn/index.js.map +1 -1
- package/dist/elements/Table/DefaultCell/index.d.ts.map +1 -1
- package/dist/elements/Table/DefaultCell/index.js +5 -1
- package/dist/elements/Table/DefaultCell/index.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/Relationship/index.js +4 -4
- package/dist/elements/WhereBuilder/Condition/Relationship/index.js.map +1 -1
- package/dist/elements/WhereBuilder/Condition/index.d.ts.map +1 -1
- package/dist/elements/WhereBuilder/Condition/index.js +4 -2
- package/dist/elements/WhereBuilder/Condition/index.js.map +1 -1
- package/dist/exports/client/index.js +18 -18
- package/dist/exports/client/index.js.map +4 -4
- package/dist/exports/shared/index.d.ts +1 -0
- package/dist/exports/shared/index.d.ts.map +1 -1
- package/dist/exports/shared/index.js +2 -2
- package/dist/exports/shared/index.js.map +4 -4
- package/dist/fields/Upload/Input.d.ts +4 -0
- package/dist/fields/Upload/Input.d.ts.map +1 -1
- package/dist/fields/Upload/Input.js +2 -2
- package/dist/fields/Upload/Input.js.map +1 -1
- package/dist/fields/Upload/index.d.ts.map +1 -1
- package/dist/fields/Upload/index.js +18 -3
- package/dist/fields/Upload/index.js.map +1 -1
- package/dist/forms/buildStateFromSchema/addFieldStatePromise.d.ts.map +1 -1
- package/dist/forms/buildStateFromSchema/addFieldStatePromise.js +39 -18
- package/dist/forms/buildStateFromSchema/addFieldStatePromise.js.map +1 -1
- package/dist/graphics/Account/index.d.ts.map +1 -1
- package/dist/graphics/Account/index.js +5 -1
- package/dist/graphics/Account/index.js.map +1 -1
- package/dist/providers/Auth/index.d.ts +1 -1
- package/dist/providers/Auth/index.d.ts.map +1 -1
- package/dist/providers/Auth/index.js +46 -38
- package/dist/providers/Auth/index.js.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/fields.d.ts.map +1 -1
- package/dist/providers/ComponentMap/buildComponentMap/fields.js +1 -0
- package/dist/providers/ComponentMap/buildComponentMap/fields.js.map +1 -1
- package/dist/utilities/buildFormState.d.ts.map +1 -1
- package/dist/utilities/buildFormState.js +1 -0
- package/dist/utilities/buildFormState.js.map +1 -1
- package/dist/utilities/formatAdminURL.d.ts +8 -0
- package/dist/utilities/formatAdminURL.d.ts.map +1 -0
- package/dist/utilities/formatAdminURL.js +15 -0
- package/dist/utilities/formatAdminURL.js.map +1 -0
- package/package.json +4 -4
|
@@ -8,6 +8,7 @@ import { Button } from '../../elements/Button/index.js';
|
|
|
8
8
|
import { useAuth } from '../../providers/Auth/index.js';
|
|
9
9
|
import { useConfig } from '../../providers/Config/index.js';
|
|
10
10
|
import { useTranslation } from '../../providers/Translation/index.js';
|
|
11
|
+
import { formatAdminURL } from '../../utilities/formatAdminURL.js';
|
|
11
12
|
import './index.scss';
|
|
12
13
|
const baseClass = 'stay-logged-in';
|
|
13
14
|
export const stayLoggedInModalSlug = 'stay-logged-in';
|
|
@@ -15,7 +16,7 @@ export const StayLoggedInModal = ()=>{
|
|
|
15
16
|
const { refreshCookie } = useAuth();
|
|
16
17
|
const router = useRouter();
|
|
17
18
|
const config = useConfig();
|
|
18
|
-
const { admin: { routes: { logout: logoutRoute } }, routes: { admin } } = config;
|
|
19
|
+
const { admin: { routes: { logout: logoutRoute } }, routes: { admin: adminRoute } } = config;
|
|
19
20
|
const { toggleModal } = useModal();
|
|
20
21
|
const { t } = useTranslation();
|
|
21
22
|
return /*#__PURE__*/ _jsx(Modal, {
|
|
@@ -42,7 +43,10 @@ export const StayLoggedInModal = ()=>{
|
|
|
42
43
|
buttonStyle: "secondary",
|
|
43
44
|
onClick: ()=>{
|
|
44
45
|
toggleModal(stayLoggedInModalSlug);
|
|
45
|
-
router.push(
|
|
46
|
+
router.push(formatAdminURL({
|
|
47
|
+
adminRoute,
|
|
48
|
+
path: logoutRoute
|
|
49
|
+
}));
|
|
46
50
|
},
|
|
47
51
|
children: t('authentication:logOut')
|
|
48
52
|
}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/elements/StayLoggedIn/index.tsx"],"sourcesContent":["'use client'\nimport { Modal, useModal } from '@faceless-ui/modal'\n// TODO: abstract the `next/navigation` dependency out from this component\nimport { useRouter } from 'next/navigation.js'\nimport React from 'react'\n\nimport { Button } from '../../elements/Button/index.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport './index.scss'\n\nconst baseClass = 'stay-logged-in'\n\nexport const stayLoggedInModalSlug = 'stay-logged-in'\n\nexport const StayLoggedInModal: React.FC = () => {\n const { refreshCookie } = useAuth()\n\n const router = useRouter()\n const config = useConfig()\n\n const {\n admin: {\n routes: { logout: logoutRoute },\n },\n routes: { admin },\n } = config\n const { toggleModal } = useModal()\n const { t } = useTranslation()\n\n return (\n <Modal className={baseClass} slug={stayLoggedInModalSlug}>\n <div className={`${baseClass}__wrapper`}>\n <div className={`${baseClass}__content`}>\n <h1>{t('authentication:stayLoggedIn')}</h1>\n <p>{t('authentication:youAreInactive')}</p>\n </div>\n <div className={`${baseClass}__controls`}>\n <Button\n buttonStyle=\"secondary\"\n onClick={() => {\n toggleModal(stayLoggedInModalSlug)\n router.push(
|
|
1
|
+
{"version":3,"sources":["../../../src/elements/StayLoggedIn/index.tsx"],"sourcesContent":["'use client'\nimport { Modal, useModal } from '@faceless-ui/modal'\n// TODO: abstract the `next/navigation` dependency out from this component\nimport { useRouter } from 'next/navigation.js'\nimport React from 'react'\n\nimport { Button } from '../../elements/Button/index.js'\nimport { useAuth } from '../../providers/Auth/index.js'\nimport { useConfig } from '../../providers/Config/index.js'\nimport { useTranslation } from '../../providers/Translation/index.js'\nimport { formatAdminURL } from '../../utilities/formatAdminURL.js'\nimport './index.scss'\n\nconst baseClass = 'stay-logged-in'\n\nexport const stayLoggedInModalSlug = 'stay-logged-in'\n\nexport const StayLoggedInModal: React.FC = () => {\n const { refreshCookie } = useAuth()\n\n const router = useRouter()\n const config = useConfig()\n\n const {\n admin: {\n routes: { logout: logoutRoute },\n },\n routes: { admin: adminRoute },\n } = config\n\n const { toggleModal } = useModal()\n const { t } = useTranslation()\n\n return (\n <Modal className={baseClass} slug={stayLoggedInModalSlug}>\n <div className={`${baseClass}__wrapper`}>\n <div className={`${baseClass}__content`}>\n <h1>{t('authentication:stayLoggedIn')}</h1>\n <p>{t('authentication:youAreInactive')}</p>\n </div>\n <div className={`${baseClass}__controls`}>\n <Button\n buttonStyle=\"secondary\"\n onClick={() => {\n toggleModal(stayLoggedInModalSlug)\n router.push(\n formatAdminURL({\n adminRoute,\n path: logoutRoute,\n }),\n )\n }}\n >\n {t('authentication:logOut')}\n </Button>\n <Button\n onClick={() => {\n refreshCookie()\n toggleModal(stayLoggedInModalSlug)\n }}\n >\n {t('authentication:stayLoggedIn')}\n </Button>\n </div>\n </div>\n </Modal>\n )\n}\n"],"names":["Modal","useModal","useRouter","React","Button","useAuth","useConfig","useTranslation","formatAdminURL","baseClass","stayLoggedInModalSlug","StayLoggedInModal","refreshCookie","router","config","admin","routes","logout","logoutRoute","adminRoute","toggleModal","t","className","slug","div","h1","p","buttonStyle","onClick","push","path"],"mappings":"AAAA;;AACA,SAASA,KAAK,EAAEC,QAAQ,QAAQ,qBAAoB;AACpD,0EAA0E;AAC1E,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,OAAOC,WAAW,QAAO;AAEzB,SAASC,MAAM,QAAQ,iCAAgC;AACvD,SAASC,OAAO,QAAQ,gCAA+B;AACvD,SAASC,SAAS,QAAQ,kCAAiC;AAC3D,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,cAAc,QAAQ,oCAAmC;AAClE,OAAO,eAAc;AAErB,MAAMC,YAAY;AAElB,OAAO,MAAMC,wBAAwB,iBAAgB;AAErD,OAAO,MAAMC,oBAA8B;IACzC,MAAM,EAAEC,aAAa,EAAE,GAAGP;IAE1B,MAAMQ,SAASX;IACf,MAAMY,SAASR;IAEf,MAAM,EACJS,OAAO,EACLC,QAAQ,EAAEC,QAAQC,WAAW,EAAE,EAChC,EACDF,QAAQ,EAAED,OAAOI,UAAU,EAAE,EAC9B,GAAGL;IAEJ,MAAM,EAAEM,WAAW,EAAE,GAAGnB;IACxB,MAAM,EAAEoB,CAAC,EAAE,GAAGd;IAEd,qBACE,KAACP;QAAMsB,WAAWb;QAAWc,MAAMb;kBACjC,cAAA,MAACc;YAAIF,WAAW,CAAC,EAAEb,UAAU,SAAS,CAAC;;8BACrC,MAACe;oBAAIF,WAAW,CAAC,EAAEb,UAAU,SAAS,CAAC;;sCACrC,KAACgB;sCAAIJ,EAAE;;sCACP,KAACK;sCAAGL,EAAE;;;;8BAER,MAACG;oBAAIF,WAAW,CAAC,EAAEb,UAAU,UAAU,CAAC;;sCACtC,KAACL;4BACCuB,aAAY;4BACZC,SAAS;gCACPR,YAAYV;gCACZG,OAAOgB,IAAI,CACTrB,eAAe;oCACbW;oCACAW,MAAMZ;gCACR;4BAEJ;sCAECG,EAAE;;sCAEL,KAACjB;4BACCwB,SAAS;gCACPhB;gCACAQ,YAAYV;4BACd;sCAECW,EAAE;;;;;;;AAMf,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/Table/DefaultCell/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAA6B,MAAM,SAAS,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/Table/DefaultCell/index.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAA6B,MAAM,SAAS,CAAA;AAa5E,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAsHpD,CAAA"}
|
|
@@ -5,6 +5,7 @@ import React from 'react'; // TODO: abstract this out to support all routers
|
|
|
5
5
|
import { getTranslation } from '@payloadcms/translations';
|
|
6
6
|
import { useConfig } from '../../../providers/Config/index.js';
|
|
7
7
|
import { useTranslation } from '../../../providers/Translation/index.js';
|
|
8
|
+
import { formatAdminURL } from '../../../utilities/formatAdminURL.js';
|
|
8
9
|
import { useTableCell } from '../TableCellProvider/index.js';
|
|
9
10
|
import { CodeCell } from './fields/Code/index.js';
|
|
10
11
|
import { cellComponents } from './fields/index.js';
|
|
@@ -25,7 +26,10 @@ export const DefaultCell = (props)=>{
|
|
|
25
26
|
const isLink = link !== undefined ? link : columnIndex === 0;
|
|
26
27
|
if (isLink) {
|
|
27
28
|
WrapElement = Link;
|
|
28
|
-
wrapElementProps.href = customCellContext?.collectionSlug ?
|
|
29
|
+
wrapElementProps.href = customCellContext?.collectionSlug ? formatAdminURL({
|
|
30
|
+
adminRoute,
|
|
31
|
+
path: `/collections/${customCellContext?.collectionSlug}/${rowData.id}`
|
|
32
|
+
}) : '';
|
|
29
33
|
}
|
|
30
34
|
if (typeof onClick === 'function') {
|
|
31
35
|
WrapElement = 'button';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/elements/Table/DefaultCell/index.tsx"],"sourcesContent":["'use client'\nimport LinkImport from 'next/link.js'\nimport React from 'react' // TODO: abstract this out to support all routers\n\nimport type { CellComponentProps, DefaultCellComponentProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport { useConfig } from '../../../providers/Config/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport { useTableCell } from '../TableCellProvider/index.js'\nimport { CodeCell } from './fields/Code/index.js'\nimport { cellComponents } from './fields/index.js'\n\nconst Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default\n\nexport const DefaultCell: React.FC<CellComponentProps> = (props) => {\n const {\n name,\n className: classNameFromProps,\n fieldType,\n isFieldAffectingData,\n label,\n onClick: onClickFromProps,\n } = props\n\n const { i18n } = useTranslation()\n\n const {\n routes: { admin: adminRoute },\n } = useConfig()\n\n const cellContext = useTableCell()\n\n const { cellData, cellProps, columnIndex, customCellContext, rowData } = cellContext || {}\n\n const { className: classNameFromContext, link, onClick: onClickFromContext } = cellProps || {}\n\n const className = classNameFromProps || classNameFromContext\n\n const onClick = onClickFromProps || onClickFromContext\n\n let WrapElement: React.ComponentType<any> | string = 'span'\n\n const wrapElementProps: {\n className?: string\n href?: string\n onClick?: () => void\n type?: 'button'\n } = {\n className,\n }\n\n const isLink = link !== undefined ? link : columnIndex === 0\n\n if (isLink) {\n WrapElement = Link\n wrapElementProps.href = customCellContext?.collectionSlug\n ?
|
|
1
|
+
{"version":3,"sources":["../../../../src/elements/Table/DefaultCell/index.tsx"],"sourcesContent":["'use client'\nimport LinkImport from 'next/link.js'\nimport React from 'react' // TODO: abstract this out to support all routers\n\nimport type { CellComponentProps, DefaultCellComponentProps } from 'payload'\n\nimport { getTranslation } from '@payloadcms/translations'\n\nimport { useConfig } from '../../../providers/Config/index.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport { formatAdminURL } from '../../../utilities/formatAdminURL.js'\nimport { useTableCell } from '../TableCellProvider/index.js'\nimport { CodeCell } from './fields/Code/index.js'\nimport { cellComponents } from './fields/index.js'\n\nconst Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default\n\nexport const DefaultCell: React.FC<CellComponentProps> = (props) => {\n const {\n name,\n className: classNameFromProps,\n fieldType,\n isFieldAffectingData,\n label,\n onClick: onClickFromProps,\n } = props\n\n const { i18n } = useTranslation()\n\n const {\n routes: { admin: adminRoute },\n } = useConfig()\n\n const cellContext = useTableCell()\n\n const { cellData, cellProps, columnIndex, customCellContext, rowData } = cellContext || {}\n\n const { className: classNameFromContext, link, onClick: onClickFromContext } = cellProps || {}\n\n const className = classNameFromProps || classNameFromContext\n\n const onClick = onClickFromProps || onClickFromContext\n\n let WrapElement: React.ComponentType<any> | string = 'span'\n\n const wrapElementProps: {\n className?: string\n href?: string\n onClick?: () => void\n type?: 'button'\n } = {\n className,\n }\n\n const isLink = link !== undefined ? link : columnIndex === 0\n\n if (isLink) {\n WrapElement = Link\n wrapElementProps.href = customCellContext?.collectionSlug\n ? formatAdminURL({\n adminRoute,\n path: `/collections/${customCellContext?.collectionSlug}/${rowData.id}`,\n })\n : ''\n }\n\n if (typeof onClick === 'function') {\n WrapElement = 'button'\n wrapElementProps.type = 'button'\n wrapElementProps.onClick = () => {\n onClick({\n cellData,\n collectionSlug: customCellContext?.collectionSlug,\n rowData,\n })\n }\n }\n\n if (name === 'id') {\n return (\n <WrapElement {...wrapElementProps}>\n <CodeCell\n cellData={`ID: ${cellData}`}\n name={name}\n nowrap\n rowData={rowData}\n schemaPath={cellContext?.cellProps?.schemaPath}\n />\n </WrapElement>\n )\n }\n\n const DefaultCellComponent: React.FC<DefaultCellComponentProps> =\n typeof cellData !== 'undefined' && cellComponents[fieldType]\n\n let CellComponent: React.ReactNode = null\n\n if (DefaultCellComponent) {\n CellComponent = (\n <DefaultCellComponent\n cellData={cellData}\n customCellContext={customCellContext}\n rowData={rowData}\n {...props}\n />\n )\n } else if (!DefaultCellComponent) {\n // DefaultCellComponent does not exist for certain field types like `text`\n if (customCellContext.uploadConfig && isFieldAffectingData && name === 'filename') {\n const FileCellComponent = cellComponents.File\n CellComponent = (\n <FileCellComponent\n cellData={cellData}\n customCellContext={customCellContext}\n rowData={rowData}\n {...props}\n />\n )\n } else {\n return (\n <WrapElement {...wrapElementProps}>\n {(cellData === '' || typeof cellData === 'undefined') &&\n 'label' in props &&\n i18n.t('general:noLabel', {\n label: getTranslation(label || 'data', i18n),\n })}\n {typeof cellData === 'string' && cellData}\n {typeof cellData === 'number' && cellData}\n {typeof cellData === 'object' && JSON.stringify(cellData)}\n </WrapElement>\n )\n }\n }\n\n return <WrapElement {...wrapElementProps}>{CellComponent}</WrapElement>\n}\n"],"names":["LinkImport","React","getTranslation","useConfig","useTranslation","formatAdminURL","useTableCell","CodeCell","cellComponents","Link","default","DefaultCell","props","name","className","classNameFromProps","fieldType","isFieldAffectingData","label","onClick","onClickFromProps","i18n","routes","admin","adminRoute","cellContext","cellData","cellProps","columnIndex","customCellContext","rowData","classNameFromContext","link","onClickFromContext","WrapElement","wrapElementProps","isLink","undefined","href","collectionSlug","path","id","type","nowrap","schemaPath","DefaultCellComponent","CellComponent","uploadConfig","FileCellComponent","File","t","JSON","stringify"],"mappings":"AAAA;;AACA,OAAOA,gBAAgB,eAAc;AACrC,OAAOC,WAAW,QAAO,CAAC,iDAAiD;AAI3E,SAASC,cAAc,QAAQ,2BAA0B;AAEzD,SAASC,SAAS,QAAQ,qCAAoC;AAC9D,SAASC,cAAc,QAAQ,0CAAyC;AACxE,SAASC,cAAc,QAAQ,uCAAsC;AACrE,SAASC,YAAY,QAAQ,gCAA+B;A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AAC5B;gBACCmB,UAAU,CAAC,IAAI,EAAEA,SAAS,CAAC;gBAC3Bb,MAAMA;gBACN8B,MAAM;gBACNb,SAASA;gBACTc,YAAYnB,aAAaE,WAAWiB;;;IAI5C;IAEA,MAAMC,uBACJ,OAAOnB,aAAa,eAAelB,cAAc,CAACQ,UAAU;IAE9D,IAAI8B,gBAAiC;IAErC,IAAID,sBAAsB;QACxBC,8BACE,KAACD;YACCnB,UAAUA;YACVG,mBAAmBA;YACnBC,SAASA;YACR,GAAGlB,KAAK;;IAGf,OAAO,IAAI,CAACiC,sBAAsB;QAChC,0EAA0E;QAC1E,IAAIhB,kBAAkBkB,YAAY,IAAI9B,wBAAwBJ,SAAS,YAAY;YACjF,MAAMmC,oBAAoBxC,eAAeyC,IAAI;YAC7CH,8BACE,KAACE;gBACCtB,UAAUA;gBACVG,mBAAmBA;gBACnBC,SAASA;gBACR,GAAGlB,KAAK;;QAGf,OAAO;YACL,qBACE,MAACsB;gBAAa,GAAGC,gBAAgB;;oBAC7BT,CAAAA,aAAa,MAAM,OAAOA,aAAa,WAAU,KACjD,WAAWd,SACXS,KAAK6B,CAAC,CAAC,mBAAmB;wBACxBhC,OAAOhB,eAAegB,SAAS,QAAQG;oBACzC;oBACD,OAAOK,aAAa,YAAYA;oBAChC,OAAOA,aAAa,YAAYA;oBAChC,OAAOA,aAAa,YAAYyB,KAAKC,SAAS,CAAC1B;;;QAGtD;IACF;IAEA,qBAAO,KAACQ;QAAa,GAAGC,gBAAgB;kBAAGW;;AAC7C,EAAC"}
|
|
@@ -129,7 +129,7 @@ export const RelationshipField = (props)=>{
|
|
|
129
129
|
options.forEach((opt)=>{
|
|
130
130
|
if (opt.options) {
|
|
131
131
|
opt.options.some((subOpt)=>{
|
|
132
|
-
if (subOpt?.value
|
|
132
|
+
if (subOpt?.value == val.value) {
|
|
133
133
|
matchedOption = subOpt;
|
|
134
134
|
return true;
|
|
135
135
|
}
|
|
@@ -139,7 +139,7 @@ export const RelationshipField = (props)=>{
|
|
|
139
139
|
});
|
|
140
140
|
return matchedOption;
|
|
141
141
|
}
|
|
142
|
-
return options.find((opt)=>opt.value
|
|
142
|
+
return options.find((opt)=>opt.value == val);
|
|
143
143
|
});
|
|
144
144
|
}
|
|
145
145
|
return undefined;
|
|
@@ -150,7 +150,7 @@ export const RelationshipField = (props)=>{
|
|
|
150
150
|
options.forEach((opt)=>{
|
|
151
151
|
if (opt?.options) {
|
|
152
152
|
opt.options.some((subOpt)=>{
|
|
153
|
-
if (subOpt?.value
|
|
153
|
+
if (subOpt?.value == valueWithRelation.value) {
|
|
154
154
|
matchedOption = subOpt;
|
|
155
155
|
return true;
|
|
156
156
|
}
|
|
@@ -160,7 +160,7 @@ export const RelationshipField = (props)=>{
|
|
|
160
160
|
});
|
|
161
161
|
return matchedOption;
|
|
162
162
|
}
|
|
163
|
-
return options.find((opt)=>opt.value
|
|
163
|
+
return options.find((opt)=>opt.value == value);
|
|
164
164
|
}
|
|
165
165
|
return undefined;
|
|
166
166
|
}, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../src/elements/WhereBuilder/Condition/Relationship/index.tsx"],"sourcesContent":["'use client'\nimport type { PaginatedDocs, Where } from 'payload'\n\nimport * as qs from 'qs-esm'\nimport React, { useCallback, useEffect, useReducer, useState } from 'react'\n\nimport type { Option } from '../../../ReactSelect/types.js'\nimport type { Props, ValueWithRelation } from './types.js'\n\nimport { useDebounce } from '../../../../hooks/useDebounce.js'\nimport { useConfig } from '../../../../providers/Config/index.js'\nimport { useTranslation } from '../../../../providers/Translation/index.js'\nimport { ReactSelect } from '../../../ReactSelect/index.js'\nimport './index.scss'\nimport optionsReducer from './optionsReducer.js'\n\nconst baseClass = 'condition-value-relationship'\n\nconst maxResultsPerRequest = 10\n\nexport const RelationshipField: React.FC<Props> = (props) => {\n const { admin: { isSortable } = {}, disabled, hasMany, onChange, relationTo, value } = props\n\n const {\n collections,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const hasMultipleRelations = Array.isArray(relationTo)\n const [options, dispatchOptions] = useReducer(optionsReducer, [])\n const [search, setSearch] = useState('')\n const [errorLoading, setErrorLoading] = useState('')\n const [hasLoadedFirstOptions, setHasLoadedFirstOptions] = useState(false)\n const debouncedSearch = useDebounce(search, 300)\n const { i18n, t } = useTranslation()\n const relationSlugs = hasMultipleRelations ? relationTo : [relationTo]\n const initialRelationMap = () => {\n const map: Map<string, number> = new Map()\n relationSlugs.forEach((relation) => {\n map.set(relation, 1)\n })\n return map\n }\n const nextPageByRelationshipRef = React.useRef<Map<string, number>>(initialRelationMap())\n const partiallyLoadedRelationshipSlugs = React.useRef<string[]>(relationSlugs)\n\n const addOptions = useCallback(\n (data, relation) => {\n const collection = collections.find((coll) => coll.slug === relation)\n dispatchOptions({ type: 'ADD', collection, data, hasMultipleRelations, i18n, relation })\n },\n [collections, hasMultipleRelations, i18n],\n )\n\n const loadRelationOptions = React.useCallback(\n async ({\n abortController,\n relationSlug,\n }: {\n abortController: AbortController\n relationSlug: string\n }) => {\n const collection = collections.find((coll) => coll.slug === relationSlug)\n const fieldToSearch = collection?.admin?.useAsTitle || 'id'\n const pageIndex = nextPageByRelationshipRef.current.get(relationSlug)\n\n if (partiallyLoadedRelationshipSlugs.current.includes(relationSlug)) {\n const query: {\n depth?: number\n limit?: number\n page?: number\n where: Where\n } = {\n depth: 0,\n limit: maxResultsPerRequest,\n page: pageIndex,\n where: {\n and: [],\n },\n }\n\n if (debouncedSearch) {\n query.where.and.push({\n [fieldToSearch]: {\n like: debouncedSearch,\n },\n })\n }\n\n try {\n const response = await fetch(\n `${serverURL}${api}/${relationSlug}${qs.stringify(query, { addQueryPrefix: true })}`,\n {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n signal: abortController.signal,\n },\n )\n\n if (response.ok) {\n const data: PaginatedDocs = await response.json()\n if (data.docs.length > 0) {\n addOptions(data, relationSlug)\n\n if (!debouncedSearch) {\n if (data.nextPage) {\n nextPageByRelationshipRef.current.set(relationSlug, data.nextPage)\n } else {\n partiallyLoadedRelationshipSlugs.current =\n partiallyLoadedRelationshipSlugs.current.filter(\n (partiallyLoadedRelation) => partiallyLoadedRelation !== relationSlug,\n )\n }\n }\n }\n } else {\n setErrorLoading(t('error:unspecific'))\n }\n } catch (e) {\n if (!abortController.signal.aborted) {\n console.error(e)\n }\n }\n }\n\n setHasLoadedFirstOptions(true)\n },\n [addOptions, api, collections, debouncedSearch, i18n.language, serverURL, t],\n )\n\n const loadMoreOptions = React.useCallback(() => {\n if (partiallyLoadedRelationshipSlugs.current.length > 0) {\n const abortController = new AbortController()\n void loadRelationOptions({\n abortController,\n relationSlug: partiallyLoadedRelationshipSlugs.current[0],\n })\n }\n }, [loadRelationOptions])\n\n const findOptionsByValue = useCallback((): Option | Option[] => {\n if (value) {\n if (hasMany) {\n if (Array.isArray(value)) {\n return value.map((val) => {\n if (hasMultipleRelations) {\n let matchedOption: Option\n\n options.forEach((opt) => {\n if (opt.options) {\n opt.options.some((subOpt) => {\n if (subOpt?.value === val.value) {\n matchedOption = subOpt\n return true\n }\n\n return false\n })\n }\n })\n\n return matchedOption\n }\n\n return options.find((opt) => opt.value === val)\n })\n }\n\n return undefined\n }\n\n if (hasMultipleRelations) {\n let matchedOption: Option\n\n const valueWithRelation = value as ValueWithRelation\n\n options.forEach((opt) => {\n if (opt?.options) {\n opt.options.some((subOpt) => {\n if (subOpt?.value === valueWithRelation.value) {\n matchedOption = subOpt\n return true\n }\n return false\n })\n }\n })\n\n return matchedOption\n }\n\n return options.find((opt) => opt.value === value)\n }\n\n return undefined\n }, [hasMany, hasMultipleRelations, value, options])\n\n const handleInputChange = useCallback(\n (newSearch) => {\n if (search !== newSearch) {\n setSearch(newSearch)\n }\n },\n [search],\n )\n\n const addOptionByID = useCallback(\n async (id, relation) => {\n if (!errorLoading && id !== 'null' && id && relation) {\n const response = await fetch(`${serverURL}${api}/${relation}/${id}?depth=0`, {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n\n if (response.ok) {\n const data = await response.json()\n addOptions({ docs: [data] }, relation)\n } else {\n // eslint-disable-next-line no-console\n console.error(t('error:loadingDocument', { id }))\n }\n }\n },\n [i18n, addOptions, api, errorLoading, serverURL, t],\n )\n\n /**\n * 1. Trigger initial relationship options fetch\n * 2. When search changes, loadRelationOptions will\n * fire off again\n */\n useEffect(() => {\n const relations = Array.isArray(relationTo) ? relationTo : [relationTo]\n const abortControllers: AbortController[] = []\n relations.forEach((relation) => {\n const abortController = new AbortController()\n void loadRelationOptions({\n abortController,\n relationSlug: relation,\n })\n abortControllers.push(abortController)\n })\n\n return () => {\n abortControllers.forEach((controller) => {\n if (controller.signal) controller.abort()\n })\n }\n }, [i18n, loadRelationOptions, relationTo])\n\n /**\n * Load any options that were not returned\n * in the first 10 of each relation fetch\n */\n useEffect(() => {\n if (value && hasLoadedFirstOptions) {\n if (hasMany) {\n const matchedOptions = findOptionsByValue()\n\n ;((matchedOptions as Option[]) || []).forEach((option, i) => {\n if (!option) {\n if (hasMultipleRelations) {\n void addOptionByID(value[i].value, value[i].relationTo)\n } else {\n void addOptionByID(value[i], relationTo)\n }\n }\n })\n } else {\n const matchedOption = findOptionsByValue()\n\n if (!matchedOption) {\n if (hasMultipleRelations) {\n const valueWithRelation = value as ValueWithRelation\n void addOptionByID(valueWithRelation.value, valueWithRelation.relationTo)\n } else {\n void addOptionByID(value, relationTo)\n }\n }\n }\n }\n }, [\n addOptionByID,\n findOptionsByValue,\n hasMany,\n hasMultipleRelations,\n relationTo,\n value,\n hasLoadedFirstOptions,\n ])\n\n const classes = ['field-type', baseClass, errorLoading && 'error-loading']\n .filter(Boolean)\n .join(' ')\n\n const valueToRender = (findOptionsByValue() || value) as Option\n\n return (\n <div className={classes}>\n {!errorLoading && (\n <ReactSelect\n disabled={disabled}\n isMulti={hasMany}\n isSortable={isSortable}\n onChange={(selected) => {\n if (!selected) {\n onChange(null)\n return\n }\n if (hasMany && Array.isArray(selected)) {\n onChange(\n selected\n ? selected.map((option) => {\n if (hasMultipleRelations) {\n return {\n relationTo: option?.relationTo,\n value: option?.value,\n }\n }\n\n return option?.value\n })\n : null,\n )\n } else if (hasMultipleRelations && !Array.isArray(selected)) {\n onChange({\n relationTo: selected?.relationTo,\n value: selected?.value,\n })\n } else if (!Array.isArray(selected)) {\n onChange(selected?.value)\n }\n }}\n onInputChange={handleInputChange}\n onMenuScrollToBottom={loadMoreOptions}\n options={options}\n placeholder={t('general:selectValue')}\n value={valueToRender}\n />\n )}\n {errorLoading && <div className={`${baseClass}__error-loading`}>{errorLoading}</div>}\n </div>\n )\n}\n"],"names":["qs","React","useCallback","useEffect","useReducer","useState","useDebounce","useConfig","useTranslation","ReactSelect","optionsReducer","baseClass","maxResultsPerRequest","RelationshipField","props","admin","isSortable","disabled","hasMany","onChange","relationTo","value","collections","routes","api","serverURL","hasMultipleRelations","Array","isArray","options","dispatchOptions","search","setSearch","errorLoading","setErrorLoading","hasLoadedFirstOptions","setHasLoadedFirstOptions","debouncedSearch","i18n","t","relationSlugs","initialRelationMap","map","Map","forEach","relation","set","nextPageByRelationshipRef","useRef","partiallyLoadedRelationshipSlugs","addOptions","data","collection","find","coll","slug","type","loadRelationOptions","abortController","relationSlug","fieldToSearch","useAsTitle","pageIndex","current","get","includes","query","depth","limit","page","where","and","push","like","response","fetch","stringify","addQueryPrefix","credentials","headers","language","signal","ok","json","docs","length","nextPage","filter","partiallyLoadedRelation","e","aborted","console","error","loadMoreOptions","AbortController","findOptionsByValue","val","matchedOption","opt","some","subOpt","undefined","valueWithRelation","handleInputChange","newSearch","addOptionByID","id","relations","abortControllers","controller","abort","matchedOptions","option","i","classes","Boolean","join","valueToRender","div","className","isMulti","selected","onInputChange","onMenuScrollToBottom","placeholder"],"mappings":"AAAA;;AAGA,YAAYA,QAAQ,SAAQ;AAC5B,OAAOC,SAASC,WAAW,EAAEC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,QAAO;AAK3E,SAASC,WAA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WAAWL;;YACb,CAACjF,8BACA,KAACxB;gBACCQ,UAAUA;gBACVuG,SAAStG;gBACTF,YAAYA;gBACZG,UAAU,CAACsG;oBACT,IAAI,CAACA,UAAU;wBACbtG,SAAS;wBACT;oBACF;oBACA,IAAID,WAAWS,MAAMC,OAAO,CAAC6F,WAAW;wBACtCtG,SACEsG,WACIA,SAAS/E,GAAG,CAAC,CAACsE;4BACZ,IAAItF,sBAAsB;gCACxB,OAAO;oCACLN,YAAY4F,QAAQ5F;oCACpBC,OAAO2F,QAAQ3F;gCACjB;4BACF;4BAEA,OAAO2F,QAAQ3F;wBACjB,KACA;oBAER,OAAO,IAAIK,wBAAwB,CAACC,MAAMC,OAAO,CAAC6F,WAAW;wBAC3DtG,SAAS;4BACPC,YAAYqG,UAAUrG;4BACtBC,OAAOoG,UAAUpG;wBACnB;oBACF,OAAO,IAAI,CAACM,MAAMC,OAAO,CAAC6F,WAAW;wBACnCtG,SAASsG,UAAUpG;oBACrB;gBACF;gBACAqG,eAAenB;gBACfoB,sBAAsB9B;gBACtBhE,SAASA;gBACT+F,aAAarF,EAAE;gBACflB,OAAOgG;;YAGVpF,8BAAgB,KAACqF;gBAAIC,WAAW,CAAC,EAAE5G,UAAU,eAAe,CAAC;0BAAGsB;;;;AAGvE,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../../../src/elements/WhereBuilder/Condition/Relationship/index.tsx"],"sourcesContent":["'use client'\nimport type { PaginatedDocs, Where } from 'payload'\n\nimport * as qs from 'qs-esm'\nimport React, { useCallback, useEffect, useReducer, useState } from 'react'\n\nimport type { Option } from '../../../ReactSelect/types.js'\nimport type { Props, ValueWithRelation } from './types.js'\n\nimport { useDebounce } from '../../../../hooks/useDebounce.js'\nimport { useConfig } from '../../../../providers/Config/index.js'\nimport { useTranslation } from '../../../../providers/Translation/index.js'\nimport { ReactSelect } from '../../../ReactSelect/index.js'\nimport './index.scss'\nimport optionsReducer from './optionsReducer.js'\n\nconst baseClass = 'condition-value-relationship'\n\nconst maxResultsPerRequest = 10\n\nexport const RelationshipField: React.FC<Props> = (props) => {\n const { admin: { isSortable } = {}, disabled, hasMany, onChange, relationTo, value } = props\n\n const {\n collections,\n routes: { api },\n serverURL,\n } = useConfig()\n\n const hasMultipleRelations = Array.isArray(relationTo)\n const [options, dispatchOptions] = useReducer(optionsReducer, [])\n const [search, setSearch] = useState('')\n const [errorLoading, setErrorLoading] = useState('')\n const [hasLoadedFirstOptions, setHasLoadedFirstOptions] = useState(false)\n const debouncedSearch = useDebounce(search, 300)\n const { i18n, t } = useTranslation()\n const relationSlugs = hasMultipleRelations ? relationTo : [relationTo]\n const initialRelationMap = () => {\n const map: Map<string, number> = new Map()\n relationSlugs.forEach((relation) => {\n map.set(relation, 1)\n })\n return map\n }\n const nextPageByRelationshipRef = React.useRef<Map<string, number>>(initialRelationMap())\n const partiallyLoadedRelationshipSlugs = React.useRef<string[]>(relationSlugs)\n\n const addOptions = useCallback(\n (data, relation) => {\n const collection = collections.find((coll) => coll.slug === relation)\n dispatchOptions({ type: 'ADD', collection, data, hasMultipleRelations, i18n, relation })\n },\n [collections, hasMultipleRelations, i18n],\n )\n\n const loadRelationOptions = React.useCallback(\n async ({\n abortController,\n relationSlug,\n }: {\n abortController: AbortController\n relationSlug: string\n }) => {\n const collection = collections.find((coll) => coll.slug === relationSlug)\n const fieldToSearch = collection?.admin?.useAsTitle || 'id'\n const pageIndex = nextPageByRelationshipRef.current.get(relationSlug)\n\n if (partiallyLoadedRelationshipSlugs.current.includes(relationSlug)) {\n const query: {\n depth?: number\n limit?: number\n page?: number\n where: Where\n } = {\n depth: 0,\n limit: maxResultsPerRequest,\n page: pageIndex,\n where: {\n and: [],\n },\n }\n\n if (debouncedSearch) {\n query.where.and.push({\n [fieldToSearch]: {\n like: debouncedSearch,\n },\n })\n }\n\n try {\n const response = await fetch(\n `${serverURL}${api}/${relationSlug}${qs.stringify(query, { addQueryPrefix: true })}`,\n {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n signal: abortController.signal,\n },\n )\n\n if (response.ok) {\n const data: PaginatedDocs = await response.json()\n if (data.docs.length > 0) {\n addOptions(data, relationSlug)\n\n if (!debouncedSearch) {\n if (data.nextPage) {\n nextPageByRelationshipRef.current.set(relationSlug, data.nextPage)\n } else {\n partiallyLoadedRelationshipSlugs.current =\n partiallyLoadedRelationshipSlugs.current.filter(\n (partiallyLoadedRelation) => partiallyLoadedRelation !== relationSlug,\n )\n }\n }\n }\n } else {\n setErrorLoading(t('error:unspecific'))\n }\n } catch (e) {\n if (!abortController.signal.aborted) {\n console.error(e)\n }\n }\n }\n\n setHasLoadedFirstOptions(true)\n },\n [addOptions, api, collections, debouncedSearch, i18n.language, serverURL, t],\n )\n\n const loadMoreOptions = React.useCallback(() => {\n if (partiallyLoadedRelationshipSlugs.current.length > 0) {\n const abortController = new AbortController()\n void loadRelationOptions({\n abortController,\n relationSlug: partiallyLoadedRelationshipSlugs.current[0],\n })\n }\n }, [loadRelationOptions])\n\n const findOptionsByValue = useCallback((): Option | Option[] => {\n if (value) {\n if (hasMany) {\n if (Array.isArray(value)) {\n return value.map((val) => {\n if (hasMultipleRelations) {\n let matchedOption: Option\n\n options.forEach((opt) => {\n if (opt.options) {\n opt.options.some((subOpt) => {\n if (subOpt?.value == val.value) {\n matchedOption = subOpt\n return true\n }\n\n return false\n })\n }\n })\n\n return matchedOption\n }\n\n return options.find((opt) => opt.value == val)\n })\n }\n\n return undefined\n }\n\n if (hasMultipleRelations) {\n let matchedOption: Option\n\n const valueWithRelation = value as ValueWithRelation\n\n options.forEach((opt) => {\n if (opt?.options) {\n opt.options.some((subOpt) => {\n if (subOpt?.value == valueWithRelation.value) {\n matchedOption = subOpt\n return true\n }\n return false\n })\n }\n })\n\n return matchedOption\n }\n\n return options.find((opt) => opt.value == value)\n }\n\n return undefined\n }, [hasMany, hasMultipleRelations, value, options])\n\n const handleInputChange = useCallback(\n (newSearch) => {\n if (search !== newSearch) {\n setSearch(newSearch)\n }\n },\n [search],\n )\n\n const addOptionByID = useCallback(\n async (id, relation) => {\n if (!errorLoading && id !== 'null' && id && relation) {\n const response = await fetch(`${serverURL}${api}/${relation}/${id}?depth=0`, {\n credentials: 'include',\n headers: {\n 'Accept-Language': i18n.language,\n },\n })\n\n if (response.ok) {\n const data = await response.json()\n addOptions({ docs: [data] }, relation)\n } else {\n // eslint-disable-next-line no-console\n console.error(t('error:loadingDocument', { id }))\n }\n }\n },\n [i18n, addOptions, api, errorLoading, serverURL, t],\n )\n\n /**\n * 1. Trigger initial relationship options fetch\n * 2. When search changes, loadRelationOptions will\n * fire off again\n */\n useEffect(() => {\n const relations = Array.isArray(relationTo) ? relationTo : [relationTo]\n const abortControllers: AbortController[] = []\n relations.forEach((relation) => {\n const abortController = new AbortController()\n void loadRelationOptions({\n abortController,\n relationSlug: relation,\n })\n abortControllers.push(abortController)\n })\n\n return () => {\n abortControllers.forEach((controller) => {\n if (controller.signal) controller.abort()\n })\n }\n }, [i18n, loadRelationOptions, relationTo])\n\n /**\n * Load any options that were not returned\n * in the first 10 of each relation fetch\n */\n useEffect(() => {\n if (value && hasLoadedFirstOptions) {\n if (hasMany) {\n const matchedOptions = findOptionsByValue()\n\n ;((matchedOptions as Option[]) || []).forEach((option, i) => {\n if (!option) {\n if (hasMultipleRelations) {\n void addOptionByID(value[i].value, value[i].relationTo)\n } else {\n void addOptionByID(value[i], relationTo)\n }\n }\n })\n } else {\n const matchedOption = findOptionsByValue()\n\n if (!matchedOption) {\n if (hasMultipleRelations) {\n const valueWithRelation = value as ValueWithRelation\n void addOptionByID(valueWithRelation.value, valueWithRelation.relationTo)\n } else {\n void addOptionByID(value, relationTo)\n }\n }\n }\n }\n }, [\n addOptionByID,\n findOptionsByValue,\n hasMany,\n hasMultipleRelations,\n relationTo,\n value,\n hasLoadedFirstOptions,\n ])\n\n const classes = ['field-type', baseClass, errorLoading && 'error-loading']\n .filter(Boolean)\n .join(' ')\n\n const valueToRender = (findOptionsByValue() || value) as Option\n\n return (\n <div className={classes}>\n {!errorLoading && (\n <ReactSelect\n disabled={disabled}\n isMulti={hasMany}\n isSortable={isSortable}\n onChange={(selected) => {\n if (!selected) {\n onChange(null)\n return\n }\n if (hasMany && Array.isArray(selected)) {\n onChange(\n selected\n ? selected.map((option) => {\n if (hasMultipleRelations) {\n return {\n relationTo: option?.relationTo,\n value: option?.value,\n }\n }\n\n return option?.value\n })\n : null,\n )\n } else if (hasMultipleRelations && !Array.isArray(selected)) {\n onChange({\n relationTo: selected?.relationTo,\n value: selected?.value,\n })\n } else if (!Array.isArray(selected)) {\n onChange(selected?.value)\n }\n }}\n onInputChange={handleInputChange}\n onMenuScrollToBottom={loadMoreOptions}\n options={options}\n placeholder={t('general:selectValue')}\n value={valueToRender}\n />\n )}\n {errorLoading && <div className={`${baseClass}__error-loading`}>{errorLoading}</div>}\n </div>\n )\n}\n"],"names":["qs","React","useCallback","useEffect","useReducer","useState","useDebounce","useConfig","useTranslation","ReactSelect","optionsReducer","baseClass","maxResultsPerRequest","RelationshipField","props","admin","isSortable","disabled","hasMany","onChange","relationTo","value","collections","routes","api","serverURL","hasMultipleRelations","Array","isArray","options","dispatchOptions","search","setSearch","errorLoading","setErrorLoading","hasLoadedFirstOptions","setHasLoadedFirstOptions","debouncedSearch","i18n","t","relationSlugs","initialRelationMap","map","Map","forEach","relation","set","nextPageByRelationshipRef","useRef","partiallyLoadedRelationshipSlugs","addOptions","data","collection","find","coll","slug","type","loadRelationOptions","abortController","relationSlug","fieldToSearch","useAsTitle","pageIndex","current","get","includes","query","depth","limit","page","where","and","push","like","response","fetch","stringify","addQueryPrefix","credentials","headers","language","signal","ok","json","docs","length","nextPage","filter","partiallyLoadedRelation","e","aborted","console","error","loadMoreOptions","AbortController","findOptionsByValue","val","matchedOption","opt","some","subOpt","undefined","valueWithRelation","handleInputChange","newSearch","addOptionByID","id","relations","abortControllers","controller","abort","matchedOptions","option","i","classes","Boolean","join","valueToRender","div","className","isMulti","selected","onInputChange","onMenuScrollToB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E,UAAU;QAAC;QAAcvG;QAAWsB,gBAAgB;KAAgB,CACvEsD,MAAM,CAAC4B,SACPC,IAAI,CAAC;IAER,MAAMC,gBAAiBtB,wBAAwB1E;IAE/C,qBACE,MAACiG;QAAIC,WAAWL;;YACb,CAACjF,8BACA,KAACxB;gBACCQ,UAAUA;gBACVuG,SAAStG;gBACTF,YAAYA;gBACZG,UAAU,CAACsG;oBACT,IAAI,CAACA,UAAU;wBACbtG,SAAS;wBACT;oBACF;oBACA,IAAID,WAAWS,MAAMC,OAAO,CAAC6F,WAAW;wBACtCtG,SACEsG,WACIA,SAAS/E,GAAG,CAAC,CAACsE;4BACZ,IAAItF,sBAAsB;gCACxB,OAAO;oCACLN,YAAY4F,QAAQ5F;oCACpBC,OAAO2F,QAAQ3F;gCACjB;4BACF;4BAEA,OAAO2F,QAAQ3F;wBACjB,KACA;oBAER,OAAO,IAAIK,wBAAwB,CAACC,MAAMC,OAAO,CAAC6F,WAAW;wBAC3DtG,SAAS;4BACPC,YAAYqG,UAAUrG;4BACtBC,OAAOoG,UAAUpG;wBACnB;oBACF,OAAO,IAAI,CAACM,MAAMC,OAAO,CAAC6F,WAAW;wBACnCtG,SAASsG,UAAUpG;oBACrB;gBACF;gBACAqG,eAAenB;gBACfoB,sBAAsB9B;gBACtBhE,SAASA;gBACT+F,aAAarF,EAAE;gBACflB,OAAOgG;;YAGVpF,8BAAgB,KAACqF;gBAAIC,WAAW,CAAC,EAAE5G,UAAU,eAAe,CAAC;0BAAGsB;;;;AAGvE,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/elements/WhereBuilder/Condition/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAA8B,MAAM,OAAO,CAAA;AAElD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAEjD,MAAM,MAAM,KAAK,GAAG;IAClB,YAAY,EAAE,CAAC,EACb,QAAQ,EACR,SAA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E,MAAM,CAAA;QACf,QAAQ,EAAE,KAAK,GAAG,IAAI,CAAA;KACvB,KAAK,IAAI,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,YAAY,EAAE,MAAM,CAAA;IACpB,QAAQ,EAAE,QAAQ,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAA;IACvF,eAAe,EAAE,CAAC,EAChB,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,OAAO,EACP,KAAK,GACN,EAAE;QACD,QAAQ,EAAE,MAAM,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;QACjB,QAAQ,EAAE,MAAM,CAAA;QAChB,OAAO,EAAE,MAAM,CAAA;QACf,KAAK,EAAE,MAAM,CAAA;KACd,KAAK,IAAI,CAAA;CACX,CAAA;AAED,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAcvC,OAAO,cAAc,CAAA;AAarB,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAiJrC,CAAA"}
|
|
@@ -3,6 +3,7 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
3
3
|
import React, { useEffect, useState } from 'react';
|
|
4
4
|
import { RenderCustomClientComponent } from '../../../elements/RenderCustomClientComponent/index.js';
|
|
5
5
|
import { useDebounce } from '../../../hooks/useDebounce.js';
|
|
6
|
+
import { useTranslation } from '../../../providers/Translation/index.js';
|
|
6
7
|
import { Button } from '../../Button/index.js';
|
|
7
8
|
import { ReactSelect } from '../../ReactSelect/index.js';
|
|
8
9
|
import { DateField } from './Date/index.js';
|
|
@@ -22,6 +23,7 @@ const baseClass = 'condition';
|
|
|
22
23
|
export const Condition = (props)=>{
|
|
23
24
|
const { addCondition, andIndex, fieldName, fields, initialValue, operator, orIndex, removeCondition, updateCondition } = props;
|
|
24
25
|
const [internalField, setInternalField] = useState(()=>fields.find((field)=>fieldName === field.value));
|
|
26
|
+
const { t } = useTranslation();
|
|
25
27
|
const [internalOperatorOption, setInternalOperatorOption] = useState(operator);
|
|
26
28
|
const [internalQueryValue, setInternalQueryValue] = useState(initialValue);
|
|
27
29
|
const debouncedValue = useDebounce(internalQueryValue, 300);
|
|
@@ -55,8 +57,8 @@ export const Condition = (props)=>{
|
|
|
55
57
|
let valueOptions;
|
|
56
58
|
if (booleanSelect) {
|
|
57
59
|
valueOptions = [
|
|
58
|
-
'true',
|
|
59
|
-
'false'
|
|
60
|
+
t('general:true'),
|
|
61
|
+
t('general:false')
|
|
60
62
|
];
|
|
61
63
|
} else if (internalField?.props && 'options' in internalField.props) {
|
|
62
64
|
valueOptions = internalField.props.options;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/elements/WhereBuilder/Condition/index.tsx"],"sourcesContent":["'use client'\nimport React, { useEffect, useState } from 'react'\n\nimport type { FieldCondition } from '../types.js'\n\nexport type Props = {\n addCondition: ({\n andIndex,\n fieldName,\n orIndex,\n relation,\n }: {\n andIndex: number\n fieldName: string\n orIndex: number\n relation: 'and' | 'or'\n }) => void\n andIndex: number\n fieldName: string\n fields: FieldCondition[]\n initialValue: string\n operator: Operator\n orIndex: number\n removeCondition: ({ andIndex, orIndex }: { andIndex: number; orIndex: number }) => void\n updateCondition: ({\n andIndex,\n fieldName,\n operator,\n orIndex,\n value,\n }: {\n andIndex: number\n fieldName: string\n operator: string\n orIndex: number\n value: string\n }) => void\n}\n\nimport type { Operator } from 'payload'\n\nimport type { Option } from '../../ReactSelect/index.js'\n\nimport { RenderCustomClientComponent } from '../../../elements/RenderCustomClientComponent/index.js'\nimport { useDebounce } from '../../../hooks/useDebounce.js'\nimport { Button } from '../../Button/index.js'\nimport { ReactSelect } from '../../ReactSelect/index.js'\nimport { DateField } from './Date/index.js'\nimport { NumberField } from './Number/index.js'\nimport { RelationshipField } from './Relationship/index.js'\nimport { Select } from './Select/index.js'\nimport Text from './Text/index.js'\nimport './index.scss'\n\ntype ComponentType = 'Date' | 'Number' | 'Relationship' | 'Select' | 'Text'\nconst valueFields: Record<ComponentType, React.FC> = {\n Date: DateField,\n Number: NumberField,\n Relationship: RelationshipField,\n Select,\n Text,\n}\n\nconst baseClass = 'condition'\n\nexport const Condition: React.FC<Props> = (props) => {\n const {\n addCondition,\n andIndex,\n fieldName,\n fields,\n initialValue,\n operator,\n orIndex,\n removeCondition,\n updateCondition,\n } = props\n const [internalField, setInternalField] = useState<FieldCondition>(() =>\n fields.find((field) => fieldName === field.value),\n )\n const [internalOperatorOption, setInternalOperatorOption] = useState<Operator>(operator)\n const [internalQueryValue, setInternalQueryValue] = useState<string>(initialValue)\n\n const debouncedValue = useDebounce(internalQueryValue, 300)\n\n useEffect(() => {\n // This is to trigger changes when the debounced value changes\n if (\n (internalField?.value || typeof internalField?.value === 'number') &&\n internalOperatorOption &&\n ![null, undefined].includes(debouncedValue)\n ) {\n updateCondition({\n andIndex,\n fieldName: internalField.value,\n operator: internalOperatorOption,\n orIndex,\n value: debouncedValue,\n })\n }\n }, [\n debouncedValue,\n andIndex,\n internalField?.value,\n internalOperatorOption,\n orIndex,\n updateCondition,\n operator,\n ])\n\n const booleanSelect =\n ['exists'].includes(internalOperatorOption) || internalField?.props?.type === 'checkbox'\n const ValueComponent = booleanSelect\n ? Select\n : valueFields[internalField?.component] || valueFields.Text\n\n let valueOptions\n if (booleanSelect) {\n valueOptions = ['true', 'false']\n } else if (internalField?.props && 'options' in internalField.props) {\n valueOptions = internalField.props.options\n }\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__wrap`}>\n <div className={`${baseClass}__inputs`}>\n <div className={`${baseClass}__field`}>\n <ReactSelect\n isClearable={false}\n onChange={(field: Option) => {\n setInternalField(fields.find((f) => f.value === field.value))\n setInternalOperatorOption(undefined)\n setInternalQueryValue(undefined)\n }}\n options={fields}\n value={fields.find((field) => internalField?.value === field.value) || fields[0]}\n />\n </div>\n <div className={`${baseClass}__operator`}>\n <ReactSelect\n disabled={!internalField?.value && typeof internalField?.value !== 'number'}\n isClearable={false}\n onChange={(operator: Option<Operator>) => {\n setInternalOperatorOption(operator.value)\n }}\n options={internalField?.operators}\n value={\n internalField?.operators.find(\n (operator) => internalOperatorOption === operator.value,\n ) || null\n }\n />\n </div>\n <div className={`${baseClass}__value`}>\n <RenderCustomClientComponent\n CustomComponent={internalField?.props?.admin?.components?.Filter}\n DefaultComponent={ValueComponent}\n componentProps={{\n ...internalField?.props,\n disabled: !internalOperatorOption,\n onChange: setInternalQueryValue,\n operator: internalOperatorOption,\n options: valueOptions,\n relationTo:\n internalField?.props?.type === 'relationship' &&\n 'cellComponentProps' in internalField.props &&\n typeof internalField.props.cellComponentProps === 'object' &&\n 'relationTo' in internalField.props.cellComponentProps\n ? internalField.props.cellComponentProps?.relationTo\n : undefined,\n value: internalQueryValue ?? '',\n }}\n />\n </div>\n </div>\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__actions-remove`}\n icon=\"x\"\n iconStyle=\"with-border\"\n onClick={() =>\n removeCondition({\n andIndex,\n orIndex,\n })\n }\n round\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__actions-add`}\n icon=\"plus\"\n iconStyle=\"with-border\"\n onClick={() =>\n addCondition({\n andIndex: andIndex + 1,\n fieldName: fields[0].value,\n orIndex,\n relation: 'and',\n })\n }\n round\n />\n </div>\n </div>\n </div>\n )\n}\n"],"names":["React","useEffect","useState","RenderCustomClientComponent","useDebounce","Button","ReactSelect","DateField","NumberField","RelationshipField","Select","Text","valueFields","Date","Number","Relationship","baseClass","Condition","props","addCondition","andIndex","fieldName","fields","initialValue","operator","orIndex","removeCondition","updateCondition","internalField","setInternalField","find","field","value","internalOperatorOption","setInternalOperatorOption","internalQueryValue","setInternalQueryValue","debouncedValue","undefined","includes","booleanSelect","type","ValueComponent","component","valueOptions","options","div","className","isClearable","onChange","f","disabled","operators","CustomComponent","admin","components","Filter","DefaultComponent","componentProps","relationTo","cellComponentProps","buttonStyle","icon","iconStyle","onClick","round","relation"],"mappings":"AAAA;;AACA,OAAOA,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AA0ClD,SAASC,2BAA2B,QAAQ,yDAAwD;AACpG,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,MAAM,QAAQ,wBAAuB;AAC9C,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,SAASC,iBAAiB,QAAQ,0BAAyB;AAC3D,SAASC,MAAM,QAAQ,oBAAmB;AAC1C,OAAOC,UAAU,kBAAiB;AAClC,OAAO,eAAc;AAGrB,MAAMC,cAA+C;IACnDC,MAAMN;IACNO,QAAQN;IACRO,cAAcN;IACdC;IACAC;AACF;AAEA,MAAMK,YAAY;AAElB,OAAO,MAAMC,YAA6B,CAACC;IACzC,MAAM,EACJC,YAAY,EACZC,QAAQ,EACRC,SAAS,EACTC,MAAM,EACNC,YAAY,EACZC,QAAQ,EACRC,OAAO,EACPC,eAAe,EACfC,eAAe,EAChB,GAAGT;IACJ,MAAM,CAACU,eAAeC,iBAAiB,GAAG3B,SAAyB,IACjEoB,OAAOQ,IAAI,CAAC,CAACC,QAAUV,cAAcU,MAAMC,KAAK;IAElD,MAAM,CAACC,wBAAwBC,0BAA0B,GAAGhC,SAAmBsB;IAC/E,MAAM,CAACW,oBAAoBC,sBAAsB,GAAGlC,SAAiBqB;IAErE,MAAMc,iBAAiBjC,YAAY+B,oBAAoB;IAEvDlC,UAAU;QACR,8DAA8D;QAC9D,IACE,AAAC2B,CAAAA,eAAeI,SAAS,OAAOJ,eAAeI,UAA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"version":3,"sources":["../../../../src/elements/WhereBuilder/Condition/index.tsx"],"sourcesContent":["'use client'\nimport React, { useEffect, useState } from 'react'\n\nimport type { FieldCondition } from '../types.js'\n\nexport type Props = {\n addCondition: ({\n andIndex,\n fieldName,\n orIndex,\n relation,\n }: {\n andIndex: number\n fieldName: string\n orIndex: number\n relation: 'and' | 'or'\n }) => void\n andIndex: number\n fieldName: string\n fields: FieldCondition[]\n initialValue: string\n operator: Operator\n orIndex: number\n removeCondition: ({ andIndex, orIndex }: { andIndex: number; orIndex: number }) => void\n updateCondition: ({\n andIndex,\n fieldName,\n operator,\n orIndex,\n value,\n }: {\n andIndex: number\n fieldName: string\n operator: string\n orIndex: number\n value: string\n }) => void\n}\n\nimport type { Operator } from 'payload'\n\nimport type { Option } from '../../ReactSelect/index.js'\n\nimport { RenderCustomClientComponent } from '../../../elements/RenderCustomClientComponent/index.js'\nimport { useDebounce } from '../../../hooks/useDebounce.js'\nimport { useTranslation } from '../../../providers/Translation/index.js'\nimport { Button } from '../../Button/index.js'\nimport { ReactSelect } from '../../ReactSelect/index.js'\nimport { DateField } from './Date/index.js'\nimport { NumberField } from './Number/index.js'\nimport { RelationshipField } from './Relationship/index.js'\nimport { Select } from './Select/index.js'\nimport Text from './Text/index.js'\nimport './index.scss'\n\ntype ComponentType = 'Date' | 'Number' | 'Relationship' | 'Select' | 'Text'\nconst valueFields: Record<ComponentType, React.FC> = {\n Date: DateField,\n Number: NumberField,\n Relationship: RelationshipField,\n Select,\n Text,\n}\n\nconst baseClass = 'condition'\n\nexport const Condition: React.FC<Props> = (props) => {\n const {\n addCondition,\n andIndex,\n fieldName,\n fields,\n initialValue,\n operator,\n orIndex,\n removeCondition,\n updateCondition,\n } = props\n const [internalField, setInternalField] = useState<FieldCondition>(() =>\n fields.find((field) => fieldName === field.value),\n )\n const { t } = useTranslation()\n const [internalOperatorOption, setInternalOperatorOption] = useState<Operator>(operator)\n const [internalQueryValue, setInternalQueryValue] = useState<string>(initialValue)\n\n const debouncedValue = useDebounce(internalQueryValue, 300)\n\n useEffect(() => {\n // This is to trigger changes when the debounced value changes\n if (\n (internalField?.value || typeof internalField?.value === 'number') &&\n internalOperatorOption &&\n ![null, undefined].includes(debouncedValue)\n ) {\n updateCondition({\n andIndex,\n fieldName: internalField.value,\n operator: internalOperatorOption,\n orIndex,\n value: debouncedValue,\n })\n }\n }, [\n debouncedValue,\n andIndex,\n internalField?.value,\n internalOperatorOption,\n orIndex,\n updateCondition,\n operator,\n ])\n\n const booleanSelect =\n ['exists'].includes(internalOperatorOption) || internalField?.props?.type === 'checkbox'\n const ValueComponent = booleanSelect\n ? Select\n : valueFields[internalField?.component] || valueFields.Text\n\n let valueOptions\n if (booleanSelect) {\n valueOptions = [t('general:true'), t('general:false')]\n } else if (internalField?.props && 'options' in internalField.props) {\n valueOptions = internalField.props.options\n }\n\n return (\n <div className={baseClass}>\n <div className={`${baseClass}__wrap`}>\n <div className={`${baseClass}__inputs`}>\n <div className={`${baseClass}__field`}>\n <ReactSelect\n isClearable={false}\n onChange={(field: Option) => {\n setInternalField(fields.find((f) => f.value === field.value))\n setInternalOperatorOption(undefined)\n setInternalQueryValue(undefined)\n }}\n options={fields}\n value={fields.find((field) => internalField?.value === field.value) || fields[0]}\n />\n </div>\n <div className={`${baseClass}__operator`}>\n <ReactSelect\n disabled={!internalField?.value && typeof internalField?.value !== 'number'}\n isClearable={false}\n onChange={(operator: Option<Operator>) => {\n setInternalOperatorOption(operator.value)\n }}\n options={internalField?.operators}\n value={\n internalField?.operators.find(\n (operator) => internalOperatorOption === operator.value,\n ) || null\n }\n />\n </div>\n <div className={`${baseClass}__value`}>\n <RenderCustomClientComponent\n CustomComponent={internalField?.props?.admin?.components?.Filter}\n DefaultComponent={ValueComponent}\n componentProps={{\n ...internalField?.props,\n disabled: !internalOperatorOption,\n onChange: setInternalQueryValue,\n operator: internalOperatorOption,\n options: valueOptions,\n relationTo:\n internalField?.props?.type === 'relationship' &&\n 'cellComponentProps' in internalField.props &&\n typeof internalField.props.cellComponentProps === 'object' &&\n 'relationTo' in internalField.props.cellComponentProps\n ? internalField.props.cellComponentProps?.relationTo\n : undefined,\n value: internalQueryValue ?? '',\n }}\n />\n </div>\n </div>\n <div className={`${baseClass}__actions`}>\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__actions-remove`}\n icon=\"x\"\n iconStyle=\"with-border\"\n onClick={() =>\n removeCondition({\n andIndex,\n orIndex,\n })\n }\n round\n />\n <Button\n buttonStyle=\"icon-label\"\n className={`${baseClass}__actions-add`}\n icon=\"plus\"\n iconStyle=\"with-border\"\n onClick={() =>\n addCondition({\n andIndex: andIndex + 1,\n fieldName: fields[0].value,\n orIndex,\n relation: 'and',\n })\n }\n round\n />\n </div>\n </div>\n </div>\n )\n}\n"],"names":["React","useEffect","useState","RenderCustomClientComponent","useDebounce","useTranslation","Button","ReactSelect","DateField","NumberField","RelationshipField","Select","Text","valueFields","Date","Number","Relationship","baseClass","Condition","props","addCondition","andIndex","fieldName","fields","initialValue","operator","orIndex","removeCondition","updateCondition","internalField","setInternalField","find","field","value","t","internalOperatorOption","setInternalOperatorOption","internalQueryValue","setInternalQueryValue","debouncedValue","undefined","includes","booleanSelect","type","ValueComponent","component","valueOptions","options","div","className","isClearable","onChange","f","disabled","operators","CustomComponent","admin","components","Filter","DefaultComponent","componentProps","relationTo","cellComponentProps","buttonStyle","icon","iconStyle","onClick","round","relation"],"mappings":"AAAA;;AACA,OAAOA,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AA0ClD,SAASC,2BAA2B,QAAQ,yDAAwD;AACpG,SAASC,WAAW,QAAQ,gCAA+B;AAC3D,SAASC,cAAc,QAAQ,0CAAyC;AACxE,SAASC,MAAM,QAAQ,wBAAuB;AAC9C,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,kBAAiB;AAC3C,SAASC,WAAW,QAAQ,oBAAmB;AAC/C,SAASC,iBAAiB,QAAQ,0BAAyB;AAC3D,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