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.
39 lines
1.0 KiB
39 lines
1.0 KiB
import type { TableType } from 'nocodb-sdk' |
|
import { useNuxtApp, useState } from '#app' |
|
import { useUser } from '~/composables/user' |
|
import { useProject } from '~/composables/project' |
|
|
|
export const useMetas = () => { |
|
const { $api } = useNuxtApp() |
|
const { user } = useUser() |
|
const { tables } = useProject() |
|
|
|
const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({})) |
|
|
|
const getMeta = async (tableIdOrTitle: string, force = false) => { |
|
if (!force && metas[tableIdOrTitle]) |
|
return metas[tableIdOrTitle] |
|
|
|
const modelId = (tables.value.find(t => t.title === tableIdOrTitle || t.id === tableIdOrTitle) || {}).id |
|
if (!modelId) { |
|
console.warn(`Table '${tableIdOrTitle}' is not found in the table list`) |
|
return |
|
} |
|
|
|
const model = await $api.dbTable.read(modelId, { |
|
headers: { |
|
'xc-auth': user.token, |
|
}, |
|
}) |
|
|
|
metas.value = { |
|
...metas.value, |
|
[model.id]: model, |
|
[model.title]: model, |
|
} |
|
|
|
return model |
|
} |
|
|
|
return { getMeta, metas } |
|
}
|
|
|