grafana/public/app/core/reducers/location.ts
David Kaltschmidt 200784ea4a Explore: Store UI state in URL
Storing queries, split state, and time range in URL.

- harmonize query serialization when generating Explore URLs in
  dashboards (use of `renderUrl`)
- move URL parse/serialization to Wrapper
- keep UI states under two keys, one for left and one for right Explore
- add option to angular router to not reload page on search change
- add lots of types
- fix time service function that gets triggered by URL change
2018-09-28 16:44:07 +02:00

27 lines
683 B
TypeScript

import { Action } from 'app/core/actions/location';
import { LocationState } from 'app/types';
import { renderUrl } from 'app/core/utils/url';
export const initialState: LocationState = {
url: '',
path: '',
query: {},
routeParams: {},
};
export const locationReducer = (state = initialState, action: Action): LocationState => {
switch (action.type) {
case 'UPDATE_LOCATION': {
const { path, query, routeParams } = action.payload;
return {
url: renderUrl(path || state.path, query),
path: path || state.path,
query: query || state.query,
routeParams: routeParams || state.routeParams,
};
}
}
return state;
};