orgRole.tsx 444 B

12345678910111213141516
  1. import {OrgRole} from 'sentry/types';
  2. export function getEffectiveOrgRole(
  3. memberOrgRoles: string[],
  4. orgRoleList: OrgRole[]
  5. ): OrgRole {
  6. const orgRoleMap = orgRoleList.reduce((acc, role, index) => {
  7. acc[role.id] = {index, role};
  8. return acc;
  9. }, {});
  10. // sort by ascending index (high to low priority)
  11. memberOrgRoles.sort((a, b) => orgRoleMap[b].index - orgRoleMap[a].index);
  12. return orgRoleMap[memberOrgRoles[0]]?.role;
  13. }