Skip to content

Commit 3b5c97b

Browse files
feat: apex full file diff
1 parent 788e3b6 commit 3b5c97b

File tree

3 files changed

+83
-9
lines changed

3 files changed

+83
-9
lines changed

src/migration/related/ApexMigration.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export class ApexMigration extends BaseRelatedObjectMigration {
155155
} else {
156156
Logger.logger.info(assessMessages.getMessage('apexFileChangesIdentifiedNotApplied', [file.name]));
157157
}
158-
difference = new FileDiffUtil().getFileDiff(file.name, fileContent, updatedContent);
158+
difference = new FileDiffUtil().getFullFileDiff(file.name, fileContent, updatedContent);
159159
}
160160
if (updateMessages.length === 0) {
161161
Logger.info(assessMessages.getMessage('fileNoOmnistudioCalls', [file.name]));

src/styles/reportGenerator.css

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,28 +256,30 @@ html {
256256
background-color: #fff;
257257
margin: auto;
258258
padding: 20px;
259+
padding-top: 20px;
259260
width: 60%;
260-
height: 60%;
261+
max-height: 80%;
261262
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
262263
border-radius: 4px;
263264
text-align: left;
264265
position: relative;
266+
overflow-y: auto;
267+
overflow-x: auto;
265268
}
266269

267270
.closeButton {
268271
color: #222121;
269-
height: 30px;
270-
width: 30px;
272+
height: 40px;
273+
width: 40px;
271274
position: absolute;
272-
background-color: #fff;
273-
top: -35px;
274-
right: 0;
275-
font-size: 25px;
275+
top: 0px;
276+
right: 0px;
277+
font-size: 30px;
276278
cursor: pointer;
277279
display: flex;
278280
align-items: center;
279281
justify-content: center;
280-
border-radius: 3px;
282+
z-index: 1050;
281283
}
282284

283285
.modalHeader {

src/utils/lwcparser/fileutils/FileDiffUtil.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,78 @@ export class FileDiffUtil {
116116
}
117117
}
118118

119+
public getFullFileDiff(filename: string, originalFileContent: string, modifiedFileContent: string): DiffPair[] {
120+
const originalLines = originalFileContent.split('\n');
121+
const modifiedLines = modifiedFileContent.split('\n');
122+
const patch: string = createPatch('', originalFileContent, modifiedFileContent);
123+
const patchLines = patch.split('\n');
124+
125+
let origIdx = 0;
126+
let modIdx = 0;
127+
const result: DiffPair[] = [];
128+
129+
// Skip the first line of the patch (the file header)
130+
let i = 0;
131+
while (i < patchLines.length) {
132+
const line = patchLines[i];
133+
const hunkHeader = /^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@/;
134+
const match = hunkHeader.exec(line);
135+
136+
if (match) {
137+
// Move to the start of the hunk
138+
const origStart = parseInt(match[1], 10) - 1;
139+
const modStart = parseInt(match[3], 10) - 1;
140+
141+
// Emit unchanged lines before the hunk
142+
while (origIdx < origStart && modIdx < modStart) {
143+
result.push({ old: originalLines[origIdx], new: modifiedLines[modIdx] });
144+
origIdx++;
145+
modIdx++;
146+
}
147+
148+
i++;
149+
// Now process the hunk lines
150+
while (i < patchLines.length && !patchLines[i].startsWith('@@')) {
151+
const hunkLine = patchLines[i];
152+
if (hunkLine.startsWith('-')) {
153+
result.push({ old: originalLines[origIdx], new: null });
154+
origIdx++;
155+
} else if (hunkLine.startsWith('+')) {
156+
result.push({ old: null, new: modifiedLines[modIdx] });
157+
modIdx++;
158+
} else if (hunkLine.startsWith(' ')) {
159+
result.push({ old: originalLines[origIdx], new: modifiedLines[modIdx] });
160+
origIdx++;
161+
modIdx++;
162+
}
163+
i++;
164+
}
165+
} else {
166+
i++;
167+
}
168+
}
169+
170+
// Emit any remaining unchanged lines at the end
171+
while (origIdx < originalLines.length && modIdx < modifiedLines.length) {
172+
result.push({ old: originalLines[origIdx], new: modifiedLines[modIdx] });
173+
origIdx++;
174+
modIdx++;
175+
}
176+
// If there are trailing additions or deletions
177+
while (origIdx < originalLines.length) {
178+
result.push({ old: originalLines[origIdx], new: null });
179+
origIdx++;
180+
}
181+
while (modIdx < modifiedLines.length) {
182+
result.push({ old: null, new: modifiedLines[modIdx] });
183+
modIdx++;
184+
}
185+
186+
// Only return if there are any changes
187+
const hasChanges = result.some((diff) => diff.old !== diff.new);
188+
return hasChanges ? result : [];
189+
}
190+
119191
escapeHtml(text: string): string {
120192
return text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&#039;');
121193
}

0 commit comments

Comments
 (0)