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.
43 lines
1.2 KiB
43 lines
1.2 KiB
import type { TableInfoType, TableType } from 'nocodb-sdk' |
|
import { useNuxtApp, useState } from '#app' |
|
import { useProject } from '#imports' |
|
|
|
export default () => { |
|
const { $api } = useNuxtApp() |
|
const { tables } = useProject() |
|
|
|
const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({})) |
|
|
|
const getMeta = async (tableIdOrTitle: string, force = false): Promise<TableType | TableInfoType | null> => { |
|
if (!force && metas.value[tableIdOrTitle as string]) return metas.value[tableIdOrTitle as string] |
|
|
|
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 null |
|
} |
|
|
|
const model = await $api.dbTable.read(modelId) |
|
|
|
metas.value = { |
|
...metas.value, |
|
[model.id!]: model, |
|
[model.title]: model, |
|
} |
|
|
|
return model |
|
} |
|
|
|
const clearAllMeta = () => { |
|
metas.value = {} |
|
} |
|
const removeMeta = (idOrTitle: string) => { |
|
const meta = metas.value[idOrTitle] |
|
if (meta) { |
|
delete metas.value[meta.id] |
|
delete metas.value[meta.title] |
|
} |
|
} |
|
|
|
return { getMeta, clearAllMeta, metas, removeMeta } |
|
}
|
|
|