From 8adf9bd6758dac2528e83c1bc005a05af6060c15 Mon Sep 17 00:00:00 2001 From: Sander Vocke Date: Tue, 15 Sep 2020 18:20:36 +0200 Subject: [PATCH] Nested tags work now too. --- .../components/querybuilder/QBAddElemMenu.tsx | 27 +++++++++++++++++-- .../components/querybuilder/QBLeafElem.tsx | 2 +- client/src/lib/query/Query.tsx | 8 +++--- 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/client/src/components/querybuilder/QBAddElemMenu.tsx b/client/src/components/querybuilder/QBAddElemMenu.tsx index 61af908..6433435 100644 --- a/client/src/components/querybuilder/QBAddElemMenu.tsx +++ b/client/src/components/querybuilder/QBAddElemMenu.tsx @@ -21,8 +21,23 @@ export function createTagInfo(tag: any, allTags: any[]): TagQueryInfo { return [t.name]; } + const resolveChildren: (t: any) => Set = (t: any) => { + if (t.childIds.length > 0) { + const childSets: Set[] = allTags.filter((o: any) => t.childIds.includes(o.tagId)) + .map((child: any) => resolveChildren(child)); + + var r = new Set(); + childSets.forEach((c: any) => { + r = new Set([...r, ...c]); + }); + + return r; + } + return new Set([t.tagId]); + } + return { - id: tag.tagId, + matchIds: [...resolveChildren(tag)], fullName: resolveName(tag), } } @@ -44,6 +59,14 @@ export function QBAddElemMenu(props: MenuProps) { return { + onClose(); + props.onCreateQuery({ + a: QueryLeafBy.TagInfo, + leafOp: QueryLeafOp.Equals, + b: createTagInfo(_props.tag, _props.allTags), + }); + }} > {children.map((child: any) => )} @@ -78,7 +101,7 @@ export function QBAddElemMenu(props: MenuProps) { return })} - : <>Loading! + : <>... } return } - throw "Unsupported leaf element"; + throw new Error("Unsupported leaf element"); } \ No newline at end of file diff --git a/client/src/lib/query/Query.tsx b/client/src/lib/query/Query.tsx index 714ce4e..e1b4151 100644 --- a/client/src/lib/query/Query.tsx +++ b/client/src/lib/query/Query.tsx @@ -15,10 +15,10 @@ export enum QueryLeafOp { export interface TagQueryInfo { fullName: string[], - id: number, + matchIds: number[], } export function isTagQueryInfo(e: any): e is TagQueryInfo { - return 'fullName' in e && 'id' in e; + return 'fullName' in e && 'matchIds' in e; } export type QueryLeafOperand = string | number | TagQueryInfo; @@ -180,8 +180,8 @@ export function toApiQuery(q: QueryElem) : serverApi.Query { // Special case for tag queries by ID const r: serverApi.QueryElem = { prop: serverApi.QueryElemProperty.tagId, - propOperator: serverApi.QueryFilterOp.Eq, - propOperand: q.b.id, + propOperator: serverApi.QueryFilterOp.In, + propOperand: q.b.matchIds, } return r; } else if(isLeafElem(q)) {