Skip to content

Commit

Permalink
MAT-7694: Add parameter apply button
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmcphillips committed Oct 14, 2024
1 parent a0123db commit 35dc7ef
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/AceEditor/madie-ace-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion src/CqlBuilderPanel/CqlBuilderPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export default function CqlBuilderPanel({
handleDeleteLibrary,
handleEditLibrary,
handleApplyCode,
handleApplyParameter,
handleApplyValueSet,
handleApplyDefinition,
handleDefinitionEdit,
Expand Down Expand Up @@ -219,7 +220,9 @@ export default function CqlBuilderPanel({
handleApplyCode={handleApplyCode}
/>
)}
{activeTab === "parameters" && <Parameters />}
{activeTab === "parameters" && (
<Parameters handleApplyParameter={handleApplyParameter} />
)}

{activeTab === "definitions" && (
<DefinitionsSection
Expand Down
20 changes: 13 additions & 7 deletions src/CqlBuilderPanel/Parameters/ParameterPane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,26 @@ const validationSchema = Yup.object({
"Only alphanumeric characters are allowed, no spaces."
)
.required("Parameter Name is required"),
expressionEditorValue: Yup.string(),
parameterExpression: Yup.string(),
});

export default function ParameterPane() {
export default function ParameterPane({ handleApplyParameter }) {
const textAreaRef = useRef(null);
const [editorHeight, setEditorHeight] = useState("100px");
const [showEditor, setShowEditor] = useState(false);
const formik = useFormik({
initialValues: {
parameterName: "",
expressionEditorValue: "",
expression: "",
},
validationSchema,
enableReinitialize: true,
onSubmit: (values) => {},
onSubmit: async (values) => {
const result = handleApplyParameter(values);

Check warning on line 30 in src/CqlBuilderPanel/Parameters/ParameterPane.tsx

View check run for this annotation

Codecov / codecov/patch

src/CqlBuilderPanel/Parameters/ParameterPane.tsx#L30

Added line #L30 was not covered by tests
if (result === "success") {
formik.resetForm();

Check warning on line 32 in src/CqlBuilderPanel/Parameters/ParameterPane.tsx

View check run for this annotation

Codecov / codecov/patch

src/CqlBuilderPanel/Parameters/ParameterPane.tsx#L32

Added line #L32 was not covered by tests
}
},
});
const { resetForm } = formik;
// adjusting the height of the editor based on the inserted text
Expand All @@ -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 (
<>
<div className="row">
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -95,6 +100,7 @@ export default function ParameterPane() {
<Button
data-testId="apply-parameter"
disabled={!formik.dirty || !formik.isValid}
onClick={formik.handleSubmit}
>
Apply
</Button>
Expand Down
6 changes: 4 additions & 2 deletions src/CqlBuilderPanel/Parameters/Parameters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<form id="cql-editor-parameters" data-testId="cql-editor-parameters">
<ParametersNavTabs activeTab={activeTab} setActiveTab={setActiveTab} />

{activeTab === "parameters" && <ParameterPane />}
{activeTab === "parameters" && (
<ParameterPane handleApplyParameter={handleApplyParameter} />
)}
{activeTab === "savedParameters" && (
<div data-testId="saved-parameters" />
)}
Expand Down
5 changes: 5 additions & 0 deletions src/api/useTerminologyServiceApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export type ValueSet = {
errorMsg: string;
};

export type Parameter = {
parameterName?: string;
expression?: string;
};

export interface CodeSystem {
id: string;
lastUpdated: string;
Expand Down
2 changes: 2 additions & 0 deletions src/cqlEditorWithTerminology/CqlEditorWithTerminology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const CqlEditorWithTerminology = ({
handleCodeDelete,
handleDefinitionDelete,
handleApplyCode,
handleApplyParameter,
handleApplyValueSet,
handleApplyDefinition,
handleApplyLibrary,
Expand Down Expand Up @@ -106,6 +107,7 @@ const CqlEditorWithTerminology = ({
setIsCQLUnchanged={setIsCQLUnchanged}
isCQLUnchanged={isCQLUnchanged}
handleApplyCode={handleApplyCode}
handleApplyParameter={handleApplyParameter}
handleApplyValueSet={handleApplyValueSet}
handleApplyDefinition={handleApplyDefinition}
handleDefinitionEdit={handleDefinitionEdit}
Expand Down

0 comments on commit 35dc7ef

Please sign in to comment.