Skip to content

Commit

Permalink
fix(RHINENG-13682): Update to remove All systems chip
Browse files Browse the repository at this point in the history
To test:

- Go to the Available tab
- Click Select systems on a task
- Use the eligibility filter

Test by removing the Eligible systems chip. It should remove the chip and apply All systems filter with no chip. Before, we swapped between the All systems and Eligible systems chips.
  • Loading branch information
Michael Johnson authored and johnsonm325 committed Jan 17, 2025
1 parent be031c2 commit 7059052
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
5 changes: 3 additions & 2 deletions src/SmartComponents/SystemTable/SelectCustomFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const SelectCustomFilter = ({

const handleSelectChange = (value) => {
setFilterData(findFilterData(value, options));
setOpen(false);
};

const toggle = (toggleRef) => (
Expand All @@ -29,7 +30,7 @@ const SelectCustomFilter = ({
width: 'auto',
}}
>
{options.find((item) => item.value === selectedValue.value)?.label}
{options.find((item) => item.value === selectedValue)?.label}
</MenuToggle>
);

Expand All @@ -44,7 +45,7 @@ const SelectCustomFilter = ({
key={filterId}
onSelect={(event, optionName) => handleSelectChange(optionName)}
onOpenChange={(isOpen) => setOpen(isOpen)}
selected={selectedValue.label}
selected={options.find((item) => item.value === selectedValue)?.label}
toggle={toggle}
shouldFocusToggleOnSelect
>
Expand Down
19 changes: 11 additions & 8 deletions src/SmartComponents/SystemTable/SystemTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,21 +109,24 @@ const SystemTable = ({
<SelectCustomFilter
filterId="task-eligibility"
options={eligibilityFilterItems}
selectedValue={eligibility}
selectedValue={eligibility.value}
setFilterData={setEligibilityData}
/>
),
},
};

const activeFiltersConfig = {
filters: [
{
id: 'Task eligibility',
category: 'Task eligibility',
chips: [{ name: eligibility.label, value: eligibility.value }],
},
],
filters:
eligibility.value === ELIGIBLE_SYSTEMS_VALUE
? [
{
id: 'Task eligibility',
category: 'Task eligibility',
chips: [{ name: eligibility.label, value: eligibility.value }],
},
]
: [],
onDelete: (event, itemsToRemove, isAll) => {
if (isAll) {
setEligibility(eligibilityFilterItems[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('SelectCustomFilter component', () => {

render(
<SelectCustomFilter
selectedValue={selectedValue}
selectedValue={selectedValue.value}
setFilterData={setFilterData}
options={options}
filterId={filterId}
Expand Down
42 changes: 35 additions & 7 deletions src/SmartComponents/SystemTable/__tests__/helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('buildFilterSortString', () => {
const workloadFilters = [];
const activeFiltersConfig = { filters: {} };

it('should return an default filterstring when no filters given', () => {
it('should return a default filterstring when no filters given', () => {
expect(
buildFilterSortString(
limit,
Expand All @@ -21,6 +21,30 @@ describe('buildFilterSortString', () => {
workloadFilters,
activeFiltersConfig
)
).toEqual('?limit=25&offset=0&sort=name&all_systems=true');
});

it('should not return all_systems=true when eligible systems filter applied', () => {
let activefilters = {
filters: [
{
id: 'Task eligibility',
category: 'Task eligibility',
chips: [{ name: 'Eligible Systems', value: 'eligible-systems' }],
},
],
};
expect(
buildFilterSortString(
limit,
offset,
orderBy,
orderDirection,
{},
tags,
workloadFilters,
activefilters
)
).toEqual('?limit=25&offset=0&sort=name');
});

Expand All @@ -44,7 +68,9 @@ describe('buildFilterSortString', () => {
workloadFilters,
activeFiltersConfig
)
).toEqual('?limit=25&offset=0&sort=name&operating_system=RHEL|9.4');
).toEqual(
'?limit=25&offset=0&sort=name&operating_system=RHEL|9.4&all_systems=true'
);

filters = {
osFilter: {
Expand All @@ -66,7 +92,9 @@ describe('buildFilterSortString', () => {
workloadFilters,
activeFiltersConfig
)
).toEqual('?limit=25&offset=0&sort=name&operating_system=RHEL|9.3');
).toEqual(
'?limit=25&offset=0&sort=name&operating_system=RHEL|9.3&all_systems=true'
);

filters = {
osFilter: {
Expand Down Expand Up @@ -99,7 +127,7 @@ describe('buildFilterSortString', () => {
activeFiltersConfig
)
).toEqual(
'?limit=25&offset=0&sort=name&operating_system=RHEL|9.4,RHEL|9.3,RHEL|9.9,RHEL|8.4,AlmaLinux|8.4,AlmaLinux|8.5'
'?limit=25&offset=0&sort=name&operating_system=RHEL|9.4,RHEL|9.3,RHEL|9.9,RHEL|8.4,AlmaLinux|8.4,AlmaLinux|8.5&all_systems=true'
);

filters = {
Expand Down Expand Up @@ -132,7 +160,7 @@ describe('buildFilterSortString', () => {
activeFiltersConfig
)
).toEqual(
'?limit=25&offset=0&sort=name&operating_system=RHEL|9.5,RHEL|9.4,RHEL|9.3,RHEL|9.2,RHEL|9.1,RHEL|9.0,Cent Os Linux|8.4,Cent Os Linux|8.5'
'?limit=25&offset=0&sort=name&operating_system=RHEL|9.5,RHEL|9.4,RHEL|9.3,RHEL|9.2,RHEL|9.1,RHEL|9.0,Cent Os Linux|8.4,Cent Os Linux|8.5&all_systems=true'
);

filters = {
Expand Down Expand Up @@ -176,7 +204,7 @@ describe('buildFilterSortString', () => {
activeFiltersConfig
)
).toEqual(
'?limit=25&offset=0&sort=name&operating_system=RHEL|9.4,RHEL|9.3,RHEL|9.9,RHEL|8.4,Alma Linux|8.4,Alma Linux|8.5,Cent Os|8.4,Cent Os|8.5,Cent Os|30.99,Cent Os|30.88'
'?limit=25&offset=0&sort=name&operating_system=RHEL|9.4,RHEL|9.3,RHEL|9.9,RHEL|8.4,Alma Linux|8.4,Alma Linux|8.5,Cent Os|8.4,Cent Os|8.5,Cent Os|30.99,Cent Os|30.88&all_systems=true'
);

filters = {
Expand Down Expand Up @@ -209,7 +237,7 @@ describe('buildFilterSortString', () => {
activeFiltersConfig
)
).toEqual(
'?limit=25&offset=0&sort=name&operating_system=RHEL|9.4,RHEL|9.3,RHEL|9.9,AlmaLinux|8.4,AlmaLinux|8.5'
'?limit=25&offset=0&sort=name&operating_system=RHEL|9.4,RHEL|9.3,RHEL|9.9,AlmaLinux|8.4,AlmaLinux|8.5&all_systems=true'
);
});
});
9 changes: 5 additions & 4 deletions src/SmartComponents/SystemTable/helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ALL_SYSTEMS_VALUE } from './constants';
import { ELIGIBLE_SYSTEMS_VALUE } from './constants';

const buildSortString = (orderBy, orderDirection) => {
let sortString = orderBy ? '&sort=' : '';
Expand Down Expand Up @@ -87,9 +87,10 @@ const buildWorkloadFiltersString = (filters) => {
};

const buildEligibilityFilterString = ({ filters }) => {
return filters[0]?.chips[0]?.value === ALL_SYSTEMS_VALUE
? '&all_systems=true'
: '';
return filters[0]?.chips &&
filters[0]?.chips[0]?.value === ELIGIBLE_SYSTEMS_VALUE
? ''
: '&all_systems=true';
};

// TODO this should be based on a URLSearchParams object and use its toString() function
Expand Down

0 comments on commit 7059052

Please sign in to comment.