Skip to content

Commit ae6bb43

Browse files
fix: ensure retrieval and deployment of views with screen aware variants (#930)
Signed-off-by: adityabisht31 <[email protected]>
1 parent bac3cae commit ae6bb43

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

src/resolve/adapters/digitalExperienceSourceAdapter.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ import { BundleSourceAdapter } from './bundleSourceAdapter';
3434
* | | | ├── _meta.json
3535
* | | | ├── content.json
3636
* | | | ├── ar.json
37+
* | | ├── view3/
38+
* | | | ├── _meta.json
39+
* | | | ├── content.json
40+
* | | | ├── mobile/
41+
* | | | | ├──mobile.json
42+
* | | | ├── tablet/
43+
* | | | | ├──tablet.json
3744
* | ├── foos.digitalExperience-meta.xml
3845
* content/
3946
* ├── bars/
@@ -58,7 +65,20 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
5865
if (this.isBundleType()) {
5966
return;
6067
}
61-
return dirname(path);
68+
const pathToContent = dirname(path);
69+
const parts = pathToContent.split(sep);
70+
/* Handle mobile or tablet variants.Eg- digitalExperiences/site/lwr11/sfdc_cms__view/home/mobile/mobile.json
71+
Go back to one level in that case
72+
Bundle hierarchy baseType/spaceApiName/contentType/contentApiName/variantFolders/file */
73+
const digitalExperiencesIndex = parts.indexOf('digitalExperiences');
74+
if (digitalExperiencesIndex > -1) {
75+
const depth = parts.length - digitalExperiencesIndex - 1;
76+
if (depth === digitalExperienceBundleWithVariantsDepth) {
77+
parts.pop();
78+
return parts.join(sep);
79+
}
80+
}
81+
return pathToContent;
6282
}
6383

6484
protected populate(trigger: string, component?: SourceComponent): SourceComponent {
@@ -131,3 +151,6 @@ export class DigitalExperienceSourceAdapter extends BundleSourceAdapter {
131151
* @returns name of type/apiName format
132152
*/
133153
const calculateNameFromPath = (contentPath: string): string => `${parentName(contentPath)}/${baseName(contentPath)}`;
154+
155+
// Bundle hierarchy baseType/spaceApiName/contentType/contentApiName/variantFolders/file
156+
const digitalExperienceBundleWithVariantsDepth = 5;

test/resolve/adapters/digitalExperienceSourceAdapter.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@ describe('DigitalExperienceSourceAdapter', () => {
2020

2121
const HOME_VIEW_NAME = 'sfdc_cms__view/home';
2222
const HOME_VIEW_PATH = join(BUNDLE_PATH, 'sfdc_cms__view', 'home');
23+
const HOME_VIEW_MOBILE_PATH = join(HOME_VIEW_PATH, 'mobile');
24+
const HOME_VIEW_TABLET_PATH = join(HOME_VIEW_PATH, 'tablet');
25+
2326
const HOME_VIEW_CONTENT_FILE = join(HOME_VIEW_PATH, 'content.json');
2427
const HOME_VIEW_META_FILE = join(HOME_VIEW_PATH, DE_METAFILE);
2528
const HOME_VIEW_FRENCH_VARIANT_FILE = join(HOME_VIEW_PATH, 'fr.json');
29+
const HOME_VIEW_MOBILE_VARIANT_FILE = join(HOME_VIEW_MOBILE_PATH, 'mobile.json');
30+
const HOME_VIEW_TABLET_VARIANT_FILE = join(HOME_VIEW_TABLET_PATH, 'tablet.json');
2631

2732
const registryAccess = new RegistryAccess();
2833
const forceIgnore = new ForceIgnore();
@@ -31,6 +36,8 @@ describe('DigitalExperienceSourceAdapter', () => {
3136
HOME_VIEW_CONTENT_FILE,
3237
HOME_VIEW_META_FILE,
3338
HOME_VIEW_FRENCH_VARIANT_FILE,
39+
HOME_VIEW_MOBILE_VARIANT_FILE,
40+
HOME_VIEW_TABLET_VARIANT_FILE,
3441
]);
3542

3643
const bundleAdapter = new DigitalExperienceSourceAdapter(
@@ -67,6 +74,11 @@ describe('DigitalExperienceSourceAdapter', () => {
6774
expect(bundleAdapter.getComponent(HOME_VIEW_FRENCH_VARIANT_FILE)).to.deep.equal(component);
6875
});
6976

77+
it('should return a SourceComponent for mobile and tablet variant json', () => {
78+
expect(bundleAdapter.getComponent(HOME_VIEW_MOBILE_VARIANT_FILE)).to.deep.equal(component);
79+
expect(bundleAdapter.getComponent(HOME_VIEW_TABLET_VARIANT_FILE)).to.deep.equal(component);
80+
});
81+
7082
it('should return a SourceComponent when a bundle path is provided', () => {
7183
expect(bundleAdapter.getComponent(HOME_VIEW_PATH)).to.deep.equal(component);
7284
expect(bundleAdapter.getComponent(BUNDLE_PATH)).to.deep.equal(component);
@@ -100,5 +112,10 @@ describe('DigitalExperienceSourceAdapter', () => {
100112
expect(digitalExperienceAdapter.getComponent(HOME_VIEW_META_FILE)).to.deep.equal(component);
101113
expect(digitalExperienceAdapter.getComponent(HOME_VIEW_FRENCH_VARIANT_FILE)).to.deep.equal(component);
102114
});
115+
116+
it('should return a SourceComponent for mobile and tablet variant json', () => {
117+
expect(digitalExperienceAdapter.getComponent(HOME_VIEW_MOBILE_VARIANT_FILE)).to.deep.equal(component);
118+
expect(digitalExperienceAdapter.getComponent(HOME_VIEW_TABLET_VARIANT_FILE)).to.deep.equal(component);
119+
});
103120
});
104121
});

0 commit comments

Comments
 (0)