open-swe/ui/src/components/agents/ported/MarkdownTable.tsx
Johannes du Plessis 0108d764d9
fix(ui): resolve eslint errors in dashboard components (#1538)
Clears ~83 pre-existing eslint errors in the UI: auto-fixable rules
(array-type, import/order, sort-imports, type-only imports, redundant
assertions/conditions) plus manual fixes for unnecessary conditions and
banned @ts-nocheck directives. The 8 ported components excluded from
tsconfig are now also ignored by eslint so type-aware linting no longer
fails to parse them.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
2026-06-15 17:29:38 -07:00

47 lines
1.4 KiB
TypeScript

import { Children, isValidElement } from 'react';
import type { ReactNode } from 'react';
type ElementWithChildren = { children?: ReactNode };
interface MarkdownTableProps {
children: ReactNode;
}
function countCells(node: ReactNode): number {
return Children.toArray(node).filter((child) => isValidElement(child) && (child.type === 'th' || child.type === 'td')).length;
}
function collectColumnCounts(node: ReactNode, counts: Array<number>) {
Children.forEach(node, (child) => {
if (!isValidElement(child)) return;
const childProps = child.props as ElementWithChildren;
if (child.type === 'tr') {
const count = countCells(childProps.children);
if (count > 0) counts.push(count);
return;
}
collectColumnCounts(childProps.children, counts);
});
}
function getTableMinWidth(columnCount: number): string {
if (columnCount <= 1) return '100%';
return `max(100%, ${Math.max(420, columnCount * 160)}px)`;
}
export function MarkdownTable({ children }: MarkdownTableProps) {
const columnCounts: Array<number> = [];
collectColumnCounts(children, columnCounts);
const columnCount = Math.max(0, ...columnCounts);
return (
<div className="my-2 max-w-full overflow-x-auto pb-1 text-[color:var(--ui-text-muted)]">
<table className="w-max border-collapse align-top" style={{ minWidth: getTableMinWidth(columnCount) }}>
{children}
</table>
</div>
);
}