Skip to content

Commit

Permalink
feat: copy row as CSV, closes #394
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Jul 29, 2022
1 parent 664d18e commit 1c3d7aa
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/renderer/components/WorkspaceTabQueryTable.vue
Expand Up @@ -449,6 +449,18 @@ const copyRow = (format: string) => {
}
navigator.clipboard.writeText(sqlInserts.join('\n'));
}
else if (format === 'csv') {
const csv = [];
if (!Array.isArray(contentToCopy)) contentToCopy = [contentToCopy];
if (contentToCopy.length)
csv.push(Object.keys(contentToCopy[0]).join(';'));
for (const row of contentToCopy)
csv.push(Object.values(row).map(col => typeof col === 'string' ? `"${col}"` : col).join(';'));
navigator.clipboard.writeText(csv.join('\n'));
}
};
const duplicateRow = () => {
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/components/WorkspaceTabQueryTableContext.vue
Expand Up @@ -21,6 +21,11 @@
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', selectedRows.length) }} (JSON)
</span>
</div>
<div class="context-element" @click="copyRow('csv')">
<span class="d-flex">
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', selectedRows.length) }} (CSV)
</span>
</div>
<div class="context-element" @click="copyRow('sql')">
<span class="d-flex">
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', selectedRows.length) }} (SQL INSERT)
Expand Down

0 comments on commit 1c3d7aa

Please sign in to comment.