Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement]Add null support in WHERE Clause for VQL Builder #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ export default function QueryFilterRow({
onChange={(newValue) => handleSelectedFilterEdits(newValue, filterRowIndex, 'value')}
/>
</Box>
: <Input
placeholder={operator.value === 'CONTAINS' ? `Enter comma-separated values (${fieldType})` : (fieldType) ? `Value (${fieldType})` : 'Value'}
value={filter.value}
onChange={(event) => handleSelectedFilterEdits(event.target.value, filterRowIndex, 'value')}
{...InputStyle}
/>
: <>
{ filter?.operator.value !== "IS NULL" && filter?.operator.value !== "IS NOT NULL" &&
( <Input
placeholder={operator.value === 'CONTAINS' ? `Enter comma-separated values (${fieldType})` : (fieldType) ? `Value (${fieldType})` : 'Value'}
value={filter.value}
onChange={(event) => handleSelectedFilterEdits(event.target.value, filterRowIndex, 'value')}
{...InputStyle}
/> )}
</>
}
</>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export default function VqlDefinitions() {

const defaultOperators = ['=', '!=', '<', '>', '<=', '>=', 'CONTAINS', 'LIKE'];
const defaultOperators = ['=', '!=', '<', '>', '<=', '>=', 'CONTAINS', 'LIKE', 'IS NULL', 'IS NOT NULL'];
const booleanValues = ['true', 'false'];

const attachmentsQueryTarget = {
Expand Down
24 changes: 23 additions & 1 deletion frontend/src/app/hooks/vql-editor/useQueryBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,10 @@ export default function useQueryBuilder({ setCode }) {
}

whereClause += `(${filter?.field?.value} ${filter.operator.value} (${filterValue}))`
} else if (filter?.operator.value == "IS NULL") {
whereClause += `(${filter?.field?.value} == null)`
} else if (filter?.operator.value == "IS NOT NULL") {
whereClause += `(${filter?.field?.value} != null)`
} else {
if (filter?.field.fieldType === 'String' || filter?.field.fieldType === 'Date' || filter?.field.fieldType === 'DateTime' || filter?.field.fieldType === 'ID') {
// Wrap all String/Date/DateTime/ID values in a string
Expand Down Expand Up @@ -363,7 +367,25 @@ export default function useQueryBuilder({ setCode }) {

if (selectedFilters?.length > 0) {
selectedFilters.forEach((filter, index) => {
if (!filter?.field || !filter?.operator || !filter?.value) { canBuild = false; }
if (!filter?.field) {
canBuild = false;
return;
}

if (!filter?.operator) {
canBuild = false;
return;
}

if (filter?.operator.value == 'IS NULL' ||filter?.operator.value == 'IS NOT NULL') {
canBuild = true;
return;
}

if (!filter?.value) {
canBuild = false;
return;
}
})
}

Expand Down