|
113 | 113 | })); |
114 | 114 | }); |
115 | 115 |
|
| 116 | + // Derived values for selected indices to ensure reactivity |
| 117 | + const selectedEVaultIndices = $derived( |
| 118 | + paginatedEVaults() |
| 119 | + .map((evault, index) => { |
| 120 | + const evaultId = evault.evault || evault.ename || evault.id; |
| 121 | + return selectedEVaults.includes(evaultId) ? index : -1; |
| 122 | + }) |
| 123 | + .filter((index) => index !== -1) |
| 124 | + ); |
| 125 | +
|
| 126 | + const selectedPlatformIndices = $derived( |
| 127 | + filteredPlatforms() |
| 128 | + .map((platform, index) => (selectedPlatforms.includes(platform.url) ? index : -1)) |
| 129 | + .filter((index) => index !== -1) |
| 130 | + ); |
| 131 | +
|
116 | 132 | const handlePreviousPage = async () => { |
117 | 133 | if (currentPage > 1) { |
118 | 134 | currentPage--; |
|
146 | 162 | selectedEVaults = selectedEVaults.filter((id) => id !== evaultId); |
147 | 163 | } |
148 | 164 |
|
149 | | - // Store selections immediately in sessionStorage |
150 | | - const selectedEVaultData = selectedEVaults |
151 | | - .map((id) => evaults.find((e) => (e.evault || e.ename || e.id) === id)) |
152 | | - .filter(Boolean); |
153 | | - sessionStorage.setItem('selectedEVaults', JSON.stringify(selectedEVaultData)); |
| 165 | + // Store selections immediately in sessionStorage (store as simple array of IDs) |
| 166 | + sessionStorage.setItem('selectedEVaults', JSON.stringify(selectedEVaults)); |
154 | 167 | } |
155 | 168 |
|
156 | 169 | // Handle platform selection changes |
|
167 | 180 | } |
168 | 181 |
|
169 | 182 | if (checked) { |
170 | | - selectedPlatforms = [...selectedPlatforms, selectedPlatform.name]; |
| 183 | + selectedPlatforms = [...selectedPlatforms, selectedPlatform.url]; |
171 | 184 | } else { |
172 | | - selectedPlatforms = selectedPlatforms.filter((name) => name !== selectedPlatform.name); |
| 185 | + selectedPlatforms = selectedPlatforms.filter((url) => url !== selectedPlatform.url); |
173 | 186 | } |
174 | 187 |
|
175 | | - // Store selections immediately in sessionStorage |
176 | | - const selectedPlatformData = selectedPlatforms |
177 | | - .map((name) => platforms.find((p) => p.name === name)) |
178 | | - .filter(Boolean); |
179 | | - sessionStorage.setItem('selectedPlatforms', JSON.stringify(selectedPlatformData)); |
| 188 | + // Store selections immediately in sessionStorage (store as simple array of URLs) |
| 189 | + sessionStorage.setItem('selectedPlatforms', JSON.stringify(selectedPlatforms)); |
180 | 190 | } |
181 | 191 |
|
182 | 192 | // Handle select all eVaults |
|
197 | 207 | console.log('❌ Deselected all eVaults, selectedEVaults:', selectedEVaults); |
198 | 208 | } |
199 | 209 |
|
200 | | - // Store selections immediately in sessionStorage |
201 | | - const selectedEVaultData = selectedEVaults |
202 | | - .map((id) => evaults.find((e) => e.evaultId === id)) |
203 | | - .filter(Boolean); |
204 | | - sessionStorage.setItem('selectedEVaults', JSON.stringify(selectedEVaultData)); |
205 | | - console.log('💾 Stored in sessionStorage:', selectedEVaultData); |
| 210 | + // Store selections immediately in sessionStorage (store as simple array of IDs) |
| 211 | + sessionStorage.setItem('selectedEVaults', JSON.stringify(selectedEVaults)); |
| 212 | + console.log('💾 Stored in sessionStorage:', selectedEVaults); |
206 | 213 | } |
207 | 214 |
|
208 | 215 | // Handle select all platforms |
|
214 | 221 | console.log('filtered platforms length:', filtered.length); |
215 | 222 |
|
216 | 223 | if (checked) { |
217 | | - // Select all filtered platforms by their name |
218 | | - selectedPlatforms = filtered.map((platform) => platform.name); |
| 224 | + // Select all filtered platforms by their URL |
| 225 | + selectedPlatforms = filtered.map((platform) => platform.url); |
219 | 226 | console.log( |
220 | 227 | '✅ Selected all filtered platforms, selectedPlatforms:', |
221 | 228 | selectedPlatforms |
|
226 | 233 | console.log('❌ Deselected all platforms, selectedPlatforms:', selectedPlatforms); |
227 | 234 | } |
228 | 235 |
|
229 | | - // Store selections immediately in sessionStorage |
230 | | - const selectedPlatformData = selectedPlatforms |
231 | | - .map((name) => platforms.find((p) => p.name === name)) |
232 | | - .filter(Boolean); |
233 | | - sessionStorage.setItem('selectedPlatforms', JSON.stringify(selectedPlatformData)); |
234 | | - console.log('💾 Stored in sessionStorage:', selectedPlatformData); |
| 236 | + // Store selections immediately in sessionStorage (store as simple array of URLs) |
| 237 | + sessionStorage.setItem('selectedPlatforms', JSON.stringify(selectedPlatforms)); |
| 238 | + console.log('💾 Stored in sessionStorage:', selectedPlatforms); |
235 | 239 | } |
236 | 240 |
|
237 | 241 | // Clear eVault selection |
238 | 242 | function clearEVaultSelection() { |
239 | 243 | selectedEVaults = []; |
240 | 244 | sessionStorage.removeItem('selectedEVaults'); |
| 245 | + sessionStorage.removeItem('selectedEVaultsData'); |
241 | 246 | } |
242 | 247 |
|
243 | 248 | // Clear platform selection |
244 | 249 | function clearPlatformSelection() { |
245 | 250 | selectedPlatforms = []; |
246 | 251 | sessionStorage.removeItem('selectedPlatforms'); |
| 252 | + sessionStorage.removeItem('selectedPlatformsData'); |
247 | 253 | } |
248 | 254 |
|
249 | 255 | // Navigate to monitoring with selected items |
250 | 256 | function goToMonitoring() { |
| 257 | + // Convert IDs/URLs to full objects for monitoring page |
251 | 258 | const selectedEVaultData = selectedEVaults |
252 | | - .map((id) => evaults.find((e) => e.evaultId === id)) |
| 259 | + .map((id) => evaults.find((e) => (e.evault || e.ename || e.id) === id)) |
253 | 260 | .filter(Boolean); |
254 | 261 | const selectedPlatformData = selectedPlatforms |
255 | | - .map((name) => platforms.find((p) => p.name === name)) |
| 262 | + .map((url) => platforms.find((p) => p.url === url)) |
256 | 263 | .filter(Boolean); |
257 | 264 |
|
258 | | - // Store selected data in sessionStorage to pass to monitoring page |
259 | | - sessionStorage.setItem('selectedEVaults', JSON.stringify(selectedEVaultData)); |
260 | | - sessionStorage.setItem('selectedPlatforms', JSON.stringify(selectedPlatformData)); |
| 265 | + // Store full objects in sessionStorage for monitoring page (it expects objects) |
| 266 | + // But also keep the simple arrays for persistence when returning |
| 267 | + sessionStorage.setItem('selectedEVaultsData', JSON.stringify(selectedEVaultData)); |
| 268 | + sessionStorage.setItem('selectedPlatformsData', JSON.stringify(selectedPlatformData)); |
| 269 | + // Keep simple arrays for persistence |
| 270 | + sessionStorage.setItem('selectedEVaults', JSON.stringify(selectedEVaults)); |
| 271 | + sessionStorage.setItem('selectedPlatforms', JSON.stringify(selectedPlatforms)); |
261 | 272 |
|
262 | 273 | goto('/monitoring'); |
263 | 274 | } |
|
354 | 365 | } |
355 | 366 | } |
356 | 367 |
|
| 368 | + // Restore selections from sessionStorage |
| 369 | + // Use an effect to restore selections when data is loaded |
| 370 | + let hasRestoredSelections = $state(false); |
| 371 | + $effect(() => { |
| 372 | + // Only restore once when both datasets are loaded |
| 373 | + // The flag prevents multiple restorations, and will reset on component remount |
| 374 | + if ( |
| 375 | + !isLoading && |
| 376 | + !platformsLoading && |
| 377 | + evaults.length >= 0 && |
| 378 | + platforms.length >= 0 && |
| 379 | + !hasRestoredSelections |
| 380 | + ) { |
| 381 | + hasRestoredSelections = true; |
| 382 | +
|
| 383 | + // Restore eVault selections - try simple array first, fallback to object array for backwards compatibility |
| 384 | + const storedEVaults = sessionStorage.getItem('selectedEVaults'); |
| 385 | + if (storedEVaults && evaults.length > 0) { |
| 386 | + try { |
| 387 | + const storedData = JSON.parse(storedEVaults); |
| 388 | +
|
| 389 | + // Check if it's a simple array of IDs or array of objects |
| 390 | + if (Array.isArray(storedData) && storedData.length > 0) { |
| 391 | + if (typeof storedData[0] === 'string') { |
| 392 | + // Simple array of IDs - filter to only include IDs that exist in current evaults |
| 393 | + selectedEVaults = storedData.filter((id: string) => |
| 394 | + evaults.some((e) => (e.evault || e.ename || e.id) === id) |
| 395 | + ); |
| 396 | + } else { |
| 397 | + // Array of objects (backwards compatibility) - extract IDs |
| 398 | + selectedEVaults = storedData |
| 399 | + .map((stored: any) => { |
| 400 | + const match = evaults.find( |
| 401 | + (e) => |
| 402 | + (stored.evault && e.evault === stored.evault) || |
| 403 | + (stored.ename && e.ename === stored.ename) || |
| 404 | + (stored.id && e.id === stored.id) || |
| 405 | + (stored.serviceUrl && |
| 406 | + e.serviceUrl === stored.serviceUrl) |
| 407 | + ); |
| 408 | + return match ? match.evault || match.ename || match.id : null; |
| 409 | + }) |
| 410 | + .filter((id: string | null): id is string => id !== null); |
| 411 | + } |
| 412 | + } |
| 413 | + console.log('✅ Restored eVault selections:', selectedEVaults); |
| 414 | + } catch (error) { |
| 415 | + console.error('Error restoring eVault selections:', error); |
| 416 | + } |
| 417 | + } |
| 418 | +
|
| 419 | + // Restore platform selections - try simple array first, fallback to object array for backwards compatibility |
| 420 | + const storedPlatforms = sessionStorage.getItem('selectedPlatforms'); |
| 421 | + if (storedPlatforms && platforms.length > 0) { |
| 422 | + try { |
| 423 | + const storedData = JSON.parse(storedPlatforms); |
| 424 | +
|
| 425 | + // Check if it's a simple array of URLs or array of objects |
| 426 | + if (Array.isArray(storedData) && storedData.length > 0) { |
| 427 | + if (typeof storedData[0] === 'string') { |
| 428 | + // Simple array of URLs - filter to only include URLs that exist in current platforms |
| 429 | + selectedPlatforms = storedData.filter((url: string) => |
| 430 | + platforms.some((p) => p.url === url) |
| 431 | + ); |
| 432 | + } else { |
| 433 | + // Array of objects (backwards compatibility) - extract URLs |
| 434 | + selectedPlatforms = storedData |
| 435 | + .map((stored: any) => { |
| 436 | + // Try to match by URL first, then by name for backwards compatibility |
| 437 | + const match = platforms.find( |
| 438 | + (p) => |
| 439 | + p.url === stored.url || |
| 440 | + (stored.name && p.name === stored.name) |
| 441 | + ); |
| 442 | + return match ? match.url : null; |
| 443 | + }) |
| 444 | + .filter((url: string | null): url is string => url !== null); |
| 445 | + } |
| 446 | + } |
| 447 | + console.log('✅ Restored platform selections:', selectedPlatforms); |
| 448 | + } catch (error) { |
| 449 | + console.error('Error restoring platform selections:', error); |
| 450 | + } |
| 451 | + } |
| 452 | + } |
| 453 | + }); |
| 454 | +
|
357 | 455 | onMount(() => { |
358 | 456 | fetchEVaults(); |
359 | 457 | fetchPlatforms(); |
|
403 | 501 | handleSelectedRow={handleEVaultRowClick} |
404 | 502 | onSelectionChange={handleEVaultSelectionChange} |
405 | 503 | onSelectAllChange={handleSelectAllEVaults} |
406 | | - selectedIndices={paginatedEVaults() |
407 | | - .map((evault, index) => { |
408 | | - const evaultId = evault.evault || evault.ename || evault.id; |
409 | | - return selectedEVaults.includes(evaultId) ? index : -1; |
410 | | - }) |
411 | | - .filter((index) => index !== -1)} |
| 504 | + selectedIndices={selectedEVaultIndices} |
412 | 505 | /> |
413 | 506 |
|
414 | 507 | <!-- Pagination Info --> |
|
480 | 573 | withPagination={false} |
481 | 574 | onSelectionChange={handlePlatformSelectionChange} |
482 | 575 | onSelectAllChange={handleSelectAllPlatforms} |
483 | | - selectedIndices={filteredPlatforms() |
484 | | - .map((platform, index) => |
485 | | - selectedPlatforms.includes(platform.name) ? index : -1 |
486 | | - ) |
487 | | - .filter((index) => index !== -1)} |
| 576 | + selectedIndices={selectedPlatformIndices} |
488 | 577 | /> |
489 | 578 | {/if} |
490 | 579 | </TableCard> |
|
0 commit comments