Skip to content

improvement(tables): tables module#3954

Open
waleedlatif1 wants to merge 11 commits intostagingfrom
improvement/tables-module
Open

improvement(tables): tables module#3954
waleedlatif1 wants to merge 11 commits intostagingfrom
improvement/tables-module

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Add user-defined tables module with full CRUD, inline cell editing, column management, and sorting/filtering
  • Undo/redo for all table operations (cell edits, row create/delete, column create/rename/delete/type change, table rename)
  • Column selection, multi-cell selection, copy/paste with auto-column creation
  • Column drag-to-reorder, column resizing, sort/filter by column from header menu
  • CSV export with active filter/sort applied
  • Add CloudWatch block with 7 tools (describe alarms, log groups/streams, get log events/metrics, query logs, list metrics)
  • Live sync option for KB connectors + fix embedding billing
  • PostHog analytics audit: remove noise, add 10 new events
  • Fix Linear connector GraphQL type errors and tag slot reuse

Type of Change

  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 5, 2026 0:22am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 4, 2026

PR Summary

High Risk
Adds new internal CloudWatch API routes that accept AWS credentials and execute AWS SDK calls, plus substantial changes to the tables UI (selection/paste/export/undo) and connector billing gates; these touch security-sensitive input handling and core user workflows, raising regression risk.

Overview
Adds AWS CloudWatch tooling end-to-end. Introduces new internal API routes for CloudWatch Logs/Metrics/Alarms (log group/stream discovery, log events, Insights queries with polling/timeout, metric listing/statistics, alarm listing) plus shared CloudWatch utility helpers, selector registry entries, and a new CloudWatch block wired into the blocks registry and icons.

Tightens Knowledge Base connector sync + tag slot behavior. Enforces billing-based gating for “live” connector sync intervals (<60 min) on create/update, updates the connector UI to expose a new Live sync option (Max-only) with disabled states/badges, and improves tag definition slot assignment by reusing existing slots when display name + field type match.

Expands tables UX + export capabilities. Adds CSV export (with filter/sort applied) and export tests, enhances table header menus with sort/filter actions, supports column-scoped filtering via an imperative TableFilter API, improves selection handling (including column selection) and drag visuals, auto-creates new columns on paste when clipboard data exceeds existing columns, and extends undo/redo to cover row create/update/delete and column delete.

Analytics/test refactors and small fixes. Adds/adjusts PostHog events across folders/schedules/documents/log filters/search/workflow import-export (and removes a chat “marked read” event), modernizes fetch/drizzle mocks in tests, and fixes Linear connector GraphQL variable types from String! to ID!.

Reviewed by Cursor Bugbot for commit d1c3a98. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit d1c3a98. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 4, 2026

Greptile Summary

This PR delivers a large tables module improvement (full CRUD, undo/redo, column selection, copy/paste with auto-column creation, drag-to-reorder, sort/filter from column headers, CSV export), adds a CloudWatch block with 7 tools, introduces live-sync gating for KB connectors behind a Max/Enterprise plan check, fixes embedding billing so platform-key usage is recorded, and resolves Linear connector GraphQL type errors.

Key highlights:

  • Tables module: well-structured separation of concerns across export.ts, use-export-table.ts, use-table-undo.ts, and the Zustand undo store
  • Async paste handler correctly calls e.preventDefault() synchronously before any await, so clipboard default is always suppressed
  • CloudWatch block: all 7 tool definitions use visibility: 'user-only' for AWS credentials, satisfying the credential-visibility rule
  • Embedding billing: isBYOK flag is captured only from the first batch (batch index 0) rather than per-batch — if batches could theoretically use different keys this would under-bill, but since getEmbeddingConfig resolves the key once per document this is safe in practice
  • A non-barrel re-export was introduced in import-export.ts, which violates the project's import guidelines
  • The column drag-drop handleDragEnd removed the fromIndex !== -1 && toIndex !== -1 bounds check; if target is somehow absent from the column order list, splice(-1, 0, dragged) would silently insert before the last column instead of at the end
  • fetchAllTableRows in use-export-table.ts doesn't forward an AbortSignal, so in-flight export requests can't be cancelled if the component unmounts mid-export

Confidence Score: 4/5

Generally safe to merge — no data-loss or security regressions found; the P2 findings are defensive improvements and a style violation.

