Skip to content

Commit 1d6fcaa

Browse files
fix: refactor code to update dependency references
1 parent 2e36976 commit 1d6fcaa

File tree

2 files changed

+33
-121
lines changed

2 files changed

+33
-121
lines changed

src/migration/flexcard.ts

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -608,27 +608,6 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
608608
if (!flexCardAssessmentInfo.dependenciesLWC.includes(lwcName)) {
609609
flexCardAssessmentInfo.dependenciesLWC.push(lwcName);
610610
}
611-
} else if (!flexCardAssessmentInfo.dependenciesLWC.includes(lwcName)) {
612-
// Regular LWC dependency
613-
flexCardAssessmentInfo.dependenciesLWC.push(lwcName);
614-
// Check if this is a FlexCard reference (starts with "cf" prefix)
615-
if (lwcName.startsWith('cf')) {
616-
const originalFlexCardName = lwcName.substring(2);
617-
const cleanedFlexCardName = this.cleanName(originalFlexCardName);
618-
if (originalFlexCardName !== cleanedFlexCardName) {
619-
flexCardAssessmentInfo.warnings.push(
620-
this.messages.getMessage('cardLWCNameChangeMessage', [originalFlexCardName, cleanedFlexCardName])
621-
);
622-
flexCardAssessmentInfo.migrationStatus = getUpdatedAssessmentStatus(
623-
flexCardAssessmentInfo.migrationStatus as
624-
| 'Warnings'
625-
| 'Needs manual intervention'
626-
| 'Ready for migration'
627-
| 'Failed',
628-
'Warnings'
629-
);
630-
}
631-
}
632611
}
633612
}
634613

@@ -1825,47 +1804,29 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
18251804
}
18261805
}
18271806

1828-
// 4. Handle flyoutLwc (Custom LWC or FlexCard reference)
1829-
if (stateAction.flyoutLwc) {
1830-
const lwcName = stateAction.flyoutLwc;
1807+
// 4. Handle omniType.Name (OmniScript)
1808+
if (stateAction.omniType && stateAction.omniType.Name) {
1809+
this.updateOmniTypeNameWithRegistry(stateAction.omniType);
1810+
}
18311811

1832-
// Check if this is a FlexCard reference when flyoutType is "childCard"
1812+
// 5. Handle osName (OmniScript - Flyout OmniScripts)
1813+
if (stateAction.osName && typeof stateAction.osName === 'string') {
1814+
this.updateOsNameWithRegistry(stateAction, 'osName');
1815+
}
1816+
1817+
// 6. Handle flyoutLwc (Custom LWC or FlexCard reference)
1818+
if (stateAction.flyoutLwc) {
18331819
if (stateAction.flyoutType === 'childCard') {
18341820
// flyoutLwc is a direct FlexCard name reference
1821+
const lwcName = stateAction.flyoutLwc;
18351822
if (this.nameRegistry.hasFlexCardMapping(lwcName)) {
18361823
stateAction.flyoutLwc = this.nameRegistry.getFlexCardCleanedName(lwcName);
18371824
} else {
18381825
Logger.logVerbose(`\n${this.messages.getMessage('componentMappingNotFound', ['Flexcard', lwcName])}`);
18391826
stateAction.flyoutLwc = this.cleanName(lwcName);
18401827
}
18411828
} else if (stateAction.flyoutType === Constants.OmniScriptPluralName && stateAction.osName) {
1842-
// flyoutLwc is an OmniScript-derived LWC name - will be updated after osName is processed
1843-
// (handled below after osName update)
1844-
} else if (lwcName.startsWith('cf')) {
1845-
// Check if this is a FlexCard reference (starts with "cf" prefix)
1846-
const originalFlexCardName = lwcName.substring(2);
1847-
if (this.nameRegistry.hasFlexCardMapping(originalFlexCardName)) {
1848-
stateAction.flyoutLwc = `cf${this.nameRegistry.getFlexCardCleanedName(originalFlexCardName)}`;
1849-
} else {
1850-
Logger.logVerbose(
1851-
`\n${this.messages.getMessage('componentMappingNotFound', ['Flexcard', originalFlexCardName])}`
1852-
);
1853-
stateAction.flyoutLwc = `cf${this.cleanName(originalFlexCardName)}`;
1854-
}
1855-
}
1856-
// Note: Non-cf LWC names that are not childCard flyouts don't need cleaning
1857-
}
1858-
1859-
// 5. Handle omniType.Name (OmniScript)
1860-
if (stateAction.omniType && stateAction.omniType.Name) {
1861-
this.updateOmniTypeNameWithRegistry(stateAction.omniType);
1862-
}
1863-
1864-
// 6. Handle osName (OmniScript - Flyout OmniScripts)
1865-
if (stateAction.osName && typeof stateAction.osName === 'string') {
1866-
this.updateOsNameWithRegistry(stateAction, 'osName');
1867-
// Also update flyoutLwc if it's an OmniScript-derived LWC name
1868-
if (stateAction.flyoutLwc && stateAction.flyoutType === Constants.OmniScriptPluralName) {
1829+
// flyoutLwc is an OmniScript-derived LWC name - derive from already-updated osName
18691830
stateAction.flyoutLwc = this.convertOsNameToLwcName(stateAction.osName);
18701831
}
18711832
}
@@ -2077,6 +2038,10 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
20772038
component.property.stateAction.osName
20782039
) {
20792040
this.updateOsNameWithRegistry(component.property.stateAction, 'osName');
2041+
// Also update flyoutLwc - it's the kebab-case LWC name derived from OmniScript
2042+
if (component.property.stateAction.flyoutLwc) {
2043+
component.property.stateAction.flyoutLwc = this.convertOsNameToLwcName(component.property.stateAction.osName);
2044+
}
20802045
}
20812046
// Handle Flyout childCard reference - flyoutLwc is a direct FlexCard name
20822047
if (
@@ -2140,6 +2105,13 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
21402105
? `${this.cleanName(parts[0])}/${this.cleanName(parts[1])}/${parts[2]}`
21412106
: parts.map((p) => this.cleanName(p)).join('/');
21422107
}
2108+
2109+
// Also update flyoutLwc if it exists - it's the kebab-case LWC name derived from OmniScript
2110+
if (component.property.flyoutOmniScript.flyoutLwc) {
2111+
component.property.flyoutOmniScript.flyoutLwc = this.convertOsNameToLwcName(
2112+
component.property.flyoutOmniScript.osName
2113+
);
2114+
}
21432115
}
21442116
}
21452117
}
@@ -2223,9 +2195,14 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
22232195

