node-details-utils.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { NODE_DETAILS_TABLE_COLUMN_WIDTHS } from '../constants/styles';
  2. export function isGenericTable(table) {
  3. return (table.type || (table.get && table.get('type'))) === 'multicolumn-table';
  4. }
  5. export function isPropertyList(table) {
  6. return (table.type || (table.get && table.get('type'))) === 'property-list';
  7. }
  8. export function isNumber(data) {
  9. return data && data.dataType && data.dataType === 'number';
  10. }
  11. /** Whether the value is considered numeric for sorting purposes. */
  12. export function isNumeric(data) {
  13. return data && data.dataType && (data.dataType === 'number' || data.dataType === 'duration');
  14. }
  15. export function isIP(data) {
  16. return data && data.dataType && data.dataType === 'ip';
  17. }
  18. export function genericTableEntryKey(row, column) {
  19. const columnId = column.id || column.get('id');
  20. const rowId = row.id || row.get('id');
  21. return `${rowId}_${columnId}`;
  22. }
  23. export function defaultSortDesc(header) {
  24. return header && isNumber(header);
  25. }
  26. export function getTableColumnsStyles(headers) {
  27. return headers.map(header => ({
  28. textAlign: isNumber(header) ? 'right' : 'left',
  29. // More beauty hacking, ports and counts can only get
  30. // so big, free up WS for other longer fields like IPs!
  31. width: NODE_DETAILS_TABLE_COLUMN_WIDTHS[header.id]
  32. }));
  33. }