Skip to content

Commit d3b6878

Browse files
committed
refactor(chat): apply cleanup pass findings
emcn design: the table context menu built its Add-to-Chat label in the parent and never pluralized it, so right-clicking a single row read 'Add rows to Chat' directly above 'Delete row'. Derive it inside ContextMenu from selectedRowCount like every sibling label, with an addToChatCellScoped boolean mirroring workflowCellScoped. Also more correct: selectedRowCount accounts for a select-all beyond the loaded page, which contextMenuRowIds.length does not. callbacks: drop two useCallback wrappers whose identity nothing observes — both handleAddSelectionToChat handlers feed unmemoized components (one through an inline arrow). buildSelectionContext stays wrapped; it is a real dep of the copy-bridge effect. comments: fold a duplicated rationale paragraph in handleAddSelectionToChat left by two commits stacking, drop a {@link MothershipHandoff} that resolves to nothing (the type is not imported there), and trim a rowIds doc that restated its own type. Skipped, deliberately: the effects pass proposed moving buildContext out of useSelectionCopyBridge's deps behind a latest-ref. buildSelectionContext is already stable, so churn is near-zero, and it would leave two sibling useCallbacks purposeless.
1 parent d939aea commit d3b6878

6 files changed

Lines changed: 21 additions & 14 deletions

File tree

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/rich-markdown-editor/rich-markdown-editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,10 +1154,10 @@ export function LoadedRichMarkdownEditor({
11541154
}
11551155
}, [editor, file.id, file.name])
11561156

1157-
const handleAddSelectionToChat = useCallback(() => {
1157+
const handleAddSelectionToChat = () => {
11581158
const context = buildSelectionContext()
11591159
if (context) addToChat(context)
1160-
}, [addToChat, buildSelectionContext])
1160+
}
11611161

11621162
useSelectionCopyBridge(containerRef, buildSelectionContext)
11631163

apps/sim/app/workspace/[workspaceId]/files/components/file-viewer/text-editor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,10 @@ export const TextEditor = memo(function TextEditor({
402402
}
403403
}, [file.id, file.name])
404404

405-
const handleAddSelectionToChat = useCallback(() => {
405+
const handleAddSelectionToChat = () => {
406406
const context = buildSelectionContext()
407407
if (context) addToChat(context)
408-
}, [addToChat, buildSelectionContext])
408+
}
409409

410410
const {
411411
content,

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/context-menu/context-menu.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ interface ContextMenuProps {
5858
disableDelete?: boolean
5959
/** Adds the selected rows / cell range to Chat as a reference. Omit to hide. */
6060
onAddToChat?: () => void
61-
/** Label describing the current selection scope, e.g. "3 rows" or "cell range". */
62-
addToChatLabel?: string
61+
/**
62+
* True when the selection is a spreadsheet-style cell range rather than whole
63+
* rows, switching the label from row-scoped to cell-scoped. Mirrors
64+
* {@link ContextMenuProps.workflowCellScoped}.
65+
*/
66+
addToChatCellScoped?: boolean
6367
}
6468

6569
export function ContextMenu({
@@ -85,7 +89,7 @@ export function ContextMenu({
8589
disableDuplicate = false,
8690
disableDelete = false,
8791
onAddToChat,
88-
addToChatLabel = 'Add to Chat',
92+
addToChatCellScoped = false,
8993
}: ContextMenuProps) {
9094
const count = selectedRowCount.toLocaleString()
9195
const deleteLabel = selectedRowCount > 1 ? `Delete ${count} rows` : 'Delete row'
@@ -107,6 +111,11 @@ export function ContextMenu({
107111
runningInSelectionCount === 1
108112
? 'Stop running workflow'
109113
: `Stop ${runningInSelectionCount} running workflows`
114+
const addToChatLabel = addToChatCellScoped
115+
? 'Add cell range to Chat'
116+
: selectedRowCount > 1
117+
? `Add ${count} rows to Chat`
118+
: 'Add row to Chat'
110119

111120
return (
112121
<DropdownMenu

apps/sim/app/workspace/[workspaceId]/tables/[tableId]/components/table-grid/table-grid.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,10 +3864,8 @@ export function TableGrid({
38643864
// `contextMenuRowIds` reflects; drain up to the cap so the chip references as
38653865
// many rows as it can carry (bounded by MAX_TABLE_SELECTION_ROWS) instead of a
38663866
// silent loaded-only subset — mirroring how the copy path loads before writing.
3867-
// A gutter selection can extend past the loaded page, and `contextMenuRowIds`
3868-
// is the loaded intersection. The chip references ids the server re-fetches,
3869-
// so send the whole selection rather than whichever rows happen to be paged in.
38703867
const gutterSelection = rowSelectionRef.current
3868+
// Prefer the whole gutter selection over the loaded intersection.
38713869
let sourceRowIds =
38723870
gutterSelection.kind === 'some' &&
38733871
contextMenu.row &&
@@ -4631,7 +4629,7 @@ export function TableGrid({
46314629
disableDuplicate={!canInsertFullRow}
46324630
disableDelete={!canDeleteRow}
46334631
onAddToChat={contextMenuRowIds.length > 0 ? handleAddSelectionToChat : undefined}
4634-
addToChatLabel={contextMenuColumnIds ? 'Add cell range to Chat' : 'Add rows to Chat'}
4632+
addToChatCellScoped={Boolean(contextMenuColumnIds)}
46354633
/>
46364634

46374635
<ExpandedCellPopover

apps/sim/lib/mothership/events.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export interface MothershipAddContextDetail {
7575
* the same stale list and drop colliding chips.
7676
*
7777
* @returns `true` when a mounted input consumed it, `false` when none was
78-
* listening — callers fall back to persisting a chip-only
79-
* {@link MothershipHandoff} for the next chat mount.
78+
* listening — callers fall back to persisting a chip-only handoff (see
79+
* `MothershipHandoffStorage`) for the next chat mount.
8080
*/
8181
export function addMothershipContexts(contexts: ChatContext[]): boolean {
8282
if (contexts.length === 0) return false

apps/sim/stores/panel/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export type ChatContext =
3434
* rewrite to keep chip tokens unique.
3535
*/
3636
tableName: string
37-
/** Ids of the selected rows. Always present (materialized from the grid selection). */
37+
/** Materialized from the grid selection, including rows not yet paged in. */
3838
rowIds: string[]
3939
/**
4040
* Ids of the selected columns. Present only for a spreadsheet-style cell

0 commit comments

Comments
 (0)