UNPKG

@empathyco/x-components

Version:
153 lines 5.58 kB
import type { Facet, Filter } from '@empathyco/x-types'; import type { Dictionary } from '@empathyco/x-utils'; import type { Store } from 'vuex'; import type { RootXStoreState } from '../../../store/index'; import type { FilterEntity } from '../entities/types'; import type { FacetGroupEntry, FacetsGetters } from '../store/types'; import type { FacetsGroup, FacetsService, FiltersMetadata } from './types'; import { FilterEntityFactory } from '../entities/filter-entity.factory'; /** * Default implementation for the {@link FacetsService}. * * @public */ export declare class DefaultFacetsService implements FacetsService { protected filterEntityFactory: FilterEntityFactory; /** * Global instance of the {@link FacetsService}. */ static instance: FacetsService; constructor(filterEntityFactory?: FilterEntityFactory); /** * The {@link https://vuex.vuejs.org/ | Vuex} store to use in the service. * * @returns The store. * @internal */ protected get store(): Store<RootXStoreState>; setFacets(facetsGroup: FacetsGroup): void; updateFacets(facetsGroup: FacetsGroup): void; updatePreselectedFilters(filters: Filter[]): void; selectPreselectedFilters(): void; clearFilters(facetIds?: Array<Facet['id']>, metadata?: FiltersMetadata): void; clearFiltersWithMetadata({ facetIds, metadata, }?: { facetIds?: Array<Facet['id']>; metadata?: FiltersMetadata; }): void; deselect(filter: Filter, metadata?: Dictionary): void; select(filterOrFilters: Filter | Filter[]): void; toggle(filter: Filter): void; /** * Sets the query. * * @param query - The query searched. * @internal */ setQuery(query: string): void; /** * Creates an entity from a filter DTO. * * @param filter - The filter to create an entity from. * @returns The filter entity. * @internal */ protected getFilterEntity(filter: Filter): FilterEntity; /** * Sets in the store the Facets, the Filters and the FacetsGroup, without applying any logic * to the selected state. * * @param facetsGroup - The {@link FacetsGroup} to set into the store state. * @returns An array with the new filters. * @internal */ protected updateStore(facetsGroup: FacetsGroup): Filter[]; /** * This function returns the filters of the facets group flattened in an array. It keeps the * relations between the filters (parent--children). * * @privateRemarks If it is necessary to deal with more cases than the hierarchical, we need to * refactor this logic and maybe move it to the entities, to not make this service dependant of * the facet type. At the moment it is only one `if`, and is ok as long as no more `if`s are * needed. * @param facetsGroup - The facets group from where extract the filters to flat. * @returns An array with the filters flattened. * @internal */ protected flatFilters(facetsGroup: FacetsGroup): Filter[]; /** * Retrieves the selected filters from the store. * * @returns The list of selected filters of the store. * @internal */ protected getSelectedFilters(): FacetsGetters['selectedFilters']; /** * Changes the filters selection state to match the store. * * @param newFilters - The list of filters to save. * @param previousFilters - (Optional) The list of old filters, used to set the `newFilters` * selected state. */ protected updateFiltersSelectedState(newFilters: Filter[], previousFilters?: Filter[]): void; /** * Removes the filters that belong to the given group. * * @param groupId - The id of the group from whom remove the filters that are in the store. * * @returns The removed filters. * * @internal */ protected removeGroupFilters(groupId: FacetsGroup['id']): Filter[]; /** * Removes the facets that belong to the given group. * * @param groupId - The id of the group from whom remove the facets that are in the store. * @returns The removed facets. * @internal */ protected removeGroupFacets(groupId: FacetsGroup['id']): Omit<Facet, 'filters'>[]; /** * Sets the group that a facet belongs to. * * @param facetGroup - The id of the facet, and the group it belongs to. * @internal */ protected setFacetGroup(facetGroup: FacetGroupEntry): void; /** * Sets the Facet to the store facets record. * * @param facet - The facet to store. * @internal */ protected setFacet({ filters, ...restFacet }: Facet): void; /** * Removes a facet from the store. * * @param facet - The facet to remove. * @internal */ protected removeFacet(facet: Omit<Facet, 'filters'>): void; /** * Saves a list of filters to the store without any state change logic applied. * * @param filters - The filters to save. * @internal */ protected setFilters(filters: Filter[]): void; /** * Saves a list of preselected filters to the store without any state change logic applied. * * @param filters - The filters to save. * @internal */ protected setPreselectedFilter(filters: Filter[]): void; /** * Removes a list of filters from the store. * * @param filters - The filters to remove. * @internal */ protected removeFilters(filters: Filter[]): void; } //# sourceMappingURL=facets.service.d.ts.map