Browse Source

fix: Added active table to useViewData so it defaults openedtable

pull/6444/head
Muhammed Mustafa 1 year ago
parent
commit
4ecf87075f
  1. 17
      packages/nc-gui/composables/useViewData.ts

17
packages/nc-gui/composables/useViewData.ts

@ -32,11 +32,16 @@ const formatData = (list: Record<string, any>[]) =>
}))
export function useViewData(
meta: Ref<TableType | undefined> | ComputedRef<TableType | undefined>,
_meta: Ref<TableType | undefined> | ComputedRef<TableType | undefined>,
viewMeta: Ref<ViewType | undefined> | ComputedRef<(ViewType & { id: string }) | undefined>,
where?: ComputedRef<string | undefined>,
) {
if (!meta) {
const { activeTableId, activeTable } = storeToRefs(useTablesStore())
const meta = computed(() => _meta.value || activeTable.value)
const metaId = computed(() => _meta.value?.id || activeTableId.value)
if (!meta.value) {
throw new Error('Table meta is not available')
}
@ -101,7 +106,7 @@ export function useViewData(
const { count } = await $api.dbViewRow.count(
NOCO,
project?.value?.id as string,
meta?.value?.id as string,
metaId.value as string,
viewMeta?.value?.id as string,
)
paginationData.value.totalRows = count
@ -150,7 +155,7 @@ export function useViewData(
aggCommentCount.value = await $api.utils.commentCount({
ids,
fk_model_id: meta.value?.id as string,
fk_model_id: metaId.value as string,
})
for (const row of formattedData.value) {
@ -160,9 +165,9 @@ export function useViewData(
}
async function loadData(params: Parameters<Api<any>['dbViewRow']['list']>[4] = {}) {
if ((!project?.value?.id || !meta.value?.id || !viewMeta.value?.id) && !isPublic.value) return
if ((!project?.value?.id || !metaId.value || !viewMeta.value?.id) && !isPublic.value) return
const response = !isPublic.value
? await api.dbViewRow.list('noco', project.value.id!, meta.value!.id!, viewMeta.value!.id!, {
? await api.dbViewRow.list('noco', project.value.id!, metaId.value!, viewMeta.value!.id!, {
...queryParams.value,
...params,
...(isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(sorts.value) }),

Loading…
Cancel
Save