Skip to content

Commit

Permalink
feat: context menu shortcut to set NULL a table cell
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabio286 committed Feb 28, 2021
1 parent 201fad9 commit 71b4310
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/main/ipc-handlers/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ export default (connections) => {
escapedParam = `b'${sqlEscaper(params.content)}'`;
reload = true;
}
else if (params.content === null)
escapedParam = 'NULL';
else
escapedParam = `"${sqlEscaper(params.content)}"`;

Expand Down
16 changes: 16 additions & 0 deletions src/renderer/components/WorkspaceQueryTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
:context-event="contextEvent"
:selected-rows="selectedRows"
@delete-selected="deleteSelected"
@set-null="setNull"
@close-context="isContext = false"
/>
<ul v-if="resultsWithRows.length > 1" class="tab tab-block result-tabs">
Expand Down Expand Up @@ -315,6 +316,21 @@ export default {
};
this.$emit('delete-selected', params);
},
setNull () {
const row = this.localResults.find(row => this.selectedRows.includes(row._id));
delete row._id;
const params = {
primary: this.primaryField.name,
schema: this.getSchema(this.resultsetIndex),
table: this.getTable(this.resultsetIndex),
id: this.getPrimaryValue(row),
row,
field: this.selectedCell.field,
content: null
};
this.$emit('update-field', params);
},
applyUpdate (params) {
const { primary, id, field, table, content } = params;
Expand Down
17 changes: 16 additions & 1 deletion src/renderer/components/WorkspaceQueryTableContext.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@
:context-event="contextEvent"
@close-context="closeContext"
>
<div
v-if="selectedRows.length === 1"
class="context-element"
@click="setNull"
>
<span class="d-flex">
<i class="mdi mdi-18px mdi-null text-light pr-1" /> {{ $t('message.setNull') }}
</span>
</div>
<div class="context-element" @click="showConfirmModal">
<span class="d-flex"><i class="mdi mdi-18px mdi-delete text-light pr-1" /> {{ $tc('message.deleteRows', selectedRows.length) }}</span>
<span class="d-flex">
<i class="mdi mdi-18px mdi-delete text-light pr-1" /> {{ $tc('message.deleteRows', selectedRows.length) }}
</span>
</div>

<ConfirmModal
Expand Down Expand Up @@ -60,6 +71,10 @@ export default {
deleteRows () {
this.$emit('delete-selected');
this.closeContext();
},
setNull () {
this.$emit('set-null');
this.closeContext();
}
}
};
Expand Down
15 changes: 9 additions & 6 deletions src/renderer/components/WorkspaceQueryTableRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:key="cKey"
class="td p-0"
tabindex="0"
@contextmenu.prevent="$emit('contextmenu', $event, {id: row._id, field: cKey})"
@contextmenu.prevent="openContext($event, { id: row._id, field: cKey })"
>
<template v-if="cKey !== '_id'">
<span
Expand Down Expand Up @@ -300,8 +300,8 @@ export default {
isEditable () {
if (this.fields) {
const nElements = Object.keys(this.fields).reduce((acc, curr) => {
acc.add(curr.table);
acc.add(curr.schema);
acc.add(this.fields[curr].table);
acc.add(this.fields[curr].schema);
return acc;
}, new Set([]));
Expand Down Expand Up @@ -441,9 +441,6 @@ export default {
};
this.willBeDeleted = true;
},
contextMenu (event, cell) {
this.$emit('update-field', event, cell);
},
selectRow (event, row) {
this.$emit('select-row', event, row);
},
Expand All @@ -452,6 +449,12 @@ export default {
return this.keyUsage.find(key => key.field === keyName.split('.').pop());
return this.keyUsage.find(key => key.field === keyName);
},
openContext (event, payload) {
if (this.isEditable) {
payload.field = this.fields[payload.field].name;// Ensures field name only
this.$emit('contextmenu', event, payload);
}
},
onKey (e) {
e.stopPropagation();
if (e.key === 'Escape') {
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/i18n/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ module.exports = {
searchForElements: 'Search for elements',
selectAll: 'Select all',
queryDuration: 'Query duration',
includeBetaUpdates: 'Include beta updates'
includeBetaUpdates: 'Include beta updates',
setNull: 'Set NULL'
},
faker: {
address: 'Address',
Expand Down

0 comments on commit 71b4310

Please sign in to comment.