/* Copyright (C) 2023-2026 QuantumNous This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . For commercial licensing, please contact support@quantumnous.com */ import type { Cell, Row } from '@tanstack/react-table' import { getCellLabel, renderCellContent } from './card-cell-utils' import { DataTableCardField, DataTableCardRow } from './card-field' type CardRole = 'title' | 'badge' | 'primary' | 'secondary' | 'hidden' function getCardRole(cell: Cell): CardRole { const meta = cell.column.columnDef.meta if (meta?.cardRole) return meta.cardRole return 'primary' } function orderCardCells( cells: Cell[] ): Cell[] { return [...cells].sort((a, b) => { const aOrder = a.column.columnDef.meta?.cardOrder const bOrder = b.column.columnDef.meta?.cardOrder if (aOrder == null && bOrder == null) return 0 if (aOrder == null) return 1 if (bOrder == null) return -1 return aOrder - bOrder }) } function isWideField(cell: Cell): boolean { const meta = cell.column.columnDef.meta return meta?.cardSpan === 2 || meta?.contentMode === 'summary' } /** * Shared row content for both the mobile list and optional desktop card grid. * All visible fields render immediately — no "More" click to reveal content. */ export function CardRowContent(props: { row: Row compact: boolean }) { const cells = props.row .getVisibleCells() .filter((cell) => cell.column.id !== 'select') const titleCell = cells.find((cell) => getCardRole(cell) === 'title') const badgeCell = cells.find((cell) => getCardRole(cell) === 'badge') const actionsCell = cells.find((cell) => cell.column.id === 'actions') const bodyCells = orderCardCells( cells.filter( (cell) => cell !== titleCell && cell !== badgeCell && cell !== actionsCell && getCardRole(cell) !== 'hidden' ) ) const rowCells = bodyCells.filter((cell) => !isWideField(cell)) const wideCells = bodyCells.filter((cell) => isWideField(cell)) return (
{props.compact && (titleCell || badgeCell) && (
{titleCell ? renderCellContent(titleCell) : null}
{badgeCell && (
{renderCellContent(badgeCell)}
)}
)} {!props.compact && (
{bodyCells.map((cell) => { const meta = cell.column.columnDef.meta return ( {renderCellContent(cell)} ) })}
)} {props.compact && rowCells.length > 0 && (
{rowCells.map((cell) => ( {renderCellContent(cell)} ))}
)} {props.compact && wideCells.length > 0 && (
{wideCells.map((cell) => ( {renderCellContent(cell)} ))}
)} {actionsCell && (
{renderCellContent(actionsCell)}
)}
) }