Nested tags work now too.

pull/20/head
Sander Vocke 5 years ago
parent 659c395752
commit 8adf9bd675
  1. 27
      client/src/components/querybuilder/QBAddElemMenu.tsx
  2. 2
      client/src/components/querybuilder/QBLeafElem.tsx
  3. 8
      client/src/lib/query/Query.tsx

@ -21,8 +21,23 @@ export function createTagInfo(tag: any, allTags: any[]): TagQueryInfo {
return [t.name];
}
const resolveChildren: (t: any) => Set<number> = (t: any) => {
if (t.childIds.length > 0) {
const childSets: Set<number>[] = allTags.filter((o: any) => t.childIds.includes(o.tagId))
.map((child: any) => resolveChildren(child));
var r = new Set<number>();
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 <NestedMenuItem
label={_props.tag.name}
parentMenuOpen={Boolean(anchorEl)}
onClick={() => {
onClose();
props.onCreateQuery({
a: QueryLeafBy.TagInfo,
leafOp: QueryLeafOp.Equals,
b: createTagInfo(_props.tag, _props.allTags),
});
}}
>
{children.map((child: any) => <TagItem tag={child} allTags={_props.allTags} />)}
</NestedMenuItem>
@ -78,7 +101,7 @@ export function QBAddElemMenu(props: MenuProps) {
return <TagItem tag={tag} allTags={tags} />
})}
</>
: <>Loading!</>
: <>...</>
}
return <Menu

@ -166,5 +166,5 @@ export function QBLeafElem(props: IProps) {
/>
}
throw "Unsupported leaf element";
throw new Error("Unsupported leaf element");
}

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

Loading…
Cancel
Save