-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: InventoryTable #2129
base: master
Are you sure you want to change the base?
refactor: InventoryTable #2129
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,13 +3,7 @@ import PropTypes from 'prop-types'; | |
import { usePermissionsWithContext } from '@redhat-cloud-services/frontend-components-utilities/RBACHook'; | ||
import { GENERAL_HOSTS_READ_PERMISSIONS } from '../constants'; | ||
|
||
const RenderWrapper = ({ | ||
cmp: Component, | ||
isRbacEnabled, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This prop is not really needed or used (please double check) |
||
inventoryRef, | ||
store, | ||
...props | ||
}) => { | ||
const RenderWrapper = ({ cmp: Component, inventoryRef, store, ...props }) => { | ||
const { hasAccess } = usePermissionsWithContext( | ||
[GENERAL_HOSTS_READ_PERMISSIONS], | ||
true, | ||
|
@@ -22,7 +16,6 @@ const RenderWrapper = ({ | |
{...(inventoryRef && { | ||
ref: inventoryRef, | ||
})} | ||
isRbacEnabled={isRbacEnabled} | ||
hasAccess={hasAccess} | ||
store={store} | ||
/> | ||
|
@@ -34,7 +27,6 @@ RenderWrapper.propTypes = { | |
inventoryRef: PropTypes.any, | ||
store: PropTypes.object, | ||
customRender: PropTypes.bool, | ||
isRbacEnabled: PropTypes.bool, | ||
}; | ||
|
||
export default RenderWrapper; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -237,35 +237,15 @@ const EntityTableToolbar = ({ | |
*/ | ||
const onRefreshDataInner = useCallback( | ||
(options) => { | ||
console.log('OPSSSS', options); | ||
if (hasAccess) { | ||
onRefreshData(options); | ||
if (showTags && !hasItems) { | ||
dispatch(fetchAllTags(filterTagsBy, {}, getTags)); | ||
} | ||
} | ||
}, | ||
[customFilters?.tags] | ||
); | ||
|
||
/** | ||
* Function used to update data, it either calls `onRefresh` from props or dispatches `onRefreshData`. | ||
* `onRefresh` function takes two parameters | ||
* * entire config with new changes. | ||
* * callback to update data. | ||
* @param {*} config new config to fetch data. | ||
*/ | ||
const updateData = (config) => { | ||
if (hasAccess) { | ||
onRefreshDataInner(config); | ||
} | ||
}; | ||
|
||
/** | ||
* Debounced `updateData` function. | ||
*/ | ||
const debouncedRefresh = useCallback( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is mainly the culprit as far as I remember, starting from line 247. These functions and callbacks were called when they shouldn't have been, due to the debouncing here. These changes in the table and the toolbar change that a little and consolidate everything to only call the ONE debounced refresh function in the EntityTable above. |
||
debounce((config) => updateData(config), 800), | ||
[sortBy?.key, sortBy?.direction] | ||
[hasAccess] | ||
); | ||
|
||
/** | ||
|
@@ -284,7 +264,6 @@ const EntityTableToolbar = ({ | |
hostGroupFilter, | ||
} = reduceFilters([...(filters || []), ...(customFilters?.filters || [])]); | ||
|
||
debouncedRefresh(); | ||
enabledFilters.name && setTextFilter(textFilter); | ||
enabledFilters.stale && setStaleFilter(staleFilter); | ||
enabledFilters.registeredWith && | ||
|
@@ -303,7 +282,7 @@ const EntityTableToolbar = ({ | |
* @param {*} value new value used for filtering. | ||
* @param {*} debounced if debounce function should be used. | ||
*/ | ||
const onSetTextFilter = (value, debounced = true) => { | ||
const onSetTextFilter = (value) => { | ||
const trimmedValue = value?.trim(); | ||
|
||
const textualFilter = filters?.find( | ||
|
@@ -315,8 +294,7 @@ const EntityTableToolbar = ({ | |
filters?.push({ value: TEXT_FILTER, filter: trimmedValue }); | ||
} | ||
|
||
const refresh = debounced ? debouncedRefresh : updateData; | ||
refresh({ page: 1, perPage, filters }); | ||
onRefreshDataInner({ page: 1, perPage, filters }); | ||
}; | ||
|
||
/** | ||
|
@@ -352,7 +330,7 @@ const EntityTableToolbar = ({ | |
|
||
useEffect(() => { | ||
if (shouldReload && enabledFilters.stale) { | ||
onSetFilter(staleFilter, 'staleFilter', debouncedRefresh); | ||
onSetFilter(staleFilter, 'staleFilter', onRefreshDataInner); | ||
} | ||
}, [staleFilter]); | ||
|
||
|
@@ -361,44 +339,44 @@ const EntityTableToolbar = ({ | |
onSetFilter( | ||
registeredWithFilter, | ||
'registeredWithFilter', | ||
debouncedRefresh | ||
onRefreshDataInner | ||
); | ||
} | ||
}, [registeredWithFilter]); | ||
|
||
useEffect(() => { | ||
if (shouldReload && showTags && enabledFilters.tags) { | ||
onSetFilter(mapGroups(selectedTags), 'tagFilters', debouncedRefresh); | ||
onSetFilter(mapGroups(selectedTags), 'tagFilters', onRefreshDataInner); | ||
} | ||
}, [selectedTags]); | ||
|
||
useEffect(() => { | ||
if (shouldReload && enabledFilters.operatingSystem) { | ||
onSetFilter(osFilterValue, 'osFilter', debouncedRefresh); | ||
onSetFilter(osFilterValue, 'osFilter', onRefreshDataInner); | ||
} | ||
}, [osFilterValue]); | ||
|
||
useEffect(() => { | ||
if (shouldReload && enabledFilters.rhcdFilter) { | ||
onSetFilter(rhcdFilterValue, 'rhcdFilter', debouncedRefresh); | ||
onSetFilter(rhcdFilterValue, 'rhcdFilter', onRefreshDataInner); | ||
} | ||
}, [rhcdFilterValue]); | ||
|
||
useEffect(() => { | ||
if (shouldReload && enabledFilters.lastSeenFilter) { | ||
onSetFilter(lastSeenFilterValue, 'lastSeenFilter', debouncedRefresh); | ||
onSetFilter(lastSeenFilterValue, 'lastSeenFilter', onRefreshDataInner); | ||
} | ||
}, [lastSeenFilterValue]); | ||
|
||
useEffect(() => { | ||
if (shouldReload && enabledFilters.updateMethodFilter) { | ||
onSetFilter(updateMethodValue, 'updateMethodFilter', debouncedRefresh); | ||
onSetFilter(updateMethodValue, 'updateMethodFilter', onRefreshDataInner); | ||
} | ||
}, [updateMethodValue]); | ||
|
||
useEffect(() => { | ||
if (shouldReload && enabledFilters.hostGroupFilter) { | ||
onSetFilter(hostGroupValue, 'hostGroupFilter', debouncedRefresh); | ||
onSetFilter(hostGroupValue, 'hostGroupFilter', onRefreshDataInner); | ||
} | ||
}, [hostGroupValue]); | ||
|
||
|
@@ -410,7 +388,7 @@ const EntityTableToolbar = ({ | |
[TAG_CHIP]: (deleted) => | ||
setSelectedTags( | ||
onDeleteTag(deleted, selectedTags, (selectedTags) => | ||
onSetFilter(mapGroups(selectedTags), 'tagFilters', updateData) | ||
onSetFilter(mapGroups(selectedTags), 'tagFilters', onRefreshDataInner) | ||
) | ||
), | ||
[STALE_CHIP]: (deleted) => | ||
|
@@ -454,7 +432,7 @@ const EntityTableToolbar = ({ | |
setEndDate(); | ||
setStartDate(oldestDate); | ||
dispatch(setFilter([])); | ||
updateData({ page: 1, filters: [] }); | ||
onRefreshDataInner({ page: 1, filters: [] }); | ||
}; | ||
|
||
/** | ||
|
@@ -637,7 +615,6 @@ EntityTableToolbar.propTypes = { | |
paginationProps: PropTypes.object, | ||
loaded: PropTypes.bool, | ||
onRefresh: PropTypes.func, | ||
hasCheckbox: PropTypes.bool, | ||
isLoaded: PropTypes.bool, | ||
items: PropTypes.array, | ||
sortBy: PropTypes.object, | ||
|
@@ -650,7 +627,7 @@ EntityTableToolbar.propTypes = { | |
|
||
EntityTableToolbar.defaultProps = { | ||
showTags: false, | ||
hasAccess: true, | ||
hasAccess: false, | ||
activeFiltersConfig: {}, | ||
hideFilters: {}, | ||
showNoGroupOption: false, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't pass this in here. all components that use params lower in the tree should access theme vie the react router (params) hook