|
|
|
@ -3,7 +3,7 @@ import { Menu, MenuItem } from '@material-ui/core'; |
|
|
|
|
import NestedMenuItem from "material-ui-nested-menu-item"; |
|
|
|
|
import { QueryElem, QueryLeafBy, QueryLeafOp, TagQueryInfo } from '../../lib/query/Query'; |
|
|
|
|
import QBSelectWithRequest from './QBSelectWithRequest'; |
|
|
|
|
import { Requests } from './QueryBuilder'; |
|
|
|
|
import { Requests, QueryBuilderTag } from './QueryBuilder'; |
|
|
|
|
|
|
|
|
|
export interface MenuProps { |
|
|
|
|
anchorEl: null | HTMLElement, |
|
|
|
@ -12,19 +12,19 @@ export interface MenuProps { |
|
|
|
|
requestFunctions: Requests, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function createTagInfo(tag: any, allTags: any[]): TagQueryInfo { |
|
|
|
|
const resolveName: (t: any) => string[] = (t: any) => { |
|
|
|
|
export function createTagInfo(tag: QueryBuilderTag, allTags: QueryBuilderTag[]): TagQueryInfo { |
|
|
|
|
const resolveName: (t: QueryBuilderTag) => string[] = (t: QueryBuilderTag) => { |
|
|
|
|
if (t.parentId) { |
|
|
|
|
const parent = allTags.filter((o: any) => o.tagId === t.parentId)[0]; |
|
|
|
|
return [resolveName(parent), t.name]; |
|
|
|
|
const parent = allTags.filter((o: QueryBuilderTag) => o.id === t.parentId)[0]; |
|
|
|
|
return resolveName(parent).concat(t.name); |
|
|
|
|
} |
|
|
|
|
return [t.name]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const resolveChildren: (t: any) => Set<number> = (t: any) => { |
|
|
|
|
const resolveChildren: (t: QueryBuilderTag) => Set<number> = (t: QueryBuilderTag) => { |
|
|
|
|
if (t.childIds.length > 0) { |
|
|
|
|
const childSets: Set<number>[] = allTags.filter((o: any) => t.childIds.includes(o.tagId)) |
|
|
|
|
.map((child: any) => resolveChildren(child)); |
|
|
|
|
const childSets: Set<number>[] = allTags.filter((o: QueryBuilderTag) => t.childIds.includes(o.id)) |
|
|
|
|
.map((child: QueryBuilderTag) => resolveChildren(child)); |
|
|
|
|
|
|
|
|
|
var r = new Set<number>(); |
|
|
|
|
childSets.forEach((c: any) => { |
|
|
|
@ -33,7 +33,7 @@ export function createTagInfo(tag: any, allTags: any[]): TagQueryInfo { |
|
|
|
|
|
|
|
|
|
return r; |
|
|
|
|
} |
|
|
|
|
return new Set([t.tagId]); |
|
|
|
|
return new Set([t.id]); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
@ -47,13 +47,14 @@ export function QBAddElemMenu(props: MenuProps) { |
|
|
|
|
let onClose = props.onClose; |
|
|
|
|
|
|
|
|
|
interface TagItemProps { |
|
|
|
|
tag: any, |
|
|
|
|
allTags: any[], |
|
|
|
|
tag: QueryBuilderTag, |
|
|
|
|
allTags: QueryBuilderTag[], |
|
|
|
|
} |
|
|
|
|
const TagItem = (_props: TagItemProps) => { |
|
|
|
|
if (_props.tag.childIds.length > 0) { |
|
|
|
|
const children = _props.allTags.filter( |
|
|
|
|
(tag: any) => _props.tag.childIds.includes(tag.tagId) |
|
|
|
|
(tag: QueryBuilderTag) =>
|
|
|
|
|
_props.tag.childIds.includes(tag.id) |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
return <NestedMenuItem |
|
|
|
@ -68,12 +69,19 @@ export function QBAddElemMenu(props: MenuProps) { |
|
|
|
|
}); |
|
|
|
|
}} |
|
|
|
|
> |
|
|
|
|
{children.map((child: any) => <TagItem tag={child} allTags={_props.allTags} />)} |
|
|
|
|
{children.map((child: QueryBuilderTag) => <TagItem tag={child} allTags={_props.allTags} />)} |
|
|
|
|
</NestedMenuItem> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return <MenuItem |
|
|
|
|
onClick={() => { |
|
|
|
|
|
|
|
|
|
console.log("onCreateQuery: adding:",{ |
|
|
|
|
a: QueryLeafBy.TagInfo, |
|
|
|
|
leafOp: QueryLeafOp.Equals, |
|
|
|
|
b: createTagInfo(_props.tag, _props.allTags), |
|
|
|
|
} ); |
|
|
|
|
|
|
|
|
|
onClose(); |
|
|
|
|
props.onCreateQuery({ |
|
|
|
|
a: QueryLeafBy.TagInfo, |
|
|
|
@ -87,7 +95,7 @@ export function QBAddElemMenu(props: MenuProps) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const BaseTagsItem = (_props: any) => { |
|
|
|
|
const [tags, setTags] = useState<any[] | null>(null); |
|
|
|
|
const [tags, setTags] = useState<QueryBuilderTag[] | null>(null); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
(async () => { |
|
|
|
@ -97,7 +105,7 @@ export function QBAddElemMenu(props: MenuProps) { |
|
|
|
|
|
|
|
|
|
return tags ? |
|
|
|
|
<> |
|
|
|
|
{tags.filter((tag: any) => !tag.parentId).map((tag: any) => { |
|
|
|
|
{tags.filter((tag: QueryBuilderTag) => !tag.parentId).map((tag: QueryBuilderTag) => { |
|
|
|
|
return <TagItem tag={tag} allTags={tags} /> |
|
|
|
|
})} |
|
|
|
|
</> |
|
|
|
|