Skip to content

Commit

Permalink
MAT7698 edit parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-cecilialiu committed Nov 7, 2024
1 parent a82a26c commit c5ddee5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 29 deletions.
4 changes: 4 additions & 0 deletions src/AceEditor/madie-ace-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ export interface EditorPropsType {
onChange?: (value: string) => void;
handleApplyCode?: (code: string) => void;
handleApplyParameter?: (parameter: Parameter) => void;
handleParameterEdit?: (
parameter: Parameter,
parameterToApply: Parameter
) => void;
handleApplyValueSet?: (vs: ValueSetForSearch) => void;
handleApplyDefinition?: (def: Definition) => void;
handleDefinitionEdit?: (lib: SelectedLibrary, def: Definition) => void;
Expand Down
2 changes: 2 additions & 0 deletions src/CqlBuilderPanel/CqlBuilderPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export default function CqlBuilderPanel({
handleEditLibrary,
handleApplyCode,
handleApplyParameter,
handleParameterEdit,
handleApplyValueSet,
handleApplyDefinition,
handleDefinitionEdit,
Expand Down Expand Up @@ -211,6 +212,7 @@ export default function CqlBuilderPanel({
<Parameters
canEdit={canEdit}
handleApplyParameter={handleApplyParameter}
handleParameterEdit={handleParameterEdit}
cqlBuilderLookupsTypes={cqlBuilderLookupsTypes}
isCQLUnchanged={isCQLUnchanged}
cql={measureStoreCql}
Expand Down
4 changes: 3 additions & 1 deletion src/CqlBuilderPanel/Parameters/EditParameterDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const EditParameterDialog = ({
}: PropTypes) => {
const updatedParameter = {
parameterName: parameter?.name,
expressionValue: parameter?.logic,
expression:
parameter?.logic?.slice(0, 1).toUpperCase() +
parameter?.logic?.slice(1, parameter?.logic?.length),
} as Parameter;

return (
Expand Down
35 changes: 7 additions & 28 deletions src/CqlBuilderPanel/Parameters/ParameterBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import AceEditor from "react-ace";

export interface Parameter {
parameterName?: string;
expressionValue?: string;
expression?: string;
}

export interface ParameterProps {
Expand All @@ -27,30 +27,20 @@ export default function ParameterBuilder({
parameter,
setOpenParameterDialog,
}: ParameterProps) {
const [editorHeight, setEditorHeight] = useState("50px");
const [editorHeight, setEditorHeight] = useState("180px");
const textAreaRef = useRef(null);
const [expressionEditorValue, setExpressionEditorValue] = useState(
parameter?.expressionValue || ""
);

const formik = useFormik({
initialValues: {
parameterName: parameter?.parameterName || "",
expression: parameter?.expressionValue || "",
expression: parameter?.expression || "",
},
validationSchema: ParameterSchemaValidator,
enableReinitialize: true,
onSubmit: (values) => {},
});
const { resetForm } = formik;

const isEditDialogFormDirty = () => {
if (parameter?.expressionValue !== expressionEditorValue || formik.dirty) {
return false;
}
return true;
};

return (
<div>
<form id="parameter-form" onSubmit={formik.handleSubmit}>
Expand Down Expand Up @@ -103,12 +93,7 @@ export default function ParameterBuilder({
<Button
variant="outline"
data-testid="parameter-cancel-btn"
disabled={
(!formik.dirty &&
expressionEditorValue ===
(parameter?.expressionValue || "")) ||
!canEdit
}
disabled={!formik.dirty || !canEdit}
tw="mr-4"
onClick={() => {
resetForm();
Expand All @@ -119,21 +104,15 @@ export default function ParameterBuilder({
</Button>
<Button
data-testid={`parameter-save-btn`}
disabled={
(!formik.dirty &&
expressionEditorValue ===
(parameter?.expressionValue || "")) ||
!canEdit
}
disabled={!formik.dirty || !canEdit}
onClick={() => {
const parameterToApply: Parameter = {
parameterName: formik.values.parameterName,
expressionValue: expressionEditorValue,
expression: formik.values.expression,
};
resetForm();
setExpressionEditorValue("");
formik.setFieldValue("parameterName", "");
// call handleParameterEdit
handleParameterEdit(parameter, parameterToApply);
onClose();
}}
>
Expand Down
2 changes: 2 additions & 0 deletions src/cqlEditorWithTerminology/CqlEditorWithTerminology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const CqlEditorWithTerminology = ({
handleDefinitionDelete,
handleApplyCode,
handleApplyParameter,
handleParameterEdit,
handleApplyValueSet,
handleApplyDefinition,
handleApplyLibrary,
Expand Down Expand Up @@ -108,6 +109,7 @@ const CqlEditorWithTerminology = ({
isCQLUnchanged={isCQLUnchanged}
handleApplyCode={handleApplyCode}
handleApplyParameter={handleApplyParameter}
handleParameterEdit={handleParameterEdit}
handleApplyValueSet={handleApplyValueSet}
handleApplyDefinition={handleApplyDefinition}
handleDefinitionEdit={handleDefinitionEdit}
Expand Down

0 comments on commit c5ddee5

Please sign in to comment.