mirror of
https://github.com/appwrite/console.git
synced 2026-06-06 19:27:48 +00:00
update: backwards compat on key scopes.
This commit is contained in:
@@ -9,8 +9,14 @@
|
||||
|
||||
const newScopes = ['tables.', 'columns.', 'rows.'];
|
||||
const legacyScopes = ['attributes.', 'collections.', 'documents.'];
|
||||
const compatPairs = [
|
||||
{ newer: 'tables.', legacy: 'collections.' },
|
||||
{ newer: 'columns.', legacy: 'attributes.' },
|
||||
{ newer: 'rows.', legacy: 'documents.' }
|
||||
] as const;
|
||||
|
||||
const isCreateMode = scopes.length === 0;
|
||||
const scopeCatalog = new Set(allScopes.map((s) => s.scope));
|
||||
|
||||
const hasLegacyScopes = !isCreateMode
|
||||
? scopes.some((scope) => legacyScopes.some((prefix) => scope?.startsWith(prefix)))
|
||||
@@ -57,9 +63,12 @@
|
||||
let mounted = false;
|
||||
|
||||
onMount(() => {
|
||||
scopes.forEach((scope) => {
|
||||
activeScopes[scope] = true;
|
||||
});
|
||||
const computedScopes = syncScopes(scopes);
|
||||
if (symmetricDifference(scopes, computedScopes).length) {
|
||||
scopes = computedScopes;
|
||||
}
|
||||
|
||||
scopes.forEach((scope) => (activeScopes[scope] = true));
|
||||
|
||||
mounted = true;
|
||||
});
|
||||
@@ -83,9 +92,8 @@
|
||||
return false;
|
||||
} else if (filtered.length === scopesByCategory.length) {
|
||||
return true;
|
||||
} else {
|
||||
return 'indeterminate';
|
||||
}
|
||||
return 'indeterminate';
|
||||
}
|
||||
|
||||
function onCategoryChange(event: CustomEvent<boolean | 'indeterminate'>, category: Category) {
|
||||
@@ -97,6 +105,25 @@
|
||||
});
|
||||
}
|
||||
|
||||
function syncScopes(list: string[]): string[] {
|
||||
const out = new Set(list);
|
||||
const pairs = compatPairs.map((pair) =>
|
||||
hasLegacyScopes
|
||||
? ([pair.legacy, pair.newer] as const)
|
||||
: ([pair.newer, pair.legacy] as const)
|
||||
);
|
||||
|
||||
for (const scope of list) {
|
||||
for (const [from, to] of pairs) {
|
||||
if (scope.startsWith(from)) {
|
||||
const counterpart = scope.replace(from, to);
|
||||
if (scopeCatalog.has(counterpart)) out.add(counterpart);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Array.from(out);
|
||||
}
|
||||
|
||||
const activeScopes = filteredScopes.reduce((prev, next) => {
|
||||
prev[next.scope] = false;
|
||||
|
||||
@@ -109,8 +136,10 @@
|
||||
.filter((scope) => activeScopes[scope.scope])
|
||||
.map(({ scope }) => scope);
|
||||
|
||||
if (symmetricDifference(scopes, newScopeSet).length) {
|
||||
scopes = newScopeSet;
|
||||
const updatedScopes = hasLegacyScopes ? newScopeSet : syncScopes(newScopeSet);
|
||||
|
||||
if (symmetricDifference(scopes, updatedScopes).length) {
|
||||
scopes = updatedScopes;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user