Skip to content

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

feat: show fields involved if relation is custom or in external db

Pranav Cfef83a114dd1
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue b/packages/nc-gui/components/smartsheet/grid/canvas/index.vue
index 41f24d1873..58d8bdd229 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/index.vue
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/index.vue
@@ -22,7 +22,7 @@ import Aggregation from './context/Aggregation.vue'
import { clearTextCache, defaultOffscreen2DContext, isBoxHovered, renderSingleLineText } from './utils/canvas'
import Tooltip from './components/Tooltip.vue'
import Scroller from './components/Scroller.vue'
-import { columnTypeName } from './utils/headerUtils'
+import { columnTypeName, getCustomColumnTooltip } from './utils/headerUtils'
import { MouseClickType, NO_EDITABLE_CELL, getMouseClickType, parseCellWidth } from './utils/cell'
import {
ADD_NEW_COLUMN_WIDTH,
@@ -163,6 +163,8 @@ const vSelectedAllRecords = useVModel(props, 'selectedAllRecords', emits)
const { eventBus, isSqlView } = useSmartsheetStoreOrThrow()
+const { metas, getMeta } = useMetas()
+
const { withLoading } = useLoadingTrigger()
const { showRecordPlanLimitExceededModal, navigateToPricing } = useEeConfig()
@@ -1667,12 +1669,14 @@ const getHeaderTooltipRegions = (
type: 'columnIcon' | 'title' | 'error' | 'info' | 'columnChevron'
text: string
disableTooltip?: boolean
+ tooltipText?: boolean
}[] => {
const regions: {
x: number
width: number
type: 'columnIcon' | 'title' | 'error' | 'info' | 'columnChevron'
text: string
+ tooltipText?: string
height?: number
y?: number
disableTooltip?: boolean
@@ -1694,14 +1698,17 @@ const getHeaderTooltipRegions = (
const rightPadding = 8
let totalIconWidth = rightPadding + 16
+ let tooltipText: string
if (column.uidt) {
totalIconWidth += 26
+ tooltipText = getCustomColumnTooltip({ column, metas: metas.value, isExternalLink: true, getMeta })
regions.push({
x: xOffset + 8 - scrollLeftValue,
width: 13,
type: 'columnIcon',
text: columnTypeName(column),
+ tooltipText,
})
}
@@ -1723,7 +1730,8 @@ const getHeaderTooltipRegions = (
width: Math.max(column.uidt ? 0 : 16, isTruncated ? availableTextWidth : measuredTextWidth),
type: 'title',
text: column.title!,
- disableTooltip: !isTruncated,
+ tooltipText,
+ disableTooltip: !isTruncated && !tooltipText,
})
let rightOffset = xOffset + width - rightPadding - (isFieldEditAllowed.value ? 16 : 0)
@@ -1821,7 +1829,7 @@ const handleMouseMove = (e: MouseEvent) => {
if (activeFixedRegion && !activeFixedRegion.disableTooltip) {
tryShowTooltip({
rect: activeFixedRegion,
- text: activeFixedRegion.text,
+ text: activeFixedRegion.tooltipText || activeFixedRegion.text,
mousePosition,
})
}
@@ -1856,7 +1864,7 @@ const handleMouseMove = (e: MouseEvent) => {
if (activeRegion && !activeRegion.disableTooltip) {
tryShowTooltip({
rect: activeRegion,
- text: activeRegion.text,
+ text: activeRegion.tooltipText || activeRegion.text,
mousePosition,
})
}
diff --git a/packages/nc-gui/components/smartsheet/grid/canvas/utils/headerUtils.ts b/packages/nc-gui/components/smartsheet/grid/canvas/utils/headerUtils.ts
index 61116a0e22..2edb7e3ae3 100644
--- a/packages/nc-gui/components/smartsheet/grid/canvas/utils/headerUtils.ts
+++ b/packages/nc-gui/components/smartsheet/grid/canvas/utils/headerUtils.ts
@@ -1,4 +1,6 @@
-import { UITypes, UITypesName } from 'nocodb-sdk'
+import type { LinkToAnotherRecordType, TableType } from 'nocodb-sdk'
+import { RelationTypes, UITypes, UITypesName, isLinksOrLTAR } from 'nocodb-sdk'
+import type { CanvasGridColumn } from '~/lib/types'
export function columnTypeName(column: CanvasGridColumn) {
if (column?.columnObj.uidt === UITypes.LongText) {
@@ -13,3 +15,78 @@ export function columnTypeName(column: CanvasGridColumn) {
return column.columnObj.uidt ? UITypesName[column.columnObj.uidt!] : ''
}
+export function getCustomColumnTooltip({
+ column,
+ metas,
+ getMeta,
+ isExternalLink = false,
+}: {
+ column: CanvasGridColumn
+ metas: Record<string, TableType>
+ isExternalLink: boolean
+ getMeta?: (tableId: string) => Promise<TableType>
+}): string {
+ if (!isLinksOrLTAR(column.columnObj)) {
+ return
+ }
+ const relOptions = column.columnObj.colOptions as LinkToAnotherRecordType
+
+ if (!isExternalLink && !column.columnObj?.meta?.custom) {
+ return
+ }
+
+ if (!relOptions) return
+
+ const currentTable = metas[column.columnObj.fk_model_id]
+ const refTable = metas[relOptions.fk_related_model_id]
+ let mmTable: TableType
+ if (relOptions.type === RelationTypes.MANY_TO_MANY) {
+ if (metas[relOptions.fk_mm_model_id]) {
+ mmTable = metas[relOptions.fk_mm_model_id]
+ } else {
+ // if metas not found in store, fetch it
+ getMeta?.(relOptions.fk_mm_model_id).catch((e) => {
+ // do nothing
+ })
+ }
+ }
+
+ let currentTableColName = ''
+ let refTableColName = ''
+ let mmTableColName = ''
+ let mmTableRefColName = ''
+
+ if (
+ relOptions.type === RelationTypes.MANY_TO_MANY ||
+ relOptions.type === RelationTypes.BELONGS_TO ||
+ (relOptions.type === RelationTypes.ONE_TO_ONE && column.columnObj?.meta?.bt)
+ ) {
+ currentTableColName = currentTable?.columns?.find((c) => c.id === relOptions.fk_child_column_id)?.title
+ refTableColName = refTable?.columns?.find((c) => c.id === relOptions.fk_parent_column_id)?.title
+ if (mmTable) {
+ mmTableColName = mmTable?.columns?.find((c) => c.id === relOptions.fk_mm_child_column_id)?.title
+ mmTableRefColName = mmTable?.columns?.find((c) => c.id === relOptions.fk_mm_parent_column_id)?.title
+ }
+ } else {
+ currentTableColName = currentTable?.columns?.find((c) => c.id === relOptions.fk_parent_column_id)?.title
+ refTableColName = refTable?.columns?.find((c) => c.id === relOptions.fk_child_column_id)?.title
+ }
+
+ // generate a detailed tooltip for link to another record with relation columns and many to many table
+ // including column names from the current table, related table and many to many table
+ // Format: "Link column: Current table(column in current table) -> Related Table (column in related table)"
+ const tooltip = `${columnTypeName(column)}:\n\n ${[
+ currentTable?.title,
+ currentTableColName ? `(${currentTableColName})` : '',
+ ' β†’ ',
+ refTable?.title,
+ refTableColName ? `(${refTableColName})` : '',
+ mmTable ? '\n\nVia ' : '',
+ mmTable ? mmTable.title : '',
+ mmTableRefColName ? `(${mmTableRefColName})` : '',
+ mmTable && mmTableColName ? ',' : '',
+ mmTableColName ? `(${mmTableColName})` : '',
+ ].join('')}`
+
+ return tooltip
+}