Remove method Explorer.openSettingPane (#880)

This commit is contained in:
Hardikkumar Nai 2021-06-10 18:39:38 +05:30 committed by GitHub
parent c632342a43
commit c980af9a5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 83 additions and 88 deletions

View File

@ -105,8 +105,6 @@ src/Explorer/Notebook/NotebookContainerClient.ts
src/Explorer/Notebook/NotebookContentClient.ts src/Explorer/Notebook/NotebookContentClient.ts
src/Explorer/Notebook/NotebookContentItem.ts src/Explorer/Notebook/NotebookContentItem.ts
src/Explorer/Notebook/NotebookUtil.ts src/Explorer/Notebook/NotebookUtil.ts
src/Explorer/OpenActions.test.ts
src/Explorer/OpenActions.ts
src/Explorer/OpenActionsStubs.ts src/Explorer/OpenActionsStubs.ts
src/Explorer/Panes/AddDatabasePane.ts src/Explorer/Panes/AddDatabasePane.ts
src/Explorer/Panes/AddDatabasePane.test.ts src/Explorer/Panes/AddDatabasePane.test.ts

View File

@ -56,7 +56,6 @@ import { DeleteDatabaseConfirmationPanel } from "./Panes/DeleteDatabaseConfirmat
import { ExecuteSprocParamsPane } from "./Panes/ExecuteSprocParamsPane/ExecuteSprocParamsPane"; import { ExecuteSprocParamsPane } from "./Panes/ExecuteSprocParamsPane/ExecuteSprocParamsPane";
import { GitHubReposPanel } from "./Panes/GitHubReposPanel/GitHubReposPanel"; import { GitHubReposPanel } from "./Panes/GitHubReposPanel/GitHubReposPanel";
import { SaveQueryPane } from "./Panes/SaveQueryPane/SaveQueryPane"; import { SaveQueryPane } from "./Panes/SaveQueryPane/SaveQueryPane";
import { SettingsPane } from "./Panes/SettingsPane/SettingsPane";
import { SetupNoteBooksPanel } from "./Panes/SetupNotebooksPanel/SetupNotebooksPanel"; import { SetupNoteBooksPanel } from "./Panes/SetupNotebooksPanel/SetupNotebooksPanel";
import { StringInputPane } from "./Panes/StringInputPane/StringInputPane"; import { StringInputPane } from "./Panes/StringInputPane/StringInputPane";
import { AddTableEntityPanel } from "./Panes/Tables/AddTableEntityPanel"; import { AddTableEntityPanel } from "./Panes/Tables/AddTableEntityPanel";
@ -1599,7 +1598,4 @@ export default class Explorer {
public openTableSelectQueryPanel(queryViewModal: QueryViewModel): void { public openTableSelectQueryPanel(queryViewModal: QueryViewModel): void {
useSidePanel.getState().openSidePanel("Select Column", <TableQuerySelectPanel queryViewModel={queryViewModal} />); useSidePanel.getState().openSidePanel("Select Column", <TableQuerySelectPanel queryViewModel={queryViewModal} />);
} }
public openSettingPane(): void {
useSidePanel.getState().openSidePanel("Settings", <SettingsPane />);
}
} }

View File

@ -28,6 +28,7 @@ import { CommandButtonComponentProps } from "../../Controls/CommandButton/Comman
import Explorer from "../../Explorer"; import Explorer from "../../Explorer";
import { OpenFullScreen } from "../../OpenFullScreen"; import { OpenFullScreen } from "../../OpenFullScreen";
import { LoadQueryPane } from "../../Panes/LoadQueryPane/LoadQueryPane"; import { LoadQueryPane } from "../../Panes/LoadQueryPane/LoadQueryPane";
import { SettingsPane } from "../../Panes/SettingsPane/SettingsPane";
let counter = 0; let counter = 0;
@ -154,7 +155,7 @@ export function createControlCommandBarButtons(container: Explorer): CommandButt
{ {
iconSrc: SettingsIcon, iconSrc: SettingsIcon,
iconAlt: "Settings", iconAlt: "Settings",
onCommandClick: container.openSettingPane, onCommandClick: () => useSidePanel.getState().openSidePanel("Settings", <SettingsPane />),
commandButtonLabel: undefined, commandButtonLabel: undefined,
ariaLabel: "Settings", ariaLabel: "Settings",
tooltipText: "Settings", tooltipText: "Settings",

View File

@ -1,7 +1,7 @@
import * as ko from "knockout"; import * as ko from "knockout";
import { ActionContracts } from "../Contracts/ExplorerContracts"; import { ActionContracts } from "../../Contracts/ExplorerContracts";
import * as ViewModels from "../Contracts/ViewModels"; import * as ViewModels from "../../Contracts/ViewModels";
import Explorer from "./Explorer"; import Explorer from "../Explorer";
import { handleOpenAction } from "./OpenActions"; import { handleOpenAction } from "./OpenActions";
describe("OpenActions", () => { describe("OpenActions", () => {
@ -9,7 +9,6 @@ describe("OpenActions", () => {
let explorer: Explorer; let explorer: Explorer;
let database: ViewModels.Database; let database: ViewModels.Database;
let collection: ViewModels.Collection; let collection: ViewModels.Collection;
let databases: ViewModels.Database[];
beforeEach(() => { beforeEach(() => {
explorer = {} as Explorer; explorer = {} as Explorer;
@ -19,7 +18,6 @@ describe("OpenActions", () => {
id: ko.observable("db"), id: ko.observable("db"),
collections: ko.observableArray<ViewModels.Collection>([]), collections: ko.observableArray<ViewModels.Collection>([]),
} as ViewModels.Database; } as ViewModels.Database;
databases = [database];
collection = { collection = {
id: ko.observable("coll"), id: ko.observable("coll"),
} as ViewModels.Collection; } as ViewModels.Collection;
@ -68,7 +66,7 @@ describe("OpenActions", () => {
paneKind: "AddCollection", paneKind: "AddCollection",
}; };
const actionHandled = handleOpenAction(action, [], explorer); handleOpenAction(action, [], explorer);
expect(explorer.onNewCollectionClicked).toHaveBeenCalled(); expect(explorer.onNewCollectionClicked).toHaveBeenCalled();
}); });
@ -78,7 +76,7 @@ describe("OpenActions", () => {
paneKind: ActionContracts.PaneKind.AddCollection, paneKind: ActionContracts.PaneKind.AddCollection,
}; };
const actionHandled = handleOpenAction(action, [], explorer); handleOpenAction(action, [], explorer);
expect(explorer.onNewCollectionClicked).toHaveBeenCalled(); expect(explorer.onNewCollectionClicked).toHaveBeenCalled();
}); });
}); });

View File

@ -1,39 +1,36 @@
// 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 React from "react";
import { ActionContracts } from "../../Contracts/ExplorerContracts";
import * as ViewModels from "../../Contracts/ViewModels";
import { useSidePanel } from "../../hooks/useSidePanel";
import Explorer from "../Explorer";
import { SettingsPane } from "../Panes/SettingsPane/SettingsPane";
import { ActionContracts } from "../Contracts/ExplorerContracts"; function generateQueryText(action: ActionContracts.OpenQueryTab, partitionKeyProperty: string): string {
import * as ViewModels from "../Contracts/ViewModels"; if (!action.query) {
import Explorer from "./Explorer"; return "SELECT * FROM c";
} else if (action.query.text) {
export function handleOpenAction( return action.query.text;
action: ActionContracts.DataExplorerAction, } else if (!!action.query.partitionKeys && action.query.partitionKeys.length > 0) {
databases: ViewModels.Database[], let query = "SELECT * FROM c WHERE";
explorer: Explorer for (let i = 0; i < action.query.partitionKeys.length; i++) {
): boolean { const partitionKey = action.query.partitionKeys[i];
if ( if (!partitionKey) {
action.actionType === ActionContracts.ActionType.OpenCollectionTab || // null partition key case
(<any>action).actionType === ActionContracts.ActionType[ActionContracts.ActionType.OpenCollectionTab] query = query.concat(` c.${partitionKeyProperty} = ${action.query.partitionKeys[i]}`);
) { } else if (typeof partitionKey !== "string") {
openCollectionTab(<ActionContracts.OpenCollectionTab>action, databases); // Undefined partition key case
return true; query = query.concat(` NOT IS_DEFINED(c.${partitionKeyProperty})`);
} else {
query = query.concat(` c.${partitionKeyProperty} = "${action.query.partitionKeys[i]}"`);
}
if (i !== action.query.partitionKeys.length - 1) {
query = query.concat(" OR");
}
}
return query;
} }
return "SELECT * FROM c";
if (
action.actionType === ActionContracts.ActionType.OpenPane ||
(<any>action).actionType === ActionContracts.ActionType[ActionContracts.ActionType.OpenPane]
) {
openPane(<ActionContracts.OpenPane>action, explorer);
return true;
}
if (
action.actionType === ActionContracts.ActionType.OpenSampleNotebook ||
(<any>action).actionType === ActionContracts.ActionType[ActionContracts.ActionType.OpenSampleNotebook]
) {
openFile(<ActionContracts.OpenSampleNotebook>action, explorer);
return true;
}
return false;
} }
function openCollectionTab( function openCollectionTab(
@ -65,7 +62,7 @@ function openCollectionTab(
if ( if (
action.tabKind === ActionContracts.TabKind.SQLDocuments || action.tabKind === ActionContracts.TabKind.SQLDocuments ||
(<any>action).tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SQLDocuments] action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SQLDocuments]
) { ) {
collection.onDocumentDBDocumentsClick(); collection.onDocumentDBDocumentsClick();
break; break;
@ -73,7 +70,7 @@ function openCollectionTab(
if ( if (
action.tabKind === ActionContracts.TabKind.MongoDocuments || action.tabKind === ActionContracts.TabKind.MongoDocuments ||
(<any>action).tabKind === ActionContracts.TabKind[ActionContracts.TabKind.MongoDocuments] action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.MongoDocuments]
) { ) {
collection.onMongoDBDocumentsClick(); collection.onMongoDBDocumentsClick();
break; break;
@ -81,7 +78,7 @@ function openCollectionTab(
if ( if (
action.tabKind === ActionContracts.TabKind.SchemaAnalyzer || action.tabKind === ActionContracts.TabKind.SchemaAnalyzer ||
(<any>action).tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SchemaAnalyzer] action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SchemaAnalyzer]
) { ) {
collection.onSchemaAnalyzerClick(); collection.onSchemaAnalyzerClick();
break; break;
@ -89,7 +86,7 @@ function openCollectionTab(
if ( if (
action.tabKind === ActionContracts.TabKind.TableEntities || action.tabKind === ActionContracts.TabKind.TableEntities ||
(<any>action).tabKind === ActionContracts.TabKind[ActionContracts.TabKind.TableEntities] action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.TableEntities]
) { ) {
collection.onTableEntitiesClick(); collection.onTableEntitiesClick();
break; break;
@ -97,7 +94,7 @@ function openCollectionTab(
if ( if (
action.tabKind === ActionContracts.TabKind.Graph || action.tabKind === ActionContracts.TabKind.Graph ||
(<any>action).tabKind === ActionContracts.TabKind[ActionContracts.TabKind.Graph] action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.Graph]
) { ) {
collection.onGraphDocumentsClick(); collection.onGraphDocumentsClick();
break; break;
@ -105,19 +102,19 @@ function openCollectionTab(
if ( if (
action.tabKind === ActionContracts.TabKind.SQLQuery || action.tabKind === ActionContracts.TabKind.SQLQuery ||
(<any>action).tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SQLQuery] action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.SQLQuery]
) { ) {
collection.onNewQueryClick( collection.onNewQueryClick(
collection, collection,
null, undefined,
generateQueryText(<ActionContracts.OpenQueryTab>action, collection.partitionKeyProperty) generateQueryText(action as ActionContracts.OpenQueryTab, collection.partitionKeyProperty)
); );
break; break;
} }
if ( if (
action.tabKind === ActionContracts.TabKind.ScaleSettings || action.tabKind === ActionContracts.TabKind.ScaleSettings ||
(<any>action).tabKind === ActionContracts.TabKind[ActionContracts.TabKind.ScaleSettings] action.tabKind === ActionContracts.TabKind[ActionContracts.TabKind.ScaleSettings]
) { ) {
collection.onSettingsClick(); collection.onSettingsClick();
break; break;
@ -138,49 +135,54 @@ function openCollectionTab(
function openPane(action: ActionContracts.OpenPane, explorer: Explorer) { function openPane(action: ActionContracts.OpenPane, explorer: Explorer) {
if ( if (
action.paneKind === ActionContracts.PaneKind.AddCollection || action.paneKind === ActionContracts.PaneKind.AddCollection ||
(<any>action).paneKind === ActionContracts.PaneKind[ActionContracts.PaneKind.AddCollection] action.paneKind === ActionContracts.PaneKind[ActionContracts.PaneKind.AddCollection]
) { ) {
explorer.onNewCollectionClicked(); explorer.onNewCollectionClicked();
} else if ( } else if (
action.paneKind === ActionContracts.PaneKind.CassandraAddCollection || action.paneKind === ActionContracts.PaneKind.CassandraAddCollection ||
(<any>action).paneKind === ActionContracts.PaneKind[ActionContracts.PaneKind.CassandraAddCollection] action.paneKind === ActionContracts.PaneKind[ActionContracts.PaneKind.CassandraAddCollection]
) { ) {
explorer.openCassandraAddCollectionPane(); explorer.openCassandraAddCollectionPane();
} else if ( } else if (
action.paneKind === ActionContracts.PaneKind.GlobalSettings || action.paneKind === ActionContracts.PaneKind.GlobalSettings ||
(<any>action).paneKind === ActionContracts.PaneKind[ActionContracts.PaneKind.GlobalSettings] action.paneKind === ActionContracts.PaneKind[ActionContracts.PaneKind.GlobalSettings]
) { ) {
explorer.openSettingPane(); useSidePanel.getState().openSidePanel("Settings", <SettingsPane />);
} }
} }
export function handleOpenAction(
action: ActionContracts.DataExplorerAction,
databases: ViewModels.Database[],
explorer: Explorer
): boolean {
if (
action.actionType === ActionContracts.ActionType.OpenCollectionTab ||
action.actionType === ActionContracts.ActionType[ActionContracts.ActionType.OpenCollectionTab]
) {
openCollectionTab(action as ActionContracts.OpenCollectionTab, databases);
return true;
}
if (
action.actionType === ActionContracts.ActionType.OpenPane ||
action.actionType === ActionContracts.ActionType[ActionContracts.ActionType.OpenPane]
) {
openPane(action as ActionContracts.OpenPane, explorer);
return true;
}
if (
action.actionType === ActionContracts.ActionType.OpenSampleNotebook ||
action.actionType === ActionContracts.ActionType[ActionContracts.ActionType.OpenSampleNotebook]
) {
openFile(action as ActionContracts.OpenSampleNotebook, explorer);
return true;
}
return false;
}
function openFile(action: ActionContracts.OpenSampleNotebook, explorer: Explorer) { function openFile(action: ActionContracts.OpenSampleNotebook, explorer: Explorer) {
explorer.handleOpenFileAction(decodeURIComponent(action.path)); explorer.handleOpenFileAction(decodeURIComponent(action.path));
} }
function generateQueryText(action: ActionContracts.OpenQueryTab, partitionKeyProperty: string): string {
if (!action.query) {
return "SELECT * FROM c";
} else if (!!action.query.text) {
return action.query.text;
} else if (!!action.query.partitionKeys && action.query.partitionKeys.length > 0) {
let query = "SELECT * FROM c WHERE";
for (let i = 0; i < action.query.partitionKeys.length; i++) {
let partitionKey = action.query.partitionKeys[i];
if (!partitionKey) {
// null partition key case
query = query.concat(` c.${partitionKeyProperty} = ${action.query.partitionKeys[i]}`);
} else if (typeof partitionKey !== "string") {
// Undefined partition key case
query = query.concat(` NOT IS_DEFINED(c.${partitionKeyProperty})`);
} else {
query = query.concat(` c.${partitionKeyProperty} = "${action.query.partitionKeys[i]}"`);
}
if (i !== action.query.partitionKeys.length - 1) {
query = query.concat(" OR");
}
}
return query;
}
return "SELECT * FROM c";
}

View File

@ -9,7 +9,7 @@ import { ActionType, DataExplorerAction } from "../Contracts/ActionContracts";
import { MessageTypes } from "../Contracts/ExplorerContracts"; import { MessageTypes } from "../Contracts/ExplorerContracts";
import { DataExplorerInputsFrame } from "../Contracts/ViewModels"; import { DataExplorerInputsFrame } from "../Contracts/ViewModels";
import Explorer, { ExplorerParams } from "../Explorer/Explorer"; import Explorer, { ExplorerParams } from "../Explorer/Explorer";
import { handleOpenAction } from "../Explorer/OpenActions"; import { handleOpenAction } from "../Explorer/OpenActions/OpenActions";
import { import {
AAD, AAD,
ConnectionString, ConnectionString,