From e0a138ffbd8442ac693d3fa970380b2db36a57bd Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Mon, 29 Jun 2026 15:16:33 -0700 Subject: [PATCH] Tweaks to bulp insert screen Moved text around, added clickable 'open a file' button for mobile. Screenshot: https://github.com/simonw/datasette/pull/2813#issuecomment-4837736664 --- datasette/static/app.css | 46 +++++++++++++++++--- datasette/static/edit-tools.js | 79 +++++++++++++++++++++++++--------- tests/test_playwright.py | 24 ++++++++++- 3 files changed, 120 insertions(+), 29 deletions(-) diff --git a/datasette/static/app.css b/datasette/static/app.css index 91379dee..b430e208 100644 --- a/datasette/static/app.css +++ b/datasette/static/app.css @@ -1819,15 +1819,12 @@ textarea.row-edit-input { display: none; } -.row-edit-bulk-label { - color: var(--ink); - font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; - font-size: 0.82rem; -} - .row-edit-bulk-actions { display: flex; - justify-content: flex-end; + align-items: center; + flex-wrap: wrap; + gap: 8px; + justify-content: flex-start; } .row-edit-bulk-actions .btn { @@ -1835,6 +1832,19 @@ textarea.row-edit-input { padding-right: 12px; } +.row-edit-copy-template-label-narrow { + display: none; +} + +.row-edit-bulk-template-note { + color: var(--muted); + font-size: 0.82rem; +} + +.row-edit-bulk-template-note-narrow { + display: none; +} + .row-edit-bulk-textarea { min-height: 16rem; resize: vertical; @@ -1855,6 +1865,28 @@ textarea.row-edit-input { margin: 0; } +.row-edit-bulk-note .button-as-link { + font: inherit; +} + +@media (max-width: 640px) { + .row-edit-copy-template-label-wide { + display: none; + } + + .row-edit-copy-template-label-narrow { + display: inline; + } + + .row-edit-bulk-template-note-wide { + display: none; + } + + .row-edit-bulk-template-note-narrow { + display: inline; + } +} + .row-edit-bulk-preview { display: grid; gap: 8px; diff --git a/datasette/static/edit-tools.js b/datasette/static/edit-tools.js index 12ddb842..0415d772 100644 --- a/datasette/static/edit-tools.js +++ b/datasette/static/edit-tools.js @@ -5474,6 +5474,22 @@ function readTextFile(file) { }); } +async function loadBulkInsertTextFile(state, file) { + if (!file) { + return; + } + try { + state.bulkInsertTextarea.value = await readTextFile(file); + state.bulkInsertTextarea.dispatchEvent( + new Event("input", { bubbles: true }), + ); + clearRowEditDialogError(state); + state.bulkInsertTextarea.focus(); + } catch (_error) { + showRowEditDialogError(state, "Could not read that text file."); + } +} + function bulkInsertTemplateText(state) { return (state.bulkInsertColumns || []).join("\t"); } @@ -5498,11 +5514,23 @@ async function copyTextToClipboard(text) { } } +function setBulkInsertCopyButtonReady(state) { + state.copyTemplateButton.textContent = ""; + var wideLabel = document.createElement("span"); + wideLabel.className = "row-edit-copy-template-label-wide"; + wideLabel.textContent = "Copy spreadsheet template"; + state.copyTemplateButton.appendChild(wideLabel); + var narrowLabel = document.createElement("span"); + narrowLabel.className = "row-edit-copy-template-label-narrow"; + narrowLabel.textContent = "Copy template"; + state.copyTemplateButton.appendChild(narrowLabel); +} + function setBulkInsertCopyButtonCopied(state) { state.copyTemplateButton.textContent = "Copied"; clearTimeout(state.copyTemplateResetTimer); state.copyTemplateResetTimer = setTimeout(function () { - state.copyTemplateButton.textContent = "Copy spreadsheet template"; + setBulkInsertCopyButtonReady(state); }, 1500); } @@ -6255,7 +6283,7 @@ function renderRowInsertFields(state, data) { return column.name; }); state.copyTemplateButton.disabled = !state.bulkInsertColumns.length; - state.copyTemplateButton.textContent = "Copy spreadsheet template"; + setBulkInsertCopyButtonReady(state); clearTimeout(state.copyTemplateResetTimer); state.copyTemplateResetTimer = null; resetBulkInsertPreview(state); @@ -6350,12 +6378,13 @@ function ensureRowEditDialog(manager) {