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

Bug: direct link to plant location does not work (first time) #2350

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ const ImageSection = (props: ImageSectionProps) => {
const isEmbed = embed === 'true';

const handleBackButton = () => {
if (setPreventShallowPush) {
setPreventShallowPush(true);
}
if (setPreventShallowPush) setPreventShallowPush(true);

const previousPageRoute = sessionStorage.getItem('backNavigationUrl');
const defaultRoute = `/${locale}`;
Expand Down
8 changes: 6 additions & 2 deletions src/features/projectsV2/ProjectsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,8 @@ export const ProjectsProvider: FC<ProjectsProviderProps> = ({
page !== 'project-details' ||
singleProject === null ||
selectedSite !== null ||
(requestedPlantLocation && requestedSite)
(requestedPlantLocation && requestedSite) ||
plantLocations === null
)
return;

Expand Down Expand Up @@ -353,14 +354,16 @@ export const ProjectsProvider: FC<ProjectsProviderProps> = ({
selectedPlantLocation,
selectedSite,
hasNoSites,
plantLocations,
]);
useEffect(() => {
if (
!router.isReady ||
page !== 'project-details' ||
singleProject === null ||
selectedPlantLocation !== null ||
preventShallowPush
preventShallowPush ||
plantLocations === null
)
return;
// Handle the case where a direct link requests a specific site (via URL query)
Expand Down Expand Up @@ -398,6 +401,7 @@ export const ProjectsProvider: FC<ProjectsProviderProps> = ({
requestedSite,
router.isReady,
selectedPlantLocation,
plantLocations,
preventShallowPush,
hasNoSites,
]);
Expand Down
15 changes: 13 additions & 2 deletions src/features/projectsV2/ProjectsMap/SingleProjectView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ const SingleProjectView = ({ mapRef }: Props) => {

// Zoom to project site
useEffect(() => {
if (!router.isReady || selectedPlantLocation !== null) return;
if (
!router.isReady ||
selectedPlantLocation !== null ||
plantLocations === null
)
return;
if (sitesGeojson.features.length > 0 && selectedSite !== null) {
zoomInToProjectSite(
mapRef,
Expand All @@ -85,7 +90,13 @@ const SingleProjectView = ({ mapRef }: Props) => {
);
}
}
}, [selectedSite, sitesGeojson, router.isReady, selectedPlantLocation]);
}, [
selectedSite,
sitesGeojson,
router.isReady,
selectedPlantLocation,
plantLocations,
]);

useEffect(() => {
const hasNoPlantLocations = !plantLocations?.length;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/projectV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ export const getLocalizedPath = (path: string, locale: string): string => {
}

// If path already starts with locale, return as is
if (cleanPath.startsWith(`/${locale}/`)) {
if (cleanPath.startsWith(`/${locale}`)) {
Copy link
Collaborator

@mohitb35 mohitb35 Jan 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this cause an issue?

What if the cleanPath starts with /france-salesforce where the first 2 letters fr match a locale?

This is currently unlikely to happen, since the number of places internally linking to the project details page are limited, but will be difficult to debug if it occurs (after adding other sources).

return cleanPath;
}

Expand Down
Loading