fix opening collections (#1780)
* fix opening collections * fix opening collections * fix opening collections * fix opening collections
This commit is contained in:
parent
f24b0bcf1b
commit
5aa6b0abe1
|
@ -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 (
|
||||
|
|
Loading…
Reference in New Issue