diff --git a/src/components/Table/ContextMenu/index.tsx b/src/components/Table/ContextMenu/index.tsx index bce4b02cd..010dcee5f 100644 --- a/src/components/Table/ContextMenu/index.tsx +++ b/src/components/Table/ContextMenu/index.tsx @@ -1,4 +1,7 @@ import _find from "lodash/find"; + +import { PopoverProps } from "@mui/material"; +import { FieldType } from "@src/constants/fields"; import { getFieldProp } from "@src/components/fields"; import { useProjectContext } from "@src/contexts/ProjectContext"; import { MenuContents } from "./MenuContent"; @@ -9,11 +12,27 @@ export default function ContextMenu() { const { anchorEle, selectedCell, resetContextMenu } = useContextMenuAtom(); const columns = tableState?.columns; const selectedColIndex = selectedCell?.colIndex; + const selectedCol = _find(tableState?.columns, { index: selectedColIndex }); + + function getColType(col) { + if (!col) return null; + return col.type === FieldType.derivative + ? selectedCol.config.renderFieldType + : selectedCol.type; + } + + const columnType = getColType(selectedCol); + const getActions = + getFieldProp("contextMenuActions", columnType) || function empty() {}; + const actions = getActions() || []; + const hasNoActions = Boolean(actions.length === 0); + const selectedCol = _find(columns, { index: selectedColIndex }); const configActions = getFieldProp("contextMenuActions", selectedCol?.type) || function empty() {}; const actions = configActions(selectedCell, resetContextMenu) || []; + if (!anchorEle || actions.length === 0) return <>; return ( diff --git a/src/components/fields/Status/ConditionList.tsx b/src/components/fields/Status/ConditionList.tsx index 72a627275..0d989e340 100644 --- a/src/components/fields/Status/ConditionList.tsx +++ b/src/components/fields/Status/ConditionList.tsx @@ -14,9 +14,7 @@ interface I_ConditionList { export default function ConditionList({ config, setModal }: I_ConditionList) { const conditions = config?.conditions ?? []; - const noConditions = Boolean(conditions?.length < 1); // Double check this - - if (noConditions) { + if (conditions?.length === 0) { return ( <> No conditions set yet @@ -50,13 +48,12 @@ export default function ConditionList({ config, setModal }: I_ConditionList) { } const GridItem = ({ condition, setModal, index }: any) => { - const noCondition = Boolean(!condition); - if (noCondition) return <>; + if (!condition) return <>; return ( <> - {condition?.label} + {condition?.label} - {createValueLabel(condition)} + {createValueLabel(condition)} setModal({ isOpen: true, condition, index })} > diff --git a/src/components/fields/Status/ConditionModal.tsx b/src/components/fields/Status/ConditionModal.tsx index 9efc4a763..1e4b88de6 100644 --- a/src/components/fields/Status/ConditionModal.tsx +++ b/src/components/fields/Status/ConditionModal.tsx @@ -4,7 +4,6 @@ import Modal from "@src/components/Modal"; import DeleteIcon from "@mui/icons-material/Delete"; import { default as Content } from "./ConditionModalContent"; import { EMPTY_STATE } from "./Settings"; -import { isElement, isEmpty } from "lodash"; export default function ConditionModal({ modal, @@ -90,7 +89,6 @@ export default function ConditionModal({ useEffect(() => { handleUpdate("operator")(modal.condition.operator ?? "=="); }, [modal.condition.type]); - return ( =" }, - { label: "More than", value: ">" }, -]; - export default function ConditionModalContent({ + isEditing, condition, conditions, handleUpdate, }: any) { const { label, operator, type, value } = condition; - const duplicateCond = Boolean(_find(conditions, condition)); - const labelReqLen = Boolean(condition.label.length < 4); + 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 ( <> DATA TYPE (input) handleUpdate("type")(v)} value={type} multiple={false} @@ -52,7 +45,13 @@ export default function ConditionModalContent({ {/** To add defaultValue into MultiSelect?*/} {type === "boolean" && ( handleUpdate("value")(v === "true")} value={value ? "true" : "false"} multiple={false} @@ -63,7 +62,13 @@ export default function ConditionModalContent({
=" }, + { label: "More than", value: ">" }, + ]} onChange={(v) => handleUpdate("operator")(v)} value={operator} multiple={false} @@ -71,25 +76,23 @@ export default function ConditionModalContent({ />
handleUpdate("value")(Number(e.target.value))} - helperText={ - duplicateCond ? "Numeric Conditional already exists" : "" - } + helperText={errorTextType(isEditing, "Number value already exists")} />
)} {type === "string" && ( handleUpdate("value")(e.target.value)} - helperText={duplicateCond ? "string value already exists" : ""} + helperText={errorTextType(isEditing, "String value already exists")} /> )}