Skip to content

Commit 62419ef

Browse files
Fix modal window small issues (elastic#238143)
## Summary 1. If workflow has manual trigger and defined inputs default tab in run modal should be "Manual". Otherwise - "Alert" https://github.com/user-attachments/assets/e3bd8151-f450-43a9-adbc-32be41a30dd5 2. Fix selection for alerts - it broke because of unsafe handling of some nested objects "event.signal" on unflattening https://github.com/user-attachments/assets/c65630d3-5068-4acf-a9c1-db161e0a38cc 3. Fix crush of Index tab. The reason was unsafe adding nested objects as strings. Also mimic discovery style of displaying documents: <img width="1195" height="612" alt="image" src="https://github.com/user-attachments/assets/1b097f60-323a-4d82-b467-9195dcb7cd10" /> ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [ ] 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/src/platform/packages/shared/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [ ] [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 - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) - [ ] This was checked for breaking HTTP API changes, and any breaking changes have been approved by the breaking-change committee. The `release_note:breaking` label should be applied in these situations. - [ ] [Flaky Test Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was used on any tests changed - [ ] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) - [ ] Review the [backport guidelines](https://docs.google.com/document/d/1VyN5k91e5OVumlc0Gb9RPa3h1ewuPE705nRtioPiTvY/edit?usp=sharing) and apply applicable `backport:*` labels. ### Identify risks Does this PR introduce any risks? For example, consider risks like hard to test bugs, performance regression, potential of data loss. Describe the risk, its severity, and mitigation for each identified risk. Invite stakeholders and evaluate how to proceed before merging. - [ ] [See some risk examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) - [ ] ... --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
1 parent 4b575b5 commit 62419ef

4 files changed

Lines changed: 71 additions & 74 deletions

File tree

src/platform/plugins/shared/workflows_management/public/features/run_workflow/ui/workflow_execute_event_form.tsx

Lines changed: 4 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import {
1717
EuiText,
1818
EuiBasicTable,
1919
} from '@elastic/eui';
20-
import type { AuthenticatedUser } from '@kbn/security-plugin-types-common';
2120
import React, { useEffect, useState, useCallback } from 'react';
22-
import type { SecurityServiceStart } from '@kbn/core-security-browser';
2321
import { KBN_FIELD_TYPES } from '@kbn/field-types';
2422
import type { Query, TimeRange } from '@kbn/data-plugin/common';
2523
import { take } from 'rxjs';
@@ -47,36 +45,6 @@ interface WorkflowExecuteEventFormProps {
4745
setErrors: (errors: string | null) => void;
4846
}
4947

50-
const getDefaultWorkflowInput = (currentUser: any): string => {
51-
const userEmail = currentUser?.email || 'workflow-user@gmail.com';
52-
const userName = currentUser?.username || 'workflow-user';
53-
return JSON.stringify(
54-
{
55-
event: {
56-
ruleName: 'Detect vulnerabilities',
57-
additionalData: {
58-
user: userEmail,
59-
userName,
60-
},
61-
},
62-
},
63-
null,
64-
2
65-
);
66-
};
67-
68-
const getCurrentUser = async (security: SecurityServiceStart) => {
69-
try {
70-
if (security) {
71-
return await security.authc.getCurrentUser();
72-
}
73-
} catch (error) {
74-
// eslint-disable-next-line no-console
75-
console.error(error);
76-
}
77-
return null;
78-
};
79-
8048
const unflattenObject = (flatObject: Record<string, any>): Record<string, any> => {
8149
const result: Record<string, any> = {};
8250

@@ -86,12 +54,14 @@ const unflattenObject = (flatObject: Record<string, any>): Record<string, any> =
8654
for (let i = 0; i < keys.length; i++) {
8755
const currentKey = keys[i];
8856
if (i === keys.length - 1) {
89-
current[currentKey] = flatObject[key];
57+
const v = flatObject[key];
58+
current[currentKey] = v && typeof v === 'object' ? { ...v } : v;
9059
} else {
9160
if (
9261
current[currentKey] === undefined ||
9362
typeof current[currentKey] !== 'object' ||
94-
Array.isArray(current[currentKey])
63+
Array.isArray(current[currentKey]) ||
64+
!Object.isExtensible(current[currentKey]) // add this
9565
) {
9666
current[currentKey] = {};
9767
}
@@ -117,7 +87,6 @@ export const WorkflowExecuteEventForm = ({
11787
spaces,
11888
} = services;
11989
const [spaceId, setSpaceId] = useState<string | null>(null);
120-
const [currentUser, setCurrentUser] = useState<AuthenticatedUser | null>(null);
12190
const [alerts, setAlerts] = useState<Alert[]>([]);
12291
const [timeRange, setTimeRange] = useState<TimeRange>({
12392
from: 'now-15m',
@@ -203,17 +172,6 @@ export const WorkflowExecuteEventForm = ({
203172
}
204173
}, [fetchAlerts, spaceId]);
205174

206-
// Get current user
207-
useEffect(() => {
208-
if (!services.security) {
209-
setErrors('Security service not available');
210-
return;
211-
}
212-
getCurrentUser(services.security).then((user: AuthenticatedUser | null): void => {
213-
setCurrentUser(user);
214-
});
215-
}, [services.security, setErrors]);
216-
217175
const updateEventData = (selectedAlerts: Alert[]) => {
218176
if (selectedAlerts.length > 0) {
219177
const alertEvents = selectedAlerts.map((alert: Alert) => {
@@ -230,25 +188,13 @@ export const WorkflowExecuteEventForm = ({
230188
const workflowEvent = {
231189
event: {
232190
alerts: alertEvents,
233-
additionalData: {
234-
user: currentUser?.email || 'workflow-user@gmail.com',
235-
userName: currentUser?.username || 'workflow-user',
236-
},
237191
},
238192
};
239193

240194
setValue(JSON.stringify(workflowEvent, null, 2));
241-
} else {
242-
setValue(getDefaultWorkflowInput(currentUser));
243195
}
244196
};
245197

246-
useEffect(() => {
247-
if (!value && currentUser) {
248-
setValue(getDefaultWorkflowInput(currentUser));
249-
}
250-
}, [value, currentUser, setValue]);
251-
252198
const handleQueryChange = ({
253199
query: newQuery,
254200
dateRange,

src/platform/plugins/shared/workflows_management/public/features/run_workflow/ui/workflow_execute_index_form.tsx

Lines changed: 50 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ import {
1919
EuiToken,
2020
EuiDescriptionList,
2121
EuiPanel,
22+
EuiDescriptionListTitle,
23+
EuiDescriptionListDescription,
2224
} from '@elastic/eui';
2325
import { DataViewPicker } from '@kbn/unified-search-plugin/public';
2426
import { buildEsQuery, type Query, type TimeRange } from '@kbn/es-query';
2527
import type { DataView, DataViewListItem } from '@kbn/data-views-plugin/public';
2628
import { take } from 'rxjs';
2729
import type { SearchHit } from '@kbn/es-types';
2830
import type { IEsSearchRequest, IEsSearchResponse } from '@kbn/search-types';
31+
import { formatHit } from '@kbn/discover-utils';
2932
import { useKibana } from '../../../hooks/use_kibana';
3033

3134
interface Document {
@@ -42,6 +45,23 @@ interface WorkflowExecuteEventFormProps {
4245
setErrors: (errors: string | null) => void;
4346
}
4447

48+
const flattenObject = (obj: any, prefix = ''): Record<string, any> => {
49+
const flattened: Record<string, any> = {};
50+
51+
for (const [key, val] of Object.entries(obj)) {
52+
const fieldName = prefix ? `${prefix}.${key}` : key;
53+
54+
if (val && typeof val === 'object' && !Array.isArray(val)) {
55+
// Recursively flatten nested objects
56+
Object.assign(flattened, flattenObject(val, fieldName));
57+
} else {
58+
flattened[fieldName] = val;
59+
}
60+
}
61+
62+
return flattened;
63+
};
64+
4565
export const WorkflowExecuteIndexForm = ({
4666
value,
4767
setValue,
@@ -224,30 +244,48 @@ export const WorkflowExecuteIndexForm = ({
224244
field: '_source',
225245
name: 'Document',
226246
render: (source: any) => {
227-
const listItems: Array<{ title: string; description: string }> = [];
228-
['kind', 'agent', 'user', 'message'].forEach((field: string) => {
229-
if (source[field] === undefined) {
230-
return;
231-
}
232-
listItems.push({
233-
title: field,
234-
description: source[field] || '-',
235-
});
236-
});
247+
const flattened = flattenObject(source);
248+
249+
// Create a mock DataTableRecord-like object for formatHit
250+
const mockRecord = {
251+
raw: { _source: source },
252+
flattened,
253+
id: source && source._id ? source._id : undefined,
254+
isAnchor: false,
255+
};
256+
257+
// Use formatHit to get properly formatted field pairs
258+
const formattedPairs = formatHit(
259+
mockRecord,
260+
selectedDataView!,
261+
() => true, // Show all fields
262+
10, // Max entries
263+
services.fieldFormats
264+
);
265+
237266
return (
238267
<EuiFlexGroup alignItems="center" gutterSize="s">
239268
<EuiFlexItem grow={false}>
240269
<EuiToken iconType="tokenString" />
241270
</EuiFlexItem>
242271
<EuiFlexItem>
243-
<EuiDescriptionList type="inline" listItems={listItems} />
272+
<EuiDescriptionList type="inline">
273+
{formattedPairs.map(([title, description], index) => (
274+
<React.Fragment key={index}>
275+
<EuiDescriptionListTitle>{title}</EuiDescriptionListTitle>
276+
<EuiDescriptionListDescription
277+
dangerouslySetInnerHTML={{ __html: description || '-' }}
278+
/>
279+
</React.Fragment>
280+
))}
281+
</EuiDescriptionList>
244282
</EuiFlexItem>
245283
</EuiFlexGroup>
246284
);
247285
},
248286
},
249287
],
250-
[]
288+
[selectedDataView, services.fieldFormats]
251289
);
252290

253291
// Table selection configuration

src/platform/plugins/shared/workflows_management/public/features/run_workflow/ui/workflow_execute_modal.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
useEuiTheme,
2222
EuiText,
2323
} from '@elastic/eui';
24-
import React, { useState } from 'react';
24+
import React, { useState, useMemo } from 'react';
2525
import type { WorkflowYaml } from '@kbn/workflows';
2626
import { FormattedMessage } from '@kbn/i18n-react';
2727
import { Global, css } from '@emotion/react';
@@ -33,6 +33,20 @@ import { WorkflowExecuteManualForm } from './workflow_execute_manual_form';
3333

3434
type TriggerType = 'manual' | 'index' | 'alert';
3535

36+
function getDefaultTrigger(definition: WorkflowYaml | null): TriggerType {
37+
if (!definition) {
38+
return 'alert';
39+
}
40+
41+
const hasManualTrigger = definition.triggers?.some((trigger) => trigger.type === 'manual');
42+
const hasInputs = definition.inputs && definition.inputs.length > 0;
43+
44+
if (hasManualTrigger && hasInputs) {
45+
return 'manual';
46+
}
47+
return 'alert';
48+
}
49+
3650
export function WorkflowExecuteModal({
3751
definition,
3852
onClose,
@@ -44,7 +58,8 @@ export function WorkflowExecuteModal({
4458
}) {
4559
const modalTitleId = useGeneratedHtmlId();
4660
const enabledTriggers = ['alert', 'index', 'manual'];
47-
const [selectedTrigger, setSelectedTrigger] = useState<TriggerType>('alert');
61+
const defaultTrigger = useMemo(() => getDefaultTrigger(definition), [definition]);
62+
const [selectedTrigger, setSelectedTrigger] = useState<TriggerType>(defaultTrigger);
4863

4964
const [executionInput, setExecutionInput] = useState<string>('');
5065
const [executionInputErrors, setExecutionInputErrors] = useState<string | null>(null);

src/platform/plugins/shared/workflows_management/tsconfig.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"@kbn/workflows",
2525
"@kbn/zod",
2626
"@kbn/code-editor",
27-
"@kbn/security-plugin-types-common",
2827
"@kbn/monaco",
2928
"@kbn/actions-plugin",
3029
"@kbn/features-plugin",
@@ -43,7 +42,6 @@
4342
"@kbn/storybook",
4443
"@kbn/react-kibana-context-theme",
4544
"@kbn/core-chrome-layout",
46-
"@kbn/core-security-browser",
4745
"@kbn/react-kibana-context-theme",
4846
"@kbn/react-field",
4947
"@kbn/storage-adapter",

0 commit comments

Comments
 (0)