Skip to content

Commit

Permalink
Use session storage for project id and update routing (#3665)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdess09 authored Sep 27, 2023
1 parent e803393 commit 788708f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
10 changes: 7 additions & 3 deletions dashboard/src/main/home/onboarding/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
import React from "react";
import React, { useContext } from "react";
import { Route, Switch } from "react-router";
import { Context } from "shared/Context";
import PorterErrorBoundary from "shared/error_handling/PorterErrorBoundary";
import { OFState } from "./state";
import ConnectRegistry from "./steps/ConnectRegistry/ConnectRegistry";
import ConnectSource from "./steps/ConnectSource";
import ProvisionResources from "./steps/ProvisionResources/ProvisionResources";

export const Routes = () => {
const context = useContext(Context);
const { currentProject } = context;

return (
<>
<PorterErrorBoundary
errorBoundaryLocation="onboarding"
tags={{ scope: "onboarding" }}
>
<Switch>
<Route path={`/onboarding/source`}>
<Route path={`/onboarding/source/${currentProject}`}>
<ConnectSource
onSuccess={(data) => OFState.actions.nextStep("continue", data)}
/>
Expand All @@ -36,4 +40,4 @@ export const Routes = () => {
);
};

export default Routes;
export default Routes;
12 changes: 9 additions & 3 deletions dashboard/src/main/home/onboarding/state/StepHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const flow: FlowType = {
initial: "connect_source",
steps: {
connect_source: {
url: "/onboarding/source",
url: "/onboarding/source/",
on: {
continue: "connect_registry",
},
Expand Down Expand Up @@ -288,7 +288,7 @@ export const useSteps = (isParentLoading?: boolean) => {
const snap = useSnapshot(StepHandler);
const location = useLocation();
const { pushFiltered } = useRouting();
const { setHasFinishedOnboarding } = useContext(Context);
const { setHasFinishedOnboarding, currentProject } = useContext(Context);

useEffect(() => {
if (isParentLoading) {
Expand All @@ -298,6 +298,12 @@ export const useSteps = (isParentLoading?: boolean) => {
StepHandler.actions.clearState();
setHasFinishedOnboarding(true);
}
pushFiltered(snap.currentStep.url, ["tab"]);
if (currentProject && currentProject.id) {
pushFiltered(`${snap.currentStep.url}?project_id=${currentProject.id}`, ["tab"]);
} else {
pushFiltered(snap.currentStep.url, ["tab"]);
}

}, [location.pathname, snap.currentStep?.url, isParentLoading]);
};

6 changes: 3 additions & 3 deletions dashboard/src/shared/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ class ContextProvider extends Component<PropsType, StateType> {
currentProject: null,
setCurrentProject: (currentProject: ProjectType, callback?: any) => {
if (currentProject) {
localStorage.setItem("currentProject", currentProject.id.toString());
sessionStorage.setItem("currentProject", currentProject.id.toString());
pushQueryParams(this.props, {
project_id: currentProject.id.toString(),
});
} else {
localStorage.removeItem("currentProject");
sessionStorage.removeItem("currentProject");
}
this.setState({ currentProject }, () => {
callback && callback();
Expand Down Expand Up @@ -216,4 +216,4 @@ class ContextProvider extends Component<PropsType, StateType> {
}
}

export { Context, ContextProvider, ContextConsumer };
export { Context, ContextProvider, ContextConsumer };

0 comments on commit 788708f

Please sign in to comment.