π₯ π₯ π₯ A Free & Self-hostable Airtable Alternative
TypeScript airtableairtable-alternativeautomatic-apihacktoberfestlow-codeno-codeno-code-databaseno-code-platformpostgresqlrest-apirestful-apispreadsheetsqliteswagger
fix(nc-gui): add copy from another view plan feature related changes
Ramesh Mane4393e1432cb4
diff --git a/packages/nc-gui/components/nc/EmptyPlaceholder.vue b/packages/nc-gui/components/nc/EmptyPlaceholder.vuenew file mode 100644index 0000000000..801f6e00a7--- /dev/null+++ b/packages/nc-gui/components/nc/EmptyPlaceholder.vue@@ -0,0 +1,36 @@+<script lang="ts" setup>+interface Props {+ title?: string+ subtitle?: string+}+defineProps<Props>()+</script>++<template>+ <div class="placeholder-container">+ <div v-if="$slots.icon" class="placeholder-icon">+ <slot name="icon" />+ </div>+ <div v-if="$slots.title || title" class="placeholder-title text-subHeading2">+ <slot name="title">{{ title }}</slot>+ </div>+ <div v-if="$slots.subtitle || subtitle" class="placeholder-subtitle text-caption">+ <slot name="subtitle">{{ subtitle }}</slot>+ </div>+ <div v-if="$slots.action" class="placeholder-action">+ <slot name="action" />+ </div>+ </div>+</template>++<style lang="scss" scoped>+.placeholder-container {+ @apply flex flex-col items-center justify-center mx-auto max-w-[420px] text-center gap-3;+ .placeholder-title {+ @apply text-nc-content-gray;+ }+ .placeholder-subtitle {+ @apply text-nc-content-gray-subtle2;+ }+}+</style>diff --git a/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vueindex 8f7c2cd11c..e9eddfeb2f 100644--- a/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue+++ b/packages/nc-gui/components/smartsheet/toolbar/ViewActionMenu.vue@@ -29,9 +29,7 @@ const view = computed(() => props.view)const table = computed(() => props.table)-const { navigateToView, duplicateView, updateView, onOpenCopyViewConfigFromAnotherViewModal } = useViewsStore()--const { user } = useGlobal()+const { navigateToView, duplicateView, updateView, isUserViewOwner, onOpenCopyViewConfigFromAnotherViewModal } = useViewsStore()const { base } = storeToRefs(useBase())@@ -175,15 +173,11 @@ const openReAssignDlg = () => {const onClickCopyViewConfig = () => {emits('closeModal')- onOpenCopyViewConfigFromAnotherViewModal()+ onOpenCopyViewConfigFromAnotherViewModal({ destView: view.value })}const isViewOwner = computed(() => {- return (- view.value?.owned_by === user.value?.id ||- (!view.value?.owned_by &&- (user.value?.base_roles?.[ProjectRoles.OWNER] || user.value?.workspace_roles?.[WorkspaceUserRoles.OWNER]))- )+ return isUserViewOwner(view.value)})const isDefaultView = computed(() => view.value?.is_default)@@ -287,6 +281,54 @@ defineOptions({}}</NcMenuItem></template>+ <NcDivider v-if="isEeUI && isUIAllowed('viewCreateOrEdit') && view?.is_default" />+ <SmartsheetToolbarNotAllowedTooltip+ v-if="isEeUI && isUIAllowed('viewCreateOrEdit')"+ :enabled="(isPersonalView && !isViewOwner) || lockType === LockType.Locked"+ :message="+ isPersonalView && !isViewOwner+ ? $t('tooltip.onlyViewOwnerCanCopyViewConfig')+ : $t('title.thisViewIsLockType', {+ type: $t(viewLockIcons[lockType]?.title).toLowerCase(),+ })+ "+ >+ <PaymentUpgradeBadgeProvider :feature="PlanFeatureTypes.FEATURE_COPY_VIEW_CONFIG_FROM_ANOTHER_VIEW">+ <template #default="{ click }">+ <NcMenuItem+ inner-class="w-full"+ :disabled="(isPersonalView && !isViewOwner) || lockType === LockType.Locked"+ @click="click(PlanFeatureTypes.FEATURE_COPY_VIEW_CONFIG_FROM_ANOTHER_VIEW, () => onClickCopyViewConfig())"+ >+ <div+ v-e="[+ 'c:navdraw:copy-view-config-from-another-view',+ {+ sidebar: props.inSidebar,+ },+ ]"+ class="w-full flex flex-row items-center gap-x-2"+ >+ <GeneralIcon icon="ncSettings2" class="opacity-80" />+ <div>+ {{ $t('objects.copyViewConfig.copyAnotherViewConfig') }}+ </div>+ <div class="flex-1 w-full mr-1" />+ <LazyPaymentUpgradeBadge+ :feature="PlanFeatureTypes.FEATURE_COPY_VIEW_CONFIG_FROM_ANOTHER_VIEW"+ :limit-or-feature="'to access copy view configuration from another view feature.' as PlanFeatureTypes"+ :content="+ $t('upgrade.upgradeToAccessCopyViewConfigFromAnotherViewSubtitle', {+ plan: getPlanTitle(PlanTitles.PLUS),+ })+ "+ :on-click-callback="() => emits('closeModal')"+ />+ </div>+ </NcMenuItem>+ </template>+ </PaymentUpgradeBadgeProvider>+ </SmartsheetToolbarNotAllowedTooltip><template v-if="view.type !== ViewTypes.FORM"><NcDivider /><template v-if="isUploadAllowed">@@ -443,7 +485,7 @@ defineOptions({<SmartsheetToolbarNotAllowedTooltipv-if="isPersonalView":enabled="!(isViewOwner || isUIAllowed('reAssignViewOwner'))"- message="Only owner or creator can re-assign"+ :message="$t('tooltip.onlyOwnerOrCreatorCanReAssign')"><PaymentUpgradeBadgeProvider :feature="PlanFeatureTypes.FEATURE_PERSONAL_VIEWS"><template #default="{ click }">@@ -483,7 +525,7 @@ defineOptions({<SmartsheetToolbarNotAllowedTooltipv-else:enabled="!isViewOwner"- message="Only view owner can assign as personal view"+ :message="$t('tooltip.onlyViewOwnerCanAssignAsPersonalView')"><PaymentUpgradeBadgeProvider :feature="PlanFeatureTypes.FEATURE_PERSONAL_VIEWS"><template #default="{ click }">@@ -521,12 +563,6 @@ defineOptions({</PaymentUpgradeBadgeProvider></SmartsheetToolbarNotAllowedTooltip></template>- <template v-if="isEeUI">- <NcMenuItem @click="onClickCopyViewConfig">- <GeneralIcon icon="copy" class="opacity-80" />- {{ $t('general.copyViewConfig') }}- </NcMenuItem>- </template></template><template v-if="!view.is_default && isUIAllowed('viewCreateOrEdit')">diff --git a/packages/nc-gui/lang/en.json b/packages/nc-gui/lang/en.jsonindex dba2b9135e..27d51fe985 100644--- a/packages/nc-gui/lang/en.json+++ b/packages/nc-gui/lang/en.json@@ -181,7 +181,8 @@"upgradeToUseAiTextField": "Upgrade to use AI Text fields","upgradeToUseAiTextFieldSubtitle": "Upgrade to the {plan} plan to use AI Text fields to generate text based on your prompt.","upgradeToUseAiButtonField": "Upgrade to use AI Button fields",- "upgradeToUseAiButtonFieldSubtitle": "Upgrade to the {plan} plan to let AI Button use record data with NocoAI to fill multiple fields automatically."+ "upgradeToUseAiButtonFieldSubtitle": "Upgrade to the {plan} plan to let AI Button use record data with NocoAI to fill multiple fields automatically.",+ "upgradeToAccessCopyViewConfigFromAnotherViewSubtitle": "Upgrade to the {plan} plan to access copy view configuration from another view feature."},"general": {"script": "Script",@@ -652,12 +653,13 @@"copyViewConfig": {"fieldVisibility": "Field visibility","fieldOrder": "Field order",- "columnWidthAndRowHeight": "Column width and row height",+ "columnWidth": "Column width","rowHeight": "Row height",- "filters": "Filters",- "groups": "Groups",- "sorts": "Sorts",- "rowColoring": "Row coloring"+ "filterCondition": "Filter condition",+ "group": "Group",+ "sort": "Sort",+ "rowColoring": "Row coloring",+ "copyAnotherViewConfig": "Copy another view configuration"}},"datatype": {@@ -1899,7 +1901,10 @@"filterByLimitExceeded": "Filter by limit exceeded","groupByLimitExceeded": "Group by limit exceeded","youDoNotHavePermissionToPasteIntoThisField": "You do not have permission to paste into this field",- "pasteOperationLimitedToMaxRows": "Paste operation limited to {max} rows. Additional rows were truncated."+ "pasteOperationLimitedToMaxRows": "Paste operation limited to {max} rows. Additional rows were truncated.",+ "onlyOwnerOrCreatorCanReAssign": "Only owner or creator can re-assign",+ "onlyViewOwnerCanAssignAsPersonalView": "Only view owner can assign as personal view",+ "onlyViewOwnerCanCopyViewConfig": "Only view owner can copy view configuration"},"placeholder": {"searchIcons": "Search icons",diff --git a/packages/nc-gui/store/views.ts b/packages/nc-gui/store/views.tsindex c88390578c..d8956a542c 100644--- a/packages/nc-gui/store/views.ts+++ b/packages/nc-gui/store/views.ts@@ -6,10 +6,11 @@ import type {MapType,RowColoringInfo,SortType,+ UserType,ViewSettingOverrideOptions,ViewType,} from 'nocodb-sdk'-import { ViewTypes, ViewTypes as _ViewTypes } from 'nocodb-sdk'+import { ProjectRoles, ViewTypes, WorkspaceUserRoles, ViewTypes as _ViewTypes } from 'nocodb-sdk'import { acceptHMRUpdate, defineStore } from 'pinia'import { useTitle } from '@vueuse/core'import type { ViewPageType } from '~/lib/types'@@ -32,7 +33,7 @@ interface RecentView {export const useViewsStore = defineStore('viewsStore', () => {const { $api, $e } = useNuxtApp()- const { ncNavigateTo } = useGlobal()+ const { ncNavigateTo, user } = useGlobal()const router = useRouter()@@ -795,19 +796,35 @@ export const useViewsStore = defineStore('viewsStore', () => {}}+ const isUserViewOwner = (view?: ViewType, _user: User | null = user.value) => {+ if (!view || !_user) return false++ return (+ view?.owned_by === _user?.id ||+ !!(!view?.owned_by && (_user?.base_roles?.[ProjectRoles.OWNER] || _user?.workspace_roles?.[WorkspaceUserRoles.OWNER]))+ )+ }+const onOpenCopyViewConfigFromAnotherViewModal = ({defaultSelectedCopyViewConfigTypes,+ destView = activeView.value,}: {defaultSelectedCopyViewConfigTypes?: ViewSettingOverrideOptions[]+ destView?: ViewType} = {}) => {if (!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))) {+ return+ }+const isOpen = ref(true)const { close } = useDialog(DlgViewCopyViewConfigFromAnotherView, {'modelValue': isOpen,'onUpdate:modelValue': closeDialog,- 'tableId': tablesStore.activeTableId,+ 'destView': destView,'defaultSelectedCopyViewConfigTypes': defaultSelectedCopyViewConfigTypes,})@@ -959,6 +976,7 @@ export const useViewsStore = defineStore('viewsStore', () => {onOpenViewCreateModal,getViewReadableUrlSlug,onOpenCopyViewConfigFromAnotherViewModal,+ isUserViewOwner,}})diff --git a/packages/nocodb-sdk/src/lib/payment/index.ts b/packages/nocodb-sdk/src/lib/payment/index.tsindex 761ce2607d..fde4fb38e8 100644--- a/packages/nocodb-sdk/src/lib/payment/index.ts+++ b/packages/nocodb-sdk/src/lib/payment/index.ts@@ -62,6 +62,7 @@ export enum PlanFeatureTypes {FEATURE_AI_BUTTON_FIELD = 'feature_ai_button_field',FEATURE_DUPLICATE_TABLE_TO_OTHER_BASE = 'feature_duplicate_table_to_other_base',FEATURE_DUPLICATE_TABLE_TO_OTHER_WS = 'feature_duplicate_table_to_other_ws',+ FEATURE_COPY_VIEW_CONFIG_FROM_ANOTHER_VIEW = 'feature_copy_view_config_from_another_view',}// todo: separate as a new enum@@ -258,6 +259,8 @@ export const PlanFeatureUpgradeMessages: Record<PlanFeatureTypes, string> = {'to target different base when duplicate table.',[PlanFeatureTypes.FEATURE_DUPLICATE_TABLE_TO_OTHER_WS]:'to target different workspace when duplicate table.',+ [PlanFeatureTypes.FEATURE_COPY_VIEW_CONFIG_FROM_ANOTHER_VIEW]:+ 'to copy view configuration from another view.',};export const getUpgradeMessage = (diff --git a/packages/nocodb-sdk/src/lib/viewUtils.ts b/packages/nocodb-sdk/src/lib/viewUtils.tsindex be033eb9e3..f906a2d20d 100644--- a/packages/nocodb-sdk/src/lib/viewUtils.ts+++ b/packages/nocodb-sdk/src/lib/viewUtils.ts@@ -19,6 +19,8 @@ export interface CopyViewConfigOption {supportedViewTypes: ViewTypes[];/** IconMapKey */icon: string;+ /** Whether this option is disabled */+ disabled?: boolean;}/**@@ -43,7 +45,7 @@ export interface CopyViewConfigOption {*/export const copyViewConfigOptionMap: Record<ViewSettingOverrideOptions,- CopyViewConfigOption+ Omit<CopyViewConfigOption, 'disabled'>> = {[ViewSettingOverrideOptions.FIELD_VISIBILITY]: {order: 1,@@ -149,10 +151,19 @@ export const copyViewConfigOptionMap: Record<* The returned options are sorted by their display order.** @param sourceViewType - The view type from which configurations will be copied- * @returns An array of configuration options with a 'disabled' flag indicating support status, sorted by order+ * @param destinationViewType - The view type to which configurations will be copied+ * @returns An array of supported destination view type configuration options with a 'disabled' flag indicating support status, sorted by order*/-export const getCopyViewConfigOptions = (sourceViewType?: ViewTypes) => {+export const getCopyViewConfigOptions = (+ sourceViewType?: ViewTypes,+ destinationViewType?: ViewTypes+): Omit<CopyViewConfigOption, 'supportedViewTypes'>[] => {return Object.values(copyViewConfigOptionMap)+ .filter((option) => {+ if (!destinationViewType) return true;++ return option.supportedViewTypes.includes(destinationViewType);+ }).map((option) => {const { supportedViewTypes, ...rest } = option;return {@@ -173,22 +184,41 @@ export const getCopyViewConfigOptions = (sourceViewType?: ViewTypes) => {** @param viewSettingOverrideOptions - Array of configuration types to be validated* @param sourceViewType - The view type from which configurations will be copied- * @returns A filtered array containing only the configuration types supported by the source view type+ * @param destinationViewType - The view type to which configurations will be copied+ * @returns A filtered array containing only the configuration types supported by the source view type and destination view type** @example* ```ts* // Validate selected config types for a Form view* const selectedTypes = [ViewSettingOverrideOptions.FIELD_VISIBILITY, ViewSettingOverrideOptions.FILTER_CONDITION, ViewSettingOverrideOptions.GROUP]- * const supportedTypes = extractSupportedViewSettingOverrideOptions(selectedTypes, ViewTypes.FORM)- * // Result: Only FieldVisibility will be included since Forms don't support Filters or Groups+ * const supportedTypes = extractSupportedViewSettingOverrideOptions(selectedTypes, ViewTypes.FORM, ViewTypes.GRID)+ * // Result: Only FieldVisibility will be included since destination Grid view support filter and group but source Forms don't support Filters or Groups* ```*/export const extractSupportedViewSettingOverrideOptions = (viewSettingOverrideOptions: ViewSettingOverrideOptions[],- sourceViewType: ViewTypes+ sourceViewType: ViewTypes,+ destinationViewType?: ViewTypes) => {+ // extract destination view type options+ const destinationViewTypeOptions = Object.values(+ ViewSettingOverrideOptions+ ).filter((option) => {+ if (!destinationViewType) return true;++ return copyViewConfigOptionMap[option].supportedViewTypes.includes(+ destinationViewType+ );+ });++ // return only options which supported in destination as well as source view typereturn (viewSettingOverrideOptions || []).filter((type) => {- if (!copyViewConfigOptionMap[type]) return false;+ if (+ !copyViewConfigOptionMap[type] ||+ !destinationViewTypeOptions.includes(type)+ ) {+ return false;+ }return copyViewConfigOptionMap[type].supportedViewTypes.includes(sourceViewType