Repository navigation
feat(data-grid): add copy/paste #1031
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
2c6a4ac
feat: add toast notifications for cell copy operations
sadmann7 7b176c1
fix: copy focused cell when no selection exists
sadmann7 5ed7773
feat: add Airtable-style paste expansion dialog
sadmann7 18cbff2
feat: add paste dialog types to data-grid.ts
sadmann7 7abce04
fix: correct onClick type for paste dialog cancel button
sadmann7 5b0623f
chore: lint
sadmann7 dfc2dcf
debug: add logging to diagnose paste expansion issue
sadmann7 d7361e8
debug: add more detailed paste loop logging
sadmann7 0cc2f8a
fix: use table row count instead of stale data.length after adding rows
sadmann7 d6b0a92
feat: implement working paste with row expansion
sadmann7 31738a0
feat: add enablePaste flag to control paste functionality
sadmann7 c833d51
refactor: use faker nanoid for row creation instead of incremental IDs
sadmann7 e98172c
fix: clear cell selections when creating a new row (Airtable behavior)
sadmann7 2a6aee6
refactor: add React.memo to DataGridPasteDialog and update registry
sadmann7 1071698
refactor: improve paste dialog copy and styling
sadmann7 d112faf
refactor: use refs and memoize callbacks in paste dialog
sadmann7 534c75d
chore: rebuild registry
sadmann7 66ee94f
feat: improve paste dialog styling with radio components
sadmann7 6f61fe0
feat: auto-select pasted cells and reorganize code
sadmann7 efb65c5
feat: add onRowsAdd for efficient bulk row creation
sadmann7 b3a7601
chore: rebuild registry again
sadmann7 f491c16
chore: rebuild registry again again again
sadmann7 3d970ff
fix: file cell copy and paste functionality
sadmann7 58f79f2
refactor: address code review feedback
sadmann7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,146 @@ | ||
| "use client"; | ||
|
|
||
| import type { Table, TableMeta } from "@tanstack/react-table"; | ||
| import * as React from "react"; | ||
| import { Button } from "@/components/ui/button"; | ||
| import { | ||
| Dialog, | ||
| DialogContent, | ||
| DialogDescription, | ||
| DialogFooter, | ||
| DialogHeader, | ||
| DialogTitle, | ||
| } from "@/components/ui/dialog"; | ||
| import { cn } from "@/lib/utils"; | ||
|
|
||
| interface DataGridPasteDialogProps<TData> { | ||
| table: Table<TData>; | ||
| } | ||
|
|
||
| export function DataGridPasteDialog<TData>({ | ||
| table, | ||
| }: DataGridPasteDialogProps<TData>) { | ||
| const meta = table.options.meta; | ||
| const pasteDialog = meta?.pasteDialog; | ||
| const onPasteDialogOpenChange = meta?.onPasteDialogOpenChange; | ||
| const onPasteWithExpansion = meta?.onPasteWithExpansion; | ||
| const onPasteWithoutExpansion = meta?.onPasteWithoutExpansion; | ||
|
|
||
| if (!pasteDialog) return null; | ||
|
|
||
| return ( | ||
| <PasteDialog | ||
| pasteDialog={pasteDialog} | ||
| onPasteDialogOpenChange={onPasteDialogOpenChange} | ||
| onPasteWithExpansion={onPasteWithExpansion} | ||
| onPasteWithoutExpansion={onPasteWithoutExpansion} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| interface PasteDialogProps | ||
| extends Pick< | ||
| TableMeta<unknown>, | ||
| | "onPasteDialogOpenChange" | ||
| | "onPasteWithExpansion" | ||
| | "onPasteWithoutExpansion" | ||
| >, | ||
| Required<Pick<TableMeta<unknown>, "pasteDialog">> {} | ||
|
|
||
| const PasteDialog = React.memo(PasteDialogImpl, (prev, next) => { | ||
| if (prev.pasteDialog.open !== next.pasteDialog.open) return false; | ||
| if (!next.pasteDialog.open) return true; | ||
| if (prev.pasteDialog.rowsNeeded !== next.pasteDialog.rowsNeeded) return false; | ||
|
|
||
| return true; | ||
| }); | ||
|
|
||
| function PasteDialogImpl({ | ||
| pasteDialog, | ||
| onPasteDialogOpenChange, | ||
| onPasteWithExpansion, | ||
| onPasteWithoutExpansion, | ||
| }: PasteDialogProps) { | ||
| const expandRadioRef = React.useRef<HTMLInputElement | null>(null); | ||
|
|
||
| const onCancel = React.useCallback(() => { | ||
| onPasteDialogOpenChange?.(false); | ||
| }, [onPasteDialogOpenChange]); | ||
|
|
||
| const onContinue = React.useCallback(() => { | ||
| if (expandRadioRef.current?.checked) { | ||
| onPasteWithExpansion?.(); | ||
| } else { | ||
| onPasteWithoutExpansion?.(); | ||
| } | ||
| }, [onPasteWithExpansion, onPasteWithoutExpansion]); | ||
|
|
||
| return ( | ||
| <Dialog open={pasteDialog.open} onOpenChange={onPasteDialogOpenChange}> | ||
| <DialogContent data-grid-popover=""> | ||
| <DialogHeader> | ||
| <DialogTitle>Do you want to add more rows?</DialogTitle> | ||
| <DialogDescription> | ||
| We need <strong>{pasteDialog.rowsNeeded}</strong> additional row | ||
| {pasteDialog.rowsNeeded !== 1 ? "s" : ""} to paste everything from | ||
| your clipboard. | ||
| </DialogDescription> | ||
| </DialogHeader> | ||
| <div className="flex flex-col gap-3 py-1"> | ||
| <label className="flex cursor-pointer items-start gap-3"> | ||
| <RadioItem | ||
| ref={expandRadioRef} | ||
| name="expand-option" | ||
| value="expand" | ||
| defaultChecked | ||
| /> | ||
| <div className="flex flex-col gap-1"> | ||
| <span className="font-medium text-sm leading-none"> | ||
| Create new rows | ||
| </span> | ||
| <span className="text-muted-foreground text-sm"> | ||
| Add {pasteDialog.rowsNeeded} new row | ||
| {pasteDialog.rowsNeeded !== 1 ? "s" : ""} to the table and paste | ||
| all data | ||
| </span> | ||
| </div> | ||
| </label> | ||
| <label className="flex cursor-pointer items-start gap-3"> | ||
| <RadioItem name="expand-option" value="no-expand" /> | ||
| <div className="flex flex-col gap-1"> | ||
| <span className="font-medium text-sm leading-none"> | ||
| Keep current rows | ||
| </span> | ||
| <span className="text-muted-foreground text-sm"> | ||
| Paste only what fits in the existing rows | ||
| </span> | ||
| </div> | ||
| </label> | ||
| </div> | ||
| <DialogFooter> | ||
| <Button variant="outline" onClick={onCancel}> | ||
| Cancel | ||
| </Button> | ||
| <Button onClick={onContinue}>Continue</Button> | ||
| </DialogFooter> | ||
| </DialogContent> | ||
| </Dialog> | ||
| ); | ||
| } | ||
|
|
||
| function RadioItem({ className, ...props }: React.ComponentProps<"input">) { | ||
| return ( | ||
| <input | ||
| type="radio" | ||
| className={cn( | ||
| "relative size-4 shrink-0 appearance-none rounded-full border border-input bg-background shadow-xs outline-none transition-[color,box-shadow]", | ||
| "text-primary focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50", | ||
| "disabled:cursor-not-allowed disabled:opacity-50", | ||
| "checked:before:-translate-x-1/2 checked:before:-translate-y-1/2 checked:before:absolute checked:before:top-1/2 checked:before:left-1/2 checked:before:size-2 checked:before:rounded-full checked:before:bg-primary checked:before:content-['']", | ||
| "dark:bg-input/30", | ||
| className, | ||
| )} | ||
| {...props} | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.