mirror of
https://github.com/rowyio/rowy.git
synced 2025-12-29 00:16:39 +01:00
remove duplicate validation check
This commit is contained in:
@@ -19,14 +19,11 @@ export default function ConditionModal({
|
||||
setModal(EMPTY_STATE);
|
||||
};
|
||||
const handleAdd = () => {
|
||||
const labelIsEmpty = Boolean(modal.condition.label.length < 4);
|
||||
const labelIsEmpty = Boolean(modal.condition.label.length === 0);
|
||||
const stringValueIsEmpty = Boolean(
|
||||
modal.condition.type === "string" && modal.condition.value.length === 0
|
||||
);
|
||||
const hasDuplicate = Boolean(_find(conditions, modal.condition));
|
||||
const validation = Boolean(
|
||||
labelIsEmpty || stringValueIsEmpty || hasDuplicate
|
||||
);
|
||||
const validation = Boolean(labelIsEmpty || stringValueIsEmpty);
|
||||
if (validation) return;
|
||||
function setConditionHack(type, condition) {
|
||||
let rCondition = condition;
|
||||
@@ -100,12 +97,7 @@ export default function ConditionModal({
|
||||
secondary: secondaryAction(modal.index),
|
||||
}}
|
||||
children={
|
||||
<Content
|
||||
isEditing={modal.index}
|
||||
condition={modal.condition}
|
||||
conditions={conditions}
|
||||
handleUpdate={handleUpdate}
|
||||
/>
|
||||
<Content condition={modal.condition} handleUpdate={handleUpdate} />
|
||||
}
|
||||
/>
|
||||
);
|
||||
|
||||
@@ -4,29 +4,12 @@ import TextField from "@mui/material/TextField";
|
||||
import Typography from "@mui/material/Typography";
|
||||
import MultiSelect from "@rowy/multiselect";
|
||||
|
||||
interface I_ConditionModalContent {
|
||||
handleUpdate: () => void;
|
||||
modal: any;
|
||||
}
|
||||
|
||||
export default function ConditionModalContent({
|
||||
isEditing,
|
||||
condition,
|
||||
conditions,
|
||||
handleUpdate,
|
||||
}: any) {
|
||||
const { label, operator, type, value } = condition;
|
||||
const labelReqLen = Boolean(condition.label.length < 1);
|
||||
const onNewHasDuplicate = Boolean(_find(conditions, condition));
|
||||
const onEditConditions = conditions.filter(
|
||||
(c) => c.value !== condition.value
|
||||
); //remove the current condition from list of conditions, to prevent false positive error on duplicate value
|
||||
const onEditHasDuplicate = Boolean(_find(onEditConditions, condition));
|
||||
|
||||
const errorTextType = (isEditing: boolean, error: string) => {
|
||||
const hasError = isEditing ? onEditHasDuplicate : onNewHasDuplicate;
|
||||
return hasError ? error : "";
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -76,23 +59,19 @@ export default function ConditionModalContent({
|
||||
/>
|
||||
</div>
|
||||
<TextField
|
||||
error={isEditing ? onEditHasDuplicate : onNewHasDuplicate}
|
||||
type="number"
|
||||
label="Value"
|
||||
value={value}
|
||||
onChange={(e) => handleUpdate("value")(Number(e.target.value))}
|
||||
helperText={errorTextType(isEditing, "Number value already exists")}
|
||||
/>
|
||||
</Grid>
|
||||
)}
|
||||
{type === "string" && (
|
||||
<TextField
|
||||
error={isEditing ? onEditHasDuplicate : onNewHasDuplicate}
|
||||
fullWidth
|
||||
label="Value"
|
||||
value={value}
|
||||
onChange={(e) => handleUpdate("value")(e.target.value)}
|
||||
helperText={errorTextType(isEditing, "String value already exists")}
|
||||
/>
|
||||
)}
|
||||
<TextField
|
||||
|
||||
Reference in New Issue
Block a user