Browse Source

feat(nc-gui): use simple label for skeleton and show table names in regular labels

pull/4071/head
braks 2 years ago
parent
commit
7653964116
  1. 7
      packages/nc-gui/components/erd/RelationEdge.vue
  2. 9
      packages/nc-gui/components/erd/utils.ts

7
packages/nc-gui/components/erd/RelationEdge.vue

@ -98,10 +98,13 @@ export default {
<EdgeText <EdgeText
v-if="data.label?.length > 0 && (selected || isHovering)" v-if="data.label?.length > 0 && (selected || isHovering)"
:key="`edge-text-${id}.${showSkeleton}`" :key="`edge-text-${id}.${showSkeleton}`"
:class="`nc-erd-table-label-${data.label.toLowerCase().replace(' ', '-').replace('\(', '').replace(')', '')}`" :class="[
showSkeleton ? '!text-5xl' : '!text-xs',
`nc-erd-table-label-${data.label.toLowerCase().replace(' ', '-').replace('\(', '').replace(')', '')}`,
]"
:x="edgePath[1]" :x="edgePath[1]"
:y="edgePath[2]" :y="edgePath[2]"
:label="data.label" :label="showSkeleton ? data.simpleLabel : data.label"
:label-style="{ fill: 'white', fontSize: `${showSkeleton ? baseStroke * 2 : baseStroke / 2}rem` }" :label-style="{ fill: 'white', fontSize: `${showSkeleton ? baseStroke * 2 : baseStroke / 2}rem` }"
:label-show-bg="true" :label-show-bg="true"
:label-bg-style="{ fill: data.color }" :label-bg-style="{ fill: data.color }"

9
packages/nc-gui/components/erd/utils.ts

@ -97,7 +97,7 @@ export function useErdElements(tables: MaybeRef<TableType[]>, props: MaybeRef<Er
}, [] as Relation[]), }, [] as Relation[]),
) )
function edgeLabel({ type, source, target, modelId, childColId, parentColId }: Relation) { function edgeLabel({ type, source, target, modelId, childColId, parentColId }: Relation, simple = false) {
const typeLabel = type === 'mm' ? 'many to many' : 'has many' const typeLabel = type === 'mm' ? 'many to many' : 'has many'
const parentCol = metasWithIdAsKey.value[source].columns?.find((col) => { const parentCol = metasWithIdAsKey.value[source].columns?.find((col) => {
@ -136,7 +136,11 @@ export function useErdElements(tables: MaybeRef<TableType[]>, props: MaybeRef<Er
} }
} }
return `${parentCol.title} ${typeLabel} ${childCol.title}` if (simple) {
return `${metasWithIdAsKey.value[source].title} ${type} ${metasWithIdAsKey.value[target].title}`
}
return `[${metasWithIdAsKey.value[source].title}] ${parentCol.title} ${typeLabel} ${childCol.title} [${metasWithIdAsKey.value[target].title}]`
} }
function createNodes() { function createNodes() {
@ -212,6 +216,7 @@ export function useErdElements(tables: MaybeRef<TableType[]>, props: MaybeRef<Er
isManyToMany: type === 'mm', isManyToMany: type === 'mm',
isSelfRelation: source === target && sourceColumnId === targetColumnId, isSelfRelation: source === target && sourceColumnId === targetColumnId,
label: edgeLabel({ type, source, target, childColId, parentColId, modelId }), label: edgeLabel({ type, source, target, childColId, parentColId, modelId }),
simpleLabel: edgeLabel({ type, source, target, childColId, parentColId, modelId }, true),
}, },
} as Edge) } as Edge)

Loading…
Cancel
Save