Skip to content

Commit

Permalink
Merge pull request #309 from jembi/CU-86bzx35gd_Deterministic-Add-Nul…
Browse files Browse the repository at this point in the history
…l-Comparator

added null operator to deterministic rule
  • Loading branch information
MatthewErispe authored Sep 2, 2024
2 parents 1c56bef + 49135cb commit 8e7ed92
Showing 1 changed file with 48 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ export const options = [
{ value: 0, label: 'Exact' },
{ value: 1, label: 'Low Fuzziness' },
{ value: 2, label: 'Medium Fuzziness' },
{ value: 3, label: 'High Fuzziness' }
{ value: 3, label: 'High Fuzziness' },
{ value: 4, label: 'Null' }
]

export enum Operator {
Expand Down Expand Up @@ -125,20 +126,29 @@ const DeterministicContent = ({
if (row.rowIndex !== undefined) {
setEditedRowIndex(row.rowIndex)
}

const regex = /(eq|match)\(([^),]+)(?:, (\d+))?\)/g
const regex = /(eq|match|null)\(([^),]+)(?:, (\d+))?\)/g
const matchedFields: string[] = []
const matchedComparators: number[] = []
let match

while ((match = regex.exec(row.ruleText)) !== null) {
matchedFields.push(match[2])
matchedComparators.push(match[1] === 'eq' ? 0 : parseInt(match[3], 10))

if (match[1] === 'eq') {
matchedComparators.push(0)
} else if (match[1] === 'match') {
matchedComparators.push(parseInt(match[3], 10))
} else if (match[1] === 'null') {
matchedComparators.push(4)
}
}

setComparators(matchedComparators)
setFields(matchedFields)
setOperators(new Array(matchedFields.length - 1).fill(Operator.AND))

const operatorsLength = Math.max(matchedFields.length - 1, 0)
setOperators(new Array(operatorsLength).fill(Operator.AND))

setViewType(1)
}

Expand All @@ -163,12 +173,20 @@ const DeterministicContent = ({
const operator =
index > 0 ? ` ${operators[index - 1].toLowerCase()} ` : ''
const comparator = comparators[index]
const comparatorFunction =
comparator === 0 ? `eq(${field})` : `match(${field},${comparator})`
let comparatorFunction

if (comparator === 4) {
comparatorFunction = `null(${field})`
} else {
comparatorFunction =
comparator === 0 ? `eq(${field})` : `match(${field},${comparator})`
}

return `${operator}${comparatorFunction}`
})
.join('')

console.log('rule', vars, text)
const rule: Rule = { vars, text }

handleUpdateConfiguration(rule)
Expand Down Expand Up @@ -228,37 +246,40 @@ const DeterministicContent = ({

const handleDeleteRow = (index: number) => {
const updateArray = (arr: any[], idx: number) => {
const newArr = [...arr];
newArr.splice(idx, 1);
return newArr;
};
setComparators(updateArray(comparators, index));
setFields(updateArray(fields, index));
const newArr = [...arr]
newArr.splice(idx, 1)
return newArr
}

setComparators(updateArray(comparators, index))
setFields(updateArray(fields, index))
if (index > 0) {
setOperators(updateArray(operators, index - 1));
setOperators(updateArray(operators, index - 1))
}
const updatedConfiguration = { ...configuration };

const updatedConfiguration = { ...configuration }
const ruleType =
currentTab === 'link'
? 'link'
: currentTab === 'validate'
? 'validate'
: 'matchNotification';
: 'matchNotification'

if (fields.length === 0) {
const newRules = updateArray(rules, index);
setRules(newRules);
const newRules = updateArray(rules, index)
setRules(newRules)

if (updatedConfiguration.rules?.[ruleType]) {
updatedConfiguration.rules[ruleType].deterministic.splice(index, 1);
updatedConfiguration.rules[ruleType].deterministic.splice(index, 1)
}

setConfiguration(updatedConfiguration as Configuration);
localStorage.setItem('configuration', JSON.stringify(updatedConfiguration));

setConfiguration(updatedConfiguration as Configuration)
localStorage.setItem(
'configuration',
JSON.stringify(updatedConfiguration)
)
}
};
}
return (
<Box>
<Box
Expand Down

0 comments on commit 8e7ed92

Please sign in to comment.