fix(ui): fix very long diffs
This commit is contained in:
parent
17da9a8498
commit
c5b3da72cd
2 changed files with 52 additions and 15 deletions
|
|
@ -1,4 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import cn from 'classnames';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
shades: Record<string, string>;
|
shades: Record<string, string>;
|
||||||
|
|
@ -11,7 +12,7 @@ const getCircularReplacer = () => {
|
||||||
const seen = new WeakSet();
|
const seen = new WeakSet();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return (key, value) => {
|
return (key, value) => {
|
||||||
if (typeof value === "object" && value !== null) {
|
if (typeof value === 'object' && value !== null) {
|
||||||
if (seen.has(value)) {
|
if (seen.has(value)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -23,20 +24,57 @@ const getCircularReplacer = () => {
|
||||||
|
|
||||||
function DiffRow({ diff, path }: Props) {
|
function DiffRow({ diff, path }: Props) {
|
||||||
const [shorten, setShorten] = React.useState(true);
|
const [shorten, setShorten] = React.useState(true);
|
||||||
|
const [shortenOldVal, setShortenOldVal] = React.useState(true);
|
||||||
|
const [shortenNewVal, setShortenNewVal] = React.useState(true);
|
||||||
|
|
||||||
const oldValue = diff.item ? JSON.stringify(diff.item.lhs, getCircularReplacer()) : JSON.stringify(diff.lhs, getCircularReplacer());
|
const oldValue = diff.item
|
||||||
const newValue = diff.item ? JSON.stringify(diff.item.rhs, getCircularReplacer()) : JSON.stringify(diff.rhs, getCircularReplacer());
|
? JSON.stringify(diff.item.lhs, getCircularReplacer(), 1)
|
||||||
|
: JSON.stringify(diff.lhs, getCircularReplacer(), 1);
|
||||||
|
const newValue = diff.item
|
||||||
|
? JSON.stringify(diff.item.rhs, getCircularReplacer(), 1)
|
||||||
|
: JSON.stringify(diff.rhs, getCircularReplacer(), 1);
|
||||||
|
|
||||||
|
const length = path.length;
|
||||||
|
const diffLengths = [oldValue?.length || 0, newValue?.length || 0];
|
||||||
|
|
||||||
|
const pathStr =
|
||||||
|
length > 20 && shorten ? path.slice(0, 5) + '...' + path.slice(length - 10, length) : path;
|
||||||
|
|
||||||
|
const oldValueSafe =
|
||||||
|
diffLengths[0] > 50 && shortenOldVal
|
||||||
|
? `${oldValue.slice(0, 10)} ... ${oldValue.slice(diffLengths[0] - 25, diffLengths[0])}`
|
||||||
|
: oldValue;
|
||||||
|
const newValueSafe =
|
||||||
|
diffLengths[1] > 50 && shortenNewVal
|
||||||
|
? `${newValue.slice(0, 10)} ... ${newValue.slice(diffLengths[1] - 25, diffLengths[1])}`
|
||||||
|
: newValue;
|
||||||
|
|
||||||
const pathStr = path.length > 15 && shorten ? path.slice(0, 5) + '...' + path.slice(10) : path;
|
|
||||||
return (
|
return (
|
||||||
<div className="p-1 rounded">
|
<div className="p-1 rounded">
|
||||||
<span className={path.length > 15 ? 'cursor-pointer' : ''} onClick={() => setShorten(false)}>
|
<span className={length > 20 ? 'cursor-pointer' : ''} onClick={() => setShorten(!shorten)}>
|
||||||
{pathStr}
|
{pathStr}
|
||||||
{': '}
|
{': '}
|
||||||
</span>
|
</span>
|
||||||
<span className="line-through text-disabled-text">{oldValue || 'undefined'}</span>
|
<span
|
||||||
|
onClick={() => setShortenOldVal(!shortenOldVal)}
|
||||||
|
className={cn(
|
||||||
|
'line-through text-disabled-text',
|
||||||
|
diffLengths[0] > 50 ? 'cursor-pointer' : ''
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{oldValueSafe || 'undefined'}
|
||||||
|
</span>
|
||||||
{' -> '}
|
{' -> '}
|
||||||
<span className={`${!newValue ? 'text-red' : 'text-green'}`}>{newValue || 'undefined'}</span>
|
<span
|
||||||
|
onClick={() => setShortenNewVal(!shortenNewVal)}
|
||||||
|
className={cn(
|
||||||
|
'whitespace-pre',
|
||||||
|
newValue ? 'text-red' : 'text-green',
|
||||||
|
diffLengths[1] > 50 ? 'cursor-pointer' : ''
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
{newValueSafe || 'undefined'}
|
||||||
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -77,14 +77,14 @@ export default class Storage extends React.PureComponent {
|
||||||
|
|
||||||
if (!stateDiff) {
|
if (!stateDiff) {
|
||||||
return (
|
return (
|
||||||
<div style={{ flex: 1 }} className="flex flex-col p-2 pr-0 font-mono text-disabled-text">
|
<div style={{ flex: 3 }} className="flex flex-col p-2 pr-0 font-mono text-disabled-text">
|
||||||
No diff
|
No diff
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ flex: 1 }} className="flex flex-col p-1 font-mono">
|
<div style={{ flex: 3 }} className="flex flex-col p-1 font-mono">
|
||||||
{stateDiff.map((d, i) => this.renderDiffs(d, i))}
|
{stateDiff.map((d, i) => this.renderDiffs(d, i))}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
@ -166,13 +166,12 @@ export default class Storage extends React.PureComponent {
|
||||||
>
|
>
|
||||||
{src === null ? (
|
{src === null ? (
|
||||||
<div className="font-mono" style={{ flex: 2, marginLeft: '26.5%' }}>
|
<div className="font-mono" style={{ flex: 2, marginLeft: '26.5%' }}>
|
||||||
{' '}
|
{name}
|
||||||
{name}{' '}
|
|
||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{this.renderDiff(item, prevItem)}
|
{this.renderDiff(item, prevItem)}
|
||||||
<div style={{ flex: 2 }} className="flex pl-10">
|
<div style={{ flex: 2 }} className="flex pl-10 pt-2">
|
||||||
<JSONTree
|
<JSONTree
|
||||||
name={this.ensureString(name)}
|
name={this.ensureString(name)}
|
||||||
src={src}
|
src={src}
|
||||||
|
|
@ -182,7 +181,7 @@ export default class Storage extends React.PureComponent {
|
||||||
</div>
|
</div>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
<div style={{ flex: 1 }} className="flex-1 flex gap-2 items-center justify-end self-center">
|
<div style={{ flex: 1 }} className="flex-1 flex gap-2 pt-2 items-center justify-end self-start">
|
||||||
{typeof item.duration === 'number' && (
|
{typeof item.duration === 'number' && (
|
||||||
<div className="font-size-12 color-gray-medium">{formatMs(item.duration)}</div>
|
<div className="font-size-12 color-gray-medium">{formatMs(item.duration)}</div>
|
||||||
)}
|
)}
|
||||||
|
|
@ -214,11 +213,11 @@ export default class Storage extends React.PureComponent {
|
||||||
<div className="flex w-full">
|
<div className="flex w-full">
|
||||||
{showStore && <h3 style={{ width: '25%', marginRight: 20 }} className="font-semibold">{'STATE'}</h3>}
|
{showStore && <h3 style={{ width: '25%', marginRight: 20 }} className="font-semibold">{'STATE'}</h3>}
|
||||||
{this.state.showDiffs ? (
|
{this.state.showDiffs ? (
|
||||||
<h3 style={{ width: '20%'}} className="font-semibold">
|
<h3 style={{ width: '39%'}} className="font-semibold">
|
||||||
DIFFS
|
DIFFS
|
||||||
</h3>
|
</h3>
|
||||||
) : null}
|
) : null}
|
||||||
<h3 style={{ width: '50%' }} className="font-semibold">{getActionsName(type)}</h3>
|
<h3 style={{ width: '30%' }} className="font-semibold">{getActionsName(type)}</h3>
|
||||||
<h3 style={{ paddingRight: 30, marginLeft: 'auto' }} className="font-semibold">
|
<h3 style={{ paddingRight: 30, marginLeft: 'auto' }} className="font-semibold">
|
||||||
<Tooltip title="Time to execute">
|
<Tooltip title="Time to execute">
|
||||||
TTE
|
TTE
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue