@@ -11,7 +11,9 @@ import {
1111 MigrationStorage ,
1212 OmniScriptStorage ,
1313 ExpSitePageJson ,
14+ Storage ,
1415 ExpSiteRegion ,
16+ FlexcardStorage ,
1517} from '../interfaces' ;
1618import { FileDiffUtil } from '../../utils/lwcparser/fileutils/FileDiffUtil' ;
1719import { ExperienceSiteAssessmentInfo } from '../../utils' ;
@@ -20,8 +22,13 @@ import { BaseRelatedObjectMigration } from './BaseRealtedObjectMigration';
2022
2123Messages . importMessagesDirectory ( __dirname ) ;
2224
25+ const TARGET_COMPONENT_NAME_OS = 'runtime_omnistudio_omniscript' ;
26+ const TARGET_COMPONENT_NAME_FC = 'runtime_omnisctudio_flexcard' ;
27+ const FLEXCARD_PREFIX = 'cf' ;
28+
2329export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
2430 private EXPERIENCE_SITES_PATH : string ;
31+
2532 public constructor ( projectPath : string , namespace : string , org : Org ) {
2633 super ( projectPath , namespace , org ) ;
2734 }
@@ -87,7 +94,6 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
8794 } ;
8895
8996 const lookupComponentName = `${ this . namespace } :vlocityLWCOmniWrapper` ;
90- const targetComponentName = 'runtime_omnistudio_omniscript' ;
9197 const fileContent = fs . readFileSync ( file . location , 'utf8' ) ;
9298 // TODO - undefined check here
9399 const experienceSiteParsedJSON = JSON . parse ( fileContent ) as ExpSitePageJson ;
@@ -124,9 +130,12 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
124130 Logger . logVerbose ( 'Omnistudio wrapper component found' ) ;
125131 experienceSiteAssessmentInfo . hasOmnistudioContent = true ;
126132
127- // Updating component
128- component . componentName = targetComponentName ;
129- this . updateComponentAttributes ( component . componentAttributes , experienceSiteAssessmentInfo , storage ) ;
133+ this . updateComponentAndItsAttributes (
134+ component ,
135+ component . componentAttributes ,
136+ experienceSiteAssessmentInfo ,
137+ storage
138+ ) ;
130139 }
131140 }
132141 }
@@ -153,12 +162,13 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
153162 return experienceSiteAssessmentInfo ;
154163 }
155164
156- private updateComponentAttributes (
165+ private updateComponentAndItsAttributes (
166+ component : ExpSiteComponent ,
157167 currentAttribute : ExpSiteComponentAttributes ,
158168 experienceSiteAssessmentInfo : ExperienceSiteAssessmentInfo ,
159169 storage : MigrationStorage
160170 ) : void {
161- if ( currentAttribute === undefined ) {
171+ if ( component === undefined || currentAttribute === undefined ) {
162172 return ;
163173 }
164174
@@ -169,16 +179,61 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
169179 return ;
170180 }
171181
172- const oldTypeSubtypeLanguage = currentAttribute . target . substring ( currentAttribute . target . indexOf ( ':' ) + 1 ) ;
182+ const targetName = currentAttribute . target . substring ( currentAttribute . target . indexOf ( ':' ) + 1 ) ; // c:ABCD -> ABCD
183+
184+ if ( targetName . startsWith ( FLEXCARD_PREFIX ) ) {
185+ this . processFCComponent ( targetName , component , currentAttribute , experienceSiteAssessmentInfo , storage ) ;
186+ } else {
187+ this . processOSComponent ( targetName , component , currentAttribute , experienceSiteAssessmentInfo , storage ) ;
188+ }
189+ Logger . logVerbose ( 'updatedComponentAttribute = ' + JSON . stringify ( currentAttribute ) ) ;
190+ }
191+
192+ private processFCComponent (
193+ targetName : string ,
194+ component : ExpSiteComponent ,
195+ currentAttribute : ExpSiteComponentAttributes ,
196+ experienceSiteAssessmentInfo : ExperienceSiteAssessmentInfo ,
197+ storage : MigrationStorage
198+ ) : void {
199+ Logger . logVerbose ( `Started processing FC component + ${ JSON . stringify ( component ) } ` ) ;
200+ const flexcardName = targetName . substring ( 2 ) ; // cfCardName -> CardName
201+ const targetDataFromStorageFC : FlexcardStorage = storage . fcStorage . get ( flexcardName ) ;
202+
203+ Logger . logVerbose ( 'The target data is ' + JSON . stringify ( targetDataFromStorageFC ) ) ;
204+
205+ // Remove later
206+ if ( this . shouldAddWarning ( targetDataFromStorageFC ) ) {
207+ const warningMsg : string = this . getWarningMessage ( flexcardName , targetDataFromStorageFC ) ;
208+ experienceSiteAssessmentInfo . warnings . push ( warningMsg ) ;
209+ } else {
210+ component . componentName = TARGET_COMPONENT_NAME_FC ;
211+
212+ currentAttribute [ 'direction' ] = 'ltr' ;
213+ currentAttribute [ 'display' ] = 'Display button to open Omniscript' ;
214+ currentAttribute [ 'inlineVariant' ] = 'brand' ;
215+ currentAttribute [ 'name' ] = targetDataFromStorageFC . name ;
216+ }
217+ }
173218
219+ private processOSComponent (
220+ targetName : string ,
221+ component : ExpSiteComponent ,
222+ currentAttribute : ExpSiteComponentAttributes ,
223+ experienceSiteAssessmentInfo : ExperienceSiteAssessmentInfo ,
224+ storage : MigrationStorage
225+ ) : void {
226+ Logger . logVerbose ( `Started processing OS component + ${ JSON . stringify ( component ) } ` ) ;
174227 // Use storage to find the updated properties
175- const targetDataFromStorage : OmniScriptStorage = storage . osStorage . get ( oldTypeSubtypeLanguage ) ;
228+ const targetDataFromStorage : OmniScriptStorage = storage . osStorage . get ( targetName ) ;
176229 Logger . logVerbose ( 'The target data is ' + JSON . stringify ( targetDataFromStorage ) ) ;
177230
178231 if ( this . shouldAddWarning ( targetDataFromStorage ) ) {
179- const warningMsg : string = this . getWarningMessage ( oldTypeSubtypeLanguage , targetDataFromStorage ) ;
232+ const warningMsg : string = this . getWarningMessage ( targetName , targetDataFromStorage ) ;
180233 experienceSiteAssessmentInfo . warnings . push ( warningMsg ) ;
181234 } else {
235+ component . componentName = TARGET_COMPONENT_NAME_OS ;
236+
182237 // Preserve the layout value before clearing
183238 const originalLayout = currentAttribute [ 'layout' ] ;
184239
@@ -195,14 +250,13 @@ export class ExperienceSiteMigration extends BaseRelatedObjectMigration {
195250 currentAttribute [ 'theme' ] = originalLayout ;
196251 currentAttribute [ 'type' ] = targetDataFromStorage . type ;
197252 }
198- Logger . logVerbose ( 'updatedComponentAttribute = ' + JSON . stringify ( currentAttribute ) ) ;
199253 }
200254
201- private shouldAddWarning ( targetData : OmniScriptStorage ) : boolean {
255+ private shouldAddWarning ( targetData : Storage ) : boolean {
202256 return targetData === undefined || targetData . migrationSuccess === false || targetData . isDuplicate === true ;
203257 }
204258
205- private getWarningMessage ( oldTypeSubtypeLanguage : string , targetDataFromStorage : OmniScriptStorage ) : string {
259+ private getWarningMessage ( oldTypeSubtypeLanguage : string , targetDataFromStorage : Storage ) : string {
206260 if ( targetDataFromStorage === undefined ) {
207261 return `${ oldTypeSubtypeLanguage } needs manual intervention as the migrated key does not exist` ;
208262 } else if ( targetDataFromStorage . migrationSuccess === false ) {
0 commit comments