The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/org/state/actions.ts

64 lines
2.1 KiB

import { getBackendSrv } from '@grafana/runtime';
import { updateConfigurationSubtitle } from 'app/core/actions';
import { ThunkResult, UserOrg } from 'app/types';
import { organizationLoaded, userOrganizationsLoaded } from './reducers';
type OrganizationDependencies = { getBackendSrv: typeof getBackendSrv };
export function loadOrganization(
dependencies: OrganizationDependencies = { getBackendSrv: getBackendSrv }
): ThunkResult<void> {
return async (dispatch) => {
const organizationResponse = await dependencies.getBackendSrv().get('/api/org');
dispatch(organizationLoaded(organizationResponse));
return organizationResponse;
};
}
export function updateOrganization(
dependencies: OrganizationDependencies = { getBackendSrv: getBackendSrv }
): ThunkResult<void> {
return async (dispatch, getStore) => {
const organization = getStore().organization.organization;
await dependencies.getBackendSrv().put('/api/org', { name: organization.name });
dispatch(updateConfigurationSubtitle(organization.name));
dispatch(loadOrganization(dependencies));
};
}
export function setUserOrganization(
orgId: number,
dependencies: OrganizationDependencies = { getBackendSrv: getBackendSrv }
): ThunkResult<void> {
return async (dispatch) => {
const organizationResponse = await dependencies.getBackendSrv().post('/api/user/using/' + orgId);
dispatch(updateConfigurationSubtitle(organizationResponse.name));
};
}
export function createOrganization(
newOrg: { name: string },
dependencies: OrganizationDependencies = { getBackendSrv: getBackendSrv }
): ThunkResult<void> {
return async (dispatch) => {
const result = await dependencies.getBackendSrv().post('/api/orgs/', newOrg);
dispatch(setUserOrganization(result.orgId));
};
}
export function getUserOrganizations(
dependencies: OrganizationDependencies = { getBackendSrv: getBackendSrv }
): ThunkResult<Promise<UserOrg[]>> {
return async (dispatch) => {
const result = await dependencies.getBackendSrv().get<UserOrg[]>('/api/user/orgs');
dispatch(userOrganizationsLoaded(result));
return result;
};
}