Browse Source

fix(gui-v2): attachments not loading in shared view

pull/3300/head
braks 2 years ago
parent
commit
67728624e2
  1. 1
      packages/nc-gui-v2/components.d.ts
  2. 4
      packages/nc-gui-v2/components/cell/attachment/index.vue
  3. 27
      packages/nc-gui-v2/components/cell/attachment/utils.ts
  4. 1
      packages/nc-gui-v2/components/general/HelpAndSupport.vue
  5. 39
      packages/nc-gui-v2/components/smartsheet-toolbar/SortListMenu.vue
  6. 5
      packages/nc-gui-v2/components/smartsheet/Grid.vue

1
packages/nc-gui-v2/components.d.ts vendored

@ -202,6 +202,7 @@ declare module '@vue/runtime-core' {
MdiSearch: typeof import('~icons/mdi/search')['default'] MdiSearch: typeof import('~icons/mdi/search')['default']
MdiShieldLockOutline: typeof import('~icons/mdi/shield-lock-outline')['default'] MdiShieldLockOutline: typeof import('~icons/mdi/shield-lock-outline')['default']
MdiSlack: typeof import('~icons/mdi/slack')['default'] MdiSlack: typeof import('~icons/mdi/slack')['default']
MdiSort: typeof import('~icons/mdi/sort')['default']
MdiStar: typeof import('~icons/mdi/star')['default'] MdiStar: typeof import('~icons/mdi/star')['default']
MdiStarOutline: typeof import('~icons/mdi/star-outline')['default'] MdiStarOutline: typeof import('~icons/mdi/star-outline')['default']
MdiStore: typeof import('~icons/mdi/store')['default'] MdiStore: typeof import('~icons/mdi/store')['default']

4
packages/nc-gui-v2/components/cell/attachment/index.vue

@ -61,7 +61,8 @@ watch(
if (nextModel) { if (nextModel) {
try { try {
attachments.value = ((typeof nextModel === 'string' ? JSON.parse(nextModel) : nextModel) || []).filter(Boolean) attachments.value = ((typeof nextModel === 'string' ? JSON.parse(nextModel) : nextModel) || []).filter(Boolean)
} catch { } catch (e) {
console.error(e)
attachments.value = [] attachments.value = []
} }
} }
@ -124,6 +125,7 @@ const { isSharedForm } = useSmartsheetStoreOrThrow()
</div> </div>
</a-tooltip> </a-tooltip>
</div> </div>
<div v-else class="flex" />
<template v-if="visibleItems.length"> <template v-if="visibleItems.length">
<div <div

27
packages/nc-gui-v2/components/cell/attachment/utils.ts

@ -1,9 +1,22 @@
import { message } from 'ant-design-vue' import { message } from 'ant-design-vue'
import FileSaver from 'file-saver' import FileSaver from 'file-saver'
import { computed, inject, ref, useApi, useFileDialog, useInjectionState, useProject, watch } from '#imports' import {
import { ColumnInj, EditModeInj, IsPublicInj, MetaInj, ReadonlyInj } from '~/context' ColumnInj,
import { isImage } from '~/utils' EditModeInj,
import { NOCO } from '~/lib' IsPublicInj,
MetaInj,
NOCO,
ReadonlyInj,
computed,
inject,
isImage,
ref,
useApi,
useFileDialog,
useInjectionState,
useProject,
watch,
} from '#imports'
import MdiPdfBox from '~icons/mdi/pdf-box' import MdiPdfBox from '~icons/mdi/pdf-box'
import MdiFileWordOutline from '~icons/mdi/file-word-outline' import MdiFileWordOutline from '~icons/mdi/file-word-outline'
import MdiFilePowerpointBox from '~icons/mdi/file-powerpoint-box' import MdiFilePowerpointBox from '~icons/mdi/file-powerpoint-box'
@ -22,8 +35,6 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
const isPublic = inject(IsPublicInj, ref(false)) const isPublic = inject(IsPublicInj, ref(false))
const isForm = inject('isForm', false)
// todo: replace placeholder var // todo: replace placeholder var
const isPublicGrid = $ref(false) const isPublicGrid = $ref(false)
@ -60,6 +71,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
updateModelValue(storedFilesData.value.map((storedFile) => storedFile.file)) updateModelValue(storedFilesData.value.map((storedFile) => storedFile.file))
} else { } else {
attachments.value.splice(i, 1) attachments.value.splice(i, 1)
updateModelValue(attachments.value) updateModelValue(attachments.value)
} }
} }
@ -149,7 +161,7 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
} }
/** our currently visible items, either the locally stored or the ones from db, depending on isPublicForm status */ /** our currently visible items, either the locally stored or the ones from db, depending on isPublicForm status */
const visibleItems = computed<any[]>(() => (isPublic.value ? storedFilesData.value : attachments.value) || ([] as any[])) const visibleItems = computed<any[]>(() => [...attachments.value, ...storedFiles.value])
watch(files, (nextFiles) => nextFiles && onFileSelect(nextFiles)) watch(files, (nextFiles) => nextFiles && onFileSelect(nextFiles))
@ -158,7 +170,6 @@ export const [useProvideAttachmentCell, useAttachmentCell] = useInjectionState(
storedFilesData, storedFilesData,
visibleItems, visibleItems,
isPublic, isPublic,
isForm,
isPublicGrid, isPublicGrid,
isReadonly, isReadonly,
meta, meta,

1
packages/nc-gui-v2/components/general/HelpAndSupport.vue

@ -25,6 +25,7 @@ const openSwaggerLink = () => {
</div> </div>
<a-drawer <a-drawer
v-bind="$attrs"
v-model:visible="showDrawer" v-model:visible="showDrawer"
class="h-full relative" class="h-full relative"
placement="right" placement="right"

39
packages/nc-gui-v2/components/smartsheet-toolbar/SortListMenu.vue

@ -1,27 +1,34 @@
<script setup lang="ts"> <script setup lang="ts">
import type { ColumnType } from 'nocodb-sdk' import type { ColumnType } from 'nocodb-sdk'
import FieldListAutoCompleteDropdown from './FieldListAutoCompleteDropdown.vue' import FieldListAutoCompleteDropdown from './FieldListAutoCompleteDropdown.vue'
import { getSortDirectionOptions } from '~/utils/sortUtils' import {
import { computed, inject, useViewSorts } from '#imports' ActiveViewInj,
import { ActiveViewInj, IsLockedInj, MetaInj, ReloadViewDataHookInj } from '~/context' IsLockedInj,
import MdiMenuDownIcon from '~icons/mdi/menu-down' MetaInj,
import MdiSortIcon from '~icons/mdi/sort' ReloadViewDataHookInj,
import MdiDeleteIcon from '~icons/mdi/close-box' computed,
import MdiAddIcon from '~icons/mdi/plus' getSortDirectionOptions,
inject,
ref,
useViewSorts,
watch,
} from '#imports'
const meta = inject(MetaInj) const meta = inject(MetaInj)
const view = inject(ActiveViewInj) const view = inject(ActiveViewInj)
const isLocked = inject(IsLockedInj) const isLocked = inject(IsLockedInj, ref(false))
const reloadDataHook = inject(ReloadViewDataHookInj) const reloadDataHook = inject(ReloadViewDataHookInj)
const { sorts, saveOrUpdate, loadSorts, addSort, deleteSort } = useViewSorts(view, () => reloadDataHook?.trigger()) const { sorts, saveOrUpdate, loadSorts, addSort, deleteSort } = useViewSorts(view, () => reloadDataHook?.trigger())
const columns = computed(() => meta?.value?.columns || []) const columns = computed(() => meta?.value?.columns || [])
const columnByID = computed<Record<string, ColumnType>>(() =>
columns?.value?.reduce((obj: any, col: any) => { const columnByID = computed(() =>
obj[col.id] = col columns.value.reduce((obj, col) => {
obj[col.id!] = col
return obj return obj
}, {}), }, {} as Record<string, ColumnType>),
) )
watch( watch(
@ -38,10 +45,10 @@ watch(
<div :class="{ 'nc-badge nc-active-btn': sorts?.length }"> <div :class="{ 'nc-badge nc-active-btn': sorts?.length }">
<a-button v-t="['c:sort']" class="nc-sort-menu-btn nc-toolbar-btn" :disabled="isLocked" <a-button v-t="['c:sort']" class="nc-sort-menu-btn nc-toolbar-btn" :disabled="isLocked"
><div class="flex items-center gap-1"> ><div class="flex items-center gap-1">
<MdiSortIcon /> <MdiSort />
<!-- Sort --> <!-- Sort -->
<span class="text-capitalize !text-sm font-weight-normal">{{ $t('activity.sort') }}</span> <span class="text-capitalize !text-sm font-weight-normal">{{ $t('activity.sort') }}</span>
<MdiMenuDownIcon class="text-grey" /> <MdiMenuDown class="text-grey" />
</div> </div>
</a-button> </a-button>
</div> </div>
@ -49,7 +56,7 @@ watch(
<div class="bg-gray-50 p-6 shadow-lg menu-filter-dropdown min-w-[400px] max-h-[max(80vh,500px)] overflow-auto !border"> <div class="bg-gray-50 p-6 shadow-lg menu-filter-dropdown min-w-[400px] max-h-[max(80vh,500px)] overflow-auto !border">
<div v-if="sorts?.length" class="sort-grid mb-2" @click.stop> <div v-if="sorts?.length" class="sort-grid mb-2" @click.stop>
<template v-for="(sort, i) in sorts || []" :key="i"> <template v-for="(sort, i) in sorts || []" :key="i">
<MdiDeleteIcon class="nc-sort-item-remove-btn text-grey self-center" small @click.stop="deleteSort(sort, i)" /> <MdiCloseBox class="nc-sort-item-remove-btn text-grey self-center" small @click.stop="deleteSort(sort, i)" />
<FieldListAutoCompleteDropdown <FieldListAutoCompleteDropdown
v-model="sort.fk_column_id" v-model="sort.fk_column_id"
@ -79,7 +86,7 @@ watch(
</div> </div>
<a-button class="text-capitalize mb-1 mt-4" type="primary" ghost @click.stop="addSort"> <a-button class="text-capitalize mb-1 mt-4" type="primary" ghost @click.stop="addSort">
<div class="flex gap-1 items-center"> <div class="flex gap-1 items-center">
<MdiAddIcon /> <MdiPlus />
<!-- Add Sort Option --> <!-- Add Sort Option -->
{{ $t('activity.addSort') }} {{ $t('activity.addSort') }}
</div> </div>

5
packages/nc-gui-v2/components/smartsheet/Grid.vue

@ -15,6 +15,7 @@ import {
PaginationDataInj, PaginationDataInj,
ReadonlyInj, ReadonlyInj,
ReloadViewDataHookInj, ReloadViewDataHookInj,
createEventHook,
enumColor, enumColor,
inject, inject,
onClickOutside, onClickOutside,
@ -44,8 +45,8 @@ const fields = inject(FieldsInj, ref([]))
const readOnly = inject(ReadonlyInj, false) const readOnly = inject(ReadonlyInj, false)
const isLocked = inject(IsLockedInj, ref(false)) const isLocked = inject(IsLockedInj, ref(false))
const reloadViewDataHook = inject(ReloadViewDataHookInj) const reloadViewDataHook = inject(ReloadViewDataHookInj, createEventHook())
const openNewRecordFormHook = inject(OpenNewRecordFormHookInj) const openNewRecordFormHook = inject(OpenNewRecordFormHookInj, createEventHook())
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()

Loading…
Cancel
Save