mirror of
https://github.com/grafana/grafana.git
synced 2025-09-22 06:53:06 +08:00

* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
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;
|
|
};
|