Skip to content

Commit fb7c494

Browse files
authored
Merge pull request #352 from snehaljha-sf/flexipage_fixes
fix: flexipage issues
2 parents 1252201 + 30f017b commit fb7c494

File tree

5 files changed

+306
-10
lines changed

5 files changed

+306
-10
lines changed

src/migration/related/FlexipageMigration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ export class FlexipageMigration extends BaseRelatedObjectMigration {
192192
Logger.logVerbose(this.messages.getMessage('updatedModifiedContent', [filePath]));
193193
}
194194

195-
const diff = new FileDiffUtil().getFileDiff(fileName, fileContent, modifiedContent);
195+
const diff = new FileDiffUtil().getXMLDiff(fileContent, modifiedContent);
196196
Logger.logVerbose(this.messages.getMessage('generatedDiffForFile', [fileName]));
197197

198198
return {

src/utils/flexipage/flexiPageTransformer.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ const targetComponentNameOS = 'runtime_omnistudio:omniscript';
2121
/** Target identifier after transformation */
2222
const targetIdentifierOS = 'runtime_omnistudio_omniscript';
2323

24+
let osSeq = 1;
25+
let fcSeq = 1;
26+
2427
const targetComponentNameFlexCard = 'runtime_omnistudio:flexcard';
2528
const targetIdentifierFlexCard = 'runtime_omnistudio_flexcard';
2629

@@ -46,6 +49,9 @@ export function transformFlexipageBundle(
4649
namespace: string,
4750
mode: 'assess' | 'migrate'
4851
): Flexipage | boolean {
52+
osSeq = 1;
53+
fcSeq = 1;
54+
4955
const bundle: Flexipage = JSON.parse(JSON.stringify(ogBundle)) as Flexipage;
5056
let changes = false;
5157

@@ -103,9 +109,9 @@ function createNewProps(
103109
componentInstanceProperties: FlexiComponentInstanceProperty[]
104110
): { componentName: string; identifier: string; props: Record<string, string> } {
105111
if (nameKey.startsWith(flexCardPrefix)) {
106-
return createNewPropsForFlexCard(nameKey.substring(flexCardPrefix.length), namespace, mode);
112+
return createNewPropsForFlexCard(nameKey.substring(flexCardPrefix.length).toLowerCase(), namespace, mode);
107113
}
108-
return createNewPropsForOmniScript(nameKey, namespace, mode, componentInstanceProperties);
114+
return createNewPropsForOmniScript(nameKey.toLowerCase(), namespace, mode, componentInstanceProperties);
109115
}
110116

111117
function createNewPropsForOmniScript(
@@ -142,7 +148,7 @@ function createNewPropsForOmniScript(
142148

143149
return {
144150
componentName: targetComponentNameOS,
145-
identifier: targetIdentifierOS,
151+
identifier: `${targetIdentifierOS}${osSeq++}`,
146152
props: newProps,
147153
};
148154
}
@@ -173,7 +179,7 @@ function createNewPropsForFlexCard(
173179

174180
return {
175181
componentName: targetComponentNameFlexCard,
176-
identifier: targetIdentifierFlexCard,
182+
identifier: `${targetIdentifierFlexCard}${fcSeq++}`,
177183
props: newProps,
178184
};
179185
}

src/utils/lwcparser/fileutils/FileDiffUtil.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-disable @typescript-eslint/explicit-member-accessibility */
33
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
44
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
5-
import { createPatch } from 'diff';
5+
import { createPatch, diffLines } from 'diff';
66
import { Logger } from '../../../utils/logger';
77
import { DiffPair } from '../../interfaces';
88

@@ -46,16 +46,25 @@ export class FileDiffUtil {
4646
let linecount = 0;
4747
for (const { old: original, new: modified } of diffArray) {
4848
if (original === modified) {
49-
result += `<div style="color: black;">• Line ${modifiedLine}: ${this.escapeHtml(original)}</div>`;
49+
result += `<div style="color: black;">• Line ${modifiedLine}: ${this.escapeHtml(original).replace(
50+
/ /g,
51+
'&nbsp;'
52+
)}</div>`;
5053
modifiedLine++;
5154
originalLine++;
5255
linecount++;
5356
} else if (original !== null && modified === null) {
54-
result += `<div style="color: red;">- Line ${originalLine}: ${this.escapeHtml(original)}</div>`;
57+
result += `<div style="color: red;">- Line ${originalLine}: ${this.escapeHtml(original).replace(
58+
/ /g,
59+
'&nbsp;'
60+
)}</div>`;
5561
originalLine++;
5662
linecount++;
5763
} else if (original === null && modified !== null) {
58-
result += `<div style="color: green;">+ Line ${modifiedLine}: ${this.escapeHtml(modified)}</div>`;
64+
result += `<div style="color: green;">+ Line ${modifiedLine}: ${this.escapeHtml(modified).replace(
65+
/ /g,
66+
'&nbsp;'
67+
)}</div>`;
5968
modifiedLine++;
6069
linecount++;
6170
}
@@ -147,4 +156,25 @@ export class FileDiffUtil {
147156
return [];
148157
}
149158
}
159+
160+
public getXMLDiff(originalFileContent: string, modifiedFileContent: string): DiffPair[] {
161+
const diff = diffLines(originalFileContent, modifiedFileContent, { stripTrailingCr: true });
162+
const result: DiffPair[] = [];
163+
for (const block of diff) {
164+
if (block.added) {
165+
block.value.split('\n').forEach((line) => {
166+
result.push({ old: null, new: line });
167+
});
168+
} else if (block.removed) {
169+
block.value.split('\n').forEach((line) => {
170+
result.push({ old: line, new: null });
171+
});
172+
} else {
173+
block.value.split('\n').forEach((line) => {
174+
result.push({ old: line, new: line });
175+
});
176+
}
177+
}
178+
return result;
179+
}
150180
}

test/migration/related/FlexipageMigration.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ interface MockXmlUtil {
2929

3030
interface MockFileDiffUtil {
3131
getFileDiff: sinon.SinonStub;
32+
getXMLDiff: sinon.SinonStub;
3233
}
3334

3435
interface MockTransformFlexipageBundle extends sinon.SinonStub {
@@ -104,6 +105,7 @@ describe('FlexipageMigration', () => {
104105
// Mock FileDiffUtil
105106
mockFileDiffUtil = {
106107
getFileDiff: sandbox.stub().returns('mock-diff'),
108+
getXMLDiff: sandbox.stub().returns('mock-diff'),
107109
};
108110

109111
// Mock transformFlexipageBundle

0 commit comments

Comments
 (0)