@@ -15,6 +15,7 @@ import { isDev } from './is_dev';
1515import { MitchellForgettable } from '../interfaces/Forgettable' ;
1616import { times } from './times_do' ;
1717import { VERIFICATION_PROGRESS_BREAKPOINT } from '../constants/verification_progress_breakpoint' ;
18+ import { sortForgettablesByGroupId } from './sort_forgettables' ;
1819
1920enum MitchellButtons {
2021 commitButton = 'COMMIT' ,
@@ -303,18 +304,22 @@ export class Mitchell_Importer extends Importer {
303304 forgettables : MitchellForgettable [ ] ,
304305 selectedTypeForCommit : string
305306 ) => {
307+ // Sort forgettables by groupId based on ORDERED_GROUP_IDS
308+ const sortedForgettables = sortForgettablesByGroupId ( forgettables ) ;
309+ console . log ( 'Sorted forgettables:' , sortedForgettables ) ;
310+
306311 const hasSelectedItemized = selectedTypeForCommit === 'Itemized' ;
307312 const hasSelectedBundled = selectedTypeForCommit === 'Bundled' ;
308313 const hasSeletedGrouped = selectedTypeForCommit === 'Grouped' ;
309- const numberOfInputs = forgettables . length * 8 ;
314+ const numberOfInputs = sortedForgettables . length * 8 ;
310315 const percentagePerCell = VERIFICATION_PROGRESS_BREAKPOINT / numberOfInputs ;
311316 this . progressUpdater . setStep ( percentagePerCell ) ;
312317 if ( hasSelectedItemized ) {
313- await this . populateItemized ( forgettables ) ;
318+ await this . populateItemized ( sortedForgettables ) ;
314319 } else if ( hasSelectedBundled ) {
315- await this . populateBundled ( forgettables ) ;
320+ await this . populateBundled ( sortedForgettables ) ;
316321 } else if ( hasSeletedGrouped ) {
317- await this . populateGrouped ( forgettables ) ;
322+ await this . populateGrouped ( sortedForgettables ) ;
318323 }
319324 } ;
320325
@@ -338,7 +343,6 @@ export class Mitchell_Importer extends Importer {
338343 await times ( 4 ) . pressKey ( Key . Tab ) ;
339344 await times ( 2 ) . pressKey ( Key . Down ) ; // Selecting Part Type to be Aftermarket New
340345
341-
342346 await keyboard . pressKey ( Key . Enter ) ; // Select it
343347 await keyboard . releaseKey ( Key . Enter ) ;
344348 await snooze ( 250 ) ;
@@ -353,7 +357,7 @@ export class Mitchell_Importer extends Importer {
353357 await keyboard . releaseKey ( Key . LeftShift ) ; // Release Left Shift
354358 await this . typeMitchellValue ( partNumber ) ; // Type Part Number
355359 this . progressUpdater . update ( ) ;
356- await snooze ( 250 )
360+ await snooze ( 250 ) ;
357361
358362 await this . pressTabButton ( 1 ) ; // Go to Quantity
359363 // // quantity is sometimes null if its a 0% and no update and it crashesh so we put default 1?
@@ -363,23 +367,22 @@ export class Mitchell_Importer extends Importer {
363367 await keyboard . type ( quantity . toString ( ) ) ;
364368 }
365369 this . progressUpdater . update ( ) ;
366- await snooze ( 250 )
367- await keyboard . pressKey ( Key . Tab )
368- await keyboard . releaseKey ( Key . Tab )
369- await snooze ( 250 )
370+ await snooze ( 250 ) ;
371+ await keyboard . pressKey ( Key . Tab ) ;
372+ await keyboard . releaseKey ( Key . Tab ) ;
373+ await snooze ( 250 ) ;
370374 // await this.pressTabButton(1); // Go to price
371375
372376 await this . typeMitchellValue ( partPrice ) ; // type totalPrice;
373377 this . progressUpdater . update ( ) ;
374- await snooze ( 250 )
378+ await snooze ( 250 ) ;
375379
376380 await this . pressTabButton ( 2 ) ; // go to (+More) button
377381 this . progressUpdater . update ( ) ;
378382
379383 await keyboard . pressKey ( Key . Enter ) ; // press Add Line with Enter to open Dropdown
380384 await keyboard . releaseKey ( Key . Enter ) ;
381- await snooze ( 250 )
382-
385+ await snooze ( 250 ) ;
383386
384387 await times ( 4 ) . pressKey ( Key . Down ) ; // Select Add New explanation
385388 await keyboard . pressKey ( Key . Enter ) ; // Press Add new explanation to open the textarea
@@ -458,7 +461,6 @@ export class Mitchell_Importer extends Importer {
458461 await times ( 4 ) . pressKey ( Key . Tab ) ;
459462 await times ( 2 ) . pressKey ( Key . Down ) ; // Selecting Part Type to be Aftermarket New
460463
461-
462464 await keyboard . pressKey ( Key . Enter ) ; // Select it
463465 await keyboard . releaseKey ( Key . Enter ) ;
464466 this . progressUpdater . update ( ) ;
@@ -474,18 +476,16 @@ export class Mitchell_Importer extends Importer {
474476 await keyboard . releaseKey ( Key . LeftShift ) ; // Release Left Shift
475477 this . progressUpdater . update ( ) ;
476478
477-
478479 await this . typeMitchellValue ( extPrice ) ; // type totalPrice;
479480 this . progressUpdater . update ( ) ;
480- await snooze ( 250 )
481+ await snooze ( 250 ) ;
481482
482483 await this . pressTabButton ( 2 ) ; // go to (+More) button
483484 this . progressUpdater . update ( ) ;
484485
485486 await keyboard . pressKey ( Key . Enter ) ; // press Add Line with Enter to open Dropdown
486487 await keyboard . releaseKey ( Key . Enter ) ;
487- await snooze ( 250 )
488-
488+ await snooze ( 250 ) ;
489489
490490 await times ( 4 ) . pressKey ( Key . Down ) ; // Select Add New explanation
491491 await keyboard . pressKey ( Key . Enter ) ; // Press Add new explanation to open the textarea
@@ -506,7 +506,6 @@ export class Mitchell_Importer extends Importer {
506506 }
507507 } ;
508508
509-
510509 private commitMitchellData = async ( commitButtonCoordinates : Point , electronWindow : BrowserWindow ) => {
511510 await mouse . setPosition ( commitButtonCoordinates ) ;
512511 await mouse . leftClick ( ) ;
0 commit comments