-
Notifications
You must be signed in to change notification settings - Fork 285
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into surface-phoenix-version
* main: fix: display point-cloud errors in the UI for troubleshooting (#525)
- Loading branch information
Showing
6 changed files
with
158 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import React, { createContext, useCallback, useContext } from "react"; | ||
|
||
import { NoticeFn, useNotification } from "@arizeai/components"; | ||
|
||
// Extract the first argument of notify | ||
type NoticeConfig = Parameters<NoticeFn>[0]; | ||
type NoticeConfigWithoutVariant = Omit<NoticeConfig, "variant">; | ||
type NotificationContextType = { | ||
/** | ||
* Send a notification that is visible in any part of the UI | ||
*/ | ||
notify: NoticeFn; | ||
/** | ||
* Convenience function to notify of an error | ||
*/ | ||
notifyError: (notice: NoticeConfigWithoutVariant) => void; | ||
/** | ||
* Convenience function to notify of a success | ||
*/ | ||
notifySuccess: (notice: NoticeConfigWithoutVariant) => void; | ||
}; | ||
|
||
const NotificationContext = createContext<NotificationContextType | null>(null); | ||
|
||
export function NotificationProvider({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const [notify, holder] = useNotification(); | ||
|
||
const notifyError = useCallback( | ||
(notice: NoticeConfigWithoutVariant) => { | ||
notify({ | ||
variant: "danger", | ||
...notice, | ||
}); | ||
}, | ||
[notify] | ||
); | ||
|
||
const notifySuccess = useCallback( | ||
(notice: NoticeConfigWithoutVariant) => { | ||
notify({ | ||
variant: "success", | ||
...notice, | ||
}); | ||
}, | ||
[notify] | ||
); | ||
|
||
return ( | ||
<NotificationContext.Provider | ||
value={{ notify, notifyError, notifySuccess }} | ||
> | ||
{children} | ||
{holder} | ||
</NotificationContext.Provider> | ||
); | ||
} | ||
|
||
export function useGlobalNotification() { | ||
const context = useContext(NotificationContext); | ||
if (context === null) { | ||
throw new Error( | ||
"useGlobalNotification must be used within a NotificationProvider" | ||
); | ||
} | ||
return context; | ||
} | ||
|
||
/** | ||
* Convenience hook to display an error at the global app level | ||
*/ | ||
export function useNotifyError() { | ||
const context = useGlobalNotification(); | ||
return context.notifyError; | ||
} | ||
|
||
/** | ||
* Convenience hook to display a success at the global app level | ||
*/ | ||
export function useNotifySuccess() { | ||
const context = useGlobalNotification(); | ||
return context.notifySuccess; | ||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from "./DatasetsContext"; | ||
export * from "./PointCloudContext"; | ||
export * from "./TimeRangeContext"; | ||
export * from "./NotificationContext"; |
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