ManageIQ/manageiq-ui-classic

View on GitHub
app/javascript/components/refresh-data-notification.jsx

Summary

Maintainability
A
2 hrs
Test Coverage
import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import RefreshNotifications from './refresh-notifications';
import { http } from '../http_api';

const RefreshDataNotification = ({
  providerId, apiUrl,
}) => {
  const [data, setCardData] = useState({ loading: true });

  useEffect(() => {
    const url = `/${apiUrl}/${providerId}`;
    http.get(url)
      .then((response) => {
        setCardData({
          loading: false,
          status: response.data,
        });
      });
  }, []);

  if (data.loading || (!data.status.last_refresh.stale && data.status.last_refresh.status === 'success')) return null;
  return (
    <RefreshNotifications status={data.status} />
  );
};
RefreshDataNotification.propTypes = {
  apiUrl: PropTypes.string.isRequired,
  providerId: PropTypes.string.isRequired,
};

export default RefreshDataNotification;