Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating advanced field type for event definition ids. #21136

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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 @@ -62,7 +63,7 @@
return <span title={value.toString()}>{formatValueWithUnitLabel(prettified?.value, prettified.unit.abbrev)}</span>;
};

const FormattedValue = ({ field, value, truncate = false, render = defaultComponent, unit, type }: TypeSpecificValueProps) => {

Check warning on line 66 in graylog2-web-interface/src/views/components/TypeSpecificValue.tsx

View workflow job for this annotation

GitHub Actions / Reviewbot

propType "value" is not required, but has no corresponding default argument value.

No further rule information available.

Check warning on line 66 in graylog2-web-interface/src/views/components/TypeSpecificValue.tsx

View workflow job for this annotation

GitHub Actions / Reviewbot

propType "unit" is not required, but has no corresponding default argument value.

No further rule information available.

Check warning on line 66 in graylog2-web-interface/src/views/components/TypeSpecificValue.tsx

View workflow job for this annotation

GitHub Actions / Reviewbot

propType "type" is not required, but has no corresponding default argument value.

No further rule information available.
const unitFeatureEnabled = useFeature(UNIT_FEATURE_FLAG);
const shouldRenderValueWithUnit = unitFeatureEnabled && unit?.isDefined && value && value !== MISSING_BUCKET_NAME && unitFeatureEnabled;
if (shouldRenderValueWithUnit) return <ValueWithUnitRenderer value={value} unit={unit} />;
Expand All @@ -70,7 +71,7 @@
return _formatValue(field, value, truncate, render, type);
};

const TypeSpecificValue = ({ field, value, render = defaultComponent, type = FieldType.Unknown, truncate = false, unit }: TypeSpecificValueProps) => {

Check warning on line 74 in graylog2-web-interface/src/views/components/TypeSpecificValue.tsx

View workflow job for this annotation

GitHub Actions / Reviewbot

propType "value" is not required, but has no corresponding default argument value.

No further rule information available.

Check warning on line 74 in graylog2-web-interface/src/views/components/TypeSpecificValue.tsx

View workflow job for this annotation

GitHub Actions / Reviewbot

propType "unit" is not required, but has no corresponding default argument value.

No further rule information available.
const Component = render;

if (value === undefined) {
Expand All @@ -88,6 +89,7 @@
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
Loading