mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-04-22 01:24:21 +01:00
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.
|
// 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 React from "react";
|
||||||
import { ActionContracts } from "../../Contracts/ExplorerContracts";
|
import { ActionContracts } from "../../Contracts/ExplorerContracts";
|
||||||
import * as ViewModels from "../../Contracts/ViewModels";
|
import * as ViewModels from "../../Contracts/ViewModels";
|
||||||
@ -40,12 +41,26 @@ function openCollectionTab(
|
|||||||
databases: ViewModels.Database[],
|
databases: ViewModels.Database[],
|
||||||
initialDatabaseIndex = 0,
|
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++) {
|
for (let i = initialDatabaseIndex; i < databases.length; i++) {
|
||||||
const database: ViewModels.Database = databases[i];
|
const database: ViewModels.Database = databases[i];
|
||||||
if (!!action.databaseResourceId && database.id() !== action.databaseResourceId) {
|
if (!!action.databaseResourceId && database.id() !== action.databaseResourceId) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//expand database first if not expanded to load the collections
|
||||||
|
if (!database.isDatabaseExpanded?.()) {
|
||||||
|
database.expandDatabase?.();
|
||||||
|
}
|
||||||
|
|
||||||
const collectionActionHandler = (collections: ViewModels.Collection[]) => {
|
const collectionActionHandler = (collections: ViewModels.Collection[]) => {
|
||||||
if (!action.collectionResourceId && collections.length === 0) {
|
if (!action.collectionResourceId && collections.length === 0) {
|
||||||
subscription.dispose();
|
subscription.dispose();
|
||||||
@ -132,6 +147,7 @@ function openCollectionTab(
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function openPane(action: ActionContracts.OpenPane, explorer: Explorer) {
|
function openPane(action: ActionContracts.OpenPane, explorer: Explorer) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user