diff options
author | Valerij Fredriksen <valerijf@yahooinc.com> | 2022-08-08 13:19:59 +0200 |
---|---|---|
committer | Valerij Fredriksen <valerijf@yahooinc.com> | 2022-08-10 09:32:31 +0200 |
commit | 77b011ac29f968d041835cd67e81171c2ecbf375 (patch) | |
tree | 5de414d755250940b06e0e79938619c55b0239f8 | |
parent | 3db384229fe236cadb3ba4512f8b7fe23527c0f3 (diff) |
Import levelZeroParameters and childMap statically
7 files changed, 154 insertions, 153 deletions
diff --git a/client/js/app/src/app/pages/querybuilder/Components/Buttons/AddPropertyButton.jsx b/client/js/app/src/app/pages/querybuilder/Components/Buttons/AddPropertyButton.jsx index 47b5a67875b..70f20ddd673 100644 --- a/client/js/app/src/app/pages/querybuilder/Components/Buttons/AddPropertyButton.jsx +++ b/client/js/app/src/app/pages/querybuilder/Components/Buttons/AddPropertyButton.jsx @@ -1,9 +1,10 @@ import React, { useContext, useState } from 'react'; import { QueryInputContext } from '../Contexts/QueryInputContext'; import SimpleButton from './SimpleButton'; +import { childMap } from 'app/pages/querybuilder/parameters'; export default function AddPropertyButton({ id }) { - const { inputs, setInputs, childMap } = useContext(QueryInputContext); + const { inputs, setInputs } = useContext(QueryInputContext); const [childId, setChildId] = useState(1); /** diff --git a/client/js/app/src/app/pages/querybuilder/Components/Buttons/PasteJSONButton.jsx b/client/js/app/src/app/pages/querybuilder/Components/Buttons/PasteJSONButton.jsx index df380c62fa1..844b8ca4453 100644 --- a/client/js/app/src/app/pages/querybuilder/Components/Buttons/PasteJSONButton.jsx +++ b/client/js/app/src/app/pages/querybuilder/Components/Buttons/PasteJSONButton.jsx @@ -1,11 +1,14 @@ import React, { useContext, useState } from 'react'; -import ImageButton from './ImageButton'; import pasteImage from '../../assets/img/paste.svg'; import { QueryInputContext } from '../Contexts/QueryInputContext'; +import ImageButton from './ImageButton'; +import { + childMap, + levelZeroParameters, +} from 'app/pages/querybuilder/parameters'; export default function PasteJSONButton() { - const { setInputs, setId, levelZeroParameters, childMap } = - useContext(QueryInputContext); + const { setInputs, setId } = useContext(QueryInputContext); const [paste, setPaste] = useState(false); //TODO: fix that the second-level dropdowns do not get set properly when pasting a JSON query diff --git a/client/js/app/src/app/pages/querybuilder/Components/Contexts/QueryInputContext.jsx b/client/js/app/src/app/pages/querybuilder/Components/Contexts/QueryInputContext.jsx index bc21ea81d9a..061b291e329 100644 --- a/client/js/app/src/app/pages/querybuilder/Components/Contexts/QueryInputContext.jsx +++ b/client/js/app/src/app/pages/querybuilder/Components/Contexts/QueryInputContext.jsx @@ -1,4 +1,5 @@ -import React, { useState, createContext } from 'react'; +import React, { createContext, useState } from 'react'; +import { levelZeroParameters } from 'app/pages/querybuilder/parameters'; export const QueryInputContext = createContext(); @@ -6,126 +7,6 @@ export const QueryInputProvider = (prop) => { // This is the id of the newest QueryInput, gets updated each time a new one is added const [id, setId] = useState(1); - // These are the methods that can be chosen in a QueryInput - const levelZeroParameters = { - yql: { name: 'yql', type: 'String', hasChildren: false }, - hits: { name: 'hits', type: 'Integer', hasChildren: false }, - offset: { name: 'offset', type: 'Integer', hasChildren: false }, - queryProfile: { name: 'queryProfile', type: 'String', hasChildren: false }, - noCache: { name: 'noCache', type: 'Boolean', hasChildren: false }, - groupingSessionCache: { - name: 'groupingSessionCache', - type: 'Boolean', - hasChildren: false, - }, - searchChain: { name: 'searchChain', type: 'String', hasChildren: false }, - timeout: { name: 'timeout', type: 'Float', hasChildren: false }, - trace: { name: 'trace', type: 'Parent', hasChildren: true }, - tracelevel: { name: 'tracelevel', type: 'Parent', hasChildren: true }, - traceLevel: { name: 'traceLevel', type: 'Integer', hasChildren: false }, - explainLevel: { name: 'explainLevel', type: 'Integer', hasChildren: false }, - explainlevel: { name: 'explainlevel', type: 'Integer', hasChildren: false }, - model: { name: 'model', type: 'Parent', hasChildren: true }, - ranking: { name: 'ranking', type: 'Parent', hasChildren: true }, - collapse: { name: 'collapse', type: 'Parent', hasChildren: true }, - collapsesize: { name: 'collapsesize', type: 'Integer', hasChildren: false }, - collapsefield: { - name: 'collapsefield', - type: 'String', - hasChildren: false, - }, - presentation: { name: 'presentation', type: 'Parent', hasChildren: true }, - pos: { name: 'pos', type: 'Parent', hasChildren: true }, - streaming: { name: 'streaming', type: 'Parent', hasChildren: true }, - rules: { name: 'rules', type: 'Parent', hasChildren: true }, - recall: { name: 'recall', type: 'List', hasChildren: false }, - user: { name: 'user', type: 'String', hasChildren: false }, - metrics: { name: 'metrics', type: 'Parent', hasChildren: true }, - }; - - // Children of the levelZeroParameters that have child attributes - const childMap = { - collapse: { - summary: { name: 'summary', type: 'String', hasChildren: false }, - }, - metrics: { - ignore: { name: 'ignore', type: 'Boolean', hasChildren: false }, - }, - model: { - defaultIndex: { - name: 'defaultIndex', - type: 'String', - hasChildren: false, - }, - encoding: { name: 'encoding', type: 'String', hasChildren: false }, - language: { name: 'language', type: 'String', hasChildren: false }, - queryString: { name: 'queryString', type: 'String', hasChildren: false }, - restrict: { name: 'restrict', type: 'List', hasChildren: false }, - searchPath: { name: 'searchPath', type: 'String', hasChildren: false }, - sources: { name: 'sources', type: 'List', hasChildren: false }, - type: { name: 'type', type: 'String', hasChildren: false }, - }, - pos: { - ll: { name: 'll', type: 'String', hasChildren: false }, - radius: { name: 'radius', type: 'String', hasChildren: false }, - bb: { name: 'bb', type: 'List', hasChildren: false }, - attribute: { name: 'attribute', type: 'String', hasChildren: false }, - }, - presentation: { - bolding: { name: 'bolding', type: 'Boolean', hasChildren: false }, - format: { name: 'format', type: 'String', hasChildren: false }, - summary: { name: 'summary', type: 'String', hasChildren: false }, - template: { name: 'template', type: 'String', hasChildren: false }, - timing: { name: 'timing', type: 'Boolean', hasChildren: false }, - }, - ranking: { - location: { name: 'location', type: 'String', hasChildren: false }, - features: { name: 'features', type: 'String', hasChildren: false }, - listFeatures: { - name: 'listFeatures', - type: 'Boolean', - hasChildren: false, - }, - profile: { name: 'profile', type: 'String', hasChildren: false }, - properties: { name: 'properties', type: 'String', hasChildren: false }, - sorting: { name: 'sorting', type: 'String', hasChildren: false }, - freshness: { name: 'freshness', type: 'String', hasChildren: false }, - queryCache: { name: 'queryCache', type: 'Boolean', hasChildren: false }, - matchPhase: { name: 'matchPhase', type: 'Parent', hasChildren: true }, - }, - ranking_matchPhase: { - maxHits: { name: 'maxHits', type: 'Long', hasChildren: false }, - attribute: { name: 'attribute', type: 'String', hasChildren: false }, - ascending: { name: 'ascending', type: 'Boolean', hasChildren: false }, - diversity: { name: 'diversity', type: 'Parent', hasChildren: true }, - }, - ranking_matchPhase_diversity: { - attribute: { name: 'attribute', type: 'String', hasChildren: false }, - minGroups: { name: 'minGroups', type: 'Long', hasChildren: false }, - }, - rules: { - off: { name: 'off', type: 'Boolean', hasChildren: false }, - rulebase: { name: 'rulebase', type: 'String', hasChildren: false }, - }, - streaming: { - userid: { name: 'userid', type: 'Integer', hasChildren: false }, - groupname: { name: 'groupname', type: 'String', hasChildren: false }, - selection: { name: 'selection', type: 'String', hasChildren: false }, - priority: { name: 'priority', type: 'String', hasChildren: false }, - maxbucketspervisitor: { - name: 'maxbucketspervisitor', - type: 'Integer', - hasChildren: false, - }, - }, - trace: { - timestamps: { name: 'timestamps', type: 'Boolean', hasChildren: false }, - }, - tracelevel: { - rules: { name: 'rules', type: 'Integer', hasChildren: false }, - }, - }; - const firstChoice = levelZeroParameters[Object.keys(levelZeroParameters)[0]]; const [inputs, setInputs] = useState([ @@ -148,8 +29,6 @@ export const QueryInputProvider = (prop) => { setInputs, id, setId, - levelZeroParameters, - childMap, selectedItems, setSelectedItems, }} diff --git a/client/js/app/src/app/pages/querybuilder/Components/Text/QueryDropDownForm.jsx b/client/js/app/src/app/pages/querybuilder/Components/Text/QueryDropDownForm.jsx index 88bd545282a..285a29a2c3e 100644 --- a/client/js/app/src/app/pages/querybuilder/Components/Text/QueryDropDownForm.jsx +++ b/client/js/app/src/app/pages/querybuilder/Components/Text/QueryDropDownForm.jsx @@ -1,6 +1,10 @@ import React, { useContext, useState } from 'react'; import { QueryInputContext } from '../Contexts/QueryInputContext'; import SimpleDropDownForm from './SimpleDropDownForm'; +import { + childMap, + levelZeroParameters, +} from 'app/pages/querybuilder/parameters'; export default function QueryDropdownForm({ choices, @@ -8,14 +12,8 @@ export default function QueryDropdownForm({ child = false, initial, }) { - const { - inputs, - setInputs, - levelZeroParameters, - childMap, - selectedItems, - setSelectedItems, - } = useContext(QueryInputContext); + const { inputs, setInputs, selectedItems, setSelectedItems } = + useContext(QueryInputContext); const [choice, setChoice] = useState(); /** @@ -51,8 +49,7 @@ export default function QueryDropdownForm({ setSelectedItems([...selectedItems, newType]); } else { newInputs[index].type = newType; - let hasChildren = levelZeroParameters[newType].hasChildren; - newInputs[index].hasChildren = hasChildren; + newInputs[index].hasChildren = levelZeroParameters[newType].hasChildren; newInputs[index].children = []; newInputs[index].typeof = levelZeroParameters[newType].type; setSelectedItems([...selectedItems, newType]); diff --git a/client/js/app/src/app/pages/querybuilder/Components/Text/QueryInput.jsx b/client/js/app/src/app/pages/querybuilder/Components/Text/QueryInput.jsx index bd41edd6008..fb760b2060a 100644 --- a/client/js/app/src/app/pages/querybuilder/Components/Text/QueryInput.jsx +++ b/client/js/app/src/app/pages/querybuilder/Components/Text/QueryInput.jsx @@ -1,15 +1,15 @@ import React, { useContext } from 'react'; -import SimpleButton from '../Buttons/SimpleButton'; -import SimpleForm from './SimpleForm'; import { OverlayTrigger, Tooltip } from 'react-bootstrap'; +import AddPropertyButton from '../Buttons/AddPropertyButton'; +import SimpleButton from '../Buttons/SimpleButton'; import { QueryInputContext } from '../Contexts/QueryInputContext'; import QueryDropdownForm from './QueryDropDownForm'; -import AddPropertyButton from '../Buttons/AddPropertyButton'; import QueryInputChild from './QueryInputChild'; +import SimpleForm from './SimpleForm'; +import { levelZeroParameters } from 'app/pages/querybuilder/parameters'; export default function QueryInput() { - const { inputs, setInputs, levelZeroParameters } = - useContext(QueryInputContext); + const { inputs, setInputs } = useContext(QueryInputContext); function removeRow(id) { const newList = inputs.filter((item) => item.id !== id); @@ -66,8 +66,9 @@ export default function QueryInput() { id={`b${value.id}`} className="removeRow" onClick={() => removeRow(value.id)} - children="-" - ></SimpleButton> + > + - + </SimpleButton> </span> </OverlayTrigger> <br /> diff --git a/client/js/app/src/app/pages/querybuilder/Components/Text/QueryInputChild.jsx b/client/js/app/src/app/pages/querybuilder/Components/Text/QueryInputChild.jsx index 4ab2a074214..60afc3050d3 100644 --- a/client/js/app/src/app/pages/querybuilder/Components/Text/QueryInputChild.jsx +++ b/client/js/app/src/app/pages/querybuilder/Components/Text/QueryInputChild.jsx @@ -1,13 +1,14 @@ import React, { useContext } from 'react'; +import { OverlayTrigger, Tooltip } from 'react-bootstrap'; import AddPropertyButton from '../Buttons/AddPropertyButton'; +import SimpleButton from '../Buttons/SimpleButton'; import { QueryInputContext } from '../Contexts/QueryInputContext'; import QueryDropdownForm from './QueryDropDownForm'; import SimpleForm from './SimpleForm'; -import { OverlayTrigger, Tooltip } from 'react-bootstrap'; -import SimpleButton from '../Buttons/SimpleButton'; +import { childMap } from 'app/pages/querybuilder/parameters'; export default function QueryInputChild({ id }) { - const { inputs, setInputs, childMap } = useContext(QueryInputContext); + const { inputs, setInputs } = useContext(QueryInputContext); let index = inputs.findIndex((element) => element.id === id); let childArray = inputs[index].children; @@ -126,8 +127,9 @@ export default function QueryInputChild({ id }) { id={`b${child.id}`} className="removeRow" onClick={() => removeRow(child.id)} - children="-" - ></SimpleButton> + > + - + </SimpleButton> </span> </OverlayTrigger> <br /> @@ -146,8 +148,6 @@ export default function QueryInputChild({ id }) { } function Child({ child, type, onChange, placeholder, removeRow }) { - const { childMap } = useContext(QueryInputContext); - const nestedChildren = (child.children || []).map((child) => { return ( <div key={child.id}> @@ -180,8 +180,9 @@ function Child({ child, type, onChange, placeholder, removeRow }) { id={`b${child.id}`} className="removeRow" onClick={() => removeRow(child.id)} - children="-" - ></SimpleButton> + > + - + </SimpleButton> </span> </OverlayTrigger> <br /> diff --git a/client/js/app/src/app/pages/querybuilder/parameters.jsx b/client/js/app/src/app/pages/querybuilder/parameters.jsx new file mode 100644 index 00000000000..9f9567c8ea4 --- /dev/null +++ b/client/js/app/src/app/pages/querybuilder/parameters.jsx @@ -0,0 +1,119 @@ +// These are the methods that can be chosen in a QueryInput +export const levelZeroParameters = { + yql: { name: 'yql', type: 'String', hasChildren: false }, + hits: { name: 'hits', type: 'Integer', hasChildren: false }, + offset: { name: 'offset', type: 'Integer', hasChildren: false }, + queryProfile: { name: 'queryProfile', type: 'String', hasChildren: false }, + noCache: { name: 'noCache', type: 'Boolean', hasChildren: false }, + groupingSessionCache: { + name: 'groupingSessionCache', + type: 'Boolean', + hasChildren: false, + }, + searchChain: { name: 'searchChain', type: 'String', hasChildren: false }, + timeout: { name: 'timeout', type: 'Float', hasChildren: false }, + trace: { name: 'trace', type: 'Parent', hasChildren: true }, + tracelevel: { name: 'tracelevel', type: 'Parent', hasChildren: true }, + traceLevel: { name: 'traceLevel', type: 'Integer', hasChildren: false }, + explainLevel: { name: 'explainLevel', type: 'Integer', hasChildren: false }, + explainlevel: { name: 'explainlevel', type: 'Integer', hasChildren: false }, + model: { name: 'model', type: 'Parent', hasChildren: true }, + ranking: { name: 'ranking', type: 'Parent', hasChildren: true }, + collapse: { name: 'collapse', type: 'Parent', hasChildren: true }, + collapsesize: { name: 'collapsesize', type: 'Integer', hasChildren: false }, + collapsefield: { + name: 'collapsefield', + type: 'String', + hasChildren: false, + }, + presentation: { name: 'presentation', type: 'Parent', hasChildren: true }, + pos: { name: 'pos', type: 'Parent', hasChildren: true }, + streaming: { name: 'streaming', type: 'Parent', hasChildren: true }, + rules: { name: 'rules', type: 'Parent', hasChildren: true }, + recall: { name: 'recall', type: 'List', hasChildren: false }, + user: { name: 'user', type: 'String', hasChildren: false }, + metrics: { name: 'metrics', type: 'Parent', hasChildren: true }, +}; + +// Children of the levelZeroParameters that have child attributes +export const childMap = { + collapse: { + summary: { name: 'summary', type: 'String', hasChildren: false }, + }, + metrics: { + ignore: { name: 'ignore', type: 'Boolean', hasChildren: false }, + }, + model: { + defaultIndex: { + name: 'defaultIndex', + type: 'String', + hasChildren: false, + }, + encoding: { name: 'encoding', type: 'String', hasChildren: false }, + language: { name: 'language', type: 'String', hasChildren: false }, + queryString: { name: 'queryString', type: 'String', hasChildren: false }, + restrict: { name: 'restrict', type: 'List', hasChildren: false }, + searchPath: { name: 'searchPath', type: 'String', hasChildren: false }, + sources: { name: 'sources', type: 'List', hasChildren: false }, + type: { name: 'type', type: 'String', hasChildren: false }, + }, + pos: { + ll: { name: 'll', type: 'String', hasChildren: false }, + radius: { name: 'radius', type: 'String', hasChildren: false }, + bb: { name: 'bb', type: 'List', hasChildren: false }, + attribute: { name: 'attribute', type: 'String', hasChildren: false }, + }, + presentation: { + bolding: { name: 'bolding', type: 'Boolean', hasChildren: false }, + format: { name: 'format', type: 'String', hasChildren: false }, + summary: { name: 'summary', type: 'String', hasChildren: false }, + template: { name: 'template', type: 'String', hasChildren: false }, + timing: { name: 'timing', type: 'Boolean', hasChildren: false }, + }, + ranking: { + location: { name: 'location', type: 'String', hasChildren: false }, + features: { name: 'features', type: 'String', hasChildren: false }, + listFeatures: { + name: 'listFeatures', + type: 'Boolean', + hasChildren: false, + }, + profile: { name: 'profile', type: 'String', hasChildren: false }, + properties: { name: 'properties', type: 'String', hasChildren: false }, + sorting: { name: 'sorting', type: 'String', hasChildren: false }, + freshness: { name: 'freshness', type: 'String', hasChildren: false }, + queryCache: { name: 'queryCache', type: 'Boolean', hasChildren: false }, + matchPhase: { name: 'matchPhase', type: 'Parent', hasChildren: true }, + }, + ranking_matchPhase: { + maxHits: { name: 'maxHits', type: 'Long', hasChildren: false }, + attribute: { name: 'attribute', type: 'String', hasChildren: false }, + ascending: { name: 'ascending', type: 'Boolean', hasChildren: false }, + diversity: { name: 'diversity', type: 'Parent', hasChildren: true }, + }, + ranking_matchPhase_diversity: { + attribute: { name: 'attribute', type: 'String', hasChildren: false }, + minGroups: { name: 'minGroups', type: 'Long', hasChildren: false }, + }, + rules: { + off: { name: 'off', type: 'Boolean', hasChildren: false }, + rulebase: { name: 'rulebase', type: 'String', hasChildren: false }, + }, + streaming: { + userid: { name: 'userid', type: 'Integer', hasChildren: false }, + groupname: { name: 'groupname', type: 'String', hasChildren: false }, + selection: { name: 'selection', type: 'String', hasChildren: false }, + priority: { name: 'priority', type: 'String', hasChildren: false }, + maxbucketspervisitor: { + name: 'maxbucketspervisitor', + type: 'Integer', + hasChildren: false, + }, + }, + trace: { + timestamps: { name: 'timestamps', type: 'Boolean', hasChildren: false }, + }, + tracelevel: { + rules: { name: 'rules', type: 'Integer', hasChildren: false }, + }, +}; |