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

fix(types): use a minimal type for transformSearchClient #2348

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions packages/docsearch-react/src/DocSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { AutocompleteState, AutocompleteOptions } from '@algolia/autocomplete-core';
import type { SearchClient } from 'algoliasearch';
import type { SearchQuery, LiteClient } from 'algoliasearch/lite';
import type { LiteClient, SearchForHits } from 'algoliasearch/lite';
import React from 'react';
import { createPortal } from 'react-dom';

Expand All @@ -16,17 +15,23 @@ export type DocSearchTranslations = Partial<{
modal: ModalTranslations;
}>;

export type DocSearchTransformClient = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export type DocSearchTransformClient = {
// The interface that describes the minimal implementation required for the algoliasearch client, when using the [`transformSearchClient`](https://docsearch.algolia.com/docs/api/#transformsearchclient) option
export type DocSearchTransformClient = {

wdyt?

we also need to update the definition here https://docsearch.algolia.com/docs/api/#transformsearchclient

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

search: LiteClient['search'];
addAlgoliaAgent: LiteClient['addAlgoliaAgent'];
transporter: Pick<LiteClient['transporter'], 'algoliaAgent'>;
};

export interface DocSearchProps {
appId: string;
apiKey: string;
indexName: string;
placeholder?: string;
searchParameters?: SearchQuery;
searchParameters?: SearchForHits;
maxResultsPerGroup?: number;
transformItems?: (items: DocSearchHit[]) => DocSearchHit[];
hitComponent?: (props: { hit: InternalDocSearchHit | StoredDocSearchHit; children: React.ReactNode }) => JSX.Element;
resultsFooterComponent?: (props: { state: AutocompleteState<InternalDocSearchHit> }) => JSX.Element | null;
transformSearchClient?: <T extends LiteClient | SearchClient>(searchClient: T) => T;
transformSearchClient?: (searchClient: DocSearchTransformClient) => DocSearchTransformClient;
disableUserPersonalization?: boolean;
initialQuery?: string;
navigator?: AutocompleteOptions<InternalDocSearchHit>['navigator'];
Expand Down
6 changes: 3 additions & 3 deletions packages/docsearch-react/src/useSearchClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { liteClient } from 'algoliasearch/lite';
import type { LiteClient } from 'algoliasearch/lite';
import React from 'react';

import type { DocSearchTransformClient } from './DocSearch';
import { version } from './version';

export function useSearchClient(
appId: string,
apiKey: string,
transformSearchClient: (searchClient: LiteClient) => LiteClient,
): LiteClient {
transformSearchClient: (searchClient: DocSearchTransformClient) => DocSearchTransformClient,
): DocSearchTransformClient {
const searchClient = React.useMemo(() => {
const client = liteClient(appId, apiKey);
client.addAlgoliaAgent('docsearch', version);
Expand Down