import { kebabCase, startCase } from 'lodash';
import React from 'react';
import { AccountTag } from '../../account';
import type { IInstanceCounts } from '../../domain';
import { HealthCounts } from '../../healthCounts';
import { Spinner } from '../../widgets';
export interface ISearchColumn {
key: string;
label?: string;
notSortable?: boolean;
scopeField?: boolean;
}
/****** Layout Renderers ******/
export class SearchTableHeader extends React.Component {
public render() {
return
{this.props.children}
;
}
}
export class SearchTableRow extends React.Component {
public render() {
return {this.props.children}
;
}
}
export class SearchTableBody extends React.Component {
public render() {
return {this.props.children}
;
}
}
/****** Cell Renderers ******/
const colClass = (key: string) => `col-${kebabCase(key)}`;
export class HeaderCell extends React.Component<{ col: ISearchColumn }> {
public render() {
const { col } = this.props;
return {col.label || startCase(col.key)}
;
}
}
export interface ICellRendererProps {
item: any;
col: ISearchColumn;
defaultValue?: string;
}
export class BasicCell extends React.Component {
public render() {
const { item, col, defaultValue, children } = this.props;
return {children || item[col.key] || defaultValue}
;
}
}
export class HrefCell extends React.Component {
public render() {
const { item, col } = this.props;
return (
);
}
}
export class AccountCell extends React.Component {
public render() {
const { item, col } = this.props;
const value: string | string[] = item[col.key];
if (!value) {
return -
;
}
const accounts = (Array.isArray(value) ? value : value.split(',')).sort();
return (
{accounts.map((account: string) => (
))}
);
}
}
export class HealthCountsCell extends React.Component {
private cellContent(instanceCounts: IInstanceCounts) {
switch (instanceCounts) {
case undefined:
return ;
case null:
return ?;
default:
return ;
}
}
public render() {
const { item, col } = this.props;
return {this.cellContent(item[col.key])}
;
}
}