mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* Add and configure eslint-plugin-import * Fix the lint:ts npm command * Autofix + prettier all the files * Manually fix remaining files * Move jquery code in jest-setup to external file to safely reorder imports * Resolve issue caused by circular dependencies within Prometheus * Update .betterer.results * Fix missing // @ts-ignore * ignore iconBundle.ts * Fix missing // @ts-ignore
65 lines
2.1 KiB
TypeScript
65 lines
2.1 KiB
TypeScript
import { getBackendSrv } from '@grafana/runtime';
|
|
import { updateConfigurationSubtitle } from 'app/core/actions';
|
|
import { ThunkResult } from 'app/types';
|
|
|
|
import { organizationLoaded, userOrganizationsLoaded } from './reducers';
|
|
|
|
type OrganizationDependencies = { getBackendSrv: typeof getBackendSrv };
|
|
|
|
export function loadOrganization(
|
|
dependencies: OrganizationDependencies = { getBackendSrv: getBackendSrv }
|
|
): ThunkResult<any> {
|
|
return async (dispatch) => {
|
|
const organizationResponse = await dependencies.getBackendSrv().get('/api/org');
|
|
dispatch(organizationLoaded(organizationResponse));
|
|
|
|
return organizationResponse;
|
|
};
|
|
}
|
|
|
|
export function updateOrganization(
|
|
dependencies: OrganizationDependencies = { getBackendSrv: getBackendSrv }
|
|
): ThunkResult<any> {
|
|
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<any> {
|
|
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<any> {
|
|
return async (dispatch) => {
|
|
const result = await dependencies.getBackendSrv().post('/api/orgs/', newOrg);
|
|
|
|
dispatch(setUserOrganization(result.orgId));
|
|
};
|
|
}
|
|
|
|
export function getUserOrganizations(
|
|
dependencies: OrganizationDependencies = { getBackendSrv: getBackendSrv }
|
|
): ThunkResult<any> {
|
|
return async (dispatch) => {
|
|
const result = await dependencies.getBackendSrv().get('/api/user/orgs');
|
|
dispatch(userOrganizationsLoaded(result));
|
|
|
|
return result;
|
|
};
|
|
}
|