@empathyco/x-components
Version:
Empathy X Components
177 lines (174 loc) • 5.34 kB
JavaScript
import { namespacedWireCommit, namespacedWireDispatch, namespacedWireDispatchWithoutPayload } from '../../wiring/namespaced-wires.factory.js';
import { namespacedDebounce } from '../../wiring/namespaced-wires.operators.js';
import { createWiring } from '../../wiring/wiring.utils.js';
/**
* `historyQueries` {@link XModuleName | XModule name}.
*
* @internal
*/
const moduleName = 'historyQueries';
/**
* WireCommit for {@link HistoryQueriesXModule}.
*
* @internal
*/
const wireCommit = namespacedWireCommit(moduleName);
/**
* WireDispatch for {@link HistoryQueriesXModule}.
*
* @internal
*/
const wireDispatch = namespacedWireDispatch(moduleName);
/**
* WireDispatchWithoutPayload for {@link HistoryQueriesXModule}.
*
* @internal
*/
const wireDispatchWithoutPayload = namespacedWireDispatchWithoutPayload(moduleName);
/**
* Saves a new query into the history queries.
*
* @public
*/
const addQueryToHistoryQueries = wireDispatch('addQueryToHistory');
/**
* Saves the selectedQueryPreview query into the history queries.
*
* @public
*/
const addQueryToHistoryQueriesFromPreview = wireDispatch('addQueryToHistory', ({ eventPayload: { query } }) => query);
/**
* Sets the query of the history queries module. Used for searching into the history queries.
*
* @public
*/
const setHistoryQueriesQuery = wireCommit('setQuery');
/**
* Sets the query of the history queries module from a selectedQueryPreview's query.
* Used for searching into the history queries.
*
* @public
*/
const setHistoryQueriesQueryFromPreview = wireCommit('setQuery', ({ eventPayload: { query } }) => query);
/**
* Sets the history queries state `query` from url.
*
* @public
*/
const setUrlParams = wireDispatch('setUrlParams');
/**
* Sets the query of the history queries module to an empty string.
*
* @public
*/
const clearHistoryQueriesQuery = wireCommit('setQuery', '');
/**
* Triggers a session refresh, extending its validity for the time configured in the
* {@link HistoryQueriesConfig.sessionTTLInMs}.
*
* @public
*/
const refreshHistoryQueriesSession = wireDispatchWithoutPayload('refreshSession');
/**
* Loads the history queries from the browser storage, saving them to the
* {@link HistoryQueriesState.historyQueries}.
*
* @public
*/
const loadHistoryQueriesFromBrowserStorageWire = wireDispatchWithoutPayload('loadHistoryQueriesFromBrowserStorage');
/**
* Clears the history queries.
*
* @public
*/
const clearHistoryQueries = wireDispatch('setHistoryQueries', []);
/**
* Removes a single history query from the history queries.
*
* @public
*/
const removeHistoryQuery = wireDispatch('removeFromHistory');
/**
* Enables history queries.
*
* @public
*/
const setHistoryQueriesEnabled = wireDispatch('toggleHistoryQueries', true);
/**
* Disables history queries.
*
* @public
*/
const setHistoryQueriesDisabled = wireDispatch('toggleHistoryQueries', false);
/**
* Updates the history queries with the relevant info included in a search response.
*
* @public
*/
const updateHistoryQueriesWithSearchResponse = wireDispatch('updateHistoryQueriesWithSearchResponse');
/**
* Sets the history queries state `filters` with a selectedHistoryQuery's filters.
*
* @public
*/
const setSearchSelectedFilters = wireCommit('setSearchSelectedFilters', ({ eventPayload: { filters } }) => filters);
/**
* Debounce function for the module.
*/
const moduleDebounce = namespacedDebounce(moduleName);
/**
* Default wiring for the {@link HistoryQueries} module.
*
* @internal
*/
const historyQueriesWiring = createWiring({
ParamsLoadedFromUrl: {
setUrlParams,
},
HistoryQueriesQueryChanged: {
refreshHistoryQueriesSession,
},
HistoryQueriesStorageKeyChanged: {
loadHistoryQueriesFromBrowserStorageWire,
},
UserClearedQuery: {
clearHistoryQueriesQuery,
},
UserAcceptedAQuery: {
setHistoryQueriesQuery,
addQueryToHistoryQueries,
},
UserSelectedAHistoryQuery: {
setSearchSelectedFilters,
},
UserIsTypingAQuery: {
setHistoryQueriesQueryDebounce: moduleDebounce(setHistoryQueriesQuery, ({ state }) => state.config.debounceInMs, { cancelOn: 'UserAcceptedAQuery' }),
},
UserPressedClearHistoryQueries: {
clearHistoryQueries,
},
UserPressedRemoveHistoryQuery: {
removeHistoryQuery,
},
UserClickedEnableHistoryQueries: {
setHistoryQueriesEnabled,
},
UserClickedConfirmDisableHistoryQueries: {
setHistoryQueriesDisabled,
},
UserClickedCloseX: {
clearHistoryQueriesQuery,
},
UserClickedOutOfMainModal: {
clearHistoryQueriesQuery,
},
SearchResponseChanged: {
updateHistoryQueriesWithSearchResponse,
},
UserAcceptedAQueryPreview: {
setHistoryQueriesQueryFromPreview,
addQueryToHistoryQueriesFromPreview,
},
});
export { addQueryToHistoryQueries, addQueryToHistoryQueriesFromPreview, clearHistoryQueries, clearHistoryQueriesQuery, historyQueriesWiring, loadHistoryQueriesFromBrowserStorageWire, refreshHistoryQueriesSession, removeHistoryQuery, setHistoryQueriesDisabled, setHistoryQueriesEnabled, setHistoryQueriesQuery, setHistoryQueriesQueryFromPreview, setSearchSelectedFilters, updateHistoryQueriesWithSearchResponse };
//# sourceMappingURL=wiring.js.map