From 5f4d71e3ca4103b82bbfda7460cca06f2d3a90d8 Mon Sep 17 00:00:00 2001 From: Dennis Oelkers Date: Fri, 6 Dec 2024 11:22:03 +0100 Subject: [PATCH] Creating advanced field type for event definition ids. --- .../indexer/fieldtypes/FieldTypeMapper.java | 8 +++++--- .../src/views/components/TypeSpecificValue.tsx | 2 ++ .../components/fieldtypes/EventDefinition.tsx | 18 ++++++++++++++++++ .../sidebar/fields/FieldTypeIcon.tsx | 2 ++ 4 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 graylog2-web-interface/src/views/components/fieldtypes/EventDefinition.tsx diff --git a/graylog2-server/src/main/java/org/graylog2/indexer/fieldtypes/FieldTypeMapper.java b/graylog2-server/src/main/java/org/graylog2/indexer/fieldtypes/FieldTypeMapper.java index 3c1fb4df6b2f..c8aa36f024b4 100644 --- a/graylog2-server/src/main/java/org/graylog2/indexer/fieldtypes/FieldTypeMapper.java +++ b/graylog2-server/src/main/java/org/graylog2/indexer/fieldtypes/FieldTypeMapper.java @@ -18,9 +18,9 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; -import org.graylog2.plugin.Message; - import jakarta.inject.Singleton; +import org.graylog.events.event.EventDto; +import org.graylog2.plugin.Message; import java.util.Map; import java.util.Optional; @@ -58,6 +58,7 @@ public class FieldTypeMapper { public static final FieldTypes.Type STREAMS_TYPE = createType("streams", of(PROP_ENUMERABLE)); public static final FieldTypes.Type INPUT_TYPE = createType("input", of(PROP_ENUMERABLE)); public static final FieldTypes.Type NODE_TYPE = createType("node", of(PROP_ENUMERABLE)); + public static final FieldTypes.Type EVENT_DEFINITION_ID_TYPE = createType("event-definition-id", of(PROP_ENUMERABLE)); /** @@ -85,7 +86,8 @@ public class FieldTypeMapper { Message.FIELD_STREAMS, STREAMS_TYPE, Message.FIELD_FAILED_MESSAGE_STREAMS, STREAMS_TYPE, Message.FIELD_GL2_SOURCE_INPUT, INPUT_TYPE, - Message.FIELD_GL2_SOURCE_NODE, NODE_TYPE + Message.FIELD_GL2_SOURCE_NODE, NODE_TYPE, + EventDto.FIELD_EVENT_DEFINITION_ID, EVENT_DEFINITION_ID_TYPE ); /** diff --git a/graylog2-web-interface/src/views/components/TypeSpecificValue.tsx b/graylog2-web-interface/src/views/components/TypeSpecificValue.tsx index c9662fa255da..cece65df1da2 100644 --- a/graylog2-web-interface/src/views/components/TypeSpecificValue.tsx +++ b/graylog2-web-interface/src/views/components/TypeSpecificValue.tsx @@ -31,6 +31,7 @@ import { UNIT_FEATURE_FLAG } from 'views/components/visualizations/Constants'; import useFeature from 'hooks/useFeature'; import { MISSING_BUCKET_NAME } from 'views/Constants'; import formatValueWithUnitLabel from 'views/components/visualizations/utils/formatValueWithUnitLabel'; +import EventDefinition from 'views/components/fieldtypes/EventDefinition'; import EmptyValue from './EmptyValue'; import type { ValueRendererProps, ValueRenderer } from './messagelist/decoration/ValueRenderer'; @@ -88,6 +89,7 @@ const TypeSpecificValue = ({ field, value, render = defaultComponent, type = Fie case 'node': return ; case 'streams': return ; case 'percentage': return ; + case 'event-definition-id': return ; default: return ; } }; diff --git a/graylog2-web-interface/src/views/components/fieldtypes/EventDefinition.tsx b/graylog2-web-interface/src/views/components/fieldtypes/EventDefinition.tsx new file mode 100644 index 000000000000..3328c7bdb59a --- /dev/null +++ b/graylog2-web-interface/src/views/components/fieldtypes/EventDefinition.tsx @@ -0,0 +1,18 @@ +import * as React from 'react'; + +import useEventDefinition from 'hooks/useEventDefinition'; +import Spinner from 'components/common/Spinner'; + +const EventDefinition = ({ value }: { value: string }) => { + const { data, isLoading } = useEventDefinition(value); + + if (isLoading) { + return ; + } + + const { eventDefinition } = data; + + return {eventDefinition?.title ?? value}; +}; + +export default EventDefinition; diff --git a/graylog2-web-interface/src/views/components/sidebar/fields/FieldTypeIcon.tsx b/graylog2-web-interface/src/views/components/sidebar/fields/FieldTypeIcon.tsx index 499f704f0f2d..f81ab4a6974e 100644 --- a/graylog2-web-interface/src/views/components/sidebar/fields/FieldTypeIcon.tsx +++ b/graylog2-web-interface/src/views/components/sidebar/fields/FieldTypeIcon.tsx @@ -45,6 +45,8 @@ const iconName = (type: string) => { return 'fork_right'; case 'input': return 'cell_tower'; + case 'event-definition-id': + return 'edit_document'; default: return 'help'; }