Skip to content

[stable0.9] feat: remove rows in view after edit when they no longer match filter #2017

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
['name' => 'row#updateSet', 'url' => '/row/{id}', 'verb' => 'PUT'],
['name' => 'row#destroyByView', 'url' => '/view/{viewId}/row/{id}', 'verb' => 'DELETE'],
['name' => 'row#destroy', 'url' => '/row/{id}', 'verb' => 'DELETE'],
['name' => 'row#presentInView', 'url' => '/view/{viewId}/row/{id}/present', 'verb' => 'GET'],

// shares
['name' => 'share#index', 'url' => '/share/table/{tableId}', 'verb' => 'GET'],
Expand Down
8 changes: 8 additions & 0 deletions lib/Controller/RowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,12 @@ public function destroyByView(int $id, int $viewId): DataResponse {
return $this->service->delete($id, $viewId, $this->userId);
});
}

#[NoAdminRequired]
public function presentInView(int $id, int $viewId): DataResponse {
return $this->handleError(function () use ($id, $viewId) {
$present = $this->service->isRowInViewPresent($id, $viewId, $this->userId);
return ['present' => $present];
});
}
}
19 changes: 19 additions & 0 deletions lib/Service/RowService.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,25 @@ public function getViewRowsCount(View $view, string $userId): int {
}
}

/**
* @param int $rowId
* @param int $viewId
* @param string $userId
* @return bool
*
* @throws PermissionError
*/
public function isRowInViewPresent(int $rowId, int $viewId, string $userId): bool {
if (!$this->permissionsService->canReadRowsByElementId($viewId, 'view', $userId)) {
$e = new \Exception('Row not found.');
$this->logger->error($e->getMessage(), ['exception' => $e]);
throw new PermissionError(get_class($this) . ' - ' . __FUNCTION__ . ': ' . $e->getMessage());
}

$view = $this->viewMapper->find($viewId);
return $this->row2Mapper->isRowInViewPresent($rowId, $view, $userId);
}

private function filterRowResult(?View $view, Row2 $row): Row2 {
if ($view === null) {
return $row;
Expand Down
36 changes: 31 additions & 5 deletions src/shared/components/ncTable/sections/CustomTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
</template>
</TableHeader>
</thead>
<tbody>
<TableRow v-for="(row, index) in currentPageRows"
:key="index"
<transition-group
name="table-row"
tag="tbody"
:css="rowAnimation"
@after-leave="disableRowAnimation">
<TableRow v-for="row in currentPageRows"
:key="row.id"
data-cy="customTableRow"
:row="row"
:columns="columns"
Expand All @@ -33,8 +37,7 @@
:config="config"
@update-row-selection="updateRowSelection"
@edit-row="rowId => $emit('edit-row', rowId)" />
<tr />
</tbody>
</transition-group>
</table>
<div v-if="totalPages > 1" class="pagination-footer" :class="{'large-width': !appNavCollapsed || isMobile}">
<div class="pagination-items">
Expand Down Expand Up @@ -144,6 +147,7 @@ export default {
localViewSetting: this.viewSetting,
pageNumber: 1,
rowsPerPage: 100,
rowAnimation: false,
}
},

Expand Down Expand Up @@ -328,9 +332,11 @@ export default {

mounted() {
subscribe('tables:selected-rows:deselect', ({ elementId, isView }) => this.deselectAllRows(elementId, isView))
subscribe('tables:row:animate', this.enableRowAnimation)
},
beforeDestroy() {
unsubscribe('tables:selected-rows:deselect', ({ elementId, isView }) => this.deselectAllRows(elementId, isView))
unsubscribe('tables:row:animate', this.enableRowAnimation)
},

methods: {
Expand Down Expand Up @@ -383,6 +389,12 @@ export default {
this.$emit('update-selected-rows', this.selectedRows)
}
},
enableRowAnimation() {
this.rowAnimation = true
},
disableRowAnimation() {
this.rowAnimation = false
},
},
}
</script>
Expand Down Expand Up @@ -572,4 +584,18 @@ export default {

}

.table-row-leave-active {
transition: all 600ms ease;
}

.table-row-leave-to {
opacity: 0;
height: 0 !important;
padding-top: 0 !important;
padding-bottom: 0 !important;
margin-top: 0 !important;
margin-bottom: 0 !important;
transform: translateX(-1rem);
}

</style>
28 changes: 28 additions & 0 deletions src/store/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { parseCol } from '../shared/components/ncTable/mixins/columnParser.js'
import { MetaColumns } from '../shared/components/ncTable/mixins/metaColumns.js'
import { showError } from '@nextcloud/dialogs'
import { set } from 'vue'
import { emit } from '@nextcloud/event-bus'

function genStateKey(isView, elementId) {
elementId = elementId.toString()
Expand Down Expand Up @@ -202,7 +203,9 @@ export const useDataStore = defineStore('data', {
const row = res.data
const index = this.rows[stateId].findIndex(r => r.id === row.id)
set(this.rows[stateId], index, row)
await this.removeRowIfNotInView({ rowId: row?.id, viewId, stateId })
}

return true
},

Expand All @@ -223,7 +226,9 @@ export const useDataStore = defineStore('data', {
const row = res?.data?.ocs?.data
const newIndex = this.rows[stateId].length
set(this.rows[stateId], newIndex, row)
await this.removeRowIfNotInView({ rowId: row?.id, viewId, stateId })
}

return true
},

Expand Down Expand Up @@ -252,5 +257,28 @@ export const useDataStore = defineStore('data', {
}
return true
},

async checkRowInView({ rowId, viewId }) {
try {
const res = await axios.get(generateUrl('/apps/tables/view/{viewId}/row/{rowId}/present', { viewId, rowId }))
return res.data.present
} catch (e) {
showError(t('tables', 'Could not verify row. View is reloaded'))
await this.loadRowsFromBE({ viewId })
}
},

async removeRowIfNotInView({ rowId, viewId, stateId }) {
if (!rowId || !viewId) {
return
}

const rowInView = await this.checkRowInView({ rowId, viewId })
if (rowInView === false) {
emit('tables:row:animate')
this.rows[stateId] = this.rows[stateId].filter(r => r.id !== rowId)
}
},
},

})
Loading