Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Lens] Table column text alignment #89300

Merged
merged 73 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from 65 commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
e3dcee1
migrate data table visualization to data grid
flash1293 Jan 4, 2021
a752f4d
memoize as good as possible
flash1293 Jan 4, 2021
84c2a9d
improve visuals
flash1293 Jan 4, 2021
60ceeba
Merge remote-tracking branch 'upstream/master' into lens/eui-data-grid
flash1293 Jan 5, 2021
234891d
clean up and fix tests
flash1293 Jan 5, 2021
f298b4d
:truck: Refactor table codebase in modules
dej611 Jan 12, 2021
ffe5fd2
Merge remote-tracking branch 'upstream/master' into lens/eui-data-grid
dej611 Jan 12, 2021
c233e3b
:truck: Move table component tests to its own folder
dej611 Jan 12, 2021
9318950
:bug: Fix deep check for table column header
dej611 Jan 12, 2021
79836ae
:label: Fix type check
dej611 Jan 12, 2021
3181b88
:globe_with_meridians: Fix locatization tokens
dej611 Jan 12, 2021
16b0d90
:bug: Fix functional tests
dej611 Jan 13, 2021
eb72077
:globe_with_meridians: Fix unused translation
dej611 Jan 13, 2021
07dc9a0
:camera_flash: Fix snapshot tests
dej611 Jan 13, 2021
5c0fecf
Merge branch 'master' into lens/eui-data-grid
kibanamachine Jan 14, 2021
1c9ce68
:white_check_mark: Add more functional tests for Lens table
dej611 Jan 14, 2021
38fdf2a
Merge branch 'lens/eui-data-grid' of github.com:dej611/kibana into le…
dej611 Jan 14, 2021
acc4f92
:sparkles: Add resize reset + add more unit tests
dej611 Jan 18, 2021
bc4f37a
Merge branch 'master' into lens/eui-data-grid
kibanamachine Jan 18, 2021
0637948
:lipstick: Make header sticky
dej611 Jan 18, 2021
ceea3cf
Merge branch 'lens/eui-data-grid' of github.com:dej611/kibana into le…
dej611 Jan 18, 2021
f6fc9a3
:camera_flash: Updated snapshots for sticky header fix
dej611 Jan 18, 2021
f27aafe
Merge branch 'master' into lens/eui-data-grid
kibanamachine Jan 19, 2021
3f02cd7
add column toggle functionality
flash1293 Jan 19, 2021
a993045
Merge branch 'master' into lens/eui-data-grid
kibanamachine Jan 20, 2021
e4e6761
Merge branch 'master' into lens/hidden-column
kibanamachine Jan 20, 2021
2f39d62
Merge branch 'master' into lens/eui-data-grid
kibanamachine Jan 21, 2021
ff69cc7
Merge branch 'master' into lens/eui-data-grid
kibanamachine Jan 25, 2021
07967ed
:lipstick: Some css classes clean up
dej611 Jan 25, 2021
0fed673
:lipstick: Make truncate work by the datagrid component
dej611 Jan 25, 2021
4eef909
Merge remote-tracking branch 'dej611/lens/eui-data-grid' into lens/hi…
flash1293 Jan 25, 2021
5a458d9
Merge branch 'lens/hidden-column' of github.com:flash1293/kibana into…
flash1293 Jan 25, 2021
9c6f5cf
Merge branch 'master' into lens/eui-data-grid
kibanamachine Jan 26, 2021
90e810b
refactoring
flash1293 Jan 26, 2021
8fc5c07
Merge remote-tracking branch 'dej611/lens/eui-data-grid' into lens/hi…
flash1293 Jan 26, 2021
e821ca6
add tests and clean up
flash1293 Jan 26, 2021
8dd99e1
add column alignment config
flash1293 Jan 26, 2021
83e3e85
Merge branch 'master' into lens/eui-data-grid
kibanamachine Jan 26, 2021
fc4b39d
Merge remote-tracking branch 'dej611/lens/eui-data-grid' into lens/hi…
flash1293 Jan 26, 2021
82d7e9f
fix migrations
flash1293 Jan 26, 2021
44fdd55
fix test
flash1293 Jan 26, 2021
b370f9a
Merge branch 'lens/hidden-column' into lens/align-column
flash1293 Jan 26, 2021
4e1052f
Merge branch 'master' into lens/eui-data-grid
kibanamachine Jan 27, 2021
c7240ab
Merge remote-tracking branch 'dej611/lens/eui-data-grid' into lens/hi…
flash1293 Jan 27, 2021
9aeb996
Merge branch 'lens/hidden-column' into lens/align-column
flash1293 Jan 27, 2021
5291a5a
add tests
flash1293 Jan 27, 2021
00b7ab6
Merge remote-tracking branch 'upstream/master' into lens/hidden-column
flash1293 Jan 29, 2021
a04f71f
Merge branch 'lens/hidden-column' into lens/align-column
flash1293 Jan 29, 2021
a17d9d5
Merge remote-tracking branch 'upstream/master' into lens/hidden-column
flash1293 Feb 1, 2021
064794b
fix bug
flash1293 Feb 1, 2021
db3ab50
Merge remote-tracking branch 'upstream/master' into lens/hidden-column
flash1293 Feb 2, 2021
1028ed5
Merge branch 'lens/hidden-column' into lens/align-column
flash1293 Feb 2, 2021
46ec8ac
Merge remote-tracking branch 'upstream/master' into lens/hidden-column
flash1293 Feb 3, 2021
0ec8926
Merge remote-tracking branch 'upstream/master' into lens/hidden-column
flash1293 Feb 3, 2021
4ebca5f
move hidden flag to dimension editor
flash1293 Feb 3, 2021
b2ba6b9
fix i18n
flash1293 Feb 3, 2021
332c1f5
Merge branch 'lens/hidden-column' into lens/align-column
flash1293 Feb 3, 2021
7a4befb
Merge branch 'master' into lens/hidden-column
kibanamachine Feb 4, 2021
a193204
review comments
flash1293 Feb 4, 2021
501933c
Merge branch 'lens/hidden-column' into lens/align-column
flash1293 Feb 4, 2021
dfd4e7d
review comments
flash1293 Feb 4, 2021
7847e86
simplify
flash1293 Feb 4, 2021
28b8811
fix license headers
flash1293 Feb 4, 2021
c0e94e7
Merge branch 'lens/hidden-column' into lens/align-column
flash1293 Feb 4, 2021
4685dd4
Merge remote-tracking branch 'upstream/master' into lens/align-column
flash1293 Feb 4, 2021
25bbbc4
Merge remote-tracking branch 'upstream/master' into lens/align-column
flash1293 Feb 5, 2021
d59d811
Merge branch 'master' into lens/align-column
kibanamachine Feb 8, 2021
fe0ee9a
Merge branch 'lens/align-column' of github.com:flash1293/kibana into …
flash1293 Feb 15, 2021
017f018
Merge remote-tracking branch 'upstream/master' into lens/align-column
flash1293 Feb 15, 2021
c5154a8
remove setCellProps usage
flash1293 Feb 15, 2021
40b8553
Merge remote-tracking branch 'upstream/master' into lens/align-column
flash1293 Feb 17, 2021
81ca61d
remove setcellprops
flash1293 Feb 17, 2021
f7a6eb9
remove unused import
flash1293 Feb 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* 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 { mountWithIntl } from '@kbn/test/jest';
import React from 'react';
import { DataContext } from './table_basic';
import { createGridCell } from './cell_value';
import { FieldFormat } from 'src/plugins/data/public';
import { Datatable } from 'src/plugins/expressions/public';