Score of 4 reflects three P2 items that should be addressed before merge: the non-barrel re-export violates stated project conventions, the drag-drop guard removal is a mild regression, and the missing AbortSignal is a best-practice gap. None of these block functionality today but the drag-drop issue could produce a silent column-order corruption in an edge case.

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table/table.tsx (drag-drop guard), apps/sim/lib/workflows/operations/import-export.ts (re-export rule), apps/sim/app/workspace/[workspaceId]/tables/[tableId]/hooks/use-export-table.ts (abort signal)

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table/table.tsx Major enhancement: column selection, CSV export button, sort/filter from header menu, async paste with auto-column creation; drag-drop bounds check removed
apps/sim/hooks/queries/tables.ts Adds fetchAllTableRows paginated helper used by CSV export; exports interfaces for consumers
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/hooks/use-export-table.ts New hook for CSV export; AbortSignal not forwarded to fetchAllTableRows for cancellation
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/export.ts New pure-utility module: formatTableExportValue and buildTableCsv with correct RFC 4180 escaping
apps/sim/stores/table/store.ts Patches create-rows undo entries when server-assigned row IDs differ from optimistic ones
apps/sim/stores/table/types.ts Adds delete-column undo action type with complete column metadata snapshot for redo
apps/sim/hooks/use-table-undo.ts Adds undo/redo dispatch for delete-column action
apps/sim/blocks/blocks/cloudwatch.ts New CloudWatch block with 7 operations, cascading file-selectors for log groups/streams
apps/sim/tools/cloudwatch/query_logs.ts New tool for CloudWatch Log Insights with user-only visibility on AWS credentials
apps/sim/app/api/tools/cloudwatch/utils.ts Shared CloudWatch Logs client factory and pollQueryResults with timeout/partial-result fallback
apps/sim/lib/billing/core/subscription.ts Adds hasLiveSyncAccess for Max/Enterprise gating; parallelizes subscription+billing fetch in hasInboxAccess
apps/sim/lib/knowledge/embeddings.ts Returns totalTokens, isBYOK, and modelName so callers can make accurate billing decisions
apps/sim/lib/knowledge/documents/service.ts Records per-document embedding token cost when platform key is used; skips billing for BYOK
apps/sim/app/api/knowledge/[id]/connectors/route.ts Adds plan-check gate for live-sync intervals (<60 min) at both create and update connector endpoints
apps/sim/lib/workflows/operations/import-export.ts Extracts downloadFile/sanitizePathSegment to lib/core; re-exports from non-barrel file (violates import guidelines)
apps/sim/connectors/linear/linear.ts Fixes Linear GraphQL type errors: String! → ID! for issue/team/project ID variables
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-filter/table-filter.tsx Refactored to forwardRef with TableFilterHandle; supports programmatic addColumnRule from column header
apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/row-modal/row-modal.tsx Adds undo tracking for single row create/edit/delete; bulk deletes do not record undo entries
packages/db/schema.ts Adds 'knowledge-base' to usage_log_source enum, matched by migration 0185
apps/sim/lib/billing/core/usage-log.ts Adds 'knowledge-base' to UsageLogSource TypeScript union, keeping TS in sync with DB enum

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User clicks Export CSV] --> B[useExportTable.handleExportTable]
    B --> C{canExport && !isExporting?}
    C -- No --> Z[return]
    C -- Yes --> D[setIsExporting true]
    D --> E[fetchAllTableRows loop]
    E --> F[fetchTableRows offset=0]
    F --> G{rows.length < totalCount?}
    G -- Yes --> H[fetchTableRows offset+=rows]
    H --> G
    G -- No / rows empty --> I[buildTableCsv]
    I --> J[downloadFile .csv]
    J --> K[captureEvent table_exported]
    K --> L[setIsExporting false]

    subgraph Paste Auto-Column Creation
    M[handlePaste async] --> N[e.preventDefault sync]
    N --> O{neededExtraCols > 0?}
    O -- Yes --> P[addColumnAsyncRef x N sequential]
    P --> Q[optimistic local col list]
    Q --> R[batch update cells]
    O -- No --> R
    end

    subgraph Undo Stack
    S[delete column] --> T[push delete-column action]
    T --> U{undo?}
    U -- undo --> V[addColumnMutation]
    U -- redo --> W[deleteColumnMutation]
    end
Loading

Comments Outside Diff (1)

  1. apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/row-modal/row-modal.tsx, line 140-157 (link)

    P2 Bulk row deletion does not push undo entry

    When idsToDelete.length > 1 the mutation fires but no undo action is pushed to the store, so Ctrl+Z after a bulk delete from the row modal is a no-op. The single-row path correctly records { type: 'delete-rows', rows: [...] }. If the necessary row snapshots are available in the caller, it would be worth forwarding them to RowModal (e.g., via a rowSnapshots prop) so bulk deletions are also undoable.

Reviews (1): Last reviewed commit: "fix(tables): undo/redo gaps, escape regr..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 force-pushed the improvement/tables-module branch from be83302 to aef5b54 Compare April 5, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant