Skip to content

Commit b97e695

Browse files
jimmymeister98kaan9700dglalperen
authored
feat: add saveAsMarkdown (#144)
resolves #126 Co-authored-by: kaan9700 <81586446+kaan9700@users.noreply.github.com> Co-authored-by: Alperen Dagli <80391142+dglalperen@users.noreply.github.com>
1 parent 2c74414 commit b97e695

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

release/app/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/screens/DatabaseScreen/QueryResultViewer/useDataTableContextMenu.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ export default function useDataTableContextMenu({
7171
);
7272
}
7373

74+
function onCopyAsMarkdown() {
75+
const selectedRows = selectedRowsIndex.map((rowIndex) => data[rowIndex].data);
76+
const displayableRows = getDisplayableFromDatabaseRows(selectedRows, headers);
77+
const headerNames = headers.map((header) => header.name);
78+
const markdownString = [headerNames.join(' | ')];
79+
markdownString.push(new Array(headerNames.length).fill('---').join(' | '));
80+
markdownString.push(
81+
...displayableRows.map((row) => headerNames.map((header) => row[header]).join(' | '))
82+
);
83+
84+
window.navigator.clipboard.writeText(markdownString.join('\n'));
85+
}
86+
7487
const lastSelectedRow =
7588
selectedRowsIndex.length > 0
7689
? data[selectedRowsIndex[selectedRowsIndex.length - 1]]
@@ -90,6 +103,7 @@ export default function useDataTableContextMenu({
90103
{ text: 'As Excel', onClick: onCopyAsExcel },
91104
{ text: 'As CSV', disabled: true },
92105
{ text: 'As JSON', onClick: onCopyAsJson },
106+
{ text: 'As Markdown', onClick: onCopyAsMarkdown },
93107
{ text: 'As SQL', disabled: true },
94108
],
95109
},

0 commit comments

Comments
 (0)