Skip to content

Commit

Permalink
Merge branch 'diff'
Browse files Browse the repository at this point in the history
  • Loading branch information
olmobrutall committed Dec 14, 2022
2 parents 4ac244b + 141dcd1 commit 880c1a7
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions Signum.React.Extensions/DiffLog/Templates/DiffDocument.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export interface LineOrWordsChange {
export function DiffDocument(p: { first: string, second: string }) {

const [margin, setMargin] = React.useState<number | null>(4);

const [force, setForce] = React.useState<number>(false);
var formatter = toNumberFormat("N0");
return (
<div>
<div>
Expand All @@ -24,18 +25,31 @@ export function DiffDocument(p: { first: string, second: string }) {
validateKey={isNumber} /> lines arround each change</label>
</div>
<div>
<DiffDocumentSimple first={p.first} second={p.second} margin={margin} />
{(p.first.length * p.second.length > DiffDocument.maxSize * DiffDocument.maxSize) && !force ?
<div class="alert alert-warning mt-2" role="alert">
The two strings are too big ({formatter.format(p.first.length)} ch. and {formatter.format(p.second.length)} ch.) and could freeze your browser...
<br />
<a href="#" className="btn btn-sm btn-warning mt-3" onClick={e => { e.preventDefault(); setForce(true); }}>Try anyway!</a>
</div> :
<DiffDocumentSimple first={p.first} second={p.second} margin={margin} />
}
</div>
</div>
);
}

DiffDocument.defaultMarginLines = 4 as (number | null);
DiffDocument.maxSize = 300000;



export function DiffDocumentSimple(p: { first: string, second: string, margin?: number | null }) {




const linesDiff = React.useMemo<Array<LineOrWordsChange>>(() => {

var diffs = diffLines(p.first, p.second);
var result: Array<LineOrWordsChange> = [];

Expand Down

2 comments on commit 880c1a7

@olmobrutall
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Client-side Diff

Thanks to @JafarMirzaie, the git-like Diff algorithm used in OperationLog / TimeMachine to compare versions of the entities is now working in the client side (instead of in the server) using @jsdiff.

This is important because comparing the log of two big entities (log > 300 KB) takes a long time, and above 600KB tipically it kills the server.

Aditionally, a warning is shown if you try to compare big entities, but if the user wants to do it anyway, then it will only compromise his browser tab.

Thanks!

@JafarMirzaie
Copy link
Contributor

@JafarMirzaie JafarMirzaie commented on 880c1a7 Dec 17, 2022 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.