2020-01-13 01:03:22 -06:00
|
|
|
import { ThunkResult } from 'app/types';
|
2019-06-03 10:55:59 -05:00
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
2020-01-13 01:03:22 -06:00
|
|
|
import { organizationLoaded } from './reducers';
|
2020-08-07 02:00:44 -05:00
|
|
|
import { updateConfigurationSubtitle } from 'app/core/actions';
|
2018-10-25 00:45:22 -05:00
|
|
|
|
2020-08-07 02:00:44 -05:00
|
|
|
type OrganizationDependencies = { getBackendSrv: typeof getBackendSrv };
|
|
|
|
|
|
|
|
export function loadOrganization(
|
|
|
|
dependencies: OrganizationDependencies = { getBackendSrv: getBackendSrv }
|
|
|
|
): ThunkResult<any> {
|
2021-01-20 00:59:48 -06:00
|
|
|
return async (dispatch) => {
|
2020-08-07 02:00:44 -05:00
|
|
|
const organizationResponse = await dependencies.getBackendSrv().get('/api/org');
|
2018-12-05 06:08:00 -06:00
|
|
|
dispatch(organizationLoaded(organizationResponse));
|
2018-10-25 09:56:49 -05:00
|
|
|
|
2018-12-05 06:08:00 -06:00
|
|
|
return organizationResponse;
|
2018-10-25 09:56:49 -05:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-08-07 02:00:44 -05:00
|
|
|
export function updateOrganization(
|
|
|
|
dependencies: OrganizationDependencies = { getBackendSrv: getBackendSrv }
|
|
|
|
): ThunkResult<any> {
|
2018-10-26 07:51:33 -05:00
|
|
|
return async (dispatch, getStore) => {
|
|
|
|
const organization = getStore().organization.organization;
|
|
|
|
|
2020-08-07 02:00:44 -05:00
|
|
|
await dependencies.getBackendSrv().put('/api/org', { name: organization.name });
|
2018-10-26 07:51:33 -05:00
|
|
|
|
2020-08-07 02:00:44 -05:00
|
|
|
dispatch(updateConfigurationSubtitle(organization.name));
|
|
|
|
dispatch(loadOrganization(dependencies));
|
2018-10-26 07:51:33 -05:00
|
|
|
};
|
2018-10-26 07:15:37 -05:00
|
|
|
}
|