Browse Source

Merge pull request #3374 from dolsem/editable-shared-views

Make shared views editable
pull/3387/head
navi 2 years ago committed by GitHub
parent
commit
27833684ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 12
      packages/nc-gui-v2/components/shared-view/Grid.vue
  2. 2
      packages/nc-gui-v2/components/smartsheet/Cell.vue
  3. 11
      packages/nc-gui-v2/components/smartsheet/Grid.vue
  4. 1
      packages/nc-gui-v2/composables/useUIPermission/rolePermissions.ts

12
packages/nc-gui-v2/components/shared-view/Grid.vue

@ -1,10 +1,13 @@
<script setup lang="ts"> <script setup lang="ts">
import type { Ref } from 'vue' import type { Ref } from 'vue'
import type { TableType } from 'nocodb-sdk' import type { TableType } from 'nocodb-sdk'
import { message } from 'ant-design-vue'
import { ActiveViewInj, FieldsInj, IsPublicInj, MetaInj, ReadonlyInj, ReloadViewDataHookInj } from '~/context' import { ActiveViewInj, FieldsInj, IsPublicInj, MetaInj, ReadonlyInj, ReloadViewDataHookInj } from '~/context'
const { sharedView, meta, sorts, nestedFilters } = useSharedView() const { sharedView, meta, sorts, nestedFilters } = useSharedView()
const { signedIn } = useGlobal()
const { loadProject } = useProject(meta?.value.project_id)
const reloadEventHook = createEventHook<void>() const reloadEventHook = createEventHook<void>()
provide(ReloadViewDataHookInj, reloadEventHook) provide(ReloadViewDataHookInj, reloadEventHook)
@ -15,6 +18,15 @@ provide(FieldsInj, ref(meta.value.columns as any[]))
provide(IsPublicInj, ref(true)) provide(IsPublicInj, ref(true))
useProvideSmartsheetStore(sharedView as Ref<TableType>, meta, true, sorts, nestedFilters) useProvideSmartsheetStore(sharedView as Ref<TableType>, meta, true, sorts, nestedFilters)
if (signedIn.value) {
try {
await loadProject()
} catch (e: any) {
console.error(e)
message.error(await extractSdkResponseErrorMsg(e))
}
}
</script> </script>
<template> <template>

2
packages/nc-gui-v2/components/smartsheet/Cell.vue

@ -170,6 +170,6 @@ const syncAndNavigate = (dir: NavigateDir) => {
<CellText v-else-if="isString" v-model="vModel" /> <CellText v-else-if="isString" v-model="vModel" />
<CellJson v-else-if="isJSON" v-model="vModel" /> <CellJson v-else-if="isJSON" v-model="vModel" />
<CellText v-else v-model="vModel" /> <CellText v-else v-model="vModel" />
<div v-if="(isLocked || (isPublic && !isForm)) && !isAttachment" class="nc-locked-overlay" @click.stop.prevent /> <div v-if="(isLocked || (isPublic && readOnly && !isForm)) && !isAttachment" class="nc-locked-overlay" @click.stop.prevent />
</div> </div>
</template> </template>

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

@ -49,6 +49,7 @@ const reloadViewDataHook = inject(ReloadViewDataHookInj, createEventHook())
const openNewRecordFormHook = inject(OpenNewRecordFormHookInj, createEventHook()) const openNewRecordFormHook = inject(OpenNewRecordFormHookInj, createEventHook())
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()
const hasEditPermission = isUIAllowed('xcDatatableEditable')
// todo: get from parent ( inject or use prop ) // todo: get from parent ( inject or use prop )
const isView = false const isView = false
@ -65,7 +66,7 @@ const _contextMenu = ref(false)
const contextMenu = computed({ const contextMenu = computed({
get: () => _contextMenu.value, get: () => _contextMenu.value,
set: (val) => { set: (val) => {
if (!readOnly) { if (hasEditPermission) {
_contextMenu.value = val _contextMenu.value = val
} }
}, },
@ -103,7 +104,7 @@ provide(PaginationDataInj, paginationData)
provide(ChangePageInj, changePage) provide(ChangePageInj, changePage)
provide(ReadonlyInj, !isUIAllowed('xcDatatableEditable')) provide(ReadonlyInj, !hasEditPermission)
reloadViewDataHook?.on(async () => { reloadViewDataHook?.on(async () => {
await loadData() await loadData()
@ -171,7 +172,7 @@ const clearCell = async (ctx: { row: number; col: number }) => {
const { copy } = useClipboard() const { copy } = useClipboard()
const makeEditable = (row: Row, col: ColumnType) => { const makeEditable = (row: Row, col: ColumnType) => {
if (isPublicView.value || editEnabled || isView) { if (!hasEditPermission || editEnabled || isView) {
return return
} }
if (!isPkAvail.value && !row.rowMeta.new) { if (!isPkAvail.value && !row.rowMeta.new) {
@ -430,7 +431,7 @@ const onNavigate = (dir: NavigateDir) => {
:key="columnObj.id" :key="columnObj.id"
class="cell relative cursor-pointer nc-grid-cell" class="cell relative cursor-pointer nc-grid-cell"
:class="{ :class="{
active: !isPublicView && selected.col === colIndex && selected.row === rowIndex, active: isUIAllowed('xcDatatableEditable') && selected.col === colIndex && selected.row === rowIndex,
}" }"
:data-key="rowIndex + columnObj.id" :data-key="rowIndex + columnObj.id"
:data-col="columnObj.id" :data-col="columnObj.id"
@ -476,7 +477,7 @@ const onNavigate = (dir: NavigateDir) => {
TODO: add relationType !== 'bt' ? TODO: add relationType !== 'bt' ?
v1: <tr v-if="!isView && !isLocked && !isPublicView && isEditable && relationType !== 'bt'"> v1: <tr v-if="!isView && !isLocked && !isPublicView && isEditable && relationType !== 'bt'">
--> -->
<tr v-if="!isView && !isLocked && !isPublicView && isUIAllowed('xcDatatableEditable')"> <tr v-if="!isView && !isLocked && isUIAllowed('xcDatatableEditable')">
<td <td
v-t="['c:row:add:grid-bottom']" v-t="['c:row:add:grid-bottom']"
:colspan="visibleColLength + 1" :colspan="visibleColLength + 1"

1
packages/nc-gui-v2/composables/useUIPermission/rolePermissions.ts

@ -1,4 +1,5 @@
const rolePermissions = { const rolePermissions = {
super: '*',
creator: '*', creator: '*',
owner: '*', owner: '*',
guest: {}, guest: {},

Loading…
Cancel
Save