generated from RedHatInsights/frontend-starter-app
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(RHINENG-13682): Update eligible filter to single select
This PR updates the system eligibility filter in the select systems modal for a task from radio buttons to a single select dropdown. The functionality should remain the same. Go to the Available tab on the Tasks app and click the Select systems button on a task to load the system modal and select the eligibility filter.
- Loading branch information
1 parent
10ab6a6
commit 729bef8
Showing
5 changed files
with
176 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import React, { useState } from 'react'; | ||
import propTypes from 'prop-types'; | ||
import { | ||
MenuToggle, | ||
Select, | ||
SelectList, | ||
SelectOption, | ||
} from '@patternfly/react-core'; | ||
import { findFilterData } from './helpers'; | ||
|
||
const SelectCustomFilter = ({ | ||
filterId, | ||
options, | ||
selectedValue, | ||
setFilterData, | ||
}) => { | ||
const [isOpen, setOpen] = useState(false); | ||
|
||
const handleSelectChange = (value) => { | ||
setFilterData(findFilterData(value, options)); | ||
}; | ||
|
||
const toggle = (toggleRef) => ( | ||
<MenuToggle | ||
ref={toggleRef} | ||
onClick={() => setOpen(!isOpen)} | ||
isExpanded={isOpen} | ||
style={{ | ||
width: 'auto', | ||
}} | ||
> | ||
{options.find((item) => item.value === selectedValue.value)?.label} | ||
</MenuToggle> | ||
); | ||
|
||
return ( | ||
<div | ||
className="pf-v5-c-select pf-v5-u-mr-sm pf-v5-u-mb-sm" | ||
style={{ width: 'auto' }} | ||
> | ||
<Select | ||
aria-label="Select Input" | ||
isOpen={isOpen} | ||
key={filterId} | ||
onSelect={(event, optionName) => handleSelectChange(optionName)} | ||
onOpenChange={(isOpen) => setOpen(isOpen)} | ||
selected={selectedValue.label} | ||
toggle={toggle} | ||
shouldFocusToggleOnSelect | ||
> | ||
<SelectList> | ||
{options.map((item) => ( | ||
<SelectOption | ||
width="100%" | ||
key={filterId + item.label} | ||
value={item.label} | ||
> | ||
{item.label} | ||
</SelectOption> | ||
))} | ||
</SelectList> | ||
</Select> | ||
</div> | ||
); | ||
}; | ||
|
||
SelectCustomFilter.propTypes = { | ||
filterId: propTypes.string, | ||
options: propTypes.array, | ||
setFilterData: propTypes.func, | ||
selectedValue: propTypes.object, | ||
}; | ||
|
||
export default SelectCustomFilter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/SmartComponents/SystemTable/__tests__/SelectCustomFilter.tests.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React from 'react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import SelectCustomFilter from '../SelectCustomFilter'; | ||
import { render, screen, waitFor, within } from '@testing-library/react'; | ||
|
||
const options = [ | ||
{ value: 'op1', label: 'option 1' }, | ||
{ value: 'op2', label: 'option 2' }, | ||
{ value: 'op3', label: 'option 3' }, | ||
]; | ||
const filterId = 'my-filter'; | ||
const setFilterData = jest.fn(); | ||
|
||
describe('SelectCustomFilter component', () => { | ||
it('Should handle select values', async () => { | ||
const selectedValue = { value: 'op1', label: 'option 1' }; | ||
|
||
render( | ||
<SelectCustomFilter | ||
selectedValue={selectedValue} | ||
setFilterData={setFilterData} | ||
options={options} | ||
filterId={filterId} | ||
/> | ||
); | ||
|
||
await waitFor(() => | ||
userEvent.click( | ||
screen.getByRole('button', { | ||
name: /option 1/i, | ||
}) | ||
) | ||
); | ||
|
||
const option1 = screen.getByRole('option', { | ||
name: /option 1/i, | ||
}); | ||
const option2 = screen.getByRole('option', { | ||
name: /option 2/i, | ||
}); | ||
const option3 = screen.getByRole('option', { | ||
name: /option 3/i, | ||
}); | ||
|
||
expect( | ||
within(option1).getByRole('img', { | ||
hidden: true, | ||
}) | ||
).toBeTruthy(); | ||
expect( | ||
within(option2).queryByRole('img', { | ||
hidden: true, | ||
}) | ||
).toBeFalsy(); | ||
expect( | ||
within(option3).queryByRole('img', { | ||
hidden: true, | ||
}) | ||
).toBeFalsy(); | ||
|
||
await waitFor(() => userEvent.click(option2)); | ||
|
||
expect(setFilterData).toHaveBeenCalledWith(options[1]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters