Skip to content

Commit

Permalink
feat: use different tab if for collection runner and folder runner
Browse files Browse the repository at this point in the history
  • Loading branch information
CurryYangxx committed Nov 28, 2024
1 parent 6efde61 commit 2807dd5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
21 changes: 16 additions & 5 deletions packages/insomnia/src/ui/hooks/use-insomnia-tab.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useCallback, useEffect } from 'react';
import { matchPath, useLocation } from 'react-router-dom';
import { matchPath, useLocation, useSearchParams } from 'react-router-dom';

import type { GrpcRequest } from '../../models/grpc-request';
import type { MockRoute } from '../../models/mock-route';
Expand Down Expand Up @@ -40,6 +40,7 @@ export const useInsomniaTab = ({

const { appTabsRef, addTab, changeActiveTab } = useInsomniaTabContext();
const location = useLocation();
const [searchParams] = useSearchParams();

const generateTabUrl = useCallback((type: TabEnum) => {
if (type === TabEnum.Request) {
Expand Down Expand Up @@ -98,6 +99,14 @@ export const useInsomniaTab = ({
return null;
};

const getRunnerTabId = useCallback(() => {
const folderId = searchParams.get('folder');
if (folderId) {
return `runner_${folderId}`;
}
return `runner_${workspaceId}`;
}, [searchParams, workspaceId]);

const getCurrentTab = useCallback((type: TabEnum | null) => {
if (!type) {
return undefined;
Expand All @@ -113,7 +122,8 @@ export const useInsomniaTab = ({

if (type === TabEnum.Runner) {
// collection runner tab id is prefixed with 'runner_'
return currentOrgTabs?.tabList.find(tab => tab.id === `runner_${workspaceId}`);
const runnerTabId = getRunnerTabId();
return currentOrgTabs?.tabList.find(tab => tab.id === runnerTabId);
}

if (type === TabEnum.MockRoute) {
Expand All @@ -128,7 +138,7 @@ export const useInsomniaTab = ({
return currentOrgTabs?.tabList.find(tab => tab.id === workspaceId);
}
return undefined;
}, [activeMockRoute?._id, activeRequest?._id, activeRequestGroup?._id, appTabsRef, organizationId, unitTestSuite?._id, workspaceId]);
}, [activeMockRoute?._id, activeRequest?._id, activeRequestGroup?._id, appTabsRef, getRunnerTabId, organizationId, unitTestSuite?._id, workspaceId]);

const getTabId = useCallback((type: TabEnum | null): string => {
if (!type) {
Expand All @@ -143,7 +153,8 @@ export const useInsomniaTab = ({
}

if (type === TabEnum.Runner) {
return `runner_${workspaceId}`;
const runnerTabId = getRunnerTabId();
return runnerTabId;
}

if (type === TabEnum.MockRoute) {
Expand All @@ -159,7 +170,7 @@ export const useInsomniaTab = ({
}

return '';
}, [activeMockRoute?._id, activeRequest?._id, activeRequestGroup?._id, unitTestSuite?._id, workspaceId]);
}, [activeMockRoute?._id, activeRequest?._id, activeRequestGroup?._id, getRunnerTabId, unitTestSuite?._id, workspaceId]);

const packTabInfo = useCallback((type: TabEnum): BaseTab | undefined => {
if (!type) {
Expand Down
1 change: 0 additions & 1 deletion packages/insomnia/src/ui/hooks/use-runner-request-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ export const useRunnerRequestList = (workspaceId: string, targetFolderId: string

useEffect(() => {
if ((previousWorkspaceId && previousWorkspaceId !== workspaceId) || (previousTargetFolderId !== undefined && previousTargetFolderId !== targetFolderId)) {
console.log('reset list');
// reset the list when workspace changes
const keys = reqList.items.map(item => item.id);
reqList.remove(...keys);
Expand Down

0 comments on commit 2807dd5

Please sign in to comment.