Skip to content

Commit 46b09dc

Browse files
committed
Revert "selection and preview"
This reverts commit 6e4eea3.
1 parent 6e4eea3 commit 46b09dc

File tree

6 files changed

+18
-123
lines changed

6 files changed

+18
-123
lines changed

packages/app/src/app/api/projects/[projectId]/queries/[queryId]/data/route.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { isDefined } from "@/utils/helpers";
55
import { countDataForQuery, readDataForQuery } from "@/db/crud/data/query";
66
import { readQuery } from "@/db/crud/query";
77
import { readQueryZones } from "@/db/crud/zone";
8-
import { ComputedColumn } from "@common/db/schema/query";
98

109
type RequestArgs = {
1110
params: {
@@ -100,29 +99,6 @@ export async function GET(request: NextRequest, { params }: RequestArgs) {
10099
zones.map((zone) => zone.zoneId),
101100
);
102101

103-
// Process computed columns if they exist
104-
let processedRows = rows;
105-
if (query.computedColumns && query.computedColumns.length > 0) {
106-
processedRows = rows.map((row) => {
107-
const newRow = { ...row };
108-
109-
for (const computedCol of query.computedColumns) {
110-
try {
111-
// Create a safe evaluation environment for the computed column function
112-
const computeFunction = new Function('row', computedCol.functionBody);
113-
const computedValue = computeFunction(row);
114-
newRow[computedCol.name] = computedValue;
115-
} catch (error) {
116-
// If computation fails, set to null and log error
117-
console.error(`Error computing column ${computedCol.name}:`, error);
118-
newRow[computedCol.name] = null;
119-
}
120-
}
121-
122-
return newRow;
123-
});
124-
}
125-
126102
const rowCount = await countDataForQuery(
127103
projectId,
128104
query.definition,
@@ -132,5 +108,5 @@ export async function GET(request: NextRequest, { params }: RequestArgs) {
132108
zones.map((zone) => zone.zoneId),
133109
);
134110

135-
return NextResponse.json({ rows: processedRows, rowCount });
111+
return NextResponse.json({ rows, rowCount });
136112
}

packages/app/src/components/data/query/helpers.ts

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export async function getQueryColumns(
2323
return [];
2424
}
2525

26-
const regularColumns = await Promise.all(
26+
return await Promise.all(
2727
Object.entries(query.definition).flatMap(([tableName, def]) =>
2828
def.columns.map(async (col: string) => {
2929
const tableConfig = schemaConfig.find(
@@ -47,29 +47,4 @@ export async function getQueryColumns(
4747
}),
4848
),
4949
);
50-
51-
// Add computed columns
52-
const computedColumns = (query.computedColumns || []).map((computedCol) => ({
53-
id: computedCol.name,
54-
label: computedCol.name,
55-
table: "Computed",
56-
columnConfig: {
57-
nameCamelCase: computedCol.name,
58-
label: computedCol.name,
59-
dbName: computedCol.name,
60-
isAbbreviation: false,
61-
isInherited: false,
62-
isRequired: false,
63-
isKey: false,
64-
dataType: "computed",
65-
units: null,
66-
groupDbName: "computed",
67-
groupLabel: "Computed Columns",
68-
mapping: {},
69-
} as ColumnConfig,
70-
tableDbName: "computed" as TableName,
71-
abbreviations: [],
72-
}));
73-
74-
return [...regularColumns, ...computedColumns];
7550
}

packages/app/src/components/data/query/query-definition-explorer.tsx

Lines changed: 4 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ import {
99
canJoinAsSiblings,
1010
SiblingJoinConfig,
1111
getAncestorTables,
12-
Query,
13-
ComputedColumn,
1412
} from "@common/db/schema/query";
1513
import { TableName } from "@common/db/schema/data";
1614
import { TableCounts } from "@/components/data/helpers";
@@ -114,7 +112,6 @@ function transformSchemaToNodes(
114112
selectedTables: TableName[],
115113
tableCounts: TableCounts,
116114
showEmptyTables: boolean,
117-
computedColumns: ComputedColumn[] = [],
118115
): TableColumnNode[] {
119116
const parentToChildren = new Map<string, GroupConfig[]>();
120117
const rootGroups = groups.filter((group) => !group.parentTableDbName);
@@ -211,38 +208,9 @@ function transformSchemaToNodes(
211208
};
212209
}
213210

214-
const tableNodes = rootGroups
211+
return rootGroups
215212
.map((group) => buildTableNode(group))
216213
.filter((node): node is TableColumnNode => node !== null);
217-
218-
// Add computed columns section if there are any
219-
if (computedColumns.length > 0) {
220-
const computedTableNode: TableColumnNode = {
221-
id: "table-computed",
222-
data: {
223-
label: "Computed Columns",
224-
type: "table" as const,
225-
tableId: "computed",
226-
isDisabled: false,
227-
count: computedColumns.length,
228-
},
229-
children: computedColumns.map((computedCol) => ({
230-
id: `column-computed-${computedCol.name}`,
231-
data: {
232-
label: computedCol.name,
233-
type: "column" as const,
234-
columnId: `computed.${computedCol.name}`,
235-
tableId: "computed",
236-
isDisabled: false,
237-
isInherited: false,
238-
groupDbName: "computed",
239-
},
240-
})),
241-
};
242-
tableNodes.push(computedTableNode);
243-
}
244-
245-
return tableNodes;
246214
}
247215

248216
// Helper to find table information by ID
@@ -325,15 +293,13 @@ type Props = {
325293
initialDefinition?: QueryDefinition | null;
326294
onDefinitionChange?: (_definition: QueryDefinition) => void;
327295
tableCounts: TableCounts;
328-
query: Query;
329296
};
330297

331298
export default function QueryDefinitionExplorer({
332299
schemaConfig,
333300
initialDefinition,
334301
onDefinitionChange,
335302
tableCounts,
336-
query,
337303
}: Props) {
338304
const [definition, setDefinition] = useState<QueryDefinition>(
339305
initialDefinition || {},
@@ -350,7 +316,6 @@ export default function QueryDefinitionExplorer({
350316
selectedTables,
351317
tableCounts,
352318
showEmptyTables,
353-
query.computedColumns || [],
354319
);
355320

356321
// Get all potential sibling joins between selected tables
@@ -505,14 +470,6 @@ export default function QueryDefinitionExplorer({
505470
const handleColumnSelect = (columnId: string, checked: boolean) => {
506471
const [tableId, columnName] = columnId.split(".");
507472
const tableName = tableId as TableName;
508-
509-
// Handle computed columns separately
510-
if (tableName === "computed") {
511-
// For computed columns, we don't modify the definition
512-
// They are always included when they exist
513-
return;
514-
}
515-
516473
const newDefinition = { ...definition };
517474

518475
// Get all tables that need to be updated
@@ -582,12 +539,9 @@ export default function QueryDefinitionExplorer({
582539
<TableColumnSelector
583540
nodes={nodes}
584541
selectedTableIds={Object.keys(definition)}
585-
selectedColumnIds={[
586-
...Object.entries(definition).flatMap(([table, def]) =>
587-
def.columns.map((col) => `${table}.${col}`),
588-
),
589-
...(query.computedColumns || []).map((col) => `computed.${col.name}`),
590-
]}
542+
selectedColumnIds={Object.entries(definition).flatMap(([table, def]) =>
543+
def.columns.map((col) => `${table}.${col}`),
544+
)}
591545
onTableSelect={handleTableSelect}
592546
onColumnSelect={handleColumnSelect}
593547
onToggleColumns={handleToggleColumns}

packages/app/src/components/data/query/query-definition.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ export function QueryDefinition({
5757
initialDefinition={definition}
5858
onDefinitionChange={handleDefinitionChange}
5959
tableCounts={tableCounts}
60-
query={query}
6160
/>
6261
</div>
6362
<QueryDefinitionSummary

packages/app/src/components/data/query/query-glide.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,9 @@ export function QueryGlide({
7272
id: col.id,
7373
label: col.label,
7474
group: col.columnConfig.groupLabel,
75-
hasMenu: col.columnConfig.groupDbName === "computed" ? false : true,
75+
hasMenu: true,
7676
menuIcon: "dots",
7777
menuFilterContent: (
78-
col.columnConfig.groupDbName === "computed" ? null : (
7978
<DataGridFilter
8079
column={col.columnConfig}
8180
abbreviations={col.abbreviations}
@@ -104,12 +103,10 @@ export function QueryGlide({
104103
};
105104
handleUpdateDefinition(newDefinition);
106105
}}
107-
/>)
106+
/>
108107
),
109108
sortDirection:
110-
col.columnConfig.groupDbName === "computed"
111-
? null
112-
: query.definition[col.tableDbName]?.sort?.columnNameCamelCase ===
109+
query.definition[col.tableDbName]?.sort?.columnNameCamelCase ===
113110
col.columnConfig.nameCamelCase
114111
? query.definition[col.tableDbName]?.sort?.order
115112
: null,
@@ -131,7 +128,6 @@ export function QueryGlide({
131128
(columnId: string, direction: "asc" | "desc" | null) => {
132129
const column = columns.find((col) => col.id === columnId);
133130
if (!column) return;
134-
if (column.columnConfig.groupDbName === "computed") return;
135131

136132
const newDefinition = { ...query.definition };
137133
const tableDefinition = newDefinition[column.tableDbName] || {

packages/app/src/components/data/query/table-column-selector.tsx

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,38 +53,33 @@ export function TableColumnSelector({
5353
);
5454
}
5555

56-
// Handle computed columns specially
57-
const isComputedColumn = node.data.type === "column" && node.data.tableId === "computed";
58-
const isSelected = isComputedColumn ? true : (
59-
node.data.type === "table"
60-
? selectedTableIds.includes(node.data.tableId!)
61-
: selectedColumnIds.includes(node.data.columnId!)
62-
);
63-
const isDisabled = isComputedColumn ? true : node.data.isDisabled;
64-
6556
return (
6657
<div
6758
className={cn(
6859
"flex items-center gap-2 rounded-md px-2 py-1 transition-colors",
69-
isDisabled && "opacity-50",
60+
node.data.isDisabled && "opacity-50",
7061
)}
7162
>
7263
<Checkbox
7364
id={node.id}
74-
checked={isSelected}
65+
checked={
66+
node.data.type === "table"
67+
? selectedTableIds.includes(node.data.tableId!)
68+
: selectedColumnIds.includes(node.data.columnId!)
69+
}
7570
onCheckedChange={(checked) => {
7671
if (node.data.type === "table") {
7772
onTableSelect(node.data.tableId!, checked as boolean);
78-
} else if (!isComputedColumn) {
73+
} else {
7974
onColumnSelect(node.data.columnId!, checked as boolean);
8075
}
8176
}}
82-
disabled={isDisabled}
77+
disabled={node.data.isDisabled}
8378
/>
8479
<span
8580
className={cn(
8681
"flex-1 truncate text-xs",
87-
isDisabled && "opacity-50",
82+
node.data.isDisabled && "opacity-50",
8883
)}
8984
title={node.data.label}
9085
>

0 commit comments

Comments
 (0)