mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
940 B
33 lines
940 B
2 years ago
|
import type { TableType } from 'nocodb-sdk'
|
||
3 years ago
|
import { useNuxtApp, useState } from '#app'
|
||
2 years ago
|
import useProject from "~/composables/useProject";
|
||
3 years ago
|
|
||
2 years ago
|
export default () => {
|
||
3 years ago
|
const { $api } = useNuxtApp()
|
||
|
const { tables } = useProject()
|
||
3 years ago
|
|
||
|
const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({}))
|
||
|
|
||
|
const getMeta = async (tableIdOrTitle: string, force = false) => {
|
||
2 years ago
|
if (!force && metas[tableIdOrTitle as keyof typeof metas]) return metas[tableIdOrTitle as keyof typeof metas]
|
||
3 years ago
|
|
||
2 years ago
|
const modelId = (tables.value.find((t) => t.title === tableIdOrTitle || t.id === tableIdOrTitle) || {}).id
|
||
3 years ago
|
if (!modelId) {
|
||
|
console.warn(`Table '${tableIdOrTitle}' is not found in the table list`)
|
||
|
return
|
||
|
}
|
||
|
|
||
2 years ago
|
const model = await $api.dbTable.read(modelId)
|
||
3 years ago
|
|
||
|
metas.value = {
|
||
|
...metas.value,
|
||
2 years ago
|
[model.id!]: model,
|
||
3 years ago
|
[model.title]: model,
|
||
3 years ago
|
}
|
||
|
|
||
|
return model
|
||
|
}
|
||
|
|
||
3 years ago
|
return { getMeta, metas }
|
||
3 years ago
|
}
|