Skip to content

Commit

Permalink
Merge pull request #449 from MeasureAuthoringTool/MAT-8150
Browse files Browse the repository at this point in the history
MAT-8150 and 8151: Value Set Search - Definition Version
  • Loading branch information
ethankaplan authored Jan 31, 2025
2 parents 2cc9e5c + 033f3ca commit be6c368
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
34 changes: 31 additions & 3 deletions src/CqlBuilderPanel/ValueSets/Search/Search.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React from "react";
import ControlledAutoComplete from "../../../common/ControlledAutoComplete";
import { useFormik } from "formik";
import SearchField from "../../../common/SearchField";
Expand Down Expand Up @@ -66,6 +66,7 @@ export default function Search(props: SearchProps) {
await handleSearch(formik.values);
},
});

const trimField = (fieldName) => {
formik.setFieldValue(fieldName, formik.values[fieldName].trim());
};
Expand Down Expand Up @@ -100,6 +101,9 @@ export default function Search(props: SearchProps) {
formik.setFieldValue(value, "");
}
});
if (!saveMap["url"] && formik.values["version"]) {
formik.setFieldValue("version", "");
}
};

return (
Expand All @@ -112,13 +116,20 @@ export default function Search(props: SearchProps) {
formControl={formik.getFieldProps("searchCategories")}
onClose={undefined}
{...formik.getFieldProps("searchCategories")}
onChange={(_event: any, selectedVal: string | null, reason) => {
onChange={(
_event: any,
selectedVal: { label: string; value: string }[] | null,
reason
) => {
if (reason === "removeOption") {
formBlanker(selectedVal);
}
if (reason === "clear") {
formBlanker([]);
}
if (!selectedVal.some((obj) => obj.value === "url")) {
selectedVal = selectedVal.filter((obj) => obj.value !== "version");
}
formik.setFieldValue("searchCategories", selectedVal);
}}
id="search-by-category"
Expand All @@ -127,7 +138,10 @@ export default function Search(props: SearchProps) {
disabled={!canEdit}
options={SEARCH_CATEGORIES}
getOptionDisabled={(option) => {
if (option.value === "version") {
if (
option.value === "version" &&
!formik.values.searchCategories.some((obj) => obj.value === "url")
) {
return formik.values.url === "";
}
return false;
Expand All @@ -149,6 +163,14 @@ export default function Search(props: SearchProps) {
prefix="Search"
label={SEARCH_MAP[value]}
trimField={trimField}
placeHolder={
value === "version" && !formik.values.url
? "OID/URL must be entered first"
: ""
}
disabled={
value === "version" ? !formik.values.url : false
}
/>
<div style={{ width: "100%" }} />
</>
Expand All @@ -160,6 +182,12 @@ export default function Search(props: SearchProps) {
prefix="Search"
label={SEARCH_MAP[value]}
trimField={trimField}
placeHolder={
value === "version" && !formik.values.url
? "OID/URL must be entered first"
: ""
}
disabled={value === "version" ? !formik.values.url : false}
/>
);
})}
Expand Down
14 changes: 14 additions & 0 deletions src/CqlBuilderPanel/ValueSets/ValueSets.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,29 @@ describe("ValueSets Page", () => {
userEvent.click(getByText("Status"));
userEvent.click(categoriesSelectButton);
userEvent.click(getByText("Title"));
userEvent.click(categoriesSelectButton);
userEvent.click(getByText("OID/URL"));
userEvent.click(categoriesSelectButton);
userEvent.click(getByText("Definition Version"));
expect(getByTestId("code-text-input")).toBeInTheDocument();
expect(getByTestId("status-text-input")).toBeInTheDocument();
expect(getByTestId("title-text-input")).toBeInTheDocument();
expect(getByTestId("url-text-input")).toBeInTheDocument();
expect(getByTestId("version-text-input")).toBeInTheDocument();
const deleteCodeButton = getByRole("button", { name: "Code" });
const deleteIcon = within(deleteCodeButton).getByTestId("CancelIcon");
userEvent.click(deleteIcon);
await waitFor(() => {
expect(queryByTestId("code-text-input")).not.toBeInTheDocument();
});
const deleteURLButton = getByRole("button", { name: "OID/URL" });
const deleteURLIcon = within(deleteURLButton).getByTestId("CancelIcon");
userEvent.click(deleteURLIcon);
await waitFor(() => {
expect(queryByTestId("url-text-input")).not.toBeInTheDocument();
expect(queryByTestId("version-text-input")).not.toBeInTheDocument();
});

const clearButton = getByLabelText("Clear");
userEvent.click(clearButton);
await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,10 @@ export default function FunctionBuilder({
fluentFunction: formik.values.fluentFunction,
expressionValue: formik.values.expressionEditorValue,
};
resetForm();
handleApplyFunction(functionToApply);
const result = handleApplyFunction(functionToApply);
if (result === "success") {
resetForm();
}
}
}
>
Expand Down

0 comments on commit be6c368

Please sign in to comment.