mirror of
https://github.com/Syngnat/GoNavi.git
synced 2026-08-05 05:18:05 +08:00
✨ feat(sidebar): 支持表元数据显示配置
- 新增侧栏表元数据字段配置并兼容旧版表备注开关 - 设置中心新增侧栏表元数据入口并移除树上重复显示开关 - 批量补齐表大小、创建时间、修改时间等元数据加载与渲染 - 统一表元数据格式化逻辑并修复 V2 左树横向滚动裁切 - 补充设置中心、store、侧栏元数据相关回归测试与多语言文案
This commit is contained in:
@@ -7,8 +7,13 @@ import {
|
||||
resolveSidebarRootOrderTokens,
|
||||
} from '../store';
|
||||
import type { ConnectionTag, SavedConnection } from '../types';
|
||||
import type { SidebarTableMetadataField } from '../utils/sidebarTableMetadata';
|
||||
import { t } from '../i18n';
|
||||
import { t as catalogTranslate } from '../i18n/catalog';
|
||||
import {
|
||||
buildSidebarTableMetadataDisplayItems,
|
||||
buildSidebarTableMetadataSnapshot,
|
||||
} from './sidebar/sidebarHelpers';
|
||||
|
||||
type SidebarV2Translate = (key: string) => string;
|
||||
|
||||
@@ -327,12 +332,15 @@ const V2_TREE_HORIZONTAL_SCROLL_MAX_WIDTH = 2600;
|
||||
const V2_TREE_HORIZONTAL_SCROLL_BASE_WIDTH = 88;
|
||||
const V2_TREE_HORIZONTAL_SCROLL_INDENT_WIDTH = 24;
|
||||
const V2_TREE_HORIZONTAL_SCROLL_AVG_CHAR_WIDTH = 8;
|
||||
const V2_TREE_HORIZONTAL_SCROLL_ITEM_GAP_WIDTH = 5;
|
||||
const V2_TREE_HORIZONTAL_SCROLL_COMMENT_MAX_CHARS = 32;
|
||||
const V2_TREE_HORIZONTAL_SCROLL_VIEWPORT_BUFFER = 48;
|
||||
export const V2_TREE_HORIZONTAL_SCROLL_BOTTOM_RESERVE = 32;
|
||||
|
||||
export const estimateV2TreeHorizontalScrollWidth = (
|
||||
nodes: SidebarTreeNode[],
|
||||
viewportWidth: number,
|
||||
sidebarTableMetadataFields: SidebarTableMetadataField[] = [],
|
||||
): number | undefined => {
|
||||
const safeViewportWidth = Math.max(0, Math.ceil(viewportWidth || 0));
|
||||
let estimatedContentWidth = safeViewportWidth;
|
||||
@@ -340,12 +348,30 @@ export const estimateV2TreeHorizontalScrollWidth = (
|
||||
const visit = (items: SidebarTreeNode[], depth: number) => {
|
||||
items.forEach((node) => {
|
||||
const title = String(node?.title || '');
|
||||
const metaText = node?.dataRef?.groupKey === 'tables' && Array.isArray(node.children)
|
||||
? String(node.children.length)
|
||||
: '';
|
||||
const tableMetadataItems = node?.type === 'table'
|
||||
? buildSidebarTableMetadataDisplayItems(
|
||||
sidebarTableMetadataFields,
|
||||
buildSidebarTableMetadataSnapshot(node?.dataRef),
|
||||
)
|
||||
: [];
|
||||
const metaText = tableMetadataItems.length > 0
|
||||
? tableMetadataItems
|
||||
.map((item) => item.key === 'comment'
|
||||
? item.text.slice(0, V2_TREE_HORIZONTAL_SCROLL_COMMENT_MAX_CHARS)
|
||||
: item.text)
|
||||
.join('')
|
||||
: node?.dataRef?.groupKey === 'tables' && Array.isArray(node.children)
|
||||
? String(node.children.length)
|
||||
: '';
|
||||
const metaItemCount = tableMetadataItems.length > 0
|
||||
? tableMetadataItems.length
|
||||
: metaText
|
||||
? 1
|
||||
: 0;
|
||||
const nodeWidth = V2_TREE_HORIZONTAL_SCROLL_BASE_WIDTH
|
||||
+ (depth * V2_TREE_HORIZONTAL_SCROLL_INDENT_WIDTH)
|
||||
+ ((title.length + metaText.length) * V2_TREE_HORIZONTAL_SCROLL_AVG_CHAR_WIDTH);
|
||||
+ ((title.length + metaText.length) * V2_TREE_HORIZONTAL_SCROLL_AVG_CHAR_WIDTH)
|
||||
+ (metaItemCount * V2_TREE_HORIZONTAL_SCROLL_ITEM_GAP_WIDTH);
|
||||
estimatedContentWidth = Math.max(estimatedContentWidth, nodeWidth);
|
||||
if (node.children?.length) {
|
||||
visit(node.children, depth + 1);
|
||||
|
||||
Reference in New Issue
Block a user