-
-
Notifications
You must be signed in to change notification settings - Fork 4k
/
teamRoleSelect.tsx
92 lines (82 loc) · 2.68 KB
/
teamRoleSelect.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import styled from '@emotion/styled';
import {ControlProps} from 'sentry/components/forms/controls/selectControl';
import RoleSelectControl from 'sentry/components/roleSelectControl';
import {space} from 'sentry/styles/space';
import {Organization, Team, TeamMember, TeamRole} from 'sentry/types';
import {getEffectiveOrgRole} from 'sentry/utils/orgRole';
import {
hasOrgRoleOverwrite,
RoleOverwriteIcon,
} from 'sentry/views/settings/organizationTeams/roleOverwriteWarning';
interface Props {
member: TeamMember;
onChangeTeamRole: (newRole: TeamRole['id'] | string) => void;
organization: Organization;
team: Team;
disabled?: boolean;
size?: ControlProps['size'];
}
function TeamRoleSelect({
organization,
team,
member,
onChangeTeamRole,
disabled,
size,
}: Props) {
const {orgRoleList, teamRoleList, features} = organization;
const hasTeamRoles = features.includes('team-roles');
// Determine the org-role, including if the current team has an org role
// and adding the user to the current team changes their minimum team-role
const possibleOrgRoles = [member.orgRole];
if (member.groupOrgRoles && member.groupOrgRoles.length > 0) {
possibleOrgRoles.push(member.groupOrgRoles[0].role.id);
}
if (team.orgRole) {
possibleOrgRoles.push(team.orgRole);
}
const effectiveOrgRole = getEffectiveOrgRole(possibleOrgRoles, orgRoleList);
// If the member's org-role has elevated permission, their team-role will
// inherit scopes from it
if (hasOrgRoleOverwrite({orgRole: effectiveOrgRole?.id, orgRoleList, teamRoleList})) {
const effectiveTeamRole = teamRoleList.find(
r => r.id === effectiveOrgRole?.minimumTeamRole
);
return (
<RoleName>
{effectiveTeamRole?.name || effectiveOrgRole?.minimumTeamRole}
<IconWrapper>
<RoleOverwriteIcon
orgRole={effectiveOrgRole?.id}
orgRoleList={orgRoleList}
teamRoleList={teamRoleList}
/>
</IconWrapper>
</RoleName>
);
}
const teamRoleId =
member.teamRole || // From TeamMemberEndpoint
member.teamRoles?.find(tr => tr.teamSlug === team.slug)?.role || // From OrgMemberDetailEndpoint
null;
const teamRole = teamRoleList.find(r => r.id === teamRoleId) || teamRoleList[0];
return (
<RoleSelectControl
disabled={disabled || !hasTeamRoles}
disableUnallowed={false}
roles={teamRoleList}
value={teamRole.id}
onChange={option => onChangeTeamRole(option.value)}
size={size}
/>
);
}
export default TeamRoleSelect;
const RoleName = styled('div')`
display: flex;
align-items: center;
`;
const IconWrapper = styled('div')`
height: ${space(2)};
margin-left: ${space(1)};
`;