feat: copy row as SQL INSERT

This commit is contained in:
Fabio Di Stasio 2022-07-25 12:42:22 +02:00
parent f3b5de38c4
commit d3da15aa13
3 changed files with 28 additions and 7 deletions

View File

@ -315,7 +315,7 @@ const downloadTable = (format: 'csv' | 'json') => {
exportRows({
type: format,
content: sortedResults.value,
filename: 'processes'
table: 'processes'
});
};

View File

@ -131,6 +131,7 @@ import * as moment from 'moment';
import { useI18n } from 'vue-i18n';
import { TableField, QueryResult } from 'common/interfaces/antares';
import { TableUpdateParams } from 'common/interfaces/tableApis';
import { jsonToSqlInsert } from 'common/libs/sqlUtils';
const { t } = useI18n();
@ -413,11 +414,22 @@ const copyCell = () => {
navigator.clipboard.writeText(valueToCopy);
};
const copyRow = () => {
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;
navigator.clipboard.writeText(JSON.stringify(rowToCopy));
if (format === 'json')
navigator.clipboard.writeText(JSON.stringify(rowToCopy));
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 duplicateRow = () => {

View File

@ -19,10 +19,19 @@
<div
v-if="selectedRows.length === 1"
class="context-element"
@click="copyRow"
@click="copyRow('json')"
>
<span class="d-flex">
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', 1) }}
<i class="mdi mdi-18px mdi-table-row text-light pr-1" /> {{ t('word.row', 1) }} (JSON)
</span>
</div>
<div
v-if="selectedRows.length === 1"
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)
</span>
</div>
</div>
@ -98,8 +107,8 @@ const copyCell = () => {
closeContext();
};
const copyRow = () => {
emit('copy-row');
const copyRow = (format: string) => {
emit('copy-row', format);
closeContext();
};