Skip to content

Commit 5611959

Browse files
committed
Filter against formatted values too
1 parent b4ac6f1 commit 5611959

1 file changed

Lines changed: 101 additions & 6 deletions

File tree

apps/webapp/app/components/code/TSQLResultsTable.tsx

Lines changed: 101 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,103 @@ type RowData = Record<string, unknown>;
5353
/**
5454
* Fuzzy filter function using match-sorter ranking
5555
*/
56+
/**
57+
* Get the formatted display string for a value based on its column type
58+
* This mirrors the formatting logic in CellValue component
59+
*/
60+
function getFormattedValue(value: unknown, column: OutputColumnMetadata): string {
61+
if (value === null) return "NULL";
62+
if (value === undefined) return "";
63+
64+
// Handle custom render types
65+
if (column.customRenderType) {
66+
switch (column.customRenderType) {
67+
case "duration":
68+
if (typeof value === "number") {
69+
return formatDurationMilliseconds(value, { style: "short" });
70+
}
71+
break;
72+
case "durationSeconds":
73+
if (typeof value === "number") {
74+
return formatDurationMilliseconds(value * 1000, { style: "short" });
75+
}
76+
break;
77+
case "cost":
78+
if (typeof value === "number") {
79+
return formatCurrencyAccurate(value / 100);
80+
}
81+
break;
82+
case "costInDollars":
83+
if (typeof value === "number") {
84+
return formatCurrencyAccurate(value);
85+
}
86+
break;
87+
case "runStatus":
88+
// Include friendly status names for searching
89+
if (typeof value === "string") {
90+
return value;
91+
}
92+
break;
93+
}
94+
}
95+
96+
// Handle DateTime types - format for display
97+
if (isDateTimeType(column.type)) {
98+
if (typeof value === "string") {
99+
try {
100+
const date = new Date(value);
101+
// Format as a searchable string: "15 Jan 2026 12:34:56"
102+
return date.toLocaleDateString("en-GB", {
103+
day: "numeric",
104+
month: "short",
105+
year: "numeric",
106+
hour: "2-digit",
107+
minute: "2-digit",
108+
second: "2-digit",
109+
});
110+
} catch {
111+
return String(value);
112+
}
113+
}
114+
}
115+
116+
// Handle numeric types - format with separators
117+
if (isNumericType(column.type) && typeof value === "number") {
118+
return formatNumber(value);
119+
}
120+
121+
// Handle booleans
122+
if (isBooleanType(column.type)) {
123+
if (typeof value === "boolean") {
124+
return value ? "true" : "false";
125+
}
126+
if (typeof value === "number") {
127+
return value === 1 ? "true" : "false";
128+
}
129+
}
130+
131+
// Handle objects/arrays
132+
if (typeof value === "object") {
133+
return JSON.stringify(value);
134+
}
135+
136+
return String(value);
137+
}
138+
56139
const fuzzyFilter: FilterFn<RowData> = (row, columnId, value, addMeta) => {
57-
// Get the cell value and convert to string for matching
140+
// Get the cell value
58141
const cellValue = row.getValue(columnId);
59-
const searchValue = String(value);
142+
const searchValue = String(value).toLowerCase();
60143

61144
// Handle empty search
62145
if (!searchValue) return true;
63146

64-
// Convert cell value to string for ranking
65-
const itemValue =
147+
// Get the column metadata from the cell
148+
const cell = row.getAllCells().find((c) => c.column.id === columnId);
149+
const meta = cell?.column.columnDef.meta as ColumnMeta | undefined;
150+
151+
// Build searchable strings - raw value
152+
const rawValue =
66153
cellValue === null
67154
? "NULL"
68155
: cellValue === undefined
@@ -71,8 +158,16 @@ const fuzzyFilter: FilterFn<RowData> = (row, columnId, value, addMeta) => {
71158
? JSON.stringify(cellValue)
72159
: String(cellValue);
73160

74-
// Rank the item
75-
const itemRank = rankItem(itemValue, searchValue);
161+
// Build searchable strings - formatted value (if we have column metadata)
162+
const formattedValue = meta?.outputColumn
163+
? getFormattedValue(cellValue, meta.outputColumn)
164+
: rawValue;
165+
166+
// Combine both values for searching (separated by space to allow matching either)
167+
const combinedSearchText = `${rawValue} ${formattedValue}`.toLowerCase();
168+
169+
// Rank against the combined text
170+
const itemRank = rankItem(combinedSearchText, searchValue);
76171

77172
// Store the ranking info
78173
addMeta({ itemRank });

0 commit comments

Comments
 (0)