Merge pull request #6182 from ToolJet/feat/add_is_operator

feat: Add is operator in tooljet db query manager
This commit is contained in:
Akshay 2023-05-16 18:14:02 +05:30 committed by GitHub
commit 97b9608e28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 73 additions and 29 deletions

View file

@ -4,6 +4,7 @@ import { uniqueId } from 'lodash';
import { CodeHinter } from '@/Editor/CodeBuilder/CodeHinter';
import Select from '@/_ui/Select';
import { operators } from '@/TooljetDatabase/constants';
import { isOperatorOptions } from './util';
export const DeleteRows = React.memo(({ currentState, darkMode }) => {
const { columns, deleteOperationLimitOptionChanged, deleteRowsOptions, handleDeleteRowsOptionsChange } =
@ -83,15 +84,25 @@ export const DeleteRows = React.memo(({ currentState, darkMode }) => {
/>
</div>
<div className="field col-4">
<CodeHinter
currentState={currentState}
initialValue={value ? (typeof value === 'string' ? value : JSON.stringify(value)) : value}
className="codehinter-plugins"
theme={darkMode ? 'monokai' : 'default'}
height={'32px'}
placeholder="key"
onChange={(newValue) => handleValueChange(newValue)}
/>
{operator === 'is' ? (
<Select
useMenuPortal={true}
placeholder="Select value"
value={value}
options={isOperatorOptions}
onChange={handleValueChange}
/>
) : (
<CodeHinter
currentState={currentState}
initialValue={value ? (typeof value === 'string' ? value : JSON.stringify(value)) : value}
className="codehinter-plugins"
theme={darkMode ? 'monokai' : 'default'}
height={'32px'}
placeholder="key"
onChange={(newValue) => handleValueChange(newValue)}
/>
)}
</div>
<div className="col-1 cursor-pointer m-1 mr-2">
<svg

View file

@ -4,6 +4,7 @@ import { TooljetDatabaseContext } from '@/TooljetDatabase/index';
import { uniqueId } from 'lodash';
import Select from '@/_ui/Select';
import { operators } from '@/TooljetDatabase/constants';
import { isOperatorOptions } from './util';
export const ListRows = React.memo(({ currentState, darkMode }) => {
const { columns, listRowsOptions, limitOptionChanged, handleOptionsChange } = useContext(TooljetDatabaseContext);
@ -116,15 +117,25 @@ export const ListRows = React.memo(({ currentState, darkMode }) => {
/>
</div>
<div className="field col-4">
<CodeHinter
currentState={currentState}
initialValue={value ? (typeof value === 'string' ? value : JSON.stringify(value)) : value}
className="codehinter-plugins"
theme={darkMode ? 'monokai' : 'default'}
height={'32px'}
placeholder="key"
onChange={(newValue) => handleValueChange(newValue)}
/>
{operator === 'is' ? (
<Select
useMenuPortal={true}
placeholder="Select value"
value={value}
options={isOperatorOptions}
onChange={handleValueChange}
/>
) : (
<CodeHinter
currentState={currentState}
initialValue={value ? (typeof value === 'string' ? value : JSON.stringify(value)) : value}
className="codehinter-plugins"
theme={darkMode ? 'monokai' : 'default'}
height={'32px'}
placeholder="key"
onChange={(newValue) => handleValueChange(newValue)}
/>
)}
</div>
<div className="col-1 cursor-pointer m-1 mr-2">
<svg

View file

@ -4,6 +4,7 @@ import { TooljetDatabaseContext } from '@/TooljetDatabase/index';
import Select from '@/_ui/Select';
import { operators } from '@/TooljetDatabase/constants';
import { uniqueId } from 'lodash';
import { isOperatorOptions } from './util';
export const UpdateRows = React.memo(({ currentState, darkMode }) => {
const { columns, updateRowsOptions, handleUpdateRowsOptionsChange } = useContext(TooljetDatabaseContext);
@ -109,15 +110,25 @@ export const UpdateRows = React.memo(({ currentState, darkMode }) => {
/>
</div>
<div className="field col-4">
<CodeHinter
currentState={currentState}
initialValue={value ? (typeof value === 'string' ? value : JSON.stringify(value)) : value}
className="codehinter-plugins"
theme={darkMode ? 'monokai' : 'default'}
height={'32px'}
placeholder="key"
onChange={(newValue) => handleValueChange(newValue)}
/>
{operator === 'is' ? (
<Select
useMenuPortal={true}
placeholder="Select value"
value={value}
options={isOperatorOptions}
onChange={handleValueChange}
/>
) : (
<CodeHinter
currentState={currentState}
initialValue={value ? (typeof value === 'string' ? value : JSON.stringify(value)) : value}
className="codehinter-plugins"
theme={darkMode ? 'monokai' : 'default'}
height={'32px'}
placeholder="key"
onChange={(newValue) => handleValueChange(newValue)}
/>
)}
</div>
<div className="col-1 cursor-pointer m-1 mr-2">
<svg

View file

@ -49,7 +49,6 @@ function buildPostgrestQuery(filters) {
}
}
});
return postgrestQueryBuilder.url.toString();
}

View file

@ -1,4 +1,5 @@
import { get } from 'lodash';
/**
* Checks if the queryOptions object contains a filter with an 'eq' (equal) operator and a value equal to '{{null}}'.
*
@ -34,3 +35,8 @@ export const hasEqualWithNull = (queryOptions, operation) => {
}
return false;
};
export const isOperatorOptions = [
{ value: 'null', label: 'null' },
{ value: 'notNull', label: 'not null' },
];

View file

@ -19,4 +19,5 @@ export const operators = [
{ value: 'match', label: 'match' },
{ value: 'imatch', label: 'imatch' },
{ value: 'in', label: 'in' },
{ value: 'is', label: 'is' },
];

View file

@ -132,9 +132,14 @@ export default class PostgrestQueryBuilder {
* @param value The value to filter with.
*/
is(column, value) {
this.url.append(`${column}`, `is.${value}`);
if (value === 'notNull') {
this.url.append(`${column}`, `not.is.null`);
} else {
this.url.append(`${column}`, `is.${value}`);
}
return this;
}
/**
* Finds all rows whose value on the stated `column` is found on the
* specified `values`.