grafana/public/app/core/components/RolePicker/TeamRolePicker.tsx
Josh Hunt 3c6e0e8ef8
Chore: ESlint import order (#44959)
* 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
2022-04-22 14:33:13 +01:00

48 lines
1.2 KiB
TypeScript

import React, { FC, useEffect } from 'react';
import { useAsyncFn } from 'react-use';
import { Role } from 'app/types';
import { RolePicker } from './RolePicker';
import { fetchTeamRoles, updateTeamRoles } from './api';
export interface Props {
teamId: number;
orgId?: number;
roleOptions: Role[];
disabled?: boolean;
builtinRolesDisabled?: boolean;
}
export const TeamRolePicker: FC<Props> = ({ teamId, orgId, roleOptions, disabled, builtinRolesDisabled }) => {
const [{ loading, value: appliedRoles = [] }, getTeamRoles] = useAsyncFn(async () => {
try {
return await fetchTeamRoles(teamId, orgId);
} catch (e) {
// TODO handle error
console.error('Error loading options');
}
return [];
}, [orgId, teamId]);
useEffect(() => {
getTeamRoles();
}, [orgId, teamId, getTeamRoles]);
const onRolesChange = async (roles: string[]) => {
await updateTeamRoles(roles, teamId, orgId);
await getTeamRoles();
};
return (
<RolePicker
onRolesChange={onRolesChange}
roleOptions={roleOptions}
appliedRoles={appliedRoles}
isLoading={loading}
disabled={disabled}
builtinRolesDisabled={builtinRolesDisabled}
/>
);
};