mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-02-16 17:25:58 +00: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,97 +41,112 @@ function openCollectionTab(
|
|||||||
databases: ViewModels.Database[],
|
databases: ViewModels.Database[],
|
||||||
initialDatabaseIndex = 0,
|
initialDatabaseIndex = 0,
|
||||||
) {
|
) {
|
||||||
for (let i = initialDatabaseIndex; i < databases.length; i++) {
|
//if databases are not yet loaded, wait until loaded
|
||||||
const database: ViewModels.Database = databases[i];
|
if (!databases || databases.length === 0) {
|
||||||
if (!!action.databaseResourceId && database.id() !== action.databaseResourceId) {
|
const databaseActionHandler = (databases: ViewModels.Database[]) => {
|
||||||
continue;
|
databasesUnsubscription();
|
||||||
}
|
openCollectionTab(action, databases, 0);
|
||||||
|
return;
|
||||||
const collectionActionHandler = (collections: ViewModels.Collection[]) => {
|
|
||||||
if (!action.collectionResourceId && collections.length === 0) {
|
|
||||||
subscription.dispose();
|
|
||||||
openCollectionTab(action, databases, ++i);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let j = 0; j < collections.length; j++) {
|
|
||||||
const collection: ViewModels.Collection = collections[j];
|
|
||||||
if (!!action.collectionResourceId && collection.id() !== action.collectionResourceId) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// select the collection
|
|
||||||
collection.expandCollection();
|
|
||||||
|
|
||||||
if (
|
|
||||||
action.tabKind === ActionContracts.TabKind.SQLDocuments ||
|
|
||||||
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SQLDocuments]
|
|
||||||
) {
|
|
||||||
collection.onDocumentDBDocumentsClick();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
action.tabKind === ActionContracts.TabKind.MongoDocuments ||
|
|
||||||
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.MongoDocuments]
|
|
||||||
) {
|
|
||||||
collection.onMongoDBDocumentsClick();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
action.tabKind === ActionContracts.TabKind.SchemaAnalyzer ||
|
|
||||||
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SchemaAnalyzer]
|
|
||||||
) {
|
|
||||||
collection.onSchemaAnalyzerClick();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
action.tabKind === ActionContracts.TabKind.TableEntities ||
|
|
||||||
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.TableEntities]
|
|
||||||
) {
|
|
||||||
collection.onTableEntitiesClick();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
action.tabKind === ActionContracts.TabKind.Graph ||
|
|
||||||
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.Graph]
|
|
||||||
) {
|
|
||||||
collection.onGraphDocumentsClick();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
action.tabKind === ActionContracts.TabKind.SQLQuery ||
|
|
||||||
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SQLQuery]
|
|
||||||
) {
|
|
||||||
collection.onNewQueryClick(
|
|
||||||
collection,
|
|
||||||
undefined,
|
|
||||||
generateQueryText(action as ActionContracts.OpenQueryTab, collection.partitionKeyProperties),
|
|
||||||
);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
action.tabKind === ActionContracts.TabKind.ScaleSettings ||
|
|
||||||
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.ScaleSettings]
|
|
||||||
) {
|
|
||||||
collection.onSettingsClick();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
subscription.dispose();
|
|
||||||
};
|
};
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
const subscription = database.collections.subscribe((collections) => collectionActionHandler(collections));
|
//expand database first if not expanded to load the collections
|
||||||
if (database.collections && database.collections() && database.collections().length) {
|
if (!database.isDatabaseExpanded?.()) {
|
||||||
collectionActionHandler(database.collections());
|
database.expandDatabase?.();
|
||||||
|
}
|
||||||
|
|
||||||
|
const collectionActionHandler = (collections: ViewModels.Collection[]) => {
|
||||||
|
if (!action.collectionResourceId && collections.length === 0) {
|
||||||
|
subscription.dispose();
|
||||||
|
openCollectionTab(action, databases, ++i);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let j = 0; j < collections.length; j++) {
|
||||||
|
const collection: ViewModels.Collection = collections[j];
|
||||||
|
if (!!action.collectionResourceId && collection.id() !== action.collectionResourceId) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// select the collection
|
||||||
|
collection.expandCollection();
|
||||||
|
|
||||||
|
if (
|
||||||
|
action.tabKind === ActionContracts.TabKind.SQLDocuments ||
|
||||||
|
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SQLDocuments]
|
||||||
|
) {
|
||||||
|
collection.onDocumentDBDocumentsClick();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
action.tabKind === ActionContracts.TabKind.MongoDocuments ||
|
||||||
|
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.MongoDocuments]
|
||||||
|
) {
|
||||||
|
collection.onMongoDBDocumentsClick();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
action.tabKind === ActionContracts.TabKind.SchemaAnalyzer ||
|
||||||
|
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SchemaAnalyzer]
|
||||||
|
) {
|
||||||
|
collection.onSchemaAnalyzerClick();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
action.tabKind === ActionContracts.TabKind.TableEntities ||
|
||||||
|
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.TableEntities]
|
||||||
|
) {
|
||||||
|
collection.onTableEntitiesClick();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
action.tabKind === ActionContracts.TabKind.Graph ||
|
||||||
|
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.Graph]
|
||||||
|
) {
|
||||||
|
collection.onGraphDocumentsClick();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
action.tabKind === ActionContracts.TabKind.SQLQuery ||
|
||||||
|
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SQLQuery]
|
||||||
|
) {
|
||||||
|
collection.onNewQueryClick(
|
||||||
|
collection,
|
||||||
|
undefined,
|
||||||
|
generateQueryText(action as ActionContracts.OpenQueryTab, collection.partitionKeyProperties),
|
||||||
|
);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
action.tabKind === ActionContracts.TabKind.ScaleSettings ||
|
||||||
|
action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.ScaleSettings]
|
||||||
|
) {
|
||||||
|
collection.onSettingsClick();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
subscription.dispose();
|
||||||
|
};
|
||||||
|
|
||||||
|
const subscription = database.collections.subscribe((collections) => collectionActionHandler(collections));
|
||||||
|
if (database.collections && database.collections() && database.collections().length) {
|
||||||
|
collectionActionHandler(database.collections());
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user