fix(plugin-search): gets api route from useConfig (#10632)

This fixes #10631.

Originally the api basepath for the reindex button is resolved during
plugin initialization. Looks like this happens before payload overrides
the config with the `basePath `from the next config.
I've changed it so that it uses the `useConfig` hook, and manually
tested that it works.

![CleanShot 2568-01-17 at 16 03
16@2x](https://github.com/user-attachments/assets/c931577b-2717-4635-b5c6-17aa1b4eb734)
This commit is contained in:
Suphon T.
2025-02-04 03:14:21 +09:00
committed by GitHub
parent 109de8cdb3
commit 6353cf8bbe
4 changed files with 3 additions and 6 deletions

View File

@@ -8,7 +8,6 @@ import { generateReindexHandler } from '../utilities/generateReindexHandler.js'
export const generateSearchCollection = (
pluginConfig: SearchPluginConfigWithLocales,
): CollectionConfig => {
const apiBasePath = pluginConfig?.apiBasePath || '/api'
const searchSlug = pluginConfig?.searchOverrides?.slug || 'search'
const searchCollections = pluginConfig?.collections || []
const collectionLabels = pluginConfig?.labels
@@ -71,7 +70,6 @@ export const generateSearchCollection = (
{
path: '@payloadcms/plugin-search/client#ReindexButton',
serverProps: {
apiBasePath,
collectionLabels,
searchCollections,
searchSlug,

View File

@@ -5,6 +5,7 @@ import {
Popup,
PopupList,
toast,
useConfig,
useLocale,
useModal,
useTranslation,
@@ -20,11 +21,11 @@ import { ReindexConfirmModal } from './ReindexConfirmModal/index.js'
const confirmReindexModalSlug = 'confirm-reindex-modal'
export const ReindexButtonClient: React.FC<ReindexButtonProps> = ({
apiBasePath,
collectionLabels,
searchCollections,
searchSlug,
}) => {
const apiBasePath = useConfig().config.routes.api
const { closeModal, openModal } = useModal()
const {
i18n: { t },

View File

@@ -3,7 +3,7 @@ import type { SearchReindexButtonServerComponent } from './types.js'
import { ReindexButtonClient } from './index.client.js'
export const ReindexButton: SearchReindexButtonServerComponent = (props) => {
const { apiBasePath, collectionLabels, i18n, searchCollections, searchSlug } = props
const { collectionLabels, i18n, searchCollections, searchSlug } = props
const getStaticLocalizedPluralLabels = () => {
return Object.fromEntries(
@@ -26,7 +26,6 @@ export const ReindexButton: SearchReindexButtonServerComponent = (props) => {
return (
<ReindexButtonClient
apiBasePath={apiBasePath}
collectionLabels={getStaticLocalizedPluralLabels()}
searchCollections={searchCollections}
searchSlug={searchSlug}

View File

@@ -3,7 +3,6 @@ import type { CustomComponent, PayloadServerReactComponent, StaticLabel } from '
import type { CollectionLabels } from '../../../types.js'
export type ReindexButtonProps = {
apiBasePath: string
collectionLabels: Record<string, StaticLabel>
searchCollections: string[]
searchSlug: string