-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Discover] make field icons consistent across field list and doc tabl…
…es (#129621)
- Loading branch information
1 parent
f20218f
commit 6954b0f
Showing
5 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/plugins/discover/public/utils/get_type_for_field_icon.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { DataViewField } from 'src/plugins/data_views/common'; | ||
import { getTypeForFieldIcon } from './get_type_for_field_icon'; | ||
|
||
describe('getTypeForFieldIcon', () => { | ||
it('extracts type for non-string types', () => { | ||
expect( | ||
getTypeForFieldIcon({ | ||
type: 'not-string', | ||
esTypes: ['bar'], | ||
} as DataViewField) | ||
).toBe('not-string'); | ||
}); | ||
|
||
it('extracts type when type is string but esTypes is unavailable', () => { | ||
expect( | ||
getTypeForFieldIcon({ | ||
type: 'string', | ||
esTypes: undefined, | ||
} as DataViewField) | ||
).toBe('string'); | ||
}); | ||
|
||
it('extracts esType when type is string and esTypes is available', () => { | ||
expect( | ||
getTypeForFieldIcon({ | ||
type: 'string', | ||
esTypes: ['version'], | ||
} as DataViewField) | ||
).toBe('version'); | ||
}); | ||
}); |
17 changes: 17 additions & 0 deletions
17
src/plugins/discover/public/utils/get_type_for_field_icon.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { DataViewField } from 'src/plugins/data_views/common'; | ||
|
||
/** | ||
* Extracts the type from a data view field that will match the right icon. | ||
* | ||
* We define custom logic for Discover in order to distinguish between various "string" types. | ||
*/ | ||
export const getTypeForFieldIcon = (field: DataViewField) => | ||
field.type === 'string' && field.esTypes ? field.esTypes[0] : field.type; |