You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.1 KiB
36 lines
1.1 KiB
import { Action, createAction } from '@reduxjs/toolkit';
|
|
import { ElasticsearchQuery } from '../../types';
|
|
|
|
/**
|
|
* When the `initQuery` Action is dispatched, the query gets populated with default values where values are not present.
|
|
* This means it won't override any existing value in place, but just ensure the query is in a "runnable" state.
|
|
*/
|
|
export const initQuery = createAction('init');
|
|
|
|
export const changeQuery = createAction<ElasticsearchQuery['query']>('change_query');
|
|
|
|
export const changeAliasPattern = createAction<ElasticsearchQuery['alias']>('change_alias_pattern');
|
|
|
|
export const queryReducer = (prevQuery: ElasticsearchQuery['query'], action: Action) => {
|
|
if (changeQuery.match(action)) {
|
|
return action.payload;
|
|
}
|
|
|
|
if (initQuery.match(action)) {
|
|
return prevQuery || '';
|
|
}
|
|
|
|
return prevQuery;
|
|
};
|
|
|
|
export const aliasPatternReducer = (prevAliasPattern: ElasticsearchQuery['alias'], action: Action) => {
|
|
if (changeAliasPattern.match(action)) {
|
|
return action.payload;
|
|
}
|
|
|
|
if (initQuery.match(action)) {
|
|
return prevAliasPattern || '';
|
|
}
|
|
|
|
return prevAliasPattern;
|
|
};
|
|
|