|
|
|
@ -6,7 +6,8 @@ import { extractSdkResponseErrorMsg, storeToRefs, useBase, useNuxtApp, useState,
|
|
|
|
|
export function useMetas() { |
|
|
|
|
const { $api } = useNuxtApp() |
|
|
|
|
|
|
|
|
|
const { tables } = storeToRefs(useBase()) |
|
|
|
|
const { tables: _tables } = storeToRefs(useBase()) |
|
|
|
|
const { baseTables } = storeToRefs(useTablesStore()) |
|
|
|
|
|
|
|
|
|
const metas = useState<{ [idOrTitle: string]: TableType | any }>('metas', () => ({})) |
|
|
|
|
|
|
|
|
@ -26,8 +27,16 @@ export function useMetas() {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// todo: this needs a proper refactor, arbitrary waiting times are usually not a good idea
|
|
|
|
|
const getMeta = async (tableIdOrTitle: string, force = false, skipIfCacheMiss = false): Promise<TableType | null> => { |
|
|
|
|
const getMeta = async ( |
|
|
|
|
tableIdOrTitle: string, |
|
|
|
|
force = false, |
|
|
|
|
skipIfCacheMiss = false, |
|
|
|
|
baseId?: string, |
|
|
|
|
): Promise<TableType | null> => { |
|
|
|
|
if (!tableIdOrTitle) return null |
|
|
|
|
|
|
|
|
|
const tables = (baseId ? baseTables.value.get(baseId) : _tables.value) ?? [] |
|
|
|
|
|
|
|
|
|
/** wait until loading is finished if requesting same meta |
|
|
|
|
* use while to recheck loading state since it can be changed by other requests |
|
|
|
|
* */ |
|
|
|
@ -72,8 +81,7 @@ export function useMetas() {
|
|
|
|
|
return metas.value[tableIdOrTitle] |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const modelId = (tables.value.find((t) => t.id === tableIdOrTitle) || tables.value.find((t) => t.title === tableIdOrTitle)) |
|
|
|
|
?.id |
|
|
|
|
const modelId = (tables.find((t) => t.id === tableIdOrTitle) || tables.find((t) => t.title === tableIdOrTitle))?.id |
|
|
|
|
|
|
|
|
|
if (!modelId) { |
|
|
|
|
console.warn(`Table '${tableIdOrTitle}' is not found in the table list`) |
|
|
|
|