|
|
@ -1,57 +1,108 @@ |
|
|
|
import React from 'react'; |
|
|
|
import React from 'react'; |
|
|
|
import { QueryLeafElem, QueryLeafBy, QueryLeafOp, QueryElem } from '../../lib/Query'; |
|
|
|
import { QueryLeafElem, QueryLeafBy, QueryLeafOp, QueryElem } from '../../lib/query/Query'; |
|
|
|
import { Chip, Typography } from '@material-ui/core'; |
|
|
|
import { Chip, Typography, IconButton, Box } from '@material-ui/core'; |
|
|
|
import { QBQueryPlaceholder } from './QBQueryPlaceholder'; |
|
|
|
import { QBQueryPlaceholder } from './QBQueryPlaceholder'; |
|
|
|
|
|
|
|
import CloseIcon from '@material-ui/icons/Close'; |
|
|
|
|
|
|
|
|
|
|
|
export interface ElemChipProps { |
|
|
|
export interface ElemChipProps { |
|
|
|
label: any |
|
|
|
label: any, |
|
|
|
|
|
|
|
extraElements?: any, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function LabeledElemChip(props: ElemChipProps) { |
|
|
|
export function LabeledElemChip(props: ElemChipProps) { |
|
|
|
const label = <Typography>{props.label}</Typography> |
|
|
|
const label = <Box display="flex" alignItems="center"> |
|
|
|
|
|
|
|
<Typography>{props.label}</Typography> |
|
|
|
|
|
|
|
{props.extraElements} |
|
|
|
|
|
|
|
</Box> |
|
|
|
return <Chip label={label} /> |
|
|
|
return <Chip label={label} /> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export interface LeafProps { |
|
|
|
export interface LeafProps { |
|
|
|
elem: QueryLeafElem |
|
|
|
elem: QueryLeafElem, |
|
|
|
onReplace: (q: QueryElem) => void |
|
|
|
onReplace: (q: QueryElem) => void, |
|
|
|
|
|
|
|
extraElements?: any, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function QBQueryElemArtistEquals(props: LeafProps) { |
|
|
|
export function QBQueryElemArtistEquals(props: LeafProps) { |
|
|
|
return <LabeledElemChip label={"By " + props.elem.b}/> |
|
|
|
return <LabeledElemChip |
|
|
|
|
|
|
|
label={"By " + props.elem.b} |
|
|
|
|
|
|
|
extraElements={props.extraElements} |
|
|
|
|
|
|
|
/> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function QBQueryElemArtistLike(props: LeafProps) { |
|
|
|
export function QBQueryElemArtistLike(props: LeafProps) { |
|
|
|
return <LabeledElemChip label={"Artist like \"" + props.elem.b + "\""}/> |
|
|
|
return <LabeledElemChip label={"Artist like \"" + props.elem.b + "\""} |
|
|
|
|
|
|
|
extraElements={props.extraElements} |
|
|
|
|
|
|
|
/> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function QBQueryElemTitleEquals(props: LeafProps) { |
|
|
|
export function QBQueryElemTitleEquals(props: LeafProps) { |
|
|
|
return <LabeledElemChip label={"\"" + props.elem.b + "\""}/> |
|
|
|
return <LabeledElemChip |
|
|
|
|
|
|
|
label={"\"" + props.elem.b + "\""} |
|
|
|
|
|
|
|
extraElements={props.extraElements} |
|
|
|
|
|
|
|
/> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function QBQueryElemTitleLike(props: LeafProps) { |
|
|
|
export function QBQueryElemTitleLike(props: LeafProps) { |
|
|
|
return <LabeledElemChip label={"Title like \"" + props.elem.b + "\""}/> |
|
|
|
return <LabeledElemChip |
|
|
|
|
|
|
|
label={"Title like \"" + props.elem.b + "\""} |
|
|
|
|
|
|
|
extraElements={props.extraElements} |
|
|
|
|
|
|
|
/> |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export function QBQueryLeafElem(props: LeafProps) { |
|
|
|
export interface DeleteButtonProps { |
|
|
|
|
|
|
|
onClick?: (e: any) => void, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function QBQueryElemDeleteButton(props: DeleteButtonProps) { |
|
|
|
|
|
|
|
return <IconButton onClick={props.onClick} size="small"> |
|
|
|
|
|
|
|
<CloseIcon /> |
|
|
|
|
|
|
|
</IconButton> |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface IProps { |
|
|
|
|
|
|
|
elem: QueryLeafElem, |
|
|
|
|
|
|
|
onReplace: (q: QueryElem | null) => void, |
|
|
|
|
|
|
|
editingQuery: boolean, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export function QBQueryLeafElem(props: IProps) { |
|
|
|
let e = props.elem; |
|
|
|
let e = props.elem; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const extraElements = props.editingQuery ? |
|
|
|
|
|
|
|
<QBQueryElemDeleteButton |
|
|
|
|
|
|
|
onClick={() => props.onReplace(null)} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
: undefined; |
|
|
|
|
|
|
|
|
|
|
|
if (e.a == QueryLeafBy.ArtistName && |
|
|
|
if (e.a == QueryLeafBy.ArtistName && |
|
|
|
e.leafOp == QueryLeafOp.Equals && |
|
|
|
e.leafOp == QueryLeafOp.Equals && |
|
|
|
typeof e.b == "string") { |
|
|
|
typeof e.b == "string") { |
|
|
|
return <QBQueryElemArtistEquals {...props} /> |
|
|
|
return <QBQueryElemArtistEquals |
|
|
|
|
|
|
|
{...props} |
|
|
|
|
|
|
|
extraElements={extraElements} |
|
|
|
|
|
|
|
/> |
|
|
|
} else if (e.a == QueryLeafBy.ArtistName && |
|
|
|
} else if (e.a == QueryLeafBy.ArtistName && |
|
|
|
e.leafOp == QueryLeafOp.Like && |
|
|
|
e.leafOp == QueryLeafOp.Like && |
|
|
|
typeof e.b == "string") { |
|
|
|
typeof e.b == "string") { |
|
|
|
return <QBQueryElemArtistLike {...props} /> |
|
|
|
return <QBQueryElemArtistLike |
|
|
|
|
|
|
|
{...props} |
|
|
|
|
|
|
|
extraElements={extraElements} |
|
|
|
|
|
|
|
/> |
|
|
|
} if (e.a == QueryLeafBy.SongTitle && |
|
|
|
} if (e.a == QueryLeafBy.SongTitle && |
|
|
|
e.leafOp == QueryLeafOp.Equals && |
|
|
|
e.leafOp == QueryLeafOp.Equals && |
|
|
|
typeof e.b == "string") { |
|
|
|
typeof e.b == "string") { |
|
|
|
return <QBQueryElemTitleEquals {...props} /> |
|
|
|
return <QBQueryElemTitleEquals |
|
|
|
|
|
|
|
{...props} |
|
|
|
|
|
|
|
extraElements={extraElements} |
|
|
|
|
|
|
|
/> |
|
|
|
} else if (e.a == QueryLeafBy.SongTitle && |
|
|
|
} else if (e.a == QueryLeafBy.SongTitle && |
|
|
|
e.leafOp == QueryLeafOp.Like && |
|
|
|
e.leafOp == QueryLeafOp.Like && |
|
|
|
typeof e.b == "string") { |
|
|
|
typeof e.b == "string") { |
|
|
|
return <QBQueryElemTitleLike {...props} /> |
|
|
|
return <QBQueryElemTitleLike |
|
|
|
|
|
|
|
{...props} |
|
|
|
|
|
|
|
extraElements={extraElements} |
|
|
|
|
|
|
|
/> |
|
|
|
} else if (e.leafOp == QueryLeafOp.Placeholder) { |
|
|
|
} else if (e.leafOp == QueryLeafOp.Placeholder) { |
|
|
|
return <QBQueryPlaceholder |
|
|
|
return <QBQueryPlaceholder |
|
|
|
onReplace={props.onReplace} |
|
|
|
onReplace={props.onReplace} |
|
|
|