2020-06-26 18:43:35 +02:00
|
|
|
/*
|
|
|
|
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
|
|
|
* or more contributor license agreements. Licensed under the Elastic License;
|
|
|
|
* you may not use this file except in compliance with the Elastic License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import './datapanel.scss';
|
|
|
|
import React, { memo, useCallback } from 'react';
|
2020-07-16 09:54:46 +02:00
|
|
|
import { i18n } from '@kbn/i18n';
|
2020-06-26 18:43:35 +02:00
|
|
|
import {
|
|
|
|
EuiText,
|
|
|
|
EuiNotificationBadge,
|
|
|
|
EuiSpacer,
|
|
|
|
EuiAccordion,
|
|
|
|
EuiLoadingSpinner,
|
2020-07-16 09:54:46 +02:00
|
|
|
EuiIconTip,
|
2020-06-26 18:43:35 +02:00
|
|
|
} from '@elastic/eui';
|
2020-12-15 18:23:41 +01:00
|
|
|
import classNames from 'classnames';
|
2020-06-26 18:43:35 +02:00
|
|
|
import { DataPublicPluginStart } from 'src/plugins/data/public';
|
|
|
|
import { IndexPatternField } from './types';
|
|
|
|
import { FieldItem } from './field_item';
|
|
|
|
import { Query, Filter } from '../../../../../src/plugins/data/public';
|
|
|
|
import { DatasourceDataPanelProps } from '../types';
|
|
|
|
import { IndexPattern } from './types';
|
2020-07-02 16:02:30 +02:00
|
|
|
import { ChartsPluginSetup } from '../../../../../src/plugins/charts/public';
|
2020-06-26 18:43:35 +02:00
|
|
|
|
|
|
|
export interface FieldItemSharedProps {
|
|
|
|
core: DatasourceDataPanelProps['core'];
|
|
|
|
data: DataPublicPluginStart;
|
2020-07-02 16:02:30 +02:00
|
|
|
chartsThemeService: ChartsPluginSetup['theme'];
|
2020-06-26 18:43:35 +02:00
|
|
|
indexPattern: IndexPattern;
|
|
|
|
highlight?: string;
|
|
|
|
query: Query;
|
|
|
|
dateRange: DatasourceDataPanelProps['dateRange'];
|
|
|
|
filters: Filter[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface FieldsAccordionProps {
|
|
|
|
initialIsOpen: boolean;
|
|
|
|
onToggle: (open: boolean) => void;
|
|
|
|
id: string;
|
|
|
|
label: string;
|
2020-12-15 18:23:41 +01:00
|
|
|
helpTooltip?: string;
|
2020-06-26 18:43:35 +02:00
|
|
|
hasLoaded: boolean;
|
|
|
|
fieldsCount: number;
|
|
|
|
isFiltered: boolean;
|
|
|
|
paginatedFields: IndexPatternField[];
|
|
|
|
fieldProps: FieldItemSharedProps;
|
|
|
|
renderCallout: JSX.Element;
|
2020-09-24 09:55:32 +02:00
|
|
|
exists: (field: IndexPatternField) => boolean;
|
2020-07-16 09:54:46 +02:00
|
|
|
showExistenceFetchError?: boolean;
|
2020-08-26 09:09:40 +02:00
|
|
|
hideDetails?: boolean;
|
2020-06-26 18:43:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export const InnerFieldsAccordion = function InnerFieldsAccordion({
|
|
|
|
initialIsOpen,
|
|
|
|
onToggle,
|
|
|
|
id,
|
|
|
|
label,
|
2020-12-15 18:23:41 +01:00
|
|
|
helpTooltip,
|
2020-06-26 18:43:35 +02:00
|
|
|
hasLoaded,
|
|
|
|
fieldsCount,
|
|
|
|
isFiltered,
|
|
|
|
paginatedFields,
|
|
|
|
fieldProps,
|
|
|
|
renderCallout,
|
|
|
|
exists,
|
2020-08-26 09:09:40 +02:00
|
|
|
hideDetails,
|
2020-07-16 09:54:46 +02:00
|
|
|
showExistenceFetchError,
|
2020-06-26 18:43:35 +02:00
|
|
|
}: FieldsAccordionProps) {
|
|
|
|
const renderField = useCallback(
|
2020-08-21 20:07:19 +02:00
|
|
|
(field: IndexPatternField) => (
|
2020-08-26 09:09:40 +02:00
|
|
|
<FieldItem
|
|
|
|
{...fieldProps}
|
|
|
|
key={field.name}
|
|
|
|
field={field}
|
2020-09-24 09:55:32 +02:00
|
|
|
exists={exists(field)}
|
2020-08-26 09:09:40 +02:00
|
|
|
hideDetails={hideDetails}
|
|
|
|
/>
|
2020-08-21 20:07:19 +02:00
|
|
|
),
|
2020-08-26 09:09:40 +02:00
|
|
|
[fieldProps, exists, hideDetails]
|
2020-06-26 18:43:35 +02:00
|
|
|
);
|
|
|
|
|
2020-12-15 18:23:41 +01:00
|
|
|
const titleClassname = classNames({
|
|
|
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
|
|
lnsInnerIndexPatternDataPanel__titleTooltip: !!helpTooltip,
|
|
|
|
});
|
|
|
|
|
2020-06-26 18:43:35 +02:00
|
|
|
return (
|
|
|
|
<EuiAccordion
|
|
|
|
initialIsOpen={initialIsOpen}
|
|
|
|
onToggle={onToggle}
|
|
|
|
data-test-subj={id}
|
|
|
|
id={id}
|
|
|
|
buttonContent={
|
|
|
|
<EuiText size="xs">
|
2020-12-15 18:23:41 +01:00
|
|
|
<strong className={titleClassname}>{label}</strong>
|
|
|
|
{!!helpTooltip && (
|
|
|
|
<EuiIconTip
|
|
|
|
aria-label={helpTooltip}
|
|
|
|
type="questionInCircle"
|
|
|
|
color="subdued"
|
|
|
|
size="s"
|
|
|
|
position="right"
|
|
|
|
content={helpTooltip}
|
|
|
|
iconProps={{
|
|
|
|
className: 'eui-alignTop',
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)}
|
2020-06-26 18:43:35 +02:00
|
|
|
</EuiText>
|
|
|
|
}
|
|
|
|
extraAction={
|
2020-07-16 09:54:46 +02:00
|
|
|
showExistenceFetchError ? (
|
|
|
|
<EuiIconTip
|
|
|
|
aria-label={i18n.translate('xpack.lens.indexPattern.existenceErrorAriaLabel', {
|
|
|
|
defaultMessage: 'Existence fetch failed',
|
|
|
|
})}
|
|
|
|
type="alert"
|
|
|
|
color="warning"
|
|
|
|
content={i18n.translate('xpack.lens.indexPattern.existenceErrorLabel', {
|
|
|
|
defaultMessage: "Field information can't be loaded",
|
|
|
|
})}
|
|
|
|
/>
|
|
|
|
) : hasLoaded ? (
|
2020-06-26 18:43:35 +02:00
|
|
|
<EuiNotificationBadge size="m" color={isFiltered ? 'accent' : 'subdued'}>
|
|
|
|
{fieldsCount}
|
|
|
|
</EuiNotificationBadge>
|
|
|
|
) : (
|
|
|
|
<EuiLoadingSpinner size="m" />
|
|
|
|
)
|
|
|
|
}
|
|
|
|
>
|
|
|
|
<EuiSpacer size="s" />
|
|
|
|
{hasLoaded &&
|
|
|
|
(!!fieldsCount ? (
|
2020-12-03 13:28:41 +01:00
|
|
|
<ul className="lnsInnerIndexPatternDataPanel__fieldItems">
|
2020-06-26 18:43:35 +02:00
|
|
|
{paginatedFields && paginatedFields.map(renderField)}
|
2020-12-03 13:28:41 +01:00
|
|
|
</ul>
|
2020-06-26 18:43:35 +02:00
|
|
|
) : (
|
|
|
|
renderCallout
|
|
|
|
))}
|
|
|
|
</EuiAccordion>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const FieldsAccordion = memo(InnerFieldsAccordion);
|