-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add floating notifications for applicable events
- setup floating notification provider - applied floating notifications to all relevant instance actions - applied floating notifications to all relevant cluster actions - applied floating notifications to all relevant profile actions - applied floating notifications to all relevant network actions - applied floating notifications to all relevant storage actions - applied floating notifications to all relevant image actions - applied floating notifications to all relevant operations actions - applied floating notifications to all relevant project actions - applied floating notifications to all relevant settings actions - removed NotificationRowLegacy component - removed NotificationRow from NetworkMap, not needed - added filtering by severity for toast notifications Signed-off-by: Mason Hu <[email protected]>
- Loading branch information
Showing
117 changed files
with
1,732 additions
and
545 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,65 @@ | ||
import React, { | ||
FC, | ||
PropsWithChildren, | ||
useLayoutEffect, | ||
useRef, | ||
useState, | ||
} from "react"; | ||
import { usePrefersReducedMotion } from "util/usePreferReducedMotion"; | ||
|
||
interface Props { | ||
show: boolean; | ||
from: Keyframe; | ||
to: Keyframe; | ||
exitAnimation?: Keyframe[]; | ||
options?: KeyframeAnimationOptions; | ||
className?: string; | ||
} | ||
|
||
const Animate: FC<PropsWithChildren<Props>> = ({ | ||
show, | ||
children, | ||
from, | ||
to, | ||
exitAnimation, | ||
options = { duration: 500, fill: "forwards" }, | ||
className, | ||
}) => { | ||
const containerRef = useRef<HTMLDivElement>(null); | ||
const preferReducedMotion = usePrefersReducedMotion(); | ||
|
||
// This state is used so that we trigger a extra render cycle | ||
// to animate the child component when it is being unmounted | ||
const [removeState, setRemove] = useState(!show); | ||
|
||
useLayoutEffect(() => { | ||
const element = containerRef.current; | ||
if (show) { | ||
setRemove(false); | ||
if (!element || preferReducedMotion) return; | ||
element.animate([from, to], options); | ||
} else { | ||
if (!element) return; | ||
if (preferReducedMotion) { | ||
setRemove(true); | ||
return; | ||
} | ||
const animation = element.animate(exitAnimation || [to, from], options); | ||
animation.onfinish = () => { | ||
setRemove(true); | ||
// This is important, else the next render cycle due to setRemove will cause flickering effect | ||
element.style.display = "none"; | ||
}; | ||
} | ||
}, [show, removeState]); | ||
|
||
return ( | ||
!removeState && ( | ||
<div ref={containerRef} className={className}> | ||
{children} | ||
</div> | ||
) | ||
); | ||
}; | ||
|
||
export default Animate; |
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 was deleted.
Oops, something went wrong.
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,28 @@ | ||
import { Icon } from "@canonical/react-components"; | ||
import { useOperations } from "context/operationsProvider"; | ||
import React, { useState } from "react"; | ||
import { isWidthBelow } from "util/helpers"; | ||
import useEventListener from "@use-it/event-listener"; | ||
import { Link } from "react-router-dom"; | ||
import { pluralize } from "util/instanceBulkActions"; | ||
|
||
const OperationStatus = () => { | ||
const [isSmallScreen, setIsSmallScreen] = useState(false); | ||
const { runningOperations } = useOperations(); | ||
|
||
useEventListener("resize", () => setIsSmallScreen(isWidthBelow(620))); | ||
|
||
let operationsStatus = `${runningOperations.length} ${pluralize("operation", runningOperations.length)} in progress...`; | ||
if (isSmallScreen) { | ||
operationsStatus = `${runningOperations.length} Ops`; | ||
} | ||
|
||
return runningOperations.length ? ( | ||
<div className="operation-status" role="alert"> | ||
<Icon name="status-in-progress-small" className="status-icon" /> | ||
<Link to="ui/operations">{operationsStatus}</Link> | ||
</div> | ||
) : null; | ||
}; | ||
|
||
export default OperationStatus; |
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,67 @@ | ||
import React, { FC } from "react"; | ||
import classnames from "classnames"; | ||
import Version from "./Version"; | ||
import OperationStatus from "./OperationStatus"; | ||
import { useToastNotification } from "context/toastNotificationProvider"; | ||
import { ICONS, Icon } from "@canonical/react-components"; | ||
import { iconLookup, severityOrder } from "util/notifications"; | ||
import useEventListener from "@use-it/event-listener"; | ||
|
||
interface Props { | ||
className?: string; | ||
} | ||
|
||
const StatusBar: FC<Props> = ({ className }) => { | ||
const { toggleListView, notifications, countBySeverity, isListView } = | ||
useToastNotification(); | ||
|
||
useEventListener("keydown", (e: KeyboardEvent) => { | ||
// Close notifications list if Escape pressed | ||
if (e.code === "Escape" && isListView) { | ||
toggleListView(); | ||
} | ||
}); | ||
|
||
const notificationIcons = severityOrder.map((severity) => { | ||
if (countBySeverity[severity]) { | ||
return ( | ||
<Icon | ||
key={severity} | ||
name={iconLookup[severity]} | ||
aria-label={`${severity} notification exists`} | ||
/> | ||
); | ||
} | ||
}); | ||
|
||
const hasNotifications = !!notifications.length; | ||
return ( | ||
<> | ||
<aside | ||
className={classnames("l-status status-bar", className)} | ||
id="status-bar" | ||
> | ||
<Version /> | ||
<div className="status-right-container"> | ||
<OperationStatus /> | ||
{hasNotifications && ( | ||
<button | ||
className={classnames( | ||
"u-no-margin u-no-padding u-no-border expand-button", | ||
{ "button-active": isListView }, | ||
)} | ||
onClick={toggleListView} | ||
aria-label="Expand notifications list" | ||
> | ||
{notificationIcons} | ||
<span className="total-count">{notifications.length}</span> | ||
<Icon name={isListView ? ICONS.chevronDown : ICONS.chevronUp} /> | ||
</button> | ||
)} | ||
</div> | ||
</aside> | ||
</> | ||
); | ||
}; | ||
|
||
export default StatusBar; |
Oops, something went wrong.