fix(editor): Paginate through all data tables when checking name collisions

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Charlie Kolb 2026-05-11 12:09:54 +02:00
parent af6cbe4d85
commit 4b7951218c
No known key found for this signature in database

View File

@ -133,16 +133,26 @@ export const useDataTableStore = defineStore(DATA_TABLE_STORE, () => {
projectId: string,
): Promise<string> => {
const MAX_NAME_LENGTH = 128;
const PAGE_SIZE = 250;
const trimmed = baseName.trim().slice(0, MAX_NAME_LENGTH).trim();
if (!trimmed || !projectId) return trimmed;
const response = await fetchDataTablesApi(
rootStore.restApiContext,
projectId,
{ skip: 0, take: 100 },
{ name: trimmed },
);
const existingNames = new Set(response.data.map((t) => t.name.toLowerCase()));
const existingNames = new Set<string>();
let skip = 0;
while (true) {
const response = await fetchDataTablesApi(
rootStore.restApiContext,
projectId,
{ skip, take: PAGE_SIZE },
{ name: trimmed },
);
for (const t of response.data) {
existingNames.add(t.name.toLowerCase());
}
skip += response.data.length;
if (response.data.length < PAGE_SIZE || skip >= response.count) break;
}
if (!existingNames.has(trimmed.toLowerCase())) return trimmed;
const buildCandidate = (n: number): string => {