Skip to content

Commit

Permalink
fix(RHINENG-462-2): hide centos versions in os filter
Browse files Browse the repository at this point in the history
Only inventory and tasks need to see centos versions in the operating system filter on the inventory table. All other apps will not be fetching centos systems, so they don't need them in the dropdown.

You can test this by running inventory with tasks and any other apps to make sure they show or are hidden.
  • Loading branch information
Michael Johnson authored and johnsonm325 committed Oct 13, 2023
1 parent 1301b0a commit 2922e1b
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 15 deletions.
15 changes: 12 additions & 3 deletions src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,18 @@ export function getAllTags(search, pagination = {}) {
);
}

export function getOperatingSystems(params = []) {
return systemProfile.apiSystemProfileGetOperatingSystem(...params);
}
export const getOperatingSystems = async (params = [], showCentosVersions) => {
let operatingSystems = await systemProfile.apiSystemProfileGetOperatingSystem(
...params
);
if (!showCentosVersions) {
let newResults = operatingSystems?.results.filter(
({ value }) => !value.name.toLowerCase().startsWith('centos')
);
operatingSystems.results = newResults;
}
return operatingSystems;
};

export const fetchDefaultStalenessValues = () => {
return instance.get(`${INVENTORY_API_BASE}/account/staleness/defaults`);
Expand Down
4 changes: 3 additions & 1 deletion src/components/InventoryTable/EntityTableToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const EntityTableToolbar = ({
onRefreshData,
loaded,
showTagModal,
showCentosVersions,
...props
}) => {
const dispatch = useDispatch();
Expand Down Expand Up @@ -158,7 +159,7 @@ const EntityTableToolbar = ({
setEndDate,
] = useLastSeenFilter(reducer);
const [osFilterConfig, osFilterChips, osFilterValue, setOsFilterValue] =
useOperatingSystemFilter([], hasAccess);
useOperatingSystemFilter([], hasAccess, showCentosVersions);
const [
updateMethodConfig,
updateMethodChips,
Expand Down Expand Up @@ -645,6 +646,7 @@ EntityTableToolbar.propTypes = {
bulkSelect: PropTypes.object,
showTagModal: PropTypes.bool,
disableDefaultColumns: PropTypes.any,
showCentosVersions: PropTypes.bool,
};

EntityTableToolbar.defaultProps = {
Expand Down
3 changes: 3 additions & 0 deletions src/components/InventoryTable/InventoryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const InventoryTable = forwardRef(
hasCheckbox,
onRowClick,
abortOnUnmount = true,
showCentosVersions = false,
...props
},
ref
Expand Down Expand Up @@ -257,6 +258,7 @@ const InventoryTable = forwardRef(
deleteTitle: 'Reset filters',
...activeFiltersConfig,
}}
showCentosVersions={showCentosVersions}
>
{children}
</EntityTableToolbar>
Expand Down Expand Up @@ -327,6 +329,7 @@ InventoryTable.propTypes = {
hasCheckbox: PropTypes.bool,
onRowClick: PropTypes.func,
abortOnUnmount: PropTypes.bool,
showCentosVersions: PropTypes.bool,
};

export default InventoryTable;
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ exports[`InventoryTable should render correctly - no data 1`] = `
onRefreshData={[Function]}
page={1}
perPage={50}
showCentosVersions={false}
showTags={false}
/>
<ForwardRef
Expand Down Expand Up @@ -55,6 +56,7 @@ exports[`InventoryTable should render correctly - with no access 1`] = `
onRefreshData={[Function]}
page={1}
perPage={50}
showCentosVersions={false}
showTags={false}
sortBy={
Object {
Expand Down Expand Up @@ -134,6 +136,7 @@ exports[`InventoryTable should render correctly 1`] = `
onRefreshData={[Function]}
page={1}
perPage={50}
showCentosVersions={false}
showTags={false}
sortBy={
Object {
Expand Down Expand Up @@ -251,6 +254,7 @@ exports[`InventoryTable should render correctly with items 1`] = `
onRefreshData={[Function]}
page={5}
perPage={20}
showCentosVersions={false}
showTags={false}
sortBy={
Object {
Expand Down Expand Up @@ -361,6 +365,7 @@ exports[`InventoryTable should render correctly with items no totla 1`] = `
onRefreshData={[Function]}
page={5}
perPage={20}
showCentosVersions={false}
showTags={false}
sortBy={
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ const ConventionalSystemsTab = ({
}}
bulkSelect={bulkSelectConfig}
onRowClick={(_e, id, app) => navigate(`/${id}${app ? `/${app}` : ''}`)}
showCentosVersions={true}
/>

<DeleteModal
Expand Down
10 changes: 7 additions & 3 deletions src/components/filters/useOperatingSystemFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export const operatingSystemFilterReducer = (_state, { type, payload }) => ({
* @param {Array} apiParams - an array containing parameters for GET /system_profile/operating_system call
* @return {Array} An array containing config object, chips array and value setter function.
*/
const useOperatingSystemFilter = (apiParams = [], hasAccess) => {
const useOperatingSystemFilter = (
apiParams = [],
hasAccess,
showCentosVersions
) => {
const dispatch = useDispatch();
const operatingSystems = useSelector(
({ entities }) => entities?.operatingSystems
Expand All @@ -35,9 +39,9 @@ const useOperatingSystemFilter = (apiParams = [], hasAccess) => {

useEffect(() => {
if (typeof hasAccess === 'undefined') {
dispatch(fetchOperatingSystems(apiParams));
dispatch(fetchOperatingSystems(apiParams, showCentosVersions));
} else if (typeof hasAccess !== 'undefined' && hasAccess === true) {
dispatch(fetchOperatingSystems(apiParams));
dispatch(fetchOperatingSystems(apiParams, showCentosVersions));
}
}, []);

Expand Down
27 changes: 21 additions & 6 deletions src/components/filters/useOperatingSystemFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,18 @@ describe('useOperatingSystemFilter', () => {
);

it('should initiate an API request', async () => {
renderHook(useOperatingSystemFilter, { wrapper });
renderHook(() => useOperatingSystemFilter([], true, true), { wrapper });
await waitFor(() => {
expect(mockSystemProfile.history.get.length).toBe(1);
});
mockSystemProfile.resetHistory();
});

it('should return empty state value', () => {
const { result } = renderHook(useOperatingSystemFilter, { wrapper });
const { result } = renderHook(
() => useOperatingSystemFilter([], true, true),
{ wrapper }
);
expect(result.current).toMatchSnapshot();
});
});
Expand All @@ -49,20 +52,29 @@ describe('useOperatingSystemFilter', () => {
);

it('should match snapshot', () => {
const { result } = renderHook(useOperatingSystemFilter, { wrapper });
const { result } = renderHook(
() => useOperatingSystemFilter([], true, true),
{ wrapper }
);
expect(result.current).toMatchSnapshot();
});

it('should return correct filter config', () => {
const { result } = renderHook(useOperatingSystemFilter, { wrapper });
const { result } = renderHook(
() => useOperatingSystemFilter([], true, true),
{ wrapper }
);
const [config] = result.current;
expect(config.filterValues.groups.length).toBe(5);
expect(config.label).toBe('Operating System'); // should be all caps
expect(config.type).toBe('group');
});

it('should return correct chips array, current value and value setter', () => {
const { result } = renderHook(useOperatingSystemFilter, { wrapper });
const { result } = renderHook(
() => useOperatingSystemFilter([], true, true),
{ wrapper }
);
const [, chips, value, setValue] = result.current;
expect(chips.length).toBe(0);
expect(value.length).toBe(0);
Expand Down Expand Up @@ -94,7 +106,10 @@ describe('useOperatingSystemFilter', () => {
{children}
</Provider>
);
const { result } = renderHook(useOperatingSystemFilter, { wrapper });
const { result } = renderHook(
() => useOperatingSystemFilter([], true, true),
{ wrapper }
);
expect(result.current).toMatchSnapshot();
});
});
Expand Down
4 changes: 2 additions & 2 deletions src/store/inventory-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,9 @@ export const fetchGroupDetail = (groupId) => ({
payload: getGroupDetail(groupId),
});

export const fetchOperatingSystems = (params = []) => ({
export const fetchOperatingSystems = (params = [], showCentosVersions) => ({
type: ACTION_TYPES.OPERATING_SYSTEMS,
payload: getOperatingSystems(params),
payload: getOperatingSystems(params, showCentosVersions),
});

export const deleteEntity = (systems, displayName) => ({
Expand Down

0 comments on commit 2922e1b

Please sign in to comment.