Skip to content

Commit 4375c19

Browse files
authored
fix(PrismDiffCode): empty line diff (#573)
1 parent 66da405 commit 4375c19

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

.changeset/itchy-days-judge.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': patch
3+
---
4+
5+
Fix diff calculation in PrismDiffCode.

.changeset/spicy-rice-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@cube-dev/ui-kit': patch
3+
---
4+
5+
Fix the bug when an empty line might appear in PrismDiffCode.

src/components/content/PrismDiffCode/PrismDiffCode.stories.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,3 +254,12 @@ SELECT
254254
FROM FinalOutput fo
255255
ORDER BY fo.GeneratedDate, fo.UserID;`,
256256
};
257+
258+
export const EmptyLineDiff = Template.bind({});
259+
EmptyLineDiff.args = {
260+
modified:
261+
"cubes:\n - name: orders\n sql: >\n select 1 as id, 100 as amount, 'new' status\n UNION ALL\n select 2 as id, 200 as amount, 'new' status\n UNION ALL\n select 3 as id, 300 as amount, 'processed' status\n UNION ALL\n select 4 as id, 500 as amount, 'processed' status\n UNION ALL\n select 5 as id, 600 as amount, 'shipped' status\n\n joins: []\n\n dimensions:\n - name: id\n type: number\n\n - name: status\n sql: status\n\n\n measures:\n - name: count\n type: count\n\n - name: amount\n sql: amount\n type: sum\n\n pre_aggregations:\n # Pre-aggregation definitions go here.\n # Learn more in the documentation: https://cube.dev/docs/caching/pre-aggregations/getting-started\n\n",
262+
original:
263+
"cubes:\n - name: orders\n sql: >\n select 1 as id, 100 as amount, 'new' status\n UNION ALL\n select 2 as id, 200 as amount, 'new' status\n UNION ALL\n select 3 as id, 300 as amount, 'processed' status\n UNION ALL\n select 4 as id, 500 as amount, 'processed' status\n UNION ALL\n select 5 as id, 600 as amount, 'shipped' status\n\n joins: []\n\n dimensions:\n - name: id\n\n - name: status\n sql: status\n\n\n measures:\n - name: count\n type: count\n\n - name: amount\n sql: amount\n type: sum\n\n pre_aggregations:\n # Pre-aggregation definitions go here.\n # Learn more in the documentation: https://cube.dev/docs/caching/pre-aggregations/getting-started\n\n",
264+
language: 'yaml',
265+
};

src/components/content/PrismDiffCode/PrismDiffCode.tsx

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,36 @@ export function PrismDiffCode({
3232
...props
3333
}: CubePrismDiffCodeProps) {
3434
// Generate the diff string
35-
const diff = diffLines(original, modified, { newlineIsToken: true });
35+
const diff = diffLines(original, modified);
36+
3637
const diffString = diff
3738
.map((part) => {
39+
const value = part.value.trimEnd();
40+
3841
if (part.added) {
39-
return `+${part.value.trimEnd()}`;
42+
return value
43+
.split('\n')
44+
.map((val) => {
45+
return val ? `+${val}` : '';
46+
})
47+
.join('\n');
4048
}
49+
4150
if (part.removed) {
42-
return `-${part.value.trimEnd()}`;
51+
return value
52+
.split('\n')
53+
.map((val) => {
54+
return val ? `-${val}` : '';
55+
})
56+
.join('\n');
4357
}
44-
return ` ${part.value.trimEnd()}`;
58+
59+
return value
60+
.split('\n')
61+
.map((val) => {
62+
return val ? ` ${val}` : '';
63+
})
64+
.join('\n');
4565
})
4666
.join('\n');
4767

0 commit comments

Comments
 (0)