Skip to content

Commit

Permalink
Merge pull request #376 from ducku/issues/362-improve-region-dropdown…
Browse files Browse the repository at this point in the history
…-display

Improve Region Dropdown Selections
  • Loading branch information
adamnovak authored Dec 11, 2023
2 parents 050b962 + c6d76e0 commit bc8040f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/components/HeaderForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const CLEAR_STATE = {
// one entry in each array per region.
regionInfo: {},

pathNames: ["none"],
pathNames: [],

tracks: {},
bedFile: undefined,
Expand Down
25 changes: 16 additions & 9 deletions src/components/RegionInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ export const RegionInput = ({
// Generate autocomplete options for regions from regionInfo
// Add : to pathNames
console.log("rendering with pathnames: ", pathNames);
const pathNamesColon = pathNames.map((name) => name + ":");
const pathNamesColon = pathNames.map((name) => {
return {label: name + ":", value: name + ":"};
});
const pathsWithRegion = [];

const regionToDesc = new Map();
Expand All @@ -29,13 +31,12 @@ export const RegionInput = ({
// Stitch path name + region start and end
for (const [index, path] of regionInfo["chr"].entries()) {
const pathWithRegion = path + ":" + regionInfo.start[index] + "-" + regionInfo.end[index];
pathsWithRegion.push(pathWithRegion);
pathsWithRegion.push({
label: pathWithRegion + " " + regionInfo.desc[index],
value: pathWithRegion
});
regionToDesc.set(pathWithRegion, regionInfo.desc[index]);
}

// Add descriptions
pathsWithRegion.push(...regionInfo["desc"]);

}

// Autocomplete selectable options
Expand All @@ -52,14 +53,20 @@ export const RegionInput = ({
<Autocomplete
disablePortal
freeSolo // Allows custom input outside of the options
getOptionLabel={(option) => option.title || option.toString()}
getOptionLabel={(option) => option.label || option.toString()}
value={region}
inputValue={region}
data-testid="autocomplete"
id="regionInput"

onInputChange={(event, newInputValue) => {
handleRegionChange(newInputValue);
onInputChange={(event, newInput) => {
let regionValue = newInput;
const regionObject = displayRegions.find((option) => option.label === newInput);
// IF input is selected from one of the options
if (regionObject) {
regionValue = regionObject.value
}
handleRegionChange(regionValue);
}}

options={displayRegions}
Expand Down
5 changes: 2 additions & 3 deletions src/end-to-end.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ describe("When we wait for it to load", () => {
});

// Make sure that option in RegionInput dropdown (17_1_100) is visible
const text = screen.getAllByText("17_1_100");
expect(text[0]).toBeInTheDocument();
expect(screen.getByText("17:1-100 17_1_100")).toBeInTheDocument();
});
it("the region options in autocomplete are cleared after selecting new data", async () => {
// Input data dropdown
Expand All @@ -232,7 +231,7 @@ describe("When we wait for it to load", () => {
userEvent.click(getRegionInput());
});
// Make sure that old option in RegionInput dropdown (17_...) is not visible
expect(screen.queryByText("17_1_100")).not.toBeInTheDocument();
expect(screen.queryByText("1-100 17_1_100")).not.toBeInTheDocument();
await act(async () => {
userEvent.click(regionInput);
});
Expand Down

0 comments on commit bc8040f

Please sign in to comment.