grafana/public/app/features/org/state/actions.ts
Jake Krammer bf3dcc809d
Admin: Fix updating organization name not updating configuration subtitle (#26315)
* 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
2020-08-07 09:00:44 +02:00

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));
};
}