Link to relevant page from status bar warnings / errors (#11140)

* Use hash state for system pages

* Add links to items

* Add stats to other types

* Link on mobile as well

* Use link

* Cleanup using util
This commit is contained in:
Nicolas Mowen
2024-04-28 16:59:03 -06:00
committed by GitHub
parent c2c6113299
commit acf37f9920
7 changed files with 79 additions and 24 deletions

View File

@@ -10,6 +10,7 @@ export type StatusMessage = {
id: string;
text: string;
color?: string;
link?: string;
};
export type StatusMessagesState = {
@@ -27,6 +28,7 @@ type StatusBarMessagesContextValue = {
message: string,
color?: string,
messageId?: string,
link?: string,
) => string;
removeMessage: (key: string, messageId: string) => void;
clearMessages: (key: string) => void;
@@ -43,14 +45,20 @@ export function StatusBarMessagesProvider({
const messages = useMemo(() => messagesState, [messagesState]);
const addMessage = useCallback(
(key: string, message: string, color?: string, messageId?: string) => {
(
key: string,
message: string,
color?: string,
messageId?: string,
link?: string,
) => {
const id = messageId || Date.now().toString();
const msgColor = color || "text-danger";
setMessagesState((prevMessages) => ({
...prevMessages,
[key]: [
...(prevMessages[key] || []),
{ id, text: message, color: msgColor },
{ id, text: message, color: msgColor, link },
],
}));
return id;