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
18 changes: 14 additions & 4 deletions src/components/ResultsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
tableFeatures,
useTable,
} from "@tanstack/react-table";
import { useVirtualizer } from "@tanstack/react-virtual";
import { measureElement, useVirtualizer } from "@tanstack/react-virtual";
import { cn } from "@/lib/utils";
import { ArrowUpDown, ArrowUp, ArrowDown, Eye, Funnel, Lock } from "lucide-react";
import {
Expand Down Expand Up @@ -138,6 +138,7 @@ export function ResultsGrid({
const [editingCell, setEditingCell] = useState<{ rowIndex: number; columnId: string } | null>(null);
const [editValue, setEditValue] = useState<string>("");
const [viewMode, setViewMode] = useState<"card" | "table">("card");
const [wrapText, setWrapText] = useState(false);
const [selectedRow, setSelectedRow] = useState<{ row: Record<string, unknown>; index: number } | null>(null);
const [columnFilters, setColumnFilters] = useState<Map<string, string>>(new Map());
const [activeFilterCol, setActiveFilterCol] = useState<string | null>(null);
Expand Down Expand Up @@ -476,6 +477,7 @@ export function ResultsGrid({
count: rows.length,
getScrollElement: () => tableContainerRef.current,
estimateSize: () => 36,
measureElement: wrapText ? measureElement : undefined,
overscan: 10,
});

Expand All @@ -490,6 +492,7 @@ export function ResultsGrid({
count: result.rows.length,
getScrollElement: () => mobileTableContainerRef.current,
estimateSize: () => 48,
measureElement: wrapText ? measureElement : undefined,
overscan: 5,
});

Expand Down Expand Up @@ -528,6 +531,8 @@ export function ResultsGrid({
onClearFilters={handleClearFilters}
viewMode={viewMode}
onSetViewMode={setViewMode}
wrapText={wrapText}
onToggleWrapText={() => setWrapText((value) => !value)}
hasSensitive={hasSensitive}
effectiveMaskingEnabled={effectiveMaskingEnabled}
userCanToggle={userCanToggle}
Expand Down Expand Up @@ -622,6 +627,7 @@ export function ResultsGrid({
height: `${virtualRow.size}px`,
transform: `translateY(${virtualRow.start}px)`,
}}
ref={wrapText ? mobileTableVirtualizer.measureElement : undefined}
className="flex hover:bg-brand-tint/[0.03] transition-colors border-b border-hairline cursor-pointer text-left"
onClick={() => setSelectedRow({ row, index: virtualRow.index })}
>
Expand All @@ -638,9 +644,9 @@ export function ResultsGrid({
<div
key={field}
className={cn(
"h-full px-4 py-3 border-r border-hairline text-xs font-mono whitespace-nowrap overflow-hidden flex items-center",
"h-full px-4 py-3 border-r border-hairline text-xs font-mono overflow-hidden flex min-w-[120px]",
wrapText ? "whitespace-normal break-words items-start" : "whitespace-nowrap items-center",
idx === 0 && "sticky left-0 z-10 bg-sunken shadow-[2px_0_8px_rgba(0,0,0,0.3)]",
"min-w-[120px]",
)}
>
<span className={className}>{displayValue}</span>
Expand Down Expand Up @@ -687,6 +693,7 @@ export function ResultsGrid({
<div
key={row.id}
data-index={virtualRow.index}
ref={wrapText ? rowVirtualizer.measureElement : undefined}
style={{
height: `${virtualRow.size}px`,
transform: `translateY(${virtualRow.start}px)`,
Expand All @@ -700,7 +707,10 @@ export function ResultsGrid({
<div
key={cell.id}
style={{ width: cell.column.getSize(), minWidth: cell.column.getSize() }}
className="h-full px-4 py-2 border-r border-hairline text-xs font-mono whitespace-nowrap overflow-hidden group-hover:border-hairline-strong flex items-center shrink-0"
className={cn(
"h-full px-4 py-2 border-r border-hairline text-xs font-mono overflow-hidden group-hover:border-hairline-strong flex shrink-0",
wrapText ? "whitespace-normal break-words items-start" : "whitespace-nowrap items-center",
)}
>
{flexRender(cell.column.columnDef.cell, cell.getContext())}
</div>
Expand Down
33 changes: 32 additions & 1 deletion src/components/results-grid/StatsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,19 @@
import React from "react";
import { QueryResult } from "@/lib/types";
import { cn } from "@/lib/utils";
import { ChevronDown, LayoutGrid, Table2, LoaderCircle, EyeOff, Eye, Save, X, Funnel, Lock } from "lucide-react";
import {
ChevronDown,
LayoutGrid,
Table2,
LoaderCircle,
EyeOff,
Eye,
Save,
X,
Funnel,
Lock,
WrapText,
} from "lucide-react";
import { Button } from "@/components/ui/button";
import type { CellChange } from "@/components/ResultsGrid";
import { describeWarning } from "@/components/results-grid/utils";
Expand All @@ -19,6 +31,8 @@ export interface StatsBarProps {
onClearFilters: () => void;
viewMode: "card" | "table";
onSetViewMode: (mode: "card" | "table") => void;
wrapText: boolean;
onToggleWrapText: () => void;
// Masking props
hasSensitive: boolean;
effectiveMaskingEnabled: boolean;
Expand All @@ -41,6 +55,8 @@ export function StatsBar({
onClearFilters,
viewMode,
onSetViewMode,
wrapText,
onToggleWrapText,
hasSensitive,
effectiveMaskingEnabled,
userCanToggle,
Expand Down Expand Up @@ -106,6 +122,19 @@ export function StatsBar({
{MASKED_LABEL}
</span>
) : null)}
<Button
variant="ghost"
size="sm"
className={cn(
"h-6 px-2 text-xs font-medium gap-1",
wrapText ? "text-brand bg-brand-tint/10" : "text-fg-muted",
)}
onClick={onToggleWrapText}
title={wrapText ? "Disable text wrapping" : "Enable text wrapping"}
>
<WrapText className="w-3 h-3" />
{wrapText ? "WRAP ON" : "WRAP"}
</Button>

{editingEnabled && pendingChanges && pendingChanges.length > 0 && (
<div className="flex items-center gap-1">
Expand All @@ -116,6 +145,7 @@ export function StatsBar({
variant="ghost"
size="sm"
className="h-6 px-1.5 text-xs text-success hover:bg-success-tint/10"
aria-label="Apply changes"
onClick={onApplyChanges}
>
<Save strokeWidth={1.5} className="w-3 h-3" />
Expand All @@ -124,6 +154,7 @@ export function StatsBar({
variant="ghost"
size="sm"
className="h-6 px-1.5 text-xs text-danger hover:bg-danger-tint/10"
aria-label="Discard changes"
onClick={onDiscardChanges}
>
<X strokeWidth={1.5} className="w-3 h-3" />
Expand Down
9 changes: 9 additions & 0 deletions tests/components/ResultsGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ mock.module("@/components/results-grid/StatsBar", () => ({
`${(props.pendingChanges as unknown[]).length} changes`,
)
: null,
props.onToggleWrapText
? React.createElement(
"button",
{ "data-testid": "wrap-toggle", onClick: props.onToggleWrapText as () => void },
"WRAP",
)
: null,
(props.activeFilterCount as number) > 0
? React.createElement(
"button",
Expand All @@ -109,6 +116,7 @@ mock.module("@/components/results-grid/StatsBar", () => ({

// ── Mock @tanstack/react-virtual ────────────────────────────────────────────
mock.module("@tanstack/react-virtual", () => ({
measureElement: () => 36,
useVirtualizer: (opts: { count: number }) => ({
getVirtualItems: () =>
Array.from({ length: opts.count }, (_, i) => ({
Expand All @@ -118,6 +126,7 @@ mock.module("@tanstack/react-virtual", () => ({
key: i,
})),
getTotalSize: () => opts.count * 36,
measureElement: () => {},
}),
}));

Expand Down
48 changes: 44 additions & 4 deletions tests/components/results-grid/StatsBar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ describe("results-grid/StatsBar", () => {
onClearFilters={onClearFilters}
viewMode="card"
onSetViewMode={mock(() => {})}
wrapText={false}
onToggleWrapText={mock(() => {})}
hasSensitive={false}
effectiveMaskingEnabled={false}
userCanToggle={false}
Expand Down Expand Up @@ -71,6 +73,8 @@ describe("results-grid/StatsBar", () => {
onClearFilters={mock(() => {})}
viewMode="table"
onSetViewMode={onSetViewMode}
wrapText={false}
onToggleWrapText={mock(() => {})}
hasSensitive
effectiveMaskingEnabled={false}
userCanToggle
Expand All @@ -88,6 +92,29 @@ describe("results-grid/StatsBar", () => {
expect(onSetViewMode).toHaveBeenCalledTimes(2);
});

test("supports text wrapping toggle", () => {
const onToggleWrapText = mock(() => {});
const { queryByText } = render(
<StatsBar
result={makeResult()}
filteredRowCount={2}
activeFilterCount={0}
onClearFilters={mock(() => {})}
viewMode="table"
onSetViewMode={mock(() => {})}
wrapText={false}
onToggleWrapText={onToggleWrapText}
hasSensitive={false}
effectiveMaskingEnabled={false}
userCanToggle={false}
/>,
);

expect(queryByText("WRAP")).not.toBeNull();
fireEvent.click(queryByText("WRAP")!);
expect(onToggleWrapText).toHaveBeenCalledTimes(1);
});

test("shows locked masked label when user cannot toggle", () => {
const { queryByText } = render(
<StatsBar
Expand All @@ -97,6 +124,8 @@ describe("results-grid/StatsBar", () => {
onClearFilters={mock(() => {})}
viewMode="card"
onSetViewMode={mock(() => {})}
wrapText={false}
onToggleWrapText={mock(() => {})}
hasSensitive
effectiveMaskingEnabled
userCanToggle={false}
Expand All @@ -114,6 +143,8 @@ describe("results-grid/StatsBar", () => {
onClearFilters={mock(() => {})}
viewMode="card"
onSetViewMode={mock(() => {})}
wrapText={false}
onToggleWrapText={mock(() => {})}
hasSensitive={false}
effectiveMaskingEnabled={false}
userCanToggle={false}
Expand All @@ -130,6 +161,8 @@ describe("results-grid/StatsBar", () => {
onClearFilters={mock(() => {})}
viewMode="card"
onSetViewMode={mock(() => {})}
wrapText={false}
onToggleWrapText={mock(() => {})}
hasSensitive={false}
effectiveMaskingEnabled={false}
userCanToggle={false}
Expand All @@ -150,6 +183,8 @@ describe("results-grid/StatsBar", () => {
onClearFilters={mock(() => {})}
viewMode="card"
onSetViewMode={mock(() => {})}
wrapText={false}
onToggleWrapText={mock(() => {})}
hasSensitive={false}
effectiveMaskingEnabled={false}
userCanToggle={false}
Expand All @@ -173,6 +208,8 @@ describe("results-grid/StatsBar", () => {
onClearFilters={mock(() => {})}
viewMode="card"
onSetViewMode={mock(() => {})}
wrapText={false}
onToggleWrapText={mock(() => {})}
hasSensitive={false}
effectiveMaskingEnabled={false}
userCanToggle={false}
Expand All @@ -196,6 +233,8 @@ describe("results-grid/StatsBar", () => {
onClearFilters={mock(() => {})}
viewMode="card"
onSetViewMode={mock(() => {})}
wrapText={false}
onToggleWrapText={mock(() => {})}
hasSensitive={false}
effectiveMaskingEnabled={false}
userCanToggle={false}
Expand All @@ -213,14 +252,16 @@ describe("results-grid/StatsBar", () => {
const pendingChanges: CellChange[] = [
{ rowIndex: 0, columnId: "name", originalValue: "Alice", newValue: "Alicia" },
];
const { container, queryByText } = render(
const { queryByText, getByLabelText } = render(
<StatsBar
result={makeResult()}
filteredRowCount={2}
activeFilterCount={0}
onClearFilters={mock(() => {})}
viewMode="card"
onSetViewMode={mock(() => {})}
wrapText={false}
onToggleWrapText={mock(() => {})}
hasSensitive={false}
effectiveMaskingEnabled={false}
userCanToggle={false}
Expand All @@ -232,9 +273,8 @@ describe("results-grid/StatsBar", () => {
);

expect(queryByText("1 change")).not.toBeNull();
const buttons = container.querySelectorAll("button");
fireEvent.click(buttons[0]!);
fireEvent.click(buttons[1]!);
fireEvent.click(getByLabelText("Apply changes"));
fireEvent.click(getByLabelText("Discard changes"));
expect(onApplyChanges).toHaveBeenCalledTimes(1);
expect(onDiscardChanges).toHaveBeenCalledTimes(1);
});
Expand Down
Loading