Browse Source

feat/Minor cleanup

pull/3612/head
Muhammed Mustafa 2 years ago
parent
commit
1f29380b7a
  1. 2
      packages/nc-gui/components/erd/TableNode.vue
  2. 12
      packages/nc-gui/components/erd/View.vue
  3. 6
      packages/nc-gui/composables/useMetas.ts

2
packages/nc-gui/components/erd/TableNode.vue

@ -14,7 +14,7 @@ const { data } = toRefs(props)
provide(MetaInj, data) provide(MetaInj, data)
const columns = computed(() => { const columns = computed(() => {
// Hide hm related created for `mm` relations // Hide hm ltar created for `mm` relations
return data.value.columns.filter((col) => !(col.uidt === UITypes.LinkToAnotherRecord && col.system === 1)) return data.value.columns.filter((col) => !(col.uidt === UITypes.LinkToAnotherRecord && col.system === 1))
}) })

12
packages/nc-gui/components/erd/View.vue

@ -16,7 +16,7 @@ interface Props {
const { tables, config } = defineProps<Props>() const { tables, config } = defineProps<Props>()
const { metasWithId } = useMetas() const { metasWithIdAsKey } = useMetas()
const initialNodes = ref<Pick<Node, 'id' | 'data' | 'type'>[]>([]) const initialNodes = ref<Pick<Node, 'id' | 'data' | 'type'>[]>([])
const nodes = ref<Node[]>([]) const nodes = ref<Node[]>([])
@ -29,11 +29,11 @@ const populateInitalNodes = () => {
tables.forEach((table) => { tables.forEach((table) => {
if (!table.id) return if (!table.id) return
dagreGraph.setNode(table.id, { width: 250, height: 50 * metasWithId.value[table.id].columns.length }) dagreGraph.setNode(table.id, { width: 250, height: 50 * metasWithIdAsKey.value[table.id].columns.length })
initialNodes.value.push({ initialNodes.value.push({
id: table.id, id: table.id,
data: { ...metasWithId.value[table.id], showPkAndFk: config.showPkAndFk }, data: { ...metasWithIdAsKey.value[table.id], showPkAndFk: config.showPkAndFk },
type: 'custom', type: 'custom',
}) })
}) })
@ -43,10 +43,10 @@ const populateInitalNodes = () => {
const populateEdges = () => { const populateEdges = () => {
const ltarColumns = tables.reduce((acc: any[], table) => { const ltarColumns = tables.reduce((acc: any[], table) => {
const meta = metasWithId.value[table.id!] const meta = metasWithIdAsKey.value[table.id!]
const ltarColumns = meta.columns.filter((column: any) => column.uidt === UITypes.LinkToAnotherRecord && column.system !== 1) const columns = meta.columns.filter((column: any) => column.uidt === UITypes.LinkToAnotherRecord && column.system !== 1)
ltarColumns.forEach((column: any) => { columns.forEach((column: any) => {
if (column.colOptions.type === 'hm') { if (column.colOptions.type === 'hm') {
acc.push(column) acc.push(column)
} }

6
packages/nc-gui/composables/useMetas.ts

@ -10,10 +10,12 @@ export function useMetas() {
const { tables } = useProject() const { tables } = useProject()
const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({})) const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({}))
const metasWithId = computed(() => {
const metasWithIdAsKey = computed(() => {
const idEntries = Object.entries(metas.value).filter(([k, v]) => k === v.id) const idEntries = Object.entries(metas.value).filter(([k, v]) => k === v.id)
return Object.fromEntries(idEntries) return Object.fromEntries(idEntries)
}) })
const loadingState = useState<Record<string, boolean>>('metas-loading-state', () => ({})) const loadingState = useState<Record<string, boolean>>('metas-loading-state', () => ({}))
const setMeta = async (model: any) => { const setMeta = async (model: any) => {
@ -95,5 +97,5 @@ export function useMetas() {
} }
} }
return { getMeta, clearAllMeta, metas, metasWithId, removeMeta, setMeta } return { getMeta, clearAllMeta, metas, metasWithIdAsKey, removeMeta, setMeta }
} }

Loading…
Cancel
Save