Skip to content

Commit

Permalink
fix(ESSNTL-4791): Hide all /groups requests under feature flag (#1853)
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarat authored May 4, 2023
1 parent 435cfe0 commit 32889d9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/components/InventoryTable/EntityTableToolbar.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ describe('EntityTableToolbar', () => {
</Provider>);
wrapper.find('.ins-c-chip-filters button.pf-m-link').last().simulate('click');
const actions = store.getActions();
expect(actions.length).toBe(4);
expect(actions.length).toBe(3);
expect(actions[actions.length - 2]).toMatchObject({ type: 'CLEAR_FILTERS' });
expect(onRefreshData).toHaveBeenCalledWith({ filters: [], page: 1 });
});
Expand Down
9 changes: 7 additions & 2 deletions src/components/filters/useGroupFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useEffect, useMemo, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { fetchGroups } from '../../store/inventory-actions';
import { HOST_GROUP_CHIP } from '../../Utilities/index';
import useFeatureFlag from '../../Utilities/useFeatureFlag';

//for attaching this filter to the redux
export const groupFilterState = { groupHostFilter: null };
Expand Down Expand Up @@ -31,9 +32,13 @@ export const buildHostGroupChips = (selectedGroups = []) => {

const useGroupFilter = (apiParams = []) => {
const dispatch = useDispatch();
const groupsEnabled = useFeatureFlag('hbi.ui.inventory-groups');

useEffect(() => {
dispatch(fetchGroups(apiParams));
}, []);
if (groupsEnabled === true) {
dispatch(fetchGroups(apiParams));
}
}, [groupsEnabled]);
//fetched values
const fetchedValues = useSelector(({ groups }) => groups?.data?.results);
//selected are the groups we selected
Expand Down
5 changes: 5 additions & 0 deletions src/components/filters/useGroupFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import { createPromise as promiseMiddleware } from 'redux-promise-middleware';
import { mockSystemProfile } from '../../__mocks__/hostApi';
import useGroupFilter from './useGroupFilter';

jest.mock('../../Utilities/useFeatureFlag', () => ({
__esModule: true,
default: () => true
}));

describe('useGroupFilter', () => {
const mockStore = configureStore([promiseMiddleware()]);
beforeEach(() => {
Expand Down
17 changes: 10 additions & 7 deletions src/routes/InventoryTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,13 +326,16 @@ const Inventory = ({
onEditOpen(false);
}}
/>
<AddHostToGroupModal
isModalOpen={addHostGroupModalOpen}
setIsModalOpen={setAddHostGroupModalOpen}
modalState={currentSytem}
//should be replaced with a fetch to update the values in the table
reloadData={() => console.log('data reloaded')}
/>
{
groupsEnabled === true &&
<AddHostToGroupModal
isModalOpen={addHostGroupModalOpen}
setIsModalOpen={setAddHostGroupModalOpen}
modalState={currentSytem}
//should be replaced with a fetch to update the values in the table
reloadData={() => console.log('data reloaded')}
/>
}
</React.Fragment>
);
};
Expand Down

0 comments on commit 32889d9

Please sign in to comment.