Skip to content

Commit 3fbc331

Browse files
fix: review comment
1 parent eb29a98 commit 3fbc331

File tree

3 files changed

+213
-280
lines changed

3 files changed

+213
-280
lines changed

src/migration/flexcard.ts

Lines changed: 121 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -409,26 +409,8 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
409409

410410
const stateAction = action.stateAction;
411411

412-
// 1. Handle message.value.bundle (DataRaptor) - message is JSON string
413-
// 2. Handle message.value.ipMethod (Integration Procedure) - message is JSON string
414-
if (stateAction.message && typeof stateAction.message === 'string') {
415-
try {
416-
const messageObj = JSON.parse(stateAction.message);
417-
if (messageObj.value) {
418-
// DataRaptor bundle
419-
if (messageObj.value.bundle) {
420-
this.addDataRaptorDependency(messageObj.value.bundle, flexCardAssessmentInfo);
421-
}
422-
// Integration Procedure ipMethod
423-
if (messageObj.value.ipMethod) {
424-
this.addIntegrationProcedureDependency(messageObj.value.ipMethod, flexCardAssessmentInfo);
425-
}
426-
}
427-
} catch (e) {
428-
// message is not valid JSON, skip
429-
Logger.logVerbose(`Failed to parse stateAction.message as JSON: ${e.message}`);
430-
}
431-
}
412+
// 1-2. Handle message.value.bundle (DataRaptor) and message.value.ipMethod (Integration Procedure)
413+
this.processStateActionMessageForDependencies(stateAction, flexCardAssessmentInfo);
432414

433415
// 3. Handle cardName (FlexCard - Flyout childCard)
434416
if (stateAction.cardName) {
@@ -470,6 +452,110 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
470452
}
471453
}
472454

