@payloadcms/plugin-search 3.24.0-canary.f229d8d → 3.25.0-canary.36940b2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"deleteFromSearch.d.ts","sourceRoot":"","sources":["../../../src/Search/hooks/deleteFromSearch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,eAAO,MAAM,gBAAgB,EAAE,gBAsC9B,CAAA"}
1
+ {"version":3,"file":"deleteFromSearch.d.ts","sourceRoot":"","sources":["../../../src/Search/hooks/deleteFromSearch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AAEtD,eAAO,MAAM,gBAAgB,EAAE,gBAwC9B,CAAA"}
@@ -4,6 +4,8 @@ export const deleteFromSearch = async ({ collection, doc, pluginConfig, req: { p
4
4
  const searchDocQuery = await payload.find({
5
5
  collection: searchSlug,
6
6
  depth: 0,
7
+ limit: 1,
8
+ pagination: false,
7
9
  req,
8
10
  where: {
9
11
  doc: {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/Search/hooks/deleteFromSearch.ts"],"sourcesContent":["import type { DeleteFromSearch } from '../../types.js'\n\nexport const deleteFromSearch: DeleteFromSearch = async ({\n collection,\n doc,\n pluginConfig,\n req: { payload },\n req,\n}) => {\n const searchSlug = pluginConfig?.searchOverrides?.slug || 'search'\n try {\n const searchDocQuery = await payload.find({\n collection: searchSlug,\n depth: 0,\n req,\n where: {\n doc: {\n equals: {\n relationTo: collection.slug,\n value: doc.id,\n },\n },\n },\n })\n\n if (searchDocQuery?.docs?.[0]) {\n await payload.delete({\n id: searchDocQuery?.docs?.[0]?.id,\n collection: searchSlug,\n req,\n })\n }\n } catch (err: unknown) {\n payload.logger.error({\n err,\n msg: `Error deleting ${searchSlug} doc.`,\n })\n }\n\n return doc\n}\n"],"names":["deleteFromSearch","collection","doc","pluginConfig","req","payload","searchSlug","searchOverrides","slug","searchDocQuery","find","depth","where","equals","relationTo","value","id","docs","delete","err","logger","error","msg"],"mappings":"AAEA,OAAO,MAAMA,mBAAqC,OAAO,EACvDC,UAAU,EACVC,GAAG,EACHC,YAAY,EACZC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACJ;IACC,MAAME,aAAaH,cAAcI,iBAAiBC,QAAQ;IAC1D,IAAI;QACF,MAAMC,iBAAiB,MAAMJ,QAAQK,IAAI,CAAC;YACxCT,YAAYK;YACZK,OAAO;YACPP;YACAQ,OAAO;gBACLV,KAAK;oBACHW,QAAQ;wBACNC,YAAYb,WAAWO,IAAI;wBAC3BO,OAAOb,IAAIc,EAAE;oBACf;gBACF;YACF;QACF;QAEA,IAAIP,gBAAgBQ,MAAM,CAAC,EAAE,EAAE;YAC7B,MAAMZ,QAAQa,MAAM,CAAC;gBACnBF,IAAIP,gBAAgBQ,MAAM,CAAC,EAAE,EAAED;gBAC/Bf,YAAYK;gBACZF;YACF;QACF;IACF,EAAE,OAAOe,KAAc;QACrBd,QAAQe,MAAM,CAACC,KAAK,CAAC;YACnBF;YACAG,KAAK,CAAC,eAAe,EAAEhB,WAAW,KAAK,CAAC;QAC1C;IACF;IAEA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../../../src/Search/hooks/deleteFromSearch.ts"],"sourcesContent":["import type { DeleteFromSearch } from '../../types.js'\n\nexport const deleteFromSearch: DeleteFromSearch = async ({\n collection,\n doc,\n pluginConfig,\n req: { payload },\n req,\n}) => {\n const searchSlug = pluginConfig?.searchOverrides?.slug || 'search'\n try {\n const searchDocQuery = await payload.find({\n collection: searchSlug,\n depth: 0,\n limit: 1,\n pagination: false,\n req,\n where: {\n doc: {\n equals: {\n relationTo: collection.slug,\n value: doc.id,\n },\n },\n },\n })\n\n if (searchDocQuery?.docs?.[0]) {\n await payload.delete({\n id: searchDocQuery?.docs?.[0]?.id,\n collection: searchSlug,\n req,\n })\n }\n } catch (err: unknown) {\n payload.logger.error({\n err,\n msg: `Error deleting ${searchSlug} doc.`,\n })\n }\n\n return doc\n}\n"],"names":["deleteFromSearch","collection","doc","pluginConfig","req","payload","searchSlug","searchOverrides","slug","searchDocQuery","find","depth","limit","pagination","where","equals","relationTo","value","id","docs","delete","err","logger","error","msg"],"mappings":"AAEA,OAAO,MAAMA,mBAAqC,OAAO,EACvDC,UAAU,EACVC,GAAG,EACHC,YAAY,EACZC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACJ;IACC,MAAME,aAAaH,cAAcI,iBAAiBC,QAAQ;IAC1D,IAAI;QACF,MAAMC,iBAAiB,MAAMJ,QAAQK,IAAI,CAAC;YACxCT,YAAYK;YACZK,OAAO;YACPC,OAAO;YACPC,YAAY;YACZT;YACAU,OAAO;gBACLZ,KAAK;oBACHa,QAAQ;wBACNC,YAAYf,WAAWO,IAAI;wBAC3BS,OAAOf,IAAIgB,EAAE;oBACf;gBACF;YACF;QACF;QAEA,IAAIT,gBAAgBU,MAAM,CAAC,EAAE,EAAE;YAC7B,MAAMd,QAAQe,MAAM,CAAC;gBACnBF,IAAIT,gBAAgBU,MAAM,CAAC,EAAE,EAAED;gBAC/BjB,YAAYK;gBACZF;YACF;QACF;IACF,EAAE,OAAOiB,KAAc;QACrBhB,QAAQiB,MAAM,CAACC,KAAK,CAAC;YACnBF;YACAG,KAAK,CAAC,eAAe,EAAElB,WAAW,KAAK,CAAC;QAC1C;IACF;IAEA,OAAOJ;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAOpD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA0I5D,CAAA"}
1
+ {"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAMpD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA+H5D,CAAA"}
@@ -1,54 +1,44 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { LoadingOverlay, Popup, PopupList, toast, useConfig, useLocale, useModal, useTranslation } from '@payloadcms/ui';
3
+ import { ConfirmationModal, Popup, PopupList, toast, useConfig, useLocale, useModal, useTranslation } from '@payloadcms/ui';
4
4
  import { useRouter } from 'next/navigation.js';
5
5
  import React, { useCallback, useMemo, useState } from 'react';
6
6
  import { ReindexButtonLabel } from './ReindexButtonLabel/index.js';
7
- import { ReindexConfirmModal } from './ReindexConfirmModal/index.js';
8
7
  const confirmReindexModalSlug = 'confirm-reindex-modal';
9
8
  export const ReindexButtonClient = ({ collectionLabels, searchCollections, searchSlug })=>{
10
- const { closeModal, openModal } = useModal();
9
+ const { openModal } = useModal();
11
10
  const { config } = useConfig();
12
11
  const { i18n: { t } } = useTranslation();
13
12
  const locale = useLocale();
14
13
  const router = useRouter();
15
14
  const [reindexCollections, setReindexCollections] = useState([]);
16
- const [isLoading, setLoading] = useState(false);
17
15
  const openConfirmModal = useCallback(()=>openModal(confirmReindexModalSlug), [
18
16
  openModal
19
17
  ]);
20
- const closeConfirmModal = useCallback(()=>closeModal(confirmReindexModalSlug), [
21
- closeModal
22
- ]);
23
18
  const handleReindexSubmit = useCallback(async ()=>{
24
- if (isLoading || !reindexCollections.length) {
19
+ if (!reindexCollections.length) {
25
20
  return;
26
21
  }
27
- closeConfirmModal();
28
- setLoading(true);
29
22
  try {
30
- const endpointRes = await fetch(`${config.routes.api}/${searchSlug}/reindex?locale=${locale.code}`, {
23
+ const res = await fetch(`${config.routes.api}/${searchSlug}/reindex?locale=${locale.code}`, {
31
24
  body: JSON.stringify({
32
25
  collections: reindexCollections
33
26
  }),
34
27
  method: 'POST'
35
28
  });
36
- const { message } = await endpointRes.json();
37
- if (!endpointRes.ok) {
29
+ const { message } = await res.json();
30
+ if (!res.ok) {
38
31
  toast.error(message);
39
32
  } else {
40
33
  toast.success(message);
41
- router.refresh();
34
+ return router.refresh();
42
35
  }
43
36
  } catch (_err) {
44
37
  // swallow error, toast shown above
45
38
  } finally{
46
39
  setReindexCollections([]);
47
- setLoading(false);
48
40
  }
49
41
  }, [
50
- closeConfirmModal,
51
- isLoading,
52
42
  reindexCollections,
53
43
  router,
54
44
  searchSlug,
@@ -123,15 +113,11 @@ export const ReindexButtonClient = ({ collectionLabels, searchCollections, searc
123
113
  size: "large",
124
114
  verticalAlign: "bottom"
125
115
  }),
126
- /*#__PURE__*/ _jsx(ReindexConfirmModal, {
127
- description: modalDescription,
128
- onCancel: closeConfirmModal,
129
- onConfirm: handleReindexSubmit,
130
- slug: confirmReindexModalSlug,
131
- title: modalTitle
132
- }),
133
- isLoading && /*#__PURE__*/ _jsx(LoadingOverlay, {
134
- loadingText: loadingText
116
+ /*#__PURE__*/ _jsx(ConfirmationModal, {
117
+ body: modalDescription,
118
+ heading: modalTitle,
119
+ modalSlug: confirmReindexModalSlug,
120
+ onConfirm: handleReindexSubmit
135
121
  })
136
122
  ]
137
123
  });
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"sourcesContent":["'use client'\n\nimport {\n LoadingOverlay,\n Popup,\n PopupList,\n toast,\n useConfig,\n useLocale,\n useModal,\n useTranslation,\n} from '@payloadcms/ui'\nimport { useRouter } from 'next/navigation.js'\nimport React, { useCallback, useMemo, useState } from 'react'\n\nimport type { ReindexButtonProps } from './types.js'\n\nimport { ReindexButtonLabel } from './ReindexButtonLabel/index.js'\nimport { ReindexConfirmModal } from './ReindexConfirmModal/index.js'\n\nconst confirmReindexModalSlug = 'confirm-reindex-modal'\n\nexport const ReindexButtonClient: React.FC<ReindexButtonProps> = ({\n collectionLabels,\n searchCollections,\n searchSlug,\n}) => {\n const { closeModal, openModal } = useModal()\n\n const { config } = useConfig()\n\n const {\n i18n: { t },\n } = useTranslation()\n\n const locale = useLocale()\n const router = useRouter()\n\n const [reindexCollections, setReindexCollections] = useState<string[]>([])\n const [isLoading, setLoading] = useState<boolean>(false)\n\n const openConfirmModal = useCallback(() => openModal(confirmReindexModalSlug), [openModal])\n const closeConfirmModal = useCallback(() => closeModal(confirmReindexModalSlug), [closeModal])\n\n const handleReindexSubmit = useCallback(async () => {\n if (isLoading || !reindexCollections.length) {\n return\n }\n\n closeConfirmModal()\n setLoading(true)\n\n try {\n const endpointRes = await fetch(\n `${config.routes.api}/${searchSlug}/reindex?locale=${locale.code}`,\n {\n body: JSON.stringify({\n collections: reindexCollections,\n }),\n method: 'POST',\n },\n )\n\n const { message } = (await endpointRes.json()) as { message: string }\n\n if (!endpointRes.ok) {\n toast.error(message)\n } else {\n toast.success(message)\n router.refresh()\n }\n } catch (_err: unknown) {\n // swallow error, toast shown above\n } finally {\n setReindexCollections([])\n setLoading(false)\n }\n }, [closeConfirmModal, isLoading, reindexCollections, router, searchSlug, locale, config])\n\n const handleShowConfirmModal = useCallback(\n (collections: string | string[] = searchCollections) => {\n setReindexCollections(typeof collections === 'string' ? [collections] : collections)\n openConfirmModal()\n },\n [openConfirmModal, searchCollections],\n )\n\n const handlePopupButtonClick = useCallback(\n (closePopup: () => void, slug?: string) => {\n closePopup()\n handleShowConfirmModal(slug)\n },\n [handleShowConfirmModal],\n )\n\n const getPluralizedLabel = useCallback(\n (slug: string) => {\n const label = collectionLabels[slug]\n if (typeof label === 'string') {\n return label\n } else {\n return Object.hasOwn(label, locale.code) ? label[locale.code] : slug\n }\n },\n [collectionLabels, locale.code],\n )\n\n const pluralizedLabels = useMemo(() => {\n return searchCollections.reduce<Record<string, string>>((acc, slug) => {\n acc[slug] = getPluralizedLabel(slug)\n return acc\n }, {})\n }, [searchCollections, getPluralizedLabel])\n\n const selectedAll = reindexCollections.length === searchCollections.length\n const selectedLabels = reindexCollections.map((slug) => pluralizedLabels[slug]).join(', ')\n\n const modalTitle = selectedAll\n ? t('general:confirmReindexAll')\n : t('general:confirmReindex', { collections: selectedLabels })\n const modalDescription = selectedAll\n ? t('general:confirmReindexDescriptionAll')\n : t('general:confirmReindexDescription', { collections: selectedLabels })\n const loadingText = selectedAll\n ? t('general:reindexingAll', { collections: t('general:collections') })\n : t('general:reindexingAll', { collections: selectedLabels })\n\n return (\n <div>\n <Popup\n button={<ReindexButtonLabel />}\n render={({ close }) => (\n <PopupList.ButtonGroup>\n {searchCollections.map((collectionSlug) => (\n <PopupList.Button\n key={collectionSlug}\n onClick={() => handlePopupButtonClick(close, collectionSlug)}\n >\n {pluralizedLabels[collectionSlug]}\n </PopupList.Button>\n ))}\n <PopupList.Button onClick={() => handlePopupButtonClick(close)}>\n {t('general:allCollections')}\n </PopupList.Button>\n </PopupList.ButtonGroup>\n )}\n showScrollbar\n size=\"large\"\n verticalAlign=\"bottom\"\n />\n <ReindexConfirmModal\n description={modalDescription}\n onCancel={closeConfirmModal}\n onConfirm={handleReindexSubmit}\n slug={confirmReindexModalSlug}\n title={modalTitle}\n />\n {isLoading && <LoadingOverlay loadingText={loadingText} />}\n </div>\n )\n}\n"],"names":["LoadingOverlay","Popup","PopupList","toast","useConfig","useLocale","useModal","useTranslation","useRouter","React","useCallback","useMemo","useState","ReindexButtonLabel","ReindexConfirmModal","confirmReindexModalSlug","ReindexButtonClient","collectionLabels","searchCollections","searchSlug","closeModal","openModal","config","i18n","t","locale","router","reindexCollections","setReindexCollections","isLoading","setLoading","openConfirmModal","closeConfirmModal","handleReindexSubmit","length","endpointRes","fetch","routes","api","code","body","JSON","stringify","collections","method","message","json","ok","error","success","refresh","_err","handleShowConfirmModal","handlePopupButtonClick","closePopup","slug","getPluralizedLabel","label","Object","hasOwn","pluralizedLabels","reduce","acc","selectedAll","selectedLabels","map","join","modalTitle","modalDescription","loadingText","div","button","render","close","ButtonGroup","collectionSlug","Button","onClick","showScrollbar","size","verticalAlign","description","onCancel","onConfirm","title"],"mappings":"AAAA;;AAEA,SACEA,cAAc,EACdC,KAAK,EACLC,SAAS,EACTC,KAAK,EACLC,SAAS,EACTC,SAAS,EACTC,QAAQ,EACRC,cAAc,QACT,iBAAgB;AACvB,SAASC,SAAS,QAAQ,qBAAoB;AAC9C,OAAOC,SAASC,WAAW,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,QAAO;AAI7D,SAASC,kBAAkB,QAAQ,gCAA+B;AAClE,SAASC,mBAAmB,QAAQ,iCAAgC;AAEpE,MAAMC,0BAA0B;AAEhC,OAAO,MAAMC,sBAAoD,CAAC,EAChEC,gBAAgB,EAChBC,iBAAiB,EACjBC,UAAU,EACX;IACC,MAAM,EAAEC,UAAU,EAAEC,SAAS,EAAE,GAAGf;IAElC,MAAM,EAAEgB,MAAM,EAAE,GAAGlB;IAEnB,MAAM,EACJmB,MAAM,EAAEC,CAAC,EAAE,EACZ,GAAGjB;IAEJ,MAAMkB,SAASpB;IACf,MAAMqB,SAASlB;IAEf,MAAM,CAACmB,oBAAoBC,sBAAsB,GAAGhB,SAAmB,EAAE;IACzE,MAAM,CAACiB,WAAWC,WAAW,GAAGlB,SAAkB;IAElD,MAAMmB,mBAAmBrB,YAAY,IAAMW,UAAUN,0BAA0B;QAACM;KAAU;IAC1F,MAAMW,oBAAoBtB,YAAY,IAAMU,WAAWL,0BAA0B;QAACK;KAAW;IAE7F,MAAMa,sBAAsBvB,YAAY;QACtC,IAAImB,aAAa,CAACF,mBAAmBO,MAAM,EAAE;YAC3C;QACF;QAEAF;QACAF,WAAW;QAEX,IAAI;YACF,MAAMK,cAAc,MAAMC,MACxB,GAAGd,OAAOe,MAAM,CAACC,GAAG,CAAC,CAAC,EAAEnB,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cAAcpC,mBAAmBO,MAAM,KAAKhB,kBAAkBgB,MAAM;IAC1E,MAAM8B,iBAAiBrC,mBAAmBsC,GAAG,CAAC,CAACV,OAASK,gBAAgB,CAACL,KAAK,EAAEW,IAAI,CAAC;IAErF,MAAMC,aAAaJ,cACfvC,EAAE,+BACFA,EAAE,0BAA0B;QAAEmB,aAAaqB;IAAe;IAC9D,MAAMI,mBAAmBL,cACrBvC,EAAE,0CACFA,EAAE,qCAAqC;QAAEmB,aAAaqB;IAAe;IACzE,MAAMK,cAAcN,cAChBvC,EAAE,yBAAyB;QAAEmB,aAAanB,EAAE;IAAuB,KACnEA,EAAE,yBAAyB;QAAEmB,aAAaqB;IAAe;IAE7D,qBACE,MAACM;;0BACC,KAACrE;gBACCsE,sBAAQ,KAAC1D;gBACT2D,QAAQ,CAAC,EAAEC,KAAK,EAAE,iBAChB,MAACvE,UAAUwE,WAAW;;4BACnBxD,kBAAkB+C,GAAG,CAAC,CAACU,+BACtB,KAACzE,UAAU0E,MAAM;oCAEfC,SAAS,IAAMxB,uBAAuBoB,OAAOE;8CAE5Cf,gBAAgB,CAACe,eAAe;mCAH5BA;0CAMT,KAACzE,UAAU0E,MAAM;gCAACC,SAAS,IAAMxB,uBAAuBoB;0CACrDjD,EAAE;;;;gBAITsD,aAAa;gBACbC,MAAK;gBACLC,eAAc;;0BAEhB,KAAClE;gBACCmE,aAAab;gBACbc,UAAUlD;gBACVmD,WAAWlD;gBACXsB,MAAMxC;gBACNqE,OAAOjB;;YAERtC,2BAAa,KAAC7B;gBAAeqE,aAAaA;;;;AAGjD,EAAC"}
1
+ {"version":3,"sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"sourcesContent":["'use client'\n\nimport {\n ConfirmationModal,\n Popup,\n PopupList,\n toast,\n useConfig,\n useLocale,\n useModal,\n useTranslation,\n} from '@payloadcms/ui'\nimport { useRouter } from 'next/navigation.js'\nimport React, { useCallback, useMemo, useState } from 'react'\n\nimport type { ReindexButtonProps } from './types.js'\n\nimport { ReindexButtonLabel } from './ReindexButtonLabel/index.js'\n\nconst confirmReindexModalSlug = 'confirm-reindex-modal'\n\nexport const ReindexButtonClient: React.FC<ReindexButtonProps> = ({\n collectionLabels,\n searchCollections,\n searchSlug,\n}) => {\n const { openModal } = useModal()\n\n const { config } = useConfig()\n\n const {\n i18n: { t },\n } = useTranslation()\n\n const locale = useLocale()\n const router = useRouter()\n\n const [reindexCollections, setReindexCollections] = useState<string[]>([])\n\n const openConfirmModal = useCallback(() => openModal(confirmReindexModalSlug), [openModal])\n\n const handleReindexSubmit = useCallback(async () => {\n if (!reindexCollections.length) {\n return\n }\n\n try {\n const res = await fetch(`${config.routes.api}/${searchSlug}/reindex?locale=${locale.code}`, {\n body: JSON.stringify({\n collections: reindexCollections,\n }),\n method: 'POST',\n })\n\n const { message } = (await res.json()) as { message: string }\n\n if (!res.ok) {\n toast.error(message)\n } else {\n toast.success(message)\n return router.refresh()\n }\n } catch (_err: unknown) {\n // swallow error, toast shown above\n } finally {\n setReindexCollections([])\n }\n }, [reindexCollections, router, searchSlug, locale, config])\n\n const handleShowConfirmModal = useCallback(\n (collections: string | string[] = searchCollections) => {\n setReindexCollections(typeof collections === 'string' ? [collections] : collections)\n openConfirmModal()\n },\n [openConfirmModal, searchCollections],\n )\n\n const handlePopupButtonClick = useCallback(\n (closePopup: () => void, slug?: string) => {\n closePopup()\n handleShowConfirmModal(slug)\n },\n [handleShowConfirmModal],\n )\n\n const getPluralizedLabel = useCallback(\n (slug: string) => {\n const label = collectionLabels[slug]\n if (typeof label === 'string') {\n return label\n } else {\n return Object.hasOwn(label, locale.code) ? label[locale.code] : slug\n }\n },\n [collectionLabels, locale.code],\n )\n\n const pluralizedLabels = useMemo(() => {\n return searchCollections.reduce<Record<string, string>>((acc, slug) => {\n acc[slug] = getPluralizedLabel(slug)\n return acc\n }, {})\n }, [searchCollections, getPluralizedLabel])\n\n const selectedAll = reindexCollections.length === searchCollections.length\n const selectedLabels = reindexCollections.map((slug) => pluralizedLabels[slug]).join(', ')\n\n const modalTitle = selectedAll\n ? t('general:confirmReindexAll')\n : t('general:confirmReindex', { collections: selectedLabels })\n const modalDescription = selectedAll\n ? t('general:confirmReindexDescriptionAll')\n : t('general:confirmReindexDescription', { collections: selectedLabels })\n const loadingText = selectedAll\n ? t('general:reindexingAll', { collections: t('general:collections') })\n : t('general:reindexingAll', { collections: selectedLabels })\n\n return (\n <div>\n <Popup\n button={<ReindexButtonLabel />}\n render={({ close }) => (\n <PopupList.ButtonGroup>\n {searchCollections.map((collectionSlug) => (\n <PopupList.Button\n key={collectionSlug}\n onClick={() => handlePopupButtonClick(close, collectionSlug)}\n >\n {pluralizedLabels[collectionSlug]}\n </PopupList.Button>\n ))}\n <PopupList.Button onClick={() => handlePopupButtonClick(close)}>\n {t('general:allCollections')}\n </PopupList.Button>\n </PopupList.ButtonGroup>\n )}\n showScrollbar\n size=\"large\"\n verticalAlign=\"bottom\"\n />\n <ConfirmationModal\n body={modalDescription}\n heading={modalTitle}\n modalSlug={confirmReindexModalSlug}\n onConfirm={handleReindexSubmit}\n />\n </div>\n )\n}\n"],"names":["ConfirmationModal","Popup","PopupList","toast","useConfig","useLocale","useModal","useTranslation","useRouter","React","useCallback","useMemo","useState","ReindexButtonLabel","confirmReindexModalSlug","ReindexButtonClient","collectionLabels","searchCollections","searchSlug","openModal","config","i18n","t","locale","router","reindexCollections","setReindexCollections","openConfirmModal","handleReindexSubmit","length","res","fetch","routes","api","code","body","JSON","stringify","collections","method","message","json","ok","error","success","refresh","_err","handleShowConfirmModal","handlePopupButtonClick","closePopup","slug","getPluralizedLabel","label","Object","hasOwn","pluralizedLabels","reduce","acc","selectedAll","selectedLabels","map","join","modalTitle","modalDescription","loadingText","div","button","render","close","ButtonGroup","collectionSlug","Button","onClick","showScrollbar","size","verticalAlign","heading","modalSlug","onConfirm"],"mappings":"AAAA;;AAEA,SACEA,iBAAiB,EACjBC,KAAK,EACLC,SAAS,EACTC,KAAK,EACLC,SAAS,E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ACrD;gBACTsD,QAAQ,CAAC,EAAEC,KAAK,EAAE,iBAChB,MAAClE,UAAUmE,WAAW;;4BACnBpD,kBAAkB2C,GAAG,CAAC,CAACU,+BACtB,KAACpE,UAAUqE,MAAM;oCAEfC,SAAS,IAAMxB,uBAAuBoB,OAAOE;8CAE5Cf,gBAAgB,CAACe,eAAe;mCAH5BA;0CAMT,KAACpE,UAAUqE,MAAM;gCAACC,SAAS,IAAMxB,uBAAuBoB;0CACrD9C,EAAE;;;;gBAITmD,aAAa;gBACbC,MAAK;gBACLC,eAAc;;0BAEhB,KAAC3E;gBACCmC,MAAM4B;gBACNa,SAASd;gBACTe,WAAW/D;gBACXgE,WAAWlD;;;;AAInB,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"syncDocAsSearchIndex.d.ts","sourceRoot":"","sources":["../../src/utilities/syncDocAsSearchIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,oBAAoB,8FAS9B,WAAW,iBA0Mb,CAAA"}
1
+ {"version":3,"file":"syncDocAsSearchIndex.d.ts","sourceRoot":"","sources":["../../src/utilities/syncDocAsSearchIndex.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,WAAW,EAAE,MAAM,aAAa,CAAA;AAEzD,eAAO,MAAM,oBAAoB,8FAS9B,WAAW,iBA4Mb,CAAA"}
@@ -124,7 +124,9 @@ export const syncDocAsSearchIndex = async ({ collection, doc, locale, onSyncErro
124
124
  const { docs: [docWithPublish] } = await payload.find({
125
125
  collection,
126
126
  draft: false,
127
+ limit: 1,
127
128
  locale: syncLocale,
129
+ pagination: false,
128
130
  req,
129
131
  where: {
130
132
  and: [
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utilities/syncDocAsSearchIndex.ts"],"sourcesContent":["import type { DocToSync, SyncDocArgs } from '../types.js'\n\nexport const syncDocAsSearchIndex = async ({\n collection,\n doc,\n locale,\n onSyncError,\n operation,\n pluginConfig,\n req: { payload },\n req,\n}: SyncDocArgs) => {\n const { id, _status: status, title } = doc || {}\n\n const { beforeSync, defaultPriorities, deleteDrafts, searchOverrides, syncDrafts } = pluginConfig\n\n const searchSlug = searchOverrides?.slug || 'search'\n const syncLocale = locale || req.locale\n\n let dataToSave: DocToSync = {\n doc: {\n relationTo: collection,\n value: id,\n },\n title,\n }\n\n if (typeof beforeSync === 'function') {\n let docToSyncWith = doc\n if (payload.config?.localization) {\n docToSyncWith = await payload.findByID({\n id,\n collection,\n locale: syncLocale,\n req,\n })\n }\n dataToSave = await beforeSync({\n originalDoc: docToSyncWith,\n payload,\n req,\n searchDoc: dataToSave,\n })\n }\n\n let defaultPriority = 0\n if (defaultPriorities) {\n const { [collection]: priority } = defaultPriorities\n\n if (typeof priority === 'function') {\n try {\n defaultPriority = await priority(doc)\n } catch (err: unknown) {\n payload.logger.error(err)\n payload.logger.error(\n `Error gathering default priority for ${searchSlug} documents related to ${collection}`,\n )\n }\n } else {\n defaultPriority = priority\n }\n }\n\n const doSync = syncDrafts || (!syncDrafts && status !== 'draft')\n\n try {\n if (operation === 'create') {\n if (doSync) {\n await payload.create({\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n }\n }\n\n if (operation === 'update') {\n try {\n // find the correct doc to sync with\n const searchDocQuery = await payload.find({\n collection: searchSlug,\n depth: 0,\n locale: syncLocale,\n req,\n where: {\n 'doc.relationTo': {\n equals: collection,\n },\n 'doc.value': {\n equals: id,\n },\n },\n })\n\n const docs: Array<{\n id: number | string\n priority?: number\n }> = searchDocQuery?.docs || []\n\n const [foundDoc, ...duplicativeDocs] = docs\n\n // delete all duplicative search docs (docs that reference the same page)\n // to ensure the same, out-of-date result does not appear twice (where only syncing the first found doc)\n if (duplicativeDocs.length > 0) {\n try {\n const duplicativeDocIDs = duplicativeDocs.map(({ id }) => id)\n await payload.delete({\n collection: searchSlug,\n req,\n where: { id: { in: duplicativeDocIDs } },\n })\n } catch (err: unknown) {\n payload.logger.error({\n err,\n msg: `Error deleting duplicative ${searchSlug} documents.`,\n })\n }\n }\n\n if (foundDoc) {\n const { id: searchDocID } = foundDoc\n\n if (doSync) {\n // update the doc normally\n try {\n await payload.update({\n id: searchDocID,\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: foundDoc.priority || defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error updating ${searchSlug} document.` })\n }\n }\n if (deleteDrafts && status === 'draft') {\n // Check to see if there's a published version of the doc\n // We don't want to remove the search doc if there is a published version but a new draft has been created\n const {\n docs: [docWithPublish],\n } = await payload.find({\n collection,\n draft: false,\n locale: syncLocale,\n req,\n where: {\n and: [\n {\n _status: {\n equals: 'published',\n },\n },\n {\n id: {\n equals: id,\n },\n },\n ],\n },\n })\n\n if (!docWithPublish) {\n // do not include draft docs in search results, so delete the record\n try {\n await payload.delete({\n id: searchDocID,\n collection: searchSlug,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error deleting ${searchSlug} document.` })\n }\n }\n }\n } else if (doSync) {\n try {\n await payload.create({\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error creating ${searchSlug} document.` })\n }\n }\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error finding ${searchSlug} document.` })\n }\n }\n } catch (err: unknown) {\n payload.logger.error({\n err,\n msg: `Error syncing ${searchSlug} document related to ${collection} with id: '${id}'.`,\n })\n\n if (onSyncError) {\n onSyncError()\n }\n }\n\n return doc\n}\n"],"names":["syncDocAsSearchIndex","collection","doc","locale","onSyncError","operation","pluginConfig","req","payload","id","_status","status","title","beforeSync","defaultPriorities","deleteDrafts","searchOverrides","syncDrafts","searchSlug","slug","syncLocale","dataToSave","relationTo","value","docToSyncWith","config","localization","findByID","originalDoc","searchDoc","defaultPriority","priority","err","logger","error","doSync","create","data","searchDocQuery","find","depth","where","equals","docs","foundDoc","duplicativeDocs","length","duplicativeDocIDs","map","delete","in","msg","searchDocID","update","docWithPublish","draft","and"],"mappings":"AAEA,OAAO,MAAMA,uBAAuB,OAAO,EACzCC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,YAAY,EACZC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACS;IACZ,MAAM,EAAEE,EAAE,EAAEC,SAASC,MAAM,EAAEC,KAAK,EAAE,GAAGV,OAAO,CAAC;IAE/C,MAAM,EAAEW,UAAU,EAAEC,iBAAiB,EAAEC,YAAY,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAGX;IAErF,MAAMY,aAAaF,iBAAiBG,QAAQ;IAC5C,MAAMC,aAAajB,UAAUI,IAAIJ,MAAM;IAEvC,IAAIkB,aAAwB;QAC1BnB,KAAK;YACHoB,YAAYrB;YACZsB,OAAOd;QACT;QACAG;IACF;IAEA,IAAI,OAAOC,eAAe,YAAY;QACpC,IAAIW,gBAAgBtB;QACpB,IAAIM,QAAQiB,MAAM,EAAEC,cAAc;YAChCF,gBAAgB,MAAMhB,QAAQmB,QAAQ,CAAC;gBACrClB;gBACAR;gBACAE,QAAQiB;gBACRb;YACF;QACF;QACAc,aAAa,MAAMR,WAAW;YAC5Be,aAAaJ;YACbhB;YACAD;YACAsB,WAAWR;QACb;IACF;IAEA,IAAIS,kBAAkB;IACtB,IAAIhB,mBAAmB;QACrB,MAAM,EAAE,CAACb,WAAW,EAAE8B,QAAQ,EAAE,GAAGjB;QAEnC,IAAI,OAAOiB,aAAa,YAAY;YAClC,IAAI;gBACFD,kBAAkB,MAAMC,SAAS7B;YACnC,EAAE,OAAO8B,KAAc;gBACrBxB,QAAQyB,MAAM,CAACC,KAAK,CAACF;gBACrBxB,QAAQyB,MAAM,CAACC,KAAK,CAClB,CAAC,qCAAqC,EAAEhB,WAAW,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C,KAAK,CAAC;4BAAEF;4BAAKmB,KAAK,CAAC,eAAe,EAAEjC,WAAW,UAAU,CAAC;wBAAC;oBAC5E;gBACF;YACF,EAAE,OAAOc,KAAc;gBACrBxB,QAAQyB,MAAM,CAACC,KAAK,CAAC;oBAAEF;oBAAKmB,KAAK,CAAC,cAAc,EAAEjC,WAAW,UAAU,CAAC;gBAAC;YAC3E;QACF;IACF,EAAE,OAAOc,KAAc;QACrBxB,QAAQyB,MAAM,CAACC,KAAK,CAAC;YACnBF;YACAmB,KAAK,CAAC,cAAc,EAAEjC,WAAW,qBAAqB,EAAEjB,WAAW,WAAW,EAAEQ,GAAG,EAAE,CAAC;QACxF;QAEA,IAAIL,aAAa;YACfA;QACF;IACF;IAEA,OAAOF;AACT,EAAC"}
1
+ {"version":3,"sources":["../../src/utilities/syncDocAsSearchIndex.ts"],"sourcesContent":["import type { DocToSync, SyncDocArgs } from '../types.js'\n\nexport const syncDocAsSearchIndex = async ({\n collection,\n doc,\n locale,\n onSyncError,\n operation,\n pluginConfig,\n req: { payload },\n req,\n}: SyncDocArgs) => {\n const { id, _status: status, title } = doc || {}\n\n const { beforeSync, defaultPriorities, deleteDrafts, searchOverrides, syncDrafts } = pluginConfig\n\n const searchSlug = searchOverrides?.slug || 'search'\n const syncLocale = locale || req.locale\n\n let dataToSave: DocToSync = {\n doc: {\n relationTo: collection,\n value: id,\n },\n title,\n }\n\n if (typeof beforeSync === 'function') {\n let docToSyncWith = doc\n if (payload.config?.localization) {\n docToSyncWith = await payload.findByID({\n id,\n collection,\n locale: syncLocale,\n req,\n })\n }\n dataToSave = await beforeSync({\n originalDoc: docToSyncWith,\n payload,\n req,\n searchDoc: dataToSave,\n })\n }\n\n let defaultPriority = 0\n if (defaultPriorities) {\n const { [collection]: priority } = defaultPriorities\n\n if (typeof priority === 'function') {\n try {\n defaultPriority = await priority(doc)\n } catch (err: unknown) {\n payload.logger.error(err)\n payload.logger.error(\n `Error gathering default priority for ${searchSlug} documents related to ${collection}`,\n )\n }\n } else {\n defaultPriority = priority\n }\n }\n\n const doSync = syncDrafts || (!syncDrafts && status !== 'draft')\n\n try {\n if (operation === 'create') {\n if (doSync) {\n await payload.create({\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n }\n }\n\n if (operation === 'update') {\n try {\n // find the correct doc to sync with\n const searchDocQuery = await payload.find({\n collection: searchSlug,\n depth: 0,\n locale: syncLocale,\n req,\n where: {\n 'doc.relationTo': {\n equals: collection,\n },\n 'doc.value': {\n equals: id,\n },\n },\n })\n\n const docs: Array<{\n id: number | string\n priority?: number\n }> = searchDocQuery?.docs || []\n\n const [foundDoc, ...duplicativeDocs] = docs\n\n // delete all duplicative search docs (docs that reference the same page)\n // to ensure the same, out-of-date result does not appear twice (where only syncing the first found doc)\n if (duplicativeDocs.length > 0) {\n try {\n const duplicativeDocIDs = duplicativeDocs.map(({ id }) => id)\n await payload.delete({\n collection: searchSlug,\n req,\n where: { id: { in: duplicativeDocIDs } },\n })\n } catch (err: unknown) {\n payload.logger.error({\n err,\n msg: `Error deleting duplicative ${searchSlug} documents.`,\n })\n }\n }\n\n if (foundDoc) {\n const { id: searchDocID } = foundDoc\n\n if (doSync) {\n // update the doc normally\n try {\n await payload.update({\n id: searchDocID,\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: foundDoc.priority || defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error updating ${searchSlug} document.` })\n }\n }\n if (deleteDrafts && status === 'draft') {\n // Check to see if there's a published version of the doc\n // We don't want to remove the search doc if there is a published version but a new draft has been created\n const {\n docs: [docWithPublish],\n } = await payload.find({\n collection,\n draft: false,\n limit: 1,\n locale: syncLocale,\n pagination: false,\n req,\n where: {\n and: [\n {\n _status: {\n equals: 'published',\n },\n },\n {\n id: {\n equals: id,\n },\n },\n ],\n },\n })\n\n if (!docWithPublish) {\n // do not include draft docs in search results, so delete the record\n try {\n await payload.delete({\n id: searchDocID,\n collection: searchSlug,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error deleting ${searchSlug} document.` })\n }\n }\n }\n } else if (doSync) {\n try {\n await payload.create({\n collection: searchSlug,\n data: {\n ...dataToSave,\n priority: defaultPriority,\n },\n locale: syncLocale,\n req,\n })\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error creating ${searchSlug} document.` })\n }\n }\n } catch (err: unknown) {\n payload.logger.error({ err, msg: `Error finding ${searchSlug} document.` })\n }\n }\n } catch (err: unknown) {\n payload.logger.error({\n err,\n msg: `Error syncing ${searchSlug} document related to ${collection} with id: '${id}'.`,\n })\n\n if (onSyncError) {\n onSyncError()\n }\n }\n\n return doc\n}\n"],"names":["syncDocAsSearchIndex","collection","doc","locale","onSyncError","operation","pluginConfig","req","payload","id","_status","status","title","beforeSync","defaultPriorities","deleteDrafts","searchOverrides","syncDrafts","searchSlug","slug","syncLocale","dataToSave","relationTo","value","docToSyncWith","config","localization","findByID","originalDoc","searchDoc","defaultPriority","priority","err","logger","error","doSync","create","data","searchDocQuery","find","depth","where","equals","docs","foundDoc","duplicativeDocs","length","duplicativeDocIDs","map","delete","in","msg","searchDocID","update","docWithPublish","draft","limit","pagination","and"],"mappings":"AAEA,OAAO,MAAMA,uBAAuB,OAAO,EACzCC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,WAAW,EACXC,SAAS,EACTC,YAAY,EACZC,KAAK,EAAEC,OAAO,EAAE,EAChBD,GAAG,EACS;IACZ,MAAM,EAAEE,EAAE,EAAEC,SAASC,MAAM,EAAEC,KAAK,EAAE,GAAGV,OAAO,CAAC;IAE/C,MAAM,EAAEW,UAAU,EAAEC,iBAAiB,EAAEC,YAAY,EAAEC,eAAe,EAAEC,UAAU,EAAE,GAAGX;IAErF,MAAMY,aAAaF,iBAAiBG,QAAQ;IAC5C,MAAMC,aAAajB,UAAUI,IAAIJ,MAAM;IAEvC,IAAIkB,aAAwB;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3
- "version": "3.24.0-canary.f229d8d",
3
+ "version": "3.25.0-canary.36940b2",
4
4
  "description": "Search plugin for Payload",
5
5
  "keywords": [
6
6
  "payload",
@@ -49,19 +49,19 @@
49
49
  "dist"
50
50
  ],
51
51
  "dependencies": {
52
- "@payloadcms/next": "3.24.0-canary.f229d8d",
53
- "@payloadcms/ui": "3.24.0-canary.f229d8d"
52
+ "@payloadcms/next": "3.25.0-canary.36940b2",
53
+ "@payloadcms/ui": "3.25.0-canary.36940b2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/react": "19.0.1",
57
57
  "@types/react-dom": "19.0.1",
58
- "@payloadcms/eslint-config": "3.9.0",
59
- "payload": "3.24.0-canary.f229d8d"
58
+ "payload": "3.25.0-canary.36940b2",
59
+ "@payloadcms/eslint-config": "3.9.0"
60
60
  },
61
61
  "peerDependencies": {
62
62
  "react": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
63
63
  "react-dom": "^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",
64
- "payload": "3.24.0-canary.f229d8d"
64
+ "payload": "3.25.0-canary.36940b2"
65
65
  },
66
66
  "publishConfig": {
67
67
  "registry": "https://registry.npmjs.org/"
@@ -1,11 +0,0 @@
1
- import './index.scss';
2
- type Props = {
3
- description: string;
4
- onCancel: () => void;
5
- onConfirm: () => void;
6
- slug: string;
7
- title: string;
8
- };
9
- export declare const ReindexConfirmModal: ({ slug, description, onCancel, onConfirm, title }: Props) => import("react").JSX.Element;
10
- export {};
11
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/Search/ui/ReindexButton/ReindexConfirmModal/index.tsx"],"names":[],"mappings":"AAEA,OAAO,cAAc,CAAA;AAErB,KAAK,KAAK,GAAG;IACX,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,SAAS,EAAE,MAAM,IAAI,CAAA;IACrB,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAID,eAAO,MAAM,mBAAmB,sDAAuD,KAAK,gCAsB3F,CAAA"}
@@ -1,45 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Button, Modal, useTranslation } from '@payloadcms/ui';
3
- import './index.scss';
4
- const baseClass = 'reindex-confirm-modal';
5
- export const ReindexConfirmModal = ({ slug, description, onCancel, onConfirm, title })=>{
6
- const { i18n: { t } } = useTranslation();
7
- return /*#__PURE__*/ _jsx(Modal, {
8
- className: baseClass,
9
- slug: slug,
10
- children: /*#__PURE__*/ _jsxs("div", {
11
- className: `${baseClass}__wrapper`,
12
- children: [
13
- /*#__PURE__*/ _jsxs("div", {
14
- className: `${baseClass}__content`,
15
- children: [
16
- /*#__PURE__*/ _jsx("h1", {
17
- children: title
18
- }),
19
- /*#__PURE__*/ _jsx("p", {
20
- children: description
21
- })
22
- ]
23
- }),
24
- /*#__PURE__*/ _jsxs("div", {
25
- className: `${baseClass}__controls`,
26
- children: [
27
- /*#__PURE__*/ _jsx(Button, {
28
- buttonStyle: "secondary",
29
- onClick: onCancel,
30
- size: "large",
31
- children: t('general:cancel')
32
- }),
33
- /*#__PURE__*/ _jsx(Button, {
34
- onClick: onConfirm,
35
- size: "large",
36
- children: t('general:confirm')
37
- })
38
- ]
39
- })
40
- ]
41
- })
42
- });
43
- };
44
-
45
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../../src/Search/ui/ReindexButton/ReindexConfirmModal/index.tsx"],"sourcesContent":["import { Button, Modal, useTranslation } from '@payloadcms/ui'\n\nimport './index.scss'\n\ntype Props = {\n description: string\n onCancel: () => void\n onConfirm: () => void\n slug: string\n title: string\n}\n\nconst baseClass = 'reindex-confirm-modal'\n\nexport const ReindexConfirmModal = ({ slug, description, onCancel, onConfirm, title }: Props) => {\n const {\n i18n: { t },\n } = useTranslation()\n return (\n <Modal className={baseClass} slug={slug}>\n <div className={`${baseClass}__wrapper`}>\n <div className={`${baseClass}__content`}>\n <h1>{title}</h1>\n <p>{description}</p>\n </div>\n <div className={`${baseClass}__controls`}>\n <Button buttonStyle=\"secondary\" onClick={onCancel} size=\"large\">\n {t('general:cancel')}\n </Button>\n <Button onClick={onConfirm} size=\"large\">\n {t('general:confirm')}\n </Button>\n </div>\n </div>\n </Modal>\n )\n}\n"],"names":["Button","Modal","useTranslation","baseClass","ReindexConfirmModal","slug","description","onCancel","onConfirm","title","i18n","t","className","div","h1","p","buttonStyle","onClick","size"],"mappings":";AAAA,SAASA,MAAM,EAAEC,KAAK,EAAEC,cAAc,QAAQ,iBAAgB;AAE9D,OAAO,eAAc;AAUrB,MAAMC,YAAY;AAElB,OAAO,MAAMC,sBAAsB,CAAC,EAAEC,IAAI,EAAEC,WAAW,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,KAAK,EAAS;IAC1F,MAAM,EACJC,MAAM,EAAEC,CAAC,EAAE,EACZ,GAAGT;IACJ,qBACE,KAACD;QAAMW,WAAWT;QAAWE,MAAMA;kBACjC,cAAA,MAACQ;YAAID,WAAW,GAAGT,UAAU,SAAS,CAAC;;8BACrC,MAACU;oBAAID,WAAW,GAAGT,UAAU,SAAS,CAAC;;sCACrC,KAACW;sCAAIL;;sCACL,KAACM;sCAAGT;;;;8BAEN,MAACO;oBAAID,WAAW,GAAGT,UAAU,UAAU,CAAC;;sCACtC,KAACH;4BAAOgB,aAAY;4BAAYC,SAASV;4BAAUW,MAAK;sCACrDP,EAAE;;sCAEL,KAACX;4BAAOiB,SAAST;4BAAWU,MAAK;sCAC9BP,EAAE;;;;;;;AAMf,EAAC"}
@@ -1,39 +0,0 @@
1
- @import '~@payloadcms/ui/scss';
2
-
3
- @layer payload-default {
4
- .reindex-confirm-modal {
5
- @include blur-bg;
6
- display: flex;
7
- align-items: center;
8
- justify-content: center;
9
- height: 100%;
10
-
11
- &__wrapper {
12
- z-index: 1;
13
- position: relative;
14
- display: flex;
15
- flex-direction: column;
16
- gap: base(2);
17
- padding: base(2);
18
- }
19
-
20
- &__content {
21
- display: flex;
22
- flex-direction: column;
23
- gap: base(1);
24
-
25
- > * {
26
- margin: 0;
27
- }
28
- }
29
-
30
- &__controls {
31
- display: flex;
32
- gap: base(0.4);
33
-
34
- .btn {
35
- margin: 0;
36
- }
37
- }
38
- }
39
- }