Skip to content
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

Fix [Pagination] next page is broken for ML functions. datasets, artifacts & models #2980

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/common/Pagination/Pagination.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ such restriction.
import React, { useCallback, useMemo, useRef } from 'react'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { useNavigate, useSearchParams } from 'react-router-dom'
import { useLocation, useNavigate, useSearchParams } from 'react-router-dom'
import { max, min } from 'lodash'

import { RoundedIcon } from 'igz-controls/components'
Expand Down Expand Up @@ -51,6 +51,7 @@ const Pagination = ({ closeParamName = '', paginationConfig }) => {
const paginationPagesRef = useRef()
const leftSideRef = useRef(0)
const rightSideRef = useRef(0)
const location = useLocation()

// Total pages are now calculated based on start and end pages
const totalPagesCount = useMemo(
Expand Down Expand Up @@ -78,9 +79,9 @@ const Pagination = ({ closeParamName = '', paginationConfig }) => {

const handlePageChange = useCallback(() => {
if (closeParamName) {
navigate(getCloseDetailsLink(closeParamName, true), { replace: true })
navigate(getCloseDetailsLink(closeParamName, location, true), { replace: true })
}
}, [navigate, closeParamName])
}, [closeParamName, navigate, location])

const paginationItems = useMemo(() => {
if (!paginationConfig[FE_PAGE]) return []
Expand Down
8 changes: 7 additions & 1 deletion src/components/Datasets/DatasetsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ such restriction.
import React from 'react'
import PropTypes from 'prop-types'
import { isEmpty } from 'lodash'
import { useLocation } from 'react-router-dom'

import ActionBar from '../ActionBar/ActionBar'
import ArtifactsFilters from '../ArtifactsActionBar/ArtifactsFilters'
Expand Down Expand Up @@ -73,6 +74,8 @@ const DatasetsView = React.forwardRef(
},
{ datasetsRef }
) => {
const location = useLocation()

return (
<>
<div className="content-wrapper" ref={datasetsRef}>
Expand Down Expand Up @@ -130,7 +133,10 @@ const DatasetsView = React.forwardRef(
applyDetailsChangesCallback={applyDetailsChangesCallback}
detailsFormInitialValues={detailsFormInitialValues}
getCloseDetailsLink={() =>
getCloseDetailsLink(isAllVersions ? ALL_VERSIONS_PATH : DATASETS_TAB)
getCloseDetailsLink(
isAllVersions ? ALL_VERSIONS_PATH : DATASETS_TAB,
location
)
}
handleCancel={() => setSelectedDatasetMin({})}
pageData={pageData}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Details/DetailsHeader/DetailsHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ const DetailsHeader = ({
className="item-header__back-btn"
to={
getCloseDetailsLink
? getCloseDetailsLink(selectedItem.name)
? getCloseDetailsLink(selectedItem.name, location)
: generateUrlFromRouterPath(
window.location.pathname.split('/').slice(0, -2).join('/') +
window.location.search
Expand Down Expand Up @@ -334,7 +334,7 @@ const DetailsHeader = ({
data-testid="details-close-btn"
to={
getCloseDetailsLink
? getCloseDetailsLink(selectedItem.name)
? getCloseDetailsLink(selectedItem.name, location)
: getDefaultCloseDetailsLink(params, pageData.page, tab)
}
onClick={handleCancelClick}
Expand Down
8 changes: 7 additions & 1 deletion src/components/Documents/DocumentsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ such restriction.
import React from 'react'
import PropTypes from 'prop-types'
import { isEmpty } from 'lodash'
import { useLocation } from 'react-router-dom'

import Breadcrumbs from '../../common/Breadcrumbs/Breadcrumbs'
import Loader from '../../common/Loader/Loader'
Expand Down Expand Up @@ -68,6 +69,8 @@ const DocumentsView = React.forwardRef(
},
{ documentsRef }
) => {
const location = useLocation()

return (
<>
<div className="content-wrapper" ref={documentsRef}>
Expand Down Expand Up @@ -117,7 +120,10 @@ const DocumentsView = React.forwardRef(
applyDetailsChangesCallback={applyDetailsChangesCallback}
detailsFormInitialValues={detailsFormInitialValues}
getCloseDetailsLink={() =>
getCloseDetailsLink(isAllVersions ? ALL_VERSIONS_PATH : DOCUMENTS_TAB)
getCloseDetailsLink(
isAllVersions ? ALL_VERSIONS_PATH : DOCUMENTS_TAB,
location
)
}
handleCancel={() => setSelectedDocumentMin({})}
pageData={pageData}
Expand Down
5 changes: 4 additions & 1 deletion src/components/Files/FilesView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ such restriction.
import React from 'react'
import PropTypes from 'prop-types'
import { isEmpty } from 'lodash'
import { useLocation } from 'react-router-dom'

import ActionBar from '../ActionBar/ActionBar'
import ArtifactsFilters from '../ArtifactsActionBar/ArtifactsFilters'
Expand Down Expand Up @@ -72,6 +73,8 @@ const FilesView = React.forwardRef(
},
{ filesRef }
) => {
const location = useLocation()

return (
<>
<div className="content-wrapper" ref={filesRef}>
Expand Down Expand Up @@ -129,7 +132,7 @@ const FilesView = React.forwardRef(
applyDetailsChangesCallback={applyDetailsChangesCallback}
detailsFormInitialValues={detailsFormInitialValues}
getCloseDetailsLink={() =>
getCloseDetailsLink(isAllVersions ? ALL_VERSIONS_PATH : FILES_TAB)
getCloseDetailsLink(isAllVersions ? ALL_VERSIONS_PATH : FILES_TAB, location)
}
handleCancel={() => setSelectedFileMin({})}
pageData={pageData}
Expand Down
8 changes: 6 additions & 2 deletions src/components/FunctionsPage/FunctionsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ under the Apache 2.0 license is conditioned upon your compliance with
such restriction.
*/
import React from 'react'
import { useParams } from 'react-router-dom'
import { useLocation, useParams } from 'react-router-dom'
import PropTypes from 'prop-types'

import ActionBar from '../ActionBar/ActionBar'
Expand Down Expand Up @@ -74,6 +74,7 @@ const FunctionsView = ({
tableContent
}) => {
const params = useParams()
const location = useLocation()

return (
<>
Expand Down Expand Up @@ -131,7 +132,10 @@ const FunctionsView = ({
<Table
actionsMenu={actionsMenu}
getCloseDetailsLink={() =>
getCloseDetailsLink(isAllVersions ? ALL_VERSIONS_PATH : FUNCTIONS_PAGE_PATH)
getCloseDetailsLink(
isAllVersions ? ALL_VERSIONS_PATH : FUNCTIONS_PAGE_PATH,
location
)
}
handleCancel={handleCancel}
pageData={pageData}
Expand Down
5 changes: 4 additions & 1 deletion src/components/ModelsPage/Models/ModelsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ such restriction.
import React from 'react'
import PropTypes from 'prop-types'
import { isEmpty } from 'lodash'
import { useLocation } from 'react-router-dom'

import ActionBar from '../../ActionBar/ActionBar'
import ArtifactsFilters from '../../ArtifactsActionBar/ArtifactsFilters'
Expand Down Expand Up @@ -72,6 +73,8 @@ const ModelsView = React.forwardRef(
},
{ modelsRef }
) => {
const location = useLocation()

return (
<>
<div className="models" ref={modelsRef}>
Expand Down Expand Up @@ -138,7 +141,7 @@ const ModelsView = React.forwardRef(
applyDetailsChangesCallback={applyDetailsChangesCallback}
detailsFormInitialValues={detailsFormInitialValues}
getCloseDetailsLink={() =>
getCloseDetailsLink(isAllVersions ? ALL_VERSIONS_PATH : MODELS_TAB)
getCloseDetailsLink(isAllVersions ? ALL_VERSIONS_PATH : MODELS_TAB, location)
}
handleCancel={() => setSelectedModelMin({})}
pageData={pageData}
Expand Down
7 changes: 4 additions & 3 deletions src/components/Workflow/Workflow.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import classnames from 'classnames'
import { forEach, isEmpty } from 'lodash'
import { useNavigate, useParams } from 'react-router-dom'
import { useLocation, useNavigate, useParams } from 'react-router-dom'

import Details from '../Details/Details'
import MlReactFlow from '../../common/ReactFlow/MlReactFlow'
Expand Down Expand Up @@ -88,6 +88,7 @@ const Workflow = ({
const params = useParams()
const navigate = useNavigate()
const { isStagingMode } = useMode()
const location = useLocation()

const graphViewClassNames = classnames(
'graph-view',
Expand Down Expand Up @@ -263,7 +264,7 @@ const Workflow = ({
<Details
actionsMenu={actionsMenu}
detailsMenu={pageData.details.menu}
getCloseDetailsLink={() => getCloseDetailsLink(params.workflowId)}
getCloseDetailsLink={() => getCloseDetailsLink(params.workflowId, location)}
handleCancel={handleCancel}
pageData={pageData}
retryRequest={refreshJobs}
Expand All @@ -275,7 +276,7 @@ const Workflow = ({
) : (
<Table
actionsMenu={actionsMenu}
getCloseDetailsLink={() => getCloseDetailsLink(params.workflowId)}
getCloseDetailsLink={() => getCloseDetailsLink(params.workflowId, location)}
handleCancel={handleCancel}
hideActionsMenu
pageData={pageData}
Expand Down
12 changes: 7 additions & 5 deletions src/elements/JobsTable/JobsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,11 +218,11 @@ const JobsTable = React.forwardRef(
(job, isDeleteAll) => {
handleDeleteJob(isDeleteAll, job, refreshJobs, filters, dispatch).then(() => {
if (params.jobName) {
navigate(getCloseDetailsLink(params.jobName, true))
navigate(getCloseDetailsLink(params.jobName, location, true))
}
})
},
[params.jobName, refreshJobs, filters, dispatch, navigate]
[refreshJobs, filters, dispatch, params.jobName, navigate, location]
)

const handleConfirmDeleteJob = useCallback(
Expand Down Expand Up @@ -319,7 +319,8 @@ const JobsTable = React.forwardRef(
setSelectedJob,
modifyAndSelectRun,
searchParams,
paginationConfigJobsRef
paginationConfigJobsRef,
location
)
}, [
searchParams,
Expand All @@ -330,7 +331,8 @@ const JobsTable = React.forwardRef(
params.jobName,
params.projectName,
setSelectedJob,
modifyAndSelectRun
modifyAndSelectRun,
location
])

return (
Expand All @@ -352,7 +354,7 @@ const JobsTable = React.forwardRef(
<>
<Table
actionsMenu={actionsMenu}
getCloseDetailsLink={() => getCloseDetailsLink(params.jobName)}
getCloseDetailsLink={() => getCloseDetailsLink(params.jobName, location)}
handleCancel={() => setSelectedJob({})}
pageData={pageData}
retryRequest={handleRefreshWithFilters}
Expand Down
5 changes: 3 additions & 2 deletions src/utils/jobs.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export const checkForSelectedJob = debounce(
setSelectedJob,
modifyAndSelectRun,
searchParams,
paginationConfigJobsRef
paginationConfigJobsRef,
location
) => {
if (jobId) {
const searchBePage = parseInt(searchParams.get(BE_PAGE))
Expand All @@ -67,7 +68,7 @@ export const checkForSelectedJob = debounce(
})

if (!selectedPaginatedJob) {
navigate(getCloseDetailsLink(jobName, true), { replace: true })
navigate(getCloseDetailsLink(jobName, location, true), { replace: true })
} else if (selectedPaginatedJob) {
modifyAndSelectRun(cloneDeep(selectedPaginatedJob))
}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/link-helper.util.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ export const generateUrlFromRouterPath = link => {
return new URL(link, window.location.origin).toString()
}

export const getCloseDetailsLink = (paramName, ignoreOrigin) => {
export const getCloseDetailsLink = (paramName, location, ignoreOrigin) => {
const link =
window.location.pathname
location.pathname
.split('/')
.splice(0, window.location.pathname.split('/').lastIndexOf(paramName) + 1)
.splice(0, location.pathname.split('/').lastIndexOf(paramName) + 1)
.join('/') + window.location.search

return ignoreOrigin ? link : generateUrlFromRouterPath(link)
Expand Down
Loading