From 9749462a08308a121cda61a74209789dabad7b46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alberto=20Monedero=20Mart=C3=ADn?= Date: Thu, 19 Oct 2023 14:16:42 +0200 Subject: [PATCH] refactor: use `setQuery` util in the x modules (#1322) --- .../src/plugins/__tests__/x-plugin-emitters.spec.ts | 5 ++--- .../src/plugins/__tests__/x-plugin.spec.ts | 5 ++--- .../src/x-modules/facets/store/types.ts | 9 ++------- .../src/x-modules/history-queries/store/types.ts | 13 ++----------- .../src/x-modules/identifier-results/store/types.ts | 8 -------- .../src/x-modules/identifier-results/wiring.ts | 2 +- .../src/x-modules/next-queries/store/types.ts | 8 -------- .../src/x-modules/query-suggestions/store/types.ts | 8 -------- .../src/x-modules/query-suggestions/wiring.ts | 2 +- .../src/x-modules/search-box/store/types.ts | 10 ---------- .../x-modules/search/store/getters/query.getter.ts | 2 +- .../src/x-modules/search/store/types.ts | 8 -------- .../src/x-modules/semantic-queries/store/module.ts | 5 ++--- .../src/x-modules/semantic-queries/store/types.ts | 13 +++++-------- .../x-components/src/x-modules/url/store/types.ts | 6 ------ 15 files changed, 18 insertions(+), 86 deletions(-) diff --git a/packages/x-components/src/plugins/__tests__/x-plugin-emitters.spec.ts b/packages/x-components/src/plugins/__tests__/x-plugin-emitters.spec.ts index 04812ce908..e03bd502d5 100644 --- a/packages/x-components/src/plugins/__tests__/x-plugin-emitters.spec.ts +++ b/packages/x-components/src/plugins/__tests__/x-plugin-emitters.spec.ts @@ -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'; @@ -35,9 +36,7 @@ const xModule = createXModule({ }, actions: {}, mutations: { - setQuery(state, query: string): void { - state.query = query; - } + setQuery } } }); diff --git a/packages/x-components/src/plugins/__tests__/x-plugin.spec.ts b/packages/x-components/src/plugins/__tests__/x-plugin.spec.ts index af8f6b2271..4378718051 100644 --- a/packages/x-components/src/plugins/__tests__/x-plugin.spec.ts +++ b/packages/x-components/src/plugins/__tests__/x-plugin.spec.ts @@ -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(); @@ -364,9 +365,7 @@ describe('testing X Plugin', () => { } }, mutations: { - setQuery(state, query) { - state.query = query; - } + setQuery }, state: () => ({ query: '' }) }; 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 231a1c428f..b6b5988434 100644 --- a/packages/x-components/src/x-modules/facets/store/types.ts +++ b/packages/x-components/src/x-modules/facets/store/types.ts @@ -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. @@ -53,7 +54,7 @@ export interface FacetsGetters { * * @public */ -export interface FacetsMutations extends ConfigMutations { +export interface FacetsMutations extends QueryMutations, ConfigMutations { /** * Updates the state of a filter. * @@ -92,12 +93,6 @@ export interface FacetsMutations extends ConfigMutations { * @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. * 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 e018d20875..7b1e52bf13 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 @@ -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. */ @@ -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[]; @@ -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. * 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 cd070f1cbe..c21f0cc773 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 @@ -21,8 +21,6 @@ export interface IdentifierResultsState extends StatusState, QueryState { origin: QueryOrigin | null; /** The extra params property of the state. */ params: Dictionary; - /** The internal query of the module. Used to request the identifier results. */ - query: string; } /** @@ -73,12 +71,6 @@ export interface IdentifierResultsMutations * @param params - The new extra params. */ setParams(params: Dictionary): 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; } /** diff --git a/packages/x-components/src/x-modules/identifier-results/wiring.ts b/packages/x-components/src/x-modules/identifier-results/wiring.ts index 6dc9c2eb37..e121fa663c 100644 --- a/packages/x-components/src/x-modules/identifier-results/wiring.ts +++ b/packages/x-components/src/x-modules/identifier-results/wiring.ts @@ -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 */ 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 c1973c47b8..f81bc2f1f9 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 @@ -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. */ @@ -59,12 +57,6 @@ export interface NextQueriesMutations extends StatusMutations, QueryMutations, ConfigMutations { - /** - * 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. * 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 c27e283719..3e5de1182e 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 @@ -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. */ @@ -49,12 +47,6 @@ export interface QuerySuggestionsMutations extends StatusMutations, QueryMutations, ConfigMutations { - /** - * Sets the query of the query suggestions module. - * - * @param newQuery - The new query. - */ - setQuery(newQuery: string): void; /** * Sets the suggestions of the module. * diff --git a/packages/x-components/src/x-modules/query-suggestions/wiring.ts b/packages/x-components/src/x-modules/query-suggestions/wiring.ts index cd399e100d..aad2e125ff 100644 --- a/packages/x-components/src/x-modules/query-suggestions/wiring.ts +++ b/packages/x-components/src/x-modules/query-suggestions/wiring.ts @@ -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 */ diff --git a/packages/x-components/src/x-modules/search-box/store/types.ts b/packages/x-components/src/x-modules/search-box/store/types.ts index 384e0a10d7..ec1e897b45 100644 --- a/packages/x-components/src/x-modules/search-box/store/types.ts +++ b/packages/x-components/src/x-modules/search-box/store/types.ts @@ -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. */ @@ -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. * diff --git a/packages/x-components/src/x-modules/search/store/getters/query.getter.ts b/packages/x-components/src/x-modules/search/store/getters/query.getter.ts index 33fc7a3240..e25bafbc0c 100644 --- a/packages/x-components/src/x-modules/search/store/getters/query.getter.ts +++ b/packages/x-components/src/x-modules/search/store/getters/query.getter.ts @@ -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. 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 db6d386e34..d8ad39084a 100644 --- a/packages/x-components/src/x-modules/search/store/types.ts +++ b/packages/x-components/src/x-modules/search/store/types.ts @@ -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`. */ @@ -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. * 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 8c578b86f8..d95a387877 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,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'; @@ -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; }, 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 9325950ded..90d4f72324 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 @@ -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. */ @@ -45,11 +44,9 @@ export interface SemanticQueriesGetters { * * @public */ -export interface SemanticQueriesMutations extends ConfigMutations { - /** - * Sets the {@link SemanticQueriesState.query} property. - */ - setQuery(query: string): void; +export interface SemanticQueriesMutations + extends QueryMutations, + ConfigMutations { /** * Sets the {@link SemanticQueriesState.totalResults} property. */ diff --git a/packages/x-components/src/x-modules/url/store/types.ts b/packages/x-components/src/x-modules/url/store/types.ts index 566256cf61..8417f48a81 100644 --- a/packages/x-components/src/x-modules/url/store/types.ts +++ b/packages/x-components/src/x-modules/url/store/types.ts @@ -49,12 +49,6 @@ export interface UrlMutations extends QueryMutations { * @param params - The new params of the Url. */ setParams(params: Partial): void; - /** - * Sets the new query. - * - * @param query - The new query of the Url. - */ - setQuery(query: string): void; /** * Sets the related tags. *