22242196
/**
22252197
* Convert OmniScript name (Type/SubType/Language) to kebab-case LWC component name
2198+
* The flyoutLwc is derived by converting each part of osName to kebab-case and joining with hyphens
22262199
* Example: "docGenerationSample/CoreSingleDocxLWC/English" -> "doc-generation-sample-core-single-docx-l-w-c-english"
2200+
* Example: "flexcard/dev/English" -> "flexcard-dev-english"
22272201
*/
22282202
private convertOsNameToLwcName(osName: string): string {
2203+
if (!osName) {
2204+
return '';
2205+
}
22292206
// Split by / and convert each part to kebab-case, then join with -
22302207
const parts = osName.split('/');
22312208
const kebabParts = parts.map((part) => this.camelToKebab(part));
@@ -2234,9 +2211,13 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
22342211

22352212
/**
22362213
* Convert camelCase or PascalCase string to kebab-case
2214+
* Example: "docGenerationSample" -> "doc-generation-sample"
22372215
* Example: "CoreSingleDocxLWC" -> "core-single-docx-l-w-c"
22382216
*/
22392217
private camelToKebab(str: string): string {
2218+
if (!str) {
2219+
return '';
2220+
}
22402221
return str
22412222
.replace(/([a-z0-9])([A-Z])/g, '$1-$2') // Insert hyphen between lowercase/digit and uppercase
22422223
.replace(/([A-Z])([A-Z][a-z])/g, '$1-$2') // Insert hyphen between consecutive uppercase followed by lowercase

test/migration/flexcard-standard-datamodel.test.ts

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -869,37 +869,6 @@ describe('FlexCard Standard Data Model (Metadata API Disabled) - Assessment and
869869
expect(result.dependenciesOS).to.have.length.greaterThan(0);
870870
expect(result.warnings).to.have.length.greaterThan(0);
871871
});
872-
873-
it('should detect LWC dependencies in events[].actionList[].stateAction.flyoutLwc with cf prefix', async () => {
874-
const mockFlexCard = {
875-
Id: 'fc_events_lwc',
876-
Name: 'EventsLWCCard',
877-
DataSourceConfig: JSON.stringify({ type: 'None' }),
878-
PropertySetConfig: JSON.stringify({
879-
layout: 'Card',
880-
states: [],
881-
events: [
882-
{
883-
actionList: [
884-
{
885-
stateAction: {
886-
flyoutLwc: 'cfFlyout-FlexCard@Name!',
887-
},
888-
},
889-
],
890-
},
891-
],
892-
}),
893-
IsActive: true,
894-
OmniUiCardType: 'Parent',
895-
VersionNumber: 1,
896-
};
897-
898-
const result = await (cardTool as any).processFlexCard(mockFlexCard, new Set<string>());
899-
900-
expect(result.dependenciesLWC).to.include('cfFlyout-FlexCard@Name!');
901-
expect(result.warnings).to.have.length.greaterThan(0);
902-
});
903872
});
904873

905874
describe('Events Array Reference Handling - Migration', () => {
@@ -1026,44 +995,6 @@ describe('FlexCard Standard Data Model (Metadata API Disabled) - Assessment and
1026995

1027996
expect(propertySetConfig.events[0].actionList[0].stateAction.cardName).to.equal('EventChildCardClean');
1028997
});
1029-
1030-
it('should update flyoutLwc with cf prefix in events using registry', () => {
1031-
nameRegistry.registerNameMapping({
1032-
originalName: 'FlyoutFlexCard',
1033-
cleanedName: 'FlyoutFlexCardClean',
1034-
componentType: 'FlexCard',
1035-
recordId: 'fc_flyout1',
1036-
});
1037-
1038-
const mockCardRecord = {
1039-
Id: 'fc_mig_events_lwc',
1040-
Name: 'MigEventsLWCCard',
1041-
DataSourceConfig: JSON.stringify({ type: 'None' }),
1042-
PropertySetConfig: JSON.stringify({
1043-
layout: 'Card',
1044-
states: [],
1045-
events: [
1046-
{
1047-
actionList: [
1048-
{
1049-
stateAction: {
1050-
flyoutLwc: 'cfFlyoutFlexCard',
1051-
},
1052-
},
1053-
],
1054-
},
1055-
],
1056-
}),
1057-
IsActive: true,
1058-
OmniUiCardType: 'Parent',
1059-
VersionNumber: 1,
1060-
};
1061-
1062-
const result = (cardTool as any).mapVlocityCardRecord(mockCardRecord, new Map(), new Map());
1063-
const propertySetConfig = JSON.parse(result.PropertySetConfig);
1064-
1065-
expect(propertySetConfig.events[0].actionList[0].stateAction.flyoutLwc).to.equal('cfFlyoutFlexCardClean');
1066-
});
1067998
});
1068999

10691000
describe('Events Array - Angular OmniScript Dependency Detection', () => {

0 commit comments

Comments
 (0)