Browse Source

fix(gui-v2): reload rows count on row insert/delete

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3039/head
Pranav C 2 years ago
parent
commit
47ccda1614
  1. 11
      packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue
  2. 15
      packages/nc-gui-v2/composables/useViewData.ts

11
packages/nc-gui-v2/components/smartsheet-toolbar/ColumnFilterMenu.vue

@ -1,4 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import { watchEffect } from '@vue/runtime-core'
import type ColumnFilter from './ColumnFilter.vue' import type ColumnFilter from './ColumnFilter.vue'
import { useState } from '#app' import { useState } from '#app'
import { ActiveViewInj, IsLockedInj } from '~/context' import { ActiveViewInj, IsLockedInj } from '~/context'
@ -17,8 +18,14 @@ const { filters, loadFilters } = useViewFilters(
undefined, undefined,
computed(() => false), computed(() => false),
) )
await loadFilters()
const filtersLength = ref(filters?.value?.length ?? 0) const filtersLength = ref(0)
watchEffect(async () => {
if (activeView?.value) {
await loadFilters()
filtersLength.value = filters?.value?.length ?? 0
}
})
const filterComp = ref<typeof ColumnFilter>() const filterComp = ref<typeof ColumnFilter>()
const applyChanges = async () => { const applyChanges = async () => {

15
packages/nc-gui-v2/composables/useViewData.ts

@ -39,6 +39,16 @@ export function useViewData(
}, },
}) })
const syncCount = async () => {
const { count } = await $api.dbViewRow.count(
NOCO,
project?.value?.title as string,
meta?.value?.id as string,
viewMeta?.value?.id as string,
)
paginationData.value.totalRows = count
}
const loadData = async (params: Parameters<Api<any>['dbViewRow']['list']>[4] = {}) => { const loadData = async (params: Parameters<Api<any>['dbViewRow']['list']>[4] = {}) => {
if (!project?.value?.id || !meta?.value?.id || !viewMeta?.value?.id) return if (!project?.value?.id || !meta?.value?.id || !viewMeta?.value?.id) return
const response = await $api.dbViewRow.list('noco', project.value.id, meta.value.id, viewMeta.value.id, { const response = await $api.dbViewRow.list('noco', project.value.id, meta.value.id, viewMeta.value.id, {
@ -70,6 +80,7 @@ export function useViewData(
rowMeta: {}, rowMeta: {},
oldRow: { ...insertedData }, oldRow: { ...insertedData },
}) })
syncCount()
} catch (error: any) { } catch (error: any) {
notification.error({ notification.error({
message: 'Row insert failed', message: 'Row insert failed',
@ -167,7 +178,6 @@ export function useViewData(
}) })
return false return false
} }
return true return true
} }
@ -186,6 +196,7 @@ export function useViewData(
} }
} }
formattedData.value.splice(rowIndex, 1) formattedData.value.splice(rowIndex, 1)
syncCount()
} catch (e: any) { } catch (e: any) {
notification.error({ notification.error({
message: 'Failed to delete row', message: 'Failed to delete row',
@ -221,6 +232,7 @@ export function useViewData(
}) })
} }
} }
syncCount()
} }
return { return {
@ -235,5 +247,6 @@ export function useViewData(
deleteSelectedRows, deleteSelectedRows,
updateOrSaveRow, updateOrSaveRow,
selectedAllRecords, selectedAllRecords,
syncCount,
} }
} }

Loading…
Cancel
Save