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

Memory routing to fix JupyterLab extension #429

Merged
merged 1 commit into from
Oct 16, 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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ REACT_APP_STYLE_TYPE=green-accent
REACT_APP_CONTEXT=webapp
REACT_APP_SHOW_AUTH_BUTTON=true
REACT_APP_LOGOUT_PAGE_URL=http://localhost:8080/conda-store/logout?next=/
REACT_APP_ROUTER_TYPE=browser
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since you are adding a new configuration, would it be worth updating the docs? https://conda.store/conda-store-ui/how-tos/configure-ui

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, if we're happy with this, I will update the docs

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems fine, it would appear that the memory setting would only be needed for the JLab extension right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it would be needed for the extension or any context in which the app is not supposed to read or manipulate the URL in the browser address bar

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok I will approve this, but will need an update on the docs.


# If you want to use a version other than the pinned conda-store-server version
# Set the CONDA_STORE_SERVER_VERSION to the package version that you want
Expand Down
15 changes: 12 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { ThemeProvider } from "@mui/material";
import React from "react";
import { Provider } from "react-redux";
import { RouterProvider } from "react-router-dom";

import {
RouterProvider,
createBrowserRouter,
createMemoryRouter
} from "react-router-dom";
import {
IPreferences,
PrefContext,
prefDefault,
prefGlobal
} from "./preferences";
import { router } from "./routes";
import { routes } from "./routes";

import { store } from "./store";
import { condaStoreTheme, grayscaleTheme } from "./theme";

Expand Down Expand Up @@ -64,6 +68,11 @@ export class App<
// }

render(): React.ReactNode {
const router =
this.state.pref.routerType === "memory"
? createMemoryRouter(routes, { initialEntries: ["/"] })
: createBrowserRouter(routes);

return (
<PrefContext.Provider value={this.state.pref}>
<ThemeProvider
Expand Down
20 changes: 19 additions & 1 deletion src/preferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ export interface IPreferences {
styleType: string;
showAuthButton: boolean;
logoutUrl: string;

// routerType - Should the app use the browser's history API for routing, or
// should app routes be handled internally in memory? This is needed for the
// JupyterLab extension because when conda-store-ui is embedded in JupyterLab,
// the URL routes in the browser address bar are for JupyterLab, not for
// conda-store-ui.
routerType: "browser" | "memory";
}

const { condaStoreConfig = {} } =
Expand Down Expand Up @@ -49,7 +56,12 @@ export const prefDefault: Readonly<IPreferences> = {
logoutUrl:
process.env.REACT_APP_LOGOUT_PAGE_URL ??
condaStoreConfig.REACT_APP_LOGOUT_PAGE_URL ??
"http://localhost:8080/conda-store/logout?next=/"
"http://localhost:8080/conda-store/logout?next=/",

routerType:
process.env.REACT_APP_ROUTER_TYPE ??
condaStoreConfig.REACT_APP_ROUTER_TYPE ??
"browser"
};

export class Preferences implements IPreferences {
Expand Down Expand Up @@ -85,6 +97,10 @@ export class Preferences implements IPreferences {
return this._logoutUrl;
}

get routerType() {
return this._routerType;
}

set(pref: IPreferences) {
this._apiUrl = pref.apiUrl;
this._authMethod = pref.authMethod;
Expand All @@ -93,6 +109,7 @@ export class Preferences implements IPreferences {
this._styleType = pref.styleType;
this._showAuthButton = pref.showAuthButton;
this._logoutUrl = pref.logoutUrl;
this._routerType = pref.routerType;
}

private _apiUrl: IPreferences["apiUrl"];
Expand All @@ -102,6 +119,7 @@ export class Preferences implements IPreferences {
private _styleType: IPreferences["styleType"];
private _showAuthButton: IPreferences["showAuthButton"];
private _logoutUrl: IPreferences["logoutUrl"];
private _routerType: IPreferences["routerType"];
}

export const prefGlobal = new Preferences();
Expand Down
6 changes: 3 additions & 3 deletions src/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from "react";
import { createBrowserRouter } from "react-router-dom";

import { PageLayout } from "./layouts";
import { EnvironmentDetails } from "./features/environmentDetails";
Expand All @@ -8,7 +7,8 @@ import { EnvironmentCreate } from "./features/environmentCreate";
/**
* Define URL routes for the single page app
*/
export const router = createBrowserRouter([

export const routes = [
{
path: "/",
element: <PageLayout />,
Expand All @@ -23,4 +23,4 @@ export const router = createBrowserRouter([
}
]
}
]);
];
Loading