Skip to content

Commit 6d24793

Browse files
committed
chore: cleanup
1 parent 89655f7 commit 6d24793

4 files changed

Lines changed: 33 additions & 19 deletions

File tree

oas_docs/output/kibana.serverless.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,9 +2906,6 @@ paths:
29062906
nullable: true
29072907
description: Payload of the attachment. Required unless `origin` is provided (content is resolved once at send time).
29082908
type: object
2909-
groupId:
2910-
description: Optional group identifier. Attachments sharing the same groupId are removed together in the UI.
2911-
type: string
29122909
hidden:
29132910
description: When true, the attachment will not be displayed in the UI.
29142911
type: boolean
@@ -3292,9 +3289,6 @@ paths:
32923289
nullable: true
32933290
description: Payload of the attachment. Required unless `origin` is provided (content is resolved once at send time).
32943291
type: object
3295-
groupId:
3296-
description: Optional group identifier. Attachments sharing the same groupId are removed together in the UI.
3297-
type: string
32983292
hidden:
32993293
description: When true, the attachment will not be displayed in the UI.
33003294
type: boolean

oas_docs/output/kibana.yaml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,9 +2976,6 @@ paths:
29762976
nullable: true
29772977
description: Payload of the attachment. Required unless `origin` is provided (content is resolved once at send time).
29782978
type: object
2979-
groupId:
2980-
description: Optional group identifier. Attachments sharing the same groupId are removed together in the UI.
2981-
type: string
29822979
hidden:
29832980
description: When true, the attachment will not be displayed in the UI.
29842981
type: boolean
@@ -3362,9 +3359,6 @@ paths:
33623359
nullable: true
33633360
description: Payload of the attachment. Required unless `origin` is provided (content is resolved once at send time).
33643361
type: object
3365-
groupId:
3366-
description: Optional group identifier. Attachments sharing the same groupId are removed together in the UI.
3367-
type: string
33683362
hidden:
33693363
description: When true, the attachment will not be displayed in the UI.
33703364
type: boolean

x-pack/platform/plugins/shared/agent_builder/public/application/context/conversation/upsert_attachments_into_list.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,21 @@ export const upsertAttachmentsIntoList = (
2424
): ConversationAttachment[] => {
2525
const existing = [...(existingAttachments ?? [])];
2626

27+
// Map of id -> attachment for the incoming list (only items with id). Used to update
28+
// existing entries in O(1). keyBy keeps last occurrence when ids repeat, which we want.
2729
const nextById = keyBy(
2830
nextAttachments.filter((a): a is ConversationAttachment & { id: string } => Boolean(a.id)),
2931
'id'
3032
);
3133

34+
// Ids already present in existing list — used to decide which next items are truly "new"
35+
// and should be appended (we must not re-append when we only meant to update by id).
3236
const existingIds = new Set(existing.map((a) => a.id).filter((id): id is string => Boolean(id)));
3337

38+
// Preserve existing order: each slot keeps its item or the updated version from nextById.
3439
const updated = existing.map((a) => (a.id && nextById[a.id] ? nextById[a.id] : a));
40+
41+
// Append only items that are new (no id) or whose id was not in the existing list.
3542
const newItems = nextAttachments.filter((a) => !a.id || !existingIds.has(a.id));
3643

3744
return [...updated, ...newItems];

x-pack/solutions/security/plugins/security_solution/public/agent_builder/helpers.test.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ describe('stringifyEssentialAlertData', () => {
8787
anotherNonEssential: ['shouldAlsoBeExcluded'],
8888
};
8989

90-
const parsed = JSON.parse(stringifyEssentialAlertData(rawData));
90+
const result = stringifyEssentialAlertData(rawData);
91+
const parsed = JSON.parse(result);
9192

9293
expect(parsed).toHaveProperty(ESSENTIAL_ALERT_FIELDS[0]);
9394
expect(parsed).toHaveProperty(ESSENTIAL_ALERT_FIELDS[1]);
@@ -96,18 +97,36 @@ describe('stringifyEssentialAlertData', () => {
9697
});
9798

9899
it('excludes non-essential fields', () => {
99-
const parsed = JSON.parse(
100-
stringifyEssentialAlertData({ field1: ['value1'], field2: ['value2'] })
101-
);
100+
const rawData: Record<string, string[]> = {
101+
field1: ['value1'],
102+
field2: ['value2'],
103+
};
104+
105+
const result = stringifyEssentialAlertData(rawData);
106+
const parsed = JSON.parse(result);
107+
102108
expect(Object.keys(parsed).length).toBe(0);
103109
});
104110

105111
it('returns valid JSON string', () => {
106-
const rawData = { [ESSENTIAL_ALERT_FIELDS[0]]: ['value1'] };
107-
expect(JSON.parse(stringifyEssentialAlertData(rawData))).toEqual(rawData);
112+
const rawData: Record<string, string[]> = {
113+
[ESSENTIAL_ALERT_FIELDS[0]]: ['value1'],
114+
};
115+
116+
const result = stringifyEssentialAlertData(rawData);
117+
118+
expect(() => JSON.parse(result)).not.toThrow();
119+
expect(JSON.parse(result)).toEqual({
120+
[ESSENTIAL_ALERT_FIELDS[0]]: ['value1'],
121+
});
108122
});
109123

110124
it('handles empty input', () => {
111-
expect(JSON.parse(stringifyEssentialAlertData({}))).toEqual({});
125+
const rawData: Record<string, string[]> = {};
126+
127+
const result = stringifyEssentialAlertData(rawData);
128+
const parsed = JSON.parse(result);
129+
130+
expect(parsed).toEqual({});
112131
});
113132
});

0 commit comments

Comments
 (0)