Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

chore(nc-gui): lint

Ramesh Manefc6d87e72d3d
diff --git a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue
index 7a25fb404d..079bf5f0ab 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue
@@ -1,5 +1,5 @@
<script setup lang="ts">
-import { CURRENT_USER_TOKEN, ViewSettingOverrideOptions, type ColumnType, type FilterType } from 'nocodb-sdk'
+import { CURRENT_USER_TOKEN, type ColumnType, type FilterType, ViewSettingOverrideOptions } from 'nocodb-sdk'
import type ColumnFilter from './ColumnFilter.vue'
const isLocked = inject(IsLockedInj, ref(false))
diff --git a/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue
index f298eb1b5d..9c82e54af8 100644
--- a/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue
+++ b/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue
@@ -37,7 +37,7 @@ const {
updateView,
isUserViewOwner,
onOpenCopyViewConfigFromAnotherViewModal,
- getViewsCountByTableId,
+ getCopyViewConfigBtnAccessStatus,
} = viewsStore
const { isCopyViewConfigFromAnotherViewFeatureEnabled } = storeToRefs(viewsStore)
@@ -216,25 +216,7 @@ const isUploadAllowed = computed(() => {
})
const copyViewConfigMenuItemStatus = computed(() => {
- const result = {
- isDisabled: false,
- tooltip: '',
- }
-
- if (isPersonalView.value && !isViewOwner.value) {
- result.isDisabled = true
- result.tooltip = t('tooltip.onlyViewOwnerCanCopyViewConfig')
- } else if (lockType.value === LockType.Locked) {
- result.isDisabled = true
- result.tooltip = t('title.thisViewIsLockType', {
- type: t(viewLockIcons[lockType.value]?.title).toLowerCase(),
- })
- } else if (getViewsCountByTableId(table.value!.id!) < 2) {
- result.isDisabled = true
- result.tooltip = t('tooltip.youNeedAtLeastOneExistingViewToCopyConfigurations')
- }
-
- return result
+ return getCopyViewConfigBtnAccessStatus(view.value, 'view-action-menu')
})
defineOptions({
diff --git a/packages/nc-gui/store/views.ts b/packages/nc-gui/store/views.ts
index 71dcc8deb3..8a3082401a 100644
--- a/packages/nc-gui/store/views.ts
+++ b/packages/nc-gui/store/views.ts
@@ -32,6 +32,8 @@ interface RecentView {
export const useViewsStore = defineStore('viewsStore', () => {
const { $api, $e } = useNuxtApp()
+ const { t } = useI18n()
+
const { ncNavigateTo, user } = useGlobal()
const router = useRouter()
@@ -810,8 +812,39 @@ export const useViewsStore = defineStore('viewsStore', () => {
)
}
- const getViewsCountByTableId = (tableId: string) => {
- return (viewsByTable.value.get(tableId) || []).length
+ const getCopyViewConfigBtnAccessStatus = (view: ViewType, from: 'view-action-menu' | 'toolbar' = 'view-action-menu') => {
+ const result = {
+ isDisabled: false,
+ tooltip: '',
+ isVisible: isEeUI && isUIAllowed('viewCreateOrEdit'),
+ }
+
+ if (view?.lock_type === LockType.Personal && !isUserViewOwner(view)) {
+ result.isDisabled = true
+ result.tooltip = t('tooltip.onlyViewOwnerCanCopyViewConfig')
+
+ if (from === 'toolbar') {
+ result.isVisible = false
+ }
+ } else if (view?.lock_type === LockType.Locked) {
+ result.isDisabled = true
+ result.tooltip = t('title.thisViewIsLockType', {
+ type: t(viewLockIcons[view?.lock_type]?.title).toLowerCase(),
+ })
+
+ if (from === 'toolbar') {
+ result.isVisible = false
+ }
+ } else if ((viewsByTable.value.get(view.fk_model_id) || []).length < 2) {
+ result.isDisabled = true
+ result.tooltip = t('tooltip.youNeedAtLeastOneExistingViewToCopyConfigurations')
+
+ if (from === 'toolbar') {
+ result.isVisible = false
+ }
+ }
+
+ return result
}
const onOpenCopyViewConfigFromAnotherViewModal = ({
@@ -823,10 +856,10 @@ export const useViewsStore = defineStore('viewsStore', () => {
destView?: ViewType
onCopy?: (selectedCopyViewConfigTypes: ViewSettingOverrideOptions[]) => void
} = {}) => {
- if (!isEeUI || !isUIAllowed('viewCreateOrEdit')) return
+ if (!destView || !isEeUI || !isUIAllowed('viewCreateOrEdit')) return
- // If destination view is locked or if personal and user is not the owner then return
- if (destView?.lock_type === LockType.Locked || (destView?.lock_type === LockType.Personal && !isUserViewOwner(destView))) {
+ // If destination view is locked or if personal and user is not the owner or if table has only one view then return
+ if (getCopyViewConfigBtnAccessStatus(destView).isDisabled) {
return
}
@@ -990,7 +1023,7 @@ export const useViewsStore = defineStore('viewsStore', () => {
getViewReadableUrlSlug,
onOpenCopyViewConfigFromAnotherViewModal,
isUserViewOwner,
- getViewsCountByTableId,
+ getCopyViewConfigBtnAccessStatus,
}
})
diff --git a/packages/nc-gui/utils/viewUtils.ts b/packages/nc-gui/utils/viewUtils.ts
index a1dd5b7e16..4f2c42e081 100644
--- a/packages/nc-gui/utils/viewUtils.ts
+++ b/packages/nc-gui/utils/viewUtils.ts
@@ -1,4 +1,5 @@
-import { type RowColoringInfo, ViewSettingOverrideOptions, ViewTypes } from 'nocodb-sdk'
+import { ViewTypes } from 'nocodb-sdk'
+import type { RowColoringInfo, ViewSettingOverrideOptions } from 'nocodb-sdk'
import { iconMap } from './iconUtils'
import type { Language } from '~/lib/types'
import UsersIcon from '~icons/nc-icons/users'