-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web-scraping): support
Show diff
functionality for the web pag…
…e content tracker
- Loading branch information
Showing
5 changed files
with
97 additions
and
57 deletions.
There are no files selected for viewing
31 changes: 21 additions & 10 deletions
31
src/pages/workspace/utils/web_scraping/web_page_content_tracker_revision.tsx
This file contains 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 |
---|---|---|
@@ -1,23 +1,34 @@ | ||
import { EuiCodeBlock } from '@elastic/eui'; | ||
import { EuiCodeBlock, useEuiTextDiff } from '@elastic/eui'; | ||
|
||
import type { WebPageContentRevision } from './web_page_data_revision'; | ||
|
||
export interface WebPageContentTrackerRevisionProps { | ||
revision: WebPageContentRevision; | ||
previousRevision?: WebPageContentRevision; | ||
showDiff?: boolean; | ||
} | ||
|
||
export function WebPageContentTrackerRevision({ revision }: WebPageContentTrackerRevisionProps) { | ||
const parsedData = JSON.parse(revision.data) as string | number | object; | ||
function getTextToRender(text: string): [string, string | undefined] { | ||
const parsedData = JSON.parse(text) as string | object; | ||
if (parsedData && typeof parsedData === 'object') { | ||
return ( | ||
<EuiCodeBlock fontSize={'l'} language={'json'} isCopyable> | ||
{JSON.stringify(parsedData, null, 2)} | ||
</EuiCodeBlock> | ||
); | ||
return [JSON.stringify(parsedData, null, 2), 'json']; | ||
} | ||
|
||
return [parsedData, undefined]; | ||
} | ||
|
||
export function WebPageContentTrackerRevision({ | ||
revision, | ||
previousRevision, | ||
showDiff, | ||
}: WebPageContentTrackerRevisionProps) { | ||
const [afterText, language] = getTextToRender(revision.data); | ||
const [beforeText] = previousRevision && showDiff ? getTextToRender(previousRevision.data) : [afterText]; | ||
|
||
const [textToRender] = useEuiTextDiff({ beforeText, afterText }); | ||
return ( | ||
<EuiCodeBlock fontSize={'l'} isCopyable> | ||
{parsedData} | ||
<EuiCodeBlock fontSize={'l'} language={language} isCopyable> | ||
{!showDiff || afterText === beforeText ? afterText : textToRender} | ||
</EuiCodeBlock> | ||
); | ||
} |
This file contains 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 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 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 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