Skip to content

Commit

Permalink
[ML] Consolidating header and content formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
qn895 committed Jan 20, 2021
1 parent 9632ad8 commit b925e59
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@

import React, { FC, useMemo } from 'react';

import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { EuiFlexItem } from '@elastic/eui';
import { Feature, Point } from 'geojson';
import type { FieldDataRowProps } from '../../../../stats_table/types/field_data_row';
import { DocumentStatsTable } from '../../../../stats_table/components/field_data_expanded_row/document_stats';
import { TopValues } from '../../../../index_based/components/field_data_row/top_values';
import { MlEmbeddedMapComponent } from '../../../../../components/ml_embedded_map';
import { convertWKTGeoToLonLat, getGeoPointsLayer } from './format_utils';
import { ExpandedRowContent } from '../../../../stats_table/components/field_data_expanded_row/expanded_row_content';

export const DEFAULT_GEO_REGEX = RegExp('(?<lat>.+) (?<lon>.+)');

Expand Down Expand Up @@ -58,7 +59,7 @@ export const GeoPointContent: FC<FieldDataRowProps> = ({ config }) => {
}
}, [config]);
return (
<EuiFlexGroup data-test-subj={'mlDVGeoPointContent'} gutterSize={'xl'}>
<ExpandedRowContent dataTestSubj={'mlDVGeoPointContent'}>
<DocumentStatsTable config={config} />
{formattedResults && Array.isArray(formattedResults.stats!.topValues) && (
<EuiFlexItem>
Expand All @@ -73,6 +74,6 @@ export const GeoPointContent: FC<FieldDataRowProps> = ({ config }) => {
<MlEmbeddedMapComponent layerList={formattedResults.layerList} />
</EuiFlexItem>
)}
</EuiFlexGroup>
</ExpandedRowContent>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { FC, useEffect, useState } from 'react';

import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { EuiFlexItem } from '@elastic/eui';
import { ExamplesList } from '../../../index_based/components/field_data_row/examples_list';
import { FieldVisConfig } from '../../../stats_table/types';
import { IndexPattern } from '../../../../../../../../../src/plugins/data/common/index_patterns/index_patterns';
Expand All @@ -18,6 +18,7 @@ import { ES_GEO_FIELD_TYPE } from '../../../../../../../maps/common/constants';
import { LayerDescriptor } from '../../../../../../../maps/common/descriptor_types';
import { useMlKibana } from '../../../../contexts/kibana';
import { DocumentStatsTable } from '../../../stats_table/components/field_data_expanded_row/document_stats';
import { ExpandedRowContent } from '../../../stats_table/components/field_data_expanded_row/expanded_row_content';

export const GeoPointContent: FC<{
config: FieldVisConfig;
Expand Down Expand Up @@ -61,7 +62,7 @@ export const GeoPointContent: FC<{

if (stats?.examples === undefined) return null;
return (
<EuiFlexGroup data-test-subj={'mlDVIndexBasedMapContent'} gutterSize={'xl'}>
<ExpandedRowContent dataTestSubj={'mlDVIndexBasedMapContent'}>
<DocumentStatsTable config={config} />

<EuiFlexItem>
Expand All @@ -70,6 +71,6 @@ export const GeoPointContent: FC<{
<EuiFlexItem className={'mlDataVisualizerMapWrapper'}>
<MlEmbeddedMapComponent layerList={layerList} />
</EuiFlexItem>
</EuiFlexGroup>
</ExpandedRowContent>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
import classNames from 'classnames';
import { kibanaFieldFormat } from '../../../../../formatters/kibana_field_format';
import { roundToDecimalPlace } from '../../../../../formatters/round_to_decimal_place';
import { ExpandedRowFieldHeader } from '../../../../stats_table/components/expanded_row_field_header';

interface Props {
stats: any;
Expand Down Expand Up @@ -46,51 +47,62 @@ export const TopValues: FC<Props> = ({ stats, fieldFormat, barColor, compressed
} = stats;
const progressBarMax = isTopValuesSampled === true ? topValuesSampleSize : count;
return (
<div data-test-subj="mlFieldDataTopValues" className={'mlFieldDataTopValuesContainer'}>
{Array.isArray(topValues) &&
topValues.map((value: any) => (
<EuiFlexGroup gutterSize="xs" alignItems="center" key={value.key}>
<EuiFlexItem
grow={false}
className={classNames(
'eui-textTruncate',
'mlTopValuesValueLabelContainer',
`mlTopValuesValueLabelContainer--${compressed === true ? 'small' : 'large'}`
)}
>
<EuiToolTip content={kibanaFieldFormat(value.key, fieldFormat)} position="right">
<EuiText size="xs" textAlign={'right'} color="subdued">
{kibanaFieldFormat(value.key, fieldFormat)}
<EuiFlexItem data-test-subj={'mlTopValues'}>
<ExpandedRowFieldHeader>
<FormattedMessage id="xpack.ml.fieldDataCard.topValuesLabel" defaultMessage="Top values" />
</ExpandedRowFieldHeader>

<div data-test-subj="mlFieldDataTopValues" className={'mlFieldDataTopValuesContainer'}>
{Array.isArray(topValues) &&
topValues.map((value: any) => (
<EuiFlexGroup gutterSize="xs" alignItems="center" key={value.key}>
<EuiFlexItem
grow={false}
className={classNames(
'eui-textTruncate',
'mlTopValuesValueLabelContainer',
`mlTopValuesValueLabelContainer--${compressed === true ? 'small' : 'large'}`
)}
>
<EuiToolTip content={kibanaFieldFormat(value.key, fieldFormat)} position="right">
<EuiText size="xs" textAlign={'right'} color="subdued">
{kibanaFieldFormat(value.key, fieldFormat)}
</EuiText>
</EuiToolTip>
</EuiFlexItem>
<EuiFlexItem data-test-subj="mlFieldDataTopValueBar">
<EuiProgress
value={value.doc_count}
max={progressBarMax}
color={barColor}
size="m"
/>
</EuiFlexItem>
<EuiFlexItem
grow={false}
className={classNames('eui-textTruncate', 'mlTopValuesPercentLabelContainer')}
>
<EuiText size="xs" textAlign="left" color="subdued">
{getPercentLabel(value.doc_count, progressBarMax)}
</EuiText>
</EuiToolTip>
</EuiFlexItem>
<EuiFlexItem data-test-subj="mlFieldDataTopValueBar">
<EuiProgress value={value.doc_count} max={progressBarMax} color={barColor} size="m" />
</EuiFlexItem>
<EuiFlexItem
grow={false}
className={classNames('eui-textTruncate', 'mlTopValuesPercentLabelContainer')}
>
<EuiText size="xs" textAlign="left" color="subdued">
{getPercentLabel(value.doc_count, progressBarMax)}
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
))}
{isTopValuesSampled === true && (
<Fragment>
<EuiSpacer size="xs" />
<EuiText size="xs" textAlign={'left'}>
<FormattedMessage
id="xpack.ml.fieldDataCard.topValues.calculatedFromSampleDescription"
defaultMessage="Calculated from sample of {topValuesSamplerShardSize} documents per shard"
values={{
topValuesSamplerShardSize,
}}
/>
</EuiText>
</Fragment>
)}
</div>
</EuiFlexItem>
</EuiFlexGroup>
))}
{isTopValuesSampled === true && (
<Fragment>
<EuiSpacer size="xs" />
<EuiText size="xs" textAlign={'left'}>
<FormattedMessage
id="xpack.ml.fieldDataCard.topValues.calculatedFromSampleDescription"
defaultMessage="Calculated from sample of {topValuesSamplerShardSize} documents per shard"
values={{
topValuesSamplerShardSize,
}}
/>
</EuiText>
</Fragment>
)}
</div>
</EuiFlexItem>
);
};
Original file line number Diff line number Diff line change
@@ -1 +1,7 @@
@import 'number_content';

.mlDataVisualizerExpandedRow {
@include euiBreakpoint('xs', 's', 'm', '') {
flex-direction: column;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React, { FC, ReactNode, useMemo } from 'react';
import { EuiBasicTable, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui';
import { EuiBasicTable, EuiFlexItem, EuiSpacer } from '@elastic/eui';
import { Axis, BarSeries, Chart, Settings } from '@elastic/charts';

import { FormattedMessage } from '@kbn/i18n/react';
Expand All @@ -16,6 +16,7 @@ import { getTFPercentage } from '../../utils';
import { roundToDecimalPlace } from '../../../../formatters/round_to_decimal_place';
import { useDataVizChartTheme } from '../../hooks';
import { DocumentStatsTable } from './document_stats';
import { ExpandedRowContent } from './expanded_row_content';

function getPercentLabel(value: number): string {
if (value === 0) {
Expand Down Expand Up @@ -85,7 +86,7 @@ export const BooleanContent: FC<FieldDataRowProps> = ({ config }) => {
);

return (
<EuiFlexGroup data-test-subj={'mlDVBooleanContent'} gutterSize={'xl'}>
<ExpandedRowContent dataTestSubj={'mlDVBooleanContent'}>
<DocumentStatsTable config={config} />

<EuiFlexItem className={'mlDataVisualizerSummaryTableWrapper'}>
Expand Down Expand Up @@ -138,6 +139,6 @@ export const BooleanContent: FC<FieldDataRowProps> = ({ config }) => {
/>
</Chart>
</EuiFlexItem>
</EuiFlexGroup>
</ExpandedRowContent>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import React, { FC, ReactNode } from 'react';
import { EuiBasicTable, EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { EuiBasicTable, EuiFlexItem } from '@elastic/eui';
// @ts-ignore
import { formatDate } from '@elastic/eui/lib/services/format';
import { FormattedMessage } from '@kbn/i18n/react';
Expand All @@ -14,6 +14,7 @@ import { i18n } from '@kbn/i18n';
import type { FieldDataRowProps } from '../../types/field_data_row';
import { ExpandedRowFieldHeader } from '../expanded_row_field_header';
import { DocumentStatsTable } from './document_stats';
import { ExpandedRowContent } from './expanded_row_content';
const TIME_FORMAT = 'MMM D YYYY, HH:mm:ss.SSS';
interface SummaryTableItem {
function: string;
Expand Down Expand Up @@ -66,7 +67,7 @@ export const DateContent: FC<FieldDataRowProps> = ({ config }) => {
];

return (
<EuiFlexGroup data-test-subj={'mlDVDateContent'} gutterSize={'xl'}>
<ExpandedRowContent dataTestSubj={'mlDVDateContent'}>
<DocumentStatsTable config={config} />
<EuiFlexItem className={'mlDataVisualizerSummaryTableWrapper'}>
<ExpandedRowFieldHeader>{summaryTableTitle}</ExpandedRowFieldHeader>
Expand All @@ -80,6 +81,6 @@ export const DateContent: FC<FieldDataRowProps> = ({ config }) => {
tableLayout="auto"
/>
</EuiFlexItem>
</EuiFlexGroup>
</ExpandedRowContent>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* 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 React, { FC, ReactNode } from 'react';
import { EuiFlexGroup } from '@elastic/eui';

interface Props {
children: ReactNode;
dataTestSubj: string;
}
export const ExpandedRowContent: FC<Props> = ({ children, dataTestSubj }) => {
return (
<EuiFlexGroup
data-test-subj={dataTestSubj}
gutterSize={'xl'}
className={'mlDataVisualizerExpandedRow'}
>
{children}
</EuiFlexGroup>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
*/

import React, { FC } from 'react';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';

import { FormattedMessage } from '@kbn/i18n/react';

import type { FieldDataRowProps } from '../../types/field_data_row';
import { TopValues } from '../../../index_based/components/field_data_row/top_values';
import { ExpandedRowFieldHeader } from '../expanded_row_field_header';
import { DocumentStatsTable } from './document_stats';
import { ExpandedRowContent } from './expanded_row_content';

export const IpContent: FC<FieldDataRowProps> = ({ config }) => {
const { stats } = config;
Expand All @@ -22,17 +18,9 @@ export const IpContent: FC<FieldDataRowProps> = ({ config }) => {
const fieldFormat = 'fieldFormat' in config ? config.fieldFormat : undefined;

return (
<EuiFlexGroup gutterSize={'xl'}>
<ExpandedRowContent dataTestSubj={'mlDVIPContent'}>
<DocumentStatsTable config={config} />
<EuiFlexItem>
<ExpandedRowFieldHeader>
<FormattedMessage
id="xpack.ml.fieldDataCard.cardIp.topValuesLabel"
defaultMessage="Top values"
/>
</ExpandedRowFieldHeader>
<TopValues stats={stats} fieldFormat={fieldFormat} barColor="secondary" />
</EuiFlexItem>
</EuiFlexGroup>
<TopValues stats={stats} fieldFormat={fieldFormat} barColor="secondary" />
</ExpandedRowContent>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,20 @@
*/

import React, { FC } from 'react';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import type { FieldDataRowProps } from '../../types/field_data_row';
import { TopValues } from '../../../index_based/components/field_data_row/top_values';
import { ExpandedRowFieldHeader } from '../expanded_row_field_header';
import { DocumentStatsTable } from './document_stats';
import { ExpandedRowContent } from './expanded_row_content';

export const KeywordContent: FC<FieldDataRowProps> = ({ config }) => {
const { stats } = config;
const fieldFormat = 'fieldFormat' in config ? config.fieldFormat : undefined;

return (
<EuiFlexGroup data-test-subj={'mlDVKeywordContent'} gutterSize={'xl'}>
<ExpandedRowContent dataTestSubj={'mlDVKeywordContent'}>
<DocumentStatsTable config={config} />

<EuiFlexItem>
<ExpandedRowFieldHeader>
<FormattedMessage
id="xpack.ml.fieldDataCard.cardKeyword.topValuesLabel"
defaultMessage="Top values"
/>
</ExpandedRowFieldHeader>
<TopValues stats={stats} fieldFormat={fieldFormat} barColor="secondary" />
</EuiFlexItem>
</EuiFlexGroup>
<TopValues stats={stats} fieldFormat={fieldFormat} barColor="secondary" />
</ExpandedRowContent>
);
};
Loading

0 comments on commit b925e59

Please sign in to comment.