Skip to content

Commit 9036e9a

Browse files
leSamobastilian
authored andcommitted
chore: Improve code clarity
1 parent bdc1f0f commit 9036e9a

File tree

1 file changed

+34
-59
lines changed

1 file changed

+34
-59
lines changed

src/Components/SmartComponents/Modals/OsExposureReportModal/OsExposureReportModal.js

Lines changed: 34 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -107,33 +107,17 @@ const OsExposureReportModal = ({
107107

108108
const CVE_REPORT_FILTERS = getCveReportFilters(false, true);
109109

110+
console.log('>>>', selectedOsVersions);
111+
110112
const selectedTotal = useMemo(() => {
111-
/**
112-
* Counts the total number of OS item objects in the provided data structure.
113-
*
114-
* @param {Array<Object>} selectedOsVersions - An array of dictionaries, where each dictionary
115-
* contains a key (e.g., "RHEL 8") and a value
116-
* that is an array of OS item objects.
117-
* @returns {number} An integer representing the total count of OS item objects.
118-
*/
119-
120-
// Initialize total_count to 0. This variable will store the cumulative count.
121113
let totalCount = 0;
122114

123-
// Iterate through each category object in the main dataStructure array.
124-
// For example, the first category object is { "RHEL 8": [...] }
125115
for (const categoryObject of selectedOsVersions) {
126-
// For each categoryObject, iterate through its keys.
127-
// For example, the key would be "RHEL 8" or "RHEL 7".
128116
for (const key in categoryObject) {
129-
// Ensure that the key belongs to the object itself and not its prototype.
130117
if (Object.prototype.hasOwnProperty.call(categoryObject, key)) {
131-
// Get the array of OS items associated with the current key.
132118
const osItemsArray = categoryObject[key];
133119

134-
// Check if osItemsArray is actually an array before trying to get its length.
135120
if (Array.isArray(osItemsArray)) {
136-
// Add the number of items in the current osItemsArray to the totalCount.
137121
totalCount += osItemsArray.length;
138122
} else {
139123
console.warn(`Expected an array for key "${key}", but found:`, osItemsArray);
@@ -142,7 +126,6 @@ const OsExposureReportModal = ({
142126
}
143127
}
144128

145-
// Return the final total count.
146129
return totalCount;
147130
}, [selectedOsVersions]);
148131

@@ -308,47 +291,39 @@ const OsExposureReportModal = ({
308291
<Flex>
309292
{selectedOsVersions.length === 0
310293
? <Text style={{ color: '#6a6e73' }}>
311-
Select at least 1 minor version of RHEL to further select the desired life cycle.
294+
Select at least 1 minor version of RHEL to further select the desired life cycle.
312295
</Text>
313-
: exposureMap.map(
314-
(majorVersionEntry, majorIndex) => {
315-
return (
316-
Object.entries(majorVersionEntry).map(
317-
([majorVersion, minorValues]) => {
318-
return (
319-
minorValues.map(({
320-
isSelected,
321-
os,
322-
osMinorVersion,
323-
lifecycles,
324-
selectedLifecycle
325-
}, minorIndex) => {
326-
if (isSelected) {
327-
return (
328-
<FlexItem key={`lifecycle-select-${os}`}>
329-
<LifecycleSelect
330-
isFetchLoading={isFetchLoading}
331-
lifecycles={lifecycles}
332-
osVersion={os}
333-
selectedLifecycle={selectedLifecycle}
334-
setSelectedLifecycle={(value) => setSelectedLifecycle(
335-
majorVersion,
336-
majorIndex,
337-
osMinorVersion,
338-
minorIndex,
339-
value
340-
)}
341-
/>
342-
</FlexItem>
343-
);
344-
}
345-
})
346-
);
347-
}
348-
)
349-
);
350-
}
351-
)
296+
: exposureMap.map((majorVersionEntry, majorIndex) => {
297+
Object.entries(majorVersionEntry).map(([majorVersion, minorValues]) =>
298+
minorValues.map(({
299+
isSelected,
300+
os,
301+
osMinorVersion,
302+
lifecycles,
303+
selectedLifecycle
304+
}, minorIndex) => {
305+
if (isSelected) {
306+
return (
307+
<FlexItem key={`lifecycle-select-${os}`}>
308+
<LifecycleSelect
309+
isFetchLoading={isFetchLoading}
310+
lifecycles={lifecycles}
311+
osVersion={os}
312+
selectedLifecycle={selectedLifecycle}
313+
setSelectedLifecycle={(value) => setSelectedLifecycle(
314+
majorVersion,
315+
majorIndex,
316+
osMinorVersion,
317+
minorIndex,
318+
value
319+
)}
320+
/>
321+
</FlexItem>
322+
);
323+
}
324+
})
325+
);
326+
})
352327
}
353328
</Flex>
354329
</FormGroup>

0 commit comments

Comments
 (0)