Skip to content

Commit

Permalink
Breadcrumb api call fix (harness#848)
Browse files Browse the repository at this point in the history
* Fixed failing api call for repos in MFE

* Changed retry limit to 5 instead of the default 3

* Renamed function

* Changed variable name

* Changed location to location.pathname in dependency array
  • Loading branch information
vivek-harness authored Jan 28, 2025
1 parent e75b7e5 commit d1b6401
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
15 changes: 7 additions & 8 deletions apps/gitness/src/AppMFE.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ export interface MFERouteRendererProps {
onRouteChange: (updatedLocationPathname: string) => void
}

const filteredRoutes = extractRedirectRouteObjects(repoRoutes)
const isRouteMatchingRedirectRoutes = (pathToValidate: string) => {
return filteredRoutes.some(route => matchPath(`/${route.path}` as string, pathToValidate))
const filteredRedirectRoutes = extractRedirectRouteObjects(repoRoutes)
const isRouteNotMatchingRedirectRoutes = (pathToValidate: string) => {
return filteredRedirectRoutes.every(route => !matchPath(`/${route.path}` as string, pathToValidate))
}

function MFERouteRenderer({ renderUrl, parentLocationPath, onRouteChange }: MFERouteRendererProps) {
const navigate = useNavigate()
const location = useLocation()
const parentPath = parentLocationPath.replace(renderUrl, '')
const isNotRedirectPath = isRouteMatchingRedirectRoutes(location.pathname)
const isNotRedirectPath = isRouteNotMatchingRedirectRoutes(location.pathname)

/**
* renderUrl ==> base URL of parent application
Expand All @@ -52,17 +52,16 @@ function MFERouteRenderer({ renderUrl, parentLocationPath, onRouteChange }: MFER
// Handle location change detected from parent route
useEffect(() => {
if (canNavigate) {
const pathToNavigate = parentLocationPath.replace(renderUrl, '')
navigate(pathToNavigate, { replace: true })
navigate(parentPath, { replace: true })
}
}, [parentLocationPath])
}, [parentPath])

// Notify parent about route change
useEffect(() => {
if (canNavigate) {
onRouteChange?.(`${renderUrl}${location.pathname}`)
}
}, [location])
}, [location.pathname])

return null
}
Expand Down
2 changes: 1 addition & 1 deletion apps/gitness/src/pages-v2/repo/repo-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default function ReposListPage() {
space_ref: `${spaceURL}/+`
},
{
retry: false
retry: 5
}
)

Expand Down

0 comments on commit d1b6401

Please sign in to comment.