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

UI: refactor use widget wrapper #1395

Merged
merged 2 commits into from
Dec 13, 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
32 changes: 16 additions & 16 deletions src/evidently/nbextension/static/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/evidently/ui/assets/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
content="Evidently - ML Monitoring Demo. Hosted example to monitor the performance of a demand forecasting model on a toy dataset."
/>
<title>Evidently - ML Monitoring Demo</title>
<script type="module" crossorigin src="/static/js/index-D461mMJX.js"></script>
<script type="module" crossorigin src="/static/js/index-Bk_zDyHx.js"></script>
<link rel="modulepreload" crossorigin href="/static/js/vendor-C2GWNUp2.js">
<link rel="stylesheet" crossorigin href="/static/css/index-CJbKDbyR.css">
</head>
Expand Down

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

This file was deleted.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import { WidgetRenderer } from '~/widgets/WidgetRenderer'

export interface DashboardContentProps {
widgets: WidgetInfo[]
ItemWrapper?: ({ id, children }: { id: string; children: React.ReactNode }) => React.ReactNode
}

export const DashboardContentWidgets: FunctionComponent<DashboardContentProps> = ({
widgets,
ItemWrapper
}) => (
export const DashboardContentWidgets: FunctionComponent<DashboardContentProps> = ({ widgets }) => (
<>
{widgets.length > 0 &&
widgets.map((wi, idx) => (
<React.Fragment key={wi.id}>{WidgetRenderer(`wi_${idx}`, wi, ItemWrapper)}</React.Fragment>
<React.Fragment key={wi.id}>{WidgetRenderer(`wi_${idx}`, wi)}</React.Fragment>
))}
</>
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ import type { WidgetInfo } from '~/api'
import { DashboardContentWidgets } from '~/components/DashboardContent'

export const DashboardWidgets = ({
widgets,
ItemWrapper
widgets
}: {
widgets: WidgetInfo[]
ItemWrapper?: ({ id, children }: { id: string; children: React.ReactNode }) => React.ReactNode
}) => {
if (widgets.length === 0) {
return (
Expand All @@ -20,7 +18,7 @@ export const DashboardWidgets = ({
return (
<>
<Grid container spacing={3} direction='row' alignItems='stretch'>
<DashboardContentWidgets widgets={widgets} ItemWrapper={ItemWrapper} />
<DashboardContentWidgets widgets={widgets} />
</Grid>
</>
)
Expand Down
13 changes: 13 additions & 0 deletions ui/packages/evidently-ui-lib/src/contexts/WidgetWrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React, { useContext } from 'react'

export type WidgetWrapper = {
WidgetWrapper: ({ id, children }: { id: string; children: React.ReactNode }) => JSX.Element
}

const EmptyWidgetWrapper: WidgetWrapper['WidgetWrapper'] = ({ children }) => <>{children}</>

export const widgetWrapperContext = React.createContext<WidgetWrapper>({
WidgetWrapper: EmptyWidgetWrapper
})

export const useWidgetWrapper = () => useContext(widgetWrapperContext)
Loading