Skip to content

Commit

Permalink
Revert "(feat) Implement config utils in the modules with config (#1321
Browse files Browse the repository at this point in the history
…)"

This reverts commit 393d758.
  • Loading branch information
CachedaCodes authored Oct 12, 2023
1 parent 393d758 commit e190478
Show file tree
Hide file tree
Showing 30 changed files with 68 additions and 107 deletions.
9 changes: 5 additions & 4 deletions packages/x-components/src/store/utils/config-store.utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Vue from 'vue';

/**
* Config mutations, containing a method to change the current config and other to merge
* a new one.
Expand Down Expand Up @@ -30,7 +28,7 @@ export interface ConfigMutations<T extends { config: T['config'] }> {
* @public
*/
export function setConfig<T extends { config: T['config'] }>(state: T, config: T['config']): void {
Vue.set(state, 'config', config);
state.config = config;
}

/**
Expand All @@ -45,5 +43,8 @@ export function mergeConfig<T extends { config: T['config'] }>(
state: T,
config: Partial<T['config']>
): void {
Object.assign(<object>state.config, config);
state.config = {
...state.config,
...config
};
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { setConfig, mergeConfig } from '../../../store/utils/config-store.utils';
import { EmpathizeXStoreModule } from './types';

/**
Expand All @@ -15,9 +14,7 @@ export const empathizeXStoreModule: EmpathizeXStoreModule = {
mutations: {
setIsOpen(state, isOpen) {
state.isOpen = isOpen;
},
setConfig,
mergeConfig
}
},
actions: {}
};
3 changes: 1 addition & 2 deletions packages/x-components/src/x-modules/empathize/store/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { XStoreModule } from '../../../store';
import { EmpathizeConfig } from '../config.types';
import { ConfigMutations } from '../../../store/utils/config-store.utils';

/**
* Empathize store state.
Expand Down Expand Up @@ -34,7 +33,7 @@ export interface EmpathizeGetters {}
*
* @public
*/
export interface EmpathizeMutations extends ConfigMutations<EmpathizeState> {
export interface EmpathizeMutations {
/**
* Sets the isOpen state of the module, which is used in the Alias API.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe('testing facets module getters', () => {
);

const store = createFacetsStore([parentFilter, childFilter, parentFilterWithoutChild], []);
store.commit('setConfig', {
store.commit('setFacetsConfig', {
filtersStrategyForRequest: 'leaves-only'
});

Expand Down
13 changes: 7 additions & 6 deletions packages/x-components/src/x-modules/facets/store/module.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
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, FacetsXStoreModule } from './types';
import { FacetGroupEntry, FacetsConfig, FacetsXStoreModule } from './types';
import { selectedFiltersForRequest } from './getters/selected-filters-for-request.getter';

/**
Expand Down Expand Up @@ -57,9 +55,12 @@ export const facetsXStoreModule: FacetsXStoreModule = {
setFacet(state, facet: Facet) {
Vue.set(state.facets, facet.id, facet);
},
setConfig,
mergeConfig,
setQuery,
setFacetsConfig(state, config: FacetsConfig) {
state.config = config;
},
setQuery(state, query) {
state.query = query;
},
setStickyFilter(state, filter) {
if (!state.stickyFilters[filter.id]) {
Vue.set(state.stickyFilters, filter.id, filter);
Expand Down
9 changes: 7 additions & 2 deletions packages/x-components/src/x-modules/facets/store/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Facet, Filter, RawFilter } from '@empathyco/x-types';
import { XActionContext, XStoreModule } from '../../../store';
import { ConfigMutations } from '../../../store/utils/config-store.utils';

/**
* Facets store state.
Expand Down Expand Up @@ -53,7 +52,7 @@ export interface FacetsGetters {
*
* @public
*/
export interface FacetsMutations extends ConfigMutations<FacetsState> {
export interface FacetsMutations {
/**
* Updates the state of a filter.
*
Expand Down Expand Up @@ -110,6 +109,12 @@ export interface FacetsMutations extends ConfigMutations<FacetsState> {
* @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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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';
Expand Down Expand Up @@ -52,8 +51,6 @@ export const historyQueriesXStoreModule: HistoryQueriesXStoreModule = {
state.sessionTimeStampInMs = sessionTimeStamp;
},
setQuery,
setConfig,
mergeConfig,
setIsEnabled(state, isEnabled) {
state.isEnabled = isEnabled;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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.
Expand Down Expand Up @@ -69,9 +68,7 @@ export interface HistoryQueriesGetters {
*
* @public
*/
export interface HistoryQueriesMutations
extends QueryMutations,
ConfigMutations<HistoryQueriesState> {
export interface HistoryQueriesMutations extends QueryMutations {
/**
* Sets the {@link HistoryQueriesState.historyQueries} property.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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
Expand Down Expand Up @@ -48,9 +47,7 @@ export const identifierResultsXStoreModule: IdentifierResultsXStoreModule = {
state.params = params;
},
setQuery,
setStatus,
setConfig,
mergeConfig
setStatus
},
actions: {
cancelFetchAndSaveIdentifierResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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.
Expand Down Expand Up @@ -50,10 +49,7 @@ export interface IdentifierResultsGetters {
*
* @public
*/
export interface IdentifierResultsMutations
extends StatusMutations,
QueryMutations,
ConfigMutations<IdentifierResultsState> {
export interface IdentifierResultsMutations extends StatusMutations, QueryMutations {
/**
* Sets the identifier results of the module.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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
Expand Down Expand Up @@ -55,9 +54,7 @@ export const nextQueriesXStoreModule: NextQueriesXStoreModule = {
},
resetResultsPreview(state) {
state.resultsPreview = {};
},
setConfig,
mergeConfig
}
},
actions: {
cancelFetchAndSaveNextQueries,
Expand Down
10 changes: 4 additions & 6 deletions packages/x-components/src/x-modules/next-queries/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ 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.
Expand Down Expand Up @@ -43,7 +42,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
* no valid data to conform a valid request.
* not valid data to conform a valid request.
*/
request: NextQueriesRequest | null;
/** List of next queries that have not been searched before. */
Expand All @@ -55,10 +54,7 @@ export interface NextQueriesGetters {
*
* @public
*/
export interface NextQueriesMutations
extends StatusMutations,
QueryMutations,
ConfigMutations<NextQueriesState> {
export interface NextQueriesMutations extends StatusMutations, QueryMutations {
/**
* Sets the query of the module, which is used to retrieve the next-queries.
*
Expand All @@ -83,13 +79,15 @@ export interface NextQueriesMutations
* @param params - The new extra params.
*/
setParams(params: Dictionary<unknown>): void;

/**
* Adds a new entry to the result's dictionary.
*
* @param resultsPreview - Object containing the next query,
* the totalResults and the results to add.
*/
setResultsPreview(resultsPreview: Dictionary<PreviewResults>): void;

/**
* Resets the result's dictionary.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { setStatus } from '../../../store/utils/status-store.utils';
import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils';
import {
cancelFetchAndSaveSuggestions,
fetchAndSaveSuggestions
Expand Down Expand Up @@ -36,12 +35,10 @@ export const popularSearchesXStoreModule: PopularSearchesXStoreModule = {
setSearchedQueries(state, searchedQueries) {
state.searchedQueries = searchedQueries;
},
setStatus,
setParams(state, params) {
state.params = params;
},
setStatus,
setConfig,
mergeConfig
}
},
actions: {
cancelFetchAndSaveSuggestions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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.
Expand Down Expand Up @@ -39,9 +38,7 @@ export interface PopularSearchesGetters {
*
* @public
*/
export interface PopularSearchesMutations
extends StatusMutations,
ConfigMutations<PopularSearchesState> {
export interface PopularSearchesMutations extends StatusMutations {
/**
* Sets the suggestions of the module.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
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';
Expand Down Expand Up @@ -39,9 +38,7 @@ export const queriesPreviewXStoreModule: QueriesPreviewXStoreModule = {
},
setSelectedQueryPreview(state, selectedQueryPreview) {
state.selectedQueryPreview = selectedQueryPreview;
},
setConfig,
mergeConfig
}
},
actions: {
fetchQueryPreview,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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.
Expand Down Expand Up @@ -76,7 +75,7 @@ export interface QueriesPreviewGetters {
*
* @public
*/
export interface QueriesPreviewMutations extends ConfigMutations<QueriesPreviewState> {
export interface QueriesPreviewMutations {
/**
* Removes a query preview entry from the queries preview's dictionary.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
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
Expand Down Expand Up @@ -42,9 +41,7 @@ export const querySuggestionsXStoreModule: QuerySuggestionsXStoreModule = {
setStatus,
setParams(state, params) {
state.params = params;
},
setConfig,
mergeConfig
}
},
actions: {
cancelFetchAndSaveSuggestions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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.
Expand Down Expand Up @@ -45,10 +44,7 @@ export interface QuerySuggestionsGetters {
*
* @public
*/
export interface QuerySuggestionsMutations
extends StatusMutations,
QueryMutations,
ConfigMutations<QuerySuggestionsState> {
export interface QuerySuggestionsMutations extends StatusMutations, QueryMutations {
/**
* Sets the query of the query suggestions module.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { setStatus } from '../../../store/utils/status-store.utils';
import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils';
import {
cancelFetchAndSaveRecommendations,
fetchAndSaveRecommendations
Expand Down Expand Up @@ -42,9 +41,7 @@ export const recommendationsXStoreModule: RecommendationsXStoreModule = {
if (stateRecommendation) {
Object.assign(stateRecommendation, recommendation);
}
},
setConfig,
mergeConfig
}
},
actions: {
cancelFetchAndSaveRecommendations,
Expand Down
Loading

0 comments on commit e190478

Please sign in to comment.