feat: tab service added (#3367)
This commit is contained in:
@@ -7,20 +7,12 @@ import { GQLHistoryEntry, RESTHistoryEntry } from "~/newstore/history"
|
||||
import { getDefaultRESTRequest } from "~/helpers/rest/default"
|
||||
import { HoppAction, HoppActionWithArgs } from "~/helpers/actions"
|
||||
import { getDefaultGQLRequest } from "~/helpers/graphql/default"
|
||||
import { RESTTabService } from "~/services/tab/rest"
|
||||
|
||||
async function flushPromises() {
|
||||
return await new Promise((r) => setTimeout(r))
|
||||
}
|
||||
|
||||
const tabMock = vi.hoisted(() => ({
|
||||
createNewTab: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock("~/helpers/rest/tab", () => ({
|
||||
__esModule: true,
|
||||
createNewTab: tabMock.createNewTab,
|
||||
}))
|
||||
|
||||
vi.mock("~/modules/i18n", () => ({
|
||||
__esModule: true,
|
||||
getI18n: () => (x: string) => x,
|
||||
@@ -72,8 +64,16 @@ describe("HistorySpotlightSearcherService", () => {
|
||||
y = historyMock.restEntries.pop()
|
||||
}
|
||||
|
||||
const container = new TestContainer()
|
||||
|
||||
const createNewTabFn = vi.fn()
|
||||
|
||||
container.bindMock(RESTTabService, {
|
||||
createNewTab: createNewTabFn,
|
||||
})
|
||||
|
||||
actionsMock.invokeAction.mockReset()
|
||||
tabMock.createNewTab.mockReset()
|
||||
createNewTabFn.mockReset()
|
||||
})
|
||||
|
||||
it("registers with the spotlight service upon initialization", async () => {
|
||||
|
||||
@@ -16,10 +16,6 @@ import {
|
||||
import IconFolder from "~icons/lucide/folder"
|
||||
import RESTRequestSpotlightEntry from "~/components/app/spotlight/entry/RESTRequest.vue"
|
||||
import GQLRequestSpotlightEntry from "~/components/app/spotlight/entry/GQLRequest.vue"
|
||||
import { createNewTab } from "~/helpers/rest/tab"
|
||||
import { createNewTab as createNewGQLTab } from "~/helpers/graphql/tab"
|
||||
import { getTabRefWithSaveContext } from "~/helpers/rest/tab"
|
||||
import { currentTabID } from "~/helpers/rest/tab"
|
||||
import {
|
||||
HoppCollection,
|
||||
HoppGQLRequest,
|
||||
@@ -27,6 +23,8 @@ import {
|
||||
} from "@hoppscotch/data"
|
||||
import { WorkspaceService } from "~/services/workspace.service"
|
||||
import { invokeAction } from "~/helpers/actions"
|
||||
import { RESTTabService } from "~/services/tab/rest"
|
||||
import { GQLTabService } from "~/services/tab/graphql"
|
||||
|
||||
/**
|
||||
* A spotlight searcher that searches through the user's collections
|
||||
@@ -44,6 +42,9 @@ export class CollectionsSpotlightSearcherService
|
||||
public searcherID = "collections"
|
||||
public searcherSectionTitle = this.t("collection.my_collections")
|
||||
|
||||
private readonly restTab = this.bind(RESTTabService)
|
||||
private readonly gqlTab = this.bind(GQLTabService)
|
||||
|
||||
private readonly spotlight = this.bind(SpotlightService)
|
||||
private readonly workspaceService = this.bind(WorkspaceService)
|
||||
|
||||
@@ -290,21 +291,21 @@ export class CollectionsSpotlightSearcherService
|
||||
})
|
||||
}
|
||||
|
||||
const possibleTab = getTabRefWithSaveContext({
|
||||
const possibleTab = this.restTab.getTabRefWithSaveContext({
|
||||
originLocation: "user-collection",
|
||||
folderPath: folderPath.join("/"),
|
||||
requestIndex: reqIndex,
|
||||
})
|
||||
|
||||
if (possibleTab) {
|
||||
currentTabID.value = possibleTab.value.id
|
||||
this.restTab.setActiveTab(possibleTab.value.id)
|
||||
} else {
|
||||
const req = this.getRESTFolderFromFolderPath(folderPath.join("/"))
|
||||
?.requests[reqIndex]
|
||||
|
||||
if (!req) return
|
||||
|
||||
createNewTab(
|
||||
this.restTab.createNewTab(
|
||||
{
|
||||
request: req,
|
||||
isDirty: false,
|
||||
@@ -326,7 +327,7 @@ export class CollectionsSpotlightSearcherService
|
||||
|
||||
if (!req) return
|
||||
|
||||
createNewGQLTab({
|
||||
this.gqlTab.createNewTab({
|
||||
saveContext: {
|
||||
originLocation: "user-collection",
|
||||
folderPath: folderPath.join("/"),
|
||||
|
||||
@@ -8,8 +8,7 @@ import {
|
||||
} from "./base/static.searcher"
|
||||
|
||||
import { useRoute } from "vue-router"
|
||||
import { RequestOptionTabs } from "~/components/http/RequestOptions.vue"
|
||||
import { currentActiveTab } from "~/helpers/rest/tab"
|
||||
import { RESTOptionTabs } from "~/components/http/RequestOptions.vue"
|
||||
import IconWindow from "~icons/lucide/app-window"
|
||||
import IconCheckCircle from "~icons/lucide/check-circle"
|
||||
import IconCode2 from "~icons/lucide/code-2"
|
||||
@@ -20,6 +19,7 @@ import IconPlay from "~icons/lucide/play"
|
||||
import IconRotateCCW from "~icons/lucide/rotate-ccw"
|
||||
import IconSave from "~icons/lucide/save"
|
||||
import { GQLOptionTabs } from "~/components/graphql/RequestOptions.vue"
|
||||
import { RESTTabService } from "~/services/tab/rest"
|
||||
|
||||
type Doc = {
|
||||
text: string | string[]
|
||||
@@ -43,6 +43,7 @@ export class RequestSpotlightSearcherService extends StaticSpotlightSearcherServ
|
||||
public searcherSectionTitle = this.t("shortcut.request.title")
|
||||
|
||||
private readonly spotlight = this.bind(SpotlightService)
|
||||
private readonly restTab = this.bind(RESTTabService)
|
||||
|
||||
private route = useRoute()
|
||||
private isRESTPage = computed(() => this.route.name === "index")
|
||||
@@ -247,7 +248,7 @@ export class RequestSpotlightSearcherService extends StaticSpotlightSearcherServ
|
||||
}
|
||||
}
|
||||
|
||||
private openRequestTab(tab: RequestOptionTabs | GQLOptionTabs): void {
|
||||
private openRequestTab(tab: RESTOptionTabs | GQLOptionTabs): void {
|
||||
invokeAction("request.open-tab", {
|
||||
tab,
|
||||
})
|
||||
@@ -267,7 +268,7 @@ export class RequestSpotlightSearcherService extends StaticSpotlightSearcherServ
|
||||
case "save_to_collections":
|
||||
invokeAction("request.save-as", {
|
||||
requestType: "rest",
|
||||
request: currentActiveTab.value?.document.request,
|
||||
request: this.restTab.currentActiveTab.value?.document.request,
|
||||
})
|
||||
break
|
||||
case "save_request":
|
||||
|
||||
@@ -12,8 +12,8 @@ import IconCopyPlus from "~icons/lucide/copy-plus"
|
||||
import IconXCircle from "~icons/lucide/x-circle"
|
||||
import IconXSquare from "~icons/lucide/x-square"
|
||||
import { invokeAction } from "~/helpers/actions"
|
||||
import { getActiveTabs as getRESTActiveTabs } from "~/helpers/rest/tab"
|
||||
import { getActiveTabs as getGQLActiveTabs } from "~/helpers/graphql/tab"
|
||||
import { RESTTabService } from "~/services/tab/rest"
|
||||
import { GQLTabService } from "~/services/tab/graphql"
|
||||
|
||||
type Doc = {
|
||||
text: string | string[]
|
||||
@@ -42,12 +42,14 @@ export class TabSpotlightSearcherService extends StaticSpotlightSearcherService<
|
||||
private showAction = computed(
|
||||
() => this.route.name === "index" || this.route.name === "graphql"
|
||||
)
|
||||
private gqlActiveTabs = getGQLActiveTabs()
|
||||
private restActiveTabs = getRESTActiveTabs()
|
||||
|
||||
private readonly restTab = this.bind(RESTTabService)
|
||||
private readonly gqlTab = this.bind(GQLTabService)
|
||||
|
||||
private isOnlyTab = computed(() =>
|
||||
this.route.name === "graphql"
|
||||
? this.gqlActiveTabs.value.length === 1
|
||||
: this.restActiveTabs.value.length === 1
|
||||
? this.gqlTab.getActiveTabs().value.length === 1
|
||||
: this.restTab.getActiveTabs().value.length === 1
|
||||
)
|
||||
|
||||
private documents: Record<string, Doc> = reactive({
|
||||
|
||||
Reference in New Issue
Block a user