Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(plugin-search): deprecates apiBasePath from config #10953

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions packages/plugin-search/src/Search/ui/ReindexButton/index.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ export const ReindexButtonClient: React.FC<ReindexButtonProps> = ({
searchCollections,
searchSlug,
}) => {
const apiBasePath = useConfig().config.routes.api
const { closeModal, openModal } = useModal()

const { config } = useConfig()

const {
i18n: { t },
} = useTranslation()

const locale = useLocale()
const router = useRouter()

Expand All @@ -47,15 +50,16 @@ export const ReindexButtonClient: React.FC<ReindexButtonProps> = ({
closeConfirmModal()
setLoading(true)

const basePath = apiBasePath.endsWith('/') ? apiBasePath.slice(0, -1) : apiBasePath

try {
const endpointRes = await fetch(`${basePath}/${searchSlug}/reindex?locale=${locale.code}`, {
body: JSON.stringify({
collections: reindexCollections,
}),
method: 'POST',
})
const endpointRes = await fetch(
`${config.routes.api}/${searchSlug}/reindex?locale=${locale.code}`,
{
body: JSON.stringify({
collections: reindexCollections,
}),
method: 'POST',
},
)

const { message } = (await endpointRes.json()) as { message: string }

Expand All @@ -65,13 +69,13 @@ export const ReindexButtonClient: React.FC<ReindexButtonProps> = ({
toast.success(message)
router.refresh()
}
} catch (err: unknown) {
} catch (_err: unknown) {
// swallow error, toast shown above
} finally {
setReindexCollections([])
setLoading(false)
}
}, [closeConfirmModal, isLoading, reindexCollections, router, searchSlug, locale, apiBasePath])
}, [closeConfirmModal, isLoading, reindexCollections, router, searchSlug, locale, config])

const handleShowConfirmModal = useCallback(
(collections: string | string[] = searchCollections) => {
Expand Down
1 change: 0 additions & 1 deletion packages/plugin-search/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export const searchPlugin =

const pluginConfig: SearchPluginConfigWithLocales = {
// write any config defaults here
apiBasePath: config.routes?.api,
deleteDrafts: true,
labels,
locales,
Expand Down
6 changes: 6 additions & 0 deletions packages/plugin-search/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ export type BeforeSync = (args: {
export type FieldsOverride = (args: { defaultFields: Field[] }) => Field[]

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
beforeSync?: BeforeSync
collections?: string[]
Expand Down