[Cases] Add search in attachment tab#246265
Conversation
|
Pinging @elastic/kibana-cases (Team:Cases) |
5d92d64 to
0614acb
Compare
| const totalAlerts = useMemo(() => { | ||
| return features.alerts.enabled | ||
| ? caseData.comments | ||
| .filter((comment) => comment.type === AttachmentType.alert) | ||
| .map((comment) => comment.alertId) | ||
| .flat().length | ||
| : 0; | ||
| }, [features.alerts.enabled, caseData.comments]); | ||
|
|
||
| const totalEvents = useMemo(() => { | ||
| return features.events.enabled | ||
| ? caseData.comments | ||
| .filter((comment) => comment.type === AttachmentType.event) | ||
| .map((comment) => comment.eventId) | ||
| .flat().length | ||
| : 0; | ||
| }, [features.events.enabled, caseData.comments]); | ||
|
|
There was a problem hiding this comment.
That's a lot of iterations that could be done in a single run:
const stats = useMemo(() => {
return caseData.comments.reduce(
(acc, comment) => {
if (comment.type === AttachmentType.alert && features.alerts.enabled) {
acc.totalAlerts = Array.isArray(comment.alertId)
? acc.totalAlerts + comment.alertId.length
: acc.totalAlerts + 1;
} else if (comment.type === AttachmentType.event && features.events.enabled) {
acc.totalEvents = Array.isArray(comment.eventId)
? acc.totalEvents + comment.eventId.length
: acc.totalEvents + 1;
}
return acc;
},
{ totalEvents: 0, totalAlerts: 0 }
);
}, [features, caseData]);There was a problem hiding this comment.
Actually, we might not want to run this logic, in case no searchterm was set:
const stats = useMemo(() => {
if (!searchTerm) {
return { totalAlerts: caseData.totalAlerts, totalEvents: caseData.totalEvents };
}
return caseData.comments.reduce(
(acc, comment) => {
if (comment.type === AttachmentType.alert && features.alerts.enabled) {
acc.totalAlerts = Array.isArray(comment.alertId)
? acc.totalAlerts + comment.alertId.length
: acc.totalAlerts + 1;
} else if (comment.type === AttachmentType.event && features.events.enabled) {
acc.totalEvents = Array.isArray(comment.eventId)
? acc.totalEvents + comment.eventId.length
: acc.totalEvents + 1;
}
return acc;
},
{ totalEvents: 0, totalAlerts: 0 }
);
}, [searchTerm, features, caseData]);There was a problem hiding this comment.
Thanks @janmonschke ! At first I thought the second approach would not work because of #245916, but the stats are recalculated every time the case is fetched 🙈
kibana/x-pack/platform/plugins/shared/cases/server/client/cases/get.ts
Lines 296 to 301 in f01d80a
| const { urlParams } = useUrlParams(); | ||
| const refreshCaseViewPage = useRefreshCaseViewPage(); | ||
|
|
||
| const [searchTerm, setSearchTerm] = useState<string>(''); |
There was a problem hiding this comment.
hey, I have 2 questions related to scenarios where we have some text input from user:
- Do we have some input validation utils or rules to be used across Kibana?
- Do we have any UX guidelines on debouncing user input?
There was a problem hiding this comment.
-
Depends on what you want to validate, for specific terms we write our own validators (as in observable form x-pack/platform/plugins/shared/cases/common/observables/validators.ts)
-
In this specific case, because I'm using EuiFieldSearch,
onSearchis only called when user pressEnter, but if you setincrementalto true, then it will fire as user types. The EUI team might have an opinion on it (like intervals if that's what you are asking?)
0cb4401 to
94c279a
Compare
💚 Build Succeeded
Metrics [docs]Async chunks
Page load bundle
History
|
Summary
Adds a search bar in attachment tab. Counts and table will reflect results based on search term. Supported search fields are:
Screen.Recording.2025-12-12.at.2.01.33.PM.mov
Checklist
release_note:breakinglabel should be applied in these situations.release_note:*label is applied per the guidelinesbackport:*labels.