chore(plugin-search): deprecates apiBasePath from config (#10953)
Continuation of #10632. The `apiBasePath` property in the Search Plugin config is unnecessary. This plugin reads directly from the Payload config for this property. Exposing it to the plugin's config was likely a mistake during sanitization before passing it through to the remaining files. This property was added to resolve the types, but as result, exposed it to the config unnecessarily. This PR marks this property with the deprecated flag to prevent breaking changes.
This commit is contained in:
@@ -25,11 +25,14 @@ export const ReindexButtonClient: React.FC<ReindexButtonProps> = ({
|
|||||||
searchCollections,
|
searchCollections,
|
||||||
searchSlug,
|
searchSlug,
|
||||||
}) => {
|
}) => {
|
||||||
const apiBasePath = useConfig().config.routes.api
|
|
||||||
const { closeModal, openModal } = useModal()
|
const { closeModal, openModal } = useModal()
|
||||||
|
|
||||||
|
const { config } = useConfig()
|
||||||
|
|
||||||
const {
|
const {
|
||||||
i18n: { t },
|
i18n: { t },
|
||||||
} = useTranslation()
|
} = useTranslation()
|
||||||
|
|
||||||
const locale = useLocale()
|
const locale = useLocale()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
|
|
||||||
@@ -47,15 +50,16 @@ export const ReindexButtonClient: React.FC<ReindexButtonProps> = ({
|
|||||||
closeConfirmModal()
|
closeConfirmModal()
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
|
|
||||||
const basePath = apiBasePath.endsWith('/') ? apiBasePath.slice(0, -1) : apiBasePath
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const endpointRes = await fetch(`${basePath}/${searchSlug}/reindex?locale=${locale.code}`, {
|
const endpointRes = await fetch(
|
||||||
body: JSON.stringify({
|
`${config.routes.api}/${searchSlug}/reindex?locale=${locale.code}`,
|
||||||
collections: reindexCollections,
|
{
|
||||||
}),
|
body: JSON.stringify({
|
||||||
method: 'POST',
|
collections: reindexCollections,
|
||||||
})
|
}),
|
||||||
|
method: 'POST',
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
const { message } = (await endpointRes.json()) as { message: string }
|
const { message } = (await endpointRes.json()) as { message: string }
|
||||||
|
|
||||||
@@ -65,13 +69,13 @@ export const ReindexButtonClient: React.FC<ReindexButtonProps> = ({
|
|||||||
toast.success(message)
|
toast.success(message)
|
||||||
router.refresh()
|
router.refresh()
|
||||||
}
|
}
|
||||||
} catch (err: unknown) {
|
} catch (_err: unknown) {
|
||||||
// swallow error, toast shown above
|
// swallow error, toast shown above
|
||||||
} finally {
|
} finally {
|
||||||
setReindexCollections([])
|
setReindexCollections([])
|
||||||
setLoading(false)
|
setLoading(false)
|
||||||
}
|
}
|
||||||
}, [closeConfirmModal, isLoading, reindexCollections, router, searchSlug, locale, apiBasePath])
|
}, [closeConfirmModal, isLoading, reindexCollections, router, searchSlug, locale, config])
|
||||||
|
|
||||||
const handleShowConfirmModal = useCallback(
|
const handleShowConfirmModal = useCallback(
|
||||||
(collections: string | string[] = searchCollections) => {
|
(collections: string | string[] = searchCollections) => {
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ export const searchPlugin =
|
|||||||
|
|
||||||
const pluginConfig: SearchPluginConfigWithLocales = {
|
const pluginConfig: SearchPluginConfigWithLocales = {
|
||||||
// write any config defaults here
|
// write any config defaults here
|
||||||
apiBasePath: config.routes?.api,
|
|
||||||
deleteDrafts: true,
|
deleteDrafts: true,
|
||||||
labels,
|
labels,
|
||||||
locales,
|
locales,
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ export type BeforeSync = (args: {
|
|||||||
export type FieldsOverride = (args: { defaultFields: Field[] }) => Field[]
|
export type FieldsOverride = (args: { defaultFields: Field[] }) => Field[]
|
||||||
|
|
||||||
export type SearchPluginConfig = {
|
export type SearchPluginConfig = {
|
||||||
|
/**
|
||||||
|
* @deprecated
|
||||||
|
* This plugin gets the api route from the config directly and does not need to be passed in.
|
||||||
|
* As long as you have `routes.api` set in your Payload config, the plugin will use that.
|
||||||
|
* This property will be removed in the next major version.
|
||||||
|
*/
|
||||||
apiBasePath?: string
|
apiBasePath?: string
|
||||||
beforeSync?: BeforeSync
|
beforeSync?: BeforeSync
|
||||||
collections?: string[]
|
collections?: string[]
|
||||||
|
|||||||
Reference in New Issue
Block a user