All files / src/types systemField.ts

0% Statements 0/0
0% Branches 0/0
0% Functions 0/0
0% Lines 0/0

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62                                                                                                                           
/**
 * Field schema for the "system" admin lists (API Keys, Roles, Members).
 *
 * Mirrors the shape/spirit of `EntityField` (see stores/entities.ts) so these
 * objects stay describable the same way an entity's fields are, but stays a
 * separate, narrower type: EntityField's type union (and the components that
 * switch on it) is scoped to entity-item rendering (images, workflows,
 * entity refs, ...) and is not extended here.
 */
 
export type SystemBadgeColor = 'success' | 'warning' | 'danger' | 'secondary' | 'primary' | 'info'
 
export interface SystemBadgeOption {
  value: string // matched against String(item[fieldId])
  label: Record<string, string>
  color: SystemBadgeColor
}
 
export interface SystemChipValue {
  label: string
  color?: SystemBadgeColor
}
 
export type SystemFieldType = 'text' | 'date' | 'boolean' | 'badge' | 'chips' | 'amount'
 
export interface SystemField {
  fieldId: string
  name: Record<string, string>
  type: SystemFieldType
  mandatory?: boolean
  /** Relative column width (CSS grid `fr` unit) among the fields of the same schema. */
  width: number
 
  // type: 'badge' — item[fieldId] is matched against each option's `value`
  badgeOptions?: SystemBadgeOption[]
  /** Color used when no badgeOptions entry matches the value. */
  badgeDefaultColor?: SystemBadgeColor
  /** When true, render nothing instead of falling back to badgeDefaultColor on a non-match. */
  hideWhenNoMatch?: boolean
 
  // type: 'chips' — item[fieldId] is string[] | SystemChipValue[]
  /** When true, shows "<field name> (<total count>)" as a caption above the chip list. */
  chipsShowCount?: boolean
  chipsMaxVisible?: number
  /** Overflow label, `{n}` is replaced with the hidden count, e.g. '+{n}'. */
  chipsOverflowLabel?: Record<string, string>
  /** Color used for plain string chips (SystemChipValue entries carry their own color). */
  chipsDefaultColor?: SystemBadgeColor
 
  /** Field whose value is shown as a muted sub-line under the primary value (type: 'text'). */
  secondaryFieldId?: string
  /** Field whose value is a small round avatar shown before the primary value (type: 'text'). */
  avatarFieldId?: string
  /** Font Awesome icon (e.g. 'fa-solid fa-user') shown instead of the avatar when it has no value. */
  avatarFallbackIcon?: string
  /** Shown instead of '-' (type: 'date') or nothing (type: 'chips') when the value is empty. */
  emptyLabel?: Record<string, string>
 
  // type: 'amount' — item[fieldId] is a signed number, shown locale-formatted
  // with a leading '+' when positive, in green; negative values in red.
}