Skip to content

Commit

Permalink
Apply label and icon to nested fields in the doc table
Browse files Browse the repository at this point in the history
  • Loading branch information
Bargs committed Jan 7, 2020
1 parent af52b29 commit 64f7c37
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,22 @@ export function DocViewTable({
const displayNoMappingWarning =
!mapping(field) && !displayUnderscoreWarning && !isArrayOfObjects;

// Nested fields are not a part of the index pattern but their children are.
// Nested children are not a part of the flattened document but their nested parent is.
// So to detect nested fields we look through the index pattern for nested children
// that have the current field in their path. Knowing which fields are nested allows us
// to label them and apply the correct icon in the table row.
const isNestedField = !!indexPattern.fields.find(patternField =>
patternField.subType?.nested?.path.includes(field)
);
const fieldType = isNestedField ? 'nested' : undefined;

return (
<DocViewTableRow
key={field}
field={field}
fieldMapping={mapping(field)}
fieldType={fieldType}
displayUnderscoreWarning={displayUnderscoreWarning}
displayNoMappingWarning={displayNoMappingWarning}
isCollapsed={isCollapsed}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { DocViewTableRowIconUnderscore } from './table_row_icon_underscore';
export interface Props {
field: string;
fieldMapping?: FieldMapping;
fieldType?: string;
displayNoMappingWarning: boolean;
displayUnderscoreWarning: boolean;
isCollapsible: boolean;
Expand All @@ -46,6 +47,7 @@ export interface Props {
export function DocViewTableRow({
field,
fieldMapping,
fieldType,
displayNoMappingWarning,
displayUnderscoreWarning,
isCollapsible,
Expand Down Expand Up @@ -85,7 +87,7 @@ export function DocViewTableRow({
</td>
)}
<td className="kbnDocViewer__field">
<FieldName field={fieldMapping} fieldName={field} />
<FieldName field={fieldMapping} fieldName={field} fieldType={fieldType} />
</td>
<td>
{isCollapsible && (
Expand Down
4 changes: 4 additions & 0 deletions src/legacy/ui/public/directives/field_name/field_type_name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ export function getFieldTypeName(type: string) {
return i18n.translate('common.ui.directives.fieldNameIcons.stringFieldAriaLabel', {
defaultMessage: 'String field',
});
case 'nested':
return i18n.translate('common.ui.directives.fieldNameIcons.nestedFieldAriaLabel', {
defaultMessage: 'Nested field',
});
default:
return i18n.translate('common.ui.directives.fieldNameIcons.unknownFieldAriaLabel', {
defaultMessage: 'Unknown field',
Expand Down

0 comments on commit 64f7c37

Please sign in to comment.