copy as yaml

This commit is contained in:
Jan Prochazka
2021-11-21 08:48:02 +01:00
parent 83f25937da
commit 30e3295d3e
2 changed files with 12 additions and 1 deletions

View File

@@ -53,6 +53,7 @@
"dependencies": { "dependencies": {
"chartjs-adapter-moment": "^1.0.0", "chartjs-adapter-moment": "^1.0.0",
"diff": "^5.0.0", "diff": "^5.0.0",
"diff2html": "^3.4.13" "diff2html": "^3.4.13",
"js-yaml": "^4.1.0"
} }
} }

View File

@@ -1,5 +1,6 @@
import _ from 'lodash'; import _ from 'lodash';
import { arrayToHexString } from 'dbgate-tools'; import { arrayToHexString } from 'dbgate-tools';
import yaml from 'js-yaml';
export function copyTextToClipboard(text) { export function copyTextToClipboard(text) {
const oldFocus = document.activeElement; 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) => { const clipboardJsonLinesFormatter = () => (columns, rows) => {
return rows.map(row => JSON.stringify(_.pick(row, columns))).join('\r\n'); return rows.map(row => JSON.stringify(_.pick(row, columns))).join('\r\n');
}; };
@@ -165,6 +170,11 @@ export const copyRowsFormatDefs = {
name: 'JSON lines', name: 'JSON lines',
formatter: clipboardJsonLinesFormatter(), formatter: clipboardJsonLinesFormatter(),
}, },
yaml: {
label: 'Copy as YAML',
name: 'YAML',
formatter: clipboardYamlFormatter(),
},
inserts: { inserts: {
label: 'Copy as SQL INSERTs', label: 'Copy as SQL INSERTs',
name: 'SQL INSERTs', name: 'SQL INSERTs',