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

@@ -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',