Skip to content

Commit

Permalink
[ML] Add responsive layout to Index data visualizer, fix doc count ch…
Browse files Browse the repository at this point in the history
…art margin (#147137)

## Summary

This PR addresses #137257 and
better handles the layout when the screen width decreases. Changes
include:
- The css is now updating based on the body content width (which
window's width - side bar navigation's width).
- The link cards are shown in the bottom instead of on the right side
when the content width is smaller
- Refresh button will only show the refresh icon when the size is small
- Fix the doc count chart margin too big causing the chart 
- Fix wide time range display with sparse data

For reviewers:
- **kibana-design**: 2 `.scss` files were deleted

Before

After
<img width="1223" alt="Screen Shot 2022-12-06 at 14 31 27"
src="https://user-images.githubusercontent.com/43350163/206016842-f884ee1f-eb60-4c83-9ad3-2fd0f7c90005.png">


### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces&mdash;unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes&mdash;Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
qn895 and kibanamachine authored Dec 22, 2022
1 parent 3a5f562 commit 602b6d6
Show file tree
Hide file tree
Showing 21 changed files with 300 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { dataVisualizerRefresh$ } from '../../../index_data_visualizer/services/
import { useUrlState } from '../../util/url_state';

const DEFAULT_REFRESH_INTERVAL_MS = 5000;
const DATE_PICKER_MAX_WIDTH = 540;

interface TimePickerQuickRange {
from: string;
Expand Down Expand Up @@ -69,10 +70,11 @@ function updateLastRefresh(timeRange?: OnRefreshProps) {
}

// FIXME: Consolidate this component with ML and AIOps's component
export const DatePickerWrapper: FC<{ isAutoRefreshOnly?: boolean; showRefresh?: boolean }> = ({
isAutoRefreshOnly,
showRefresh,
}) => {
export const DatePickerWrapper: FC<{
isAutoRefreshOnly?: boolean;
showRefresh?: boolean;
compact?: boolean;
}> = ({ isAutoRefreshOnly, showRefresh, compact = false }) => {
const {
services,
notifications: { toasts },
Expand Down Expand Up @@ -242,9 +244,18 @@ export const DatePickerWrapper: FC<{ isAutoRefreshOnly?: boolean; showRefresh?:
<EuiFlexGroup
gutterSize="s"
alignItems="center"
className="mlNavigationMenu__datePickerWrapper"
data-test-subj="mlNavigationMenuDatePickerWrapper"
>
<EuiFlexItem grow={false}>
<EuiFlexItem
grow={false}
css={
compact
? {
maxWidth: DATE_PICKER_MAX_WIDTH,
}
: null
}
>
<EuiSuperDatePicker
start={time.from}
end={time.to}
Expand All @@ -257,6 +268,7 @@ export const DatePickerWrapper: FC<{ isAutoRefreshOnly?: boolean; showRefresh?:
recentlyUsedRanges={recentlyUsedRanges}
dateFormat={dateFormat}
commonlyUsedRanges={commonlyUsedRanges}
updateButtonProps={{ iconOnly: compact }}
/>
</EuiFlexItem>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, { FC, useCallback, useMemo } from 'react';
import { i18n } from '@kbn/i18n';
import {
Axis,
BarSeries,
HistogramBarSeries,
BrushEndListener,
Chart,
ElementClickListener,
Expand All @@ -22,7 +22,7 @@ import {
import moment from 'moment';
import { IUiSettingsClient } from '@kbn/core/public';
import { MULTILAYER_TIME_AXIS_STYLE } from '@kbn/charts-plugin/common';
import { EuiLoadingSpinner, EuiFlexItem } from '@elastic/eui';
import { EuiFlexGroup, EuiLoadingSpinner, EuiFlexItem } from '@elastic/eui';
import { useDataVisualizerKibana } from '../../../../kibana_context';

export interface DocumentCountChartPoint {
Expand Down Expand Up @@ -137,8 +137,9 @@ export const DocumentCountChart: FC<Props> = ({
const timeZone = getTimezone(uiSettings);

return (
<div
style={{ width: width ?? '100%', height: 120, display: 'flex', alignItems: 'center' }}
<EuiFlexGroup
alignItems="center"
css={{ width: width ?? '100%' }}
data-test-subj="dataVisualizerDocumentCountChart"
>
{loading ? (
Expand All @@ -147,6 +148,7 @@ export const DocumentCountChart: FC<Props> = ({
<Chart
size={{
width: '100%',
height: 120,
}}
>
<Settings
Expand All @@ -161,11 +163,13 @@ export const DocumentCountChart: FC<Props> = ({
position={Position.Bottom}
showOverlappingTicks={true}
tickFormat={(value) => xAxisFormatter.convert(value)}
// temporary fix to reduce horizontal chart margin until fixed in Elastic Charts itself
labelFormat={useLegacyTimeAxis ? undefined : () => ''}
timeAxisLayerCount={useLegacyTimeAxis ? 0 : 2}
style={useLegacyTimeAxis ? {} : MULTILAYER_TIME_AXIS_STYLE}
/>
<Axis id="left" position={Position.Left} />
<BarSeries
<HistogramBarSeries
id={SPEC_ID}
name={seriesName}
xScaleType={ScaleType.Time}
Expand All @@ -174,9 +178,10 @@ export const DocumentCountChart: FC<Props> = ({
yAccessors={['value']}
data={adjustedChartPoints}
timeZone={timeZone}
yNice
/>
</Chart>
)}
</div>
</EuiFlexGroup>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const FieldCountPanel: FC<Props> = ({
data-test-subj="dataVisualizerFieldCountPanel"
responsive={false}
className="dvFieldCount__panel"
wrap
>
<TotalFieldsCount fieldsCountStats={fieldsCountStats} />
<MetricFieldsCount metricsStats={metricsStats} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export const FieldsStatsGrid: FC<Props> = ({ results }) => {
gutterSize="xs"
style={{ marginLeft: 4 }}
data-test-subj="dataVisualizerFieldCountPanel"
responsive={true}
>
<TotalFieldsCount fieldsCountStats={fieldsCountStats} />
<MetricFieldsCount metricsStats={metricsStats} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
EuiPanel,
EuiLink,
} from '@elastic/eui';
import { useCurrentEuiTheme } from '../../hooks/use_current_eui_theme';

export interface LinkCardProps {
icon: IconType;
Expand All @@ -41,6 +42,8 @@ export const LinkCard: FC<LinkCardProps> = ({
isDisabled,
'data-test-subj': dataTestSubj,
}) => {
const euiTheme = useCurrentEuiTheme();

const linkHrefAndOnClickProps = {
...(href ? { href } : {}),
...(onClick ? { onClick } : {}),
Expand All @@ -62,10 +65,10 @@ export const LinkCard: FC<LinkCardProps> = ({
color="subdued"
{...linkHrefAndOnClickProps}
>
<EuiFlexGroup gutterSize="l" responsive={true}>
<EuiFlexItem grow={false} style={{ paddingTop: '8px' }}>
<EuiFlexGroup gutterSize="s" responsive={true}>
<EuiFlexItem grow={false} css={{ paddingTop: euiTheme.euiSizeXS }}>
{typeof icon === 'string' ? (
<EuiIcon size="xl" type={icon} aria-label={iconAreaLabel} />
<EuiIcon size="m" type={icon} aria-label={iconAreaLabel} />
) : (
icon
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import {
EuiPopoverTitle,
EuiSpacer,
} from '@elastic/eui';
import React, { FC, ReactNode, useEffect, useMemo, useState } from 'react';
import React, { FC, ReactNode, useEffect, useState } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { euiDarkVars as euiThemeDark, euiLightVars as euiThemeLight } from '@kbn/ui-theme';
import { useDataVisualizerKibana } from '../../../kibana_context';
import type { SerializedStyles } from '@emotion/react';
import { css } from '@emotion/react';
import { useCurrentEuiTheme } from '../../hooks/use_current_eui_theme';

export interface Option {
name?: string | ReactNode;
Expand All @@ -27,6 +28,8 @@ export interface Option {
disabled?: boolean;
}

const SELECT_PICKER_HEIGHT = '250px';

const NoFilterItems = () => {
return (
<div className="euiFilterSelect__note">
Expand All @@ -44,23 +47,19 @@ const NoFilterItems = () => {
);
};

export function useCurrentEuiTheme() {
const { services } = useDataVisualizerKibana();
const uiSettings = services.uiSettings;
return useMemo(
() => (uiSettings.get('theme:darkMode') ? euiThemeDark : euiThemeLight),
[uiSettings]
);
interface MultiSelectPickerStyles {
filterGroup?: SerializedStyles;
filterItemContainer?: SerializedStyles;
}

export const MultiSelectPicker: FC<{
options: Option[];
onChange?: (items: string[]) => void;
title?: string;
checkedOptions: string[];
dataTestSubj: string;
postfix?: React.ReactElement;
}> = ({ options, onChange, title, checkedOptions, dataTestSubj, postfix }) => {
cssStyles?: MultiSelectPickerStyles;
}> = ({ options, onChange, title, checkedOptions, dataTestSubj, postfix, cssStyles }) => {
const euiTheme = useCurrentEuiTheme();

const [items, setItems] = useState<Option[]>(options);
Expand Down Expand Up @@ -114,7 +113,7 @@ export const MultiSelectPicker: FC<{
);

return (
<EuiFilterGroup data-test-subj={dataTestSubj} style={{ marginLeft: 8 }}>
<EuiFilterGroup data-test-subj={dataTestSubj} css={cssStyles?.filterGroup}>
<EuiPopover
ownFocus
data-test-subj={`${dataTestSubj}-popover`}
Expand All @@ -130,7 +129,15 @@ export const MultiSelectPicker: FC<{
data-test-subj={`${dataTestSubj}-searchInput`}
/>
</EuiPopoverTitle>
<div style={{ maxHeight: 250, overflow: 'auto' }}>
<div
css={
cssStyles?.filterItemContainer ??
css`
max-height: ${SELECT_PICKER_HEIGHT};
overflow: auto;
`
}
>
{Array.isArray(items) && items.length > 0 ? (
items.map((item, index) => {
const checked =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

.dvFieldCount__item {
max-width: 300px;
min-width: 300px;
min-width: 200px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export const DataVisualizerTable = <T extends DataVisualizerTableItem>({
);
const [showDistributions, setShowDistributions] = useState<boolean>(showPreviewByDefault ?? true);
const [dimensions, setDimensions] = useState(calculateTableColumnsDimensions());
const [tableWidth, setTableWidth] = useState<number>(1400);

const toggleExpandAll = useCallback(
(shouldExpandAll: boolean) => {
Expand All @@ -109,10 +108,9 @@ export const DataVisualizerTable = <T extends DataVisualizerTableItem>({
throttle((e: { width: number; height: number }) => {
// When window or table is resized,
// update the column widths and other settings accordingly
setTableWidth(e.width);
setDimensions(calculateTableColumnsDimensions(e.width));
}, 500),
[tableWidth]
[]
);

const toggleShowDistribution = useCallback(() => {
Expand All @@ -138,6 +136,8 @@ export const DataVisualizerTable = <T extends DataVisualizerTableItem>({
const columns = useMemo(() => {
const expanderColumn: EuiTableComputedColumnType<DataVisualizerTableItem> = {
name:
// EUI will automatically show an expander button when table is mobile view (where width <700)
// so we need to not render any addition button
dimensions.breakPoint !== 'small' ? (
<EuiButtonIcon
data-test-subj={`dataVisualizerToggleDetailsForAllRowsButton ${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
*/

import d3 from 'd3';
import { useMemo } from 'react';
import { euiLightVars as euiThemeLight, euiDarkVars as euiThemeDark } from '@kbn/ui-theme';

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

import { useDataVisualizerKibana } from '../../../../kibana_context';
import { useCurrentEuiTheme } from '../../../hooks/use_current_eui_theme';

/**
* Custom color scale factory that takes the amount of feature influencers
Expand Down Expand Up @@ -159,7 +158,7 @@ export const useColorRange = (
colorRangeScale = COLOR_RANGE_SCALE.LINEAR,
featureCount = 1
) => {
const { euiTheme } = useCurrentEuiTheme();
const euiTheme = useCurrentEuiTheme();

const colorRanges: Record<COLOR_RANGE, string[]> = {
[COLOR_RANGE.BLUE]: [
Expand Down Expand Up @@ -197,13 +196,3 @@ export const useColorRange = (
};

export type EuiThemeType = typeof euiThemeLight | typeof euiThemeDark;

export function useCurrentEuiTheme() {
const {
services: { uiSettings },
} = useDataVisualizerKibana();
return useMemo(
() => ({ euiTheme: uiSettings.get('theme:darkMode') ? euiThemeDark : euiThemeLight }),
[uiSettings]
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import type { PartialTheme } from '@elastic/charts';
import { useMemo } from 'react';
import { useCurrentEuiTheme } from './use_color_range';
import { useCurrentEuiTheme } from '../../../hooks/use_current_eui_theme';
export const useDataVizChartTheme = (): PartialTheme => {
const { euiTheme } = useCurrentEuiTheme();
const euiTheme = useCurrentEuiTheme();
const chartTheme = useMemo<PartialTheme>(() => {
const AREA_SERIES_COLOR = euiTheme.euiColorVis0;
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export const getTFPercentage = (config: FileBasedFieldVisConfig) => {
// Map of DataVisualizerTable breakpoints specific to the table component
// Note that the table width is not always the full width of the browser window
const TABLE_BREAKPOINTS = {
small: 600,
small: 700,
medium: 1000,
large: Infinity, // default
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { useMemo } from 'react';
import { euiDarkVars as euiThemeDark, euiLightVars as euiThemeLight } from '@kbn/ui-theme';
import { useDataVisualizerKibana } from '../../kibana_context';

export function useCurrentEuiTheme() {
const { services } = useDataVisualizerKibana();
const uiSettings = services.uiSettings;
return useMemo(
() => (uiSettings.get('theme:darkMode') ? euiThemeDark : euiThemeLight),
[uiSettings]
);
}
Loading

0 comments on commit 602b6d6

Please sign in to comment.