From cc624a9c18c8a41f1b79218d408e0fadf8a5a25f Mon Sep 17 00:00:00 2001 From: Stephanie Yang Date: Fri, 4 Jun 2021 13:43:28 -0500 Subject: [PATCH] add support for non-keyed set, time, mutex and decimals --- .../MoleculaTable/MoleculaTable.tsx | 2 +- lattice/src/App/QueryBuilder/QueryBuilder.tsx | 3 +- .../src/App/QueryBuilder/RowCall/RowCall.tsx | 54 ++++++++++--------- .../src/App/QueryBuilder/RowCall/helpers.ts | 33 +++++++++++- lattice/src/App/QueryBuilder/rowTypes.ts | 3 +- .../src/App/QueryBuilder/stringifyRowData.ts | 6 +-- 6 files changed, 70 insertions(+), 31 deletions(-) diff --git a/lattice/src/App/MoleculaTables/MoleculaTable/MoleculaTable.tsx b/lattice/src/App/MoleculaTables/MoleculaTable/MoleculaTable.tsx index cfe2d6dc8..0946b3d0e 100644 --- a/lattice/src/App/MoleculaTables/MoleculaTable/MoleculaTable.tsx +++ b/lattice/src/App/MoleculaTables/MoleculaTable/MoleculaTable.tsx @@ -203,7 +203,7 @@ export const MoleculaTable: FC = ({ .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 ( diff --git a/lattice/src/App/QueryBuilder/QueryBuilder.tsx b/lattice/src/App/QueryBuilder/QueryBuilder.tsx index ef83a787b..7f948b1ca 100644 --- a/lattice/src/App/QueryBuilder/QueryBuilder.tsx +++ b/lattice/src/App/QueryBuilder/QueryBuilder.tsx @@ -147,7 +147,8 @@ export const QueryBuilder: FC = ({ field: '', rowOperator: '=', value: '', - type: 'set' + type: 'set', + keys: true } ]; diff --git a/lattice/src/App/QueryBuilder/RowCall/RowCall.tsx b/lattice/src/App/QueryBuilder/RowCall/RowCall.tsx index 1b0279097..cd0501060 100644 --- a/lattice/src/App/QueryBuilder/RowCall/RowCall.tsx +++ b/lattice/src/App/QueryBuilder/RowCall/RowCall.tsx @@ -40,9 +40,8 @@ export const RowCall: FC = ({ onRemoveGroup }) => { const [operatorEl, setOperatorEl] = useState(null); - const [activeOperatorEl, setActiveOperatorEl] = useState( - null - ); + const [activeOperatorEl, setActiveOperatorEl] = + useState(null); const [anchorEl, setAnchorEl] = useState(null); const [activeAnchor, setActiveAnchor] = useState(); @@ -51,7 +50,8 @@ export const RowCall: FC = ({ field: '', rowOperator: '=', value: '', - type: 'set' + type: 'set', + keys: true }; if (op) { @@ -106,7 +106,10 @@ export const RowCall: FC = ({ {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 = ({ 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 = ({ - {['int', 'set'].includes(type) ? ( - - onRowUpdate(idx, { ...row, value: event.target.value }) - } - /> - ) : type === 'timestamp' ? ( + {type === 'timestamp' ? ( = ({ fullWidth /> - ) : null} + ) : ( + + onRowUpdate(idx, { ...row, value: event.target.value }) + } + /> + )} {rowData.length > 1 ? ( ', 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: '>' }, diff --git a/lattice/src/App/QueryBuilder/rowTypes.ts b/lattice/src/App/QueryBuilder/rowTypes.ts index 066da68ad..b4808cd0d 100644 --- a/lattice/src/App/QueryBuilder/rowTypes.ts +++ b/lattice/src/App/QueryBuilder/rowTypes.ts @@ -12,7 +12,8 @@ export type RowCallType = { field: string; rowOperator: string; value: string; - type: 'set' | 'int' | 'timestamp'; + type: string; + keys: boolean; }; export type RowsCallType = { diff --git a/lattice/src/App/QueryBuilder/stringifyRowData.ts b/lattice/src/App/QueryBuilder/stringifyRowData.ts index c03ea9da4..5b06c88c9 100644 --- a/lattice/src/App/QueryBuilder/stringifyRowData.ts +++ b/lattice/src/App/QueryBuilder/stringifyRowData.ts @@ -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})`; }