-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI] Get kubeflow namespace from kfp UI (#2655)
* Get kubeflow namespace from kfp UI * Add a react context that makes namespace available anywhere. * Move KFP_FLAGS check to index.tsx * Update index.tsx
- Loading branch information
1 parent
7e327ae
commit 675b1cd
Showing
6 changed files
with
96 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
export enum Deployments { | ||
KUBEFLOW = 'KUBEFLOW', | ||
} | ||
|
||
export const KFP_FLAGS = { | ||
DEPLOYMENT: | ||
// tslint:disable-next-line:no-string-literal | ||
window && window['KFP_FLAGS'] && window['KFP_FLAGS']['DEPLOYMENT'] === Deployments.KUBEFLOW | ||
? Deployments.KUBEFLOW | ||
: undefined, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import React from 'react'; | ||
import { logger } from './Utils'; | ||
|
||
declare global { | ||
interface Window { | ||
// Provided by: | ||
// 1. https://github.com/kubeflow/kubeflow/tree/master/components/centraldashboard#client-side-library | ||
// 2. /frontend/server/server.ts -> KUBEFLOW_CLIENT_PLACEHOLDER | ||
centraldashboard: any; | ||
} | ||
} | ||
|
||
let namespace: string | undefined; | ||
let registeredHandler: undefined | ((namespace: string) => void); | ||
function onNamespaceChanged(handler: (namespace: string) => void) { | ||
registeredHandler = handler; | ||
} | ||
|
||
export function init(): void { | ||
try { | ||
// Init method will invoke the callback with the event handler instance | ||
// and a boolean indicating whether the page is iframed or not | ||
window.centraldashboard.CentralDashboardEventHandler.init((cdeh: any) => { | ||
// Binds a callback that gets invoked anytime the Dashboard's | ||
// namespace is changed | ||
cdeh.onNamespaceSelected = (newNamespace: string) => { | ||
namespace = newNamespace; | ||
if (registeredHandler) { | ||
registeredHandler(namespace); | ||
} | ||
}; | ||
}); | ||
} catch (err) { | ||
logger.error('Failed to initialize central dashboard client', err); | ||
} | ||
} | ||
|
||
const NamespaceContext = React.createContext<string | undefined>(undefined); | ||
export const NamespaceContextConsumer = NamespaceContext.Consumer; | ||
export class NamespaceContextProvider extends React.Component { | ||
state = { | ||
namespace, | ||
}; | ||
componentDidMount() { | ||
onNamespaceChanged(ns => this.setState({ namespace: ns })); | ||
} | ||
render() { | ||
return <NamespaceContext.Provider value={this.state.namespace} {...this.props} />; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters