Mongo tabs UX fixes (#851)

* Fixed mongo tabs UX

* changed logic for new tab index

* moved index to tabs base

* removed getIndex method
This commit is contained in:
Srinath Narayanan 2021-06-08 00:17:55 +05:30 committed by GitHub
parent f296c00a1c
commit ee60f61cfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 27 additions and 5 deletions

View File

@ -286,6 +286,7 @@ export interface TabOptions {
rid?: string; rid?: string;
node?: TreeNode; node?: TreeNode;
theme?: string; theme?: string;
index?: number;
} }
export interface DocumentsTabOptions extends TabOptions { export interface DocumentsTabOptions extends TabOptions {

View File

@ -1394,7 +1394,11 @@ export default class Explorer {
tab.hashLocation().startsWith(hashLocation) tab.hashLocation().startsWith(hashLocation)
) as TerminalTab[]; ) as TerminalTab[];
const index = terminalTabs.length + 1; let index = 1;
if (terminalTabs.length > 0) {
index = terminalTabs[terminalTabs.length - 1].index + 1;
}
const newTab = new TerminalTab({ const newTab = new TerminalTab({
account: userContext.databaseAccount, account: userContext.databaseAccount,
tabKind: ViewModels.CollectionTabKind.Terminal, tabKind: ViewModels.CollectionTabKind.Terminal,
@ -1407,6 +1411,7 @@ export default class Explorer {
onLoadStartKey: null, onLoadStartKey: null,
container: this, container: this,
kind: kind, kind: kind,
index: index,
}); });
this.tabsManager.activateNewTab(newTab); this.tabsManager.activateNewTab(newTab);

View File

@ -16,6 +16,7 @@ import { TabsManager } from "./TabsManager";
// TODO: Use specific actions for logging telemetry data // TODO: Use specific actions for logging telemetry data
export default class TabsBase extends WaitsForTemplateViewModel { export default class TabsBase extends WaitsForTemplateViewModel {
private static id = 0; private static id = 0;
public readonly index: number;
public closeTabButton: ViewModels.Button; public closeTabButton: ViewModels.Button;
public node: ViewModels.TreeNode; public node: ViewModels.TreeNode;
public collection: ViewModels.CollectionBase; public collection: ViewModels.CollectionBase;
@ -35,6 +36,7 @@ export default class TabsBase extends WaitsForTemplateViewModel {
constructor(options: ViewModels.TabOptions) { constructor(options: ViewModels.TabOptions) {
super(); super();
this.index = options.index;
this._theme = ThemeUtility.getMonacoTheme(options.theme); this._theme = ThemeUtility.getMonacoTheme(options.theme);
this.node = options.node; this.node = options.node;
this.collection = options.collection; this.collection = options.collection;

View File

@ -1,3 +1,4 @@
import { Spinner, SpinnerSize } from "@fluentui/react";
import * as ko from "knockout"; import * as ko from "knockout";
import * as React from "react"; import * as React from "react";
import { ReactAdapter } from "../../Bindings/ReactBindingHandler"; import { ReactAdapter } from "../../Bindings/ReactBindingHandler";
@ -33,7 +34,7 @@ class NotebookTerminalComponentAdapter implements ReactAdapter {
databaseAccount={this.getDatabaseAccount()} databaseAccount={this.getDatabaseAccount()}
/> />
) : ( ) : (
<></> <Spinner styles={{ root: { marginTop: 10 } }} size={SpinnerSize.large}></Spinner>
); );
} }
} }
@ -51,7 +52,11 @@ export default class TerminalTab extends TabsBase {
() => userContext?.databaseAccount () => userContext?.databaseAccount
); );
this.notebookTerminalComponentAdapter.parameters = ko.computed<boolean>(() => { this.notebookTerminalComponentAdapter.parameters = ko.computed<boolean>(() => {
if (this.isTemplateReady() && this.container.isNotebookEnabled()) { if (
this.isTemplateReady() &&
this.container.isNotebookEnabled() &&
this.container.notebookServerInfo().notebookServerEndpoint
) {
return true; return true;
} }
return false; return false;

View File

@ -690,14 +690,23 @@ export default class Collection implements ViewModels.Collection {
} }
public onNewMongoShellClick() { public onNewMongoShellClick() {
const id = this.container.tabsManager.getTabs(ViewModels.CollectionTabKind.MongoShell).length + 1; const mongoShellTabs = this.container.tabsManager.getTabs(
ViewModels.CollectionTabKind.MongoShell
) as MongoShellTab[];
let index = 1;
if (mongoShellTabs.length > 0) {
index = mongoShellTabs[mongoShellTabs.length - 1].index + 1;
}
const mongoShellTab: MongoShellTab = new MongoShellTab({ const mongoShellTab: MongoShellTab = new MongoShellTab({
tabKind: ViewModels.CollectionTabKind.MongoShell, tabKind: ViewModels.CollectionTabKind.MongoShell,
title: "Shell " + id, title: "Shell " + index,
tabPath: "", tabPath: "",
collection: this, collection: this,
node: this, node: this,
hashLocation: `${Constants.HashRoutePrefixes.collectionsWithIds(this.databaseId, this.id())}/mongoShell`, hashLocation: `${Constants.HashRoutePrefixes.collectionsWithIds(this.databaseId, this.id())}/mongoShell`,
index: index,
}); });
this.container.tabsManager.activateNewTab(mongoShellTab); this.container.tabsManager.activateNewTab(mongoShellTab);