@patternfly/react-core#AlertActionLink JavaScript Examples

The following examples show how to use @patternfly/react-core#AlertActionLink. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ibutsu-page.js    From ibutsu-server with MIT License 6 votes vote down vote up
checkVersion() {
    const frontendUrl = window.location.origin;
    HttpClient.get([frontendUrl, 'version.json'], {'v': getDateString()})
      .then(response => HttpClient.handleResponse(response))
      .then((data) => {
        if (data && data.version && (data.version !== this.state.version)) {
          const action = <AlertActionLink onClick={() => { window.location.reload(); }}>Reload</AlertActionLink>;
          this.showNotification('info', 'Ibutsu has been updated', 'A newer version of Ibutsu is available, click reload to get it.', action, true, 'check-version');
        }
      });
  }
Example #2
Source File: NotificationProvider.js    From sed-frontend with Apache License 2.0 5 votes vote down vote up
NotificationProvider = ({ children }) => {
  const [notifications, setNotifications] = useState([]);

  const buildNotificationProps = (variant, message, options) => {
    const notificationKey = uuid();
    const notificationProps = {
      variant: variant,
      message: message,
      key: notificationKey,
      timeout: options?.hasTimeout ?? true,
    };

    if (options && options.alertLinkText && options.alertLinkHref) {
      const linkAttributes = options.alertLinkIsDownload
        ? { download: '' }
        : {};
      const alertLink = (
        <>
          <AlertActionLink>
            <a href={options.alertLinkHref} {...linkAttributes}>
              {options.alertLinkText}
            </a>
          </AlertActionLink>
        </>
      );
      notificationProps.actionLinks = alertLink;
    }

    if (options && options.alertLinkIsDownload && options.alertLinkHref) {
      notificationProps.downloadHref = options.alertLinkHref;
    }

    return notificationProps;
  };

  const addNotification = (variant, message, options) => {
    const newNotificationProps = buildNotificationProps(
      variant,
      message,
      options
    );

    let newNotifications = [...notifications, { ...newNotificationProps }];

    if (options && options.keyOfAlertToReplace) {
      newNotifications = newNotifications.filter(
        (notification) => notification.key !== options.keyOfAlertToReplace
      );
    }

    setNotifications(newNotifications);
    return newNotificationProps.key;
  };

  const removeNotification = (key) => {
    setNotifications(
      notifications.filter((notification) => notification.key !== key)
    );
  };

  const contextValue = {
    notifications,
    addNotification: (variant, message, options) => {
      return addNotification(variant, message, options);
    },
    removeNotification: (key) => removeNotification(key),
  };

  return (
    <NotificationContext.Provider value={contextValue}>
      {children}
    </NotificationContext.Provider>
  );
}