Skip to content

Commit c06361b

Browse files
authored
improvement(tables): clean up duplicate types, unnecessary memos, and barrel imports (#4205)
* improvement(tables): clean up duplicate types, unnecessary memos, and barrel imports * fix(tables): revert barrel import in client component to avoid bundling server-only deps
1 parent 6fd1767 commit c06361b

File tree

4 files changed

+38
-38
lines changed

4 files changed

+38
-38
lines changed

apps/sim/app/workspace/[workspaceId]/tables/components/import-csv-dialog/import-csv-dialog.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,15 @@ export function ImportCsvDialog({
244244
}
245245
}, [mapping, parsed?.headers, table.schema.columns])
246246

247-
const appendCapacityDeficit = useMemo(() => {
248-
if (!parsed || mode !== 'append') return 0
249-
const projected = table.rowCount + parsed.totalRows
250-
return projected > table.maxRows ? projected - table.maxRows : 0
251-
}, [mode, parsed, table.maxRows, table.rowCount])
247+
const appendCapacityDeficit =
248+
parsed && mode === 'append' && table.rowCount + parsed.totalRows > table.maxRows
249+
? table.rowCount + parsed.totalRows - table.maxRows
250+
: 0
252251

253-
const replaceCapacityDeficit = useMemo(() => {
254-
if (!parsed || mode !== 'replace') return 0
255-
return parsed.totalRows > table.maxRows ? parsed.totalRows - table.maxRows : 0
256-
}, [mode, parsed, table.maxRows])
252+
const replaceCapacityDeficit =
253+
parsed && mode === 'replace' && parsed.totalRows > table.maxRows
254+
? parsed.totalRows - table.maxRows
255+
: 0
257256

258257
const canSubmit =
259258
parsed !== null &&
@@ -264,12 +263,11 @@ export function ImportCsvDialog({
264263
appendCapacityDeficit === 0 &&
265264
replaceCapacityDeficit === 0
266265

267-
const importCsv = importMutation.mutateAsync
268266
const handleSubmit = useCallback(async () => {
269267
if (!parsed || !canSubmit) return
270268
setSubmitError(null)
271269
try {
272-
const result = await importCsv({
270+
const result = await importMutation.mutateAsync({
273271
workspaceId,
274272
tableId: table.id,
275273
file: parsed.file,
@@ -294,9 +292,9 @@ export function ImportCsvDialog({
294292
setSubmitError(summarizeImportError(message))
295293
logger.error('CSV import into existing table failed', err)
296294
}
295+
// eslint-disable-next-line react-hooks/exhaustive-deps
297296
}, [
298297
canSubmit,
299-
importCsv,
300298
mapping,
301299
mode,
302300
onImported,
@@ -363,7 +361,7 @@ export function ImportCsvDialog({
363361
<div className='flex flex-col gap-4'>
364362
<div className='flex items-center justify-between gap-3 rounded-sm border border-[var(--border)] p-2'>
365363
<div className='flex min-w-0 flex-col'>
366-
<span className='truncate text-caption text-[var(--text-primary)]'>
364+
<span className='truncate text-[var(--text-primary)] text-caption'>
367365
{parsed.file.name}
368366
</span>
369367
<span className='text-[var(--text-tertiary)] text-xs'>

apps/sim/hooks/queries/tables.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
import { createLogger } from '@sim/logger'
66
import { keepPreviousData, useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
77
import { toast } from '@/components/emcn'
8-
import type { Filter, RowData, Sort, TableDefinition, TableMetadata, TableRow } from '@/lib/table'
8+
import type {
9+
CsvHeaderMapping,
10+
Filter,
11+
RowData,
12+
Sort,
13+
TableDefinition,
14+
TableMetadata,
15+
TableRow,
16+
} from '@/lib/table'
917

1018
const logger = createLogger('TableQueries')
1119

@@ -780,7 +788,6 @@ export function useUploadCsvToTable() {
780788
})
781789
}
782790

783-
export type CsvHeaderMapping = Record<string, string | null>
784791
export type CsvImportMode = 'append' | 'replace'
785792

786793
interface ImportCsvIntoTableParams {

apps/sim/lib/copilot/tools/server/table/user-table.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ import {
66
type ServerToolContext,
77
} from '@/lib/copilot/tools/server/base-tool'
88
import { generateId } from '@/lib/core/utils/uuid'
9-
import { COLUMN_TYPES } from '@/lib/table/constants'
109
import {
1110
buildAutoMapping,
11+
COLUMN_TYPES,
1212
CSV_MAX_BATCH_SIZE,
1313
type CsvHeaderMapping,
1414
CsvImportValidationError,
@@ -17,7 +17,7 @@ import {
1717
parseCsvBuffer,
1818
sanitizeName,
1919
validateMapping,
20-
} from '@/lib/table/csv-import'
20+
} from '@/lib/table'
2121
import {
2222
addTableColumn,
2323
batchInsertRows,

apps/sim/lib/table/query-builder/use-query-builder.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Hooks for query builder UI state management (filters and sorting).
33
*/
44

5-
import { useCallback, useMemo } from 'react'
5+
import { useCallback } from 'react'
66
import { generateShortId } from '@/lib/core/utils/uuid'
77
import type { ColumnOption } from '../types'
88
import {
@@ -15,28 +15,28 @@ import {
1515

1616
export type { ColumnOption }
1717

18+
const comparisonOptions: ColumnOption[] = COMPARISON_OPERATORS.map((op) => ({
19+
value: op.value,
20+
label: op.label,
21+
}))
22+
23+
const logicalOptions: ColumnOption[] = LOGICAL_OPERATORS.map((op) => ({
24+
value: op.value,
25+
label: op.label,
26+
}))
27+
28+
const sortDirectionOptions: ColumnOption[] = SORT_DIRECTIONS.map((d) => ({
29+
value: d.value,
30+
label: d.label,
31+
}))
32+
1833
/** Manages filter rule state with add/remove/update operations. */
1934
export function useFilterBuilder({
2035
columns,
2136
rules,
2237
setRules,
2338
isReadOnly = false,
2439
}: UseFilterBuilderProps): UseFilterBuilderReturn {
25-
const comparisonOptions = useMemo(
26-
() => COMPARISON_OPERATORS.map((op) => ({ value: op.value, label: op.label })),
27-
[]
28-
)
29-
30-
const logicalOptions = useMemo(
31-
() => LOGICAL_OPERATORS.map((op) => ({ value: op.value, label: op.label })),
32-
[]
33-
)
34-
35-
const sortDirectionOptions = useMemo(
36-
() => SORT_DIRECTIONS.map((d) => ({ value: d.value, label: d.label })),
37-
[]
38-
)
39-
4040
const createDefaultRule = useCallback((): FilterRule => {
4141
return {
4242
id: generateShortId(),
@@ -85,11 +85,6 @@ export function useSortBuilder({
8585
sortRule,
8686
setSortRule,
8787
}: UseSortBuilderProps): UseSortBuilderReturn {
88-
const sortDirectionOptions = useMemo(
89-
() => SORT_DIRECTIONS.map((d) => ({ value: d.value, label: d.label })),
90-
[]
91-
)
92-
9388
const addSort = useCallback(() => {
9489
setSortRule({
9590
id: generateShortId(),

0 commit comments

Comments
 (0)