-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also, render permission details using epxandable summary rows
- Loading branch information
1 parent
cfedddf
commit f2d8c20
Showing
8 changed files
with
155 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,113 @@ | ||
import cn from 'classnames'; | ||
import { Adjust } from '@/components/icons/Adjust'; | ||
import BellIcon from '@/components/icons/BellIcon'; | ||
import { ChevronDown16Icon } from '@/components/icons/ChevronDown16Icon'; | ||
import GlobeIcon from '@/components/icons/GlobeIcon'; | ||
import KeyIcon from '@/components/icons/KeyIcon'; | ||
import SigIcon from '@/components/icons/SigIcon'; | ||
import ZapIcon from '@/components/icons/ZapIcon'; | ||
import { PermSummary } from '@/gear'; | ||
import React from 'react'; | ||
import { AppPerm, PassportPerm } from '@/gear'; | ||
import { capFirst } from '@/logic/utils'; | ||
import React, { useCallback, useMemo, useState } from 'react'; | ||
import exp from 'constants'; | ||
|
||
interface SummaryRowProps { | ||
/** | ||
* A permission summary. | ||
* A permission bucket. | ||
*/ | ||
summary: PermSummary; | ||
perm: PassportPerm | AppPerm; | ||
} | ||
|
||
// TODO: figured out mapping from permission to icon from Dan & Mark | ||
const iconFromPerm = (perm: PermSummary) => { | ||
if(perm.pers.some(p => p.vane && ['ames', 'eyre', 'gall'].includes(p.vane))) { | ||
return <GlobeIcon />; | ||
/** | ||
* A row summarizing a requested permission. | ||
* It has the description of the permission and an optional warning icon. | ||
*/ | ||
export default function SummaryRow({ perm }: SummaryRowProps) { | ||
const [expanded, setExpanded] = useState(false); | ||
|
||
// TODO: need icon identifier from perm; requested from tinnus | ||
// for now, return random icon placeholder | ||
const iconSeed = useMemo(() => Math.random(), []); | ||
const iconFromPerm = (perm: PassportPerm) => { | ||
|
||
if (iconSeed < 0.2) { | ||
return <GlobeIcon />; | ||
} else if (iconSeed < 0.4) { | ||
return <KeyIcon />; | ||
} else if (iconSeed < 0.6) { | ||
return <BellIcon />; | ||
} else if (iconSeed < 0.8) { | ||
return <SigIcon />; | ||
} else { | ||
return <Adjust />; | ||
} | ||
} | ||
|
||
// TODO: handle node perms | ||
if ('node' in perm) { | ||
return null; | ||
} | ||
|
||
if(perm.pers.some(p => p.vane && p.vane === 'jael')) { | ||
return <KeyIcon />; | ||
// TODO: handle app perms | ||
if ('app' in perm) { | ||
return null; | ||
} | ||
|
||
// TODO: | ||
// <BellIcon /> | ||
// <SigIcon /> | ||
const { nom, pes } = perm.kind; | ||
const hasWarning = pes.some(pe => pe.warn !== null); | ||
const expandable = pes.length > 0; | ||
|
||
return <Adjust />; | ||
} | ||
|
||
/** | ||
* A row summarizing a requested permission. | ||
* It has the description of the permission and an optional warning icon. | ||
*/ | ||
export default function SummaryRow({ summary }: SummaryRowProps) { | ||
const { desc, warn } = summary; | ||
const toggleExpanded = useCallback(() => { | ||
if (!expandable) return; | ||
setExpanded(!expanded); | ||
}, [expanded]); | ||
|
||
return ( | ||
<div className='w-full flex justify-between content-center p-2 space-x-4'> | ||
<div className='flex space-x-1'> | ||
<div className='h-8 w-8 bg-gray-50 p-1.5'> | ||
{iconFromPerm(summary)} | ||
<section> | ||
<div | ||
onClick={toggleExpanded} | ||
className={cn('w-full flex justify-between content-center p-2 space-x-4 rounded-t-lg', | ||
expandable && 'cursor-pointer', | ||
expanded && 'bg-gray-50', | ||
)}> | ||
<div className='flex space-x-1'> | ||
<div className='h-8 w-8 bg-gray-50 p-1.5 bg-blend-multiply'> | ||
{iconFromPerm(perm)} | ||
</div> | ||
<div className='flex flex-col justify-center text-sm font-medium text-gray-900'> | ||
{capFirst(nom)} | ||
</div> | ||
</div> | ||
<div className='flex flex-col justify-center text-sm font-medium text-gray-900'> | ||
{desc} | ||
<div className='flex flex-row space-x-3'> | ||
{hasWarning ? ( | ||
<div className='flex flex-col justify-center'> | ||
<ZapIcon color='#FF6240' /> | ||
</div> | ||
) : null} | ||
{ | ||
expandable ? ( | ||
<div className='flex flex-col justify-center'> | ||
<ChevronDown16Icon className={`transform ${expanded ? 'rotate-180' : ''}`} /> | ||
</div> | ||
) : null | ||
} | ||
</div> | ||
</div> | ||
{warn ? ( | ||
<div className='flex flex-col justify-center'> | ||
<ZapIcon color='#FF6240' /> | ||
</div> | ||
) : null} | ||
</div> | ||
{ | ||
expanded ? ( | ||
<div className='flex flex-col space-y-2 rounded-b-lg bg-gray-50 px-2 py-3'> | ||
{ | ||
pes.map(pe => ( | ||
<div className='flex flex-row'> | ||
<div className='text-sm font-semibold leading-4'> | ||
{capFirst(pe.desc)} | ||
</div> | ||
</div> | ||
)) | ||
} | ||
</div> | ||
) : null | ||
} | ||
</section> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters