fix opening collections (#1780)

* fix opening collections

* fix opening collections

* fix opening collections

* fix opening collections
This commit is contained in:
sunghyunkang1111 2024-03-28 12:10:32 -05:00 committed by GitHub
parent f24b0bcf1b
commit 5aa6b0abe1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 104 additions and 88 deletions

View File

@ -1,4 +1,5 @@
// TODO convert this file to an action registry in order to have actions and their handlers be more tightly coupled.
import { useDatabases } from "Explorer/useDatabases";
import React from "react";
import { ActionContracts } from "../../Contracts/ExplorerContracts";
import * as ViewModels from "../../Contracts/ViewModels";
@ -40,12 +41,26 @@ function openCollectionTab(
databases: ViewModels.Database[],
initialDatabaseIndex = 0,
) {
//if databases are not yet loaded, wait until loaded
if (!databases || databases.length === 0) {
const databaseActionHandler = (databases: ViewModels.Database[]) => {
databasesUnsubscription();
openCollectionTab(action, databases, 0);
return;
};
const databasesUnsubscription = useDatabases.subscribe(databaseActionHandler, (state) => state.databases);
} else {
for (let i = initialDatabaseIndex; i < databases.length; i++) {
const database: ViewModels.Database = databases[i];
if (!!action.databaseResourceId && database.id() !== action.databaseResourceId) {
continue;
}
//expand database first if not expanded to load the collections
if (!database.isDatabaseExpanded?.()) {
database.expandDatabase?.();
}
const collectionActionHandler = (collections: ViewModels.Collection[]) => {
if (!action.collectionResourceId && collections.length === 0) {
subscription.dispose();
@ -133,6 +148,7 @@ function openCollectionTab(
break;
}
}
}
function openPane(action: ActionContracts.OpenPane, explorer: Explorer) {
if (