Skip to content

Commit

Permalink
MAT-7797 hook up components for function edit
Browse files Browse the repository at this point in the history
  • Loading branch information
sb-cecilialiu committed Dec 19, 2024
1 parent b1c85c4 commit c3e6b16
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 65 deletions.
1 change: 1 addition & 0 deletions src/AceEditor/madie-ace-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface EditorPropsType {
handleDeleteLibrary?: (lib: SelectedLibrary) => void;
handleApplyFunction?: (funct: Funct) => void;
handleFunctionDelete?: (funct: any) => void;
handleFunctionEdit?: (funct: any, newFunct: string) => void;
parseDebounceTime?: number;
inboundAnnotations?: Ace.Annotation[];
inboundErrorMarkers?: Ace.MarkerLike[];
Expand Down
2 changes: 2 additions & 0 deletions src/CqlBuilderPanel/CqlBuilderPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default function CqlBuilderPanel({
handleDefinitionDelete,
handleApplyFunction,
handleFunctionDelete,
handleFunctionEdit,
resetCql,
getCqlDefinitionReturnTypes,
makeExpanded,
Expand Down Expand Up @@ -246,6 +247,7 @@ export default function CqlBuilderPanel({
canEdit={canEdit}
handleApplyFunction={handleApplyFunction}
handleFunctionDelete={handleFunctionDelete}
handleFunctionEdit={handleFunctionEdit}
loading={loading}
cql={measureStoreCql}
isCQLUnchanged={isCQLUnchanged}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default function ExpressionEditor(props: ExpressionsProps) {
type === "Definitions" ||
type === "Functions"
) {
if (cqlBuilderLookupsTypes[type?.toLowerCase()]) {
if (cqlBuilderLookupsTypes?.[type?.toLowerCase()]) {
setNamesOptions(
cqlBuilderLookupsTypes[type?.toLowerCase()].map((def) =>
getDefinitionNameWithAlias(def, type?.toLowerCase())
Expand Down
8 changes: 3 additions & 5 deletions src/CqlBuilderPanel/functionsSection/EditFunctionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ const EditFunctionDialog = ({

const updatedFunction = {
...funct,
fluentFunction: funct?.isFluent === true ? true : false,
functionsArguments: parseArgumentsFromLogicString(
funct?.logic ? funct?.logic : ""
),
expressionEditorValue: funct?.logic,
fluentFunction: funct?.isFluent === "Yes" ? true : false,
functionsArguments: funct?.arguments,
expressionEditorValue: funct?.expressionEditorValue,
};

return (
Expand Down
36 changes: 30 additions & 6 deletions src/CqlBuilderPanel/functionsSection/FunctionsSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,19 @@ import "./Functions.scss";
import FunctionSectionNavTabs from "./FunctionSectionNavTabs";
import Functions from "./functions/Functions";
import FunctionBuilder from "./functionBuilder/FunctionBuilder";
import { CqlBuilderLookup, FunctionLookup } from "../../model/CqlBuilderLookup";
import {
CqlBuilderLookup,
FunctionLookup,
FunctionArgument,
} from "../../model/CqlBuilderLookup";
import * as _ from "lodash";
import { CqlAntlr } from "@madie/cql-antlr-parser/dist/src";

export interface FunctionProps {
canEdit: boolean;
handleApplyFunction?: Function;
handleFunctionDelete?: Function;
handleFunctionEdit?: Function;
loading: boolean;
cqlBuilderLookupsTypes?: CqlBuilderLookup;
cql: string;
Expand All @@ -19,9 +24,24 @@ export interface FunctionProps {
resetCql: Function;
}

const getArgumentNames = (logic: string) => {
const getArgumentNames = (logic: string): FunctionArgument[] => {
const args = logic.substring(logic.indexOf("(") + 1, logic.indexOf(")"));
return args.split(",");
const argstr = args.split(",");
return argstr.map((arg) => {
if (arg[0] === " ") {
arg = arg.substring(1);
}
const splitted = arg.split(" ");
return { argumentName: splitted[0], dataType: splitted[1] };
});
};

const getExpressionEditorValue = (logic: string): string => {
const expressionEditorValue = logic.substring(
logic.indexOf(":") + 1,
logic.length
);
return expressionEditorValue ? expressionEditorValue.trim() : "";
};

export default function FunctionsSection({
Expand All @@ -32,6 +52,7 @@ export default function FunctionsSection({
cqlBuilderLookupsTypes,
resetCql,
handleFunctionDelete,
handleFunctionEdit,
loading,
}: FunctionProps) {
const [activeTab, setActiveTab] = useState<string>("function");
Expand All @@ -52,7 +73,8 @@ export default function FunctionsSection({
...func,
comment: expression?.comment,
isFluent: "-",
argumentNames: getArgumentNames(func.logic),
arguments: getArgumentNames(func.logic),
expressionEditorValue: getExpressionEditorValue(func.logic),
} as FunctionLookup;
}) || [];

Expand All @@ -67,8 +89,9 @@ export default function FunctionsSection({
...func,
comment: expression?.comment,
isFluent: "Yes",
argumentNames: getArgumentNames(func.logic),
};
arguments: getArgumentNames(func.logic),
expressionEditorValue: getExpressionEditorValue(func.logic),
} as FunctionLookup;
}) || []
);
functionLookups = _.sortBy(functionLookups, (o) => o.name?.toLowerCase());
Expand Down Expand Up @@ -99,6 +122,7 @@ export default function FunctionsSection({
resetCql={resetCql}
handleApplyFunction={handleApplyFunction}
handleFunctionDelete={handleFunctionDelete}
handleFunctionEdit={handleFunctionEdit}
/>
)}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -584,20 +584,13 @@ describe("CQL Function Builder Tests", () => {
fireEvent.click(submitButton);

await waitFor(() => {
expect(handleApplyFn).toHaveBeenCalledWith(
expect.objectContaining({
comment: "comment",
expressionValue: "after",
fluentFunction: true,
functionName: "IP",
functionsArguments: [
expect.objectContaining({
argumentName: "Test",
dataType: "test",
}),
],
})
);
expect(handleApplyFn).toHaveBeenCalledWith({
comment: "comment",
expressionValue: "after",
fluentFunction: true,
functionName: "IP",
functionsArguments: [{ argumentName: "Test", dataType: "test" }],
});
});
});
it("should call handleApplyFunction with a function that we've created through the UI", async () => {
Expand Down Expand Up @@ -710,20 +703,13 @@ describe("CQL Function Builder Tests", () => {
fireEvent.click(submitButton);

await waitFor(() => {
expect(handleApplyFn).toHaveBeenCalledWith(
expect.objectContaining({
comment: "comment",
expressionValue: "after",
fluentFunction: true,
functionName: "IP",
functionsArguments: [
expect.objectContaining({
argumentName: "Test",
dataType: "Boolean",
}),
],
})
);
expect(handleApplyFn).toHaveBeenCalledWith({
comment: "comment",
expressionValue: "after",
fluentFunction: true,
functionName: "IP",
functionsArguments: [{ argumentName: "Test", dataType: "Boolean" }],
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default function FunctionBuilder({
initialValues: {
functionName: funct?.name || "",
comment: funct?.comment || "",
fluentFunction: funct?.fluentFunction || true,
fluentFunction: funct?.name ? funct?.fluentFunction : true,
functionsArguments: funct?.functionsArguments || [],
expressionEditorValue: funct?.expressionEditorValue || "",
type: "",
Expand Down Expand Up @@ -244,7 +244,15 @@ export default function FunctionBuilder({
disabled={!formik.values.functionName || !canEdit || !formik.dirty}
onClick={
operation === "edit"
? handleFunctionEdit
? () => {
const functionToApply = {
functionName: formik.values.functionName,
comment: formik.values.comment,
functionsArguments: formik.values.functionsArguments,
fluentFunction: formik.values.fluentFunction,
expressionValue: formik.values.expressionEditorValue,
};
}
: () => {
const functionToApply = {
functionName: formik.values.functionName,
Expand Down
47 changes: 29 additions & 18 deletions src/CqlBuilderPanel/functionsSection/functions/Functions.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,29 @@ import Functions from "./Functions";
import {
FunctionLookup,
CqlBuilderLookup,
FunctionArgument,
} from "../../../model/CqlBuilderLookup";

const arg: FunctionArgument = {
argumentName: "Enc",
dataType: "Encounter",
} as unknown as FunctionArgument;
const arg1: FunctionArgument = {
argumentName: "Enc1",
dataType: "Encounter",
} as unknown as FunctionArgument;
const arg2: FunctionArgument = {
argumentName: "Enc2",
dataType: "Encounter",
} as unknown as FunctionArgument;
const arg3: FunctionArgument = {
argumentName: "Enc3",
dataType: "Encounter",
} as unknown as FunctionArgument;
const arg4: FunctionArgument = {
argumentName: "Enc4",
dataType: "Encounter",
} as unknown as FunctionArgument;
const saveFunctions = [
{
name: "isFinishedEncounter",
Expand All @@ -16,12 +37,7 @@ const saveFunctions = [
"define fluent function \"isFinishedEncounter\"(Enc Encounter):\n(Enc E where E.status = 'finished') is not null",
comment: "",
isFluent: "Yes",
argumentNames: [
"Enc1 Encounter",
"Enc2 Encounter",
"Enc3 Encounter",
"Enc4 Encounter",
],
arguments: [arg1, arg2, arg3, arg4],
},
] as unknown as FunctionLookup[];

Expand All @@ -38,12 +54,7 @@ const cqlBuilderLookupsTypes = {
"define fluent function \"isFinishedEncounter\"(Enc Encounter):\n(Enc E where E.status = 'finished') is not null",
comment: "",
isFluent: "Yes",
argumentNames: [
"Enc1 Encounter",
"Enc2 Encounter",
"Enc3 Encounter",
"Enc4 Encounter",
],
arguments: [arg1, arg2, arg3, arg4],
},
],
} as unknown as CqlBuilderLookup;
Expand All @@ -57,7 +68,7 @@ const testFunctions = [
"define fluent function \"isFinishedEncounter\"(Enc Encounter):\n(Enc E where E.status = 'finished') is not null",
isFluent: "Yes",
comment: "test comment",
argumentNames: ["Enc Encounter"],
arguments: [arg],
},
{
name: "Test Function 2",
Expand All @@ -67,7 +78,7 @@ const testFunctions = [
"define fluent function \"isFinishedEncounter\"(Enc Encounter):\n(Enc E where E.status = 'finished') is not null",
isFluent: "Yes",
comment: "test comment test comment test comment test comment",
argumentNames: ["Enc Encounter"],
arguments: [arg],
},
{
name: "Test Function 3",
Expand All @@ -76,7 +87,7 @@ const testFunctions = [
logic:
"define fluent function \"isFinishedEncounter\"(Enc Encounter):\n(Enc E where E.status = 'finished') is not null",
isFluent: "Yes",
argumentNames: ["Enc Encounter"],
arguments: [arg],
},
{
name: "Test Function 4",
Expand All @@ -85,7 +96,7 @@ const testFunctions = [
logic:
"define fluent function \"isFinishedEncounter\"(Enc Encounter):\n(Enc E where E.status = 'finished') is not null",
isFluent: "Yes",
argumentNames: ["Enc Encounter"],
arguments: [arg],
},
{
name: "Test Function 5",
Expand All @@ -94,7 +105,7 @@ const testFunctions = [
logic:
"define fluent function \"isFinishedEncounter\"(Enc Encounter):\n(Enc E where E.status = 'finished') is not null",
isFluent: "Yes",
argumentNames: ["Enc Encounter"],
arguments: [arg],
},
{
name: "Test Function 6",
Expand All @@ -103,7 +114,7 @@ const testFunctions = [
logic:
"define fluent function \"isFinishedEncounter\"(Enc Encounter):\n(Enc E where E.status = 'finished') is not null",
isFluent: "Yes",
argumentNames: ["Enc Encounter"],
arguments: [arg],
},
] as unknown as FunctionLookup[];

Expand Down
14 changes: 9 additions & 5 deletions src/CqlBuilderPanel/functionsSection/functions/Functions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const Functions = ({
resetCql,
handleApplyFunction,
handleFunctionDelete,
handleFunctionEdit,
cqlBuilderLookupsTypes,
}: FunctionProps) => {
// pagination utilities
Expand Down Expand Up @@ -83,7 +84,7 @@ const Functions = ({
managePagination();
}, [functions, currentPage, currentLimit]);

const handleFunctionEdit = () => {};
//const handleFunctionEdit = () => {};
// table data
const data = visibleFunctions;

Expand All @@ -99,16 +100,19 @@ const Functions = ({
},
{
header: "Argument Name",
accessorKey: "argumentNames",
accessorKey: "arguments",
cell: (row: any) => {
const args = row.cell.row.original.argumentNames;
const args = row.cell.row.original.arguments;
const argStrArr = args.map((arg) => {
return arg.argumentName + " " + arg.dataType;
});
return (
<div>
<Tooltip
title={getArgNameToolTipHtml(args, args?.length)}
title={getArgNameToolTipHtml(argStrArr, argStrArr?.length)}
aria-label={args}
>
<button>{getArgNameToolTipHtml(args, 2)}</button>
<button>{getArgNameToolTipHtml(argStrArr, 2)}</button>
</Tooltip>
</div>
);
Expand Down
2 changes: 2 additions & 0 deletions src/cqlEditorWithTerminology/CqlEditorWithTerminology.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const CqlEditorWithTerminology = ({
handleDefinitionEdit,
handleApplyFunction,
handleFunctionDelete,
handleFunctionEdit,
height,
parseDebounceTime = 1500,
inboundAnnotations,
Expand Down Expand Up @@ -125,6 +126,7 @@ const CqlEditorWithTerminology = ({
handleDeleteLibrary={handleDeleteLibrary}
handleApplyFunction={handleApplyFunction}
handleFunctionDelete={handleFunctionDelete}
handleFunctionEdit={handleFunctionEdit}
resetCql={resetCql}
getCqlDefinitionReturnTypes={getCqlDefinitionReturnTypes}
/>
Expand Down
1 change: 1 addition & 0 deletions src/model/CqlBuilderLookup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface Lookup {
export interface FunctionLookup extends Lookup {
isFluent?: string;
arguments?: FunctionArgument[];
expressionEditorValue?: string;
}

export interface FunctionArgument {
Expand Down

0 comments on commit c3e6b16

Please sign in to comment.