mirror of
https://github.com/grafana/grafana.git
synced 2025-02-14 01:23:32 -06:00
35 lines
914 B
TypeScript
35 lines
914 B
TypeScript
import { Action, CoreActionTypes } from 'app/core/actions/location';
|
|
import { LocationState } from 'app/types';
|
|
import { renderUrl } from 'app/core/utils/url';
|
|
import _ from 'lodash';
|
|
|
|
export const initialState: LocationState = {
|
|
url: '',
|
|
path: '',
|
|
query: {},
|
|
routeParams: {},
|
|
};
|
|
|
|
export const locationReducer = (state = initialState, action: Action): LocationState => {
|
|
switch (action.type) {
|
|
case CoreActionTypes.UpdateLocation: {
|
|
const { path, routeParams } = action.payload;
|
|
let query = action.payload.query || state.query;
|
|
|
|
if (action.payload.partial) {
|
|
query = _.defaults(query, state.query);
|
|
query = _.omitBy(query, _.isNull);
|
|
}
|
|
|
|
return {
|
|
url: renderUrl(path || state.path, query),
|
|
path: path || state.path,
|
|
query: { ...query },
|
|
routeParams: routeParams || state.routeParams,
|
|
};
|
|
}
|
|
}
|
|
|
|
return state;
|
|
};
|