Skip to content

Commit df5422c

Browse files
committed
feat(RHINENG-20424): fixed bugs and ux issues
1 parent 91236e5 commit df5422c

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

web/src/components/Incidents/IncidentsPage.tsx

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,6 @@ const IncidentsPage = () => {
124124
const incidentsActiveFilters = useSelector((state: MonitoringState) =>
125125
state.plugins.mcp.getIn(['incidentsData', 'incidentsActiveFilters']),
126126
);
127-
const incidentGroupId = useSelector((state: MonitoringState) =>
128-
state.plugins.mcp.getIn(['incidentsData', 'groupId']),
129-
);
130127
const alertsData = useSelector((state: MonitoringState) =>
131128
state.plugins.mcp.getIn(['incidentsData', 'alertsData']),
132129
);
@@ -142,6 +139,7 @@ const IncidentsPage = () => {
142139
state.plugins.mcp.getIn(['incidentsData', 'incidentPageFilterType']),
143140
);
144141

142+
const selectedGroupId = incidentsActiveFilters.groupId?.[0] ?? null;
145143
useEffect(() => {
146144
const hasUrlParams = Object.keys(urlParams).length > 0;
147145
if (hasUrlParams) {
@@ -170,7 +168,7 @@ const IncidentsPage = () => {
170168
}, []);
171169

172170
useEffect(() => {
173-
updateBrowserUrl(incidentsActiveFilters, incidentGroupId);
171+
updateBrowserUrl(incidentsActiveFilters, selectedGroupId);
174172
}, [incidentsActiveFilters]);
175173

176174
useEffect(() => {
@@ -284,13 +282,13 @@ const IncidentsPage = () => {
284282
}, [timeRanges]);
285283

286284
useEffect(() => {
287-
if (incidentGroupId) {
285+
if (selectedGroupId) {
288286
Promise.all(
289287
timeRanges.map(async (range) => {
290288
const response = await fetchDataForIncidentsAndAlerts(
291289
safeFetch,
292290
range,
293-
`cluster:health:components:map{group_id='${incidentGroupId}'}`,
291+
`cluster:health:components:map{group_id='${selectedGroupId}'}`,
294292
perspective,
295293
);
296294
return response.data.result;
@@ -307,7 +305,7 @@ const IncidentsPage = () => {
307305
console.log(err);
308306
});
309307
}
310-
}, [incidentGroupId, timeRanges]);
308+
}, [selectedGroupId, timeRanges]);
311309

312310
const onSelect = (_event, value) => {
313311
if (value) {
@@ -334,7 +332,7 @@ const IncidentsPage = () => {
334332
<Toolbar
335333
id="toolbar-with-filter"
336334
collapseListedFiltersBreakpoint="xl"
337-
clearAllFilters={() =>
335+
clearAllFilters={() => {
338336
dispatch(
339337
setIncidentsActiveFilters({
340338
incidentsActiveFilters: {
@@ -344,8 +342,9 @@ const IncidentsPage = () => {
344342
groupId: [],
345343
},
346344
}),
347-
)
348-
}
345+
);
346+
dispatch(setAlertsAreLoading({ alertsAreLoading: true }));
347+
}}
349348
>
350349
<ToolbarContent>
351350
<ToolbarGroup>
@@ -373,6 +372,7 @@ const IncidentsPage = () => {
373372
{incidentPageFilterTypeSelected}
374373
</MenuToggle>
375374
)}
375+
style={{ width: '145px' }}
376376
>
377377
<SelectOption
378378
value="Severity"
@@ -394,7 +394,9 @@ const IncidentsPage = () => {
394394
</SelectOption>
395395
</Select>
396396
</ToolbarItem>
397-
<ToolbarItem>
397+
<ToolbarItem
398+
className={incidentPageFilterTypeSelected !== 'Severity' ? 'pf-m-hidden' : ''}
399+
>
398400
<IncidentFilterToolbarItem
399401
categoryName="Severity"
400402
toggleLabel="Severity filters"
@@ -414,7 +416,9 @@ const IncidentsPage = () => {
414416
showToolbarItem={incidentPageFilterTypeSelected?.includes('Severity')}
415417
/>
416418
</ToolbarItem>
417-
<ToolbarItem>
419+
<ToolbarItem
420+
className={incidentPageFilterTypeSelected !== 'State' ? 'pf-m-hidden' : ''}
421+
>
418422
<IncidentFilterToolbarItem
419423
categoryName="State"
420424
toggleLabel="State filters"
@@ -434,7 +438,11 @@ const IncidentsPage = () => {
434438
showToolbarItem={incidentPageFilterTypeSelected?.includes('State')}
435439
/>
436440
</ToolbarItem>
437-
<ToolbarItem>
441+
<ToolbarItem
442+
className={
443+
incidentPageFilterTypeSelected !== 'Incident ID' ? 'pf-m-hidden' : ''
444+
}
445+
>
438446
<IncidentFilterToolbarItem
439447
categoryName="Incident ID"
440448
toggleLabel="Incident ID filters"
@@ -445,7 +453,7 @@ const IncidentsPage = () => {
445453
incidentFilterIsExpanded={filtersExpanded.groupId}
446454
onIncidentFiltersSelect={onIncidentFiltersSelect}
447455
setIncidentIsExpanded={(isExpanded) =>
448-
setFiltersExpanded((prev) => ({ ...prev, incidentId: isExpanded }))
456+
setFiltersExpanded((prev) => ({ ...prev, groupId: isExpanded }))
449457
}
450458
onIncidentFilterToggle={(ev) =>
451459
onFilterToggle(ev, 'groupId', setFiltersExpanded)

web/src/components/Incidents/ToolbarItemFilter.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ const IncidentFilterToolbarItem: React.FC<IncidentFilterToolbarItemProps> = ({
119119
option.value,
120120
)}
121121
description={option?.description}
122-
hasCheckbox
122+
hasCheckbox={categoryName === 'Incident ID' ? false : true}
123123
>
124124
{option.value}
125125
</SelectOption>

web/src/components/Incidents/incidents-styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@
2828

2929
.incidents-page-main-section.pf-v6-c-page__main-section {
3030
gap: 0;
31+
}
32+
33+
.pf-m-hidden {
34+
display: none;
3135
}

web/src/components/Incidents/utils.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,12 @@ export const changeDaysFilter = (
479479
) => {
480480
dispatch(
481481
setIncidentsActiveFilters({
482-
incidentsActiveFilters: { days: [days], severity: filters.severity, state: filters.state },
482+
incidentsActiveFilters: {
483+
days: [days],
484+
severity: filters.severity,
485+
state: filters.state,
486+
groupId: filters.groupId,
487+
},
483488
}),
484489
);
485490
};
@@ -523,7 +528,6 @@ export const onIncidentFiltersSelect = (
523528
* @returns {void}
524529
*/
525530
const onSelect = (event, selection, dispatch, incidentsActiveFilters, filterCategoryType) => {
526-
const checked = event.target.checked;
527531
let effectiveFilterType = filterCategoryType;
528532

529533
if (effectiveFilterType === 'incident id') {
@@ -534,19 +538,19 @@ const onSelect = (event, selection, dispatch, incidentsActiveFilters, filterCate
534538
const targetArray = incidentsActiveFilters[effectiveFilterType] || [];
535539
const newFilters = { ...incidentsActiveFilters };
536540

541+
// Determine if the item is already selected by checking the current state.
542+
// This replaces the need for event.target.checked.
543+
const isSelected = targetArray.includes(selection);
544+
537545
if (effectiveFilterType === 'groupId') {
538-
if (checked) {
539-
newFilters[effectiveFilterType] = [selection];
540-
} else {
541-
newFilters[effectiveFilterType] = [];
542-
}
546+
// Single-select logic: If already selected, unselect it. Otherwise, select it.
547+
newFilters[effectiveFilterType] = isSelected ? [] : [selection];
543548
} else {
544-
if (checked) {
545-
if (!targetArray.includes(selection)) {
546-
newFilters[effectiveFilterType] = [...targetArray, selection];
547-
}
548-
} else {
549+
// Multi-select logic: If already selected, remove it. Otherwise, add it.
550+
if (isSelected) {
549551
newFilters[effectiveFilterType] = targetArray.filter((value) => value !== selection);
552+
} else {
553+
newFilters[effectiveFilterType] = [...targetArray, selection];
550554
}
551555
}
552556

@@ -593,6 +597,7 @@ export const getIncidentIdOptions = (incidents: Array<Incident>) => {
593597
});
594598
return Array.from(uniqueIds).map((id) => ({
595599
value: id,
600+
description: `Incident ID: ${id}`,
596601
}));
597602
};
598603

0 commit comments

Comments
 (0)