UNPKG

apisearch-events-ui

Version:

Javascript User Interface to visualize all events data.

64 lines (58 loc) 1.35 kB
import cloneDeep from 'clone-deep'; import ApisearchDispatcher from '../../dispatcher'; /** * Define items per page on result * * This action is triggered when mounting a component * receives two parameters: * @param queryOptions -> given new query options * @param appOptions -> current application options * * Finally dispatches an event with the modified query. * @returns {{ * type: string, * payload: { * updatedQuery * } * }} */ export function changeItemsPerResultPageSetup( { itemsPerPage, highlightsEnabled }, { currentQuery, client } ) { const clonedQuery = cloneDeep(currentQuery); /** * Set result size */ clonedQuery.setResultSize(itemsPerPage); /** * Set order */ clonedQuery.sortBy({ 'indexed_metadata.occurred_on': { 'order': 'desc' } }); /** * Enabling highlights on query result */ if (highlightsEnabled) { clonedQuery.enableHighlights(); } client.events(clonedQuery.toJSON(), (result, error) => { if (error) return; ApisearchDispatcher.dispatch({ type: 'RAW_EVENTS__RENDER_DATA', payload: { result, updatedQuery: clonedQuery } }) }); }