Browse Source

fix(nc-gui): remove getAttachmentUrl

pull/5046/head
Wing-Kam Wong 2 years ago
parent
commit
7e9aa7b810
  1. 15
      packages/nc-gui/components/cell/attachment/utils.ts
  2. 33
      packages/nc-gui/composables/useKanbanViewStore.ts
  3. 34
      packages/nc-gui/composables/useViewData.ts

15
packages/nc-gui/components/cell/attachment/utils.ts

@ -229,20 +229,6 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
;(await import('file-saver')).saveAs(item.url || item.data, item.title) ;(await import('file-saver')).saveAs(item.url || item.data, item.title)
} }
/** construct the attachment url
* See /packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts for the details
* */
async function getAttachmentUrl(item: AttachmentType) {
const path = item?.path
// if path doesn't exist, use `item.url`
if (path) {
// try ${appInfo.value.ncSiteUrl}/${item.path} first
return Promise.resolve(`${appInfo.value.ncSiteUrl}/${item.path}`)
}
// if it fails, use the original url
return Promise.resolve(item.url)
}
const FileIcon = (icon: string) => { const FileIcon = (icon: string) => {
switch (icon) { switch (icon) {
case 'mdi-pdf-box': case 'mdi-pdf-box':
@ -284,7 +270,6 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
storedFiles, storedFiles,
bulkDownloadFiles, bulkDownloadFiles,
defaultAttachmentMeta, defaultAttachmentMeta,
getAttachmentUrl,
} }
}, },
'useAttachmentCell', 'useAttachmentCell',

33
packages/nc-gui/composables/useKanbanViewStore.ts

@ -144,17 +144,6 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
rowMeta: {}, rowMeta: {},
})) }))
async function getAttachmentUrl(item: AttachmentType) {
const path = item?.path
// if path doesn't exist, use `item.url`
if (path) {
// try ${appInfo.value.ncSiteUrl}/${item.path} first
return Promise.resolve(`${appInfo.value.ncSiteUrl}/${item.path}`)
}
// if it fails, use the original url
return Promise.resolve(item.url)
}
async function loadKanbanData() { async function loadKanbanData() {
if ((!project?.value?.id || !meta.value?.id || !viewMeta?.value?.id || !groupingFieldColumn?.value?.id) && !isPublic.value) if ((!project?.value?.id || !meta.value?.id || !viewMeta?.value?.id || !groupingFieldColumn?.value?.id) && !isPublic.value)
return return
@ -183,28 +172,8 @@ const [useProvideKanbanViewStore, useKanbanViewStore] = useInjectionState(
} }
for (const data of groupData) { for (const data of groupData) {
const records = []
const key = data.key const key = data.key
// TODO: optimize formattedData.value.set(key, formatData(data.value.list))
// reconstruct the url
// See /packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts for the details
for (const record of data.value.list) {
for (const attachmentColumn of attachmentColumns.value) {
// attachment column can be hidden
if (!record[attachmentColumn!]) continue
const oldAttachment = JSON.parse(record[attachmentColumn!])
const newAttachment = []
for (const attachmentObj of oldAttachment) {
newAttachment.push({
...attachmentObj,
url: await getAttachmentUrl(attachmentObj),
})
}
record[attachmentColumn!] = newAttachment
}
records.push(record)
}
formattedData.value.set(key, formatData(records))
countByStack.value.set(key, data.value.pageInfo.totalRows || 0) countByStack.value.set(key, data.value.pageInfo.totalRows || 0)
} }
} }

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

@ -201,18 +201,6 @@ export function useViewData(
} }
} }
// TODO: refactor
async function getAttachmentUrl(item: AttachmentType) {
const path = item?.path
// if path doesn't exist, use `item.url`
if (path) {
// try ${appInfo.value.ncSiteUrl}/${item.path} first
return Promise.resolve(`${appInfo.ncSiteUrl}/${item.path}`)
}
// if it fails, use the original url
return Promise.resolve(item.url)
}
async function loadData(params: Parameters<Api<any>['dbViewRow']['list']>[4] = {}) { 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 || !meta.value?.id || !viewMeta.value?.id) && !isPublic.value) return
const response = !isPublic.value const response = !isPublic.value
@ -224,27 +212,7 @@ export function useViewData(
where: where?.value, where: where?.value,
}) })
: await fetchSharedViewData({ sortsArr: sorts.value, filtersArr: nestedFilters.value }) : await fetchSharedViewData({ sortsArr: sorts.value, filtersArr: nestedFilters.value })
// reconstruct the url formattedData.value = formatData(response.list)
// See /packages/nocodb/src/lib/version-upgrader/ncAttachmentUpgrader.ts for the details
const records = []
for (const record of response.list) {
for (const attachmentColumn of attachmentColumns.value) {
// attachment column can be hidden
if (!record[attachmentColumn!]) continue
const oldAttachment =
typeof record[attachmentColumn!] === 'string' ? JSON.parse(record[attachmentColumn!]) : record[attachmentColumn!]
const newAttachment = []
for (const attachmentObj of oldAttachment) {
newAttachment.push({
...attachmentObj,
url: await getAttachmentUrl(attachmentObj),
})
}
record[attachmentColumn!] = newAttachment
}
records.push(record)
}
formattedData.value = formatData(records)
paginationData.value = response.pageInfo paginationData.value = response.pageInfo
// to cater the case like when querying with a non-zero offset // to cater the case like when querying with a non-zero offset

Loading…
Cancel
Save