| 29 | * Categorizes asset changes |
| 30 | */ |
| 31 | const categorizeChanges = (oldAssets, newAssets) => { |
| 32 | const oldMap = new Map(oldAssets.map(a => [a.name, a])); |
| 33 | const newMap = new Map(newAssets.map(a => [a.name, a])); |
| 34 | const changes = { added: [], removed: [], modified: [] }; |
| 35 | |
| 36 | for (const [name, oldAsset] of oldMap) { |
| 37 | const newAsset = newMap.get(name); |
| 38 | if (!newAsset) { |
| 39 | changes.removed.push({ name, size: oldAsset.size }); |
| 40 | } else if (oldAsset.size !== newAsset.size) { |
| 41 | changes.modified.push({ |
| 42 | name, |
| 43 | oldSize: oldAsset.size, |
| 44 | newSize: newAsset.size, |
| 45 | delta: newAsset.size - oldAsset.size, |
| 46 | }); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | for (const [name, newAsset] of newMap) { |
| 51 | if (!oldMap.has(name)) { |
| 52 | changes.added.push({ name, size: newAsset.size }); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | return changes; |
| 57 | }; |
| 58 | |
| 59 | /** |
| 60 | * Builds a collapsible table section |