From 35dc7ef1d5704535475cdf8d74d26122134c7945 Mon Sep 17 00:00:00 2001 From: mcmcphillips Date: Sun, 13 Oct 2024 20:40:09 -0700 Subject: [PATCH] MAT-7694: Add parameter apply button --- src/AceEditor/madie-ace-editor.tsx | 2 ++ src/CqlBuilderPanel/CqlBuilderPanel.tsx | 5 ++++- .../Parameters/ParameterPane.tsx | 20 ++++++++++++------- src/CqlBuilderPanel/Parameters/Parameters.tsx | 6 ++++-- src/api/useTerminologyServiceApi.ts | 5 +++++ .../CqlEditorWithTerminology.tsx | 2 ++ 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/src/AceEditor/madie-ace-editor.tsx b/src/AceEditor/madie-ace-editor.tsx index 2eb17a9c..a81a9078 100644 --- a/src/AceEditor/madie-ace-editor.tsx +++ b/src/AceEditor/madie-ace-editor.tsx @@ -20,6 +20,7 @@ import "./madie-custom.css"; import { ParsedCql, Statement } from "../model/ParsedCql"; import { CqlMetaData, + Parameter, ValueSetForSearch, } from "../api/useTerminologyServiceApi"; import { Definition } from "../CqlBuilderPanel/definitionsSection/definitionBuilder/DefinitionBuilder"; @@ -29,6 +30,7 @@ export interface EditorPropsType { value: string; onChange?: (value: string) => void; handleApplyCode?: (code: string) => void; + handleApplyParameter?: (parameter: Parameter) => void; handleApplyValueSet?: (vs: ValueSetForSearch) => void; handleApplyDefinition?: (def: Definition) => void; handleDefinitionEdit?: (lib: SelectedLibrary, def: Definition) => void; diff --git a/src/CqlBuilderPanel/CqlBuilderPanel.tsx b/src/CqlBuilderPanel/CqlBuilderPanel.tsx index a607881e..c4a08356 100644 --- a/src/CqlBuilderPanel/CqlBuilderPanel.tsx +++ b/src/CqlBuilderPanel/CqlBuilderPanel.tsx @@ -27,6 +27,7 @@ export default function CqlBuilderPanel({ handleDeleteLibrary, handleEditLibrary, handleApplyCode, + handleApplyParameter, handleApplyValueSet, handleApplyDefinition, handleDefinitionEdit, @@ -219,7 +220,9 @@ export default function CqlBuilderPanel({ handleApplyCode={handleApplyCode} /> )} - {activeTab === "parameters" && } + {activeTab === "parameters" && ( + + )} {activeTab === "definitions" && ( {}, + onSubmit: async (values) => { + const result = handleApplyParameter(values); + if (result === "success") { + formik.resetForm(); + } + }, }); const { resetForm } = formik; // adjusting the height of the editor based on the inserted text @@ -36,7 +41,7 @@ export default function ParameterPane() { const newHeight = Math.max(lineCount * 20, 100) + "px"; setEditorHeight(newHeight); } - }, [formik.values.expressionEditorValue]); + }, [formik.values.expression]); return ( <>
@@ -65,9 +70,9 @@ export default function ParameterPane() { mode="sql" ref={textAreaRef} theme="monokai" - value={formik.values.expressionEditorValue} + value={formik.values.expression} onChange={(value) => { - formik.setFieldValue("expressionEditorValue", value); + formik.setFieldValue("expression", value); }} onLoad={(aceEditor) => { // On load we want to tell the ace editor that it's inside of a scrollabel page @@ -95,6 +100,7 @@ export default function ParameterPane() { diff --git a/src/CqlBuilderPanel/Parameters/Parameters.tsx b/src/CqlBuilderPanel/Parameters/Parameters.tsx index 56b9c672..58c03e12 100644 --- a/src/CqlBuilderPanel/Parameters/Parameters.tsx +++ b/src/CqlBuilderPanel/Parameters/Parameters.tsx @@ -3,14 +3,16 @@ import ParametersNavTabs from "./ParamatersNavTabs"; import ParameterPane from "./ParameterPane"; import "./Parameters.scss"; -export default function Parameters() { +export default function Parameters({ handleApplyParameter }) { const [activeTab, setActiveTab] = useState("parameters"); return (
- {activeTab === "parameters" && } + {activeTab === "parameters" && ( + + )} {activeTab === "savedParameters" && (
)} diff --git a/src/api/useTerminologyServiceApi.ts b/src/api/useTerminologyServiceApi.ts index d4fcab6a..f542ad56 100644 --- a/src/api/useTerminologyServiceApi.ts +++ b/src/api/useTerminologyServiceApi.ts @@ -24,6 +24,11 @@ export type ValueSet = { errorMsg: string; }; +export type Parameter = { + parameterName?: string; + expression?: string; +}; + export interface CodeSystem { id: string; lastUpdated: string; diff --git a/src/cqlEditorWithTerminology/CqlEditorWithTerminology.tsx b/src/cqlEditorWithTerminology/CqlEditorWithTerminology.tsx index 78d517ee..73d883de 100644 --- a/src/cqlEditorWithTerminology/CqlEditorWithTerminology.tsx +++ b/src/cqlEditorWithTerminology/CqlEditorWithTerminology.tsx @@ -14,6 +14,7 @@ const CqlEditorWithTerminology = ({ handleCodeDelete, handleDefinitionDelete, handleApplyCode, + handleApplyParameter, handleApplyValueSet, handleApplyDefinition, handleApplyLibrary, @@ -106,6 +107,7 @@ const CqlEditorWithTerminology = ({ setIsCQLUnchanged={setIsCQLUnchanged} isCQLUnchanged={isCQLUnchanged} handleApplyCode={handleApplyCode} + handleApplyParameter={handleApplyParameter} handleApplyValueSet={handleApplyValueSet} handleApplyDefinition={handleApplyDefinition} handleDefinitionEdit={handleDefinitionEdit}