Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip text diff #134

Merged
merged 4 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/utils/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ import { create } from 'jsondiffpatch'
import { hexToU8a, u8aToHex } from '@polkadot/util'
import _ from 'lodash'

const diffPatcher = create({ array: { detectMove: false } })
const diffPatcher = create({
array: { detectMove: false },
textDiff: { minLength: Number.MAX_VALUE }, // skip text diff
})

const cache: Record<HexString, StorageEntry> = {}

Expand Down
28 changes: 9 additions & 19 deletions template/diff.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,29 @@
}

li:has(> span > span.diffWrap > span.diffRemove) > label {
color: #db2703 !important;
color: red !important;
text-decoration: line-through;
text-decoration-thickness: 1px;
}

.diffAdd {
color: #64c83c;
color: darkseagreen;
}

.diffRemove {
text-decoration: line-through;
text-decoration-thickness: 1px;
color: #db2703;
color: red;
}

.diffUpdateFrom {
text-decoration: line-through;
text-decoration-thickness: 1px;
color: #db2703;
color: red;
}

.diffUpdateTo {
color: #64c83c;
color: darkseagreen;
}

.diffUpdateArrow {
Expand Down Expand Up @@ -112,8 +112,8 @@
const oldValue = parseInt(value[0].replace(/,/g, ''))
const newValue = parseInt(value[1].replace(/,/g, ''))
if (oldValue > 0 && newValue > 0) {
const delta = newValue - oldValue
return (<span className="delta" >{delta > 0 ? '+' : ''}{delta}</span>)
const delta = Number(newValue - oldValue)
return (<span className="delta" >{delta > 0 ? '+' : ''}{delta.toLocaleString()}</span>)
}
}
}
Expand Down Expand Up @@ -161,15 +161,13 @@

return (
<span {...styling('diffWrap')}>
{renderSpan('unchanged', stringifyAndShrink(raw))}
{renderSpan('unchanged', stringifyAndShrink(value))}
</span>
);
};

function prepareDelta(value) {
if (!value) return value;

if (value._t === 'a') {
if (value && value._t === 'a') {
const res = {};
for (const key in value) {
if (key !== '_t') {
Expand All @@ -183,14 +181,6 @@
}
}
return res;
} else {
if (Array.isArray(value) && value.length === 3 && typeof value[0] === 'string' && value[0].startsWith('@@')) {
const [left, right] = value[0].split("@@").filter(x => x.length > 0)
const items = right.split("\n").slice(1).filter(x => x.length > 0)
const oldValue = items.filter(x => x[0] !== '+').map(x => x.slice(1)).join('')
const newValue = items.filter(x => x[0] !== '-').map(x => x.slice(1)).join('')
return [oldValue, newValue]
}
}
return value;
}
Expand Down