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:
Jack Kavanagh 2023-08-15 18:46:10 +02:00 committed by GitHub
parent 8b642ea292
commit 8ad5682a20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 42 additions and 14 deletions

View File

@ -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));

View File

@ -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: () => {

View File

@ -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';

View File

@ -506,6 +506,13 @@ const router = createMemoryRouter(
...args
),
},
{
path: ':workspaceId/update-meta',
action: async (...args) =>
(await import('./routes/actions')).updateWorkspaceMetaAction(
...args
),
},
],
},
{

View File

@ -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,

View File

@ -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}`);
}
}