import { MinusIcon, PlusIcon } from 'lucide-react' import { cn } from 'ui' import { formatPermissionName, getDiffBetweenScopes, ScopeGroupLevel, } from './OAuthAppsAuthorizeScreen.utils' import { ScopePermissionLabel } from './ScopeGroupCardItem' export interface ScopeGroupCardProps { scopes: string[] previousScopes: string[] } const scopeLabels: Record = { 'read-write': 'Read and write', write: 'Write', read: 'Read only', } const scopeLevels = ['read-write', 'write', 'read'] as const export const ScopeGroupCardWithDiff = (props: ScopeGroupCardProps) => { const diff = getDiffBetweenScopes(props) const removedPermissions = [ ...diff.changed.removed, ...scopeLevels.flatMap((level) => diff.changed[level].filter(({ previousLevel }) => previousLevel) ), ] return (
{scopeLevels.map((level) => { const rows = [ ...diff.changed[level].map(({ permission }) => ({ permission, status: 'Added' })), ...removedPermissions .filter(({ previousLevel }) => previousLevel === level) .map(({ permission }) => ({ permission, status: 'Removed' })), ...diff.unchanged[level].map((permission) => ({ permission, status: 'Unchanged' })), ] if (rows.length === 0) return null return (

{scopeLabels[level]}

    {rows.map(({ permission, status }) => (
  • {status === 'Added' && } {status === 'Removed' && ( )} {status === 'Unchanged' && } {status === 'Removed' ? ( formatPermissionName(permission) ) : ( )} {status}
  • ))}
) })}
) }