Skip to content

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

fix(nc-gui): show tooltip is button url is invalid #6150

Ramesh Mane7e1828dac97f
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/cells/Button.ts b/packages/nc-gui/components/smartsheet/grid/canvas/cells/Button.ts
index 9536a08639..5a1a056a13 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/cells/Button.ts
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/cells/Button.ts
@@ -1,5 +1,4 @@
import { ButtonActionsType, type ButtonType } from 'nocodb-sdk'
-import { getI18n } from '../../../../../plugins/a.i18n'
import { defaultOffscreen2DContext, renderSpinner, truncateText } from '../utils/canvas'
const buttonColorMap = {
@@ -224,7 +223,21 @@ const iconSpacing = 6
export const ButtonCellRenderer: CellRenderer = {
render: (ctx: CanvasRenderingContext2D, props: CellRendererOptions) => {
- const { x, y, width, column, spriteLoader, mousePosition, actionManager, pk, disabled, value, allowLocalUrl } = props
+ const {
+ x,
+ y,
+ width,
+ column,
+ spriteLoader,
+ mousePosition,
+ actionManager,
+ pk,
+ disabled,
+ value,
+ allowLocalUrl,
+ cellRenderStore,
+ t,
+ } = props
const isLoading = actionManager.isLoading(pk, column.id!)
let disabledState = isLoading || disabled?.isInvalid
@@ -257,6 +270,10 @@ export const ButtonCellRenderer: CellRenderer = {
require_tld: !allowLocalUrl,
})
)
+
+ Object.assign(cellRenderStore, {
+ invalidUrlTooltip: disabledState ? t('msg.error.invalidURL') : '',
+ })
}
const hasIcon = !!buttonMeta.icon
@@ -401,7 +418,7 @@ export const ButtonCellRenderer: CellRenderer = {
return true
},
- async handleHover({ column, getCellPosition, row, mousePosition }) {
+ async handleHover({ column, getCellPosition, row, mousePosition, t, cellRenderStore }) {
const { tryShowTooltip, hideTooltip } = useTooltipStore()
hideTooltip()
@@ -410,7 +427,7 @@ export const ButtonCellRenderer: CellRenderer = {
const isInvalid = column?.isInvalidColumn?.isInvalid
const ignoreTooltip = column?.isInvalidColumn?.ignoreTooltip
- if (!isInvalid || ignoreTooltip) return
+ if (!cellRenderStore.invalidUrlTooltip && (!isInvalid || ignoreTooltip)) return
const { aiIntegrations } = useNocoAi()
@@ -427,6 +444,7 @@ export const ButtonCellRenderer: CellRenderer = {
}
const hasIcon = !!buttonMeta.icon
const hasLabel = !!buttonMeta.label
+
if (!hasLabel) return
let contentWidth = 0
let labelWidth = 0
@@ -443,9 +461,11 @@ export const ButtonCellRenderer: CellRenderer = {
contentWidth += labelWidth
}
- const tooltip = aiIntegrations.value.length
- ? getI18n().global.t('tooltip.aiIntegrationReConfigure')
- : getI18n().global.t('tooltip.aiIntegrationAddAndReConfigure')
+ const tooltip = cellRenderStore.invalidUrlTooltip
+ ? cellRenderStore.invalidUrlTooltip
+ : aiIntegrations.value.length
+ ? t('tooltip.aiIntegrationReConfigure')
+ : t('tooltip.aiIntegrationAddAndReConfigure')
const buttonWidth = Math.min(maxButtonWidth, Math.max(buttonMinWidth, contentWidth + horizontalPadding * 2))
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts b/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts
index cf3ae03fd0..3269fe927a 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/cells/index.ts
@@ -359,6 +359,7 @@ export function useGridCellHandler(params: {
path: ctx.path ?? [],
allowLocalUrl: appInfo.value?.allowLocalUrl,
baseRoles: baseRoles.value,
+ t,
})
}
return false
@@ -388,6 +389,7 @@ export function useGridCellHandler(params: {
openDetachedLongText,
allowLocalUrl: appInfo.value?.allowLocalUrl,
path: ctx.path ?? [],
+ t,
})
} else {
console.log('No handler found for cell type', ctx.column.columnObj.uidt)
@@ -424,6 +426,7 @@ export function useGridCellHandler(params: {
setCursor,
path: ctx.path ?? [],
baseUsers: baseUsers.value,
+ t,
})
}
}
diff --git a/packages/nc-gui/components/virtual-cell/Button.vue b/packages/nc-gui/components/virtual-cell/Button.vue
index 966e100850..50a7b4ed75 100644
--- a/packages/nc-gui/components/virtual-cell/Button.vue
+++ b/packages/nc-gui/components/virtual-cell/Button.vue
@@ -28,6 +28,8 @@ const isPublic = inject(IsPublicInj, ref(false))
const { $api } = useNuxtApp()
+const { t } = useI18n()
+
const rowId = computed(() => {
return extractPkFromRow(currentRow.value?.row, meta.value!.columns!)
})
@@ -45,8 +47,10 @@ const pk = computed(() => {
return extractPkFromRow(currentRow.value?.row, meta.value.columns)
})
+const isAiButtonType = computed(() => column.value?.colOptions?.type === ButtonActionsType.Ai)
+
const isFieldAiIntegrationAvailable = computed(() => {
- if (column.value?.colOptions?.type !== ButtonActionsType.Ai) return true
+ if (!isAiButtonType.value) return true
const fkIntegrationId = column.value?.colOptions?.fk_integration_id
@@ -96,6 +100,8 @@ const isExecuting = computed(
fieldIDRowMapping.value.get(`${pk.value}:${column.value.id}`) === 'running',
)
+const invalidUrlTooltip = ref('')
+
const componentProps = computed(() => {
if (column.value.colOptions.type === ButtonActionsType.Url) {
let url = addMissingUrlSchma(cellValue.value?.url)
@@ -107,12 +113,14 @@ const componentProps = computed(() => {
url = encodeURI(url)
}
+ const isValidUrl = isValidURL(url, { require_tld: !appInfo.value?.allowLocalUrl })
+
+ invalidUrlTooltip.value = !isValidUrl ? t('msg.error.invalidURL') : ''
+
return {
href: url,
target: '_blank',
- ...(column.value?.colOptions.error || !isValidURL(url, { require_tld: !appInfo.value?.allowLocalUrl })
- ? { disabled: true }
- : {}),
+ ...(column.value?.colOptions.error || !isValidUrl ? { disabled: true } : {}),
}
} else if (column.value.colOptions.type === ButtonActionsType.Webhook) {
return {
@@ -189,9 +197,18 @@ const triggerAction = async () => {
}"
class="w-full flex items-center"
>
- <NcTooltip :disabled="isFieldAiIntegrationAvailable || isPublic || !isUIAllowed('dataEdit')" class="flex">
+ <NcTooltip
+ :disabled="isAiButtonType ? isFieldAiIntegrationAvailable || isPublic || !isUIAllowed('dataEdit') : !invalidUrlTooltip"
+ class="flex"
+ >
<template #title>
- {{ aiIntegrations.length ? $t('tooltip.aiIntegrationReConfigure') : $t('tooltip.aiIntegrationAddAndReConfigure') }}
+ {{
+ isAiButtonType
+ ? aiIntegrations.length
+ ? $t('tooltip.aiIntegrationReConfigure')
+ : $t('tooltip.aiIntegrationAddAndReConfigure')
+ : invalidUrlTooltip
+ }}
</template>
<component
:is="column.colOptions.type === ButtonActionsType.Url ? 'a' : 'button'"
diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.ts
index b6fe3c3563..7fea9325b9 100644
--- a/packages/nc-gui/lib/types.ts
+++ b/packages/nc-gui/lib/types.ts
@@ -511,6 +511,7 @@ interface CellRenderStore {
hoverValue: number
}
ltar?: { oldX?: number; oldY?: number; x?: number; y?: number; width?: number; height?: number; value?: any }[]
+ [key: string]: any
}
type CursorType = CSSProperties['cursor']
@@ -555,6 +556,7 @@ interface CellRenderer {
openDetachedLongText: (props: UseDetachedLongTextProps) => void
formula?: boolean
allowLocalUrl?: boolean
+ t: Composer['t']
}) => Promise<boolean>
handleKeyDown?: (options: {
e: KeyboardEvent
@@ -577,6 +579,7 @@ interface CellRenderer {
cellRenderStore: CellRenderStore
openDetachedLongText: (props: UseDetachedLongTextProps) => void
allowLocalUrl?: boolean
+ t: Composer['t']
}) => Promise<boolean | void>
handleHover?: (options: {
event: MouseEvent
@@ -602,6 +605,7 @@ interface CellRenderer {
setCursor: SetCursorType
path: Array<number>
baseUsers?: (Partial<UserType> | Partial<User>)[]
+ t: Composer['t']
}) => Promise<void>
[key: string]: any
}
diff --git a/packages/nc-gui/utils/columnUtils.ts b/packages/nc-gui/utils/columnUtils.ts
index 4577a767dc..8ec18b8f2d 100644
--- a/packages/nc-gui/utils/columnUtils.ts
+++ b/packages/nc-gui/utils/columnUtils.ts
@@ -305,7 +305,7 @@ const isColumnInvalid = (
result.isInvalid = !colOptions.fk_webhook_id
} else if (colOptions.type === ButtonActionsType.Url) {
result.isInvalid = !!colOptions.error
- } else if (colOptions.type === ButtonActionsType.AI) {
+ } else if (colOptions.type === ButtonActionsType.Ai) {
result.isInvalid =
!colOptions.fk_integration_id ||
(isReadOnly