Add is operator for delete and update operations

This commit is contained in:
Vik 2023-04-28 14:18:34 +05:30
parent f09554bd7b
commit 2928fc63ed
4 changed files with 48 additions and 27 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,11 +4,7 @@ import { TooljetDatabaseContext } from '@/TooljetDatabase/index';
import { uniqueId } from 'lodash';
import Select from '@/_ui/Select';
import { operators } from '@/TooljetDatabase/constants';
const isOperatorOptions = [
{ value: 'null', label: 'null' },
{ value: 'notNull', label: 'not null' },
];
import { isOperatorOptions } from './util';
export const ListRows = React.memo(({ currentState, darkMode }) => {
const { columns, listRowsOptions, limitOptionChanged, handleOptionsChange } = useContext(TooljetDatabaseContext);
@ -99,9 +95,6 @@ export const ListRows = React.memo(({ currentState, darkMode }) => {
updateFilterOptionsChanged({ ...listRowsOptions?.where_filters[id], ...{ value: newValue } });
};
console.log('value', value);
console.log('operator', operator);
return (
<div className="mt-1 row-container">
<div className="d-flex fields-container">
@ -127,7 +120,7 @@ export const ListRows = React.memo(({ currentState, darkMode }) => {
{operator === 'is' ? (
<Select
useMenuPortal={true}
placeholder="Select operation"
placeholder="Select value"
value={value}
options={isOperatorOptions}
onChange={handleValueChange}

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

@ -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' },
];