Skip to content

Commit 554fcdf

Browse files
authored
Merge pull request #351 from MeasureAuthoringTool/MAT-7407
MAT-7407 CQL - Definitions - Return Type field on Edit popup screen
2 parents 239aa32 + f6abaf4 commit 554fcdf

11 files changed

Lines changed: 90 additions & 48 deletions

File tree

package-lock.json

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AceEditor/madie-ace-editor.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export interface EditorPropsType {
5353
setIsCQLUnchanged?: Function;
5454
isCQLUnchanged?: boolean;
5555
resetCql?: () => void;
56+
getCqlDefinitionReturnTypes?: () => void;
5657
// conditional props used to pass up annotations outside of the editor
5758
setOutboundAnnotations?: Function;
5859
}

src/CqlBuilderPanel/CqlBuilderPanel.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ const props = {
118118
handleDefinitionDelete: jest.fn(),
119119
handleApplyLibrary: jest.fn(),
120120
handleDeleteLibrary: jest.fn(),
121+
handleEditLibrary: jest.fn(),
122+
handleDefinitionEdit: jest.fn(),
123+
resetCql: jest.fn(),
124+
getCqlDefinitionReturnTypes: jest.fn(),
125+
makeExpanded: jest.fn(),
121126
};
122127
const { getByTestId } = screen;
123128

