Sha256: e156618c2d0e1cfd6929985c91ee5ab5979700951c8292ed3fb81ddf49095d78

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

import { STATUS } from 'foremanReact/constants';
import { deepPropsToCamelCase } from 'foremanReact/common/helpers';
import {
  selectAPIStatus,
  selectAPIResponse,
  selectAPIErrorMessage,
} from 'foremanReact/redux/API/APISelectors';

import { HOST_REPORT_REQUEST_KEY } from '../constants';

const selectHostReportResponse = state => {
  const response = deepPropsToCamelCase(
    selectAPIResponse(state, HOST_REPORT_REQUEST_KEY)
  );
  return response;
};

export const selectIsLoading = state => {
  const status = selectHostReportPageStatus(state);
  return !status || status === STATUS.PENDING;
};

const selectHostReportPageStatus = state =>
  selectAPIStatus(state, HOST_REPORT_REQUEST_KEY);

export const selectHasError = state =>
  selectHostReportPageStatus(state) === STATUS.ERROR;

export const selectHostReport = state => {
  if (selectHasError(state)) {
    return [];
  }
  return selectHostReportResponse(state).hostReport;
};

export const selectSearch = state => selectHostReportResponse(state).search;

export const selectPermissions = state =>
  selectHostReportResponse(state).permissions || {};

export const selectErrorMessage = state => {
  if (!selectHasError(state)) return { message: '', details: '' };
  const error = selectHostReportResponse(state).response?.data?.error;

  if (error) return error;

  return {
    message: selectAPIErrorMessage(state, HOST_REPORT_REQUEST_KEY),
    details: '',
  };
};

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
foreman_host_reports-1.0.2 webpack/src/Router/HostReports/ShowPage/ShowPageSelectors.js
foreman_host_reports-1.0.1 webpack/src/Router/HostReports/ShowPage/ShowPageSelectors.js
foreman_host_reports-1.0.0 webpack/src/Router/HostReports/ShowPage/ShowPageSelectors.js
foreman_host_reports-0.0.4 webpack/src/Router/HostReports/ShowPage/ShowPageSelectors.js
foreman_host_reports-0.0.3 webpack/src/Router/HostReports/ShowPage/ShowPageSelectors.js