Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 16 additions & 29 deletions frontend/web/components/PermissionsSummaryList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { FC, useMemo } from 'react'
import Tooltip from './Tooltip'
import { RolePermission } from 'common/types/responses'
import Format from 'common/utils/format'
import classNames from 'classnames'
import Chip, { chipClassName } from './base/Chip'
import { sortBy } from 'lodash'

type PermissionsSummaryListType = {
Expand Down Expand Up @@ -40,49 +40,36 @@ const PermissionsSummaryList: FC<PermissionsSummaryListType> = ({
const getPermissionString = (v: RolePermission['permissions'][number]) =>
`${Format.enumeration.get(v.permission_key)}${v.tags?.length ? `*` : ''}`

// Tag-scoped permissions grant limited access.
const getVariant = (v: RolePermission['permissions'][number]) =>
v.tags?.length ? 'warning' : 'success'

const truncatedHasLimitedAccess = truncatedItems?.find((v) => v.tags?.length)
return (
<div className='flex-row gap-1 align-items-center'>
{items.map((value, i) => (
<div
key={i}
className={classNames('chip chip--xs', {
'bg-white text-success border-success bg-opacity-10':
!value.tags?.length,
'bg-white text-warning border-warning bg-opacity-10':
value.tags?.length,
})}
>
<Chip key={i} size='xs' variant={getVariant(value)}>
{getPermissionString(value)}
</div>
</Chip>
))}
{!!truncatedItems.length && (
<Tooltip
title={
<span
className={classNames('chip chip--xs', {
'bg-white text-success border-success bg-opacity-10':
!truncatedHasLimitedAccess,
'bg-white text-warning border-warning bg-opacity-10':
truncatedHasLimitedAccess,
})}
<Chip
size='xs'
variant={truncatedHasLimitedAccess ? 'warning' : 'success'}
>
+{truncatedItems.length}
</span>
</Chip>
}
>
{`<div class='d-flex flex-wrap gap-1'>${truncatedItems
.map(
(v) => `<div
class='${classNames('chip chip--xs', {
'bg-success text-success border-success bg-opacity-10':
!v.tags?.length,
'bg-warning text-warning border-warning bg-opacity-10':
v.tags?.length,
})}'
>
${getPermissionString(v)}
</div>`,
(v) =>
`<span class='${chipClassName({
size: 'xs',
variant: getVariant(v),
})}'>${getPermissionString(v)}</span>`,
)
.join('')}</div>`}
</Tooltip>
Expand Down
25 changes: 18 additions & 7 deletions frontend/web/components/base/Chip/Chip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ const VARIANT_UTILITIES: Record<TokenVariant, string> = {
warning: 'bg-surface-warning text-warning',
}

// The classes for a token chip, for markup built as an HTML string (tooltips).
export const chipClassName = ({
size = 'default',
variant = 'neutral',
}: {
size?: ChipSize
variant?: ChipVariant
}) =>
classNames(
'ds-chip d-inline-flex align-items-center align-middle gap-1 rounded-sm',
variant !== 'tinted' && VARIANT_UTILITIES[variant],
{
[`ds-chip--${variant}`]: variant !== 'neutral',
[`ds-chip--${size}`]: size !== 'default',
},
)

// Token-based chip primitive. Uses `ds-chip` rather than the legacy `.chip`
// (old SCSS vars + a manual `.dark {}` block, ~35 usages) so the two coexist
// until those migrate under #6606. Clickable on its own (role=button), or a
Expand Down Expand Up @@ -80,16 +97,10 @@ const Chip = ({
// Data, not styling: Chip.scss derives the shades from these.
style={tintStyle}
className={classNames(
'ds-chip d-inline-flex align-items-center align-middle gap-1 rounded-sm',
!tint && VARIANT_UTILITIES[tokenVariant],
chipClassName({ size, variant: tint ? 'tinted' : tokenVariant }),
{
'ds-chip--accent': !tint && tokenVariant === 'accent',
'ds-chip--clickable': interactive,
'ds-chip--success': !tint && tokenVariant === 'success',
'ds-chip--tinted': !!tint,
'ds-chip--truncate': truncate,
[`ds-chip--${size}`]: size !== 'default',
'ds-chip--warning': !tint && tokenVariant === 'warning',
},
className,
)}
Expand Down
2 changes: 1 addition & 1 deletion frontend/web/components/base/Chip/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from './Chip'
export { default, chipClassName } from './Chip'
export type { ChipProps, ChipSize, ChipVariant, ChipVariantProps } from './Chip'
Loading