Skip to content

Commit b4bf1d1

Browse files
chore: flexcard to be enabled for community
1 parent 3b89f8d commit b4bf1d1

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

src/migration/flexcard.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
8989
async migrate(): Promise<MigrationResult[]> {
9090
// Get All the Active VlocityCard__c records
9191
const allCards = await this.getAllActiveCards();
92+
9293
Logger.log(this.messages.getMessage('foundFlexCardsToMigrate', [allCards.length]));
9394

9495
// Filter out FlexCards with Angular OmniScript dependencies
@@ -1041,6 +1042,8 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
10411042
mappedObject[CardMappings.Datasource__c] = JSON.stringify(datasource);
10421043
}
10431044

1045+
this.ensureCommunityTargets(mappedObject);
1046+
10441047
// Update all dependencies comprehensively
10451048
this.updateAllDependenciesWithRegistry(mappedObject, invalidIpNames);
10461049

@@ -1532,4 +1535,42 @@ export class CardMigrationTool extends BaseMigrationTool implements MigrationToo
15321535

15331536
return false;
15341537
}
1538+
1539+
/**
1540+
* Ensures that the FlexCard Definition includes required Lightning Community targets
1541+
* Adds "lightningCommunity__Page" and "lightningCommunity__Default" if missing
1542+
*/
1543+
private ensureCommunityTargets(mappedObject: any): void {
1544+
const definition = JSON.parse(mappedObject[CardMappings.Definition__c] || '{}');
1545+
1546+
if (!definition || !definition.xmlObject) {
1547+
return;
1548+
}
1549+
1550+
// Initialize targets structure if it doesn't exist
1551+
if (!definition.xmlObject.targets) {
1552+
definition.xmlObject.targets = { target: [] };
1553+
}
1554+
1555+
// Ensure target is an array
1556+
// This also does not seem to be correct and may not be needed as the specified json structure would exist already
1557+
if (!Array.isArray(definition.xmlObject.targets.target)) {
1558+
definition.xmlObject.targets.target = [definition.xmlObject.targets.target];
1559+
}
1560+
1561+
const requiredTargets = ['lightningCommunity__Page', 'lightningCommunity__Default'];
1562+
const currentTargets = definition.xmlObject.targets.target;
1563+
1564+
// Add missing community targets
1565+
for (const requiredTarget of requiredTargets) {
1566+
if (!currentTargets.includes(requiredTarget)) {
1567+
currentTargets.push(requiredTarget);
1568+
}
1569+
}
1570+
1571+
Logger.logVerbose(`Targets processed`);
1572+
1573+
// Save the updated definition back to the mappedObject
1574+
mappedObject[CardMappings.Definition__c] = JSON.stringify(definition);
1575+
}
15351576
}

0 commit comments

Comments
 (0)