Skip to content

Commit 6c3023d

Browse files
feat(ui): Make CaraML AI placeholder app generic (caraml-dev#110)
* Clean up deprecated prop * Refactor caraml ai app into generic streamlit placeholders * Remove redundant comment * Remove references to streamlit
1 parent 09c363a commit 6c3023d

File tree

8 files changed

+49
-42
lines changed

8 files changed

+49
-42
lines changed

Diff for: api/config/config.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ type UIConfig struct {
119119
StaticPath string `validated:"required"`
120120
IndexPath string `validated:"required"`
121121

122-
ClockworkUIHomepage string `json:"REACT_APP_CLOCKWORK_UI_HOMEPAGE"`
123-
KubeflowUIHomepage string `json:"REACT_APP_KUBEFLOW_UI_HOMEPAGE"`
124-
CaramlAIStreamlitHomepage string `json:"REACT_APP_CARAML_AI_STREAMLIT_HOMEPAGE"`
122+
ClockworkUIHomepage string `json:"REACT_APP_CLOCKWORK_UI_HOMEPAGE"`
123+
KubeflowUIHomepage string `json:"REACT_APP_KUBEFLOW_UI_HOMEPAGE"`
125124

126125
AllowCustomStream bool `json:"REACT_APP_ALLOW_CUSTOM_STREAM"`
127126
AllowCustomTeam bool `json:"REACT_APP_ALLOW_CUSTOM_TEAM"`

Diff for: api/models/v2/application.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package models
22

33
type Application struct {
4-
Name string `json:"name" validate:"required"`
5-
Description string `json:"description"`
6-
Homepage string `json:"homepage"`
7-
Configuration *ApplicationConfig `json:"config" validate:"dive"`
8-
IsProjectAgnostic bool `json:"is_project_agnostic"`
4+
Name string `json:"name" validate:"required"`
5+
Description string `json:"description"`
6+
Homepage string `json:"homepage"`
7+
Configuration *ApplicationConfig `json:"config" validate:"dive"`
8+
IsProjectAgnostic bool `json:"is_project_agnostic"`
9+
PlaceholderPageConfig *PlaceholderPageConfig `json:"placeholder_page_config"`
910
}
1011

1112
type ApplicationConfig struct {
@@ -18,3 +19,7 @@ type NavigationMenuItem struct {
1819
Label string `json:"label"`
1920
Destination string `json:"destination"`
2021
}
22+
23+
type PlaceholderPageConfig struct {
24+
URL string `json:"url"`
25+
}

Diff for: ui/packages/app/src/App.js

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
ErrorBoundary,
44
Login,
55
MlpApiContextProvider,
6+
ApplicationsContextProvider,
67
Page404,
78
Toast
89
} from "@caraml-dev/ui-lib";
@@ -12,7 +13,6 @@ import { Route, Routes } from "react-router-dom";
1213
import AppRoutes from "./AppRoutes";
1314
import { PrivateLayout } from "./PrivateLayout";
1415
import config from "./config";
15-
import { CaraMLAIPage } from "./caraml_ai/CaraMLAIPage";
1616

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

2828
<Route element={<PrivateLayout />}>
29-
<Route path="/*" element={<AppRoutes />} />
29+
<Route path="/*" element={<ApplicationsContextProvider><AppRoutes /></ApplicationsContextProvider>} />
3030
</Route>
3131

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

34-
{
35-
config.CARAML_AI_STREAMLIT_HOMEPAGE &&
36-
<Route element={<PrivateLayout />}>
37-
<Route path="/caraml-ai" element={<CaraMLAIPage />} />
38-
</Route>
39-
}
4034
</Routes>
4135
<Toast />
4236
</AuthProvider>

Diff for: ui/packages/app/src/AppRoutes.js

+29-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
1-
import React from "react";
1+
import React, { useContext } from "react";
22
import { Home, Project } from "./pages";
33
import { ProjectCreation } from "./project_setting/ProjectCreation";
44
import ProjectSetting from "./project_setting/ProjectSetting";
55
import { Navigate, Route, Routes } from "react-router-dom";
6+
import { PlaceholderPage } from "./placeholder_page/PlaceholderPage";
7+
import { ApplicationsContext } from "@caraml-dev/ui-lib";
68

7-
export const AppRoutes = () => (
8-
<Routes>
9-
{/* LANDING */}
10-
<Route index element={<Home />} />
9+
export const AppRoutes = () => {
10+
const { apps, isLoaded } = useContext(ApplicationsContext);
1111

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

21-
{/* DEFAULT */}
22-
<Route path="*" element={<Navigate to="/pages/404" replace={true} />} />
23-
</Routes>
24-
);
19+
{apps?.map(app => !!app.placeholder_page_config &&
20+
<Route key={app.name} path={app.homepage} element={<PlaceholderPage app={app} />} />)
21+
}
22+
23+
<Route path="projects">
24+
{/* PROJECT LANDING PAGE */}
25+
<Route path=":projectId" element={<Project />} />
26+
{/* PROJECT SETTING */}
27+
<Route path=":projectId/settings/*" element={<ProjectSetting />} />
28+
{/* New Project */}
29+
<Route path="create" element={<ProjectCreation />} />
30+
</Route>
31+
32+
{/* DEFAULT */}
33+
<Route path="*" element={<Navigate to="/pages/404" replace={true} />} />
34+
</Routes>
35+
)
36+
};
2537

2638
export default AppRoutes;

Diff for: ui/packages/app/src/config.js

-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ const config = {
3333
),
3434
CLOCKWORK_UI_HOMEPAGE: getEnv("REACT_APP_CLOCKWORK_UI_HOMEPAGE"),
3535
KUBEFLOW_UI_HOMEPAGE: getEnv("REACT_APP_KUBEFLOW_UI_HOMEPAGE"),
36-
CARAML_AI_STREAMLIT_HOMEPAGE: getEnv("REACT_APP_CARAML_AI_STREAMLIT_HOMEPAGE"),
3736
ALLOW_CUSTOM_STREAM:
3837
getEnv("REACT_APP_ALLOW_CUSTOM_STREAM") != null
3938
? getEnv("REACT_APP_ALLOW_CUSTOM_STREAM")

Diff for: ui/packages/app/src/caraml_ai/CaraMLAIPage.js renamed to ui/packages/app/src/placeholder_page/PlaceholderPage.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import React from "react";
22
import { EuiPageTemplate } from "@elastic/eui";
3-
import config from "./../config";
43

5-
export const CaraMLAIPage = () => {
6-
const iframe = `<iframe src=${config.CARAML_AI_STREAMLIT_HOMEPAGE} style="height: 80vh; width: 100%;"></iframe>`
4+
export const PlaceholderPage = ({ app }) => {
5+
const iframe = `<iframe src=${app.placeholder_page_config.url} style="height: 80vh; width: 100%;"></iframe>`
76

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

1918
<EuiPageTemplate.Section paddingSize="none">

Diff for: ui/packages/lib/src/components/header/HeaderUserMenu.js

-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ export const HeaderUserMenu = ({ profileObj, logout, children }) => {
8686
<EuiContextMenuItem
8787
key="log_out"
8888
icon="exit"
89-
toolTipPosition="right"
9089
onClick={logout}>
9190
Log out
9291
</EuiContextMenuItem>

Diff for: ui/packages/lib/src/providers/application/context.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ const ApplicationsContext = React.createContext({
99

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

1414
const currentApp = useMemo(
1515
() => apps.find(a => location.pathname.startsWith(a.homepage)),
1616
[apps, location.pathname]
1717
);
1818

1919
return (
20-
<ApplicationsContext.Provider value={{ currentApp, apps }}>
20+
<ApplicationsContext.Provider value={{ currentApp, apps, isLoaded }}>
2121
{children}
2222
</ApplicationsContext.Provider>
2323
);

0 commit comments

Comments
 (0)