Skip to content

Commit 3e48031

Browse files
author
Bryan Soltis
committed
Fix ID collision bug when adding components after deletion and modal footer visibility
- Fixed ID assignment in ResourceComponentService, CustomComponentService, ResourceDelimiterService, and ResourceTypeService to use Max(ID)+1 instead of Count+1 - This prevents ID collisions when adding new items after deletions - Fixed AddModal footer being cut off by moving it inside modern-modal-content container - Updated modal CSS to properly handle scrolling body with fixed footer using flexbox layout
1 parent c23a1bd commit 3e48031

6 files changed

Lines changed: 14 additions & 15 deletions

File tree

src/Components/Modals/AddModal.razor

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@
272272
</div>
273273
</div>
274274
</div>
275-
</div>
276275

277-
<div class="modern-modal-footer">
278-
<button title="Add" @onclick="Save" class="modern-btn-success">Add</button>
279-
<button title="Cancel" @onclick="Cancel" class="modern-btn-secondary">Cancel</button>
276+
<div class="modern-modal-footer">
277+
<button title="Add" @onclick="Save" class="modern-btn-success">Add</button>
278+
<button title="Cancel" @onclick="Cancel" class="modern-btn-secondary">Cancel</button>
279+
</div>
280280
</div>
281281

282282
@code {

src/Services/CustomComponentService.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,16 @@ public async Task<ServiceResponse> PostItemAsync(CustomComponent item)
193193
// Set the new id
194194
if (item.Id == 0)
195195
{
196-
item.Id = items.Count + 1;
196+
// Use max ID + 1 instead of count + 1 to avoid ID collisions after deletions
197+
item.Id = items.Count > 0 ? items.Max(x => x.Id) + 1 : 1;
197198
}
198199

199200
int position = 1;
200201
items = [.. items.OrderBy(x => x.SortOrder)];
201202

202203
if (item.SortOrder == 0)
203204
{
204-
if (items.Count > 0)
205-
{
206-
item.Id = items.Max(t => t.Id) + 1;
207-
}
205+
item.SortOrder = items.Count + 1;
208206
}
209207

210208
// Determine new item id

src/Services/ResourceComponentService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ public async Task<ServiceResponse> PostItemAsync(ResourceComponent item)
124124
// Set the new id
125125
if (item.Id == 0)
126126
{
127-
item.Id = items.Count + 1;
127+
// Use max ID + 1 instead of count + 1 to avoid ID collisions after deletions
128+
item.Id = items.Count > 0 ? items.Max(x => x.Id) + 1 : 1;
128129
}
129130

130131
int position = 1;

src/Services/ResourceDelimiterService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ public async Task<ServiceResponse> PostItemAsync(ResourceDelimiter item)
150150
// Set the new id
151151
if (item.Id == 0)
152152
{
153-
item.Id = items.Count + 1;
153+
// Use max ID + 1 instead of count + 1 to avoid ID collisions after deletions
154+
item.Id = items.Count > 0 ? items.Max(x => x.Id) + 1 : 1;
154155
}
155156
item.Enabled = true;
156157
int position = 1;

src/Services/ResourceTypeService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,8 @@ public async Task<ServiceResponse> PostItemAsync(ResourceType item)
139139
// Set the new id
140140
if (item.Id == 0)
141141
{
142-
item.Id = items.Count + 1;
142+
// Use max ID + 1 instead of count + 1 to avoid ID collisions after deletions
143+
item.Id = items.Count > 0 ? items.Max(x => x.Id) + 1 : 1;
143144
}
144145

145146
// Determine new item id

src/wwwroot/css/modern-components.css

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2966,7 +2966,7 @@ h3.blazored-modal-title,
29662966
padding: 16px 24px;
29672967
border-top: 1px solid var(--color-border);
29682968
background-color: var(--color-bg-secondary);
2969-
margin-top: auto; /* Push footer to bottom when content is short */
2969+
flex-shrink: 0; /* Prevent footer from shrinking */
29702970
}
29712971

29722972
/* Modal Animations */
@@ -2996,7 +2996,6 @@ h3.blazored-modal-title,
29962996
display: flex;
29972997
flex-direction: column;
29982998
max-height: 85vh;
2999-
overflow-y: auto; /* Enable scrolling on the modal content */
30002999
line-height: 1.6; /* Consistent line height for readability */
30013000
font-size: 14px; /* Consistent font size */
30023001
}
@@ -3015,7 +3014,6 @@ h3.blazored-modal-title,
30153014
flex: 1;
30163015
overflow-y: auto;
30173016
padding: 1.5rem;
3018-
max-height: calc(85vh - 120px); /* Account for header and footer */
30193017
line-height: 1.6; /* Consistent line height for readability */
30203018
font-size: 14px; /* Consistent font size */
30213019
}

0 commit comments

Comments
 (0)