kibana/x-pack/packages
Jatin Kathuria 091b5c133b
[Security Solution][Security Assistant] Investigate in timeline control should be visible only on eligible queries. (#161240)
## Summary

Handles elastic/security-team#6971

This PR mainly resolved below 3 issues:

### Rename to `Add To Timeline` control in conversation code blocks to
`Investigate in Timeline`
 
- `Add to Timeline` according to existing Security Solution actions
means, adding a condition to the timeline with an `OR` clause without
affecting the existing Timeline.

- But the `Add to Timeline` control in the Security Assistant, creates a
new timeline on each action by the user, which contradicts the above
workflow. Hence, it might confuse user.

- `Investigate in Timeline` already means that a new timeline will be
created.

### `Add To Timeline` control was visible on types of codeblock. For
example, it does not make sense for a `Query DSL` to have an `Add to
Timeline` control.

- This PR adds the list of eligible types of queries/code blocks on
which `Add To Timeline` action can be added.

- Currently, that list only contains `kql`, `dsl` and `eql`. Below is
the complete list of types of query that can occur in code blocks.

- Please feel free to suggest a change.
    ```
    'eql' | 'kql' | 'dsl' | 'json' | 'no-type';
    ```

### Lazy calculation of CodeBlockPortals and CodeBlock Action container

- To add controls to the conversation code blocks, we need to follow
below 2 steps.
    1. get the codeBlock containers on which the controls can be added.
2. create portals in the HTML container with our `Add to Timeline`
control.
  
- Below are issues these steps sometime created.
1. We get codeBlock container in the `useLayoutEffect` but at the time,
all conversations might not have loaded because of which containers are
returns as the undefined.
2. Then, we try to create portal in the `undefined` container, which
fails and hence, `Add to Timeline` controls are not visible.
 
- Solution:
1. Instead of getting the codeblock container in useLayoutEffect, we get
the function which will eventually return that container, whenever we
are creating the portal.
2. Converted codeBlock Portal to a callback such that callback can be
called during the rendering which makes sure that all needed
conversations are available and using above step we can easily get the
portal containers.
Feel free to let me know if there are any issues with above strategy. 

### Better Pattern matching.

- Currently, when we are trying to identify the type of codeblock it
might result in unexpected output because of below reason.
1. Let say, we are trying to identify KQL Query and for that we use
below phrases to match in the `OpenAI` response.
        `'Kibana Query Language', 'KQL Query'`
2. Because of this, if the `OpenAI` response contains the phrase `KQL
query` or `kql query`, that fails because of case senstivity when
searching the above phrases.
    3. This PR makes that part of pattern matching case insensitive


### Before



b472178a-0145-42d8-8fb9-ab107915086a



### After


b499f099-a7a1-435f-99b2-ab27ee1f5680



### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
2023-07-11 12:09:33 -06:00
..
kbn-alerting-state-types [RAM][Maintenance Window][8.8]Fix window maintenance workflow (#156427) 2023-05-04 17:11:26 -07:00
kbn-elastic-assistant [Security Solution][Security Assistant] Investigate in timeline control should be visible only on eligible queries. (#161240) 2023-07-11 12:09:33 -06:00
kbn-infra-forge [AO] Add metric threshold integration test (#157489) 2023-05-16 10:11:53 +02:00
kbn-random-sampling [Lens] New random sampling shared plugin (#155068) 2023-05-02 10:30:46 +02:00
kbn-slo-schema [SLO] Support filters for good/total custom metrics (#161308) 2023-07-06 08:00:09 -06:00
maps/vector_tile_utils [maps] fix double encoding MVT request body (#157788) 2023-05-16 14:45:40 -06:00
ml [ML] Explain Log Rate Spikes: Fix slowness of flushFix random payload generation. (#160645) 2023-06-30 12:39:15 +02:00
observability/alert_details [Alerting] Fix the charts on Log Threshold Rule Alert Detail page (#160321) 2023-06-27 09:18:31 -07:00
security-solution [Security Solutions] Update Events/alerts table to use FieldSpec for CellActions (#161361) 2023-07-10 16:57:04 +02:00