Skip to content

Commit

Permalink
temporarily remove new variable validations: #767
Browse files Browse the repository at this point in the history
  • Loading branch information
jthrilly committed Nov 22, 2022
1 parent 9e2cd39 commit 9dda8c2
Show file tree
Hide file tree
Showing 3 changed files with 140 additions and 125 deletions.
88 changes: 46 additions & 42 deletions src/components/Query/Rules/EditEgoRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { compose } from 'recompose';
import { isArray, isNil } from 'lodash';
import DetachedField from '@components/DetachedField';
import NativeSelect from '@components/Form/Fields/NativeSelect';
import { operatorsWithValue, operatorsWithRegExp, operatorsWithOptionCount } from './options';
import {
operatorsWithValue,
// operatorsWithRegExp,
operatorsWithOptionCount,
} from './options';
import EditValue from './EditValue';
import withRuleChangeHandler from './withRuleChangeHandler';
import withOptions from './withOptions';
Expand All @@ -28,7 +32,7 @@ const EditEgoRule = ({
const options = rule && rule.options;
const optionsWithDefaults = { ...defaultOptions, ...options };
const operatorNeedsValue = operatorsWithValue.has(optionsWithDefaults.operator);
const operatorNeedsRegExp = operatorsWithRegExp.has(optionsWithDefaults.operator);
// const operatorNeedsRegExp = operatorsWithRegExp.has(optionsWithDefaults.operator);
const operatorNeedsOptionCount = operatorsWithOptionCount.has(optionsWithDefaults.operator);
const countFriendlyValue = !isNil(optionsWithDefaults.value) ? optionsWithDefaults.value : '';
const optionsWithCounts = {
Expand All @@ -49,37 +53,37 @@ const EditEgoRule = ({
validation={{ required: true }}
/>
</Section>
{ optionsWithDefaults.attribute
{optionsWithDefaults.attribute
&& (
<Section
title="Operator"
>
<DetachedField
component={NativeSelect}
name="operator"
options={operatorOptions}
onChange={handleRuleChange}
value={optionsWithDefaults.operator}
validation={{ required: true }}
/>
</Section>
<Section
title="Operator"
>
<DetachedField
component={NativeSelect}
name="operator"
options={operatorOptions}
onChange={handleRuleChange}
value={optionsWithDefaults.operator}
validation={{ required: true }}
/>
</Section>
)}
{ operatorNeedsValue
{operatorNeedsValue
&& (
<Section
title="Attribute Value"
>
<EditValue
variableType={variableType}
placeholder="Enter a value..."
onChange={handleRuleChange}
value={optionsWithDefaults.value}
options={variableOptions}
validation={{ required: true }}
/>
</Section>
<Section
title="Attribute Value"
>
<EditValue
variableType={variableType}
placeholder="Enter a value..."
onChange={handleRuleChange}
value={optionsWithDefaults.value}
options={variableOptions}
validation={{ required: true }}
/>
</Section>
)}
{ operatorNeedsRegExp
{/* { operatorNeedsRegExp
&& (
<Section
title="Attribute Value"
Expand All @@ -93,20 +97,20 @@ const EditEgoRule = ({
validation={{ required: true, validRegExp: true }}
/>
</Section>
)}
{ operatorNeedsOptionCount
)} */}
{operatorNeedsOptionCount
&& (
<Section
title="Selected Option Count"
>
<EditValue
variableType="number"
placeholder="Enter a value..."
onChange={handleRuleChange}
value={optionsWithCounts.value}
validation={{ requiredAcceptsZero: true }}
/>
</Section>
<Section
title="Selected Option Count"
>
<EditValue
variableType="number"
placeholder="Enter a value..."
onChange={handleRuleChange}
value={optionsWithCounts.value}
validation={{ requiredAcceptsZero: true }}
/>
</Section>
)}
</>
);
Expand Down
150 changes: 77 additions & 73 deletions src/components/Query/Rules/EditEntityRule.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import NativeSelect from '@components/Form/Fields/NativeSelect';
import RadioGroup from '@codaco/ui/lib/components/Fields/RadioGroup';
import EditValue from './EditValue';
import Section from '../../EditorLayout/Section';
import { operatorsWithValue, operatorsWithRegExp, operatorsWithOptionCount } from './options';
import {
operatorsWithValue,
// operatorsWithRegExp,
operatorsWithOptionCount,
} from './options';
import withRuleChangeHandler from './withRuleChangeHandler';
import withOptions from './withOptions';
import {
Expand Down Expand Up @@ -38,7 +42,7 @@ const EditEntityRule = ({
);
const optionsWithDefaults = getOptionsWithDefaults(options);
const operatorNeedsValue = operatorsWithValue.has(optionsWithDefaults.operator);
const operatorNeedsRegExp = operatorsWithRegExp.has(optionsWithDefaults.operator);
// const operatorNeedsRegExp = operatorsWithRegExp.has(optionsWithDefaults.operator);
const isVariableRule = entityRuleType === entityRuleTypes.VARIABLE_RULE;
const isTypeRule = entityRuleType === entityRuleTypes.TYPE_RULE;
const operatorNeedsOptionCount = operatorsWithOptionCount.has(optionsWithDefaults.operator);
Expand Down Expand Up @@ -88,72 +92,72 @@ const EditEntityRule = ({
onChange={handleChangeEntityRuleType}
/>
</Section>
{ isTypeRule && optionsWithDefaults.type
{isTypeRule && optionsWithDefaults.type
&& (
<Section
title="Operator"
>
<DetachedField
component={RadioGroup}
name="operator"
options={operatorOptions}
onChange={handleRuleChange}
value={optionsWithDefaults.operator}
validation={{ required: true }}
/>
</Section>
<Section
title="Operator"
>
<DetachedField
component={RadioGroup}
name="operator"
options={operatorOptions}
onChange={handleRuleChange}
value={optionsWithDefaults.operator}
validation={{ required: true }}
/>
</Section>
)}
{ isVariableRule && optionsWithDefaults.type
{isVariableRule && optionsWithDefaults.type
&& (
<Section
title="Variable"
summary={(
<p>
Select a variable to query.
</p>
)}
>
<DetachedField
component={NativeSelect}
name="attribute"
options={variablesAsOptions}
onChange={handleRuleChange}
value={optionsWithDefaults.attribute}
validation={{ required: true }}
/>
</Section>
<Section
title="Variable"
summary={(
<p>
Select a variable to query.
</p>
)}
>
<DetachedField
component={NativeSelect}
name="attribute"
options={variablesAsOptions}
onChange={handleRuleChange}
value={optionsWithDefaults.attribute}
validation={{ required: true }}
/>
</Section>
)}
{ isVariableRule && optionsWithDefaults.attribute
{isVariableRule && optionsWithDefaults.attribute
&& (
<Section
title="Operator"
>
<DetachedField
component={NativeSelect}
name="operator"
options={operatorOptions}
onChange={handleRuleChange}
value={optionsWithDefaults.operator}
validation={{ required: true }}
/>
</Section>
<Section
title="Operator"
>
<DetachedField
component={NativeSelect}
name="operator"
options={operatorOptions}
onChange={handleRuleChange}
value={optionsWithDefaults.operator}
validation={{ required: true }}
/>
</Section>
)}
{ isVariableRule && operatorNeedsValue
{isVariableRule && operatorNeedsValue
&& (
<Section
title="Attribute Value"
>
<EditValue
variableType={variableType}
placeholder="Enter a value..."
onChange={handleRuleChange}
value={optionsWithDefaults.value}
options={variableOptions}
validation={{ required: true }}
/>
</Section>
<Section
title="Attribute Value"
>
<EditValue
variableType={variableType}
placeholder="Enter a value..."
onChange={handleRuleChange}
value={optionsWithDefaults.value}
options={variableOptions}
validation={{ required: true }}
/>
</Section>
)}
{ isVariableRule && operatorNeedsRegExp
{/* { isVariableRule && operatorNeedsRegExp
&& (
<Section
title="Attribute Value"
Expand All @@ -167,20 +171,20 @@ const EditEntityRule = ({
validation={{ required: true, validRegExp: true }}
/>
</Section>
)}
{ isVariableRule && operatorNeedsOptionCount
)} */}
{isVariableRule && operatorNeedsOptionCount
&& (
<Section
title="Selected Option Count"
>
<EditValue
variableType="number"
placeholder="Enter a value..."
onChange={handleRuleChange}
value={optionsWithCounts.value}
validation={{ requiredAcceptsZero: true }}
/>
</Section>
<Section
title="Selected Option Count"
>
<EditValue
variableType="number"
placeholder="Enter a value..."
onChange={handleRuleChange}
value={optionsWithCounts.value}
validation={{ requiredAcceptsZero: true }}
/>
</Section>
)}
</>
);
Expand Down
27 changes: 17 additions & 10 deletions src/components/Query/Rules/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@ const disallowedVariableTypes = ['scalar', 'layout'];

export const validTypes = new Set(Object.keys(omit(VARIABLE_TYPES, disallowedVariableTypes)));

// Todo: commented out options below to be reinstated when we switch to schema 8

// List of operators
export const operators = {
EXACTLY: 'EXACTLY',
EXISTS: 'EXISTS',
INCLUDES: 'INCLUDES',
EXCLUDES: 'EXCLUDES',
CONTAINS: 'CONTAINS',
DOES_NOT_CONTAIN: 'DOES_NOT_CONTAIN',
// CONTAINS: 'CONTAINS',
// DOES_NOT_CONTAIN: 'DOES_NOT_CONTAIN',
NOT_EXISTS: 'NOT_EXISTS',
NOT: 'NOT',
GREATER_THAN: 'GREATER_THAN',
Expand All @@ -37,8 +39,8 @@ export const operatorsAsOptions = [
[operators.GREATER_THAN_OR_EQUAL, 'is greater than or exactly'],
[operators.LESS_THAN, 'is less than'],
[operators.LESS_THAN_OR_EQUAL, 'is less than or exactly'],
[operators.CONTAINS, 'contains'],
[operators.DOES_NOT_CONTAIN, 'does not contain'],
// [operators.CONTAINS, 'contains'],
// [operators.DOES_NOT_CONTAIN, 'does not contain'],
[operators.INCLUDES, 'includes'],
[operators.EXCLUDES, 'excludes'],
[operators.OPTIONS_GREATER_THAN, 'number of selected options is greater than'],
Expand All @@ -59,10 +61,10 @@ export const operatorsWithValue = new Set([
operators.EXCLUDES,
]);

export const operatorsWithRegExp = new Set([
operators.CONTAINS,
operators.DOES_NOT_CONTAIN,
]);
// export const operatorsWithRegExp = new Set([
// operators.CONTAINS,
// operators.DOES_NOT_CONTAIN,
// ]);

// Operators that also require a count of options
export const operatorsWithOptionCount = new Set([
Expand All @@ -73,12 +75,17 @@ export const operatorsWithOptionCount = new Set([
]);

export const operatorsByType = {
text: new Set(['EXACTLY', 'NOT', 'CONTAINS', 'DOES_NOT_CONTAIN']),
text: new Set([
'EXACTLY',
'NOT',
// 'CONTAINS',
// 'DOES_NOT_CONTAIN',
]),
number: new Set(['EXACTLY', 'NOT', 'GREATER_THAN', 'GREATER_THAN_OR_EQUAL', 'LESS_THAN', 'LESS_THAN_OR_EQUAL']),
boolean: new Set(['EXACTLY', 'NOT']),
ordinal: new Set(['EXACTLY', 'NOT', 'INCLUDES', 'EXCLUDES']),
categorical: new Set(['EXACTLY', 'NOT', 'INCLUDES', 'EXCLUDES', 'OPTIONS_GREATER_THAN', 'OPTIONS_LESS_THAN', 'OPTIONS_EQUALS', 'OPTIONS_NOT_EQUALS']),
exists: new Set(['EXISTS', 'NOT_EXISTS']), // TODO: Better words for these?
exists: new Set(['EXISTS', 'NOT_EXISTS']),
};

export const templates = {
Expand Down

0 comments on commit 9dda8c2

Please sign in to comment.