import { UserRoleData } from '@/modules/shared/domain/rolesAndScopes/types' import { AvailableRoles } from '@speckle/shared' import { isUndefined } from 'lodash-es' /** * Order roles by weight in descending order (meaning - highest permission roles come first) */ export const orderByWeight = ( roles: T[], definitions: UserRoleData[] ): UserRoleData[] => { const roleDefinitions = roles .map((role) => definitions.find((definition) => definition.name === role)) .filter((definition): definition is UserRoleData => !isUndefined(definition)) return roleDefinitions.sort((a, b) => b.weight - a.weight) }