src/CqlBuilderPanel/CqlBuilderPanel.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export default function CqlBuilderPanel({
3131
handleDefinitionEdit,
3232
handleDefinitionDelete,
3333
resetCql,
34+
getCqlDefinitionReturnTypes,
3435
makeExpanded,
3536
}) {
3637
const featureFlags = useFeatureFlags();
@@ -209,11 +210,11 @@ export default function CqlBuilderPanel({
209210
handleApplyDefinition={handleApplyDefinition}
210211
handleDefinitionDelete={handleDefinitionDelete}
211212
cqlBuilderLookupsTypes={cqlBuilderLookupsTypes}
212-
setIsCQLUnchanged={setIsCQLUnchanged}
213213
isCQLUnchanged={isCQLUnchanged}
214214
cql={measureStoreCql}
215215
setEditorVal={setEditorVal}
216216
resetCql={resetCql}
217+
getCqlDefinitionReturnTypes={getCqlDefinitionReturnTypes}
217218
handleDefinitionEdit={handleDefinitionEdit}
218219
/>
219220
)}

src/CqlBuilderPanel/definitionsSection/DefinitionsSection.test.tsx

Lines changed: 45 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,22 @@ import userEvent from "@testing-library/user-event";
55
import { CqlBuilderLookup } from "../../model/CqlBuilderLookup";
66
import { cqlBuilderLookup } from "../__mocks__/MockCqlBuilderLookupsTypes";
77

8+
const props = {
9+
canEdit: true,
10+
handleApplyDefinition: jest.fn(),
11+
handleDefinitionEdit: jest.fn(),
12+
handleDefinitionDelete: jest.fn(),
13+
cqlBuilderLookupsTypes: {} as CqlBuilderLookup,
14+
isCQLUnchanged: true,
15+
cql: "",
16+
setEditorVal: jest.fn(),
17+
resetCql: jest.fn(),
18+
getCqlDefinitionReturnTypes: jest.fn(),
19+
};
20+
821
describe("DefinitionsSection", () => {
922
it("Should display definition section", async () => {
10-
render(
11-
<DefinitionsSection
12-
canEdit={true}
13-
handleApplyDefinition={jest.fn()}
14-
cqlBuilderLookupsTypes={{} as CqlBuilderLookup}
15-
handleDefinitionDelete={jest.fn()}
16-
isCQLUnchanged
17-
setIsCQLUnchanged
18-
/>
19-
);
23+
render(<DefinitionsSection {...props} />);
2024
const definition = await screen.findByTestId("definition-tab");
2125
const savedDefinitions = await screen.findByText("Saved Definitions (0)");
2226
expect(definition).toBeInTheDocument();
@@ -30,16 +34,7 @@ describe("DefinitionsSection", () => {
3034
});
3135

3236
it("Should display saved definition section", async () => {
33-
render(
34-
<DefinitionsSection
35-
canEdit={true}
36-
handleApplyDefinition={jest.fn()}
37-
handleDefinitionDelete={jest.fn()}
38-
isCQLUnchanged
39-
setIsCQLUnchanged
40-
cqlBuilderLookupsTypes={{} as unknown as CqlBuilderLookup}
41-
/>
42-
);
37+
render(<DefinitionsSection {...props} />);
4338
const definition = await screen.findByTestId("definition-tab");
4439
const savedDefinitions = await screen.findByText("Saved Definitions (0)");
4540
expect(definition).toBeInTheDocument();
@@ -59,12 +54,8 @@ describe("DefinitionsSection", () => {
5954
it("Should allow pagination for savedDefinitions", async () => {
6055
render(
6156
<DefinitionsSection
62-
canEdit={true}
63-
handleApplyDefinition={jest.fn()}
57+
{...props}
6458
cqlBuilderLookupsTypes={cqlBuilderLookup}
65-
handleDefinitionDelete={jest.fn()}
66-
isCQLUnchanged
67-
setIsCQLUnchanged
6859
/>
6960
);
7061
const definition = await screen.findByTestId("definition-tab");
@@ -99,12 +90,8 @@ describe("DefinitionsSection", () => {
9990
it("Should allow limit changes for savedDefinitions pagination", async () => {
10091
render(
10192
<DefinitionsSection
102-
canEdit={true}
103-
handleApplyDefinition={jest.fn()}
93+
{...props}
10494
cqlBuilderLookupsTypes={cqlBuilderLookup}
105-
handleDefinitionDelete={jest.fn()}
106-
isCQLUnchanged
107-
setIsCQLUnchanged
10895
/>
10996
);
11097
const definition = await screen.findByTestId("definition-tab");
@@ -152,15 +139,36 @@ describe("DefinitionsSection", () => {
152139
});
153140
});
154141

142+
it("Should not show edit/delete actions for measure if user does not have permission", async () => {
143+
render(
144+
<DefinitionsSection
145+
{...props}
146+
cqlBuilderLookupsTypes={cqlBuilderLookup}
147+
canEdit={false}
148+
/>
149+
);
150+
// go to saved definitions tab
151+
const savedDefinitionsTab = screen.getByRole("tab", {
152+
name: /Saved Definitions/i,
153+
});
154+
expect(savedDefinitionsTab).toBeInTheDocument();
155+
userEvent.click(savedDefinitionsTab);
156+
const table = screen.getByRole("table");
157+
expect(table).toBeInTheDocument();
158+
expect(screen.queryByTestId("definition-actions")).not.toBeInTheDocument();
159+
});
160+
155161
it("Should render edit definition dialog on edit button click", async () => {
162+
const getCqlDefinitionReturnTypes = () => {
163+
return {
164+
sdeSex: "PatientCharacteristicSex",
165+
};
166+
};
156167
render(
157168
<DefinitionsSection
158-
canEdit={true}
159-
handleApplyDefinition={jest.fn()}
169+
{...props}
160170
cqlBuilderLookupsTypes={cqlBuilderLookup}
161-
handleDefinitionDelete={jest.fn()}
162-
isCQLUnchanged
163-
setIsCQLUnchanged
171+
getCqlDefinitionReturnTypes={getCqlDefinitionReturnTypes}
164172
/>
165173
);
166174
// go to saved definitions tab
@@ -182,5 +190,7 @@ describe("DefinitionsSection", () => {
182190
expect(screen.getByTestId("definition-name-text-input")).toHaveValue(
183191
"SDE Sex"
184192
);
193+
const returnType = screen.getByTestId("return-type");
194+
expect(returnType).toHaveTextContent(getCqlDefinitionReturnTypes().sdeSex);
185195
});
186196
});

src/CqlBuilderPanel/definitionsSection/DefinitionsSection.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ import DefinitionSectionNavTabs from "./DefinitionSectionNavTabs";
44
import Definitions from "./definitions/Definitions";
55
import DefinitionBuilder from "./definitionBuilder/DefinitionBuilder";
66
import { CqlBuilderLookup } from "../../model/CqlBuilderLookup";
7-
import { ResetTvTwoTone } from "@mui/icons-material";
87

98
interface DefinitionProps {
109
canEdit: boolean;
1110
handleApplyDefinition: Function;
1211
handleDefinitionEdit: Function;
1312
handleDefinitionDelete: Function;
1413
cqlBuilderLookupsTypes: CqlBuilderLookup;
15-
setIsCQLUnchanged: boolean;
1614
isCQLUnchanged: boolean;
1715
cql: string;
1816
setEditorVal: (cql: string) => void;
1917
resetCql: Function;
18+
getCqlDefinitionReturnTypes: Function;
2019
}
2120

2221
export default function DefinitionsSection({
@@ -29,6 +28,7 @@ export default function DefinitionsSection({
2928
cql,
3029
setEditorVal,
3130
resetCql,
31+
getCqlDefinitionReturnTypes,
3232
}: DefinitionProps) {
3333
const [activeTab, setActiveTab] = useState<string>("definition");
3434

@@ -54,12 +54,14 @@ export default function DefinitionsSection({
5454
)}
5555
{activeTab === "saved-definitions" && (
5656
<Definitions
57+
canEdit={canEdit}
5758
definitions={measureDefinitions}
5859
isCQLUnchanged={isCQLUnchanged}
5960
cql={cql}
6061
setEditorValue={setEditorVal}
6162
handleDefinitionDelete={handleDefinitionDelete}
6263
resetCql={resetCql}
64+
getCqlDefinitionReturnTypes={getCqlDefinitionReturnTypes}
6365
cqlBuilderLookup={cqlBuilderLookupsTypes}
6466
handleDefinitionEdit={handleDefinitionEdit}
6567
/>

src/CqlBuilderPanel/definitionsSection/definitionBuilder/DefinitionBuilder.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface Definition {
1616
definitionName?: string;
1717
comment?: string;
1818
expressionValue?: string;
19+
returnType?: string;
1920
}
2021

2122
export interface DefinitionProps {
@@ -155,10 +156,10 @@ export default function DefinitionBuilder({
155156
{...formik.getFieldProps("definitionName")}
156157
/>
157158
</div>
158-
{definition && (
159-
<div tw="w-1/2 ml-10 my-2">
159+
{definition && definition.returnType && (
160+
<div tw="w-1/2 ml-10 my-2" data-testid="return-type">
160161
<p className="result-label">Return Type</p>
161-
<span className="result-value">-</span>
162+
<span className="result-value">{definition.returnType}</span>
162163
</div>
163164
)}
164165
</div>

src/CqlBuilderPanel/definitionsSection/definitionBuilderDialog/DefinitionBuilderDialog.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const DefinitionBuilderDialog = ({
3232
const updatedDefinition = {
3333
definitionName: definition?.name,
3434
expressionValue: getExpression(definition),
35+
returnType: definition?.returnType,
3536
} as Definition;
3637

3738
return (

src/CqlBuilderPanel/definitionsSection/definitions/Definitions.tsx

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useCallback, useEffect, useMemo, useState } from "react";
2+
import _ from "lodash";
23
import {
34
ColumnDef,
45
flexRender,
@@ -17,28 +18,33 @@ import BorderColorOutlinedIcon from "@mui/icons-material/BorderColorOutlined";
1718
import ToolTippedIcon from "../../../toolTippedIcon/ToolTippedIcon";
1819
import { CqlBuilderLookup, Lookup } from "../../../model/CqlBuilderLookup";
1920
import DefinitionBuilderDialog from "../definitionBuilderDialog/DefinitionBuilderDialog";
21+
import { Stack } from "@mui/material";
2022

2123
const TH = tw.th`p-3 text-left text-sm font-bold capitalize`;
2224
const TD = tw.td`p-3 text-left text-sm break-all`;
2325

2426
type DefinitionsPropTypes = {
27+
canEdit: boolean;
2528
definitions: Lookup[];
2629
isCQLUnchanged: boolean;
2730
cql: string;
2831
setEditorValue: (cql) => void;
2932
handleDefinitionEdit?: Function;
3033
handleDefinitionDelete?: Function;
3134
resetCql: Function;
35+
getCqlDefinitionReturnTypes: Function;
3236
cqlBuilderLookup: CqlBuilderLookup;
3337
};
3438
const Definitions = ({
39+
canEdit,
3540
definitions,
3641
isCQLUnchanged,
3742
cql,
3843
setEditorValue,
3944
handleDefinitionEdit,
4045
handleDefinitionDelete,
4146
resetCql,
47+
getCqlDefinitionReturnTypes,
4248
cqlBuilderLookup,
4349
}: DefinitionsPropTypes) => {
4450
const [deleteDialogOpen, setDeleteDialogOpen] = useState<boolean>(false);
@@ -77,7 +83,11 @@ const Definitions = ({
7783

7884
const showEditDefinitionDialog = (index) => {
7985
const rowModal = table.getRow(index).original;
80-
setSelectedDefinition(rowModal);
86+
const returnTypes = getCqlDefinitionReturnTypes();
87+
const returnType = returnTypes
88+
? returnTypes[_.camelCase(rowModal.name)]
89+
: undefined;
90+
setSelectedDefinition({ ...rowModal, returnType: returnType });
8191
};
8292

8393
// table data
@@ -93,8 +103,15 @@ const Definitions = ({
93103
header: "",
94104
accessorKey: "apply",
95105
cell: (row: any) => {
106+
if (!canEdit) {
107+
return null;
108+
}
96109
return (
97-
<>
110+
<Stack
111+
direction="row"
112+
alignItems="center"
113+
data-testid="definition-actions"
114+
>
98115
<ToolTippedIcon
99116
tooltipMessage="Delete"
100117
buttonProps={{
@@ -131,7 +148,7 @@ const Definitions = ({
131148
>
132149
<BorderColorOutlinedIcon color="primary" />
133150
</ToolTippedIcon>
134-
</>
151+
</Stack>
135152
);
136153
},
137154
},

src/cqlEditorWithTerminology/CqlEditorWithTerminology.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ const CqlEditorWithTerminology = ({
3434
setIsCQLUnchanged,
3535
isCQLUnchanged,
3636
resetCql,
37+
getCqlDefinitionReturnTypes,
3738
}: EditorPropsType) => {
3839
const [expanded, setExpanded] = useState(true);
3940
const toggleSearch = () => {
@@ -113,6 +114,7 @@ const CqlEditorWithTerminology = ({
113114
handleEditLibrary={handleEditLibrary}
114115
handleDeleteLibrary={handleDeleteLibrary}
115116
resetCql={resetCql}
117+
getCqlDefinitionReturnTypes={getCqlDefinitionReturnTypes}
116118
/>
117119
</Allotment.Pane>
118120
)}

0 commit comments

Comments
 (0)