mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Refactor: Adds Redux Toolkit package * Refactor: Uses configureStore from Redux Toolkit * Refactor: Migrates applicationReducer * Refactor: Migrates appNotificationsReducer * Refactor: Migrates locationReducer * Refactor: Migrates navModelReducer * Refactor: Migrates teamsReducer and teamReducer * Refactor: Migrates cleanUpAction * Refactor: Migrates alertRulesReducer * Refactor: Cleans up recursiveCleanState * Refactor: Switched to Angular compatible reducers * Refactor: Migrates folderReducer * Refactor: Migrates dashboardReducer * Migrates panelEditorReducer * Refactor: Migrates dataSourcesReducer * Refactor: Migrates usersReducer * Refactor: Migrates organizationReducer * Refactor: Migrates pluginsReducer * Refactor: Migrates ldapReducer and ldapUserReducer * Refactor: Migrates apiKeysReducer * Refactor: Migrates exploreReducer and itemReducer * Refactor: Removes actionCreatorFactory and reducerFactory * Refactor: Moves mocks to test section * Docs: Removes sections about home grown framework * Update contribute/style-guides/redux.md Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com> * Refactor: Cleans up some code * Refactor: Adds state typings * Refactor: Cleans up typings * Refactor: Adds comment about ImmerJs autoFreeze Co-authored-by: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>
94 lines
3.0 KiB
TypeScript
94 lines
3.0 KiB
TypeScript
import { getBackendSrv } from '@grafana/runtime';
|
|
|
|
import { TeamMember, ThunkResult } from 'app/types';
|
|
import { updateNavIndex } from 'app/core/actions';
|
|
import { buildNavModel } from './navModel';
|
|
import { teamGroupsLoaded, teamLoaded, teamMembersLoaded, teamsLoaded } from './reducers';
|
|
|
|
export function loadTeams(): ThunkResult<void> {
|
|
return async dispatch => {
|
|
const response = await getBackendSrv().get('/api/teams/search', { perpage: 1000, page: 1 });
|
|
dispatch(teamsLoaded(response.teams));
|
|
};
|
|
}
|
|
|
|
export function loadTeam(id: number): ThunkResult<void> {
|
|
return async dispatch => {
|
|
const response = await getBackendSrv().get(`/api/teams/${id}`);
|
|
dispatch(teamLoaded(response));
|
|
dispatch(updateNavIndex(buildNavModel(response)));
|
|
};
|
|
}
|
|
|
|
export function loadTeamMembers(): ThunkResult<void> {
|
|
return async (dispatch, getStore) => {
|
|
const team = getStore().team.team;
|
|
const response = await getBackendSrv().get(`/api/teams/${team.id}/members`);
|
|
dispatch(teamMembersLoaded(response));
|
|
};
|
|
}
|
|
|
|
export function addTeamMember(id: number): ThunkResult<void> {
|
|
return async (dispatch, getStore) => {
|
|
const team = getStore().team.team;
|
|
await getBackendSrv().post(`/api/teams/${team.id}/members`, { userId: id });
|
|
dispatch(loadTeamMembers());
|
|
};
|
|
}
|
|
|
|
export function removeTeamMember(id: number): ThunkResult<void> {
|
|
return async (dispatch, getStore) => {
|
|
const team = getStore().team.team;
|
|
await getBackendSrv().delete(`/api/teams/${team.id}/members/${id}`);
|
|
dispatch(loadTeamMembers());
|
|
};
|
|
}
|
|
|
|
export function updateTeam(name: string, email: string): ThunkResult<void> {
|
|
return async (dispatch, getStore) => {
|
|
const team = getStore().team.team;
|
|
await getBackendSrv().put(`/api/teams/${team.id}`, { name, email });
|
|
dispatch(loadTeam(team.id));
|
|
};
|
|
}
|
|
|
|
export function loadTeamGroups(): ThunkResult<void> {
|
|
return async (dispatch, getStore) => {
|
|
const team = getStore().team.team;
|
|
const response = await getBackendSrv().get(`/api/teams/${team.id}/groups`);
|
|
dispatch(teamGroupsLoaded(response));
|
|
};
|
|
}
|
|
|
|
export function addTeamGroup(groupId: string): ThunkResult<void> {
|
|
return async (dispatch, getStore) => {
|
|
const team = getStore().team.team;
|
|
await getBackendSrv().post(`/api/teams/${team.id}/groups`, { groupId: groupId });
|
|
dispatch(loadTeamGroups());
|
|
};
|
|
}
|
|
|
|
export function removeTeamGroup(groupId: string): ThunkResult<void> {
|
|
return async (dispatch, getStore) => {
|
|
const team = getStore().team.team;
|
|
await getBackendSrv().delete(`/api/teams/${team.id}/groups/${encodeURIComponent(groupId)}`);
|
|
dispatch(loadTeamGroups());
|
|
};
|
|
}
|
|
|
|
export function deleteTeam(id: number): ThunkResult<void> {
|
|
return async dispatch => {
|
|
await getBackendSrv().delete(`/api/teams/${id}`);
|
|
dispatch(loadTeams());
|
|
};
|
|
}
|
|
|
|
export function updateTeamMember(member: TeamMember): ThunkResult<void> {
|
|
return async dispatch => {
|
|
await getBackendSrv().put(`/api/teams/${member.teamId}/members/${member.userId}`, {
|
|
permission: member.permission,
|
|
});
|
|
dispatch(loadTeamMembers());
|
|
};
|
|
}
|