Skip to content

Commit 77f4473

Browse files
authored
Merge pull request #169 from Accedia/#5288-The-Mitchell-RPA-should-insert-data-in-the-estimate-ordered-according-to-the-Master-Group-list-ordering
#5288 the mitchell rpa should insert data in the estimate ordered according to the master group list ordering
2 parents 5291a67 + 86a7411 commit 77f4473

File tree

6 files changed

+112
-23
lines changed

6 files changed

+112
-23
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
export const ORDERED_GROUP_IDS: string[] = [
2+
'frontbumper',
3+
'grille',
4+
'frontlamps',
5+
'radiatorsupport',
6+
'cooling',
7+
'airconditioningheating',
8+
'hood',
9+
'fender',
10+
'frontinnerstructure',
11+
'frame',
12+
'electrical',
13+
'engine',
14+
'enginetransmount',
15+
'turbochargerintercooler',
16+
'transmissioncooler',
17+
'exhaustsystem',
18+
'emissionsystem',
19+
'wheels',
20+
'frontsuspension',
21+
'steeringgearlinkage',
22+
'steeringcolumn',
23+
'steeringwheel',
24+
'windshield',
25+
'cowl',
26+
'cab',
27+
'instrumentpanel',
28+
'console',
29+
'restraintsystem',
30+
'seats',
31+
'rollbarcomponents',
32+
'removabletop',
33+
'roof',
34+
'pillarsrockerfloor',
35+
'frontdoor',
36+
'reardoor',
37+
'sideloaddoor',
38+
'quarterpanel',
39+
'sidepanel',
40+
'backglass',
41+
'pickupbox',
42+
'fuelsystem',
43+
'rearsuspension',
44+
'rearbodyfloor',
45+
'decklid',
46+
'liftgate',
47+
'rearlamps',
48+
'rearbumper',
49+
'backdoor',
50+
'colordocumentation',
51+
'specificfasteners',
52+
'specificfluids',
53+
'stripetape',
54+
'vehiclediagnostics',
55+
'miscellaneousoperations',
56+
'recycledassemblies',
57+
];

electron-app/src/interfaces/Forgettable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export interface Forgettable {
1616
export interface MitchellForgettable {
1717
oper: string;
1818
description?: string;
19+
groupId?: string;
1920
quantity?: string;
2021
partPrice?: string;
2122
extPrice?: string;

electron-app/src/main.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { FirebaseService, SessionStatus } from './utils/firebase';
1515
import mitchell_importer from './utils/mitchell_importer';
1616
import { spawn } from 'child_process';
1717
import * as os from 'os';
18+
import { sortForgettablesByGroupId } from './utils/sort_forgettables';
1819

1920
const userHomeDir = os.homedir();
2021
const fitMitchellCloudPath = path.join(userHomeDir, 'AppData', 'Local', 'FIT-Mitchell_Cloud', 'FIT.bat');
@@ -70,16 +71,22 @@ class Main {
7071
const bat = spawn(fitMitchellCloudPath, [], { windowsHide: true });
7172
log.info('here');
7273
bat.on('error', (code) => {
73-
dialog.showErrorBox('Error', `The specified file was not found: ${fitMitchellCloudPath}. Please make sure that file FIT.bat is in the specified directory`);
74+
dialog.showErrorBox(
75+
'Error',
76+
`The specified file was not found: ${fitMitchellCloudPath}. Please make sure that file FIT.bat is in the specified directory`
77+
);
7478
app.quit();
75-
})
79+
});
7680
bat.on('close', (code) => {
7781
log.info(`Child process exited with code ${code}`);
7882
app.quit();
7983
});
8084
return;
8185
} catch (error) {
82-
dialog.showErrorBox('Error', 'The specified file was not found: C:\\FIT-Mitchell-Cloud-RO-Import-Tool\\FIT.bat');
86+
dialog.showErrorBox(
87+
'Error',
88+
'The specified file was not found: C:\\FIT-Mitchell-Cloud-RO-Import-Tool\\FIT.bat'
89+
);
8390
}
8491
}
8592
this.finalUrl = url;
@@ -174,6 +181,7 @@ class Main {
174181
/** Fetch the data. Replace localhost with [::1] because otherwise it does not work */
175182
url = url.replace('localhost', '[::1]');
176183
const { data } = await axios.get<ResponseData>(url);
184+
console.log(data);
177185
this.automationIdToFinishRPA = data.automationIdToFinishRPA;
178186
this.finalUrl = url;
179187
const existingUrl = store.get('url') as string | null;
@@ -183,6 +191,11 @@ class Main {
183191
}
184192
await FirebaseService.setSessionStatus(data.automationId, SessionStatus.APP_STARTED);
185193

194+
/** Sort forgettables by groupId before processing */
195+
if (data.forgettables && data.forgettables.length > 0) {
196+
data.forgettables = sortForgettablesByGroupId(data.forgettables);
197+
}
198+
console.log('Sorted forgettables:', data.forgettables);
186199
/** Do the population (CCC || Mitchell) */
187200
if (data.dataSource === 'Mitchell') {
188201
// await importer.startMitchellPopulation(data, this.windowManager.mainWindow);

electron-app/src/utils/get_custom_protocol_url.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ export const getCustomProtocolUrl = (argv: any): string => {
2222
// }
2323

2424
// return url;
25-
// };
25+
// };

electron-app/src/utils/mitchell_importer.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { isDev } from './is_dev';
1515
import { MitchellForgettable } from '../interfaces/Forgettable';
1616
import { times } from './times_do';
1717
import { VERIFICATION_PROGRESS_BREAKPOINT } from '../constants/verification_progress_breakpoint';
18+
import { sortForgettablesByGroupId } from './sort_forgettables';
1819

1920
enum 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();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { MitchellForgettable } from '../interfaces/Forgettable';
2+
import { ORDERED_GROUP_IDS } from '../constants/ordered_group_ids';
3+
4+
/**
5+
* Sorts forgettables by their groupId based on the order defined in ORDERED_GROUP_IDS.
6+
* Items with groupIds not in the list will be placed at the end.
7+
*/
8+
export const sortForgettablesByGroupId = (forgettables: MitchellForgettable[]): MitchellForgettable[] => {
9+
return [...forgettables].sort((a, b) => {
10+
const indexA = ORDERED_GROUP_IDS.indexOf(a.groupId || '');
11+
const indexB = ORDERED_GROUP_IDS.indexOf(b.groupId || '');
12+
13+
// If groupId not found in the ordered list, put it at the end
14+
const orderA = indexA === -1 ? ORDERED_GROUP_IDS.length : indexA;
15+
const orderB = indexB === -1 ? ORDERED_GROUP_IDS.length : indexB;
16+
17+
return orderA - orderB;
18+
});
19+
};

0 commit comments

Comments
 (0)