import classNames from 'classnames';
import React from 'react';
import { ArrayChips } from '../components/data-display/ArrayChips';
import { Formula } from '../components/data-display/Formula';
import { Column, ColumnFormat } from '../components/data-display/SearchUI/types';
import { Tooltip } from '../components/data-display/Tooltip';
import { formatPointGroup } from '../components/data-entry/utils';
import { Link } from '../components/navigation/Link';
import { spaceGroups } from '../constants/spaceGroups';
import { joinUrl } from './navigation';
const emptyCellPlaceholder = '-';
/**
* Get the corresponding value for a row object given a selector string.
* Can select values from keys nested up to 4 levels.
* @param selector string that corresponds to a key or nested group of keys (e.g. 'data.a.b.c.d') in an object.
* @param row object that has the key(s) specified in selector
*/
export const getRowValueFromSelectorString = (selector: string, row: any) => {
try {
const selectors = selector.split('.');
switch (selectors.length) {
case 1:
return row[selectors[0]];
case 2:
return row[selectors[0]][selectors[1]];
case 3:
return row[selectors[0]][selectors[1]][selectors[2]];
case 4:
return row[selectors[0]][selectors[1]][selectors[2]][selectors[3]];
case 5:
return row[selectors[0]][selectors[1]][selectors[2]][selectors[3]][selectors[4]];
default:
return emptyCellPlaceholder;
}
} catch (error) {
return emptyCellPlaceholder;
}
};
/**
* Initialize columns with their proper format function
* The "format" prop should initially be one of the ColumnFormat strings
* which maps to one of the format (or cell) functions defined here.
* FIXED_DECIMAL and SIGNIFICANT_FIGURES both expect another column property "formatArg"
* that will specify how many decimals or figures to apply to the format.
*/
export const initColumns = (columns: Column[], disableRichColumnHeaders?: boolean): Column[] => {
return columns.map((c) => {
/** Make columns sortable by default */
c.sortable = c.sortable !== undefined ? c.sortable : true;
/** Automatically right align numberic columns */
if (
(c.formatType === ColumnFormat.FIXED_DECIMAL ||
c.formatType === ColumnFormat.SIGNIFICANT_FIGURES) &&
c.right !== false
) {
c.right = true;
}
if (disableRichColumnHeaders) {
c.name = c.hideName ? '' : c.title;
} else {
c.name = (