mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 10:03:33 -06:00
* 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
48 lines
1.2 KiB
TypeScript
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}
|
|
/>
|
|
);
|
|
};
|