Skip to content

Commit

Permalink
[SecuritySolutions][Lens][Embeddable] Use the correct Lens typeguard …
Browse files Browse the repository at this point in the history
…for the new embeddable (#204189)

## Summary

Fixes #180726 

Use the new `isLensApi` helper in place of the previous system.

Co-authored-by: Angela Chuang <[email protected]>
  • Loading branch information
dej611 and angorayc authored Dec 18, 2024
1 parent 65bc6bc commit 9b0879c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ import type { CellValueContext, IEmbeddable } from '@kbn/embeddable-plugin/publi
import { isErrorEmbeddable } from '@kbn/embeddable-plugin/public';
import { createAction } from '@kbn/ui-actions-plugin/public';
import copy from 'copy-to-clipboard';
import { isLensApi } from '@kbn/lens-plugin/public';
import { isInSecurityApp } from '../../../../common/hooks/is_in_security_app';
import { KibanaServices } from '../../../../common/lib/kibana';
import { fieldHasCellActions, isCountField, isLensEmbeddable } from '../../utils';
import { fieldHasCellActions, isCountField } from '../../utils';
import { COPY_TO_CLIPBOARD, COPY_TO_CLIPBOARD_ICON, COPY_TO_CLIPBOARD_SUCCESS } from '../constants';

export const ACTION_ID = 'embeddable_copyToClipboard';
Expand Down Expand Up @@ -39,7 +40,7 @@ export const createCopyToClipboardLensAction = ({ order }: { order?: number }) =
getDisplayName: () => COPY_TO_CLIPBOARD,
isCompatible: async ({ embeddable, data }) =>
!isErrorEmbeddable(embeddable as IEmbeddable) &&
isLensEmbeddable(embeddable as IEmbeddable) &&
isLensApi(embeddable) &&
isDataColumnsValid(data) &&
isInSecurityApp(currentAppId),
execute: async ({ data }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ import type { CellValueContext, IEmbeddable } from '@kbn/embeddable-plugin/publi
import { createAction } from '@kbn/ui-actions-plugin/public';
import { ACTION_INCOMPATIBLE_VALUE_WARNING } from '@kbn/cell-actions/src/actions/translations';
import { i18n } from '@kbn/i18n';
import { isLensApi } from '@kbn/lens-plugin/public';
import { isInSecurityApp } from '../../../../common/hooks/is_in_security_app';
import { timelineSelectors } from '../../../../timelines/store';
import { fieldHasCellActions, isLensEmbeddable } from '../../utils';
import { fieldHasCellActions } from '../../utils';
import { TimelineId } from '../../../../../common/types';
import { DefaultCellActionTypes } from '../../constants';
import type { SecurityAppStore } from '../../../../common/store';
Expand Down Expand Up @@ -79,7 +80,7 @@ export const createFilterLensAction = ({
type: DefaultCellActionTypes.FILTER,
isCompatible: async ({ embeddable, data }) =>
!isErrorEmbeddable(embeddable as IEmbeddable) &&
isLensEmbeddable(embeddable as IEmbeddable) &&
isLensApi(embeddable) &&
isDataColumnsValid(data) &&
isInSecurityApp(currentAppId),
execute: async ({ data }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import type { IEmbeddable } from '@kbn/embeddable-plugin/public';
import { isLensApi } from '@kbn/lens-plugin/public';
import type { Serializable } from '@kbn/utility-types';

// All cell actions are disabled for these fields in Security
Expand All @@ -16,12 +14,6 @@ const FIELDS_WITHOUT_CELL_ACTIONS = [
'kibana.alert.reason',
];

// @TODO: this is a temporary fix. It needs a better refactor on the consumer side here to
// adapt to the new Embeddable architecture
export const isLensEmbeddable = (embeddable: IEmbeddable): embeddable is IEmbeddable => {
return isLensApi(embeddable);
};

export const fieldHasCellActions = (field?: string): boolean => {
return !!field && !FIELDS_WITHOUT_CELL_ACTIONS.includes(field);
};
Expand Down

0 comments on commit 9b0879c

Please sign in to comment.