aboutsummaryrefslogtreecommitdiffstats
path: root/client/js
diff options
context:
space:
mode:
authorValerij Fredriksen <valerijf@yahooinc.com>2022-10-24 23:39:42 +0200
committerValerij Fredriksen <valerijf@yahooinc.com>2022-10-24 23:39:42 +0200
commite2b8e9ad11e6ac745f8397882d12c81c7e103285 (patch)
treee8dcd5dbd5fed18bc947af8848bd457df79b4607 /client/js
parent4a0f1f07f40874fc7ea08d48fa415e06043efb24 (diff)
Support ranking.features
Diffstat (limited to 'client/js')
-rw-r--r--client/js/app/src/app/pages/querybuilder/context/__test__/query-builder-provider.test.jsx39
-rw-r--r--client/js/app/src/app/pages/querybuilder/context/parameters.jsx2
-rw-r--r--client/js/app/src/app/pages/querybuilder/context/query-builder-provider.jsx17
-rw-r--r--client/js/app/src/app/pages/querybuilder/query-filters/query-filters.jsx45
4 files changed, 83 insertions, 20 deletions
diff --git a/client/js/app/src/app/pages/querybuilder/context/__test__/query-builder-provider.test.jsx b/client/js/app/src/app/pages/querybuilder/context/__test__/query-builder-provider.test.jsx
index 3915ccd61cd..bf164671639 100644
--- a/client/js/app/src/app/pages/querybuilder/context/__test__/query-builder-provider.test.jsx
+++ b/client/js/app/src/app/pages/querybuilder/context/__test__/query-builder-provider.test.jsx
@@ -52,11 +52,20 @@ test('manipulates inputs', () => {
[ACTION.INPUT_ADD, { id: '2', type: 'location' }],
[ACTION.INPUT_ADD, { id: '2', type: 'matchPhase' }],
[ACTION.INPUT_UPDATE, { id: '2.0', value: 'us' }],
+ [ACTION.INPUT_ADD, { id: '2', type: 'features' }],
+ [ACTION.INPUT_ADD, { id: '2.2', type: '' }],
+ [ACTION.INPUT_UPDATE, { id: '2.2.0', type: 'abc' }],
+ [ACTION.INPUT_UPDATE, { id: '2.2.0', value: '123' }],
]);
assert(
s2,
- { input: { offset: 12, ranking: { location: 'us', matchPhase: {} } } },
- { input: 'offset=12&ranking.location=us' },
+ {
+ input: {
+ offset: 12,
+ ranking: { location: 'us', matchPhase: {}, features: { abc: '123' } },
+ },
+ },
+ { input: 'offset=12&ranking.location=us&ranking.features.abc=123' },
[
{ id: '1', value: '12', type: 'offset' },
{
@@ -65,6 +74,11 @@ test('manipulates inputs', () => {
value: [
{ id: '2.0', value: 'us', type: 'location' },
{ id: '2.1', type: 'matchPhase', value: [] },
+ {
+ id: '2.2',
+ type: 'features',
+ value: [{ id: '2.2.0', type: 'abc', value: '123' }],
+ },
],
},
]
@@ -147,6 +161,27 @@ test('set query', () => {
},
]);
+ assert(
+ '{"ranking":{"features":{"abc":"123","def":"456"}}}',
+ 'ranking.features.abc=123&ranking.features.def=456',
+ [
+ {
+ id: '0',
+ type: 'ranking',
+ value: [
+ {
+ id: '0.0',
+ type: 'features',
+ value: [
+ { id: '0.0.0', type: 'abc', value: '123' },
+ { id: '0.0.1', type: 'def', value: '456' },
+ ],
+ },
+ ],
+ },
+ ]
+ );
+
let msg = "Unknown property 'asd' on root level";
error('POST', '{"asd":123}', msg);
error('GET', 'asd=123', msg);
diff --git a/client/js/app/src/app/pages/querybuilder/context/parameters.jsx b/client/js/app/src/app/pages/querybuilder/context/parameters.jsx
index 6b73f72113d..9803d824d53 100644
--- a/client/js/app/src/app/pages/querybuilder/context/parameters.jsx
+++ b/client/js/app/src/app/pages/querybuilder/context/parameters.jsx
@@ -35,7 +35,7 @@ export default {
type: 'Parent',
children: {
location: { name: 'location', type: 'String' },
- features: { name: 'features', type: 'String' },
+ features: { name: 'features', type: 'Parent', children: 'String' },
listFeatures: { name: 'listFeatures', type: 'Boolean' },
profile: { name: 'profile', type: 'String' },
properties: { name: 'properties', type: 'String' },
diff --git a/client/js/app/src/app/pages/querybuilder/context/query-builder-provider.jsx b/client/js/app/src/app/pages/querybuilder/context/query-builder-provider.jsx
index 596085b8fba..df9b8a105a0 100644
--- a/client/js/app/src/app/pages/querybuilder/context/query-builder-provider.jsx
+++ b/client/js/app/src/app/pages/querybuilder/context/query-builder-provider.jsx
@@ -60,7 +60,10 @@ function jsonToInputs(json, parent = root) {
return Object.entries(json).map(([key, value], i) => {
const node = {
id: parent.id ? `${parent.id}.${i}` : i.toString(),
- type: parent.type.children[key],
+ type:
+ typeof parent.type.children === 'string'
+ ? { name: key, type: parent.type.children }
+ : parent.type.children[key],
};
if (!node.type) {
const location = parent.type.name
@@ -86,7 +89,7 @@ function jsonToInputs(json, parent = root) {
}
function parseInput(value, type) {
- if (type === 'Integer' || type === 'Long') return parseInt(value);
+ if (type === 'Integer') return parseInt(value);
if (type === 'Float') return parseFloat(value);
if (type === 'Boolean') return value.toLowerCase() === 'true';
return value;
@@ -98,7 +101,10 @@ function inputAdd(params, { id: parentId, type: typeName }) {
const nextId = parseInt(last(last(parent.value)?.id?.split('.')) ?? -1) + 1;
const id = parentId ? `${parentId}.${nextId}` : nextId.toString();
- const type = parent.type.children[typeName];
+ const type =
+ typeof parent.type.children === 'string'
+ ? { name: typeName, type: parent.type.children }
+ : parent.type.children[typeName];
parent.value.push({ id, value: type.children ? [] : '', type });
@@ -110,7 +116,10 @@ function inputUpdate(params, { id, type, value }) {
const node = findInput(cloned, id);
if (type) {
const parent = findInput(cloned, id.substring(0, id.lastIndexOf('.')));
- const newType = parent.type.children[type];
+ const newType =
+ typeof parent.type.children === 'string'
+ ? { name: type, type: parent.type.children }
+ : parent.type.children[type];
if ((node.type.children != null) !== (newType.children != null))
node.value = newType.children ? [] : '';
node.type = newType;
diff --git a/client/js/app/src/app/pages/querybuilder/query-filters/query-filters.jsx b/client/js/app/src/app/pages/querybuilder/query-filters/query-filters.jsx
index 178270eb71f..668164b54ee 100644
--- a/client/js/app/src/app/pages/querybuilder/query-filters/query-filters.jsx
+++ b/client/js/app/src/app/pages/querybuilder/query-filters/query-filters.jsx
@@ -26,17 +26,32 @@ function AddProperty(props) {
}
function Input({ id, value, types, type }) {
- const options = { [type.name]: type, ...types };
return (
<>
<Box sx={{ display: 'flex', alignItems: 'center', gap: '5px' }}>
- <Select
- sx={{ flex: 1 }}
- data={Object.values(options).map(({ name }) => name)}
- onChange={(type) => dispatch(ACTION.INPUT_UPDATE, { id, type })}
- value={type.name}
- searchable
- />
+ {types ? (
+ <Select
+ sx={{ flex: 1 }}
+ data={Object.values({ [type.name]: type, ...types }).map(
+ ({ name }) => name
+ )}
+ onChange={(type) => dispatch(ACTION.INPUT_UPDATE, { id, type })}
+ value={type.name}
+ searchable
+ />
+ ) : (
+ <TextInput
+ sx={{ flex: 1 }}
+ onChange={(event) =>
+ dispatch(ACTION.INPUT_UPDATE, {
+ id,
+ type: event.currentTarget.value,
+ })
+ }
+ placeholder="String"
+ value={type.name}
+ />
+ )}
{!type.children && (
<TextInput
sx={{ flex: 1 }}
@@ -75,16 +90,20 @@ function Input({ id, value, types, type }) {
function Inputs({ id, type, inputs }) {
const usedTypes = inputs.map(({ type }) => type.name);
- const remainingTypes = Object.fromEntries(
- Object.entries(type).filter(([name]) => !usedTypes.includes(name))
- );
- const firstRemaining = Object.keys(remainingTypes)[0];
+ const remainingTypes =
+ typeof type === 'string'
+ ? null
+ : Object.fromEntries(
+ Object.entries(type).filter(([name]) => !usedTypes.includes(name))
+ );
+ const firstRemaining = remainingTypes ? Object.keys(remainingTypes)[0] : '';
+
return (
<Container sx={{ rowGap: '5px' }}>
{inputs.map(({ id, value, type }) => (
<Input key={id} types={remainingTypes} {...{ id, value, type }} />
))}
- {firstRemaining && (
+ {firstRemaining != null && (
<>
{id != null ? (
<Container sx={{ justifyContent: 'start' }}>