From 8af2ff85f88e9e2283420df8fcdac2841c25e1ac Mon Sep 17 00:00:00 2001 From: Kirk Swenson Date: Fri, 13 Sep 2024 18:03:20 -0700 Subject: [PATCH 1/4] feat: infrastructure for filter formula --- .../edit-filter-formula-modal.tsx | 89 +++++++++++++++++++ .../case-tile-common/hide-show-menu-list.tsx | 23 ++++- v3/src/models/data/data-set.ts | 25 +++++- v3/src/utilities/translation/lang/en-US.json5 | 4 + 4 files changed, 138 insertions(+), 3 deletions(-) create mode 100644 v3/src/components/case-tile-common/edit-filter-formula-modal.tsx diff --git a/v3/src/components/case-tile-common/edit-filter-formula-modal.tsx b/v3/src/components/case-tile-common/edit-filter-formula-modal.tsx new file mode 100644 index 0000000000..7f9ba48e6d --- /dev/null +++ b/v3/src/components/case-tile-common/edit-filter-formula-modal.tsx @@ -0,0 +1,89 @@ +import { + Button, FormControl, FormLabel, ModalBody, ModalCloseButton, ModalFooter, ModalHeader, + Textarea, Tooltip +} from "@chakra-ui/react" +import React, { useEffect, useState } from "react" +import { observer } from "mobx-react-lite" +import { useDataSetContext } from "../../hooks/use-data-set-context" +import { t } from "../../utilities/translation/translate" +import { CodapModal } from "../codap-modal" + +interface IProps { + isOpen: boolean + onClose: () => void +} + +export const EditFilterFormulaModal = observer(function EditFormulaModal({ isOpen, onClose }: IProps) { + const data = useDataSetContext() + const [formula, setFormula] = useState("") + + useEffect(() => { + setFormula(data?.filterFormula?.display || "") + }, [data?.filterFormula?.display]) + + const closeModal = () => { + onClose() + } + + function applyFilterFormula() { + data?.applyModelChange(() => { + data.setFilterFormula(formula) + }, { + undoStringKey: "V3.Undo.hideShowMenu.changeFilterFormula", + redoStringKey: "V3.Redo.hideShowMenu.changeFilterFormula" + }) + closeModal() + } + + const handleFormulaChange = (e: React.ChangeEvent) => setFormula(e.target.value) + + const buttons = [{ + label: t("DG.AttrFormView.cancelBtnTitle"), + tooltip: t("DG.AttrFormView.cancelBtnTooltip"), + onClick: closeModal + }, { + label: t("DG.AttrFormView.applyBtnTitle"), + onClick: applyFilterFormula, + default: true + }] + + return ( + + +
+
+ + + + + {t("DG.AttrFormView.formulaPrompt")} +