Browse Source

refactor/gui-v2-Share view minor cleanup

pull/3083/head
Muhammed Mustafa 2 years ago
parent
commit
9c44490cda
  1. 24
      packages/nc-gui-v2/composables/useViewData.ts
  2. 44
      packages/nc-gui-v2/composables/useViewFilters.ts

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

@ -30,17 +30,28 @@ export function useViewData(
throw new Error('Table meta is not available') throw new Error('Table meta is not available')
} }
const paginationData = ref<PaginatedType>({ page: 1, pageSize: 25 }) const _paginationData = ref<PaginatedType>({ page: 1, pageSize: 25 })
const aggCommentCount = ref<{ row_id: string; count: number }[]>([]) const aggCommentCount = ref<{ row_id: string; count: number }[]>([])
const galleryData = ref<GalleryType>() const galleryData = ref<GalleryType>()
const formColumnData = ref<FormType>() const formColumnData = ref<FormType>()
// todo: missing properties on FormType (success_msg, show_blank_form, // todo: missing properties on FormType (success_msg, show_blank_form,
const formViewData = ref<FormType & { success_msg?: string; show_blank_form?: boolean }>() const formViewData = ref<FormType & { success_msg?: string; show_blank_form?: boolean }>()
let isPublic = inject(IsPublicInj, ref(false))
const { project } = useProject() const { project } = useProject()
const { fetchSharedViewData, paginationData: sharedPaginationData } = useSharedView() const { fetchSharedViewData, paginationData: sharedPaginationData } = useSharedView()
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
let isPublic = inject(IsPublicInj, ref(false))
const paginationData = computed({
get: () => (isPublic.value ? sharedPaginationData.value : _paginationData.value),
set: (value) => {
if (isPublic.value) {
sharedPaginationData.value = value
} else {
_paginationData.value = value
}
},
})
const selectedAllRecords = computed({ const selectedAllRecords = computed({
get() { get() {
@ -322,15 +333,6 @@ export function useViewData(
} }
} }
watch(
() => paginationData.value,
() => {
if (!isPublic.value) return
sharedPaginationData.value = paginationData.value
},
)
return { return {
loadData, loadData,
paginationData, paginationData,

44
packages/nc-gui-v2/composables/useViewFilters.ts

@ -2,7 +2,7 @@ import type { FilterType, ViewType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { useNuxtApp, useUIPermission } from '#imports' import { useNuxtApp, useUIPermission } from '#imports'
import { useMetas } from '~/composables/useMetas' import { useMetas } from '~/composables/useMetas'
import { IsPublicInj, MetaInj } from '~/context' import { IsPublicInj, ReloadViewDataHookInj } from '~/context'
export function useViewFilters( export function useViewFilters(
view: Ref<ViewType> | undefined, view: Ref<ViewType> | undefined,
@ -11,16 +11,28 @@ export function useViewFilters(
reloadData?: () => void, reloadData?: () => void,
) { ) {
const { filters: sharedViewFilter } = useSharedView() const { filters: sharedViewFilter } = useSharedView()
const meta = inject(MetaInj)
const { loadData } = useViewData(meta, view)
const filters = ref<(FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string })[]>([]) const reloadHook = inject(ReloadViewDataHookInj)
const _filters = ref<(FilterType & { status?: 'update' | 'delete' | 'create'; parentId?: string })[]>([])
const isPublic = inject(IsPublicInj, ref(false)) const isPublic = inject(IsPublicInj, ref(false))
const { $api } = useNuxtApp() const { $api } = useNuxtApp()
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()
const { metas } = useMetas() const { metas } = useMetas()
const filters = computed({
get: () => (isPublic.value ? sharedViewFilter.value : _filters.value),
set: (value) => {
if (isPublic.value) {
sharedViewFilter.value = value
reloadHook?.trigger()
} else {
_filters.value = value
}
},
})
const loadFilters = async (hookId?: string) => { const loadFilters = async (hookId?: string) => {
if (isPublic.value) return if (isPublic.value) return
@ -111,27 +123,21 @@ export function useViewFilters(
} }
const addFilter = () => { const addFilter = () => {
filters.value = [ filters.value.push({
...filters.value,
{
comparison_op: 'eq', comparison_op: 'eq',
value: '', value: '',
status: 'create', status: 'create',
logical_op: 'and', logical_op: 'and',
}, })
]
} }
const addFilterGroup = async () => { const addFilterGroup = async () => {
filters.value = [ filters.value.push({
...filters.value,
{
parentId, parentId,
is_group: true, is_group: true,
status: 'create', status: 'create',
logical_op: 'and', logical_op: 'and',
}, })
]
const index = filters.value.length - 1 const index = filters.value.length - 1
await saveOrUpdate(filters.value[index], index, true) await saveOrUpdate(filters.value[index], index, true)
} }
@ -152,15 +158,5 @@ export function useViewFilters(
}, },
) )
watch(
() => filters.value,
() => {
if (!isPublic.value) return
sharedViewFilter.value = filters.value
loadData()
},
)
return { filters, loadFilters, sync, deleteFilter, saveOrUpdate, addFilter, addFilterGroup } return { filters, loadFilters, sync, deleteFilter, saveOrUpdate, addFilter, addFilterGroup }
} }

Loading…
Cancel
Save