diff --git a/webpack/components/AnsibleHostDetail/components/RolesTab/AllRolesModal/index.js b/webpack/components/AnsibleHostDetail/components/RolesTab/AllRolesModal/index.js index 7998445d..48dedde6 100644 --- a/webpack/components/AnsibleHostDetail/components/RolesTab/AllRolesModal/index.js +++ b/webpack/components/AnsibleHostDetail/components/RolesTab/AllRolesModal/index.js @@ -28,8 +28,6 @@ const AllRolesModal = ({ hostGlobalId, onClose, history }) => { ), }; - const paginationKeys = { page: 'page', perPage: 'per_page' }; - const wrapper = child => ( {child} @@ -46,7 +44,7 @@ const AllRolesModal = ({ hostGlobalId, onClose, history }) => { useQuery(allAnsibleRolesQuery, { variables: { id: hostGlobalId, - ...useParamsToVars(history, paginationKeys), + ...useParamsToVars(history), }, fetchPolicy: 'network-only', }); @@ -56,7 +54,7 @@ const AllRolesModal = ({ hostGlobalId, onClose, history }) => { totalCount: data.host.allAnsibleRoles.totalCount, }); - const pagination = useCurrentPagination(history, paginationKeys); + const pagination = useCurrentPagination(history); return ( { return `${basePath}${stringyfied}`; }; -export const useCurrentPagination = ( - history, - keys = { page: 'page', perPage: 'per_page' } -) => { +export const useCurrentPagination = (history) => { const pageParams = parsePageParams(history); const uiSettings = useForemanSettings(); return { - [keys.page]: parseInt(pageParams[keys.page], 10) || 1, - [keys.perPage]: - parseInt(pageParams[keys.perPage], 10) || uiSettings.perPage, + page: parseInt(pageParams.page, 10) || 1, + per_page: + parseInt(pageParams.per_page, 10) || uiSettings.perPage, }; }; -export const pageToVars = ( - pagination, - totalCount = 0, - keys = { page: 'page', perPage: 'per_page' }, -) => { - return ({ - first: pagination[keys.page] * pagination[keys.perPage], - last: pagination[keys.page] > 1 & totalCount > 0 ? totalCount - pagination[keys.perPage] : pagination[keys.perPage], - }) -}; +export const pageToVars = ({ page, per_page }, totalCount = 0) => ({ + first: page * per_page, + last: page > 1 & totalCount > 0 ? totalCount - per_page : per_page, +}) -export const useParamsToVars = ( - history, - totalCount, - keys = { page: 'page', perPage: 'per_page' } -) => pageToVars(useCurrentPagination(history, keys), totalCount, keys); +export const useParamsToVars = (history, totalCount) => pageToVars(useCurrentPagination(history), totalCount);