text: import { SecurityIcon, UnknownIcon } from '@patternfly/react-icons';
  import { SortByDirection } from '@patternfly/react-table';
  import findIndex from 'lodash/findIndex';
  import propTypes from 'prop-types';
  import React from 'react';
  import { impactColorList, impactList } from './constants';
  
  export const dataShape = propTypes.shape({
      data: propTypes.oneOfType([propTypes.object, propTypes.array]),
      meta: propTypes.object,
      isLoading: propTypes.bool
  });
  
  export function constructParameters(apiProps, allowedParams) {
      if (apiProps) {
          Object.keys(apiProps).forEach(key => (apiProps[key] === undefined || apiProps[key] === '') && delete apiProps[key]);
          const params = allowedParams.map(item => apiProps[item]);
  
          return params;
      }
  
      return [];
  }
  
  export function getImpactDetails(impact) {
      if (Object.keys(impactList).includes(impact)) {
          return {
              title: impactList[impact].title,
              color: impactList[impact].color,
              text: impactList[impact].text,
              titleContent: (
                  <span>
                      <SecurityIcon size="lg" />
                  </span>
              )
          };
      } else {
          return {
              title: 'Unknown',
              color: impactColorList.unknown,
              text: '',
              titleContent: (
                  <span>
                      <UnknownIcon size="lg" />
                  </span>
              )
          };
      }
  }
  
  export const createSortBy = (header, value) => {
      if (value) {
          let direction = value[0] === '-' ? SortByDirection.desc : SortByDirection.asc;
          value = value.replace(/^(-|\+)/, '');
          const index = findIndex(header, item => item.key === value);
          let sort = {
              index,
              direction
          };
          return sort;
      }
  
      return {};
  };
  
  export const handleSortColumn = (key, direction, header, currentSort, apply) => {
      let columnName = header[key].key;
      const useDefault = currentSort && currentSort.substr(1) !== columnName;
      if (direction === SortByDirection.desc || useDefault) {
          columnName = '-' + columnName;
      }
  
      apply({ sort: columnName });
  };
  
  export const updateStateSet = (stateSet, names, value) => {
      [].concat(names).forEach(name => {
          value ? stateSet.add(name) : stateSet.delete(name);
      });
      return stateSet;
  };
  