Skip to content

Commit

Permalink
fix: use view check in events
Browse files Browse the repository at this point in the history
Signed-off-by: Cleopatra Enjeck M <patrathewhiz@gmail.com>
  • Loading branch information
enjeck committed Feb 13, 2024
1 parent decb108 commit 2ce0601
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 39 deletions.
3 changes: 2 additions & 1 deletion src/modules/main/partials/TableView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
<NcTable v-if="columns.length > 0"
:rows="rows"
:columns="columns"
:table-id="element.id"
:element-id="element.id"
:is-view="isView"
:download-title="element.title"
:view-setting.sync="localViewSetting"
:can-read-rows="canReadRows"
Expand Down
1 change: 0 additions & 1 deletion src/modules/main/sections/MainWrapper.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
@toggle-share="toggleShare"
@show-integration="showIntegration" />
<CustomTable v-else
:table-id="element.id"
:table="element"
:columns="columns"
:rows="rows"
Expand Down
2 changes: 1 addition & 1 deletion src/modules/modals/DeleteRows.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default {
if (error) {
showError(t('tables', 'Error occurred while deleting rows.'))
}
emit('tables:selected-rows:deselect', this.rowsToDelete.elementId)
emit('tables:selected-rows:deselect', { elementId: this.rowsToDelete.elementId, isView: this.rowsToDelete.isView })
this.$emit('cancel')
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/modules/modals/EditRow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default {
default: false,
},
element: {
type: Number,
type: Object,
default: null,
},
},
Expand All @@ -92,7 +92,7 @@ export default {
},
computed: {
showDeleteButton() {
return this.canDeleteData(this.element.id) && !this.localLoading
return this.canDeleteData(this.element) && !this.localLoading
},
nonMetaColumns() {
return this.columns.filter(col => col.id >= 0)
Expand Down
49 changes: 22 additions & 27 deletions src/shared/components/ncTable/NcTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,21 @@ deselect-all-rows -> unselect all rows, e.g. after deleting selected rows
<template>
<div class="NcTable">
<div class="options row" style="padding-right: calc(var(--default-grid-baseline) * 2);">
<Options :rows="rows"
:columns="parsedColumns"
:table-id="tableId"
:selected-rows="localSelectedRows"
:show-options="parsedColumns.length !== 0"
:view-setting.sync="localViewSetting"
:config="config"
@create-row="$emit('create-row', tableId)"
<Options :rows="rows" :columns="parsedColumns" :element-id="elementId" :is-view="isView"
:selected-rows="localSelectedRows" :show-options="parsedColumns.length !== 0"
:view-setting.sync="localViewSetting" :config="config" @create-row="$emit('create-row', elementId, isView)"
@download-csv="data => downloadCsv(data, parsedColumns, downloadTitle)"
@set-search-string="str => setSearchString(str)"
@delete-selected-rows="rowIds => $emit('delete-selected-rows', rowIds, tableId)" />
@delete-selected-rows="rowIds => $emit('delete-selected-rows', rowIds, elementId, isView)" />
</div>
<div class="custom-table row">
<CustomTable v-if="config.canReadRows || (config.canCreateRows && rows.length > 0)"
:columns="parsedColumns"
:rows="rows"
:table-id="tableId"
:view-setting.sync="localViewSetting"
:config="config"
@create-row="$emit('create-row', tableId)"
@edit-row="rowId => $emit('edit-row', rowId, tableId)"
@create-column="$emit('create-column', tableId)"
@edit-column="col => $emit('edit-column', col, tableId)"
@delete-column="col => $emit('delete-column', col, tableId)"
<CustomTable v-if="config.canReadRows || (config.canCreateRows && rows.length > 0)" :columns="parsedColumns"
:rows="rows" :is-view="isView" :element-id="elementId" :view-setting.sync="localViewSetting"
:config="config" @create-row="$emit('create-row', elementId, isView)"
@edit-row="rowId => $emit('edit-row', rowId, elementId, isView)"
@create-column="$emit('create-column', elementId, isView)"
@edit-column="col => $emit('edit-column', col, elementId, isView)"
@delete-column="col => $emit('delete-column', col, elementId, isView)"
@update-selected-rows="rowIds => localSelectedRows = rowIds"
@download-csv="data => downloadCsv(data, parsedColumns, table)">
<template #actions>
Expand All @@ -76,7 +67,8 @@ deselect-all-rows -> unselect all rows, e.g. after deleting selected rows
<Plus :size="25" />
</template>
<template #action>
<NcButton :aria-label="t('tables', 'Create row')" type="primary" @click="$emit('create-row', tableId)">
<NcButton :aria-label="t('tables', 'Create row')" type="primary"
@click="$emit('create-row', elementId, isView)">
<template #icon>
<Plus :size="25" />
</template>
Expand Down Expand Up @@ -124,10 +116,14 @@ export default {
type: Array,
default: () => [],
},
tableId: {
elementId: {
type: Number,
default: null,
},
isView: {
type: Boolean,
default: true,
},
downloadTitle: {
type: String,
default: t('tables', 'Download'),
Expand Down Expand Up @@ -231,15 +227,15 @@ export default {
},
},
mounted() {
subscribe('tables:selected-rows:deselect', tableId => this.deselectRows(tableId))
subscribe('tables:selected-rows:deselect', ({ elementId, isView }) => this.deselectRows(elementId, isView))
},
beforeDestroy() {
unsubscribe('tables:selected-rows:deselect', tableId => this.deselectRows(tableId))
unsubscribe('tables:selected-rows:deselect', ({ elementId, isView }) => this.deselectRows(elementId, isView))
},
methods: {
t,
deselectRows(tableId) {
if (parseInt(tableId) === parseInt(this.tableId)) {
deselectRows(elementId, isView) {
if (parseInt(elementId) === parseInt(this.elementId) && isView === this.isView) {
this.localSelectedRows = []
}
},
Expand All @@ -252,7 +248,6 @@ export default {
</script>

<style scoped lang="scss">

.options.row {
position: sticky;
top: 52px;
Expand Down
14 changes: 9 additions & 5 deletions src/shared/components/ncTable/sections/CustomTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,14 @@ export default {
type: Array,
default: () => [],
},
tableId: {
elementId: {
type: Number,
default: null,
},
isView: {
type: Boolean,
default: true,
},
viewSetting: {
type: Object,
default: null,
Expand Down Expand Up @@ -220,10 +224,10 @@ export default {
},
mounted() {
subscribe('tables:selected-rows:deselect', tableId => this.deselectAllRows(tableId))
subscribe('tables:selected-rows:deselect', ({ elementId, isView }) => this.deselectAllRows(elementId, isView))
},
beforeDestroy() {
unsubscribe('tables:selected-rows:deselect', tableId => this.deselectAllRows(tableId))
unsubscribe('tables:selected-rows:deselect', ({ elementId, isView }) => this.deselectAllRows(elementId, isView))
},
methods: {
Expand All @@ -244,8 +248,8 @@ export default {
}
return null
},
deselectAllRows(tableId) {
if (parseInt(tableId) === parseInt(this.tableId)) {
deselectAllRows(elementId, isView) {
if (parseInt(elementId) === parseInt(this.elementId) && isView === this.isView) {
this.selectedRows = []
}
},
Expand Down
8 changes: 6 additions & 2 deletions src/shared/components/ncTable/sections/Options.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,14 @@ export default {
type: Array,
default: () => [],
},
tableId: {
elementId: {
type: Number,
default: null,
},
isView: {
type: Boolean,
default: true,
},
showOptions: {
type: Boolean,
default: true,
Expand Down Expand Up @@ -164,7 +168,7 @@ export default {
this.$emit('delete-selected-rows', this.selectedRows)
},
deselectAllRows() {
emit('tables:selected-rows:deselect', this.tableId)
emit('tables:selected-rows:deselect', { elementId: this.elementId, isView: this.isView })
},
},
}
Expand Down

0 comments on commit 2ce0601

Please sign in to comment.