mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
* Fix updating organization name not updating configuration subtitle * PR feedback: Remove unnecessary square brackets * Refactor code to update redux state in a safer way, add org action test * Refactor updateConfigurationSubtitle test, remove jest.mock usage * Consolidate dependency type
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import { ThunkResult } from 'app/types';
|
|
import { getBackendSrv } from '@grafana/runtime';
|
|
import { organizationLoaded } from './reducers';
|
|
import { updateConfigurationSubtitle } from 'app/core/actions';
|
|
|
|
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));
|
|
};
|
|
}
|