Skip to content

Commit

Permalink
Correctly sort metrics in the "Add metric" dropdown menu.
Browse files Browse the repository at this point in the history
Fixes #9857.
  • Loading branch information
fniessink committed Oct 23, 2024
1 parent 8afa6a1 commit 03705df
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions components/frontend/src/widgets/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ export function AddDropdownButton({ itemSubtypes, itemType, onClick, allItemSubt
items = items.filter((item) => !usedItemSubtypeKeys.includes(item.key))
}
const options = items.filter((itemSubtype) => itemSubtype.text.toLowerCase().includes(query.toLowerCase()))
options.sort((a, b) => a.text.localeCompare(b.text))
return (
<Popup
content={`Add a new ${itemType} here`}
Expand Down
10 changes: 9 additions & 1 deletion components/frontend/src/widgets/Button.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function renderAddDropdownButton(nrItems = 2, totalItems = 10, usedItemKeys = []
<AddDropdownButton
allItemSubtypes={allItemSubtypes}
itemType="foo"
itemSubtypes={itemSubtypes}
itemSubtypes={itemSubtypes.toReversed()} // Pass items in reversed order to test they are sorted correctly
onClick={mockCallback}
usedItemSubtypeKeys={usedItemKeys}
/>,
Expand Down Expand Up @@ -71,6 +71,14 @@ test("AddDropdownButton keyboard navigation", async () => {
expect(mockCallback).toHaveBeenCalledWith("sub 2")
})

test("AddDropdownButton sort order", async () => {
renderAddDropdownButton()
await act(async () => {
fireEvent.click(screen.getByText(/Add foo/))
})
expect(screen.getAllByText(/Sub/).map((item) => item.innerHTML)).toStrictEqual(["Sub 1", "Sub 2"])
})

test("AddDropdownButton hides popup when dropdown is shown", async () => {
renderAddDropdownButton()
await userEvent.hover(screen.getByText(/Add foo/))
Expand Down
1 change: 1 addition & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ If your currently installed *Quality-time* version is not v5.17.0, please first

### Fixed

- Correctly sort metrics in the "Add metric" dropdown menu. Fixes [#9857](https://github.com/ICTU/quality-time/issues/9857).
- The warning message shown for unsupported measurement details was incorrect for metrics with a version scale. Fixes [#9973](https://github.com/ICTU/quality-time/issues/9973).
- The metric summary cards with pie chart wouldn't erase the center label when rerendering, causing the label to be visible multiple times. Fixes [#10098](https://github.com/ICTU/quality-time/issues/10098).

Expand Down

0 comments on commit 03705df

Please sign in to comment.