mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-06-08 13:37:29 +01:00
feat: Add "Duplicate Tab" support for Items, Query, and Settings tabs (#2498)
* feat: Add "Duplicate Tab" support for Items, Query, and Settings tabs * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * added UT * Fix QueryTab useTabs import path for duplicate tab test mock --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -2,6 +2,7 @@ import { ActionType, TabKind } from "Contracts/ActionContracts";
|
||||
import React from "react";
|
||||
import MongoUtility from "../../../Common/MongoUtility";
|
||||
import * as ViewModels from "../../../Contracts/ViewModels";
|
||||
import { useTabs } from "../../../hooks/useTabs";
|
||||
import Explorer from "../../Explorer";
|
||||
import { NewQueryTab } from "../QueryTab/QueryTab";
|
||||
import { IQueryTabComponentProps, ITabAccessor, QueryTabComponent } from "../QueryTab/QueryTabComponent";
|
||||
@@ -67,6 +68,30 @@ export class NewMongoQueryTab extends NewQueryTab {
|
||||
return MongoUtility.tojson(value, undefined, false);
|
||||
}
|
||||
|
||||
public canDuplicate(): boolean {
|
||||
return true;
|
||||
}
|
||||
|
||||
public duplicateTab(): void {
|
||||
const id = useTabs.getState().getTabs(ViewModels.CollectionTabKind.Query).length + 1;
|
||||
const queryText = this.iTabAccessor?.onSaveClickEvent() ?? this.persistedState?.query?.text ?? "";
|
||||
const newTab = new NewMongoQueryTab(
|
||||
{
|
||||
tabKind: ViewModels.CollectionTabKind.Query,
|
||||
title: `Query ${id}`,
|
||||
tabPath: "",
|
||||
collection: this.collection,
|
||||
node: this.collection,
|
||||
queryText,
|
||||
partitionKey: this.partitionKey,
|
||||
splitterDirection: this.persistedState?.splitterDirection,
|
||||
queryViewSizePercent: this.persistedState?.queryViewSizePercent,
|
||||
},
|
||||
this.mongoQueryTabProps,
|
||||
);
|
||||
useTabs.getState().activateNewTab(newTab);
|
||||
}
|
||||
|
||||
public render(): JSX.Element {
|
||||
return <QueryTabComponent {...this.iMongoQueryTabComponentProps} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user