-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
Improves the formatting of array values and JSON in the Event and Alert Details panels #115141
Improves the formatting of array values and JSON in the Event and Alert Details panels #115141
Conversation
…ON in the Event and Alert Details panels This PR improves the formatting of array values and JSON in the Event and Alert details panels by: - in the `Table` tab, formatting array values such that each value appears on a separate line, (instead of joining the values on a single line) - in the `JSON` tab, displaying the raw search hit JSON, instead displaying a JSON representation based on the `Fields` API ### Table value formatting In the Event and Alert details `Table` tab, array values were joined on a single line, as shown in the _before_ screenshot below: ![event-details-value-formatting-before](https://user-images.githubusercontent.com/4459398/137524968-6450cd73-3154-457d-b850-32a3e7faaab2.png) _Above: (before) array values were joined on a single line_ Array values are now formatted such that each value appears on a separate line, as shown in the _after_ screenshot below: ![event-details-value-formatting-after](https://user-images.githubusercontent.com/4459398/137436705-b0bec735-5a83-402e-843a-2776e1c80da9.png) _Above: (after) array values each appear on a separte line_ ### JSON formatting The `JSON` tab previously displayed a JSON representation based on the `Fields` API. Array values were previously represented as a joined string, as shown in the _before_ screenshot below: ![event-details-json-formatting-before](https://user-images.githubusercontent.com/4459398/137525039-d1b14f21-5f9c-4201-905e-8b08f00bb5a0.png) _Above: (before) array values were previously represented as a joined string_ The `JSON` tab now displays the raw search hit JSON, per the _after_ screenshot below: ![event-details-json-formatting-after](https://user-images.githubusercontent.com/4459398/137437257-330c5b49-a4ad-418e-a976-923f7a35c0cf.png) _Above: (after) the `JSON` tab displays the raw search hit_ CC @monina-n @paulewing
cd3b0ad
to
deb7f06
Compare
<EuiText size="xs" key={value}> | ||
{value} | ||
</EuiText> | ||
<EuiFlexItem grow={false} key={`${i}-${value}`}> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Figure they aren't re-orderable so shouldn't be an issue, but can we not use index here? 🤷🏾
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original code used key={value}
, but that's not correct because users may index a document like:
POST /test-delete-me/_doc/1?pretty
{
"has_dupes": ["foo", "bar", "baz", "foo"]
}
, which when retrieved via GET /test-delete-me/_doc/1?pretty
returns the non-unique values in the array:
{
"_index" : "test-delete-me",
"_id" : "1",
"_version" : 1,
"_seq_no" : 0,
"_primary_term" : 1,
"found" : true,
"_source" : {
"has_dupes" : [
"foo",
"bar",
"baz",
"foo"
]
}
}
The official React docs on lists and keys link to Index as a key is an anti-pattern, which recommends evaluating three conditions to determine whether or not it's safe to use index
as a key:
To help you decide, I put together three conditions which these examples have in common:
1. the list and items are static–they are not computed and do not change;
2. the items in the list have no ids;
3. the list is never reordered or filtered.
When all of them are met, you may safely use the index as a key.
Applying the criteria above, the details panel fails condition 3:
3. the list is never reordered or filtered.
because users can filter the view by value, as shown in the screenshot below:
@@ -42,7 +42,7 @@ export const useTimelineEventsDetails = ({ | |||
indexName, | |||
eventId, | |||
skip, | |||
}: UseTimelineEventsDetailsProps): [boolean, EventsArgs['detailsData']] => { | |||
}: UseTimelineEventsDetailsProps): [boolean, EventsArgs['detailsData'], object | undefined] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, why undefined instead of null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just curious, why undefined instead of null?
I chose undefined
instead of null
, because (just) null is valid JSON, but undefined
is not valid JSON, which (perhaps subjectively) makes undefined
a better sentinel value to represent "no data".
For example, entering the following in Chrome dev tools:
JSON.parse(null)
has the following output:
null
because null
is valid JSON, but entering:
JSON.parse(undefined)
has the following output:
VM324:1 Uncaught SyntaxError: Unexpected token u in JSON at position 0
at JSON.parse (<anonymous>)
at <anonymous>:1:6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great, thanks for putting this through! Tested the table view as well as the JSON view, and the array values are properly formatted and the JSON view is properly formatted in both the alert table flyout and timeline flyout. Thanks!!
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Test FailuresKibana Pipeline / general / Chrome X-Pack UI Functional Tests.x-pack/test/functional_with_es_ssl/apps/uptime/alert_flyout·ts.Uptime app with real-world data uptime alerts overview page alert flyout controls can save alertStandard Out
Stack Trace
Metrics [docs]Public APIs missing comments
Async chunks
Unknown metric groupsAPI count
History
To update your PR or re-run it, just comment with: |
…in the Event and Alert Details panels (elastic#115141) ## [Security Solution] Improves the formatting of array values and JSON in the Event and Alert Details panels This PR improves the formatting of array values and JSON in the Event and Alert details panels by: - in the `Table` tab, formatting array values such that each value appears on a separate line, (instead of joining the values on a single line) - in the `JSON` tab, displaying the raw search hit JSON, instead displaying a JSON representation based on the `Fields` API ### Table value formatting In the Event and Alert details `Table` tab, array values were joined on a single line, as shown in the _before_ screenshot below: ![event-details-value-formatting-before](https://user-images.githubusercontent.com/4459398/137524968-6450cd73-3154-457d-b850-32a3e7faaab2.png) _Above: (before) array values were joined on a single line_ Array values are now formatted such that each value appears on a separate line, as shown in the _after_ screenshot below: ![event-details-value-formatting-after](https://user-images.githubusercontent.com/4459398/137436705-b0bec735-5a83-402e-843a-2776e1c80da9.png) _Above: (after) array values each appear on a separte line_ ### JSON formatting The `JSON` tab previously displayed a JSON representation based on the `Fields` API. Array values were previously represented as a joined string, as shown in the _before_ screenshot below: ![event-details-json-formatting-before](https://user-images.githubusercontent.com/4459398/137525039-d1b14f21-5f9c-4201-905e-8b08f00bb5a0.png) _Above: (before) array values were previously represented as a joined string_ The `JSON` tab now displays the raw search hit JSON, per the _after_ screenshot below: ![event-details-json-formatting-after](https://user-images.githubusercontent.com/4459398/137437257-330c5b49-a4ad-418e-a976-923f7a35c0cf.png) _Above: (after) the `JSON` tab displays the raw search hit_ CC @monina-n @paulewing
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
…in the Event and Alert Details panels (#115141) (#115532) ## [Security Solution] Improves the formatting of array values and JSON in the Event and Alert Details panels This PR improves the formatting of array values and JSON in the Event and Alert details panels by: - in the `Table` tab, formatting array values such that each value appears on a separate line, (instead of joining the values on a single line) - in the `JSON` tab, displaying the raw search hit JSON, instead displaying a JSON representation based on the `Fields` API ### Table value formatting In the Event and Alert details `Table` tab, array values were joined on a single line, as shown in the _before_ screenshot below: ![event-details-value-formatting-before](https://user-images.githubusercontent.com/4459398/137524968-6450cd73-3154-457d-b850-32a3e7faaab2.png) _Above: (before) array values were joined on a single line_ Array values are now formatted such that each value appears on a separate line, as shown in the _after_ screenshot below: ![event-details-value-formatting-after](https://user-images.githubusercontent.com/4459398/137436705-b0bec735-5a83-402e-843a-2776e1c80da9.png) _Above: (after) array values each appear on a separte line_ ### JSON formatting The `JSON` tab previously displayed a JSON representation based on the `Fields` API. Array values were previously represented as a joined string, as shown in the _before_ screenshot below: ![event-details-json-formatting-before](https://user-images.githubusercontent.com/4459398/137525039-d1b14f21-5f9c-4201-905e-8b08f00bb5a0.png) _Above: (before) array values were previously represented as a joined string_ The `JSON` tab now displays the raw search hit JSON, per the _after_ screenshot below: ![event-details-json-formatting-after](https://user-images.githubusercontent.com/4459398/137437257-330c5b49-a4ad-418e-a976-923f7a35c0cf.png) _Above: (after) the `JSON` tab displays the raw search hit_ CC @monina-n @paulewing Co-authored-by: Andrew Goldstein <[email protected]>
[Security Solution] Improves the formatting of array values and JSON in the Event and Alert Details panels
This PR improves the formatting of array values and JSON in the Event and Alert details panels by:
Table
tab, formatting array values such that each value appears on a separate line, (instead of joining the values on a single line)JSON
tab, displaying the raw search hit JSON, instead displaying a JSON representation based on theFields
APITable value formatting
In the Event and Alert details
Table
tab, array values were joined on a single line, as shown in the before screenshot below:Above: (before) array values were joined on a single line
Array values are now formatted such that each value appears on a separate line, as shown in the after screenshot below:
Above: (after) array values each appear on a separte line
JSON formatting
The
JSON
tab previously displayed a JSON representation based on theFields
API. Array values were previously represented as a joined string, as shown in the before screenshot below:Above: (before) array values were previously represented as a joined string
The
JSON
tab now displays the raw search hit JSON, per the after screenshot below:Above: (after) the
JSON
tab displays the raw search hitCC @monina-n @paulewing