Browse Source

fix(nc-gui): set default values for `useState` and fix type issues

pull/3606/head
braks 2 years ago
parent
commit
2b780cc3e0
  1. 2
      packages/nc-gui/components/shared-view/Grid.vue
  2. 22
      packages/nc-gui/composables/useSharedView.ts

2
packages/nc-gui/components/shared-view/Grid.vue

@ -6,7 +6,7 @@ import { ActiveViewInj, FieldsInj, IsPublicInj, MetaInj, ReadonlyInj, ReloadView
const { sharedView, meta, sorts, nestedFilters } = useSharedView()
const { signedIn } = useGlobal()
const { loadProject } = useProject(meta?.value.project_id)
const { loadProject } = useProject((meta.value as any)?.project_id)
const reloadEventHook = createEventHook<void>()

22
packages/nc-gui/composables/useSharedView.ts

@ -1,4 +1,4 @@
import type { ExportTypes, FilterType, PaginatedType, SortType, TableType, ViewType } from 'nocodb-sdk'
import type { ExportTypes, FilterType, PaginatedType, RequestParams, SortType, TableType, ViewType } from 'nocodb-sdk'
import { UITypes } from 'nocodb-sdk'
import { useNuxtApp } from '#app'
@ -8,15 +8,15 @@ export function useSharedView() {
() => [],
)
const paginationData = useState<PaginatedType>('paginationData', () => ({ page: 1, pageSize: 25 }))
const sharedView = useState<ViewType>('sharedView')
const sharedView = useState<ViewType | undefined>('sharedView', () => undefined)
const sorts = useState<SortType[]>('sorts', () => [])
const password = useState<string | undefined>('password')
const password = useState<string | undefined>('password', () => undefined)
const allowCSVDownload = useState<boolean>('allowCSVDownload', () => false)
const meta = useState<TableType | undefined>('meta', () => undefined)
const meta = useState<TableType>('meta')
const formColumns = computed(
() =>
meta.value.columns
meta.value?.columns
?.filter(
(f: Record<string, any>) =>
f.show && f.uidt !== UITypes.Rollup && f.uidt !== UITypes.Lookup && f.uidt !== UITypes.Formula,
@ -29,7 +29,9 @@ export function useSharedView() {
const { setMeta } = useMetas()
const loadSharedView = async (viewId: string, localPassword: string | undefined = undefined) => {
const viewMeta = await $api.public.sharedViewMetaGet(viewId, {
if (!meta.value) return
const viewMeta: Record<string, any> = await $api.public.sharedViewMetaGet(viewId, {
headers: {
'xc-password': localPassword ?? password.value,
},
@ -42,7 +44,7 @@ export function useSharedView() {
meta.value = { ...viewMeta.model }
let order = 1
meta.value.columns = [...viewMeta.model.columns]
meta.value!.columns = [...viewMeta.model.columns]
.filter((c) => c.show)
.map((c) => ({ ...c, order: order++ }))
.sort((a, b) => a.order - b.order)
@ -58,7 +60,7 @@ export function useSharedView() {
const pageSize = paginationData.value.pageSize || 25
const { data } = await $api.public.dataList(
sharedView?.value?.uuid,
(sharedView.value as any)?.uuid,
{
offset: (page - 1) * pageSize,
filterArrJson: JSON.stringify(nestedFilters.value),
@ -80,7 +82,7 @@ export function useSharedView() {
type: ExportTypes.EXCEL | ExportTypes.CSV,
responseType: 'base64' | 'blob',
) => {
return await $api.public.csvExport(sharedView.value?.uuid, type, {
return await $api.public.csvExport((sharedView.value as any)?.uuid, type, {
format: responseType as any,
query: {
fields: fields.map((field) => field.title),
@ -92,7 +94,7 @@ export function useSharedView() {
headers: {
'xc-password': password.value,
},
})
} as RequestParams)
}
return {

Loading…
Cancel
Save