/*
* Copyright OpenSearch Contributors
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/
// TODO: call the util functions from wherever applicable.
import {
EuiFlexItem,
EuiText,
EuiIcon,
EuiFlexGroup,
EuiButton,
EuiButtonProps,
EuiToolTip,
EuiLink,
} from '@elastic/eui';
import { isEmpty } from 'lodash';
import React from 'react';
import { ExpressionModal } from '../panels/expression-modal';
import { EMPTY_FIELD_VALUE } from '../ui-constants';
import { LEARN_MORE } from '../constants';
export interface UIProps {
cssClassName: string;
}
export const tableItemsUIProps: UIProps = {
cssClassName: 'table-items',
};
export function renderTextFlexItem(header: string, value: string) {
return (
{header}
{value}
);
}
export function displayBoolean(bool: boolean | undefined) {
return bool ? 'Enabled' : 'Disabled';
}
export function displayArray(array: string[] | undefined) {
return array?.join(', ') || EMPTY_FIELD_VALUE;
}
export function displayObject(object: object | undefined) {
return !isEmpty(object) ? JSON.stringify(object, null, 2) : EMPTY_FIELD_VALUE;
}
export function renderCustomization(reserved: boolean, props: UIProps) {
return (
{reserved ? 'Reserved' : 'Custom'}
);
}
export function truncatedListView(props: UIProps, limit = 3) {
return (items: string[]) => {
// Show - to indicate empty
if (items === undefined || items.length === 0) {
return (
{EMPTY_FIELD_VALUE}
);
}
// If number of items over than limit, truncate and show ...
return (
{items.slice(0, limit).map((item) => (
{item}
))}
{items.length > limit && (
...
)}
);
};
}
export function renderExpression(title: string, expression: object) {
if (isEmpty(expression)) {
return EMPTY_FIELD_VALUE;
}
return ;
}
export const displayHeaderWithTooltip = (columnHeader: string, tooltipText: string) => {
return (
{columnHeader}{' '}
);
};
export function ExternalLinkButton(props: { text: string; href: string } & EuiButtonProps) {
const { text, ...buttonProps } = props;
return (
{props.text}
);
}
export function ExternalLink(props: { href: string }) {
return (
{LEARN_MORE}
);
}