Skip to content

Commit

Permalink
refactor: use setQuery util in the x modules (#1322)
Browse files Browse the repository at this point in the history
  • Loading branch information
albertjcuac authored Oct 19, 2023
1 parent e4f28a7 commit 9749462
Show file tree
Hide file tree
Showing 15 changed files with 18 additions and 86 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createLocalVue } from '@vue/test-utils';
import { default as Vue, VueConstructor } from 'vue';
import Vuex, { Store } from 'vuex';
import { setQuery } from '../../store/utils/query.utils';
import { createWireFromFunction } from '../../wiring/wires.factory';
import { XComponentsAdapterDummy } from '../../__tests__/adapter.dummy';
import { createXModule } from '../../__tests__/utils';
Expand Down Expand Up @@ -35,9 +36,7 @@ const xModule = createXModule({
},
actions: {},
mutations: {
setQuery(state, query: string): void {
state.query = query;
}
setQuery
}
}
});
Expand Down
5 changes: 2 additions & 3 deletions packages/x-components/src/plugins/__tests__/x-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { installNewXPlugin } from '../../__tests__/utils';
import { XPlugin } from '../x-plugin';
import { PrivateXModulesOptions, XModulesOptions, XPluginOptions } from '../x-plugin.types';
import { XDummyBus } from '../../__tests__/bus.dummy';
import { setQuery } from '../../store/utils/query.utils';

const wireToReplace: AnyWire = jest.fn();
const wireToRemove: AnyWire = jest.fn();
Expand Down Expand Up @@ -364,9 +365,7 @@ describe('testing X Plugin', () => {
}
},
mutations: {
setQuery(state, query) {
state.query = query;
}
setQuery
},
state: () => ({ query: '' })
};
Expand Down
9 changes: 2 additions & 7 deletions packages/x-components/src/x-modules/facets/store/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Facet, Filter, RawFilter } from '@empathyco/x-types';
import { XActionContext, XStoreModule } from '../../../store';
import { ConfigMutations } from '../../../store/utils/config-store.utils';
import { QueryMutations } from '../../../store/utils/query.utils';

