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

feat(ui): Make CaraML AI placeholder app generic #110

Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 2 additions & 3 deletions api/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ type UIConfig struct {
StaticPath string `validated:"required"`
IndexPath string `validated:"required"`

ClockworkUIHomepage string `json:"REACT_APP_CLOCKWORK_UI_HOMEPAGE"`
KubeflowUIHomepage string `json:"REACT_APP_KUBEFLOW_UI_HOMEPAGE"`
CaramlAIStreamlitHomepage string `json:"REACT_APP_CARAML_AI_STREAMLIT_HOMEPAGE"`
leonlnj marked this conversation as resolved.
Show resolved Hide resolved
ClockworkUIHomepage string `json:"REACT_APP_CLOCKWORK_UI_HOMEPAGE"`
KubeflowUIHomepage string `json:"REACT_APP_KUBEFLOW_UI_HOMEPAGE"`

AllowCustomStream bool `json:"REACT_APP_ALLOW_CUSTOM_STREAM"`
AllowCustomTeam bool `json:"REACT_APP_ALLOW_CUSTOM_TEAM"`
Expand Down
15 changes: 10 additions & 5 deletions api/models/v2/application.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package models

type Application struct {
Name string `json:"name" validate:"required"`
Description string `json:"description"`
Homepage string `json:"homepage"`
Configuration *ApplicationConfig `json:"config" validate:"dive"`
IsProjectAgnostic bool `json:"is_project_agnostic"`
Name string `json:"name" validate:"required"`
Description string `json:"description"`
Homepage string `json:"homepage"`
Configuration *ApplicationConfig `json:"config" validate:"dive"`
IsProjectAgnostic bool `json:"is_project_agnostic"`
StreamlitPlaceholderPageConfig *StreamlitPlaceholderPageConfig `json:"streamlit_placeholder_page_config"`
deadlycoconuts marked this conversation as resolved.
Show resolved Hide resolved
}

type ApplicationConfig struct {
Expand All @@ -18,3 +19,7 @@ type NavigationMenuItem struct {
Label string `json:"label"`
Destination string `json:"destination"`
}

type StreamlitPlaceholderPageConfig struct {
deadlycoconuts marked this conversation as resolved.
Show resolved Hide resolved
StreamlitURL string `json:"streamlit_url"`
}
10 changes: 2 additions & 8 deletions ui/packages/app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
ErrorBoundary,
Login,
MlpApiContextProvider,
ApplicationsContextProvider,
Page404,
Toast
} from "@caraml-dev/ui-lib";
Expand All @@ -12,7 +13,6 @@ import { Route, Routes } from "react-router-dom";
import AppRoutes from "./AppRoutes";
import { PrivateLayout } from "./PrivateLayout";
import config from "./config";
import { CaraMLAIPage } from "./caraml_ai/CaraMLAIPage";

const App = () => (
<EuiProvider>
Expand All @@ -26,17 +26,11 @@ const App = () => (
<Route path="/login" element={<Login />} />

<Route element={<PrivateLayout />}>
<Route path="/*" element={<AppRoutes />} />
<Route path="/*" element={<ApplicationsContextProvider><AppRoutes /></ApplicationsContextProvider>} />
</Route>

<Route path="/pages/404" element={<Page404 />} />

{
config.CARAML_AI_STREAMLIT_HOMEPAGE &&
<Route element={<PrivateLayout />}>
<Route path="/caraml-ai" element={<CaraMLAIPage />} />
</Route>
}
</Routes>
<Toast />
</AuthProvider>
Expand Down
46 changes: 29 additions & 17 deletions ui/packages/app/src/AppRoutes.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import React from "react";
import React, { useContext } from "react";
import { Home, Project } from "./pages";
import { ProjectCreation } from "./project_setting/ProjectCreation";
import ProjectSetting from "./project_setting/ProjectSetting";
import { Navigate, Route, Routes } from "react-router-dom";
import { StreamlitPlaceholderPage } from "./streamlit_placeholder_page/StreamlitPlaceholderPage";
import { ApplicationsContext } from "@caraml-dev/ui-lib";

export const AppRoutes = () => (
<Routes>
{/* LANDING */}
<Route index element={<Home />} />
export const AppRoutes = () => {
const { apps, isLoaded } = useContext(ApplicationsContext);

<Route path="projects">
{/* PROJECT LANDING PAGE */}
<Route path=":projectId" element={<Project />} />
{/* PROJECT SETTING */}
<Route path=":projectId/settings/*" element={<ProjectSetting />} />
{/* New Project */}
<Route path="create" element={<ProjectCreation />} />
</Route>
// If the apps have not been loaded yet, we do not render any of the app related routes - the additional streamlit
// apps need to be retrieved from the MLP API v2/applications endpoint first before we generate each route for them.
return isLoaded && (
<Routes>
{/* LANDING */}
<Route index element={<Home />} />

{/* DEFAULT */}
<Route path="*" element={<Navigate to="/pages/404" replace={true} />} />
</Routes>
);
{apps?.map(app => !!app.streamlit_placeholder_page_config &&
<Route key={app.name} path={app.homepage} element={<StreamlitPlaceholderPage app={app} />} />)
}

deadlycoconuts marked this conversation as resolved.
Show resolved Hide resolved
<Route path="projects">
{/* PROJECT LANDING PAGE */}
<Route path=":projectId" element={<Project />} />
{/* PROJECT SETTING */}
<Route path=":projectId/settings/*" element={<ProjectSetting />} />
{/* New Project */}
<Route path="create" element={<ProjectCreation />} />
</Route>

{/* DEFAULT */}
<Route path="*" element={<Navigate to="/pages/404" replace={true} />} />
</Routes>
)
};

export default AppRoutes;
1 change: 0 additions & 1 deletion ui/packages/app/src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const config = {
),
CLOCKWORK_UI_HOMEPAGE: getEnv("REACT_APP_CLOCKWORK_UI_HOMEPAGE"),
KUBEFLOW_UI_HOMEPAGE: getEnv("REACT_APP_KUBEFLOW_UI_HOMEPAGE"),
CARAML_AI_STREAMLIT_HOMEPAGE: getEnv("REACT_APP_CARAML_AI_STREAMLIT_HOMEPAGE"),
ALLOW_CUSTOM_STREAM:
getEnv("REACT_APP_ALLOW_CUSTOM_STREAM") != null
? getEnv("REACT_APP_ALLOW_CUSTOM_STREAM")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React from "react";
import { EuiPageTemplate } from "@elastic/eui";
import config from "./../config";

export const CaraMLAIPage = () => {
const iframe = `<iframe src=${config.CARAML_AI_STREAMLIT_HOMEPAGE} style="height: 80vh; width: 100%;"></iframe>`
export const StreamlitPlaceholderPage = ({ app }) => {
const iframe = `<iframe src=${app.streamlit_placeholder_page_config.streamlit_url} style="height: 80vh; width: 100%;"></iframe>`

function Iframe(props) {
return (<div dangerouslySetInnerHTML={ {__html: props.iframe?props.iframe:""}} />);
Expand All @@ -12,8 +11,8 @@ export const CaraMLAIPage = () => {
<EuiPageTemplate restrictWidth="90%" panelled={false}>
<EuiPageTemplate.Header
bottomBorder={false}
iconType="timelionApp"
pageTitle="CaraML AI"
iconType={app.config.icon}
pageTitle={app.name}
/>

<EuiPageTemplate.Section paddingSize="none">
Expand Down
1 change: 0 additions & 1 deletion ui/packages/lib/src/components/header/HeaderUserMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export const HeaderUserMenu = ({ profileObj, logout, children }) => {
<EuiContextMenuItem
key="log_out"
icon="exit"
toolTipPosition="right"
deadlycoconuts marked this conversation as resolved.
Show resolved Hide resolved
onClick={logout}>
Log out
</EuiContextMenuItem>
Expand Down
4 changes: 2 additions & 2 deletions ui/packages/lib/src/providers/application/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ const ApplicationsContext = React.createContext({

export const ApplicationsContextProvider = ({ children }) => {
const location = useLocation();
const [{ data: apps }] = useMlpApi("/v2/applications", {}, []);
const [{ data: apps, isLoaded }] = useMlpApi("/v2/applications", {}, []);

const currentApp = useMemo(
() => apps.find(a => location.pathname.startsWith(a.homepage)),
[apps, location.pathname]
);

return (
<ApplicationsContext.Provider value={{ currentApp, apps }}>
<ApplicationsContext.Provider value={{ currentApp, apps, isLoaded }}>
{children}
</ApplicationsContext.Provider>
);
Expand Down
Loading