Skip to content

Commit

Permalink
feat: ability to copy multiple selected rows
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Jul 25, 2022
1 parent 1ead76c commit 9551afb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
43 changes: 31 additions & 12 deletions src/renderer/components/WorkspaceTabQueryTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ import { useI18n } from 'vue-i18n';
import { TableField, QueryResult } from 'common/interfaces/antares';
import { TableUpdateParams } from 'common/interfaces/tableApis';
import { jsonToSqlInsert } from 'common/libs/sqlUtils';
import { unproxify } from '@/libs/unproxify';
const { t } = useI18n();
Expand Down Expand Up @@ -415,20 +416,38 @@ const copyCell = () => {
};
const copyRow = (format: string) => {
const row = localResults.value.find((row: any) => selectedRows.value.includes(row._antares_id));
const rowToCopy = JSON.parse(JSON.stringify(row));
delete rowToCopy._antares_id;
let contentToCopy;
if (selectedRows.value.length === 1) {
const row = localResults.value.find((row: any) => selectedRows.value.includes(row._antares_id));
const rowToCopy = unproxify(row);
delete rowToCopy._antares_id;
contentToCopy = rowToCopy;
}
else {
contentToCopy = unproxify(localResults.value).filter((row: any) => selectedRows.value.includes(row._antares_id)).map((row: any) => {
delete row._antares_id;
return row;
});
}
if (format === 'json')
navigator.clipboard.writeText(JSON.stringify(rowToCopy));
navigator.clipboard.writeText(JSON.stringify(contentToCopy));
else if (format === 'sql') {
navigator.clipboard.writeText(jsonToSqlInsert({
json: rowToCopy,
client: workspaceClient.value,
fields: fieldsObj.value as {
[key: string]: {type: string; datePrecision: number};
},
table: getTable(resultsetIndex.value)
}));
const sqlInserts = [];
if (!Array.isArray(contentToCopy)) contentToCopy = [contentToCopy];
for (const row of contentToCopy) {
sqlInserts.push(jsonToSqlInsert({
json: row,
client: workspaceClient.value,
fields: fieldsObj.value as {
[key: string]: {type: string; datePrecision: number};
},
table: getTable(resultsetIndex.value)
}));
}
navigator.clipboard.writeText(sqlInserts.join('\n'));
}
};
Expand Down
18 changes: 5 additions & 13 deletions src/renderer/components/WorkspaceTabQueryTableContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
:context-event="contextEvent"
@close-context="closeContext"
>
<div v-if="selectedRows.length === 1" class="context-element">
<div class="context-element">
<span class="d-flex"><i class="mdi mdi-18px mdi-content-copy text-light pr-1" /> {{ t('word.copy') }}</span>
<i class="mdi mdi-18px mdi-chevron-right text-light pl-1" />
<div class="context-submenu">
Expand All @@ -16,22 +16,14 @@
<i class="mdi mdi-18px mdi-numeric-0 mdi-rotate-90 text-light pr-1" /> {{ t('word.cell', 1) }}
</span>
</div>
<div
v-if="selectedRows.length === 1"
class="context-element"
@click="copyRow('json')"
>
<div class="context-element" @click="copyRow('json')">
<span class="d-flex">
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', 1) }} (JSON)
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', selectedRows.length) }} (JSON)
</span>
</div>
<div
v-if="selectedRows.length === 1"
class="context-element"
@click="copyRow('sql')"
>
<div class="context-element" @click="copyRow('sql')">
<span class="d-flex">
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', 1) }} (SQL INSERT)
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', selectedRows.length) }} (SQL INSERT)
</span>
</div>
</div>
Expand Down

0 comments on commit 9551afb

Please sign in to comment.