/**
* Facets store state.
Expand Down Expand Up @@ -53,7 +54,7 @@ export interface FacetsGetters {
*
* @public
*/
export interface FacetsMutations extends ConfigMutations<FacetsState> {
export interface FacetsMutations extends QueryMutations, ConfigMutations<FacetsState> {
/**
* Updates the state of a filter.
*
Expand Down Expand Up @@ -92,12 +93,6 @@ export interface FacetsMutations extends ConfigMutations<FacetsState> {
* @param filters - The filters to add.
*/
setPreselectedFilters(filters: RawFilter[]): void;
/**
* Sets the {@link FacetsState.query} property.
*
* @param query - The new {@link FacetsState.query}.
*/
setQuery(query: string): void;
/**
* Removes the facet from the {@link FacetsState.facets | facets} record.
*
Expand Down
13 changes: 2 additions & 11 deletions packages/x-components/src/x-modules/history-queries/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ export interface HistoryQueriesState extends QueryState {
* search sessions.
*/
historyQueries: HistoryQuery[];
/**
* The current query for searching into the {@link HistoryQueriesState.historyQueries}.
*/
query: string;

/**
* Whether the history queries are enabled or disabled.
*/
Expand All @@ -43,7 +40,7 @@ export interface HistoryQueriesState extends QueryState {
export interface HistoryQueriesGetters {
/**
* A sub-set of the {@link HistoryQueriesState.historyQueries}. If the
* {@link HistoryQueriesState.query} property is not empty, this list will only contain
* query property is not empty, this list will only contain
* suggestions whose query matches with it.
*/
historyQueries: HistoryQuery[];
Expand Down Expand Up @@ -84,12 +81,6 @@ export interface HistoryQueriesMutations
* @param timeStamp - The new {@link HistoryQueriesState.sessionTimeStampInMs }.
*/
setSessionTimeStamp(timeStamp: number): void;
/**
* Sets the {@link HistoryQueriesState.query } property.
*
* @param query - The new {@link HistoryQueriesState.query }.
*/
setQuery(query: string): void;
/**
* Sets the {@link HistoryQueriesState.isEnabled } property.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ export interface IdentifierResultsState extends StatusState, QueryState {
origin: QueryOrigin | null;
/** The extra params property of the state. */
params: Dictionary<unknown>;
/** The internal query of the module. Used to request the identifier results. */
query: string;
}

/**
Expand Down Expand Up @@ -73,12 +71,6 @@ export interface IdentifierResultsMutations
* @param params - The new extra params.
*/
setParams(params: Dictionary<unknown>): void;
/**
* Sets the query of the module, which is used to retrieve the identifier-results.
*
* @param newQuery - The new query to save to the state.
*/
setQuery(newQuery: string): void;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const clearIdentifierResultsQuery = wireCommit('setQuery', '');
const setUrlParams = wireDispatch('saveQuery', ({ eventPayload: { query } }) => query);

/**
* Requests and stores a new set of identifier results for the {@link IdentifierResultsState.query}.
* Requests and stores a new set of identifier results for the query.
*
* @public
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import { ConfigMutations } from '../../../store/utils/config-store.utils';
* @public
*/
export interface NextQueriesState extends StatusState, QueryState {
/** The internal query of the module. Used to request the next queries. */
query: string;
/** The list of the next queries, related to the `query` property of the state. */
nextQueries: NextQuery[];
/** The list of the searched queries, related to the `query` property of the state. */
Expand Down Expand Up @@ -59,12 +57,6 @@ export interface NextQueriesMutations
extends StatusMutations,
QueryMutations,
ConfigMutations<NextQueriesState> {
/**
* Sets the query of the module, which is used to retrieve the next-queries.
*
* @param newQuery - The new query to save to the state.
*/
setQuery(newQuery: string): void;
/**
* Sets the next queries of the module.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import { ConfigMutations } from '../../../store/utils/config-store.utils';
* @public
*/
export interface QuerySuggestionsState extends StatusState, QueryState {
/** The query of the query suggestions module. Used to request the suggestions. */
query: string;
/** The suggestions for the query of the state. */
suggestions: Suggestion[];
/** The configuration of the query suggestions module. */
Expand Down Expand Up @@ -49,12 +47,6 @@ export interface QuerySuggestionsMutations
extends StatusMutations,
QueryMutations,
ConfigMutations<QuerySuggestionsState> {
/**
* Sets the query of the query suggestions module.
*
* @param newQuery - The new query.
*/
setQuery(newQuery: string): void;
/**
* Sets the suggestions of the module.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const clearQuerySuggestionsQuery = wireCommit('setQuery', '');
const setUrlParams = wireDispatch('setUrlParams');

/**
* Requests and stores a new set of query suggestions for the {@link QuerySuggestionsState.query}.
* Requests and stores a new set of query suggestions for the query.
*
* @public
*/
Expand Down
10 changes: 0 additions & 10 deletions packages/x-components/src/x-modules/search-box/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import { XEvent } from '../../../wiring/events.types';
* @public
*/
export interface SearchBoxState extends QueryState {
/**
* The query of the search box input.
*/
query: string;
/**
* The status of the search box input based on a state machine.
*/
Expand All @@ -35,12 +31,6 @@ export interface SearchBoxGetters {
* @public
*/
export interface SearchBoxMutations extends QueryMutations {
/**
* Sets the new query of the search-box.
*
* @param newQuery - The new query of the search-box.
*/
setQuery(newQuery: string): void;
/**
* Sets the new input status of the search-box.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createRelatedTagsQueryGetter } from '../../../../store/utils/query.util
import { SearchXStoreModule } from '../types';

/**
* Default implementation for the {@link SearchState.query} getter.
* Default implementation for the search query getter.
*
* @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the related
* tags' module.
Expand Down
8 changes: 0 additions & 8 deletions packages/x-components/src/x-modules/search/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ export interface SearchState extends StatusState, QueryState {
partialResults: PartialResult[];
/** The list of the promoted, related to the `query` property of the state. */
promoteds: Promoted[];
/** The internal query of the module. Used to request the search results. */
query: string;
/** The query tagging used to track the search events. */
queryTagging: TaggingRequest;
/** The redirections associated to the `query`. */
Expand Down Expand Up @@ -168,12 +166,6 @@ export interface SearchMutations
* @param promoteds - The new promoted to save to the state.
*/
setPromoteds(promoteds: Promoted[]): void;
/**
* Sets the query of the module, which is used to retrieve the results.
*
* @param newQuery - The new query to save to the state.
*/
setQuery(newQuery: string): void;
/**
* Sets the query tagging of the module, which is used to track the query.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { mergeConfig, setConfig } from '../../../store/utils/config-store.utils';
import { setQuery } from '../../../store/utils/query.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 @@ -32,9 +33,7 @@ export const semanticQueriesXStoreModule: SemanticQueriesXStoreModule = {
setSemanticQueries(state, queries) {
state.semanticQueries = queries;
},
setQuery(state, query) {
state.query = query;
},
setQuery,
setTotalResults(state, totalResults) {
state.totalResults = totalResults;
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ 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';
import { QueryMutations, QueryState } from '../../../store/utils/query.utils';

/**
* SemanticQueries store state.
*
* @public
*/
export interface SemanticQueriesState {
/** The query sending on the request. */
query: string;
export interface SemanticQueriesState extends QueryState {
/** The number of the total results of the query. */
totalResults: number;
/** The request and results. */
Expand Down Expand Up @@ -45,11 +44,9 @@ export interface SemanticQueriesGetters {
*
* @public
*/
export interface SemanticQueriesMutations extends ConfigMutations<SemanticQueriesState> {
/**
* Sets the {@link SemanticQueriesState.query} property.
*/
setQuery(query: string): void;
export interface SemanticQueriesMutations
extends QueryMutations,
ConfigMutations<SemanticQueriesState> {
/**
* Sets the {@link SemanticQueriesState.totalResults} property.
*/
Expand Down
6 changes: 0 additions & 6 deletions packages/x-components/src/x-modules/url/store/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,6 @@ export interface UrlMutations extends QueryMutations {
* @param params - The new params of the Url.
*/
setParams(params: Partial<UrlParams>): void;
/**
* Sets the new query.
*
* @param query - The new query of the Url.
*/
setQuery(query: string): void;
/**
* Sets the related tags.
*
Expand Down

0 comments on commit 9749462

Please sign in to comment.