diff --git a/packages/x-components/src/store/utils/config-store.utils.ts b/packages/x-components/src/store/utils/config-store.utils.ts index fdde8e4105..ee6210fcee 100644 --- a/packages/x-components/src/store/utils/config-store.utils.ts +++ b/packages/x-components/src/store/utils/config-store.utils.ts @@ -1,3 +1,5 @@ +import Vue from 'vue'; + /** * Config mutations, containing a method to change the current config and other to merge * a new one. @@ -28,7 +30,7 @@ export interface ConfigMutations { * @public */ export function setConfig(state: T, config: T['config']): void { - state.config = config; + Vue.set(state, 'config', config); } /** @@ -43,8 +45,5 @@ export function mergeConfig( state: T, config: Partial ): void { - state.config = { - ...state.config, - ...config - }; + Object.assign(state.config, config); } diff --git a/packages/x-components/src/x-modules/empathize/store/module.ts b/packages/x-components/src/x-modules/empathize/store/module.ts index d53bb61691..70fd0e4b06 100644 --- a/packages/x-components/src/x-modules/empathize/store/module.ts +++ b/packages/x-components/src/x-modules/empathize/store/module.ts @@ -1,3 +1,4 @@ +import { setConfig, mergeConfig } from '../../../store/utils/config-store.utils'; import { EmpathizeXStoreModule } from './types'; /** @@ -14,7 +15,9 @@ export const empathizeXStoreModule: EmpathizeXStoreModule = { mutations: { setIsOpen(state, isOpen) { state.isOpen = isOpen; - } + }, + setConfig, + mergeConfig }, actions: {} }; diff --git a/packages/x-components/src/x-modules/empathize/store/types.ts b/packages/x-components/src/x-modules/empathize/store/types.ts index 414cd5211e..7a79a8afb3 100644 --- a/packages/x-components/src/x-modules/empathize/store/types.ts +++ b/packages/x-components/src/x-modules/empathize/store/types.ts @@ -1,5 +1,6 @@ import { XStoreModule } from '../../../store'; import { EmpathizeConfig } from '../config.types'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * Empathize store state. @@ -33,7 +34,7 @@ export interface EmpathizeGetters {} * * @public */ -export interface EmpathizeMutations { +export interface EmpathizeMutations extends ConfigMutations { /** * Sets the isOpen state of the module, which is used in the Alias API. * diff --git a/packages/x-components/src/x-modules/facets/store/__tests__/getters.spec.ts b/packages/x-components/src/x-modules/facets/store/__tests__/getters.spec.ts index a8b8b63b0a..ede77ce1d7 100644 --- a/packages/x-components/src/x-modules/facets/store/__tests__/getters.spec.ts +++ b/packages/x-components/src/x-modules/facets/store/__tests__/getters.spec.ts @@ -239,7 +239,7 @@ describe('testing facets module getters', () => { ); const store = createFacetsStore([parentFilter, childFilter, parentFilterWithoutChild], []); - store.commit('setFacetsConfig', { + store.commit('setConfig', { filtersStrategyForRequest: 'leaves-only' }); diff --git a/packages/x-components/src/x-modules/facets/store/module.ts b/packages/x-components/src/x-modules/facets/store/module.ts index 3c6b55f875..c4e6a0df50 100644 --- a/packages/x-components/src/x-modules/facets/store/module.ts +++ b/packages/x-components/src/x-modules/facets/store/module.ts @@ -1,9 +1,11 @@ import { Facet } from '@empathyco/x-types'; import Vue from 'vue'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; +import { setQuery } from '../../../store/utils/query.utils'; import { facets } from './getters/facets.getter'; import { selectedFiltersByFacet } from './getters/selected-filters-by-facet.getter'; import { selectedFilters } from './getters/selected-filters.getter'; -import { FacetGroupEntry, FacetsConfig, FacetsXStoreModule } from './types'; +import { FacetGroupEntry, FacetsXStoreModule } from './types'; import { selectedFiltersForRequest } from './getters/selected-filters-for-request.getter'; /** @@ -55,12 +57,9 @@ export const facetsXStoreModule: FacetsXStoreModule = { setFacet(state, facet: Facet) { Vue.set(state.facets, facet.id, facet); }, - setFacetsConfig(state, config: FacetsConfig) { - state.config = config; - }, - setQuery(state, query) { - state.query = query; - }, + setConfig, + mergeConfig, + setQuery, setStickyFilter(state, filter) { if (!state.stickyFilters[filter.id]) { Vue.set(state.stickyFilters, filter.id, filter); diff --git a/packages/x-components/src/x-modules/facets/store/types.ts b/packages/x-components/src/x-modules/facets/store/types.ts index 713259e405..231a1c428f 100644 --- a/packages/x-components/src/x-modules/facets/store/types.ts +++ b/packages/x-components/src/x-modules/facets/store/types.ts @@ -1,5 +1,6 @@ import { Facet, Filter, RawFilter } from '@empathyco/x-types'; import { XActionContext, XStoreModule } from '../../../store'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * Facets store state. @@ -52,7 +53,7 @@ export interface FacetsGetters { * * @public */ -export interface FacetsMutations { +export interface FacetsMutations extends ConfigMutations { /** * Updates the state of a filter. * @@ -109,12 +110,6 @@ export interface FacetsMutations { * @param facet - The facet to set in the store. */ setFacet(facet: Facet): void; - /** - * Sets the {@link FacetsState.facets | facets} config. - * - * @param config - The new config. - */ - setFacetsConfig(config: FacetsConfig): void; /** * Adds the filter to the {@link FacetsState.stickyFilters | sticky filters} record. * diff --git a/packages/x-components/src/x-modules/history-queries/store/module.ts b/packages/x-components/src/x-modules/history-queries/store/module.ts index 03f769cf6c..07ac71e705 100644 --- a/packages/x-components/src/x-modules/history-queries/store/module.ts +++ b/packages/x-components/src/x-modules/history-queries/store/module.ts @@ -1,5 +1,6 @@ import { setQuery } from '../../../store/utils/query.utils'; import { localStorageService } from '../../../utils/storage'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; import { addQueryToHistory } from './actions/add-query-to-history.action'; // eslint-disable-next-line max-len import { loadHistoryQueriesFromBrowserStorage } from './actions/load-history-queries-from-browser-storage.action'; @@ -51,6 +52,8 @@ export const historyQueriesXStoreModule: HistoryQueriesXStoreModule = { state.sessionTimeStampInMs = sessionTimeStamp; }, setQuery, + setConfig, + mergeConfig, setIsEnabled(state, isEnabled) { state.isEnabled = isEnabled; }, diff --git a/packages/x-components/src/x-modules/history-queries/store/types.ts b/packages/x-components/src/x-modules/history-queries/store/types.ts index 7013c4693c..e018d20875 100644 --- a/packages/x-components/src/x-modules/history-queries/store/types.ts +++ b/packages/x-components/src/x-modules/history-queries/store/types.ts @@ -4,6 +4,7 @@ import { QueryMutations, QueryState } from '../../../store/utils/query.utils'; import { UrlParams } from '../../../types/url-params'; import { HistoryQueriesConfig } from '../config.types'; import { InternalSearchResponse } from '../../search/index'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * HistoryQueries store state. @@ -68,7 +69,9 @@ export interface HistoryQueriesGetters { * * @public */ -export interface HistoryQueriesMutations extends QueryMutations { +export interface HistoryQueriesMutations + extends QueryMutations, + ConfigMutations { /** * Sets the {@link HistoryQueriesState.historyQueries} property. * diff --git a/packages/x-components/src/x-modules/identifier-results/store/module.ts b/packages/x-components/src/x-modules/identifier-results/store/module.ts index 0ad6f3c0e5..6f3872b5a6 100644 --- a/packages/x-components/src/x-modules/identifier-results/store/module.ts +++ b/packages/x-components/src/x-modules/identifier-results/store/module.ts @@ -1,5 +1,6 @@ import { setQuery } from '../../../store/utils/query.utils'; import { setStatus } from '../../../store/utils/status-store.utils'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; import { cancelFetchAndSaveIdentifierResults, fetchAndSaveIdentifierResults @@ -47,7 +48,9 @@ export const identifierResultsXStoreModule: IdentifierResultsXStoreModule = { state.params = params; }, setQuery, - setStatus + setStatus, + setConfig, + mergeConfig }, actions: { cancelFetchAndSaveIdentifierResults, diff --git a/packages/x-components/src/x-modules/identifier-results/store/types.ts b/packages/x-components/src/x-modules/identifier-results/store/types.ts index e89b229086..cd070f1cbe 100644 --- a/packages/x-components/src/x-modules/identifier-results/store/types.ts +++ b/packages/x-components/src/x-modules/identifier-results/store/types.ts @@ -5,6 +5,7 @@ import { QueryMutations, QueryState } from '../../../store/utils/query.utils'; import { StatusMutations, StatusState } from '../../../store/utils/status-store.utils'; import { QueryOrigin, QueryOriginInit } from '../../../types/origin'; import { IdentifierResultsConfig } from '../config.types'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * IdentifierResults store state. @@ -49,7 +50,10 @@ export interface IdentifierResultsGetters { * * @public */ -export interface IdentifierResultsMutations extends StatusMutations, QueryMutations { +export interface IdentifierResultsMutations + extends StatusMutations, + QueryMutations, + ConfigMutations { /** * Sets the identifier results of the module. * diff --git a/packages/x-components/src/x-modules/next-queries/store/module.ts b/packages/x-components/src/x-modules/next-queries/store/module.ts index e12a5e6b4c..cc8278bbd4 100644 --- a/packages/x-components/src/x-modules/next-queries/store/module.ts +++ b/packages/x-components/src/x-modules/next-queries/store/module.ts @@ -1,5 +1,6 @@ import { setQuery } from '../../../store/utils/query.utils'; import { setStatus } from '../../../store/utils/status-store.utils'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; import { cancelFetchAndSaveNextQueries, fetchAndSaveNextQueries @@ -54,7 +55,9 @@ export const nextQueriesXStoreModule: NextQueriesXStoreModule = { }, resetResultsPreview(state) { state.resultsPreview = {}; - } + }, + setConfig, + mergeConfig }, actions: { cancelFetchAndSaveNextQueries, diff --git a/packages/x-components/src/x-modules/next-queries/store/types.ts b/packages/x-components/src/x-modules/next-queries/store/types.ts index 082c7c6a8a..c1973c47b8 100644 --- a/packages/x-components/src/x-modules/next-queries/store/types.ts +++ b/packages/x-components/src/x-modules/next-queries/store/types.ts @@ -12,6 +12,7 @@ import { StatusMutations, StatusState } from '../../../store/utils/status-store. import { UrlParams } from '../../../types/url-params'; import { NextQueriesConfig } from '../config.types'; import { FeatureLocation } from '../../../types/index'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * Next queries module state. @@ -42,7 +43,7 @@ export interface NextQueriesState extends StatusState, QueryState { export interface NextQueriesGetters { /** * Request object to retrieve the next queries using the search adapter, or null if there is - * not valid data to conform a valid request. + * no valid data to conform a valid request. */ request: NextQueriesRequest | null; /** List of next queries that have not been searched before. */ @@ -54,7 +55,10 @@ export interface NextQueriesGetters { * * @public */ -export interface NextQueriesMutations extends StatusMutations, QueryMutations { +export interface NextQueriesMutations + extends StatusMutations, + QueryMutations, + ConfigMutations { /** * Sets the query of the module, which is used to retrieve the next-queries. * @@ -79,7 +83,6 @@ export interface NextQueriesMutations extends StatusMutations, QueryMutations { * @param params - The new extra params. */ setParams(params: Dictionary): void; - /** * Adds a new entry to the result's dictionary. * @@ -87,7 +90,6 @@ export interface NextQueriesMutations extends StatusMutations, QueryMutations { * the totalResults and the results to add. */ setResultsPreview(resultsPreview: Dictionary): void; - /** * Resets the result's dictionary. */ diff --git a/packages/x-components/src/x-modules/popular-searches/store/module.ts b/packages/x-components/src/x-modules/popular-searches/store/module.ts index 92caeed7e4..5df9abb1e5 100644 --- a/packages/x-components/src/x-modules/popular-searches/store/module.ts +++ b/packages/x-components/src/x-modules/popular-searches/store/module.ts @@ -1,4 +1,5 @@ import { setStatus } from '../../../store/utils/status-store.utils'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; import { cancelFetchAndSaveSuggestions, fetchAndSaveSuggestions @@ -35,10 +36,12 @@ export const popularSearchesXStoreModule: PopularSearchesXStoreModule = { setSearchedQueries(state, searchedQueries) { state.searchedQueries = searchedQueries; }, - setStatus, setParams(state, params) { state.params = params; - } + }, + setStatus, + setConfig, + mergeConfig }, actions: { cancelFetchAndSaveSuggestions, diff --git a/packages/x-components/src/x-modules/popular-searches/store/types.ts b/packages/x-components/src/x-modules/popular-searches/store/types.ts index bffb74824b..992dc6a395 100644 --- a/packages/x-components/src/x-modules/popular-searches/store/types.ts +++ b/packages/x-components/src/x-modules/popular-searches/store/types.ts @@ -3,6 +3,7 @@ import { Dictionary } from '@empathyco/x-utils'; import { XActionContext, XStoreModule } from '../../../store'; import { StatusMutations, StatusState } from '../../../store/utils/status-store.utils'; import { PopularSearchesConfig } from '../config.types'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * Popular searches module state. @@ -38,7 +39,9 @@ export interface PopularSearchesGetters { * * @public */ -export interface PopularSearchesMutations extends StatusMutations { +export interface PopularSearchesMutations + extends StatusMutations, + ConfigMutations { /** * Sets the suggestions of the module. * diff --git a/packages/x-components/src/x-modules/queries-preview/store/module.ts b/packages/x-components/src/x-modules/queries-preview/store/module.ts index 04f6fb377c..17a42791a1 100644 --- a/packages/x-components/src/x-modules/queries-preview/store/module.ts +++ b/packages/x-components/src/x-modules/queries-preview/store/module.ts @@ -1,4 +1,5 @@ import Vue from 'vue'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; import { QueriesPreviewXStoreModule } from './types'; import { fetchQueryPreview } from './actions/fetch-query-preview.action'; import { fetchAndSaveQueryPreview } from './actions/fetch-and-save-query-preview.action'; @@ -38,7 +39,9 @@ export const queriesPreviewXStoreModule: QueriesPreviewXStoreModule = { }, setSelectedQueryPreview(state, selectedQueryPreview) { state.selectedQueryPreview = selectedQueryPreview; - } + }, + setConfig, + mergeConfig }, actions: { fetchQueryPreview, diff --git a/packages/x-components/src/x-modules/queries-preview/store/types.ts b/packages/x-components/src/x-modules/queries-preview/store/types.ts index 7e562242f8..0b78414632 100644 --- a/packages/x-components/src/x-modules/queries-preview/store/types.ts +++ b/packages/x-components/src/x-modules/queries-preview/store/types.ts @@ -4,6 +4,7 @@ import { XActionContext } from '../../../store/actions.types'; import { XStoreModule } from '../../../store/store.types'; import { RequestStatus, StatusState } from '../../../store/utils/status-store.utils'; import { QueriesPreviewConfig } from '../config.types'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * QueriesPreview store state. @@ -75,7 +76,7 @@ export interface QueriesPreviewGetters { * * @public */ -export interface QueriesPreviewMutations { +export interface QueriesPreviewMutations extends ConfigMutations { /** * Removes a query preview entry from the queries preview's dictionary. * diff --git a/packages/x-components/src/x-modules/query-suggestions/store/module.ts b/packages/x-components/src/x-modules/query-suggestions/store/module.ts index 39982eeecf..91bce9cfdc 100644 --- a/packages/x-components/src/x-modules/query-suggestions/store/module.ts +++ b/packages/x-components/src/x-modules/query-suggestions/store/module.ts @@ -1,5 +1,6 @@ import { setQuery } from '../../../store/utils/query.utils'; import { setStatus } from '../../../store/utils/status-store.utils'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; import { cancelFetchAndSaveSuggestions, fetchAndSaveSuggestions @@ -41,7 +42,9 @@ export const querySuggestionsXStoreModule: QuerySuggestionsXStoreModule = { setStatus, setParams(state, params) { state.params = params; - } + }, + setConfig, + mergeConfig }, actions: { cancelFetchAndSaveSuggestions, diff --git a/packages/x-components/src/x-modules/query-suggestions/store/types.ts b/packages/x-components/src/x-modules/query-suggestions/store/types.ts index 9f2cfbc802..c27e283719 100644 --- a/packages/x-components/src/x-modules/query-suggestions/store/types.ts +++ b/packages/x-components/src/x-modules/query-suggestions/store/types.ts @@ -5,6 +5,7 @@ import { QueryMutations, QueryState } from '../../../store/utils/query.utils'; import { StatusMutations, StatusState } from '../../../store/utils/status-store.utils'; import { UrlParams } from '../../../types/url-params'; import { QuerySuggestionsConfig } from '../config.types'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * QuerySuggestions store state. @@ -44,7 +45,10 @@ export interface QuerySuggestionsGetters { * * @public */ -export interface QuerySuggestionsMutations extends StatusMutations, QueryMutations { +export interface QuerySuggestionsMutations + extends StatusMutations, + QueryMutations, + ConfigMutations { /** * Sets the query of the query suggestions module. * diff --git a/packages/x-components/src/x-modules/recommendations/store/module.ts b/packages/x-components/src/x-modules/recommendations/store/module.ts index 9e32221408..b077a4b0d5 100644 --- a/packages/x-components/src/x-modules/recommendations/store/module.ts +++ b/packages/x-components/src/x-modules/recommendations/store/module.ts @@ -1,4 +1,5 @@ import { setStatus } from '../../../store/utils/status-store.utils'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; import { cancelFetchAndSaveRecommendations, fetchAndSaveRecommendations @@ -41,7 +42,9 @@ export const recommendationsXStoreModule: RecommendationsXStoreModule = { if (stateRecommendation) { Object.assign(stateRecommendation, recommendation); } - } + }, + setConfig, + mergeConfig }, actions: { cancelFetchAndSaveRecommendations, diff --git a/packages/x-components/src/x-modules/recommendations/store/types.ts b/packages/x-components/src/x-modules/recommendations/store/types.ts index bb65e7ffd3..8234b7e774 100644 --- a/packages/x-components/src/x-modules/recommendations/store/types.ts +++ b/packages/x-components/src/x-modules/recommendations/store/types.ts @@ -3,6 +3,7 @@ import { Dictionary } from '@empathyco/x-utils'; import { XActionContext, XStoreModule } from '../../../store'; import { StatusMutations, StatusState } from '../../../store/utils/status-store.utils'; import { RecommendationsConfig } from '../config.types'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * Recommendations store state. @@ -35,7 +36,9 @@ export interface RecommendationsGetters { * * @public */ -export interface RecommendationsMutations extends StatusMutations { +export interface RecommendationsMutations + extends StatusMutations, + ConfigMutations { /** * Sets the recommendations of the module. * diff --git a/packages/x-components/src/x-modules/related-tags/store/module.ts b/packages/x-components/src/x-modules/related-tags/store/module.ts index 1f6d793be5..7ad62ce2f4 100644 --- a/packages/x-components/src/x-modules/related-tags/store/module.ts +++ b/packages/x-components/src/x-modules/related-tags/store/module.ts @@ -1,5 +1,6 @@ import { setQuery } from '../../../store/utils/query.utils'; import { setStatus } from '../../../store/utils/status-store.utils'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; import { cancelFetchAndSaveRelatedTags, fetchAndSaveRelatedTags @@ -45,7 +46,9 @@ export const relatedTagsXStoreModule: RelatedTagsXStoreModule = { setStatus, setParams(state, params) { state.params = params; - } + }, + setConfig, + mergeConfig }, actions: { cancelFetchAndSaveRelatedTags, diff --git a/packages/x-components/src/x-modules/related-tags/store/types.ts b/packages/x-components/src/x-modules/related-tags/store/types.ts index dbc83a9d8e..99e157a386 100644 --- a/packages/x-components/src/x-modules/related-tags/store/types.ts +++ b/packages/x-components/src/x-modules/related-tags/store/types.ts @@ -5,6 +5,7 @@ import { QueryMutations, QueryState } from '../../../store/utils/query.utils'; import { StatusMutations, StatusState } from '../../../store/utils/status-store.utils'; import { UrlParams } from '../../../types/url-params'; import { RelatedTagsConfig } from '../config.types'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * RelatedTags store state. @@ -45,7 +46,10 @@ export interface RelatedTagsGetters { * * @public */ -export interface RelatedTagsMutations extends StatusMutations, QueryMutations { +export interface RelatedTagsMutations + extends StatusMutations, + QueryMutations, + ConfigMutations { /** * Sets the related tags of the module. * diff --git a/packages/x-components/src/x-modules/search/store/module.ts b/packages/x-components/src/x-modules/search/store/module.ts index 864ff08f98..506b194f46 100644 --- a/packages/x-components/src/x-modules/search/store/module.ts +++ b/packages/x-components/src/x-modules/search/store/module.ts @@ -2,6 +2,7 @@ import { isFacetFilter } from '@empathyco/x-types'; import { setQuery } from '../../../store/utils/query.utils'; import { setStatus } from '../../../store/utils/status-store.utils'; import { groupItemsBy } from '../../../utils/array'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; // eslint-disable-next-line max-len import { cancelFetchAndSaveSearchResponse, @@ -81,9 +82,8 @@ export const searchXStoreModule: SearchXStoreModule = { setPage(state, page) { state.page = page; }, - setPageSize(state, pageSize) { - state.config.pageSize = pageSize; - }, + setConfig, + mergeConfig, setIsAppendResults(state, isAppendResults) { state.isAppendResults = isAppendResults; }, diff --git a/packages/x-components/src/x-modules/search/store/types.ts b/packages/x-components/src/x-modules/search/store/types.ts index f651ce4820..db6d386e34 100644 --- a/packages/x-components/src/x-modules/search/store/types.ts +++ b/packages/x-components/src/x-modules/search/store/types.ts @@ -20,6 +20,7 @@ import { QueryOrigin, QueryOriginInit } from '../../../types/origin'; import { UrlParams } from '../../../types/url-params'; import { SearchConfig } from '../config.types'; import { InternalSearchRequest, WatchedInternalSearchRequest } from '../types'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * Search store state. @@ -92,7 +93,10 @@ export interface SearchGetters { * * @public */ -export interface SearchMutations extends StatusMutations, QueryMutations { +export interface SearchMutations + extends StatusMutations, + QueryMutations, + ConfigMutations { /** * Append the results to the results state. * @@ -146,12 +150,6 @@ export interface SearchMutations extends StatusMutations, QueryMutations { * @param page - The new page. */ setPage(page: number): void; - /** - * Sets the page size of the module. - * - * @param pageSize - The new page size. - */ - setPageSize(pageSize: number): void; /** * Sets the extra params of the module. * diff --git a/packages/x-components/src/x-modules/semantic-queries/store/module.ts b/packages/x-components/src/x-modules/semantic-queries/store/module.ts index 38e6108c4e..8c578b86f8 100644 --- a/packages/x-components/src/x-modules/semantic-queries/store/module.ts +++ b/packages/x-components/src/x-modules/semantic-queries/store/module.ts @@ -1,3 +1,4 @@ +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; import { SemanticQueriesXStoreModule } from './types'; import { fetchSemanticQuery } from './actions/fetch-semantic-query.action'; import { fetchAndSaveSemanticQuery } from './actions/fetch-and-save-semantic-query.action'; @@ -36,7 +37,9 @@ export const semanticQueriesXStoreModule: SemanticQueriesXStoreModule = { }, setTotalResults(state, totalResults) { state.totalResults = totalResults; - } + }, + setConfig, + mergeConfig }, actions: { fetchSemanticQuery, diff --git a/packages/x-components/src/x-modules/semantic-queries/store/types.ts b/packages/x-components/src/x-modules/semantic-queries/store/types.ts index f86196b085..9325950ded 100644 --- a/packages/x-components/src/x-modules/semantic-queries/store/types.ts +++ b/packages/x-components/src/x-modules/semantic-queries/store/types.ts @@ -3,6 +3,7 @@ import { Dictionary } from '@empathyco/x-utils'; import { XActionContext } from '../../../store/actions.types'; import { XStoreModule } from '../../../store/store.types'; import { SemanticQueriesConfig } from '../config.types'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * SemanticQueries store state. @@ -44,12 +45,11 @@ export interface SemanticQueriesGetters { * * @public */ -export interface SemanticQueriesMutations { +export interface SemanticQueriesMutations extends ConfigMutations { /** * Sets the {@link SemanticQueriesState.query} property. */ setQuery(query: string): void; - /** * Sets the {@link SemanticQueriesState.totalResults} property. */ @@ -60,7 +60,6 @@ export interface SemanticQueriesMutations { * @param params - The new extra params. */ setParams(params: Dictionary): void; - /** * Sets the {@link SemanticQueriesState.semanticQueries} property. */ diff --git a/packages/x-components/src/x-modules/tagging/service/__tests__/pdp-add-to-cart.service.spec.ts b/packages/x-components/src/x-modules/tagging/service/__tests__/pdp-add-to-cart.service.spec.ts index 4b0395d488..ebdc764851 100644 --- a/packages/x-components/src/x-modules/tagging/service/__tests__/pdp-add-to-cart.service.spec.ts +++ b/packages/x-components/src/x-modules/tagging/service/__tests__/pdp-add-to-cart.service.spec.ts @@ -37,7 +37,7 @@ function commitTaggingConfig( store: Store, taggingConfig: Partial ): void { - store.commit('x/tagging/setTaggingConfig', taggingConfig); + store.commit('x/tagging/mergeConfig', taggingConfig); } describe('testing pdp add to cart', () => { diff --git a/packages/x-components/src/x-modules/tagging/store/module.ts b/packages/x-components/src/x-modules/tagging/store/module.ts index cca5e6778e..9b199c9dfa 100644 --- a/packages/x-components/src/x-modules/tagging/store/module.ts +++ b/packages/x-components/src/x-modules/tagging/store/module.ts @@ -1,4 +1,5 @@ import { TaggingRequest } from '@empathyco/x-types'; +import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils'; import { track } from './actions/track.action'; import { TaggingXStoreModule } from './types'; @@ -26,9 +27,8 @@ export const taggingXStoreModule: TaggingXStoreModule = { setQueryTaggingInfo(state, queryTaggingInfo: TaggingRequest) { state.queryTaggingInfo = queryTaggingInfo; }, - setTaggingConfig(state, taggingConfig) { - Object.assign(state.config, taggingConfig); - } + setConfig, + mergeConfig }, actions: { track diff --git a/packages/x-components/src/x-modules/tagging/store/types.ts b/packages/x-components/src/x-modules/tagging/store/types.ts index 47e51530ae..909fe8d928 100644 --- a/packages/x-components/src/x-modules/tagging/store/types.ts +++ b/packages/x-components/src/x-modules/tagging/store/types.ts @@ -1,6 +1,7 @@ import { TaggingRequest } from '@empathyco/x-types'; import { XStoreModule } from '../../../store'; import { TaggingConfig } from '../config.types'; +import { ConfigMutations } from '../../../store/utils/config-store.utils'; /** * Tagging store state. * @@ -33,7 +34,7 @@ export interface TaggingGetters {} * * @public */ -export interface TaggingMutations { +export interface TaggingMutations extends ConfigMutations { /** * Sets the {@link TaggingState.consent } property. * @@ -46,13 +47,6 @@ export interface TaggingMutations { * @param queryTaggingInfo - The new {@link TaggingState.queryTaggingInfo}. */ setQueryTaggingInfo(queryTaggingInfo: TaggingRequest): void; - - /** - * Sets the {@link TaggingState.config} property. - * - * @param taggingConfig - The new {@link TaggingState.config}. - */ - setTaggingConfig(taggingConfig: TaggingConfig): void; } /** diff --git a/packages/x-components/src/x-modules/tagging/wiring.ts b/packages/x-components/src/x-modules/tagging/wiring.ts index 9012cdc670..fd5d9570ee 100644 --- a/packages/x-components/src/x-modules/tagging/wiring.ts +++ b/packages/x-components/src/x-modules/tagging/wiring.ts @@ -97,7 +97,7 @@ export const setConsent = wireCommit('setConsent'); * * @public */ -export const setTaggingConfig = wireCommit('setTaggingConfig'); +export const setTaggingConfig = wireCommit('mergeConfig'); /** * Tracks the tagging of the query.