diff --git a/packages/web/package.json b/packages/web/package.json index 07378ab5e..e391b5b3f 100644 --- a/packages/web/package.json +++ b/packages/web/package.json @@ -53,6 +53,7 @@ "dependencies": { "chartjs-adapter-moment": "^1.0.0", "diff": "^5.0.0", - "diff2html": "^3.4.13" + "diff2html": "^3.4.13", + "js-yaml": "^4.1.0" } } diff --git a/packages/web/src/utility/clipboard.ts b/packages/web/src/utility/clipboard.ts index 00a219d82..7a39e7bd6 100644 --- a/packages/web/src/utility/clipboard.ts +++ b/packages/web/src/utility/clipboard.ts @@ -1,5 +1,6 @@ import _ from 'lodash'; import { arrayToHexString } from 'dbgate-tools'; +import yaml from 'js-yaml'; export function copyTextToClipboard(text) { const oldFocus = document.activeElement; @@ -96,6 +97,10 @@ const clipboardJsonFormatter = () => (columns, rows) => { ); }; +const clipboardYamlFormatter = () => (columns, rows) => { + return yaml.dump(rows.map(row => _.pick(row, columns))); +}; + const clipboardJsonLinesFormatter = () => (columns, rows) => { return rows.map(row => JSON.stringify(_.pick(row, columns))).join('\r\n'); }; @@ -165,6 +170,11 @@ export const copyRowsFormatDefs = { name: 'JSON lines', formatter: clipboardJsonLinesFormatter(), }, + yaml: { + label: 'Copy as YAML', + name: 'YAML', + formatter: clipboardYamlFormatter(), + }, inserts: { label: 'Copy as SQL INSERTs', name: 'SQL INSERTs',