webpack/components/withLoading.js in foreman_ansible-7.1.1 vs webpack/components/withLoading.js in foreman_ansible-7.1.2

- old
+ new

@@ -11,18 +11,16 @@ permissionDeniedMsg, allowPrimaryAction, } from '../permissionsHelper'; import ErrorState from './ErrorState'; -const pluckData = (data, path) => { +const getResultsLength = (data, path) => { const split = path.split('.'); - return split.reduce((memo, item) => { - if (item) { - return memo[item]; - } - throw new Error('Unexpected empty segment in response data path'); - }, data); + return split.reduce( + (prevValue, currentValue) => prevValue + data[currentValue]?.length || 0, + 0 + ); }; const withLoading = Component => { const defaultEmptyStateProps = { header: __('Nothing Found!'), @@ -77,15 +75,12 @@ /> ); } const renamedData = renameData(data); - const result = pluckData(renamedData, renamedDataPath); + const resultLength = getResultsLength(renamedData, renamedDataPath); - if ( - showEmptyState && - ((Array.isArray(result) && result.length === 0) || !result) - ) { + if (showEmptyState && !resultLength) { return emptyWrapper( <EmptyState {...{ ...defaultEmptyStateProps, ...allowPrimaryAction(