2019-11-01 10:38:34 -05:00
|
|
|
import { createSelector } from 'reselect';
|
2019-02-12 05:36:46 -06:00
|
|
|
import { ExploreItemState } from 'app/types';
|
|
|
|
import { filterLogLevels, dedupLogRows } from 'app/core/logs_model';
|
|
|
|
|
2019-11-01 10:38:34 -05:00
|
|
|
const logsRowsSelector = (state: ExploreItemState) => state.logsResult && state.logsResult.rows;
|
2019-02-12 05:36:46 -06:00
|
|
|
const hiddenLogLevelsSelector = (state: ExploreItemState) => state.hiddenLogLevels;
|
|
|
|
const dedupStrategySelector = (state: ExploreItemState) => state.dedupStrategy;
|
2019-11-01 10:38:34 -05:00
|
|
|
export const deduplicatedRowsSelector = createSelector(
|
|
|
|
logsRowsSelector,
|
2019-02-12 05:36:46 -06:00
|
|
|
hiddenLogLevelsSelector,
|
|
|
|
dedupStrategySelector,
|
2019-11-01 10:38:34 -05:00
|
|
|
function dedupRows(rows, hiddenLogLevels, dedupStrategy) {
|
|
|
|
if (!(rows && rows.length)) {
|
|
|
|
return rows;
|
2019-02-12 05:36:46 -06:00
|
|
|
}
|
2019-11-01 10:38:34 -05:00
|
|
|
const filteredRows = filterLogLevels(rows, new Set(hiddenLogLevels));
|
|
|
|
return dedupLogRows(filteredRows, dedupStrategy);
|
2019-02-12 05:36:46 -06:00
|
|
|
}
|
|
|
|
);
|