@@ -75,7 +75,8 @@ export const SortableGroupWidget: React.FC<Props> = ({
7575
7676 // Handle item changes (reordering within the group)
7777 const handleItemsChange = useCallback ( async ( newItems : GroupItem [ ] ) => {
78- if ( ! config ) return ;
78+ // Ensure config exists with defaults for new groups
79+ const safeConfig = config || { maxItems : '3' , showLabel : true , items : [ ] } ;
7980
8081 // Update the group widget config directly using saveLayout instead of updateItem
8182 // to avoid triggering any unexpected state changes
@@ -84,7 +85,8 @@ export const SortableGroupWidget: React.FC<Props> = ({
8485 return {
8586 ...layoutItem ,
8687 config : {
87- ...layoutItem . config ,
88+ ...safeConfig , // Use safeConfig which includes defaults
89+ ...layoutItem . config , // Preserve any existing config
8890 items : newItems
8991 }
9092 } ;
@@ -97,7 +99,7 @@ export const SortableGroupWidget: React.FC<Props> = ({
9799
98100 // Update local state to reflect the change
99101 setDashboardLayout ( updatedLayout ) ;
100- } , [ id , config , dashboardLayout , saveLayout , setDashboardLayout ] ) ;
102+ } , [ id , dashboardLayout , saveLayout , setDashboardLayout , config ] ) ;
101103
102104 // Get a group item as a dashboard item for editing
103105 const getItemAsDashboardItem = useCallback ( ( itemId : string ) : DashboardItem | null => {
@@ -150,7 +152,9 @@ export const SortableGroupWidget: React.FC<Props> = ({
150152
151153 // Function to update a group item after it has been edited
152154 const updateGroupItem = useCallback ( async ( itemId : string , updatedItem : DashboardItem ) => {
153- if ( ! config ?. items ) return ;
155+ // Ensure config exists with defaults for new groups
156+ const safeConfig = config || { maxItems : '3' , showLabel : true , items : [ ] } ;
157+ const currentItems = safeConfig . items || [ ] ;
154158
155159 // Create an updated GroupItem from the updated DashboardItem
156160 const updatedGroupItem : GroupItem = {
@@ -176,7 +180,7 @@ export const SortableGroupWidget: React.FC<Props> = ({
176180 }
177181
178182 // Replace the item in the group's items array
179- const updatedItems = config . items . map ( item =>
183+ const updatedItems = currentItems . map ( item =>
180184 item . id === itemId ? updatedGroupItem : item
181185 ) ;
182186
@@ -187,7 +191,8 @@ export const SortableGroupWidget: React.FC<Props> = ({
187191 return {
188192 ...layoutItem ,
189193 config : {
190- ...layoutItem . config ,
194+ ...safeConfig , // Use safeConfig which includes defaults
195+ ...layoutItem . config , // Preserve any existing config
191196 items : updatedItems
192197 }
193198 } ;
@@ -200,7 +205,7 @@ export const SortableGroupWidget: React.FC<Props> = ({
200205
201206 // Update local state to reflect the change
202207 setDashboardLayout ( updatedLayout ) ;
203- } , [ config , id , dashboardLayout , saveLayout , setDashboardLayout ] ) ;
208+ } , [ id , dashboardLayout , saveLayout , setDashboardLayout , config ] ) ;
204209
205210 // Function to notify about dragging a group item
206211 const notifyGroupItemDrag = useCallback ( ( isDragging : boolean , itemId ?: string ) => {
@@ -320,17 +325,22 @@ export const SortableGroupWidget: React.FC<Props> = ({
320325
321326 // Add an app shortcut to the group
322327 const addAppShortcutToGroup = useCallback ( ( shortcutItem : DashboardItem ) => {
323- if ( ! config || ! dashboardLayout ) {
324- console . error ( 'Missing config or dashboardLayout' ) ;
328+ if ( ! dashboardLayout ) {
329+ console . error ( 'Missing dashboardLayout' ) ;
325330 return ;
326331 }
327332
333+ // Ensure config exists with defaults for new groups
334+ const safeConfig = config || { maxItems : '3' , showLabel : true , items : [ ] } ;
335+
328336 // Use the configured maxItems or parse from the special format strings
329- const maxItemsStr = String ( config . maxItems || 3 ) ;
337+ const maxItemsStr = String ( safeConfig . maxItems || 3 ) ;
330338 let MAX_ITEMS = 3 ;
331339
332340 if ( maxItemsStr === '6_2x3' || maxItemsStr === '6_3x2' ) {
333341 MAX_ITEMS = 6 ;
342+ } else if ( maxItemsStr === '8_4x2' ) {
343+ MAX_ITEMS = 8 ;
334344 } else {
335345 MAX_ITEMS = parseInt ( maxItemsStr , 10 ) || 3 ;
336346 }
@@ -400,7 +410,8 @@ export const SortableGroupWidget: React.FC<Props> = ({
400410 }
401411
402412 updatedGroupWidget . config = {
403- ...updatedGroupWidget . config ,
413+ ...safeConfig , // Use safeConfig which includes defaults
414+ ...updatedGroupWidget . config , // Preserve any existing config
404415 items : updatedItems
405416 } ;
406417
@@ -411,7 +422,7 @@ export const SortableGroupWidget: React.FC<Props> = ({
411422
412423 // Save to server
413424 saveLayout ( updatedLayout ) ;
414- } , [ dashboardLayout , config , id , ensureItems , setDashboardLayout , saveLayout ] ) ;
425+ } , [ dashboardLayout , id , ensureItems , setDashboardLayout , saveLayout , config ] ) ;
415426
416427 // Get maximum items allowed in the group
417428 const getMaxItems = useCallback ( ( ) => {
0 commit comments