-
Notifications
You must be signed in to change notification settings - Fork 1
feat: recreate diff viewer components and created new utils #19
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e6b1846
feat: recreate diff viewer components and created utils from json dif…
utkuakyuz deca570
fix: some null check corrections
utkuakyuz 347afdd
feat!: new grid viewer created to have more flexibility
utkuakyuz 9d45816
feat: old renderers are deleted
utkuakyuz c7def0f
fix: review notes applied
utkuakyuz a6ea905
chore: version update to 1.0.12
utkuakyuz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import type { SearchState } from "../types"; | ||
|
|
||
| import { SearchIcon } from "../../SearchIcon"; | ||
|
|
||
| type Props = { | ||
| searchState: SearchState; | ||
| handleSearch: (term: string) => void; | ||
| navigateMatch: (direction: "next" | "prev") => void; | ||
| hideSearch?: boolean; | ||
| }; | ||
|
|
||
| function SearchboxHolder({ searchState, handleSearch, navigateMatch, hideSearch }: Props) { | ||
| if (hideSearch) | ||
| return null; | ||
|
|
||
| return ( | ||
| <div> | ||
| <div className="search-container"> | ||
| <div className="search-input-container"> | ||
| <span role="img" aria-label="search"><SearchIcon /></span> | ||
| <input | ||
| type="text" | ||
| placeholder="Search in JSON..." | ||
| value={searchState.term} | ||
| onChange={e => handleSearch(e.target.value)} | ||
| /> | ||
| </div> | ||
| {searchState.results.length > 0 && ( | ||
| <div className="search-results"> | ||
| <span> | ||
| {searchState.currentIndex + 1} | ||
| {" "} | ||
| of | ||
| {" "} | ||
| {searchState.results.length} | ||
| {" "} | ||
| matches | ||
| </span> | ||
| <button onClick={() => navigateMatch("prev")}>Previous</button> | ||
| <button onClick={() => navigateMatch("next")}>Next</button> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </div> | ||
utkuakyuz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ); | ||
| } | ||
|
|
||
| export default SearchboxHolder; | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| // VirtualDiffGrid.tsx | ||
| import type { InlineDiffOptions } from "json-diff-kit"; | ||
| import type { Dispatch } from "react"; | ||
| import type { ListOnScrollProps } from "react-window"; | ||
|
|
||
| import React, { useCallback, useEffect, useMemo } from "react"; | ||
| import { VariableSizeList as List } from "react-window"; | ||
|
|
||
| import type { DiffRowOrCollapsed } from "../types"; | ||
|
|
||
| import { useRowHeights } from "../hooks/useRowHeights"; | ||
| import { COLLAPSED_ROW_HEIGHT, getRowHeightFromCSS, isCollapsed } from "../utils/constants"; | ||
| import RowRendererGrid from "../utils/json-diff/row-renderer-grid"; | ||
|
|
||
| type VirtualDiffGridProps = { | ||
| leftDiff: DiffRowOrCollapsed[]; | ||
| rightDiff: DiffRowOrCollapsed[]; | ||
| outerRef: React.RefObject<Node | null>; | ||
| listRef: React.RefObject<List<any>>; | ||
| height: number; | ||
| inlineDiffOptions?: InlineDiffOptions; | ||
| className?: string; | ||
| setScrollTop: Dispatch<React.SetStateAction<number>>; | ||
| onExpand: (segmentIndex: number) => void; | ||
| }; | ||
|
|
||
| const VirtualDiffGrid: React.FC<VirtualDiffGridProps> = ({ | ||
| leftDiff, | ||
| rightDiff, | ||
| outerRef, | ||
| listRef, | ||
| height, | ||
| inlineDiffOptions, | ||
| className, | ||
| setScrollTop, | ||
| onExpand, | ||
| }) => { | ||
| // Virtual List Data | ||
| const listData = useMemo( | ||
| () => ({ | ||
| leftDiff, | ||
| rightDiff, | ||
| onExpand, | ||
| inlineDiffOptions, | ||
| }), | ||
| [leftDiff, rightDiff, onExpand, inlineDiffOptions], | ||
| ); | ||
|
|
||
| const classes = [ | ||
| "json-diff-viewer", | ||
| `json-diff-viewer-theme-custom`, | ||
| className, | ||
| ] | ||
| .filter(Boolean) | ||
| .join(" "); | ||
|
|
||
| // ROW HEIGHT CALCULATION | ||
| const ROW_HEIGHT = useMemo(() => getRowHeightFromCSS(), []); | ||
| const rowHeights = useRowHeights(leftDiff); | ||
| const dynamicRowHeights = useCallback( | ||
| (index: number) => { | ||
| const leftLine = leftDiff[index]; | ||
| if (isCollapsed(leftLine)) | ||
| return COLLAPSED_ROW_HEIGHT; | ||
| return (rowHeights[index] ?? 1) * ROW_HEIGHT; | ||
| }, | ||
| [leftDiff, rowHeights], | ||
| ); | ||
|
|
||
| useEffect(() => { | ||
| listRef.current?.resetAfterIndex(0, true); | ||
| }, [rowHeights]); | ||
|
|
||
| return ( | ||
| <div className={classes}> | ||
| <List | ||
| height={height} | ||
| width="100%" | ||
| style={{ alignItems: "start" }} | ||
| outerRef={outerRef} | ||
| ref={listRef} | ||
| className="virtual-json-diff-list-container" | ||
| itemCount={Math.max(leftDiff.length, rightDiff.length)} | ||
| itemSize={dynamicRowHeights} | ||
| overscanCount={28} | ||
utkuakyuz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| itemData={listData} | ||
| onScroll={({ scrollOffset }: ListOnScrollProps) => setScrollTop(scrollOffset)} | ||
| > | ||
| {RowRendererGrid} | ||
| </List> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| export default VirtualDiffGrid; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.