Skip to content

Commit

Permalink
[Mappings editor] Handle unsupported types (elastic#198185)
Browse files Browse the repository at this point in the history
Fixes elastic#197592

## Summary

This PR fixes the bug where the index Mappings details page crashes if
the index has a mapping field with a type that is not recognized in
Kibana. We fix this by using `getTypeLabelFromField` instead of directly
fetching the `label` property of an object that might be `undefined` -
`getTypeLabelFromField` takes care of this case.

**How to test:**
1. Create the following index in Console (it has the unsupported
`counted_keyword` field type):
```
PUT test
{
  "mappings": {
    "properties": {
      "@timestamp": {
        "type": "date"
      },
      "log": {
        "type": "text"
      },
      "ids": {
        "type": "counted_keyword"
      }
    }
  }
}
```
2. Go to Index Management and click on the index that we just created
3. Go to Mappings tab
4. Verify that the page loads correctly
5. Check that the opening filter and selecting an option doesn't make
the page crash.

https://github.com/user-attachments/assets/4a595968-7cd8-4d36-9a53-264a0d5db50f
(cherry picked from commit 3c5319f)
  • Loading branch information
ElenaStoeva committed Oct 30, 2024
1 parent 72dee9d commit bd4d929
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ export const getFieldsMatchingFilterFromState = (
} => {
return Object.fromEntries(
Object.entries(state.fields.byId).filter(([_, fieldId]) =>
filteredDataTypes.includes(TYPE_DEFINITION[state.fields.byId[fieldId.id].source.type].label)
filteredDataTypes.includes(getTypeLabelFromField(state.fields.byId[fieldId.id].source))
)
);
};
Expand All @@ -646,9 +646,7 @@ export const getFieldsFromState = (
const getField = (fieldId: string) => {
if (filteredDataTypes) {
if (
filteredDataTypes.includes(
TYPE_DEFINITION[normalizedFields.byId[fieldId].source.type].label
)
filteredDataTypes.includes(getTypeLabelFromField(normalizedFields.byId[fieldId].source))
) {
return normalizedFields.byId[fieldId];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import {
deNormalizeRuntimeFields,
getAllFieldTypesFromState,
getFieldsFromState,
getTypeLabelFromField,
} from './lib';
import { useMappingsState, useDispatch } from './mappings_state_context';
import { TYPE_DEFINITION } from './constants';

interface Args {
onChange?: OnUpdateHandler;
Expand Down Expand Up @@ -56,7 +56,7 @@ export const useMappingsStateListener = ({ onChange, value, status }: Args) => {
const allFieldsTypes = getAllFieldTypesFromState(deNormalize(normalize(mappedFields)));
return allFieldsTypes.map((dataType) => ({
checked: undefined,
label: TYPE_DEFINITION[dataType].label,
label: getTypeLabelFromField({ type: dataType }),
'data-test-subj': `indexDetailsMappingsSelectFilter-${dataType}`,
}));
}, [mappedFields]);
Expand Down

0 comments on commit bd4d929

Please sign in to comment.