Skip to content

Commit

Permalink
Fix custom highlighting of field values in the message details of the…
Browse files Browse the repository at this point in the history
… message table widget. (#20921)

* Fix custom highlighting of field values for message details in message table.

* Adding changelog
  • Loading branch information
linuspahl authored Nov 20, 2024
1 parent e9abe47 commit 21da00d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/issue-18388.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type = "fixed"
message = "Fix custom highlighting of field values in the message details of the message table widget"

issues = ["18388"]
pulls = ["20921"]
21 changes: 18 additions & 3 deletions graylog2-web-interface/src/views/components/Value.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import FieldType from 'views/logic/fieldtypes/FieldType';
import type { ValueRenderer, ValueRendererProps } from 'views/components/messagelist/decoration/ValueRenderer';
import useActiveQueryId from 'views/hooks/useActiveQueryId';
import type FieldUnit from 'views/logic/aggregationbuilder/FieldUnit';
import CustomHighlighting from 'views/components/highlighting/CustomHighlighting';

import ValueActions from './actions/ValueActions';
import TypeSpecificValue from './TypeSpecificValue';
Expand All @@ -39,13 +40,27 @@ const ValueActionTitle = styled.span`
white-space: nowrap;
`;

type TypeSpecificValueWithHighlightProps = {
field: string,
value?: any,
type?: FieldType
render?: React.ComponentType<ValueRendererProps>,
unit?: FieldUnit,
}
const TypeSpecificValueWithHighlight = ({ field, value, type, render, unit }: TypeSpecificValueWithHighlightProps) => (
<CustomHighlighting field={field}
value={value}>
<TypeSpecificValue field={field} value={value} type={type} render={render} unit={unit} />
</CustomHighlighting>
);

const defaultRenderer: ValueRenderer = ({ value }: ValueRendererProps) => value;

const InteractiveValue = ({ field, value, render = defaultRenderer, type, unit }: Props) => {
const queryId = useActiveQueryId();
const RenderComponent: ValueRenderer = useMemo(() => render ?? ((props: ValueRendererProps) => props.value), [render]);
const Component = useCallback(({ value: componentValue }) => <RenderComponent field={field} value={componentValue} />, [RenderComponent, field]);
const element = <TypeSpecificValue field={field} value={value} type={type} render={Component} unit={unit} />;
const element = <TypeSpecificValueWithHighlight field={field} value={value} type={type} render={Component} unit={unit} />;

return (
<ValueActions element={element} field={field} queryId={queryId} type={type} value={value}>
Expand All @@ -58,9 +73,9 @@ const InteractiveValue = ({ field, value, render = defaultRenderer, type, unit }

const Value = ({ field, value, render = defaultRenderer, type = FieldType.Unknown, unit }: Props) => (
<InteractiveContext.Consumer>
{(interactive) => ((interactive)
{(interactive) => (interactive
? <InteractiveValue field={field} value={value} render={render} type={type} unit={unit} />
: <span><TypeSpecificValue field={field} value={value} render={render} type={type} unit={unit} /></span>)}
: <span><TypeSpecificValueWithHighlight field={field} value={value} render={render} type={type} unit={unit} /></span>)}
</InteractiveContext.Consumer>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import FieldTypeMapping from 'views/logic/fieldtypes/FieldTypeMapping';

import type { Message } from './Types';

import CustomHighlighting from '../highlighting/CustomHighlighting';

type Props = {
message: Message,
fields: FieldTypeMappingsList,
Expand All @@ -50,14 +48,10 @@ const MessageFields = ({ message, fields }: Props) => {
const { type } = fields.find((t) => t.name === key, undefined, FieldTypeMapping.create(key, FieldType.Unknown));

return (
<CustomHighlighting key={key}
field={key}
value={formattedFields[key]}>
<MessageField fieldName={key}
fieldType={type}
message={message}
value={formattedFields[key]} />
</CustomHighlighting>
<MessageField fieldName={key}
fieldType={type}
message={message}
value={formattedFields[key]} />
);
});

Expand Down

0 comments on commit 21da00d

Please sign in to comment.