Skip to content

Commit

Permalink
feat: pass insights option default to undefined (#1198)
Browse files Browse the repository at this point in the history
Co-authored-by: Dhaya <154633+dhayab@users.noreply.github.com>
  • Loading branch information
sarahdayan and dhayab committed Oct 9, 2023
1 parent 5fd58f6 commit 2f5c683
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/autocomplete-core/src/createAutocomplete.ts
Expand Up @@ -69,11 +69,11 @@ export function createAutocomplete<
}

if (
options.insights &&
props.insights &&
!props.plugins.some((plugin) => plugin.name === 'aa.algoliaInsightsPlugin')
) {
const insightsParams =
typeof options.insights === 'boolean' ? {} : options.insights;
typeof props.insights === 'boolean' ? {} : props.insights;
props.plugins.push(createAlgoliaInsightsPlugin(insightsParams));
}

Expand Down
2 changes: 1 addition & 1 deletion packages/autocomplete-core/src/getDefaultProps.ts
Expand Up @@ -32,7 +32,7 @@ export function getDefaultProps<TItem extends BaseItem>(
autoFocus: false,
defaultActiveItemId: null,
stallThreshold: 300,
insights: false,
insights: undefined,
environment,
shouldPanelOpen: ({ state }) => getItemsCount(state) > 0,
reshape: ({ sources }) => sources,
Expand Down
18 changes: 13 additions & 5 deletions packages/autocomplete-core/src/types/index.ts
Expand Up @@ -9,20 +9,28 @@ import {
} from '@algolia/autocomplete-plugin-algolia-insights';
import {
AutocompleteOptions as _AutocompleteOptions,
InternalAutocompleteOptions as _InternalAutocompleteOptions,
BaseItem,
} from '@algolia/autocomplete-shared/dist/esm/core';

export type AutocompleteInsightsApi = _AutocompleteInsightsApi;
export type AlgoliaInsightsHit = _AlgoliaInsightsHit;
export interface AutocompleteOptions<TItem extends BaseItem>
extends _AutocompleteOptions<TItem> {

type InsightsOption = {
/**
* Whether to enable the Insights plugin and load the Insights library if it has not been loaded yet.
*
* See [**autocomplete-plugin-algolia-insights**](https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-plugin-algolia-insights/) for more information.
*
* @default false
* @default undefined
* @link https://www.algolia.com/doc/ui-libraries/autocomplete/api-reference/autocomplete-js/autocomplete/#param-insights
*/
insights?: CreateAlgoliaInsightsPluginParams | boolean;
}
insights?: CreateAlgoliaInsightsPluginParams | boolean | undefined;
};

export interface AutocompleteOptions<TItem extends BaseItem>
extends _AutocompleteOptions<TItem>,
InsightsOption {}
export interface InternalAutocompleteOptions<TItem extends BaseItem>
extends _InternalAutocompleteOptions<TItem>,
InsightsOption {}

0 comments on commit 2f5c683

Please sign in to comment.