Skip to content

Commit

Permalink
feat: use config utils in modules with state.config to enable using t…
Browse files Browse the repository at this point in the history
…hese mutations outside the modules

EMP-2328
  • Loading branch information
annacv committed Oct 11, 2023
1 parent e223b2d commit 9a39dc5
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { setConfig } from '../../../store/utils/config-store.utils';
import { EmpathizeXStoreModule } from './types';

/**
Expand All @@ -14,7 +15,8 @@ export const empathizeXStoreModule: EmpathizeXStoreModule = {
mutations: {
setIsOpen(state, isOpen) {
state.isOpen = isOpen;
}
},
setConfig
},
actions: {}
};
6 changes: 6 additions & 0 deletions packages/x-components/src/x-modules/empathize/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ export interface EmpathizeMutations {
* @param isOpen - The new isOpen state to save.
*/
setIsOpen(isOpen: boolean): void;
/**
* Sets the {@link EmpathizeState.config } config.
*
* @param config - The new config.
*/
setConfig(config: EmpathizeConfig): void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setQuery } from '../../../store/utils/query.utils';
import { localStorageService } from '../../../utils/storage';
import { 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 @@ -51,6 +52,7 @@ export const historyQueriesXStoreModule: HistoryQueriesXStoreModule = {
state.sessionTimeStampInMs = sessionTimeStamp;
},
setQuery,
setConfig,
setIsEnabled(state, isEnabled) {
state.isEnabled = isEnabled;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ export interface HistoryQueriesMutations extends QueryMutations {
* @param query - The new {@link HistoryQueriesState.query }.
*/
setQuery(query: string): void;
/**
* Sets the {@link HistoryQueriesState.config } config.
*
* @param config - The new config.
*/
setConfig(config: HistoryQueriesConfig): void;
/**
* Sets the {@link HistoryQueriesState.isEnabled } property.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setQuery } from '../../../store/utils/query.utils';
import { setStatus } from '../../../store/utils/status-store.utils';
import { setConfig } from '../../../store/utils/config-store.utils';
import {
cancelFetchAndSaveIdentifierResults,
fetchAndSaveIdentifierResults
Expand Down Expand Up @@ -47,7 +48,8 @@ export const identifierResultsXStoreModule: IdentifierResultsXStoreModule = {
state.params = params;
},
setQuery,
setStatus
setStatus,
setConfig
},
actions: {
cancelFetchAndSaveIdentifierResults,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ export interface IdentifierResultsMutations extends StatusMutations, QueryMutati
* @param newQuery - The new query to save to the state.
*/
setQuery(newQuery: string): void;
/**
* Sets the {@link IdentifierResultsState.config } config.
*
* @param config - The new config.
*/
setConfig(config: IdentifierResultsConfig): void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setQuery } from '../../../store/utils/query.utils';
import { setStatus } from '../../../store/utils/status-store.utils';
import { setConfig } from '../../../store/utils/config-store.utils';
import {
cancelFetchAndSaveNextQueries,
fetchAndSaveNextQueries
Expand Down Expand Up @@ -54,7 +55,8 @@ export const nextQueriesXStoreModule: NextQueriesXStoreModule = {
},
resetResultsPreview(state) {
state.resultsPreview = {};
}
},
setConfig
},
actions: {
cancelFetchAndSaveNextQueries,
Expand Down
10 changes: 7 additions & 3 deletions packages/x-components/src/x-modules/next-queries/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,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
* 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. */
Expand Down Expand Up @@ -79,19 +79,23 @@ export interface NextQueriesMutations extends StatusMutations, QueryMutations {
* @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.
*/
resetResultsPreview(): void;
/**
* Sets the {@link NextQueriesState.config } config.
*
* @param config - The new config.
*/
setConfig(config: NextQueriesConfig): void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { setStatus } from '../../../store/utils/status-store.utils';
import { setConfig } from '../../../store/utils/config-store.utils';
import {
cancelFetchAndSaveSuggestions,
fetchAndSaveSuggestions
Expand Down Expand Up @@ -38,7 +39,8 @@ export const popularSearchesXStoreModule: PopularSearchesXStoreModule = {
setStatus,
setParams(state, params) {
state.params = params;
}
},
setConfig
},
actions: {
cancelFetchAndSaveSuggestions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export interface PopularSearchesMutations extends StatusMutations {
* @param params - The new extra params.
*/
setParams(params: Dictionary<unknown>): void;
/**
* Sets the {@link PopularSearchesState.config } config.
*
* @param config - The new config.
*/
setConfig(config: PopularSearchesConfig): void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Vue from 'vue';
import { 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 @@ -38,7 +39,8 @@ export const queriesPreviewXStoreModule: QueriesPreviewXStoreModule = {
},
setSelectedQueryPreview(state, selectedQueryPreview) {
state.selectedQueryPreview = selectedQueryPreview;
}
},
setConfig
},
actions: {
fetchQueryPreview,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ export interface QueriesPreviewMutations {
* @param selectedQueryPreview - The selected query preview to save to the state.
*/
setSelectedQueryPreview(selectedQueryPreview: QueryPreviewInfo | null): void;
/**
* Sets the {@link QueriesPreviewState.config } config.
*
* @param config - The new config.
*/
setConfig(config: QueriesPreviewConfig): void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setQuery } from '../../../store/utils/query.utils';
import { setStatus } from '../../../store/utils/status-store.utils';
import { setConfig } from '../../../store/utils/config-store.utils';
import {
cancelFetchAndSaveSuggestions,
fetchAndSaveSuggestions
Expand Down Expand Up @@ -41,7 +42,8 @@ export const querySuggestionsXStoreModule: QuerySuggestionsXStoreModule = {
setStatus,
setParams(state, params) {
state.params = params;
}
},
setConfig
},
actions: {
cancelFetchAndSaveSuggestions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ export interface QuerySuggestionsMutations extends StatusMutations, QueryMutatio
* @param params - The new extra params.
*/
setParams(params: Dictionary<unknown>): void;
/**
* Sets the {@link QuerySuggestionsState.config } config.
*
* @param config - The new config.
*/
setConfig(config: QuerySuggestionsConfig): void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { setStatus } from '../../../store/utils/status-store.utils';
import { setConfig } from '../../../store/utils/config-store.utils';
import {
cancelFetchAndSaveRecommendations,
fetchAndSaveRecommendations
Expand Down Expand Up @@ -41,7 +42,8 @@ export const recommendationsXStoreModule: RecommendationsXStoreModule = {
if (stateRecommendation) {
Object.assign(stateRecommendation, recommendation);
}
}
},
setConfig
},
actions: {
cancelFetchAndSaveRecommendations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export interface RecommendationsMutations extends StatusMutations {
* and the properties to modify.
*/
updateRecommendation(recommendation: Partial<Result> & Pick<Result, 'id'>): void;
/**
* Sets the {@link RecommendationsState.config } config.
*
* @param config - The new config.
*/
setConfig(config: RecommendationsConfig): void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { setQuery } from '../../../store/utils/query.utils';
import { setStatus } from '../../../store/utils/status-store.utils';
import { setConfig } from '../../../store/utils/config-store.utils';
import {
cancelFetchAndSaveRelatedTags,
fetchAndSaveRelatedTags
Expand Down Expand Up @@ -45,7 +46,8 @@ export const relatedTagsXStoreModule: RelatedTagsXStoreModule = {
setStatus,
setParams(state, params) {
state.params = params;
}
},
setConfig
},
actions: {
cancelFetchAndSaveRelatedTags,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ export interface RelatedTagsMutations extends StatusMutations, QueryMutations {
* @param params - The new extra params.
*/
setParams(params: Dictionary<unknown>): void;
/**
* Sets the {@link RelatedTagsState.config } config.
*
* @param config - The new config.
*/
setConfig(config: RelatedTagsConfig): void;
}
/**
* RelatedTags store actions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { 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';
Expand Down Expand Up @@ -36,7 +37,8 @@ export const semanticQueriesXStoreModule: SemanticQueriesXStoreModule = {
},
setTotalResults(state, totalResults) {
state.totalResults = totalResults;
}
},
setConfig
},
actions: {
fetchSemanticQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export interface SemanticQueriesMutations {
* Sets the {@link SemanticQueriesState.query} property.
*/
setQuery(query: string): void;

/**
* Sets the {@link SemanticQueriesState.totalResults} property.
*/
Expand All @@ -60,11 +59,16 @@ export interface SemanticQueriesMutations {
* @param params - The new extra params.
*/
setParams(params: Dictionary<unknown>): void;

/**
* Sets the {@link SemanticQueriesState.semanticQueries} property.
*/
setSemanticQueries(semanticQueries: SemanticQuery[]): void;
/**
* Sets the {@link SemanticQueriesState.config } config.
*
* @param config - The new config.
*/
setConfig(config: SemanticQueriesConfig): void;
}

/**
Expand Down

0 comments on commit 9a39dc5

Please sign in to comment.