Skip to content

feat(DataTable): copy as text/html so paste into rich-text editors keeps the table - #274

Merged
tnrich merged 2 commits into
masterfrom
feat/datatable-copy-html-clipboard
May 22, 2026
Merged

tnrich merged 2 commits into
masterfrom
feat/datatable-copy-html-clipboard

Conversation

@aberguecio

Copy link
Copy Markdown
Contributor

Summary

  • DataTable copy currently writes only text/plain (TSV) and application/json to the clipboard. Pasting into rich-text editors (LIMS ELN, Google Docs, Notion, Word) flattens the data into raw lines instead of a table.
  • This change adds a text/html payload to the clipboard inside the existing onCopy callback in handleCopyHelper, built from the same TSV string the caller already produces.
  • All copy paths benefit transparently: handleCopyRows, handleCopyColumn, handleCopyTable, and the in-component handleCopySelectedCells.

Motivation

Tracked by TeselaGen/lims#13380 (board: USP). Repro: copy a few rows from a DataTable record view → paste into an ELN entry → only raw lines, no table.

Changes

  • packages/ui/src/DataTable/utils/handleCopyHelper.js — also call clipboardData.setData("text/html", tsvToHtmlTable(stringToCopy)). text/plain and application/json are unchanged.
  • packages/ui/src/DataTable/utils/tsvToHtmlTable.js — new helper that splits the TSV string by \n / \t, HTML-escapes & < > ", and wraps the cells in <table><tr><td>…</td></tr></table>.
  • packages/ui/src/DataTable/utils/tsvToHtmlTable.test.js — unit tests for single/multi row, HTML escaping, empty cells/rows, and null/undefined input.

Behavior matrix

Paste target Before After
Google Sheets / Excel columns split by \t (works) unchanged — text/plain TSV still wins
ELN / Google Docs / Notion raw lines real <table>
In-app DataTable (uses application/json) unchanged unchanged

Test plan

  • Bun unit tests: bun test packages/ui/src/DataTable/utils/ → 78 pass.
  • Full ui test suite: bun test packages/ui → 96 pass.
  • Lint: npx eslint on the three changed files → clean.
  • Manual: in the consumer apps (LIMS), copy from a DataTable and paste into rich-text editors / spreadsheets to confirm both formats behave as expected.

Notes

  • HTML structure intentionally minimal (<table><tr><td>) — no <thead>/<tbody>/<th> — to keep the helper format-agnostic. The TSV doesn't carry header semantics today; if needed, headers can be wired in later.
  • Cypress path is preserved: the !window.Cypress guard still short-circuits copy in test runs.

🤖 Generated with Claude Code

DataTable copy currently writes only text/plain (TSV) and
application/json. Pasting into rich-text editors (ELN, Google Docs,
Notion) flattens the data into raw lines instead of a table.

handleCopyHelper now also attaches an HTML <table> built from the same
TSV string via tsvToHtmlTable, so any clipboard consumer that prefers
text/html renders a real table. Spreadsheets keep splitting on tabs
because text/plain is unchanged, and the application/json payload used
for in-app paste is untouched.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented May 20, 2026

Copy link
Copy Markdown

🚀 PR Previews Deployed!

(Note: It might take a minute for GitHub Pages to update)

Release the text/html clipboard support added in this PR.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@tnrich tnrich left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nice

@tnrich
tnrich merged commit a72264c into master May 22, 2026
15 of 17 checks passed
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.

3 participants