[Lens] Fix table alignment (#173908)

## Summary

Fixes https://github.com/elastic/kibana/issues/173902

Fix issue and introduces also a unit test.


![text_alignment_table_fix](201f70cd-6fc6-41e9-bf87-8e87f9906052)


### Checklist

- [x] [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

---------

Co-authored-by: Stratoula Kalafateli <efstratia.kalafateli@elastic.co>
Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Marco Liberati 2024-01-02 13:54:07 +01:00 committed by GitHub
parent 10d94e4532
commit 2cddc60368
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 43 additions and 1 deletions

View file

@ -1,5 +1,5 @@
Kibana source code with Kibana X-Pack source code
Copyright 2012-2023 Elasticsearch B.V.
Copyright 2012-2024 Elasticsearch B.V.
---
Pretty handling of logarithmic axes.

View file

@ -759,6 +759,47 @@ describe('Datatable Visualization', () => {
}).headerRowHeightLines
).toEqual([2]);
});
it('sets alignment correctly', () => {
datasource.publicAPIMock.getOperationForColumnId.mockReturnValue({
dataType: 'string',
isBucketed: false, // <= make them metrics
label: 'label',
isStaticValue: false,
hasTimeShift: false,
hasReducedTimeRange: false,
});
const expression = datatableVisualization.toExpression(
{
...defaultExpressionTableState,
columns: [
{ columnId: 'b', alignment: 'center' },
{ columnId: 'c', alignment: 'left' },
{ columnId: 'a' },
],
},
frame.datasourceLayers,
{},
{ '1': { type: 'expression', chain: [] } }
) as Ast;
const columnArgs = buildExpression(expression).findFunction('lens_datatable_column');
expect(columnArgs[0].arguments).toEqual(
expect.objectContaining({
alignment: ['left'],
})
);
expect(columnArgs[1].arguments).toEqual(
expect.objectContaining({
alignment: ['center'],
})
);
expect(columnArgs[2].arguments).toEqual(
expect.not.objectContaining({
alignment: [],
})
);
});
});
describe('#onEditAction', () => {

View file

@ -496,6 +496,7 @@ export const getDatatableVisualization = ({
width: column.width,
isTransposed: column.isTransposed,
transposable: isTransposable,
alignment: column.alignment,
colorMode: canColor && column.colorMode ? column.colorMode : 'none',
palette: paletteService.get(CUSTOM_PALETTE).toExpression(paletteParams),
summaryRow: hasNoSummaryRow ? undefined : column.summaryRow!,