fix drag and drop and sort (#5168)

This commit is contained in:
Jack Kavanagh authored and GitHub committed 2022-09-12 14:13:05 +00:00
1 parent 451e5fbbaa
commit f325b94e73
3 files changed
+10 -3

No files matched your search

@@ -89,4 +89,6 @@ export async function duplicate(request: WebSocketRequest, patch: Partial<WebSoc
export const getById = (_id: string) => database.getWhere<WebSocketRequest>(type, { _id });
export const findByParentId = (parentId: string) => database.find<WebSocketRequest>(type, { parentId });
export const all = () => database.all<WebSocketRequest>(type);
@@ -5,8 +5,9 @@ import { database } from '../../../common/database';
import { BaseModel } from '../../../models';
import * as models from '../../../models';
import { GrpcRequest } from '../../../models/grpc-request';
import * as requestOperations from '../../../models/helpers/request-operations';
import { Request } from '../../../models/request';
import { RequestGroup } from '../../../models/request-group';
import { isRequestGroup, RequestGroup } from '../../../models/request-group';
import { WebSocketRequest } from '../../../models/websocket-request';
export type DnDDragProps = ReturnType<typeof sourceCollect>;
@@ -103,8 +104,10 @@ const moveDoc = async ({
}
function __updateDoc(doc: BaseModel, patch: any) {
// @ts-expect-error -- TSCONVERSION
return models.getModel(docToMove.type).update(doc, patch);
if (isRequestGroup(doc)) {
return models.requestGroup.update(doc, patch);
}
return requestOperations.update(doc, patch);
}
if (!targetId) {
@@ -116,6 +119,7 @@ const moveDoc = async ({
// NOTE: using requestToTarget's parentId so we can switch parents!
const docs = [
...(await models.request.findByParentId(parentId)),
...(await models.webSocketRequest.findByParentId(parentId)),
...(await models.grpcRequest.findByParentId(parentId)),
...(await models.requestGroup.findByParentId(parentId)),
].sort((a, b) => (a.metaSortKey < b.metaSortKey ? -1 : 1));
@@ -54,6 +54,7 @@ export const SidebarFilter: FC<Props> = ({ filter }) => {
...(await models.requestGroup.findByParentId(parentId)),
...(await models.request.findByParentId(parentId)),
...(await models.grpcRequest.findByParentId(parentId)),
...(await models.webSocketRequest.findByParentId(parentId)),
].sort(sortMethodMap[order]);
// @ts-expect-error -- TSCONVERSION the fetched model will only ever be a RequestGroup, Request, or GrpcRequest
// Which all have the .update method. How do we better filter types?