Skip to content
Open
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
17 changes: 13 additions & 4 deletions frontend/src/components/Topics/Topic/Messages/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ const Message: React.FC<Props> = ({ message, keyFilters, contentFilters }) => {
}
};

const evaluateFilter = (path: string, json: unknown) => {
// A stored preview filter can hold an invalid JSONPath (e.g. saved before

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove this ai prose

// validation existed, or one that only throws against real message data).
// Evaluating it during render would otherwise throw and crash the whole
// messages page on every load until local storage is cleared manually.
try {
return JSON.stringify(JSONPath({ path, json, wrap: false }));
} catch {
return 'Invalid JSONPath';
}
};

const renderFilteredJson = (
jsonValue?: string,
filters?: PreviewFilter[]
Expand All @@ -92,10 +104,7 @@ const Message: React.FC<Props> = ({ message, keyFilters, contentFilters }) => {
{filters.map((item) => {
return (
<div key={`${item.path}--${item.field}`}>
{item.field}:{' '}
{JSON.stringify(
JSONPath({ path: item.path, json: parsedJson, wrap: false })
)}
{item.field}: {evaluateFilter(item.path, parsedJson)}
</div>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ describe('Message component', () => {
expect(keyFiltered).toBeInTheDocument();
});

it('does not crash the row when a preview filter has an invalid JSONPath', () => {
const props = {
message: { ...mockMessage, value: mockMessageValue as string },
contentFilters: [{ field: 'broken', path: '$[?(@.foo.bar.baz)]' }],
};
renderComponent(props);
expect(screen.getByText('broken: Invalid JSONPath')).toBeInTheDocument();
});

it('shows action options in dropdown on click', async () => {
renderComponent();
const trElement = screen.getByRole('row');
Expand Down
Loading