Skip to content

Commit

Permalink
add nested field inside of dataprovider
Browse files Browse the repository at this point in the history
  • Loading branch information
XavierM committed Mar 5, 2021
1 parent 28750e9 commit 9a5df4f
Showing 1 changed file with 37 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,35 @@ const checkIfFieldTypeIsDate = (field: string, browserFields: BrowserFields) =>
return false;
};

const convertNestedFieldToQuery = (
field: string,
value: string | number,
browserFields: BrowserFields
) => {
const pathBrowserField = getBrowserFieldPath(field, browserFields);
const browserField = get(pathBrowserField, browserFields);
const nestedPath = browserField.subType.nested.path;
const key = field.replace(`${nestedPath}.`, '');
return `${nestedPath}: { ${key}: ${value} }`;
};

const convertNestedFieldToExistQuery = (field: string, browserFields: BrowserFields) => {
const pathBrowserField = getBrowserFieldPath(field, browserFields);
const browserField = get(pathBrowserField, browserFields);
const nestedPath = browserField.subType.nested.path;
const key = field.replace(`${nestedPath}.`, '');
return `${nestedPath}: { ${key}: * }`;
};

const checkIfFieldTypeIsNested = (field: string, browserFields: BrowserFields) => {
const pathBrowserField = getBrowserFieldPath(field, browserFields);
const browserField = get(pathBrowserField, browserFields);
if (browserField != null && browserField.subType) {
return true;
}
return false;
};

const buildQueryMatch = (
dataProvider: DataProvider | DataProvidersAnd,
browserFields: BrowserFields
Expand All @@ -73,11 +102,19 @@ const buildQueryMatch = (
dataProvider.type !== DataProviderType.template
? checkIfFieldTypeIsDate(dataProvider.queryMatch.field, browserFields)
? convertDateFieldToQuery(dataProvider.queryMatch.field, dataProvider.queryMatch.value)
: checkIfFieldTypeIsNested(dataProvider.queryMatch.field, browserFields)
? convertNestedFieldToQuery(
dataProvider.queryMatch.field,
dataProvider.queryMatch.value,
browserFields
)
: `${dataProvider.queryMatch.field} : ${
isNumber(dataProvider.queryMatch.value)
? dataProvider.queryMatch.value
: escapeQueryValue(dataProvider.queryMatch.value)
}`
: checkIfFieldTypeIsNested(dataProvider.queryMatch.field, browserFields)
? convertNestedFieldExistToQuery(dataProvider.queryMatch.field, browserFields)
: `${dataProvider.queryMatch.field} ${EXISTS_OPERATOR}`
}`.trim();

Expand Down

0 comments on commit 9a5df4f

Please sign in to comment.