mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[RAM] Fix alert table with new props cases (#137728)
* Remove cases props and try to get it directly inside of the components by passing casesFeatureId instead * add cases to apm * fix unit test * skip test until we are bringingt them back without adding dependency in trigger action UI Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
c03820a9c0
commit
fb49ff39b1
15 changed files with 145 additions and 20 deletions
|
@ -24,6 +24,7 @@
|
|||
"optionalPlugins": [
|
||||
"actions",
|
||||
"alerting",
|
||||
"cases",
|
||||
"cloud",
|
||||
"fleet",
|
||||
"home",
|
||||
|
|
|
@ -371,6 +371,38 @@ describe('CaseViewPage', () => {
|
|||
});
|
||||
|
||||
describe('Tabs', () => {
|
||||
jest.mock('@kbn/kibana-react-plugin/public', () => ({
|
||||
useKibana: () => ({
|
||||
services: {
|
||||
application: {
|
||||
capabilities: {
|
||||
fakeCases: {
|
||||
create_cases: true,
|
||||
read_cases: true,
|
||||
update_cases: true,
|
||||
delete_cases: true,
|
||||
push_cases: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
cases: {
|
||||
ui: {
|
||||
getCasesContext: () => null,
|
||||
},
|
||||
helpers: {
|
||||
getUICapabilities: () => ({
|
||||
all: true,
|
||||
read: true,
|
||||
create: true,
|
||||
update: true,
|
||||
delete: true,
|
||||
push: true,
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}));
|
||||
it('renders tabs correctly', async () => {
|
||||
const result = appMockRenderer.render(<CaseViewPage {...caseProps} />);
|
||||
await act(async () => {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
import type { GetRenderCellValue } from '@kbn/triggers-actions-ui-plugin/public';
|
||||
import { observabilityFeatureId } from '../../common';
|
||||
import { casesFeatureId, observabilityFeatureId } from '../../common';
|
||||
import { useBulkAddToCaseActions } from '../hooks/use_alert_bulk_case_actions';
|
||||
import { TopAlert, useToGetInternalFlyout } from '../pages/alerts';
|
||||
import { getRenderCellValue } from '../pages/alerts/components/render_cell_value';
|
||||
|
@ -19,6 +19,7 @@ const getO11yAlertsTableConfiguration = (
|
|||
observabilityRuleTypeRegistry: ObservabilityRuleTypeRegistry
|
||||
) => ({
|
||||
id: observabilityFeatureId,
|
||||
casesFeatureId,
|
||||
columns: alertO11yColumns.map(addDisplayNames),
|
||||
useInternalFlyout: () => {
|
||||
const { header, body, footer } = useToGetInternalFlyout(observabilityRuleTypeRegistry);
|
||||
|
|
|
@ -49,10 +49,9 @@ import { paths } from '../../config/paths';
|
|||
import { observabilityFeatureId } from '../../../common';
|
||||
import { ALERT_STATUS_LICENSE_ERROR, rulesStatusesTranslationsMapping } from './translations';
|
||||
import { ObservabilityAppServices } from '../../application/types';
|
||||
import { useGetUserCasesPermissions } from '../../hooks/use_get_user_cases_permissions';
|
||||
|
||||
export function RuleDetailsPage() {
|
||||
const {
|
||||
cases,
|
||||
http,
|
||||
triggersActionsUi: {
|
||||
alertsTableConfigurationRegistry,
|
||||
|
@ -153,12 +152,7 @@ export function RuleDetailsPage() {
|
|||
? !ruleTypeRegistry.get(rule.ruleTypeId).requiresAppContext
|
||||
: false);
|
||||
|
||||
const userPermissions = useGetUserCasesPermissions();
|
||||
const alertStateProps = {
|
||||
cases: {
|
||||
ui: cases.ui,
|
||||
permissions: userPermissions,
|
||||
},
|
||||
alertsTableConfigurationRegistry,
|
||||
configurationId: observabilityFeatureId,
|
||||
id: `case-details-alerts-o11y`,
|
||||
|
|
|
@ -29,4 +29,4 @@ export const KIBANA_NAVIGATION_TOGGLE = '[data-test-subj="toggleNavButton"]';
|
|||
|
||||
export const SPACES_BUTTON = '[data-test-subj="spacesNavSelector"]';
|
||||
|
||||
export const getGoToSpaceMenuItem = (space: string) => `[data-test-subj="${space}-gotoSpace"]`;
|
||||
export const getGoToSpaceMenuItem = (space: string) => `[data-test-subj="space-avatar-${space}"]`;
|
||||
|
|
|
@ -11,7 +11,7 @@ import type {
|
|||
GetRenderCellValue,
|
||||
} from '@kbn/triggers-actions-ui-plugin/public';
|
||||
|
||||
import { APP_ID } from '../../../../common/constants';
|
||||
import { APP_ID, CASES_FEATURE_ID } from '../../../../common/constants';
|
||||
import { getTimelinesInStorageByIds } from '../../../timelines/containers/local_storage';
|
||||
import { TimelineId } from '../../../../common/types';
|
||||
import { columns } from '../../../detections/configurations/security_solution_detections';
|
||||
|
@ -31,6 +31,7 @@ const registerAlertsTableConfiguration = (
|
|||
|
||||
registry.register({
|
||||
id: APP_ID,
|
||||
casesFeatureId: CASES_FEATURE_ID,
|
||||
columns: alertColumns,
|
||||
getRenderCellValue: useRenderCellValue as GetRenderCellValue,
|
||||
useInternalFlyout: () => {
|
||||
|
|
|
@ -22,6 +22,7 @@ const props = {
|
|||
} as unknown as EcsFieldsResponse,
|
||||
alertsTableConfiguration: {
|
||||
id: 'test',
|
||||
casesFeatureId: 'testCases',
|
||||
columns: [
|
||||
{
|
||||
id: AlertsField.name,
|
||||
|
|
|
@ -26,6 +26,7 @@ export function registerAlertsTableConfiguration({
|
|||
}) {
|
||||
alertsTableConfigurationRegistry.register({
|
||||
id: PLUGIN_ID,
|
||||
casesFeatureId: `${PLUGIN_ID}Cases`,
|
||||
columns: [
|
||||
{
|
||||
id: 'event.action',
|
||||
|
|
|
@ -60,6 +60,7 @@ describe('AlertsTable', () => {
|
|||
|
||||
const alertsTableConfiguration = {
|
||||
id: '',
|
||||
casesFeatureId: '',
|
||||
columns,
|
||||
sort: [],
|
||||
useInternalFlyout: jest.fn().mockImplementation(() => ({
|
||||
|
|
|
@ -26,6 +26,38 @@ import { __IntlProvider as IntlProvider } from '@kbn/i18n-react';
|
|||
|
||||
jest.mock('./hooks/use_fetch_alerts');
|
||||
jest.mock('@kbn/kibana-utils-plugin/public');
|
||||
jest.mock('@kbn/kibana-react-plugin/public', () => ({
|
||||
useKibana: () => ({
|
||||
services: {
|
||||
application: {
|
||||
capabilities: {
|
||||
fakeCases: {
|
||||
create_cases: true,
|
||||
read_cases: true,
|
||||
update_cases: true,
|
||||
delete_cases: true,
|
||||
push_cases: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
cases: {
|
||||
ui: {
|
||||
getCasesContext: () => null,
|
||||
},
|
||||
helpers: {
|
||||
getUICapabilities: () => ({
|
||||
all: true,
|
||||
read: true,
|
||||
create: true,
|
||||
update: true,
|
||||
delete: true,
|
||||
push: true,
|
||||
}),
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
const columns = [
|
||||
{
|
||||
|
|
|
@ -16,6 +16,7 @@ import {
|
|||
import type { ValidFeatureId } from '@kbn/rule-data-utils';
|
||||
import type { RuleRegistrySearchRequestPagination } from '@kbn/rule-registry-plugin/common';
|
||||
import { Storage } from '@kbn/kibana-utils-plugin/public';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
import type {
|
||||
QueryDslQueryContainer,
|
||||
SortCombinations,
|
||||
|
@ -33,22 +34,17 @@ import {
|
|||
import { ALERTS_TABLE_CONF_ERROR_MESSAGE, ALERTS_TABLE_CONF_ERROR_TITLE } from './translations';
|
||||
import { TypeRegistry } from '../../type_registry';
|
||||
import { bulkActionsReducer } from './bulk_actions/reducer';
|
||||
import { useGetUserCasesPermissions } from './hooks/use_get_user_cases_permissions';
|
||||
|
||||
const DefaultPagination = {
|
||||
pageSize: 10,
|
||||
pageIndex: 0,
|
||||
};
|
||||
|
||||
interface CasePermission {
|
||||
all: boolean;
|
||||
read: boolean;
|
||||
}
|
||||
|
||||
interface CaseUi {
|
||||
ui: {
|
||||
getCasesContext: () => React.FC<any>;
|
||||
};
|
||||
permissions: CasePermission;
|
||||
}
|
||||
|
||||
export interface AlertsTableStateProps {
|
||||
|
@ -60,7 +56,6 @@ export interface AlertsTableStateProps {
|
|||
query: Pick<QueryDslQueryContainer, 'bool' | 'ids'>;
|
||||
pageSize?: number;
|
||||
showExpandToDetails: boolean;
|
||||
cases?: CaseUi;
|
||||
}
|
||||
|
||||
interface AlertsTableStorage {
|
||||
|
@ -71,6 +66,7 @@ interface AlertsTableStorage {
|
|||
|
||||
const EmptyConfiguration = {
|
||||
id: '',
|
||||
casesFeatureId: '',
|
||||
columns: [],
|
||||
sort: [],
|
||||
externalFlyout: {
|
||||
|
@ -106,8 +102,8 @@ const AlertsTableState = ({
|
|||
query,
|
||||
pageSize,
|
||||
showExpandToDetails,
|
||||
cases,
|
||||
}: AlertsTableStateProps) => {
|
||||
const { cases } = useKibana<{ cases: CaseUi }>().services;
|
||||
const hasAlertsTableConfiguration =
|
||||
alertsTableConfigurationRegistry?.has(configurationId) ?? false;
|
||||
const alertsTableConfiguration = hasAlertsTableConfiguration
|
||||
|
@ -269,6 +265,7 @@ const AlertsTableState = ({
|
|||
);
|
||||
|
||||
const CasesContext = cases?.ui.getCasesContext();
|
||||
const userCasesPermissions = useGetUserCasesPermissions(alertsTableConfiguration.casesFeatureId);
|
||||
|
||||
return hasAlertsTableConfiguration ? (
|
||||
<>
|
||||
|
@ -279,7 +276,7 @@ const AlertsTableState = ({
|
|||
{alertsCount !== 0 && CasesContext && cases && (
|
||||
<CasesContext
|
||||
owner={[configurationId]}
|
||||
permissions={cases.permissions}
|
||||
permissions={userCasesPermissions}
|
||||
features={{ alerts: { sync: false } }}
|
||||
>
|
||||
<AlertsTableWithBulkActionsContext
|
||||
|
|
|
@ -66,6 +66,7 @@ describe('AlertsTable.BulkActions', () => {
|
|||
|
||||
const alertsTableConfiguration = {
|
||||
id: '',
|
||||
casesFeatureId: 'test',
|
||||
columns,
|
||||
sort: [],
|
||||
useInternalFlyout: jest.fn().mockImplementation(() => ({
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* 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 { useEffect, useState } from 'react';
|
||||
import { useKibana } from '@kbn/kibana-react-plugin/public';
|
||||
|
||||
interface CasesPermissions {
|
||||
all: boolean;
|
||||
create: boolean;
|
||||
read: boolean;
|
||||
update: boolean;
|
||||
delete: boolean;
|
||||
push: boolean;
|
||||
}
|
||||
|
||||
interface CasesUserPermissions {
|
||||
helpers: {
|
||||
getUICapabilities: (
|
||||
featureCapabilities?: Partial<Record<string, boolean | Record<string, boolean>>>
|
||||
) => CasesPermissions;
|
||||
};
|
||||
}
|
||||
|
||||
export function useGetUserCasesPermissions(casesFeatureId: string) {
|
||||
const [casesPermissions, setCasesPermissions] = useState<CasesPermissions>({
|
||||
all: false,
|
||||
read: false,
|
||||
create: false,
|
||||
update: false,
|
||||
delete: false,
|
||||
push: false,
|
||||
});
|
||||
const uiCapabilities = useKibana().services.application?.capabilities;
|
||||
|
||||
const casesCapabilities = useKibana<{
|
||||
cases: CasesUserPermissions;
|
||||
}>().services.cases.helpers.getUICapabilities(uiCapabilities![casesFeatureId]);
|
||||
|
||||
useEffect(() => {
|
||||
setCasesPermissions({
|
||||
all: casesCapabilities.all,
|
||||
create: casesCapabilities.create,
|
||||
read: casesCapabilities.read,
|
||||
update: casesCapabilities.update,
|
||||
delete: casesCapabilities.delete,
|
||||
push: casesCapabilities.push,
|
||||
});
|
||||
}, [
|
||||
casesCapabilities.all,
|
||||
casesCapabilities.create,
|
||||
casesCapabilities.read,
|
||||
casesCapabilities.update,
|
||||
casesCapabilities.delete,
|
||||
casesCapabilities.push,
|
||||
]);
|
||||
|
||||
return casesPermissions;
|
||||
}
|
|
@ -458,6 +458,7 @@ export type UseBulkActionsRegistry = () => BulkActionsConfig[];
|
|||
|
||||
export interface AlertsTableConfigurationRegistry {
|
||||
id: string;
|
||||
casesFeatureId: string;
|
||||
columns: EuiDataGridColumn[];
|
||||
useInternalFlyout?: () => {
|
||||
header: AlertTableFlyoutComponent;
|
||||
|
|
|
@ -16,7 +16,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
|
|||
const esArchiver = getService('esArchiver');
|
||||
const find = getService('find');
|
||||
|
||||
describe('Alerts table', function () {
|
||||
describe.skip('Alerts table', function () {
|
||||
before(async () => {
|
||||
await esArchiver.load('x-pack/test/functional/es_archives/observability/alerts');
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue