Logs panel: Table UI - Guess string field types (#82397)

* Guess field type for string fields in logs table
This commit is contained in:
Galen Kistler 2024-02-14 07:14:22 -06:00 committed by GitHub
parent 705ab460a2
commit 4dcc59244a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 27 additions and 1 deletions

View File

@ -164,7 +164,7 @@ describe('LogsTable', () => {
});
});
it('should not render `tsNs`', async () => {
it('should not render `tsNs` column', async () => {
setup(undefined, getMockLokiFrame());
await waitFor(() => {
@ -174,6 +174,28 @@ describe('LogsTable', () => {
});
});
it('should render numeric field aligned right', async () => {
setup(
{
columnsWithMeta: {
Time: { active: true, percentOfLinesWithLabel: 100, index: 0 },
line: { active: true, percentOfLinesWithLabel: 100, index: 1 },
tsNs: { active: true, percentOfLinesWithLabel: 100, index: 2 },
},
},
getMockLokiFrame()
);
await waitFor(() => {
const columns = screen.queryAllByRole('columnheader', { name: 'tsNs' });
expect(columns.length).toBe(1);
});
const cells = screen.queryAllByRole('cell');
expect(cells[cells.length - 1].style.textAlign).toBe('right');
});
it('should not render `labels`', async () => {
setup();

View File

@ -9,6 +9,7 @@ import {
DataTransformerConfig,
Field,
FieldType,
guessFieldTypeForField,
LogsSortOrder,
sortDataFrame,
SplitOpen,
@ -86,6 +87,9 @@ export function LogsTable(props: Props) {
// This sets the individual field value as filterable
filterable: isFieldFilterable(field, logsFrame?.bodyField.name ?? '', logsFrame?.timeField.name ?? ''),
};
// If it's a string, then try to guess for a better type for numeric support in viz
field.type = field.type === FieldType.string ? guessFieldTypeForField(field) ?? FieldType.string : field.type;
}
return frameWithOverrides;