Skip to content
Open
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
24 changes: 13 additions & 11 deletions src/components/ui/data-table/DataTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,14 +154,14 @@ export function DataTable<T extends Record<string, unknown>>({
{ isActive: focus },
);

// Column widths
const colWidths = columns.map((col) => {
if (col.width) return col.width;
// default the width of each column
const columnsWithWidths = columns.map((col) => {
if (col.width !== undefined) return { ...col, width: col.width };

@Hweinstock Hweinstock Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we explicitly check undefined to fix the edge case where the width is explicitly set to 0

const maxData = pageData.reduce((max, row) => {
const val = col.render ? col.render(row[col.key], row) : String(row[col.key] ?? "");
return Math.max(max, val.length);
}, 0);
return Math.max(col.header.length + 2, maxData + 2, 6);
return { ...col, width: Math.max(col.header.length + 2, maxData + 2, 6) };
});

const pad = (s: string, w: number, align: "left" | "center" | "right" = "left") => {
Expand Down Expand Up @@ -214,12 +214,12 @@ export function DataTable<T extends Record<string, unknown>>({
{/* Header */}
<Box flexDirection="row">
{selectable && <Text color={theme.colors.muted}>{" "}</Text>}
{columns.map((col, i) => {
{columnsWithWidths.map((col) => {
const sortArrow = sortColumn === col.key ? (sortDirection === "asc" ? " ▲" : " ▼") : "";
return (
<Box key={col.key} width={colWidths[i]}>
<Box key={col.key} width={col.width}>
<Text bold color={theme.colors.primary}>
{pad(col.header + sortArrow, colWidths[i], col.align)}
{pad(col.header + sortArrow, col.width, col.align)}
</Text>
</Box>
);
Expand All @@ -230,7 +230,9 @@ export function DataTable<T extends Record<string, unknown>>({
<Box flexDirection="row">
<Text color={theme.colors.border}>
{showDivider
? "─".repeat(colWidths.reduce((a, b) => a + b, 0) + (selectable ? 2 : 0))
? "─".repeat(
columnsWithWidths.reduce((acc, col) => acc + col.width, 0) + (selectable ? 2 : 0),
)
: " "}
</Text>
</Box>
Expand All @@ -250,17 +252,17 @@ export function DataTable<T extends Record<string, unknown>>({
{isSelected ? "❯ " : " "}
</Text>
)}
{columns.map((col, ci) => {
{columnsWithWidths.map((col) => {
const val = col.render
? col.render(row[col.key], row)
: String(row[col.key] ?? "");
return (
<Box key={col.key} width={colWidths[ci]}>
<Box key={col.key} width={col.width}>
<Text
color={isSelected ? theme.colors.text : theme.colors.muted}
bold={isSelected}
>
{pad(val, colWidths[ci], col.align)}
{pad(val, col.width, col.align)}
</Text>
</Box>
);
Expand Down
13 changes: 8 additions & 5 deletions src/components/ui/markdown/Markdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,17 @@ export const Markdown: React.FC<MarkdownProps> = ({ content, theme = darkTheme }
let i = 0;

while (i < lines.length) {
const line = lines[i];
// Note: assertion is safe based on bound above.
const line = lines[i]!;

// Fenced code block
if (line.startsWith("```")) {
const lang = line.slice(3).trim();
const codeLines: string[] = [];
i++;
while (i < lines.length && !lines[i].startsWith("```")) {
codeLines.push(lines[i]);
// Note: assertions on lines[i] are safe based on first term in the while condition.
while (i < lines.length && !lines[i]!.startsWith("```")) {
codeLines.push(lines[i]!);
i++;
}
elements.push(
Expand Down Expand Up @@ -253,10 +255,11 @@ export const Markdown: React.FC<MarkdownProps> = ({ content, theme = darkTheme }
// Ordered list
const olMatch = line.match(/^(\d+)\.\s(.*)/);
if (olMatch) {
// note: if the regex matched, there must be number at olMatch[1], so assertion is safe.
elements.push(
<Box key={i} flexDirection="row">
<Text color={theme.colors.primary}>{` ${olMatch[1]}. `}</Text>
<Text>{renderInline(parseInline(olMatch[2]), theme)}</Text>
<Text color={theme.colors.primary}>{` ${olMatch[1]!}. `}</Text>
<Text>{renderInline(parseInline(olMatch[2] ?? ""), theme)}</Text>
</Box>,
);
i++;
Expand Down
13 changes: 8 additions & 5 deletions src/components/ui/tabs/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,24 @@ export const Tabs: React.FC<TabsProps> = ({
const currentIndex = tabs.findIndex((t) => t.key === effectiveActiveKey);
if (key.leftArrow || input === "h") {
for (let i = currentIndex - 1; i >= 0; i--) {
if (!tabs[i].disabled) {
onChange(tabs[i].key);
const tab = tabs[i];
if (tab && !tab.disabled) {
onChange(tab.key);
break;
}
}
} else if (key.rightArrow || input === "l") {
for (let i = currentIndex + 1; i < tabs.length; i++) {
if (!tabs[i].disabled) {
onChange(tabs[i].key);
const tab = tabs[i];
if (tab && !tab.disabled) {
onChange(tab.key);
break;
}
}
} else if (input >= "1" && input <= "9") {
const idx = parseInt(input, 10) - 1;
if (idx < tabs.length && !tabs[idx].disabled) onChange(tabs[idx].key);
const tab = tabs[idx];
if (idx < tabs.length && tab && !tab.disabled) onChange(tab.key);
}
},
{ isActive: focus },
Expand Down
Loading