Browse Source

refactor(nc-gui): show expand icon depending on role and readonly state

pull/4141/head
braks 2 years ago
parent
commit
eea4ef0211
  1. 9
      packages/nc-gui/components/smartsheet/Grid.vue
  2. 8
      packages/nc-gui/composables/useRoles/index.ts

9
packages/nc-gui/components/smartsheet/Grid.vue

@ -33,6 +33,7 @@ import {
useI18n, useI18n,
useMetas, useMetas,
useMultiSelect, useMultiSelect,
useRoles,
useRoute, useRoute,
useSmartsheetStoreOrThrow, useSmartsheetStoreOrThrow,
useUIPermission, useUIPermission,
@ -57,6 +58,7 @@ const isLocked = inject(IsLockedInj, ref(false))
const reloadViewDataHook = inject(ReloadViewDataHookInj, createEventHook()) const reloadViewDataHook = inject(ReloadViewDataHookInj, createEventHook())
const openNewRecordFormHook = inject(OpenNewRecordFormHookInj, createEventHook()) const openNewRecordFormHook = inject(OpenNewRecordFormHookInj, createEventHook())
const { hasRole } = useRoles()
const { isUIAllowed } = useUIPermission() const { isUIAllowed } = useUIPermission()
const hasEditPermission = $computed(() => isUIAllowed('xcDatatableEditable')) const hasEditPermission = $computed(() => isUIAllowed('xcDatatableEditable'))
@ -477,7 +479,12 @@ watch(
<a-checkbox v-model:checked="row.rowMeta.selected" /> <a-checkbox v-model:checked="row.rowMeta.selected" />
</div> </div>
<span class="flex-1" /> <span class="flex-1" />
<div v-if="!isLocked" class="nc-expand" :class="{ 'nc-comment': row.rowMeta?.commentCount }">
<div
v-if="(!readOnly || hasRole('commenter', true) || hasRole('viewer', true)) && !isLocked"
class="nc-expand"
:class="{ 'nc-comment': row.rowMeta?.commentCount }"
>
<a-spin v-if="row.rowMeta.saving" class="!flex items-center" /> <a-spin v-if="row.rowMeta.saving" class="!flex items-center" />
<template v-else> <template v-else>
<span <span

8
packages/nc-gui/composables/useRoles/index.ts

@ -12,7 +12,7 @@ import type { ProjectRole, Role, Roles } from '~/lib'
* * `loadProjectRoles` - a function to load the project roles for a specific project (by id) * * `loadProjectRoles` - a function to load the project roles for a specific project (by id)
*/ */
export const useRoles = createSharedComposable(() => { export const useRoles = createSharedComposable(() => {
const { user } = useGlobal() const { user, previewAs } = useGlobal()
const { api } = useApi() const { api } = useApi()
@ -57,7 +57,11 @@ export const useRoles = createSharedComposable(() => {
} }
} }
function hasRole(role: Role | ProjectRole | string) { function hasRole(role: Role | ProjectRole | string, includePreviewRoles = false) {
if (includePreviewRoles) {
return previewAs.value === role
}
return allRoles.value[role] return allRoles.value[role]
} }

Loading…
Cancel
Save