Skip to content

Commit

Permalink
[8.x] [Mappings editor] Handle unsupported types (elastic#198185) (el…
Browse files Browse the repository at this point in the history
…astic#198421)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Mappings editor] Handle unsupported types
(elastic#198185)](elastic#198185)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Elena
Stoeva","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-30T18:03:36Z","message":"[Mappings
editor] Handle unsupported types (elastic#198185)\n\nFixes
https://github.com/elastic/kibana/issues/197592\r\n\r\n##
Summary\r\n\r\nThis PR fixes the bug where the index Mappings details
page crashes if\r\nthe index has a mapping field with a type that is not
recognized in\r\nKibana. We fix this by using `getTypeLabelFromField`
instead of directly\r\nfetching the `label` property of an object that
might be `undefined` -\r\n`getTypeLabelFromField` takes care of this
case.\r\n\r\n**How to test:**\r\n1. Create the following index in
Console (it has the unsupported\r\n`counted_keyword` field
type):\r\n```\r\nPUT test\r\n{\r\n \"mappings\": {\r\n \"properties\":
{\r\n \"@timestamp\": {\r\n \"type\": \"date\"\r\n },\r\n \"log\": {\r\n
\"type\": \"text\"\r\n },\r\n \"ids\": {\r\n \"type\":
\"counted_keyword\"\r\n }\r\n }\r\n }\r\n}\r\n```\r\n2. Go to Index
Management and click on the index that we just created\r\n3. Go to
Mappings tab\r\n4. Verify that the page loads correctly\r\n5. Check that
the opening filter and selecting an option doesn't make\r\nthe page
crash.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/4a595968-7cd8-4d36-9a53-264a0d5db50f","sha":"3c5319f2152cb38333e53dd2cc993aada8a38e34","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Kibana
Management","release_note:skip","Feature:Mappings
Editor","v9.0.0","backport:prev-minor","v8.17.0"],"title":"[Mappings
editor] Handle unsupported
types","number":198185,"url":"https://github.com/elastic/kibana/pull/198185","mergeCommit":{"message":"[Mappings
editor] Handle unsupported types (elastic#198185)\n\nFixes
https://github.com/elastic/kibana/issues/197592\r\n\r\n##
Summary\r\n\r\nThis PR fixes the bug where the index Mappings details
page crashes if\r\nthe index has a mapping field with a type that is not
recognized in\r\nKibana. We fix this by using `getTypeLabelFromField`
instead of directly\r\nfetching the `label` property of an object that
might be `undefined` -\r\n`getTypeLabelFromField` takes care of this
case.\r\n\r\n**How to test:**\r\n1. Create the following index in
Console (it has the unsupported\r\n`counted_keyword` field
type):\r\n```\r\nPUT test\r\n{\r\n \"mappings\": {\r\n \"properties\":
{\r\n \"@timestamp\": {\r\n \"type\": \"date\"\r\n },\r\n \"log\": {\r\n
\"type\": \"text\"\r\n },\r\n \"ids\": {\r\n \"type\":
\"counted_keyword\"\r\n }\r\n }\r\n }\r\n}\r\n```\r\n2. Go to Index
Management and click on the index that we just created\r\n3. Go to
Mappings tab\r\n4. Verify that the page loads correctly\r\n5. Check that
the opening filter and selecting an option doesn't make\r\nthe page
crash.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/4a595968-7cd8-4d36-9a53-264a0d5db50f","sha":"3c5319f2152cb38333e53dd2cc993aada8a38e34"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198185","number":198185,"mergeCommit":{"message":"[Mappings
editor] Handle unsupported types (elastic#198185)\n\nFixes
https://github.com/elastic/kibana/issues/197592\r\n\r\n##
Summary\r\n\r\nThis PR fixes the bug where the index Mappings details
page crashes if\r\nthe index has a mapping field with a type that is not
recognized in\r\nKibana. We fix this by using `getTypeLabelFromField`
instead of directly\r\nfetching the `label` property of an object that
might be `undefined` -\r\n`getTypeLabelFromField` takes care of this
case.\r\n\r\n**How to test:**\r\n1. Create the following index in
Console (it has the unsupported\r\n`counted_keyword` field
type):\r\n```\r\nPUT test\r\n{\r\n \"mappings\": {\r\n \"properties\":
{\r\n \"@timestamp\": {\r\n \"type\": \"date\"\r\n },\r\n \"log\": {\r\n
\"type\": \"text\"\r\n },\r\n \"ids\": {\r\n \"type\":
\"counted_keyword\"\r\n }\r\n }\r\n }\r\n}\r\n```\r\n2. Go to Index
Management and click on the index that we just created\r\n3. Go to
Mappings tab\r\n4. Verify that the page loads correctly\r\n5. Check that
the opening filter and selecting an option doesn't make\r\nthe page
crash.\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/4a595968-7cd8-4d36-9a53-264a0d5db50f","sha":"3c5319f2152cb38333e53dd2cc993aada8a38e34"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Elena Stoeva <[email protected]>
  • Loading branch information
kibanamachine and ElenaStoeva authored Oct 30, 2024
1 parent 68a7d5e commit 5a4a17f
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 5a4a17f

Please sign in to comment.