add support for non-keyed set, time, mutex and decimals

This commit is contained in:
Stephanie Yang 2021-06-04 13:43:28 -05:00
parent 22d46a8afa
commit cc624a9c18
6 changed files with 70 additions and 31 deletions

View file

@ -203,7 +203,7 @@ export const MoleculaTable: FC<MoleculaTableProps> = ({
.map((field) => {
const { name, options, cardinality } = field;
const { type, keys, bitDepth, ...rest } = options;
const showKeys = ['set', 'time'].includes(type);
const showKeys = ['set', 'time', 'mutex'].includes(type);
return (
<TableRow key={`field-${name}`} className={css.row}>

View file

@ -147,7 +147,8 @@ export const QueryBuilder: FC<QueryBuilderProps> = ({
field: '',
rowOperator: '=',
value: '',
type: 'set'
type: 'set',
keys: true
}
];

View file

@ -40,9 +40,8 @@ export const RowCall: FC<RowCallProps> = ({
onRemoveGroup
}) => {
const [operatorEl, setOperatorEl] = useState<null | HTMLElement>(null);
const [activeOperatorEl, setActiveOperatorEl] = useState<null | HTMLElement>(
null
);
const [activeOperatorEl, setActiveOperatorEl] =
useState<null | HTMLElement>(null);
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
const [activeAnchor, setActiveAnchor] = useState<number>();
@ -51,7 +50,8 @@ export const RowCall: FC<RowCallProps> = ({
field: '',
rowOperator: '=',
value: '',
type: 'set'
type: 'set',
keys: true
};
if (op) {
@ -106,7 +106,10 @@ export const RowCall: FC<RowCallProps> = ({
</div>
{rowData.map((row, idx) => {
const { field, rowOperator, value, type } = row;
const { field, rowOperator, value, keys } = row;
const type = ['set', 'time', 'mutex'].includes(row.type)
? `${row.type}-${keys ? 'keys' : 'id'}`
: row.type;
let isInvalidValue = !value;
if (rowOperator === 'cidr') {
try {
@ -156,21 +159,24 @@ export const RowCall: FC<RowCallProps> = ({
options={fields.map((field) => {
return {
label: `${field.name} (${field.options.type})`,
value: field.name,
disabled:
!Object.keys(operators).includes(field.options.type) ||
(field.options.type === 'set' && !field.options.keys)
value: field.name
};
})}
onChange={(value) => {
const updatedField = fields.find((f) => f.name === value);
const rowUpdate =
row.type === updatedField.options.type
? { ...row, field: value, value: row.value }
? {
...row,
field: value,
value: row.value,
keys: updatedField.options.keys
}
: {
field: value,
rowOperator: '=',
type: updatedField.options.type,
keys: updatedField.options.keys,
value:
updatedField.options.type === 'timestamp'
? moment.utc().format()
@ -217,19 +223,7 @@ export const RowCall: FC<RowCallProps> = ({
</Menu>
</div>
{['int', 'set'].includes(type) ? (
<TextField
className={css.rowValue}
variant="outlined"
size="small"
value={value}
type={type === 'int' ? 'number' : 'text'}
error={showErrors && isInvalidValue}
onChange={(event) =>
onRowUpdate(idx, { ...row, value: event.target.value })
}
/>
) : type === 'timestamp' ? (
{type === 'timestamp' ? (
<MuiPickersUtilsProvider utils={MomentUtils}>
<DateTimePicker
variant="inline"
@ -253,7 +247,19 @@ export const RowCall: FC<RowCallProps> = ({
fullWidth
/>
</MuiPickersUtilsProvider>
) : null}
) : (
<TextField
className={css.rowValue}
variant="outlined"
size="small"
value={value}
type={type === 'int' ? 'number' : 'text'}
error={showErrors && isInvalidValue}
onChange={(event) =>
onRowUpdate(idx, { ...row, value: event.target.value })
}
/>
)}
{rowData.length > 1 ? (
<CloseIcon

View file

@ -1,4 +1,12 @@
export const operators = {
decimal: [
{ label: '>', value: '>' },
{ label: '<', value: '<' },
{ label: '>=', value: '>=' },
{ label: '<=', value: '<=' },
{ label: '==', value: '=' },
{ label: '!=', value: '!=' },
],
int: [
{ label: '>', value: '>' },
{ label: '<', value: '<' },
@ -7,12 +15,35 @@ export const operators = {
{ label: '==', value: '=' },
{ label: '!=', value: '!=' },
],
set: [
'mutex-id': [
{ label: 'is', value: '=' },
{ label: 'is not', value: '!=' }
],
'mutex-keys': [
{ label: 'is', value: '=' },
{ label: 'is not', value: '!=' },
{ label: 'like', value: 'like' },
{ label: 'CIDR', value: 'cidr' }
],
"set-id": [
{ label: 'is', value: '=' },
{ label: 'is not', value: '!=' }
],
"set-keys": [
{ label: 'is', value: '=' },
{ label: 'is not', value: '!=' },
{ label: 'like', value: 'like' },
{ label: 'CIDR', value: 'cidr' }
],
"time-id": [
{ label: 'is', value: '=' },
{ label: 'is not', value: '!=' }
],
"time-keys": [
{ label: 'is', value: '=' },
{ label: 'is not', value: '!=' },
{ label: 'like', value: 'like' }
],
timestamp: [
{ label: 'is before', value: '<' },
{ label: 'is after', value: '>' },

View file

@ -12,7 +12,8 @@ export type RowCallType = {
field: string;
rowOperator: string;
value: string;
type: 'set' | 'int' | 'timestamp';
type: string;
keys: boolean;
};
export type RowsCallType = {

View file

@ -8,7 +8,7 @@ export const stringifyRowData = (rowData: RowGrouping[], operator?: Operator) =>
rowsMap.push([]);
group.row.forEach((row) => {
let rowString = '';
const { field, rowOperator, value, type } = row;
const { field, rowOperator, value, type, keys } = row;
const isNegatory = rowOperator === '!=';
const isUnion =
['=', '!='].includes(rowOperator) && value.split(',').length > 1;
@ -16,7 +16,7 @@ export const stringifyRowData = (rowData: RowGrouping[], operator?: Operator) =>
if (isUnion) {
const values = value.split(',');
const unionRows = values
.map((v) => `Row(${field}="${v.trim()}")`)
.map((v) => keys ? `Row(${field}="${v.trim()}")` : `Row(${field}=${v.trim()})`)
.join(', ');
rowString = `Union(${unionRows})`;
} else if (rowOperator === 'cidr') {
@ -36,7 +36,7 @@ export const stringifyRowData = (rowData: RowGrouping[], operator?: Operator) =>
rowString = `UnionRows(Rows(field=${field}, like="%${value}%"))`;
}
} else {
rowString = ['set', 'timestamp'].includes(type)
rowString = keys || type === 'timestamp'
? `Row(${field}${operator}"${value}")`
: `Row(${field}${operator}${value})`;
}