describe('datatable cell renderer', () => {
const table: Datatable = {
type: 'datatable',
columns: [
{
id: 'a',
name: 'a',
meta: {
type: 'number',
},
},
],
rows: [{ a: 123 }],
};
const CellRenderer = createGridCell(
{
a: { convert: (x) => `formatted ${x}` } as FieldFormat,
},
DataContext
);

it('renders formatted value', () => {
const instance = mountWithIntl(
<DataContext.Provider
value={{
table,
alignments: {
a: 'right',
},
}}
>
<CellRenderer
rowIndex={0}
columnId="a"
setCellProps={() => {}}
isExpandable={false}
isDetails={false}
isExpanded={false}
/>
</DataContext.Provider>
);
expect(instance.text()).toEqual('formatted 123');
});

it('call setCellProps with text alignment', () => {
const setCellPropsFn = jest.fn();
mountWithIntl(
<DataContext.Provider
value={{
table,
alignments: {
a: 'right',
},
}}
>
<CellRenderer
rowIndex={0}
columnId="a"
setCellProps={setCellPropsFn}
isExpandable={false}
isDetails={false}
isExpanded={false}
/>
</DataContext.Provider>
);
expect(setCellPropsFn).toHaveBeenCalledWith({
style: {
textAlign: 'right',
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,27 @@
* 2.0.
*/

import React, { useContext } from 'react';
import React, { useContext, useEffect } from 'react';
import { EuiDataGridCellValueElementProps } from '@elastic/eui';
import type { FormatFactory } from '../../types';
import type { DataContextType } from './types';

export const createGridCell = (
formatters: Record<string, ReturnType<FormatFactory>>,
DataContext: React.Context<DataContextType>
) => ({ rowIndex, columnId }: EuiDataGridCellValueElementProps) => {
const { table } = useContext(DataContext);
) => ({ rowIndex, columnId, setCellProps }: EuiDataGridCellValueElementProps) => {
const { table, alignments } = useContext(DataContext);
const rowValue = table?.rows[rowIndex][columnId];
const content = formatters[columnId]?.convert(rowValue, 'html');
const currentAlignment = alignments && alignments[columnId];

useEffect(() => {
setCellProps({
style: {
textAlign: currentAlignment,
},
});
}, [currentAlignment, setCellProps]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use of useEffect here is causing visible flickering during scrolls. I know that the docs recommend setCellProps, but why aren't we using class names? I did a local test using classnames and found that the flickering goes away.

I recorded a video of the flickering effect, and here is a single frame from the video:

Screen Shot 2021-02-09 at 5 15 22 PM

As you can see in this frame, the text is not evenly aligned during the scroll.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@flash1293 It looks like you're now assigning the alignment twice: there's a className and a useEffect. Do we need both?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wylieconlon eh, I forgot to remove the setCellProps hook. I will fix it tomorrow morning.


return (
<span
Expand All @@ -26,7 +35,6 @@ export const createGridCell = (
*/
dangerouslySetInnerHTML={{ __html: content }} // eslint-disable-line react/no-danger
data-test-subj="lnsTableCellContent"
className="lnsDataTableCellContent"
/>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
/*
* 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 React from 'react';
import { EuiButtonGroup } from '@elastic/eui';
import { FramePublicAPI, VisualizationDimensionEditorProps } from '../../types';
import { DatatableVisualizationState } from '../visualization';
import { createMockDatasource, createMockFramePublicAPI } from '../../editor_frame_service/mocks';
import { mountWithIntl } from '@kbn/test/jest';
import { TableDimensionEditor } from './dimension_editor';

describe('data table dimension editor', () => {
let frame: FramePublicAPI;
let state: DatatableVisualizationState;
let setState: (newState: DatatableVisualizationState) => void;
let props: VisualizationDimensionEditorProps<DatatableVisualizationState>;

function testState(): DatatableVisualizationState {
return {
layerId: 'first',
columns: [
{
columnId: 'foo',
},
],
};
}

beforeEach(() => {
state = testState();
frame = createMockFramePublicAPI();
frame.datasourceLayers = {
first: createMockDatasource('test').publicAPIMock,
};
frame.activeData = {
first: {
type: 'datatable',
columns: [
{
id: 'foo',
name: 'foo',
meta: {
type: 'string',
},
},
],
rows: [],
},
};
setState = jest.fn();
props = {
accessor: 'foo',
frame,
groupId: 'columns',
layerId: 'first',
state,
setState,
};
});

it('should render default alignment', () => {
const instance = mountWithIntl(<TableDimensionEditor {...props} />);
expect(instance.find(EuiButtonGroup).prop('idSelected')).toEqual(
expect.stringContaining('left')
);
});

it('should render default alignment for number', () => {
frame.activeData!.first.columns[0].meta.type = 'number';
const instance = mountWithIntl(<TableDimensionEditor {...props} />);
expect(instance.find(EuiButtonGroup).prop('idSelected')).toEqual(
expect.stringContaining('right')
);
});

it('should render specific alignment', () => {
state.columns[0].alignment = 'center';
const instance = mountWithIntl(<TableDimensionEditor {...props} />);
expect(instance.find(EuiButtonGroup).prop('idSelected')).toEqual(
expect.stringContaining('center')
);
});

it('should set state for the right column', () => {
state.columns = [
{
columnId: 'foo',
},
{
columnId: 'bar',
},
];
const instance = mountWithIntl(<TableDimensionEditor {...props} />);
instance.find(EuiButtonGroup).prop('onChange')('center');
expect(setState).toHaveBeenCalledWith({
...state,
columns: [
{
columnId: 'foo',
alignment: 'center',
},
{
columnId: 'bar',
},
],
});
});
});
Loading