Skip to content

Commit

Permalink
Creating advanced field type for event definition ids.
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisoelkers committed Dec 6, 2024
1 parent d2d2e11 commit 5f4d71e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));


/**
Expand Down Expand Up @@ -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
);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -88,6 +89,7 @@ const TypeSpecificValue = ({ field, value, render = defaultComponent, type = Fie
case 'node': return <NodeField value={String(value)} />;
case 'streams': return <StreamsField value={value} />;
case 'percentage': return <PercentageField value={value} />;
case 'event-definition-id': return <EventDefinition value={value} />;
default: return <FormattedValue field={field} value={value} truncate={truncate} unit={unit} render={render} type={type} />;
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <Spinner />;
}

const { eventDefinition } = data;

return <span>{eventDefinition?.title ?? value}</span>;
};

export default EventDefinition;
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down

0 comments on commit 5f4d71e

Please sign in to comment.