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
53 changes: 36 additions & 17 deletions frontend-v2/src/app/(authed)/activists/activists-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import {
TableHeader,
TableRow,
} from '@/components/ui/table'
import { ArrowDown, ArrowUp } from 'lucide-react'
import { ArrowDown, ArrowUp, Check, Minus } from 'lucide-react'
import { ActivistJSON, ActivistColumnName } from '@/lib/api'
import { IntentPrefetchLink } from '@/components/intent-prefetch-link'
import { COLUMN_DEFINITION_BY_NAME } from './column-definitions'
import { getActivistDisplayName } from './display-name'
import { formatValue } from './format-value'
import { formatValue, COLUMN_TYPE_BY_NAME } from './format-value'
import type { SortColumn } from './query-state'

interface ActivistTableProps {
Expand Down Expand Up @@ -101,6 +101,17 @@ export function ActivistTable({
}

const value = row.original[colName as keyof ActivistJSON]
if (COLUMN_TYPE_BY_NAME[colName] === 'boolean') {
return (
<div className="flex items-center text-sm">
{value ? (
<Check className="h-4 w-4 text-foreground" />
) : (
<Minus className="h-4 w-4 text-muted-foreground" />
)}
</div>
)
}
const formatted = formatValue(value, colName)
return <div className="truncate text-sm">{formatted}</div>
},
Expand Down Expand Up @@ -199,28 +210,36 @@ export function ActivistTable({
{visibleColumns.map((colName) => {
const definition = COLUMN_DEFINITION_BY_NAME[colName]
const label = definition?.label || colName
const formattedValue =
colName === 'name'
const isBool = COLUMN_TYPE_BY_NAME[colName] === 'boolean'
const rawValue = activist[colName as keyof ActivistJSON]
const formattedValue = isBool
? null
: colName === 'name'
? displayName.text
: formatValue(
activist[colName as keyof ActivistJSON],
colName,
)
: formatValue(rawValue, colName)

return (
<div key={colName} className="flex justify-between gap-2">
<span className="text-sm font-medium text-muted-foreground">
{label}:
</span>
<span
className={`text-sm ${
colName === 'name' && displayName.isPlaceholder
? 'italic text-muted-foreground'
: ''
}`}
>
{formattedValue}
</span>
{isBool ? (
rawValue ? (
<Check className="h-4 w-4 text-foreground" />
) : (
<Minus className="h-4 w-4 text-muted-foreground" />
)
) : (
<span
className={`text-sm ${
colName === 'name' && displayName.isPlaceholder
? 'italic text-muted-foreground'
: ''
}`}
>
{formattedValue}
</span>
)}
</div>
)
})}
Expand Down
2 changes: 1 addition & 1 deletion frontend-v2/src/app/(authed)/activists/format-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { formatDateValueForActivists } from './date-time'

type ColumnType = 'string' | 'number' | 'boolean'

const COLUMN_TYPE_BY_NAME = Object.fromEntries(
export const COLUMN_TYPE_BY_NAME = Object.fromEntries(
Object.entries(ActivistJSON.shape).map(([columnName, schema]) => {
const unwrapped =
schema instanceof z.ZodOptional || schema instanceof z.ZodNullable
Expand Down
Loading