mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* creating types, actions, reducer * load teams and store in redux * delete team * set search query action and tests * Teampages page * team members, bug in fetching team * flattened team state, tests for TeamMembers * test for team member selector * team settings * actions for group sync * tests for team groups * removed comment * remove old stores * fix: formating of datasource.go * fix: minor changes to imports * adding debounce and fixing issue in teamlist * refactoring: moving types to their own files
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { Action, ActionTypes } from 'app/core/actions/navModel';
|
|
import { NavIndex, NavModelItem } from 'app/types';
|
|
import config from 'app/core/config';
|
|
|
|
export function buildInitialState(): NavIndex {
|
|
const navIndex: NavIndex = {};
|
|
const rootNodes = config.bootData.navTree as NavModelItem[];
|
|
buildNavIndex(navIndex, rootNodes);
|
|
return navIndex;
|
|
}
|
|
|
|
function buildNavIndex(navIndex: NavIndex, children: NavModelItem[], parentItem?: NavModelItem) {
|
|
for (const node of children) {
|
|
navIndex[node.id] = {
|
|
...node,
|
|
parentItem: parentItem,
|
|
};
|
|
|
|
if (node.children) {
|
|
buildNavIndex(navIndex, node.children, node);
|
|
}
|
|
}
|
|
}
|
|
|
|
export const initialState: NavIndex = buildInitialState();
|
|
|
|
export const navIndexReducer = (state = initialState, action: Action): NavIndex => {
|
|
switch (action.type) {
|
|
case ActionTypes.UpdateNavIndex:
|
|
const newPages = {};
|
|
const payload = action.payload;
|
|
|
|
for (const node of payload.children) {
|
|
newPages[node.id] = {
|
|
...node,
|
|
parentItem: payload,
|
|
};
|
|
}
|
|
|
|
return { ...state, ...newPages };
|
|
}
|
|
return state;
|
|
};
|