Sha256: b7ac2dca66b054ec276e3c556353ce434f781e1a7f2f128799f8dbe3d2dbeef5

Contents?: true

Size: 1.29 KB

Versions: 33

Compression:

Stored size: 1.29 KB

Contents

/* eslint-disable camelcase */
import { columns } from './InsightsTableConstants';

export const modifySelectedRows = (hits, selectedIds, showSelectAllAlert) => {
  if (hits.length === 0) return [];

  return hits
    .asMutable()
    .map(({ id, hostname, title, total_risk, has_playbook }) => {
      const disableCheckbox = !has_playbook;
      return {
        cells: [hostname, title, total_risk, has_playbook],
        disableCheckbox,
        id,
        /** The main table checkbox will be seen as selected only if all rows are selected,
         * in this case we need to select also the disabled once and hide it with css */
        selected: selectedIds[id] || (disableCheckbox && showSelectAllAlert),
      };
    });
};

export const getSortColumnIndex = sortBy => {
  let colIndex = 0;
  columns.forEach((col, index) => {
    if (col.sortKey === sortBy) {
      // The checkbox column shifts the data columns by 1;
      colIndex = index + 1;
    }
  });
  return colIndex;
};

export const getPerPageOptions = (urlPerPage, appPerPage) => {
  const initialValues = new Set([5, 10, 15, 25, 50]);
  initialValues.add(appPerPage);
  urlPerPage && initialValues.add(urlPerPage);
  const options = [...initialValues].sort((a, b) => a - b);
  return options.map(value => ({ title: value.toString(), value }));
};

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
foreman_rh_cloud-4.0.24 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-3.0.23 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-4.0.23 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-3.0.22 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-4.0.22 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-4.0.21.1 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-3.0.21.1 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-3.0.21 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-3.0.20 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-3.0.19 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-3.0.18.1 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-3.0.18 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js
foreman_rh_cloud-3.0.17 webpack/InsightsCloudSync/Components/InsightsTable/InsightsTableHelpers.js