Deleting query elements works.

pull/16/head
Sander Vocke 5 years ago
parent 475cd2cf2f
commit a36830802f
  1. 2
      client/src/components/Window.tsx
  2. 12
      client/src/components/querybuilder/QBQueryElem.tsx
  3. 2
      client/src/components/querybuilder/QBQueryElemMenu.tsx
  4. 81
      client/src/components/querybuilder/QBQueryLeafElem.tsx
  5. 28
      client/src/components/querybuilder/QBQueryNodeElem.tsx
  6. 2
      client/src/components/querybuilder/QBQueryPlaceholder.tsx
  7. 3
      client/src/components/querybuilder/QueryBuilder.tsx
  8. 0
      client/src/lib/query/Query.tsx

@ -1,6 +1,6 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { ThemeProvider, CssBaseline, createMuiTheme } from '@material-ui/core'; import { ThemeProvider, CssBaseline, createMuiTheme } from '@material-ui/core';
import { QueryElem } from '../lib/Query'; import { QueryElem } from '../lib/query/Query';
import QueryBuilder from './querybuilder/QueryBuilder'; import QueryBuilder from './querybuilder/QueryBuilder';
const darkTheme = createMuiTheme({ const darkTheme = createMuiTheme({

@ -1,22 +1,28 @@
import React from 'react'; import React from 'react';
import { QueryLeafElem, QueryNodeElem, QueryElem, isLeafElem, isNodeElem } from '../../lib/Query'; import { QueryLeafElem, QueryNodeElem, QueryElem, isLeafElem, isNodeElem } from '../../lib/query/Query';
import { QBQueryLeafElem } from './QBQueryLeafElem'; import { QBQueryLeafElem } from './QBQueryLeafElem';
import { QBQueryNodeElem } from './QBQueryNodeElem'; import { QBQueryNodeElem } from './QBQueryNodeElem';
export interface IProps { export interface IProps {
elem: QueryLeafElem | QueryNodeElem, elem: QueryLeafElem | QueryNodeElem,
onReplace: (q: QueryElem) => void, onReplace: (q: QueryElem | null) => void,
editingQuery: boolean,
} }
export function QBQueryElem(props: IProps) { export function QBQueryElem(props: IProps) {
let e = props.elem; let e = props.elem;
if (isLeafElem(e)) { if (isLeafElem(e)) {
return <QBQueryLeafElem elem={e} onReplace={props.onReplace} /> return <QBQueryLeafElem
elem={e}
onReplace={props.onReplace}
editingQuery={props.editingQuery}
/>
} else if (isNodeElem(e)) { } else if (isNodeElem(e)) {
return <QBQueryNodeElem return <QBQueryNodeElem
elem={e} elem={e}
onReplace={props.onReplace} onReplace={props.onReplace}
editingQuery={props.editingQuery}
/> />
} }

@ -1,7 +1,7 @@
import React, { useState } from 'react'; import React, { useState } from 'react';
import { Menu, TextField } from '@material-ui/core'; import { Menu, TextField } 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'; import { QueryElem, QueryLeafBy, QueryLeafOp } from '../../lib/query/Query';
import Autocomplete from '@material-ui/lab/Autocomplete' import Autocomplete from '@material-ui/lab/Autocomplete'
export interface FreeSoloInputProps { export interface FreeSoloInputProps {

@ -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}

@ -1,34 +1,36 @@
import React from 'react'; import React from 'react';
import QBOrBlock from './QBOrBlock'; import QBOrBlock from './QBOrBlock';
import QBAndBlock from './QBAndBlock'; import QBAndBlock from './QBAndBlock';
import { QueryNodeElem, QueryNodeOp, QueryElem, isNodeElem } from '../../lib/Query'; import { QueryNodeElem, QueryNodeOp, QueryElem, isNodeElem, simplify } from '../../lib/query/Query';
import { QBQueryLeafElem } from './QBQueryLeafElem'; import { QBQueryLeafElem } from './QBQueryLeafElem';
import { QBQueryElem } from './QBQueryElem';
import { O_APPEND } from 'constants';
export interface NodeProps { export interface NodeProps {
elem: QueryNodeElem, elem: QueryNodeElem,
onReplace: (q: QueryElem) => void, onReplace: (q: QueryElem | null) => void,
editingQuery: boolean,
} }
export function QBQueryNodeElem(props: NodeProps) { export function QBQueryNodeElem(props: NodeProps) {
let e = props.elem; let e = props.elem;
const onReplace = (idx: number, q: QueryElem) => { const onReplace = (idx: number, q: QueryElem | null) => {
var ops = e.operands; var ops = e.operands;
ops[idx] = q; if (q) {
let newNode = { operands: ops, nodeOp: e.nodeOp }; ops[idx] = q;
} else {
ops.splice(idx, 1);
}
let newNode = simplify({ operands: ops, nodeOp: e.nodeOp });
props.onReplace(newNode); props.onReplace(newNode);
} }
const children = e.operands.map((o: any, idx: number) => { const children = e.operands.map((o: any, idx: number) => {
if (isNodeElem(o)) { return <QBQueryElem
return <QBQueryNodeElem
elem={o}
onReplace={(q: QueryElem) => onReplace(idx, q)}
/>
}
return <QBQueryLeafElem
elem={o} elem={o}
onReplace={(q: QueryElem) => onReplace(idx, q)} onReplace={(q: QueryElem | null) => onReplace(idx, q)}
editingQuery={props.editingQuery}
/> />
}); });

@ -1,7 +1,7 @@
import React from 'react'; import React from 'react';
import { Chip } from '@material-ui/core'; import { Chip } from '@material-ui/core';
import { QBQueryElemMenu } from './QBQueryElemMenu'; import { QBQueryElemMenu } from './QBQueryElemMenu';
import { QueryElem } from '../../lib/Query'; import { QueryElem } from '../../lib/query/Query';
export interface IProps { export interface IProps {
onReplace: (q: QueryElem) => void, onReplace: (q: QueryElem) => void,

@ -2,7 +2,7 @@ import React, { useState } from 'react';
import { Box } from '@material-ui/core'; import { Box } from '@material-ui/core';
import QBQueryButton from './QBQueryButton'; import QBQueryButton from './QBQueryButton';
import { QBQueryElem } from './QBQueryElem'; import { QBQueryElem } from './QBQueryElem';
import { QueryElem, addPlaceholders, removePlaceholders, simplify } from '../../lib/Query'; import { QueryElem, addPlaceholders, removePlaceholders, simplify } from '../../lib/query/Query';
export interface IProps { export interface IProps {
query: QueryElem | null, query: QueryElem | null,
@ -33,6 +33,7 @@ export default function QueryBuilder(props: IProps) {
{showQuery && <QBQueryElem {showQuery && <QBQueryElem
elem={showQuery} elem={showQuery}
onReplace={onReplace} onReplace={onReplace}
editingQuery={editing}
/>} />}
</Box> </Box>
</Box> </Box>

Loading…
Cancel
Save