Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sqllab): add headers when copying results to clipboard #23720

Merged
merged 4 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion superset-frontend/src/utils/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function optionFromValue(opt) {
}

export function prepareCopyToClipboardTabularData(data, columns) {
let result = '';
let result = `${columns.map(column => column.name || column).join('\t')}\n`;
for (let i = 0; i < data.length; i += 1) {
const row = {};
for (let j = 0; j < columns.length; j += 1) {
Expand Down
24 changes: 12 additions & 12 deletions superset-frontend/src/utils/common.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,28 +50,28 @@ describe('utils/common', () => {
});
describe('prepareCopyToClipboardTabularData', () => {
it('converts empty array', () => {
const array = [];
const column = [];
expect(prepareCopyToClipboardTabularData(array, column)).toEqual('');
const data = [];
const columns = [];
expect(prepareCopyToClipboardTabularData(data, columns)).toEqual('\n');
});
it('converts non empty array', () => {
const array = [
const data = [
{ column1: 'lorem', column2: 'ipsum' },
{ column1: 'dolor', column2: 'sit', column3: 'amet' },
];
const column = ['column1', 'column2', 'column3'];
expect(prepareCopyToClipboardTabularData(array, column)).toEqual(
'lorem\tipsum\t\ndolor\tsit\tamet\n',
const columns = ['column1', 'column2', 'column3'];
expect(prepareCopyToClipboardTabularData(data, columns)).toEqual(
'column1\tcolumn2\tcolumn3\nlorem\tipsum\t\ndolor\tsit\tamet\n',
);
});
it('includes 0 values', () => {
const array = [
it('includes 0 values and handle column objects', () => {
const data = [
{ column1: 0, column2: 0 },
{ column1: 1, column2: -1, 0: 0 },
];
const column = ['column1', 'column2', '0'];
expect(prepareCopyToClipboardTabularData(array, column)).toEqual(
'0\t0\t\n1\t-1\t0\n',
const columns = [{ name: 'column1' }, { name: 'column2' }, { name: '0' }];
expect(prepareCopyToClipboardTabularData(data, columns)).toEqual(
'column1\tcolumn2\t0\n0\t0\t\n1\t-1\t0\n',
);
});
});
Expand Down