|
|
@ -1,9 +1,9 @@ |
|
|
|
import React from 'react'; |
|
|
|
import React, { useState, useEffect } from 'react'; |
|
|
|
import { Menu, MenuItem } from '@material-ui/core'; |
|
|
|
import { Menu, MenuItem } from '@material-ui/core'; |
|
|
|
import NestedMenuItem from "material-ui-nested-menu-item"; |
|
|
|
import NestedMenuItem from "material-ui-nested-menu-item"; |
|
|
|
import { QueryElem, QueryLeafBy, QueryLeafOp } from '../../lib/query/Query'; |
|
|
|
import { QueryElem, QueryLeafBy, QueryLeafOp, TagQueryInfo } from '../../lib/query/Query'; |
|
|
|
import QBSelectWithRequest from './QBSelectWithRequest'; |
|
|
|
import QBSelectWithRequest from './QBSelectWithRequest'; |
|
|
|
import { Requests } from './QueryBuilder'; |
|
|
|
import { Requests, TagItem } from './QueryBuilder'; |
|
|
|
|
|
|
|
|
|
|
|
export interface MenuProps { |
|
|
|
export interface MenuProps { |
|
|
|
anchorEl: null | HTMLElement, |
|
|
|
anchorEl: null | HTMLElement, |
|
|
@ -12,10 +12,75 @@ export interface MenuProps { |
|
|
|
requestFunctions: Requests, |
|
|
|
requestFunctions: Requests, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function createTagInfo(tag: any, allTags: any[]): TagQueryInfo { |
|
|
|
|
|
|
|
const resolveName: (t: any) => string[] = (t: any) => { |
|
|
|
|
|
|
|
if (t.parentId) { |
|
|
|
|
|
|
|
const parent = allTags.filter((o: any) => o.tagId === t.parentId)[0]; |
|
|
|
|
|
|
|
return [resolveName(parent), t.name]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return [t.name]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|
|
|
id: tag.tagId, |
|
|
|
|
|
|
|
fullName: resolveName(tag), |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function QBAddElemMenu(props: MenuProps) { |
|
|
|
export function QBAddElemMenu(props: MenuProps) { |
|
|
|
let anchorEl = props.anchorEl; |
|
|
|
let anchorEl = props.anchorEl; |
|
|
|
let onClose = props.onClose; |
|
|
|
let onClose = props.onClose; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface TagItemProps { |
|
|
|
|
|
|
|
tag: any, |
|
|
|
|
|
|
|
allTags: any[], |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const TagItem = (_props: TagItemProps) => { |
|
|
|
|
|
|
|
if (_props.tag.childIds.length > 0) { |
|
|
|
|
|
|
|
const children = _props.allTags.filter( |
|
|
|
|
|
|
|
(tag: any) => _props.tag.childIds.includes(tag.tagId) |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return <NestedMenuItem |
|
|
|
|
|
|
|
label={_props.tag.name} |
|
|
|
|
|
|
|
parentMenuOpen={Boolean(anchorEl)} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{children.map((child: any) => <TagItem tag={child} allTags={_props.allTags} />)} |
|
|
|
|
|
|
|
</NestedMenuItem> |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return <MenuItem |
|
|
|
|
|
|
|
onClick={() => { |
|
|
|
|
|
|
|
onClose(); |
|
|
|
|
|
|
|
props.onCreateQuery({ |
|
|
|
|
|
|
|
a: QueryLeafBy.TagInfo, |
|
|
|
|
|
|
|
leafOp: QueryLeafOp.Equals, |
|
|
|
|
|
|
|
b: createTagInfo(_props.tag, _props.allTags), |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
{_props.tag.name} |
|
|
|
|
|
|
|
</MenuItem> |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const BaseTagsItem = (_props: any) => { |
|
|
|
|
|
|
|
const [tags, setTags] = useState<any[] | null>(null); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
(async () => { |
|
|
|
|
|
|
|
setTags(await props.requestFunctions.getTags()); |
|
|
|
|
|
|
|
})() |
|
|
|
|
|
|
|
}, []); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return tags ? |
|
|
|
|
|
|
|
<> |
|
|
|
|
|
|
|
{tags.filter((tag: any) => !tag.parentId).map((tag: any) => { |
|
|
|
|
|
|
|
return <TagItem tag={tag} allTags={tags} /> |
|
|
|
|
|
|
|
})} |
|
|
|
|
|
|
|
</> |
|
|
|
|
|
|
|
: <>Loading!</> |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return <Menu |
|
|
|
return <Menu |
|
|
|
anchorEl={anchorEl} |
|
|
|
anchorEl={anchorEl} |
|
|
|
keepMounted |
|
|
|
keepMounted |
|
|
@ -77,5 +142,11 @@ export function QBAddElemMenu(props: MenuProps) { |
|
|
|
style={{ width: 300 }} |
|
|
|
style={{ width: 300 }} |
|
|
|
/> |
|
|
|
/> |
|
|
|
</NestedMenuItem> |
|
|
|
</NestedMenuItem> |
|
|
|
|
|
|
|
<NestedMenuItem |
|
|
|
|
|
|
|
label="Tag" |
|
|
|
|
|
|
|
parentMenuOpen={Boolean(anchorEl)} |
|
|
|
|
|
|
|
> |
|
|
|
|
|
|
|
<BaseTagsItem /> |
|
|
|
|
|
|
|
</NestedMenuItem> |
|
|
|
</Menu > |
|
|
|
</Menu > |
|
|
|
} |
|
|
|
} |
|
|
|