Skip to content

Commit cd3b574

Browse files
committed
Fix time instage and pallet status
1 parent 089840b commit cd3b574

File tree

1 file changed

+33
-40
lines changed

1 file changed

+33
-40
lines changed

frontend/src/components/PerPalletMigrationStatus.tsx

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -69,30 +69,12 @@ const PalletTimer: React.FC<{
6969
const PerPalletMigrationStatus: React.FC = () => {
7070
const [currentPage, setCurrentPage] = useState(0);
7171
const [palletStatuses, setPalletStatuses] = useState<Map<string, PalletStatus>>(new Map());
72-
72+
7373
const totalPages = Math.ceil(MIGRATION_PALLETS.length / PALLETS_PER_PAGE);
7474
const startIndex = currentPage * PALLETS_PER_PAGE;
7575
const endIndex = startIndex + PALLETS_PER_PAGE;
7676
const visiblePallets = MIGRATION_PALLETS.slice(startIndex, endIndex);
7777

78-
// Initialize pallet statuses
79-
useEffect(() => {
80-
const initialStatuses = new Map<string, PalletStatus>();
81-
MIGRATION_PALLETS.forEach(pallet => {
82-
initialStatuses.set(pallet, {
83-
palletName: pallet,
84-
status: 'pending',
85-
currentStage: null,
86-
timeInPallet: null,
87-
totalDuration: null,
88-
isCompleted: false,
89-
palletInitStartedAt: null,
90-
lastUpdated: Date.now(),
91-
});
92-
});
93-
setPalletStatuses(initialStatuses);
94-
}, []);
95-
9678
// Subscribe to rcStageUpdate events
9779
const handleStageUpdate = useCallback((eventType: string, data: any) => {
9880
if (eventType === 'rcStageUpdate') {
@@ -102,16 +84,18 @@ const PerPalletMigrationStatus: React.FC = () => {
10284
// If migration is done, mark all pallets as completed
10385
if (data.stage === 'MigrationDone') {
10486
MIGRATION_PALLETS.forEach(pallet => {
105-
const existing = newStatuses.get(pallet);
87+
const existing = newStatuses.get(pallet) || {
88+
palletName: pallet,
89+
status: 'pending' as const,
90+
currentStage: null,
91+
timeInPallet: null,
92+
totalDuration: null,
93+
isCompleted: false,
94+
palletInitStartedAt: null,
95+
lastUpdated: Date.now(),
96+
};
10697
newStatuses.set(pallet, {
107-
...(existing || {
108-
palletName: pallet,
109-
currentStage: null,
110-
timeInPallet: null,
111-
totalDuration: null,
112-
palletInitStartedAt: null,
113-
lastUpdated: Date.now(),
114-
}),
98+
...existing,
11599
status: 'completed',
116100
isCompleted: true,
117101
});
@@ -199,20 +183,27 @@ const PerPalletMigrationStatus: React.FC = () => {
199183
if (eventType === 'palletMigrationSummary') {
200184
setPalletStatuses(prev => {
201185
const newStatuses = new Map(prev);
202-
186+
203187
// Update each pallet with its migration data
204188
data.pallets.forEach((pallet: any) => {
205-
const existing = newStatuses.get(pallet.palletName);
206-
if (existing) {
207-
newStatuses.set(pallet.palletName, {
208-
...existing,
209-
itemsProcessed: pallet.totalItemsProcessed,
210-
itemsFailed: pallet.totalItemsFailed,
211-
lastUpdated: Date.now(),
212-
});
213-
}
189+
const existing = newStatuses.get(pallet.palletName) || {
190+
palletName: pallet.palletName,
191+
status: 'pending' as const,
192+
currentStage: null,
193+
timeInPallet: null,
194+
totalDuration: null,
195+
isCompleted: false,
196+
palletInitStartedAt: null,
197+
lastUpdated: Date.now(),
198+
};
199+
newStatuses.set(pallet.palletName, {
200+
...existing,
201+
itemsProcessed: pallet.totalItemsProcessed,
202+
itemsFailed: pallet.totalItemsFailed,
203+
lastUpdated: Date.now(),
204+
});
214205
});
215-
206+
216207
return newStatuses;
217208
});
218209
}
@@ -304,13 +295,15 @@ const PerPalletMigrationStatus: React.FC = () => {
304295
)}
305296
</td>
306297
<td>
307-
{status && (
298+
{status ? (
308299
<PalletTimer
309300
startTime={status.currentStage ? status.palletInitStartedAt : null}
310301
isCompleted={status.isCompleted}
311302
totalDuration={status.totalDuration}
312303
timeInPallet={status.timeInPallet}
313304
/>
305+
) : (
306+
<span>-</span>
314307
)}
315308
</td>
316309
</tr>

0 commit comments

Comments
 (0)