Skip to content

Commit

Permalink
ui: added closable prop for generic notification component
Browse files Browse the repository at this point in the history
addresses reanahub#118
  • Loading branch information
audrium committed Sep 14, 2020
1 parent 5164c0c commit f0e9f52
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions reana-ui/src/components/Notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ import { getError } from "../selectors";

import styles from "./Notification.module.scss";

export default function Notification({ icon, message }) {
export default function Notification({ icon, message, closable }) {
const dispatch = useDispatch();
const error = useSelector(getError);
const timer = useRef(null);

const hide = () => dispatch(clearError);
const visible = message || error ? true : false;

if (visible) {
if (closable && visible) {
clearTimeout(timer.current);
timer.current = setTimeout(() => hide(), 16000);
}
Expand All @@ -37,7 +37,7 @@ export default function Notification({ icon, message }) {
<Message
icon={icon}
header={message || error?.message}
onDismiss={hide}
onDismiss={closable ? hide : null}
size="small"
error
/>
Expand All @@ -49,9 +49,11 @@ export default function Notification({ icon, message }) {
Notification.propTypes = {
icon: PropTypes.string,
message: PropTypes.string,
closable: PropTypes.bool
};

Notification.defaultProps = {
icon: "warning sign",
message: null,
closable: true
};

0 comments on commit f0e9f52

Please sign in to comment.