diff --git a/src/components/ConfigurationSelector/ConfigSection.jsx b/src/components/ConfigurationSelector/ConfigSection.jsx index dccfb3a..a6c7c3c 100644 --- a/src/components/ConfigurationSelector/ConfigSection.jsx +++ b/src/components/ConfigurationSelector/ConfigSection.jsx @@ -1,9 +1,11 @@ import { useState } from 'react'; import ConfigOption from './ConfigOption'; +import { useSelection } from '../../context/SelectionContext'; const ConfigSection = ({ category, configs, isSearching }) => { const [expanded, setExpanded] = useState(true); const [prevIsSearching, setPrevIsSearching] = useState(isSearching); + const { isAllConfigCategorySelected, selectAllConfigsInCategory, deselectAllConfigsInCategory } = useSelection(); if (isSearching !== prevIsSearching) { setPrevIsSearching(isSearching); @@ -12,35 +14,75 @@ const ConfigSection = ({ category, configs, isSearching }) => { } } + const allSelected = isAllConfigCategorySelected(category.id); + + const handleSelectAll = (e) => { + e.stopPropagation(); + if (allSelected) { + deselectAllConfigsInCategory(category.id); + } else { + selectAllConfigsInCategory(category.id); + } + }; + return (
-
+
+ +
diff --git a/src/context/SelectionContext.jsx b/src/context/SelectionContext.jsx index 44fa2f0..7ee947f 100644 --- a/src/context/SelectionContext.jsx +++ b/src/context/SelectionContext.jsx @@ -1,5 +1,6 @@ import { createContext, useContext, useState, useEffect, useCallback, useMemo } from 'react'; import { softwareCatalog } from '../data/software-catalog'; +import { configurations } from '../data/configurations'; import { getCategoryItemIds } from '../utils/catalogHelpers'; import { STORAGE_KEYS } from '../constants'; @@ -73,9 +74,31 @@ export function SelectionProvider({ children }) { // Check if all items in category are selected const isAllCategorySelected = useCallback((categoryId) => { const categoryItems = getCategoryItemIds(softwareCatalog, categoryId); + if (categoryItems.length === 0) return false; return categoryItems.every((id) => selectedSoftware.includes(id)); }, [selectedSoftware]); + // Select all configurations in a category + const selectAllConfigsInCategory = useCallback((categoryId) => { + const categoryItems = getCategoryItemIds(configurations, categoryId); + setSelectedConfigs((prev) => [...new Set([...prev, ...categoryItems])]); + }, []); + + // Deselect all configurations in a category + const deselectAllConfigsInCategory = useCallback((categoryId) => { + const categoryItems = getCategoryItemIds(configurations, categoryId); + setSelectedConfigs((prev) => + prev.filter((id) => !categoryItems.includes(id)) + ); + }, []); + + // Check if all configurations in category are selected + const isAllConfigCategorySelected = useCallback((categoryId) => { + const categoryItems = getCategoryItemIds(configurations, categoryId); + if (categoryItems.length === 0) return false; + return categoryItems.every((id) => selectedConfigs.includes(id)); + }, [selectedConfigs]); + // Clear all selections const clearAll = useCallback(() => { setSelectedSoftware([]); @@ -100,6 +123,9 @@ export function SelectionProvider({ children }) { selectAllInCategory, deselectAllInCategory, isAllCategorySelected, + selectAllConfigsInCategory, + deselectAllConfigsInCategory, + isAllConfigCategorySelected, clearAll, clearSoftware, clearConfigs, @@ -111,6 +137,9 @@ export function SelectionProvider({ children }) { selectAllInCategory, deselectAllInCategory, isAllCategorySelected, + selectAllConfigsInCategory, + deselectAllConfigsInCategory, + isAllConfigCategorySelected, clearAll, clearSoftware, clearConfigs,