mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
fix reqtree bug (#6289)
* create meta update * only redirect to existing request * fix bug in export empty * fix lint * empty req tree
This commit is contained in:
parent
8b642ea292
commit
8ad5682a20
@ -33,9 +33,8 @@ export interface ExportRequestsModalHandle {
|
||||
|
||||
export const ExportRequestsModal = ({ onHide }: ModalProps) => {
|
||||
const modalRef = useRef<ModalHandle>(null);
|
||||
const {
|
||||
requestTree,
|
||||
} = useRouteLoaderData(':workspaceId') as WorkspaceLoaderData;
|
||||
const workspaceData = useRouteLoaderData(':workspaceId') as WorkspaceLoaderData;
|
||||
const requestTree = workspaceData?.requestTree || [];
|
||||
|
||||
const createNode = useCallback((item: Record<string, any>): Node => {
|
||||
const children: Node[] = item.children.map((child: Record<string, any>) => createNode(child));
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { FC, useCallback, useRef } from 'react';
|
||||
import React, { FC, useRef } from 'react';
|
||||
import { useRouteLoaderData } from 'react-router-dom';
|
||||
|
||||
import { SortOrder } from '../../../common/constants';
|
||||
@ -6,6 +6,7 @@ import { database as db } from '../../../common/database';
|
||||
import { sortMethodMap } from '../../../common/sorting';
|
||||
import * as models from '../../../models';
|
||||
import { isRequestGroup } from '../../../models/request-group';
|
||||
import { useWorkspaceMetaPatcher } from '../../hooks/use-request';
|
||||
import { WorkspaceLoaderData } from '../../routes/workspace';
|
||||
import { useDocBodyKeyboardShortcuts } from '../keydown-binder';
|
||||
import { SidebarCreateDropdown } from './sidebar-create-dropdown';
|
||||
@ -16,23 +17,21 @@ interface Props {
|
||||
|
||||
export const SidebarFilter: FC<Props> = ({ filter }) => {
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const updateMeta = useWorkspaceMetaPatcher();
|
||||
const {
|
||||
activeWorkspace,
|
||||
activeWorkspaceMeta,
|
||||
} = useRouteLoaderData(':workspaceId') as WorkspaceLoaderData;
|
||||
|
||||
const handleClearFilter = useCallback(async () => {
|
||||
await models.workspaceMeta.update(activeWorkspaceMeta, { sidebarFilter: '' });
|
||||
const handleClearFilter = () => {
|
||||
updateMeta(activeWorkspace._id, { sidebarFilter: '' });
|
||||
if (inputRef.current) {
|
||||
inputRef.current.value = '';
|
||||
inputRef.current.focus();
|
||||
}
|
||||
}, [activeWorkspaceMeta]);
|
||||
};
|
||||
|
||||
const handleOnChange = useCallback(async (event: React.SyntheticEvent<HTMLInputElement>) => {
|
||||
await models.workspaceMeta.update(activeWorkspaceMeta, { sidebarFilter: event.currentTarget.value });
|
||||
}, [activeWorkspaceMeta]);
|
||||
const handleOnChange = async (event: React.SyntheticEvent<HTMLInputElement>) => {
|
||||
updateMeta(activeWorkspace._id, { sidebarFilter: event.currentTarget.value });
|
||||
};
|
||||
|
||||
useDocBodyKeyboardShortcuts({
|
||||
sidebar_focusFilter: () => {
|
||||
|
@ -9,6 +9,7 @@ import { RequestGroupMeta } from '../../models/request-group-meta';
|
||||
import { RequestMeta } from '../../models/request-meta';
|
||||
import { Settings } from '../../models/settings';
|
||||
import { WebSocketRequest } from '../../models/websocket-request';
|
||||
import { WorkspaceMeta } from '../../models/workspace-meta';
|
||||
|
||||
export const useRequestPatcher = () => {
|
||||
const { organizationId, projectId, workspaceId } = useParams<{ organizationId: string; projectId: string; workspaceId: string }>();
|
||||
@ -69,4 +70,16 @@ export const useSettingsPatcher = () => {
|
||||
};
|
||||
};
|
||||
|
||||
export const useWorkspaceMetaPatcher = () => {
|
||||
const { organizationId, projectId } = useParams<{ organizationId: string; projectId: string }>();
|
||||
const fetcher = useFetcher();
|
||||
return (workspaceId: string, patch: Partial<WorkspaceMeta>) => {
|
||||
fetcher.submit(patch, {
|
||||
action: `/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/update-meta`,
|
||||
method: 'post',
|
||||
encType: 'application/json',
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
export type CreateRequestType = 'HTTP' | 'gRPC' | 'GraphQL' | 'WebSocket' | 'Event Stream';
|
||||
|
@ -506,6 +506,13 @@ const router = createMemoryRouter(
|
||||
...args
|
||||
),
|
||||
},
|
||||
{
|
||||
path: ':workspaceId/update-meta',
|
||||
action: async (...args) =>
|
||||
(await import('./routes/actions')).updateWorkspaceMetaAction(
|
||||
...args
|
||||
),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@ -16,6 +16,7 @@ import { DEFAULT_PROJECT_ID, isRemoteProject } from '../../models/project';
|
||||
import { isRequest, Request } from '../../models/request';
|
||||
import { UnitTest } from '../../models/unit-test';
|
||||
import { isCollection, Workspace } from '../../models/workspace';
|
||||
import { WorkspaceMeta } from '../../models/workspace-meta';
|
||||
import { getSendRequestCallback } from '../../network/unit-test-feature';
|
||||
import { initializeLocalBackendProjectAndMarkForSync } from '../../sync/vcs/initialize-backend-project';
|
||||
import { getVCS } from '../../sync/vcs/vcs';
|
||||
@ -254,6 +255,14 @@ export const updateWorkspaceAction: ActionFunction = async ({ request }) => {
|
||||
return null;
|
||||
};
|
||||
|
||||
export const updateWorkspaceMetaAction: ActionFunction = async ({ request, params }) => {
|
||||
const { workspaceId } = params;
|
||||
invariant(typeof workspaceId === 'string', 'Workspace ID is required');
|
||||
const patch = await request.json() as Partial<WorkspaceMeta>;
|
||||
await models.workspaceMeta.updateByParentId(workspaceId, patch);
|
||||
return null;
|
||||
};
|
||||
|
||||
// Test Suite
|
||||
export const createNewTestSuiteAction: ActionFunction = async ({
|
||||
request,
|
||||
|
@ -71,7 +71,8 @@ export const loader: LoaderFunction = async ({ params }) => {
|
||||
const activeWorkspaceMeta = await models.workspaceMeta.getOrCreateByParentId(workspaceId);
|
||||
invariant(activeWorkspaceMeta, 'Workspace meta not found');
|
||||
const activeRequestId = activeWorkspaceMeta.activeRequestId;
|
||||
if (activeRequestId) {
|
||||
const activeRequest = activeRequestId ? await models.request.getById(activeRequestId) : null;
|
||||
if (activeRequest) {
|
||||
return redirect(`/organization/${organizationId}/project/${projectId}/workspace/${workspaceId}/debug/request/${activeRequestId}`);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user