455+
/**
456+
* Shared helper to update flyoutLwc value with registry (migration phase)
457+
* Handles both FlexCard child cards and OmniScript-derived LWC names
458+
*/
459+
private updateFlyoutLwcValue(stateAction: any): void {
460+
if (stateAction.flyoutLwc) {
461+
if (stateAction.flyoutType === Constants.ChildCard) {
462+
// flyoutLwc is a direct FlexCard name reference
463+
const lwcName = stateAction.flyoutLwc;
464+
if (this.nameRegistry.hasFlexCardMapping(lwcName)) {
465+
stateAction.flyoutLwc = this.nameRegistry.getFlexCardCleanedName(lwcName);
466+
} else {
467+
Logger.logVerbose(`\n${this.messages.getMessage('componentMappingNotFound', ['Flexcard', lwcName])}`);
468+
stateAction.flyoutLwc = this.cleanName(lwcName);
469+
}
470+
} else if (stateAction.flyoutType === Constants.OmniScriptPluralName && stateAction.osName) {
471+
// flyoutLwc is an OmniScript-derived LWC name - derive from already-updated osName
472+
stateAction.flyoutLwc = this.convertOsNameToLwcName(stateAction.osName);
473+
}
474+
}
475+
}
476+
477+
/**
478+
* Shared helper to process stateAction.message JSON for dependencies
479+
* Handles DataRaptor bundle and Integration Procedure ipMethod references
480+
*/
481+
private processStateActionMessageForDependencies(
482+
stateAction: any,
483+
flexCardAssessmentInfo: FlexCardAssessmentInfo
484+
): void {
485+
if (stateAction.message && typeof stateAction.message === 'string') {
486+
try {
487+
const messageObj = JSON.parse(stateAction.message);
488+
if (messageObj.value) {
489+
// DataRaptor bundle
490+
if (messageObj.value.bundle) {
491+
this.addDataRaptorDependency(messageObj.value.bundle, flexCardAssessmentInfo);
492+
}
493+
// Integration Procedure ipMethod
494+
if (messageObj.value.ipMethod) {
495+
this.addIntegrationProcedureDependency(messageObj.value.ipMethod, flexCardAssessmentInfo);
496+
}
497+
}
498+
} catch (e) {
499+
// message is not valid JSON, skip
500+
Logger.error(`Failed to parse stateAction.message as JSON: ${e.message}`);
501+
}
502+
}
503+
}
504+
505+
/**
506+
* Shared helper to process stateAction.message JSON with registry updates
507+
* Handles DataRaptor bundle and Integration Procedure ipMethod references
508+
*/
509+
private processStateActionMessageWithRegistry(stateAction: any, invalidIpNames?: Map<string, string>): void {
510+
if (stateAction.message && typeof stateAction.message === 'string') {
511+
try {
512+
const messageObj = JSON.parse(stateAction.message);
513+
let messageUpdated = false;
514+
515+
if (messageObj.value) {
516+
// DataRaptor bundle
517+
if (messageObj.value.bundle) {
518+
const originalBundle = messageObj.value.bundle;
519+
if (this.nameRegistry.hasDataMapperMapping(originalBundle)) {
520+
messageObj.value.bundle = this.nameRegistry.getDataMapperCleanedName(originalBundle);
521+
} else {
522+
Logger.logVerbose(
523+
`\n${this.messages.getMessage('componentMappingNotFound', ['DataMapper', originalBundle])}`
524+
);
525+
messageObj.value.bundle = this.cleanName(originalBundle);
526+
}
527+
messageUpdated = true;
528+
}
529+
530+
// Integration Procedure ipMethod
531+
if (messageObj.value.ipMethod) {
532+
const ipMethod = messageObj.value.ipMethod;
533+
if (this.nameRegistry.hasIntegrationProcedureMapping(ipMethod)) {
534+
messageObj.value.ipMethod = this.nameRegistry.getIntegrationProcedureCleanedName(ipMethod);
535+
} else {
536+
Logger.logVerbose(
537+
`\n${this.messages.getMessage('componentMappingNotFound', ['IntegrationProcedure', ipMethod])}`
538+
);
539+
const parts = ipMethod.split('_');
540+
messageObj.value.ipMethod = parts.map((p) => this.cleanName(p, true)).join('_');
541+
if (parts.length > 2 && invalidIpNames) {
542+
invalidIpNames.set(`event.actionList.stateAction.message`, ipMethod);
543+
}
544+
}
545+
messageUpdated = true;
546+
}
547+
}
548+
549+
if (messageUpdated) {
550+
stateAction.message = JSON.stringify(messageObj);
551+
}
552+
} catch (e) {
553+
// message is not valid JSON, skip
554+
Logger.error(`Failed to parse stateAction.message as JSON: ${e.message}`);
555+
}
556+
}
557+
}
558+
473559
private handleAssessmentForStdDataModelOrgsWithMetadataAPIEnabled(flexCards: AnyJson[]): FlexCardAssessmentInfo[] {
474560
Logger.logVerbose(this.messages.getMessage('preparingStorageForMetadataEnabledOrg', [Constants.Flexcard]));
475561
let storage: MigrationStorage = StorageUtil.getOmnistudioAssessmentStorage();
@@ -515,25 +601,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
515601
for (const action of component.property.actionList) {
516602
if (action.stateAction) {
517603
// Handle message field (contains DataRaptor/IP references as JSON string)
518-
// Applies to action types: cardAction, DataAction, etc.
519-
if (action.stateAction.message && typeof action.stateAction.message === 'string') {
520-
try {
521-
const messageObj = JSON.parse(action.stateAction.message);
522-
if (messageObj.value) {
523-
// DataRaptor bundle
524-
if (messageObj.value.bundle) {
525-
this.addDataRaptorDependency(messageObj.value.bundle, flexCardAssessmentInfo);
526-
}
527-
// Integration Procedure ipMethod
528-
if (messageObj.value.ipMethod) {
529-
this.addIntegrationProcedureDependency(messageObj.value.ipMethod, flexCardAssessmentInfo);
530-
}
531-
}
532-
} catch (e) {
533-
// message is not valid JSON, skip
534-
Logger.logVerbose(`Failed to parse stateAction.message as JSON: ${e.message}`);
535-
}
536-
}
604+
this.processStateActionMessageForDependencies(action.stateAction, flexCardAssessmentInfo);
537605

538606
// Case 1: Direct OmniScript reference
539607
if (action.stateAction.type === Constants.OmniScriptComponentName && action.stateAction.omniType) {
@@ -1270,55 +1338,8 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
12701338

12711339
const stateAction = action.stateAction;
12721340

1273-
// 1. Handle message.value.bundle (DataRaptor) - message is JSON string
1274-
// 2. Handle message.value.ipMethod (Integration Procedure) - message is JSON string
1275-
if (stateAction.message && typeof stateAction.message === 'string') {
1276-
try {
1277-
const messageObj = JSON.parse(stateAction.message);
1278-
let messageUpdated = false;
1279-
1280-
if (messageObj.value) {
1281-
// DataRaptor bundle
1282-
if (messageObj.value.bundle) {
1283-
const originalBundle = messageObj.value.bundle;
1284-
if (this.nameRegistry.hasDataMapperMapping(originalBundle)) {
1285-
messageObj.value.bundle = this.nameRegistry.getDataMapperCleanedName(originalBundle);
1286-
} else {
1287-
Logger.logVerbose(
1288-
`\n${this.messages.getMessage('componentMappingNotFound', ['DataMapper', originalBundle])}`
1289-
);
1290-
messageObj.value.bundle = this.cleanName(originalBundle);
1291-
}
1292-
messageUpdated = true;
1293-
}
1294-
1295-
// Integration Procedure ipMethod
1296-
if (messageObj.value.ipMethod) {
1297-
const ipMethod = messageObj.value.ipMethod;
1298-
if (this.nameRegistry.hasIntegrationProcedureMapping(ipMethod)) {
1299-
messageObj.value.ipMethod = this.nameRegistry.getIntegrationProcedureCleanedName(ipMethod);
1300-
} else {
1301-
Logger.logVerbose(
1302-
`\n${this.messages.getMessage('componentMappingNotFound', ['IntegrationProcedure', ipMethod])}`
1303-
);
1304-
const parts = ipMethod.split('_');
1305-
messageObj.value.ipMethod = parts.map((p) => this.cleanName(p, true)).join('_');
1306-
if (parts.length > 2) {
1307-
invalidIpNames.set(`event.actionList.stateAction.message`, ipMethod);
1308-
}
1309-
}
1310-
messageUpdated = true;
1311-
}
1312-
}
1313-
1314-
if (messageUpdated) {
1315-
stateAction.message = JSON.stringify(messageObj);
1316-
}
1317-
} catch (e) {
1318-
// message is not valid JSON, skip
1319-
Logger.logVerbose(`Failed to parse stateAction.message as JSON: ${e.message}`);
1320-
}
1321-
}
1341+
// 1-2. Handle message.value.bundle (DataRaptor) and message.value.ipMethod (Integration Procedure)
1342+
this.processStateActionMessageWithRegistry(stateAction, invalidIpNames);
13221343

13231344
// 3. Handle cardName (FlexCard - Flyout childCard)
13241345
if (stateAction.cardName) {
@@ -1344,21 +1365,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
13441365
}
13451366

13461367
// 6. Handle flyoutLwc (Custom LWC or FlexCard reference)
1347-
if (stateAction.flyoutLwc) {
1348-
if (stateAction.flyoutType === Constants.ChildCard) {
1349-
// flyoutLwc is a direct FlexCard name reference
1350-
const lwcName = stateAction.flyoutLwc;
1351-
if (this.nameRegistry.hasFlexCardMapping(lwcName)) {
1352-
stateAction.flyoutLwc = this.nameRegistry.getFlexCardCleanedName(lwcName);
1353-
} else {
1354-
Logger.logVerbose(`\n${this.messages.getMessage('componentMappingNotFound', ['Flexcard', lwcName])}`);
1355-
stateAction.flyoutLwc = this.cleanName(lwcName);
1356-
}
1357-
} else if (stateAction.flyoutType === Constants.OmniScriptPluralName && stateAction.osName) {
1358-
// flyoutLwc is an OmniScript-derived LWC name - derive from already-updated osName
1359-
stateAction.flyoutLwc = this.convertOsNameToLwcName(stateAction.osName);
1360-
}
1361-
}
1368+
this.updateFlyoutLwcValue(stateAction);
13621369
}
13631370
}
13641371
}
@@ -1442,51 +1449,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
14421449
for (const action of component.property.actionList) {
14431450
if (action.stateAction) {
14441451
// Handle message field (contains DataRaptor/IP references as JSON string)
1445-
// Applies to action types: cardAction, DataAction, etc.
1446-
if (action.stateAction.message && typeof action.stateAction.message === 'string') {
1447-
try {
1448-
const messageObj = JSON.parse(action.stateAction.message);
1449-
let messageUpdated = false;
1450-
1451-
if (messageObj.value) {
1452-
// DataRaptor bundle
1453-
if (messageObj.value.bundle) {
1454-
const originalBundle = messageObj.value.bundle;
1455-
if (this.nameRegistry.hasDataMapperMapping(originalBundle)) {
1456-
messageObj.value.bundle = this.nameRegistry.getDataMapperCleanedName(originalBundle);
1457-
} else {
1458-
Logger.logVerbose(
1459-
`\n${this.messages.getMessage('componentMappingNotFound', ['DataMapper', originalBundle])}`
1460-
);
1461-
messageObj.value.bundle = this.cleanName(originalBundle);
1462-
}
1463-
messageUpdated = true;
1464-
}
1465-
1466-
// Integration Procedure ipMethod
1467-
if (messageObj.value.ipMethod) {
1468-
const ipMethod = messageObj.value.ipMethod;
1469-
if (this.nameRegistry.hasIntegrationProcedureMapping(ipMethod)) {
1470-
messageObj.value.ipMethod = this.nameRegistry.getIntegrationProcedureCleanedName(ipMethod);
1471-
} else {
1472-
Logger.logVerbose(
1473-
`\n${this.messages.getMessage('componentMappingNotFound', ['IntegrationProcedure', ipMethod])}`
1474-
);
1475-
const parts = ipMethod.split('_');
1476-
messageObj.value.ipMethod = parts.map((p) => this.cleanName(p, true)).join('_');
1477-
}
1478-
messageUpdated = true;
1479-
}
1480-
}
1481-
1482-
if (messageUpdated) {
1483-
action.stateAction.message = JSON.stringify(messageObj);
1484-
}
1485-
} catch (e) {
1486-
// message is not valid JSON, skip
1487-
Logger.logVerbose(`Failed to parse stateAction.message as JSON: ${e.message}`);
1488-
}
1489-
}
1452+
this.processStateActionMessageWithRegistry(action.stateAction);
14901453

14911454
// Case 1: Direct OmniScript reference
14921455
if (action.stateAction.type === Constants.OmniScriptComponentName && action.stateAction.omniType) {
@@ -1496,22 +1459,12 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
14961459
else if (this.hasOmniscriptFlyoutDependency(action.stateAction)) {
14971460
// Update osName
14981461
this.updateOsNameWithRegistry(action.stateAction, 'osName');
1499-
// Also update flyoutLwc - it's the kebab-case LWC name derived from OmniScript
1500-
if (action.stateAction.flyoutLwc) {
1501-
action.stateAction.flyoutLwc = this.convertOsNameToLwcName(action.stateAction.osName);
1502-
}
1462+
// Update flyoutLwc
1463+
this.updateFlyoutLwcValue(action.stateAction);
15031464
}
1504-
// Case 3: Flyout childCard reference - flyoutLwc is a direct FlexCard name
1465+
// Case 3: Flyout childCard reference
15051466
else if (this.hasFlexCardFlyoutDependency(action.stateAction)) {
1506-
const originalFlyoutLwc = action.stateAction.flyoutLwc;
1507-
if (this.nameRegistry.hasFlexCardMapping(originalFlyoutLwc)) {
1508-
action.stateAction.flyoutLwc = this.nameRegistry.getFlexCardCleanedName(originalFlyoutLwc);
1509-
} else {
1510-
Logger.logVerbose(
1511-
`\n${this.messages.getMessage('componentMappingNotFound', ['Flexcard', originalFlyoutLwc])}`
1512-
);
1513-
action.stateAction.flyoutLwc = this.cleanName(originalFlyoutLwc);
1514-
}
1467+
this.updateFlyoutLwcValue(action.stateAction);
15151468
}
15161469
}
15171470
}
@@ -1555,22 +1508,12 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
15551508
}
15561509
if (this.hasOmniscriptFlyoutDependency(component.property.stateAction)) {
15571510
this.updateOsNameWithRegistry(component.property.stateAction, 'osName');
1558-
// Also update flyoutLwc - it's the kebab-case LWC name derived from OmniScript
1559-
if (component.property.stateAction.flyoutLwc) {
1560-
component.property.stateAction.flyoutLwc = this.convertOsNameToLwcName(component.property.stateAction.osName);
1561-
}
1511+
// Update flyoutLwc
1512+
this.updateFlyoutLwcValue(component.property.stateAction);
15621513
}
1563-
// Handle Flyout childCard reference - flyoutLwc is a direct FlexCard name
1514+
// Handle Flyout childCard reference
15641515
if (this.hasFlexCardFlyoutDependency(component.property.stateAction)) {
1565-
const originalFlyoutLwc = component.property.stateAction.flyoutLwc;
1566-
if (this.nameRegistry.hasFlexCardMapping(originalFlyoutLwc)) {
1567-
component.property.stateAction.flyoutLwc = this.nameRegistry.getFlexCardCleanedName(originalFlyoutLwc);
1568-
} else {
1569-
Logger.logVerbose(
1570-
`\n${this.messages.getMessage('componentMappingNotFound', ['Flexcard', originalFlyoutLwc])}`
1571-
);
1572-
component.property.stateAction.flyoutLwc = this.cleanName(originalFlyoutLwc);
1573-
}
1516+
this.updateFlyoutLwcValue(component.property.stateAction);
15741517
}
15751518
}
15761519

@@ -1619,12 +1562,8 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
16191562
: parts.map((p) => this.cleanName(p)).join('/');
16201563
}
16211564

1622-
// Also update flyoutLwc if it exists - it's the kebab-case LWC name derived from OmniScript
1623-
if (component.property.flyoutOmniScript.flyoutLwc) {
1624-
component.property.flyoutOmniScript.flyoutLwc = this.convertOsNameToLwcName(
1625-
component.property.flyoutOmniScript.osName
1626-
);
1627-
}
1565+
// Update flyoutLwc if it exists
1566+
this.updateFlyoutLwcValue(component.property.flyoutOmniScript);
16281567
}
16291568
}
16301569
}

0 commit comments

Comments
 (0)