Skip to content

Commit

Permalink
[Security Solution] Remove SavedObjects client UI for CTI and risk sc…
Browse files Browse the repository at this point in the history
…ores module (#156213)

## Summary

issue: #155995


1. Remove SO client from UI.
2. Replace **Kibana** dashboard url with **Security** dashboard url in
threat intel overview.

### Checklist

Delete any items that are not applicable to this PR.


- [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

---------

Co-authored-by: Angela Chuang <yi-chun.chuang@elastic.co>
Co-authored-by: Angela Chuang <6295984+angorayc@users.noreply.github.com>
  • Loading branch information
3 people authored May 15, 2023
1 parent 6f5f7d0 commit 973f4f3
Show file tree
Hide file tree
Showing 57 changed files with 1,133 additions and 906 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@
* 2.0.
*/

import { SECURITY_TAG_NAME, SECURITY_TAG_DESCRIPTION } from '../../../../../../common/constants';

export const MOCK_TAG_ID = 'securityTagId';

export const DEFAULT_TAGS_RESPONSE = [
{
id: MOCK_TAG_ID,
name: SECURITY_TAG_NAME,
description: SECURITY_TAG_DESCRIPTION,
color: '#2c7b82',
},
];

export const DEFAULT_DASHBOARDS_RESPONSE = [
{
type: 'dashboard',
Expand All @@ -44,10 +31,6 @@ export const DEFAULT_DASHBOARDS_RESPONSE = [
},
];

export const getSecuritySolutionTags = jest
.fn()
.mockImplementation(() => Promise.resolve(DEFAULT_TAGS_RESPONSE));

export const getSecuritySolutionDashboards = jest
export const getDashboardsByTagIds = jest
.fn()
.mockImplementation(() => Promise.resolve(DEFAULT_DASHBOARDS_RESPONSE));

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { HttpSetup } from '@kbn/core/public';
import { INTERNAL_DASHBOARDS_URL } from '../../../../common/constants';

export interface Dashboard {
id: string;
type: string;
attributes: {
title: string;
description: string;
};
references: Array<{ name: string; type: string; id: string }>;
}

export const getDashboardsByTagIds = (
{ http, tagIds }: { http: HttpSetup; tagIds: string[] },
abortSignal?: AbortSignal
): Promise<Dashboard[] | null> =>
http.post(INTERNAL_DASHBOARDS_URL, {
body: JSON.stringify({ tagIds }),
signal: abortSignal,
});

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export const MOCK_TAG_ID = 'securityTagId';

export const DEFAULT_TAGS_RESPONSE = [
{
id: MOCK_TAG_ID,
name: 'test tag',
description: 'test tag description',
color: '#2c7b82',
},
];

export const getTagsByName = jest
.fn()
.mockImplementation(() => Promise.resolve(DEFAULT_TAGS_RESPONSE));
export const createTag = jest
.fn()
.mockImplementation(() => Promise.resolve(DEFAULT_TAGS_RESPONSE[0]));
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import type { HttpSetup } from '@kbn/core/public';
import type { Tag } from '@kbn/saved-objects-tagging-plugin/public';
import type { TagAttributes } from '@kbn/saved-objects-tagging-plugin/common';
import { INTERNAL_TAGS_URL } from '../../../../common/constants';

export const getTagsByName = (
{ http, tagName }: { http: HttpSetup; tagName: string },
abortSignal?: AbortSignal
): Promise<Tag[]> => http.get(INTERNAL_TAGS_URL, { query: { name: tagName }, signal: abortSignal });

export const createTag = (
{ http, tag }: { http: HttpSetup; tag: Omit<TagAttributes, 'color'> & { color?: string } },
abortSignal?: AbortSignal
): Promise<Tag> =>
http.put(INTERNAL_TAGS_URL, {
body: JSON.stringify(tag),
signal: abortSignal,
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import { APP_UI_ID } from '../../../../common/constants';

export const REQUEST_NAMES = {
SECURITY_DASHBOARDS: `${APP_UI_ID} fetch security dashboards`,
SECURITY_TAGS: `${APP_UI_ID} fetch security tags`,
SECURITY_CREATE_TAG: `${APP_UI_ID} fetch security create tag`,
CTI_TAGS: `${APP_UI_ID} fetch cti tags`,
ANOMALIES_TABLE: `${APP_UI_ID} fetch anomalies table data`,
GET_RISK_SCORE_DEPRECATED: `${APP_UI_ID} fetch is risk score deprecated`,
ENABLE_RISK_SCORE: `${APP_UI_ID} fetch enable risk score`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ describe('useFetch', () => {
});

expect(result.current.data).toEqual(undefined);
expect(result.current.isLoading).toEqual(true);
expect(result.current.isLoading).toEqual(false);
expect(result.current.error).toEqual(undefined);

expect(mockFetchFn).not.toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const useFetch = <Parameters, Response, Error extends unknown>(
Reducer<State<Parameters, Response, Error>, Action<Parameters, Response, Error>>
>(requestReducer, {
data: undefined,
isLoading: initialParameters !== undefined, // isLoading state is used internally to control fetch executions
isLoading: !disabled && initialParameters !== undefined, // isLoading state is used internally to control fetch executions
error: undefined,
parameters: initialParameters,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { render } from '@testing-library/react';
import React from 'react';
import { TestProviders } from '../../mock';
import { TestProviders } from '../../common/mock';
import { DashboardRenderer } from './dashboard_renderer';

jest.mock('@kbn/dashboard-plugin/public', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { ViewMode } from '@kbn/embeddable-plugin/public';
import type { Filter, Query } from '@kbn/es-query';

import { useDispatch } from 'react-redux';
import { InputsModelId } from '../../store/inputs/constants';
import { inputsActions } from '../../store/inputs';
import { InputsModelId } from '../../common/store/inputs/constants';
import { inputsActions } from '../../common/store/inputs';

const DashboardRendererComponent = ({
canReadDashboard,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { TestProviders } from '../../mock';
import { DashboardsTable } from './dashboards_table';
import { TestProviders } from '../../common/mock';

// mock lodash debounce to speed up the test
jest.mock('lodash', () => ({ ...jest.requireActual('lodash'), debounce: (fn: () => void) => fn }));
Expand All @@ -35,8 +35,8 @@ const mockUseSecurityDashboardsTableItems = jest.fn(() => ({
items: DASHBOARD_TABLE_ITEMS,
isLoading: false,
}));
jest.mock('../../containers/dashboards/use_security_dashboards_table', () => {
const actual = jest.requireActual('../../containers/dashboards/use_security_dashboards_table');
jest.mock('../hooks/use_security_dashboards_table', () => {
const actual = jest.requireActual('../hooks/use_security_dashboards_table');
return {
...actual,
useSecurityDashboardsTableItems: () => mockUseSecurityDashboardsTableItems(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { i18n } from '@kbn/i18n';
import {
useSecurityDashboardsTableItems,
useSecurityDashboardsTableColumns,
} from '../../containers/dashboards/use_security_dashboards_table';
import { useAppToasts } from '../../hooks/use_app_toasts';
} from '../hooks/use_security_dashboards_table';
import { useAppToasts } from '../../common/hooks/use_app_toasts';

export const DASHBOARDS_QUERY_ERROR = i18n.translate(
'xpack.securitySolution.dashboards.queryError',
Expand Down
Loading

0 comments on commit 973f4f3

Please sign in to comment.