Skip to content

Commit 72c746a

Browse files
author
=
committed
improve display of removed metadata fields history
1 parent fc816ad commit 72c746a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/LoadHistory.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ describe('generateMetadataChanges', () => {
6969
{ ...SampleEvents.kind0, content: JSON.stringify(c) },
7070
{ ...SampleEvents.kind0 },
7171
]);
72-
expect(r[0].changes).toEqual(['removed about']);
72+
expect(r[0].changes).toEqual([
73+
'removed about: A mobile bitcoin experience fit for the gods Est. 563345. https://zeusln.app',
74+
]);
7375
});
7476
test('when a content properties are added, modified and removed, this is all referenced in the changes array', () => {
7577
const c = { ...kind0content, name: 'Bob', custom: 'custom property value' };
@@ -81,7 +83,7 @@ describe('generateMetadataChanges', () => {
8183
expect(r[0].changes).toEqual([
8284
'added custom: custom property value',
8385
'modified name: Bob',
84-
'removed about',
86+
'removed about: A mobile bitcoin experience fit for the gods Est. 563345. https://zeusln.app',
8587
]);
8688
});
8789
});

src/LoadHistory.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const generateMetadataChanges = (
2626
):VersionChange[] => history.map((e, i, a) => {
2727
const changes:string[] = [];
2828
const c = JSON.parse(e.content);
29-
const clean = (s:string | number) => (typeof s === 'string' ? s.replace(/\r?\n|\r/, '') : s);
29+
const clean = (s:string | number) => (typeof s === 'string' ? s.replace(/(\r\n|\n|\r)/gm, ' ') : s.toString());
3030
// if first backup list all fields and values
3131
if (i === a.length - 1) {
3232
Object.keys(c).forEach((k) => changes.push(`${k}: ${clean(c[k])}`));
@@ -43,7 +43,11 @@ export const generateMetadataChanges = (
4343
// list deletes
4444
Object.keys(nextc)
4545
.filter((k) => !Object.keys(c).some((v) => v === k))
46-
.forEach((k) => { changes.push(`removed ${k}`); });
46+
.forEach((k) => {
47+
changes.push(
48+
`removed ${clean(nextc[k]).length === 0 ? `blank ${k}` : `${k}: ${clean(nextc[k])}`}`,
49+
);
50+
});
4751
}
4852
return {
4953
ago: e.created_at,

0 commit comments

Comments
 (0)