@payloadcms/plugin-search 3.1.1 → 3.2.0
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/Search/hooks/syncWithSearch.d.ts.map +1 -1
- package/dist/Search/hooks/syncWithSearch.js +3 -167
- package/dist/Search/hooks/syncWithSearch.js.map +1 -1
- package/dist/Search/index.d.ts +2 -2
- package/dist/Search/index.d.ts.map +1 -1
- package/dist/Search/index.js +30 -2
- package/dist/Search/index.js.map +1 -1
- package/dist/Search/ui/LinkToDoc/index.client.d.ts.map +1 -0
- package/dist/Search/ui/LinkToDoc/index.client.js.map +1 -0
- package/dist/Search/ui/LinkToDoc/index.d.ts.map +1 -0
- package/dist/Search/ui/LinkToDoc/index.js.map +1 -0
- package/dist/Search/ui/ReindexButton/ReindexButtonLabel/index.d.ts +2 -0
- package/dist/Search/ui/ReindexButton/ReindexButtonLabel/index.d.ts.map +1 -0
- package/dist/Search/ui/ReindexButton/ReindexButtonLabel/index.js +13 -0
- package/dist/Search/ui/ReindexButton/ReindexButtonLabel/index.js.map +1 -0
- package/dist/Search/ui/ReindexButton/ReindexConfirmModal/index.d.ts +11 -0
- package/dist/Search/ui/ReindexButton/ReindexConfirmModal/index.d.ts.map +1 -0
- package/dist/Search/ui/ReindexButton/ReindexConfirmModal/index.js +45 -0
- package/dist/Search/ui/ReindexButton/ReindexConfirmModal/index.js.map +1 -0
- package/dist/Search/ui/ReindexButton/index.client.d.ts +4 -0
- package/dist/Search/ui/ReindexButton/index.client.d.ts.map +1 -0
- package/dist/Search/ui/ReindexButton/index.client.js +138 -0
- package/dist/Search/ui/ReindexButton/index.client.js.map +1 -0
- package/dist/Search/ui/ReindexButton/index.d.ts +3 -0
- package/dist/Search/ui/ReindexButton/index.d.ts.map +1 -0
- package/dist/Search/ui/ReindexButton/index.js +36 -0
- package/dist/Search/ui/ReindexButton/index.js.map +1 -0
- package/dist/Search/ui/ReindexButton/types.d.ts +14 -0
- package/dist/Search/ui/ReindexButton/types.d.ts.map +1 -0
- package/dist/Search/ui/ReindexButton/types.js +3 -0
- package/dist/Search/ui/ReindexButton/types.js.map +1 -0
- package/dist/exports/client.d.ts +2 -1
- package/dist/exports/client.d.ts.map +1 -1
- package/dist/exports/client.js +2 -1
- package/dist/exports/client.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +19 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utilities/generateReindexHandler.d.ts +4 -0
- package/dist/utilities/generateReindexHandler.d.ts.map +1 -0
- package/dist/utilities/generateReindexHandler.js +172 -0
- package/dist/utilities/generateReindexHandler.js.map +1 -0
- package/dist/utilities/syncDocAsSearchIndex.d.ts +3 -0
- package/dist/utilities/syncDocAsSearchIndex.d.ts.map +1 -0
- package/dist/utilities/syncDocAsSearchIndex.js +173 -0
- package/dist/utilities/syncDocAsSearchIndex.js.map +1 -0
- package/package.json +6 -5
- package/dist/Search/ui/index.client.d.ts.map +0 -1
- package/dist/Search/ui/index.client.js.map +0 -1
- package/dist/Search/ui/index.d.ts.map +0 -1
- package/dist/Search/ui/index.js.map +0 -1
- /package/dist/Search/ui/{index.client.d.ts → LinkToDoc/index.client.d.ts} +0 -0
- /package/dist/Search/ui/{index.client.js → LinkToDoc/index.client.js} +0 -0
- /package/dist/Search/ui/{index.d.ts → LinkToDoc/index.d.ts} +0 -0
- /package/dist/Search/ui/{index.js → LinkToDoc/index.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"syncWithSearch.d.ts","sourceRoot":"","sources":["../../../src/Search/hooks/syncWithSearch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"syncWithSearch.d.ts","sourceRoot":"","sources":["../../../src/Search/hooks/syncWithSearch.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAA;AAIpD,eAAO,MAAM,cAAc,EAAE,cAE5B,CAAA"}
|
|
@@ -1,170 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const { beforeSync, defaultPriorities, deleteDrafts, searchOverrides, syncDrafts } = pluginConfig;
|
|
5
|
-
const searchSlug = searchOverrides?.slug || 'search';
|
|
6
|
-
let dataToSave = {
|
|
7
|
-
doc: {
|
|
8
|
-
relationTo: collection,
|
|
9
|
-
value: id
|
|
10
|
-
},
|
|
11
|
-
title
|
|
12
|
-
};
|
|
13
|
-
if (typeof beforeSync === 'function') {
|
|
14
|
-
let docToSyncWith = doc;
|
|
15
|
-
if (payload.config?.localization) {
|
|
16
|
-
docToSyncWith = await payload.findByID({
|
|
17
|
-
id,
|
|
18
|
-
collection,
|
|
19
|
-
locale: req.locale,
|
|
20
|
-
req
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
dataToSave = await beforeSync({
|
|
24
|
-
originalDoc: docToSyncWith,
|
|
25
|
-
payload,
|
|
26
|
-
req,
|
|
27
|
-
searchDoc: dataToSave
|
|
28
|
-
});
|
|
29
|
-
}
|
|
30
|
-
let defaultPriority = 0;
|
|
31
|
-
if (defaultPriorities) {
|
|
32
|
-
const { [collection]: priority } = defaultPriorities;
|
|
33
|
-
if (typeof priority === 'function') {
|
|
34
|
-
try {
|
|
35
|
-
defaultPriority = await priority(doc);
|
|
36
|
-
} catch (err) {
|
|
37
|
-
payload.logger.error(err);
|
|
38
|
-
payload.logger.error(`Error gathering default priority for ${searchSlug} documents related to ${collection}`);
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
defaultPriority = priority;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
const doSync = syncDrafts || !syncDrafts && status !== 'draft';
|
|
45
|
-
try {
|
|
46
|
-
if (operation === 'create') {
|
|
47
|
-
if (doSync) {
|
|
48
|
-
await payload.create({
|
|
49
|
-
collection: searchSlug,
|
|
50
|
-
data: {
|
|
51
|
-
...dataToSave,
|
|
52
|
-
priority: defaultPriority
|
|
53
|
-
},
|
|
54
|
-
locale: req.locale,
|
|
55
|
-
req
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (operation === 'update') {
|
|
60
|
-
try {
|
|
61
|
-
// find the correct doc to sync with
|
|
62
|
-
const searchDocQuery = await payload.find({
|
|
63
|
-
collection: searchSlug,
|
|
64
|
-
depth: 0,
|
|
65
|
-
locale: req.locale,
|
|
66
|
-
req,
|
|
67
|
-
where: {
|
|
68
|
-
'doc.relationTo': {
|
|
69
|
-
equals: collection
|
|
70
|
-
},
|
|
71
|
-
'doc.value': {
|
|
72
|
-
equals: id
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
const docs = searchDocQuery?.docs || [];
|
|
77
|
-
const [foundDoc, ...duplicativeDocs] = docs;
|
|
78
|
-
// delete all duplicative search docs (docs that reference the same page)
|
|
79
|
-
// to ensure the same, out-of-date result does not appear twice (where only syncing the first found doc)
|
|
80
|
-
if (duplicativeDocs.length > 0) {
|
|
81
|
-
try {
|
|
82
|
-
const duplicativeDocIDs = duplicativeDocs.map(({ id })=>id);
|
|
83
|
-
await payload.delete({
|
|
84
|
-
collection: searchSlug,
|
|
85
|
-
req,
|
|
86
|
-
where: {
|
|
87
|
-
id: {
|
|
88
|
-
in: duplicativeDocIDs
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
});
|
|
92
|
-
} catch (err) {
|
|
93
|
-
payload.logger.error({
|
|
94
|
-
err,
|
|
95
|
-
msg: `Error deleting duplicative ${searchSlug} documents.`
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
if (foundDoc) {
|
|
100
|
-
const { id: searchDocID } = foundDoc;
|
|
101
|
-
if (doSync) {
|
|
102
|
-
// update the doc normally
|
|
103
|
-
try {
|
|
104
|
-
await payload.update({
|
|
105
|
-
id: searchDocID,
|
|
106
|
-
collection: searchSlug,
|
|
107
|
-
data: {
|
|
108
|
-
...dataToSave,
|
|
109
|
-
priority: foundDoc.priority || defaultPriority
|
|
110
|
-
},
|
|
111
|
-
locale: req.locale,
|
|
112
|
-
req
|
|
113
|
-
});
|
|
114
|
-
} catch (err) {
|
|
115
|
-
payload.logger.error({
|
|
116
|
-
err,
|
|
117
|
-
msg: `Error updating ${searchSlug} document.`
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (deleteDrafts && status === 'draft') {
|
|
122
|
-
// do not include draft docs in search results, so delete the record
|
|
123
|
-
try {
|
|
124
|
-
await payload.delete({
|
|
125
|
-
id: searchDocID,
|
|
126
|
-
collection: searchSlug,
|
|
127
|
-
req
|
|
128
|
-
});
|
|
129
|
-
} catch (err) {
|
|
130
|
-
payload.logger.error({
|
|
131
|
-
err,
|
|
132
|
-
msg: `Error deleting ${searchSlug} document.`
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
} else if (doSync) {
|
|
137
|
-
try {
|
|
138
|
-
await payload.create({
|
|
139
|
-
collection: searchSlug,
|
|
140
|
-
data: {
|
|
141
|
-
...dataToSave,
|
|
142
|
-
priority: defaultPriority
|
|
143
|
-
},
|
|
144
|
-
locale: req.locale,
|
|
145
|
-
req
|
|
146
|
-
});
|
|
147
|
-
} catch (err) {
|
|
148
|
-
payload.logger.error({
|
|
149
|
-
err,
|
|
150
|
-
msg: `Error creating ${searchSlug} document.`
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
} catch (err) {
|
|
155
|
-
payload.logger.error({
|
|
156
|
-
err,
|
|
157
|
-
msg: `Error finding ${searchSlug} document.`
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
} catch (err) {
|
|
162
|
-
payload.logger.error({
|
|
163
|
-
err,
|
|
164
|
-
msg: `Error syncing ${searchSlug} document related to ${collection} with id: '${id}'.`
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
return doc;
|
|
1
|
+
import { syncDocAsSearchIndex } from '../../utilities/syncDocAsSearchIndex.js';
|
|
2
|
+
export const syncWithSearch = (args)=>{
|
|
3
|
+
return syncDocAsSearchIndex(args);
|
|
168
4
|
};
|
|
169
5
|
|
|
170
6
|
//# sourceMappingURL=syncWithSearch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Search/hooks/syncWithSearch.ts"],"sourcesContent":["import type {
|
|
1
|
+
{"version":3,"sources":["../../../src/Search/hooks/syncWithSearch.ts"],"sourcesContent":["import type { SyncWithSearch } from '../../types.js'\n\nimport { syncDocAsSearchIndex } from '../../utilities/syncDocAsSearchIndex.js'\n\nexport const syncWithSearch: SyncWithSearch = (args) => {\n return syncDocAsSearchIndex(args)\n}\n"],"names":["syncDocAsSearchIndex","syncWithSearch","args"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,0CAAyC;AAE9E,OAAO,MAAMC,iBAAiC,CAACC;IAC7C,OAAOF,qBAAqBE;AAC9B,EAAC"}
|
package/dist/Search/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { CollectionConfig } from 'payload';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const generateSearchCollection: (pluginConfig:
|
|
2
|
+
import type { SearchPluginConfigWithLocales } from '../types.js';
|
|
3
|
+
export declare const generateSearchCollection: (pluginConfig: SearchPluginConfigWithLocales) => CollectionConfig;
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Search/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Search/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,SAAS,CAAA;AAEtD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAA;AAKhE,eAAO,MAAM,wBAAwB,iBACrB,6BAA6B,KAC1C,gBAqGF,CAAA"}
|
package/dist/Search/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { generateReindexHandler } from '../utilities/generateReindexHandler.js';
|
|
1
2
|
// all settings can be overridden by the config
|
|
2
3
|
export const generateSearchCollection = (pluginConfig)=>{
|
|
4
|
+
const searchSlug = pluginConfig?.searchOverrides?.slug || 'search';
|
|
5
|
+
const searchCollections = pluginConfig?.collections || [];
|
|
6
|
+
const collectionLabels = pluginConfig?.labels;
|
|
3
7
|
const defaultFields = [
|
|
4
8
|
{
|
|
5
9
|
name: 'title',
|
|
@@ -25,7 +29,7 @@ export const generateSearchCollection = (pluginConfig)=>{
|
|
|
25
29
|
},
|
|
26
30
|
index: true,
|
|
27
31
|
maxDepth: 0,
|
|
28
|
-
relationTo:
|
|
32
|
+
relationTo: searchCollections,
|
|
29
33
|
required: true
|
|
30
34
|
},
|
|
31
35
|
{
|
|
@@ -43,13 +47,29 @@ export const generateSearchCollection = (pluginConfig)=>{
|
|
|
43
47
|
];
|
|
44
48
|
const newConfig = {
|
|
45
49
|
...pluginConfig?.searchOverrides || {},
|
|
46
|
-
slug:
|
|
50
|
+
slug: searchSlug,
|
|
47
51
|
access: {
|
|
48
52
|
create: ()=>false,
|
|
49
53
|
read: ()=>true,
|
|
50
54
|
...pluginConfig?.searchOverrides?.access || {}
|
|
51
55
|
},
|
|
52
56
|
admin: {
|
|
57
|
+
components: {
|
|
58
|
+
views: {
|
|
59
|
+
list: {
|
|
60
|
+
actions: [
|
|
61
|
+
{
|
|
62
|
+
path: '@payloadcms/plugin-search/client#ReindexButton',
|
|
63
|
+
serverProps: {
|
|
64
|
+
collectionLabels,
|
|
65
|
+
searchCollections,
|
|
66
|
+
searchSlug
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
]
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
},
|
|
53
73
|
defaultColumns: [
|
|
54
74
|
'title'
|
|
55
75
|
],
|
|
@@ -58,6 +78,14 @@ export const generateSearchCollection = (pluginConfig)=>{
|
|
|
58
78
|
useAsTitle: 'title',
|
|
59
79
|
...pluginConfig?.searchOverrides?.admin || {}
|
|
60
80
|
},
|
|
81
|
+
endpoints: [
|
|
82
|
+
...pluginConfig?.searchOverrides?.endpoints || [],
|
|
83
|
+
{
|
|
84
|
+
handler: generateReindexHandler(pluginConfig),
|
|
85
|
+
method: 'post',
|
|
86
|
+
path: '/reindex'
|
|
87
|
+
}
|
|
88
|
+
],
|
|
61
89
|
fields: pluginConfig?.searchOverrides?.fields && typeof pluginConfig?.searchOverrides?.fields === 'function' ? pluginConfig?.searchOverrides.fields({
|
|
62
90
|
defaultFields
|
|
63
91
|
}) : defaultFields,
|
package/dist/Search/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Search/index.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/Search/index.ts"],"sourcesContent":["import type { CollectionConfig, Field } from 'payload'\n\nimport type { SearchPluginConfigWithLocales } from '../types.js'\n\nimport { generateReindexHandler } from '../utilities/generateReindexHandler.js'\n\n// all settings can be overridden by the config\nexport const generateSearchCollection = (\n pluginConfig: SearchPluginConfigWithLocales,\n): CollectionConfig => {\n const searchSlug = pluginConfig?.searchOverrides?.slug || 'search'\n const searchCollections = pluginConfig?.collections || []\n const collectionLabels = pluginConfig?.labels\n\n const defaultFields: Field[] = [\n {\n name: 'title',\n type: 'text',\n admin: {\n readOnly: true,\n },\n localized: pluginConfig.localize,\n },\n {\n name: 'priority',\n type: 'number',\n admin: {\n position: 'sidebar',\n },\n },\n {\n name: 'doc',\n type: 'relationship',\n admin: {\n position: 'sidebar',\n readOnly: true,\n },\n index: true,\n maxDepth: 0,\n relationTo: searchCollections,\n required: true,\n },\n {\n name: 'docUrl',\n type: 'ui',\n admin: {\n components: {\n Field: {\n path: '@payloadcms/plugin-search/client#LinkToDoc',\n },\n },\n position: 'sidebar',\n },\n },\n ]\n\n const newConfig: CollectionConfig = {\n ...(pluginConfig?.searchOverrides || {}),\n slug: searchSlug,\n access: {\n create: (): boolean => false,\n read: (): boolean => true,\n ...(pluginConfig?.searchOverrides?.access || {}),\n },\n admin: {\n components: {\n views: {\n list: {\n actions: [\n {\n path: '@payloadcms/plugin-search/client#ReindexButton',\n serverProps: {\n collectionLabels,\n searchCollections,\n searchSlug,\n },\n },\n ],\n },\n },\n },\n defaultColumns: ['title'],\n description:\n 'This is a collection of automatically created search results. These results are used by the global site search and will be updated automatically as documents in the CMS are created or updated.',\n enableRichTextRelationship: false,\n useAsTitle: 'title',\n ...(pluginConfig?.searchOverrides?.admin || {}),\n },\n endpoints: [\n ...(pluginConfig?.searchOverrides?.endpoints || []),\n {\n handler: generateReindexHandler(pluginConfig),\n method: 'post',\n path: '/reindex',\n },\n ],\n fields:\n pluginConfig?.searchOverrides?.fields &&\n typeof pluginConfig?.searchOverrides?.fields === 'function'\n ? pluginConfig?.searchOverrides.fields({ defaultFields })\n : defaultFields,\n labels: {\n ...(pluginConfig?.searchOverrides?.labels || {\n plural: 'Search Results',\n singular: 'Search Result',\n }),\n },\n }\n\n return newConfig\n}\n"],"names":["generateReindexHandler","generateSearchCollection","pluginConfig","searchSlug","searchOverrides","slug","searchCollections","collections","collectionLabels","labels","defaultFields","name","type","admin","readOnly","localized","localize","position","index","maxDepth","relationTo","required","components","Field","path","newConfig","access","create","read","views","list","actions","serverProps","defaultColumns","description","enableRichTextRelationship","useAsTitle","endpoints","handler","method","fields","plural","singular"],"mappings":"AAIA,SAASA,sBAAsB,QAAQ,yCAAwC;AAE/E,+CAA+C;AAC/C,OAAO,MAAMC,2BAA2B,CACtCC;I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AgBoC,OAAO;YAAE9B;QAAc,KACrDA;QACND,QAAQ;YACN,GAAIP,cAAcE,iBAAiBK,UAAU;gBAC3CgC,QAAQ;gBACRC,UAAU;YACZ,CAAC;QACH;IACF;IAEA,OAAOjB;AACT,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/LinkToDoc/index.client.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EA+CnC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/Search/ui/LinkToDoc/index.client.tsx"],"sourcesContent":["'use client'\n\nimport { useConfig, useField } from '@payloadcms/ui'\nimport { formatAdminURL } from '@payloadcms/ui/shared'\nimport React from 'react'\n// TODO: fix this import to work in dev mode within the monorepo in a way that is backwards compatible with 1.x\n// import CopyToClipboard from 'payload/dist/admin/components/elements/CopyToClipboard'\n\nexport const LinkToDocClient: React.FC = () => {\n const { config } = useConfig()\n\n const {\n routes: {\n admin: adminRoute, // already includes leading slash\n },\n serverURL,\n } = config\n\n const { value } = useField<{ relationTo?: string; value?: string }>({ path: 'doc' })\n\n const href = `${serverURL}${formatAdminURL({\n adminRoute,\n path: `/collections/${value.relationTo || ''}/${value.value || ''}`,\n })}`\n\n if (!value.relationTo || !value.value) {\n return null\n }\n\n return (\n <div style={{ marginBottom: 'var(--spacing-field, 1rem)' }}>\n <div>\n <span\n className=\"label\"\n style={{\n color: '#9A9A9A',\n }}\n >\n Doc URL\n </span>\n {/* <CopyToClipboard value={href} /> */}\n </div>\n <div\n style={{\n fontWeight: '600',\n overflow: 'hidden',\n textOverflow: 'ellipsis',\n }}\n >\n <a href={href} target=\"_blank\">\n {href}\n </a>\n </div>\n </div>\n )\n}\n"],"names":["useConfig","useField","formatAdminURL","React","LinkToDocClient","config","routes","admin","adminRoute","serverURL","value","path","href","relationTo","div","style","marginBottom","span","className","color","fontWeight","overflow","textOverflow","a","target"],"mappings":"AAAA;;AAEA,SAASA,SAAS,EAAEC,QAAQ,QAAQ,iBAAgB;AACpD,SAASC,cAAc,QAAQ,wBAAuB;AACtD,OAAOC,WAAW,QAAO;AACzB,+GAA+G;AAC/G,uFAAuF;AAEvF,OAAO,MAAMC,kBAA4B;IACvC,MAAM,EAAEC,MAAM,EAAE,GAAGL;IAEnB,MAAM,EACJM,QAAQ,EACNC,OAAOC,UAAU,EAClB,EACDC,SAAS,EACV,GAAGJ;IAEJ,MAAM,EAAEK,KAAK,EAAE,GAAGT,SAAkD;QAAEU,MAAM;IAAM;IAElF,MAAMC,OAAO,CAAC,EAAEH,UAAU,EAAEP,eAAe;QACzCM;QACAG,MAAM,CAAC,aAAa,EAAED,MAAMG,UAAU,IAAI,GAAG,CAAC,EAAEH,MAAMA,KAAK,IAAI,GAAG,CAAC;IACrE,GAAG,CAAC;IAEJ,IAAI,CAACA,MAAMG,UAAU,IAAI,CAACH,MAAMA,KAAK,EAAE;QACrC,OAAO;IACT;IAEA,qBACE,MAACI;QAAIC,OAAO;YAAEC,cAAc;QAA6B;;0BACvD,KAACF;0BACC,cAAA,KAACG;oBACCC,WAAU;oBACVH,OAAO;wBACLI,OAAO;oBACT;8BACD;;;0BAKH,KAACL;gBACCC,OAAO;oBACLK,YAAY;oBACZC,UAAU;oBACVC,cAAc;gBAChB;0BAEA,cAAA,KAACC;oBAAEX,MAAMA;oBAAMY,QAAO;8BACnBZ;;;;;AAKX,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/LinkToDoc/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,MAAM,OAAO,CAAA;AAIzB,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,EAAE,CAAC,OAAO,CAEvC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/Search/ui/LinkToDoc/index.tsx"],"sourcesContent":["import type { UIField } from 'payload'\n\nimport React from 'react'\n\nimport { LinkToDocClient } from './index.client.js'\n\nexport const LinkToDoc: React.FC<UIField> = () => {\n return <LinkToDocClient />\n}\n"],"names":["React","LinkToDocClient","LinkToDoc"],"mappings":";AAEA,OAAOA,WAAW,QAAO;AAEzB,SAASC,eAAe,QAAQ,oBAAmB;AAEnD,OAAO,MAAMC,YAA+B;IAC1C,qBAAO,KAACD;AACV,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/Search/ui/ReindexButton/ReindexButtonLabel/index.tsx"],"names":[],"mappings":"AAEA,eAAO,MAAM,kBAAkB,mCAS9B,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { ChevronIcon, Pill, useTranslation } from '@payloadcms/ui';
|
|
3
|
+
export const ReindexButtonLabel = ()=>{
|
|
4
|
+
const { i18n: { t } } = useTranslation();
|
|
5
|
+
return /*#__PURE__*/ _jsx(Pill, {
|
|
6
|
+
className: "pill--has-action",
|
|
7
|
+
icon: /*#__PURE__*/ _jsx(ChevronIcon, {}),
|
|
8
|
+
pillStyle: "light",
|
|
9
|
+
children: t('general:reindex')
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../src/Search/ui/ReindexButton/ReindexButtonLabel/index.tsx"],"sourcesContent":["import { ChevronIcon, Pill, useTranslation } from '@payloadcms/ui'\n\nexport const ReindexButtonLabel = () => {\n const {\n i18n: { t },\n } = useTranslation()\n return (\n <Pill className=\"pill--has-action\" icon={<ChevronIcon />} pillStyle=\"light\">\n {t('general:reindex')}\n </Pill>\n )\n}\n"],"names":["ChevronIcon","Pill","useTranslation","ReindexButtonLabel","i18n","t","className","icon","pillStyle"],"mappings":";AAAA,SAASA,WAAW,EAAEC,IAAI,EAAEC,cAAc,QAAQ,iBAAgB;AAElE,OAAO,MAAMC,qBAAqB;IAChC,MAAM,EACJC,MAAM,EAAEC,CAAC,EAAE,EACZ,GAAGH;IACJ,qBACE,KAACD;QAAKK,WAAU;QAAmBC,oBAAM,KAACP;QAAgBQ,WAAU;kBACjEH,EAAE;;AAGT,EAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAC,EAAET,UAAU,SAAS,CAAC;;8BACrC,MAACU;oBAAID,WAAW,CAAC,EAAET,UAAU,SAAS,CAAC;;sCACrC,KAACW;sCAAIL;;sCACL,KAACM;sCAAGT;;;;8BAEN,MAACO;oBAAID,WAAW,CAAC,EAAET,UAAU,UAAU,CAAC;;sCACtC,KAACH;4BAAOgB,aAAY;4BAAYC,SAASV;4BAAUW,MAAK;sCACrDP,EAAE;;sCAEL,KAACX;4BAAOiB,SAAST;4BAAWU,MAAK;sCAC9BP,EAAE;;;;;;;AAMf,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.client.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/index.client.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAyC,MAAM,OAAO,CAAA;AAE7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAOpD,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CAmI5D,CAAA"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { LoadingOverlay, Popup, PopupList, toast, useLocale, useModal, useTranslation } from '@payloadcms/ui';
|
|
4
|
+
import { useRouter } from 'next/navigation.js';
|
|
5
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
6
|
+
import { ReindexButtonLabel } from './ReindexButtonLabel/index.js';
|
|
7
|
+
import { ReindexConfirmModal } from './ReindexConfirmModal/index.js';
|
|
8
|
+
const confirmReindexModalSlug = 'confirm-reindex-modal';
|
|
9
|
+
export const ReindexButtonClient = ({ collectionLabels, searchCollections, searchSlug })=>{
|
|
10
|
+
const { closeModal, openModal } = useModal();
|
|
11
|
+
const { i18n: { t } } = useTranslation();
|
|
12
|
+
const locale = useLocale();
|
|
13
|
+
const router = useRouter();
|
|
14
|
+
const [reindexCollections, setReindexCollections] = useState([]);
|
|
15
|
+
const [isLoading, setLoading] = useState(false);
|
|
16
|
+
const openConfirmModal = useCallback(()=>openModal(confirmReindexModalSlug), [
|
|
17
|
+
openModal
|
|
18
|
+
]);
|
|
19
|
+
const closeConfirmModal = useCallback(()=>closeModal(confirmReindexModalSlug), [
|
|
20
|
+
closeModal
|
|
21
|
+
]);
|
|
22
|
+
const handleReindexSubmit = useCallback(async ()=>{
|
|
23
|
+
if (isLoading || !reindexCollections.length) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
closeConfirmModal();
|
|
27
|
+
setLoading(true);
|
|
28
|
+
try {
|
|
29
|
+
const endpointRes = await fetch(`/api/${searchSlug}/reindex?locale=${locale.code}`, {
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
collections: reindexCollections
|
|
32
|
+
}),
|
|
33
|
+
method: 'POST'
|
|
34
|
+
});
|
|
35
|
+
const { message } = await endpointRes.json();
|
|
36
|
+
if (!endpointRes.ok) {
|
|
37
|
+
toast.error(message);
|
|
38
|
+
} else {
|
|
39
|
+
toast.success(message);
|
|
40
|
+
router.refresh();
|
|
41
|
+
}
|
|
42
|
+
} catch (err) {
|
|
43
|
+
// swallow error, toast shown above
|
|
44
|
+
} finally{
|
|
45
|
+
setReindexCollections([]);
|
|
46
|
+
setLoading(false);
|
|
47
|
+
}
|
|
48
|
+
}, [
|
|
49
|
+
closeConfirmModal,
|
|
50
|
+
isLoading,
|
|
51
|
+
reindexCollections,
|
|
52
|
+
router,
|
|
53
|
+
searchSlug,
|
|
54
|
+
locale
|
|
55
|
+
]);
|
|
56
|
+
const handleShowConfirmModal = useCallback((collections = searchCollections)=>{
|
|
57
|
+
setReindexCollections(typeof collections === 'string' ? [
|
|
58
|
+
collections
|
|
59
|
+
] : collections);
|
|
60
|
+
openConfirmModal();
|
|
61
|
+
}, [
|
|
62
|
+
openConfirmModal,
|
|
63
|
+
searchCollections
|
|
64
|
+
]);
|
|
65
|
+
const handlePopupButtonClick = useCallback((closePopup, slug)=>{
|
|
66
|
+
closePopup();
|
|
67
|
+
handleShowConfirmModal(slug);
|
|
68
|
+
}, [
|
|
69
|
+
handleShowConfirmModal
|
|
70
|
+
]);
|
|
71
|
+
const getPluralizedLabel = useCallback((slug)=>{
|
|
72
|
+
const label = collectionLabels[slug];
|
|
73
|
+
if (typeof label === 'string') {
|
|
74
|
+
return label;
|
|
75
|
+
} else {
|
|
76
|
+
return Object.hasOwn(label, locale.code) ? label[locale.code] : slug;
|
|
77
|
+
}
|
|
78
|
+
}, [
|
|
79
|
+
collectionLabels,
|
|
80
|
+
locale.code
|
|
81
|
+
]);
|
|
82
|
+
const pluralizedLabels = useMemo(()=>{
|
|
83
|
+
return searchCollections.reduce((acc, slug)=>{
|
|
84
|
+
acc[slug] = getPluralizedLabel(slug);
|
|
85
|
+
return acc;
|
|
86
|
+
}, {});
|
|
87
|
+
}, [
|
|
88
|
+
searchCollections,
|
|
89
|
+
getPluralizedLabel
|
|
90
|
+
]);
|
|
91
|
+
const selectedAll = reindexCollections.length === searchCollections.length;
|
|
92
|
+
const selectedLabels = reindexCollections.map((slug)=>pluralizedLabels[slug]).join(', ');
|
|
93
|
+
const modalTitle = selectedAll ? t('general:confirmReindexAll') : t('general:confirmReindex', {
|
|
94
|
+
collections: selectedLabels
|
|
95
|
+
});
|
|
96
|
+
const modalDescription = selectedAll ? t('general:confirmReindexDescriptionAll') : t('general:confirmReindexDescription', {
|
|
97
|
+
collections: selectedLabels
|
|
98
|
+
});
|
|
99
|
+
const loadingText = selectedAll ? t('general:reindexingAll', {
|
|
100
|
+
collections: t('general:collections')
|
|
101
|
+
}) : t('general:reindexingAll', {
|
|
102
|
+
collections: selectedLabels
|
|
103
|
+
});
|
|
104
|
+
return /*#__PURE__*/ _jsxs("div", {
|
|
105
|
+
children: [
|
|
106
|
+
/*#__PURE__*/ _jsx(Popup, {
|
|
107
|
+
button: /*#__PURE__*/ _jsx(ReindexButtonLabel, {}),
|
|
108
|
+
render: ({ close })=>/*#__PURE__*/ _jsxs(PopupList.ButtonGroup, {
|
|
109
|
+
children: [
|
|
110
|
+
searchCollections.map((collectionSlug)=>/*#__PURE__*/ _jsx(PopupList.Button, {
|
|
111
|
+
onClick: ()=>handlePopupButtonClick(close, collectionSlug),
|
|
112
|
+
children: pluralizedLabels[collectionSlug]
|
|
113
|
+
}, collectionSlug)),
|
|
114
|
+
/*#__PURE__*/ _jsx(PopupList.Button, {
|
|
115
|
+
onClick: ()=>handlePopupButtonClick(close),
|
|
116
|
+
children: t('general:allCollections')
|
|
117
|
+
})
|
|
118
|
+
]
|
|
119
|
+
}),
|
|
120
|
+
showScrollbar: true,
|
|
121
|
+
size: "large",
|
|
122
|
+
verticalAlign: "bottom"
|
|
123
|
+
}),
|
|
124
|
+
/*#__PURE__*/ _jsx(ReindexConfirmModal, {
|
|
125
|
+
description: modalDescription,
|
|
126
|
+
onCancel: closeConfirmModal,
|
|
127
|
+
onConfirm: handleReindexSubmit,
|
|
128
|
+
slug: confirmReindexModalSlug,
|
|
129
|
+
title: modalTitle
|
|
130
|
+
}),
|
|
131
|
+
isLoading && /*#__PURE__*/ _jsx(LoadingOverlay, {
|
|
132
|
+
loadingText: loadingText
|
|
133
|
+
})
|
|
134
|
+
]
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
//# sourceMappingURL=index.client.js.map
|
|
@@ -0,0 +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 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 const {\n i18n: { t },\n } = useTranslation()\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(`/api/${searchSlug}/reindex?locale=${locale.code}`, {\n body: JSON.stringify({\n collections: reindexCollections,\n }),\n method: 'POST',\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])\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","useLocale","useModal","useTranslation","useRouter","React","useCallback","useMemo","useState","ReindexButtonLabel","ReindexConfirmModal","confirmReindexModalSlug","ReindexButtonClient","collectionLabels","searchCollections","searchSlug","closeModal","openModal","i18n","t","locale","router","reindexCollections","setReindexCollections","isLoading","setLoading","openConfirmModal","closeConfirmModal","handleReindexSubmit","length","endpointRes","fetch","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,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,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BACtB,KAACrE,UAAUsE,MAAM;oCAEfC,SAAS,IAAMxB,uBAAuBoB,OAAOE;8CAE5Cf,gBAAgB,CAACe,eAAe;mCAH5BA;0CAMT,KAACrE,UAAUsE,MAAM;gCAACC,SAAS,IAAMxB,uBAAuBoB;0CACrD/C,EAAE;;;;gBAIToD,aAAa;gBACbC,MAAK;gBACLC,eAAc;;0BAEhB,KAAC/D;gBACCgE,aAAab;gBACbc,UAAUhD;gBACViD,WAAWhD;gBACXoB,MAAMrC;gBACNkE,OAAOjB;;YAERpC,2BAAa,KAAC3B;gBAAeiE,aAAaA;;;;AAGjD,EAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/Search/ui/ReindexButton/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAA;AAIpE,eAAO,MAAM,aAAa,EAAE,kCA6B3B,CAAA"}
|