Skip to content

Commit

Permalink
[ML] Use EuiDataGrid's own display prop to render chart instead of ref.
Browse files Browse the repository at this point in the history
  • Loading branch information
walterra committed Jun 15, 2020
1 parent 4026c82 commit c4acf11
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
}

.mlDataGridChart + .mlDataGridChart {
border-left: solid 0px $euiColorLightShade;
border-left: none;
}

.mlDataGridChart__histogram {
Expand All @@ -17,11 +17,12 @@
color: $euiColorMediumShade;
display: block;
overflow-x: hidden;
margin: $euiSizeXS $euiSizeXS 0px $euiSizeXS;
margin: $euiSizeXS 0px 0px 0px;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 0.75rem;
font-style: italic;
font-weight: normal;
line-height: 1.4;
text-align: left;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import { euiDataGridStyle, euiDataGridToolbarSettings } from './common';
import { UseIndexDataReturnType } from './types';
// TODO Fix row hovering + bar highlighting
// import { hoveredRow$ } from './column_chart';
import { useColumnCharts } from './use_column_charts';

import './data_grid.scss';

Expand Down Expand Up @@ -61,8 +60,7 @@ export const DataGrid: FC<Props> = memo(
(props) => {
const {
chartsVisible,
columnCharts,
columns,
columnsWithCharts,
dataTestSubj,
errorMessage,
invalidSortingColumnns,
Expand All @@ -82,12 +80,6 @@ export const DataGrid: FC<Props> = memo(
visibleColumns,
} = props;

const { columnResizeHandler, refFn } = useColumnCharts(
columns.filter((c) => visibleColumns.includes(c.id)),
columnCharts,
chartsVisible
);

// TODO Fix row hovering + bar highlighting
// const getRowProps = (item: any) => {
// return {
Expand Down Expand Up @@ -185,10 +177,10 @@ export const DataGrid: FC<Props> = memo(
<EuiSpacer size="m" />
</div>
)}
<div ref={refFn} className="mlDataGrid">
<div className="mlDataGrid">
<EuiDataGrid
aria-label={isWithHeader(props) ? props.title : ''}
columns={columns.map((c) => {
columns={columnsWithCharts.map((c) => {
c.initialWidth = 150;
return c;
})}
Expand Down Expand Up @@ -221,7 +213,6 @@ export const DataGrid: FC<Props> = memo(
onChangeItemsPerPage,
onChangePage,
}}
onColumnResize={columnResizeHandler}
/>
</div>
</div>
Expand All @@ -232,7 +223,7 @@ export const DataGrid: FC<Props> = memo(

function pickProps(props: Props) {
return [
props.columns,
props.columnsWithCharts,
props.dataTestSubj,
props.errorMessage,
props.invalidSortingColumnns,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export interface UseIndexDataReturnType
extends Pick<
UseDataGridReturnType,
| 'chartsVisible'
| 'columnCharts'
| 'columnsWithCharts'
| 'errorMessage'
| 'invalidSortingColumnns'
| 'noDataMessage'
Expand All @@ -74,13 +74,12 @@ export interface UseIndexDataReturnType
| 'toggleChartVisibility'
| 'visibleColumns'
> {
columns: EuiDataGridColumn[];
renderCellValue: RenderCellValue;
}

export interface UseDataGridReturnType {
chartsVisible: boolean;
columnCharts: ChartData[];
columnsWithCharts: EuiDataGridColumn[];
errorMessage: string;
invalidSortingColumnns: ColumnId[];
noDataMessage: string;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
* you may not use this file except in compliance with the Elastic License.
*/

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

import { EuiDataGridSorting, EuiDataGridColumn } from '@elastic/eui';

import { INDEX_STATUS } from '../../data_frame_analytics/common';

import { ColumnChart } from './column_chart';
import { INIT_MAX_COLUMNS } from './common';
import {
ColumnId,
Expand Down Expand Up @@ -95,7 +96,20 @@ export const useDataGrid = (

return {
chartsVisible,
columnCharts,
columnsWithCharts: columns.map((c) => {
const chartData = columnCharts.find((cd) => cd.id === c.id);

return {
...c,
display:
chartData !== undefined && chartsVisible === true ? (
<>
<ColumnChart chartData={chartData} columnType={c} />
{c.id}
</>
) : undefined,
};
}),
errorMessage,
invalidSortingColumnns,
noDataMessage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export const useIndexData = (indexPattern: IndexPattern, query: any): UseIndexDa

return {
...dataGrid,
columns,
renderCellValue,
};
};
2 changes: 0 additions & 2 deletions x-pack/plugins/transform/public/app/hooks/use_index_data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
getErrorMessage,
useDataGrid,
useRenderCellValue,
ChartData,
EsSorting,
SearchResponse7,
UseIndexDataReturnType,
Expand Down Expand Up @@ -131,7 +130,6 @@ export const useIndexData = (

return {
...dataGrid,
columns,
renderCellValue,
};
};

0 comments on commit c4acf11

Please sign in to comment.