mirror of
https://github.com/grafana/grafana.git
synced 2025-02-20 11:48:34 -06:00
* Add auth labels and access control metadata to org users search results * Fix search result JSON model * Org users: Use API for pagination * Fix default page size * Refactor: UsersListPage to functional component * Refactor: update UsersTable component code style * Add pagination to the /orgs/{org_id}/users endpoint * Use pagination on the AdminEditOrgPage * Add /orgs/{org_id}/users/search endpoint to prevent breaking API * Use existing search store method * Remove unnecessary error * Remove unused * Add query param to search endpoint * Fix endpoint docs * Minor refactor * Fix number of pages calculation * Use SearchOrgUsers for all org users methods * Refactor: GetOrgUsers as a service method * Minor refactor: rename orgId => orgID * Fix integration tests * Fix tests
57 lines
1.6 KiB
TypeScript
57 lines
1.6 KiB
TypeScript
import { debounce } from 'lodash';
|
|
|
|
import { getBackendSrv } from '@grafana/runtime';
|
|
import { accessControlQueryParam } from 'app/core/utils/accessControl';
|
|
import { OrgUser } from 'app/types';
|
|
|
|
import { ThunkResult } from '../../../types';
|
|
|
|
import { usersLoaded, pageChanged, usersFetchBegin, usersFetchEnd, searchQueryChanged } from './reducers';
|
|
|
|
export function loadUsers(): ThunkResult<void> {
|
|
return async (dispatch, getState) => {
|
|
try {
|
|
const { perPage, page, searchQuery } = getState().users;
|
|
const users = await getBackendSrv().get(
|
|
`/api/org/users/search`,
|
|
accessControlQueryParam({ perpage: perPage, page, query: searchQuery })
|
|
);
|
|
dispatch(usersLoaded(users));
|
|
} catch (error) {
|
|
usersFetchEnd();
|
|
}
|
|
};
|
|
}
|
|
|
|
const fetchUsersWithDebounce = debounce((dispatch) => dispatch(loadUsers()), 300);
|
|
|
|
export function updateUser(user: OrgUser): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
await getBackendSrv().patch(`/api/org/users/${user.userId}`, { role: user.role });
|
|
dispatch(loadUsers());
|
|
};
|
|
}
|
|
|
|
export function removeUser(userId: number): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
await getBackendSrv().delete(`/api/org/users/${userId}`);
|
|
dispatch(loadUsers());
|
|
};
|
|
}
|
|
|
|
export function changePage(page: number): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
dispatch(usersFetchBegin());
|
|
dispatch(pageChanged(page));
|
|
dispatch(loadUsers());
|
|
};
|
|
}
|
|
|
|
export function changeSearchQuery(query: string): ThunkResult<void> {
|
|
return async (dispatch) => {
|
|
dispatch(usersFetchBegin());
|
|
dispatch(searchQueryChanged(query));
|
|
fetchUsersWithDebounce(dispatch);
|
|
};
|
|
}
|