Add sidebar action to select the active request

This commit is contained in:
Gregory Schier
2025-11-11 14:38:05 -08:00
parent 7b6278405c
commit 5449e3c620
4 changed files with 52 additions and 14 deletions

View File

@@ -83,6 +83,17 @@ export function getModel<M extends AnyModel['model'], T extends ExtractModel<Any
return null;
}
export function getAnyModel(
id: string,
): AnyModel | null {
let data = mustStore().get(modelStoreDataAtom);
for (const t of Object.keys(data)) {
let v = (data as any)[t]?.[id];
if (v?.model === t) return v;
}
return null;
}
export function patchModelById<M extends AnyModel['model'], T extends ExtractModel<AnyModel, M>>(
model: M,
id: string,

View File

@@ -10,16 +10,6 @@ import type {
WebsocketRequest,
Workspace,
} from '@yaakapp-internal/models';
import {
duplicateModel,
foldersAtom,
getModel,
grpcConnectionsAtom,
httpResponsesAtom,
patchModel,
websocketConnectionsAtom,
workspacesAtom,
} from '@yaakapp-internal/models';
import classNames from 'classnames';
import { atom, useAtomValue } from 'jotai';
import { selectAtom } from 'jotai/utils';
@@ -37,6 +27,7 @@ import { getGrpcRequestActions } from '../hooks/useGrpcRequestActions';
import { useHotKey } from '../hooks/useHotKey';
import { getHttpRequestActions } from '../hooks/useHttpRequestActions';
import { useListenToTauriEvent } from '../hooks/useListenToTauriEvent';
import { getModelAncestors } from '../hooks/useModelAncestors';
import { sendAnyHttpRequest } from '../hooks/useSendAnyHttpRequest';
import { useSidebarHidden } from '../hooks/useSidebarHidden';
import { deepEqualAtom } from '../lib/atoms';
@@ -65,6 +56,17 @@ import type { TreeHandle, TreeProps } from './core/tree/Tree';
import { Tree } from './core/tree/Tree';
import type { TreeItemProps } from './core/tree/TreeItem';
import { GitDropdown } from './GitDropdown';
import {
getAnyModel,
duplicateModel,
foldersAtom,
getModel,
grpcConnectionsAtom,
httpResponsesAtom,
patchModel,
websocketConnectionsAtom,
workspacesAtom,
} from '@yaakapp-internal/models';
type SidebarModel = Workspace | Folder | HttpRequest | GrpcRequest | WebsocketRequest;
function isSidebarLeafModel(m: AnyModel): boolean {
@@ -486,6 +488,29 @@ function Sidebar({ className }: { className?: string }) {
/>
<Dropdown
items={[
{
label: 'Select Open Request',
leftSlot: <Icon icon="crosshair" />,
onSelect: () => {
const activeId = jotaiStore.get(activeIdAtom);
if (activeId == null) return;
const folders = jotaiStore.get(foldersAtom);
const workspaces = jotaiStore.get(workspacesAtom);
const currentModel = getAnyModel(activeId);
const ancestors = getModelAncestors(folders, workspaces, currentModel);
jotaiStore.set(collapsedFamily(treeId), (prev) => {
const n = { ...prev };
for (const ancestor of ancestors) {
if (ancestor.model === 'folder') {
delete n[ancestor.id];
}
}
return n;
});
treeRef.current?.selectItem(activeId, true);
},
},
{
label: 'Expand All Folders',
leftSlot: <Icon icon="chevrons_up_down" />,

View File

@@ -43,6 +43,7 @@ import {
CopyIcon,
CornerRightUpIcon,
CreditCardIcon,
CrosshairIcon,
DotIcon,
DownloadIcon,
EllipsisIcon,
@@ -169,6 +170,7 @@ const icons = {
copy_check: CopyCheck,
corner_right_up: CornerRightUpIcon,
credit_card: CreditCardIcon,
crosshair: CrosshairIcon,
dot: DotIcon,
download: DownloadIcon,
ellipsis: EllipsisIcon,

View File

@@ -9,10 +9,10 @@ export function useModelAncestors(m: AnyModel | null) {
const folders = useAtomValue(foldersAtom);
const workspaces = useAtomValue(workspacesAtom);
return useMemo(() => getParents(folders, workspaces, m), [folders, workspaces, m]);
return useMemo(() => getModelAncestors(folders, workspaces, m), [folders, workspaces, m]);
}
function getParents(
export function getModelAncestors(
folders: Folder[],
workspaces: Workspace[],
currentModel: AnyModel | null,
@@ -25,7 +25,7 @@ function getParents(
: null;
if (parentFolder != null) {
return [parentFolder, ...getParents(folders, workspaces, parentFolder)];
return [parentFolder, ...getModelAncestors(folders, workspaces, parentFolder)];
}
const parentWorkspace =
@@ -34,7 +34,7 @@ function getParents(
: null;
if (parentWorkspace != null) {
return [parentWorkspace, ...getParents(folders, workspaces, parentWorkspace)];
return [parentWorkspace, ...getModelAncestors(folders, workspaces, parentWorkspace)];
}
return [];