From 344ad09a65ca5a7e00465028f899f65765d7fa97 Mon Sep 17 00:00:00 2001 From: nicosampler Date: Sat, 17 Aug 2024 11:53:55 -0300 Subject: [PATCH] feat(website): CAN-488 Show package code when diff can't be shown. --- .../features/Deploy/TransactionDisplay.tsx | 96 +++++++++++++------ packages/website/src/hooks/cannon.ts | 1 + packages/website/src/hooks/git.ts | 16 +++- 3 files changed, 82 insertions(+), 31 deletions(-) diff --git a/packages/website/src/features/Deploy/TransactionDisplay.tsx b/packages/website/src/features/Deploy/TransactionDisplay.tsx index 9fe372e52..7ba811ff0 100644 --- a/packages/website/src/features/Deploy/TransactionDisplay.tsx +++ b/packages/website/src/features/Deploy/TransactionDisplay.tsx @@ -21,13 +21,26 @@ import { Text, Image, Portal, - Code, + Skeleton, + Stack, } from '@chakra-ui/react'; import { Diff, parseDiff, Hunk } from 'react-diff-view'; -import { InfoOutlineIcon } from '@chakra-ui/icons'; import { GitHub } from 'react-feather'; import { DisplayedTransaction } from './DisplayedTransaction'; +const CommitLink = ({ gitUrl, hash }: { gitUrl?: string; hash?: string }) => { + if (!gitUrl || !hash) return null; + + return ( + + + + {hash} + {' '} + + ); +}; + const parseDiffFileNames = (diffString: string): string[] => { const regExp = /[-|+]{3}\s[ab]\/\.(.*?)\n/g; let match; @@ -38,6 +51,17 @@ const parseDiffFileNames = (diffString: string): string[] => { return fileNames; }; +const NoDiffWarning = () => ( + + + No cannon-file diff available. This may occur when + signing an initial deployment, changing Safes used for deployments, + changing package names for the deployment, or re-executing the same + partial deployment more than once. + + +); + export function TransactionDisplay(props: { safeTxn: SafeTransaction; safe: SafeDefinition; @@ -80,7 +104,11 @@ export function TransactionDisplay(props: { gitFile ?? '' ); - const { patches } = useGitDiff( + const { + patches, + isLoading: isGitDiffLoading, + areDiff, + } = useGitDiff( gitUrl ?? '', prevDeployGitHash, hintData?.gitRepoHash ?? '', @@ -114,20 +142,34 @@ export function TransactionDisplay(props: { return ( + {/* Code diff */} - {props.showQueueSource && - props.queuedWithGitOps && - (prevDeployGitHash ? ( + {isGitDiffLoading ? ( + + + + + + + ) : ( + props.showQueueSource && + props.queuedWithGitOps && ( <> + {prevDeployGitHash == '' && } + {/* Commit hashes */} - - {prevDeployGitHash} - - - {hintData?.gitRepoHash} - + {areDiff && ( + + + + )} + + + + + {/* package code */} {patches.map((p, i) => { const { oldRevision, newRevision, type, hunks } = parseDiff(p)[0]; @@ -149,16 +191,18 @@ export function TransactionDisplay(props: { py="1" fontWeight="semibold" > - - {fromFileName} - - - {toFileName} + {areDiff && ( + + {fromFileName} + + )} + + {areDiff ? toFileName : fromFileName} @@ -174,18 +218,11 @@ export function TransactionDisplay(props: { })} - ) : ( - <> - - {' '} - No cannonfile diff available. This may occur - when signing an initial deployment, changing Safes used for - deployments, changing package names for the deployment, or - re-executing the same partial deployment more than once. - - - ))} + ) + )} + + {/* Queued from */} {props.showQueueSource && (props.queuedWithGitOps ? ( <> @@ -290,6 +327,7 @@ export function TransactionDisplay(props: { ))} + {/* Transactions */} {hintData.txns.map((txn, i) => { const pkgUrl = hintData.cannonPackage.split(',')[i]; diff --git a/packages/website/src/hooks/cannon.ts b/packages/website/src/hooks/cannon.ts index cffd7a036..dea41c93c 100644 --- a/packages/website/src/hooks/cannon.ts +++ b/packages/website/src/hooks/cannon.ts @@ -61,6 +61,7 @@ export function useLoadCannonDefinition(repo: string, ref: string, filepath: str }); return { + isLoading: loadGitRepoQuery.isLoading || loadDefinitionQuery.isLoading, isFetching: loadGitRepoQuery.isFetching || loadDefinitionQuery.isFetching, isError: loadGitRepoQuery.isError || loadDefinitionQuery.isError, error: loadGitRepoQuery.error || loadDefinitionQuery.error, diff --git a/packages/website/src/hooks/git.ts b/packages/website/src/hooks/git.ts index a14bd1435..f2e568a5f 100644 --- a/packages/website/src/hooks/git.ts +++ b/packages/website/src/hooks/git.ts @@ -83,12 +83,22 @@ export function useGitDiff(url: string, fromRef: string, toRef: string, files: s const patches = useMemo(() => { const patches: string[] = []; - if (!fromQuery.data || !toQuery.data) return patches; + if (!fromQuery.data && !toQuery.data) return patches; const fromFiles = fromQuery.data; const toFiles = toQuery.data; - for (let i = 0; i < fromFiles.length; i++) { + // If the fromFiles are not available, then we only use the toFiles to create the patches. + if (!fromFiles && toFiles) { + for (let i = 0; i < toFiles.length; i++) { + const p = createTwoFilesPatch('a/', `b/${files[i]}`, '', toFiles[i], undefined, undefined); + patches.push(p.slice(p.indexOf('\n'))); + } + return patches; + } + + // create patches comparing the fromFiles and toFiles + for (let i = 0; i < fromFiles!.length; i++) { const p = createTwoFilesPatch(`a/${files[i]}`, `b/${files[i]}`, fromFiles![i], toFiles![i], undefined, undefined); patches.push(p.slice(p.indexOf('\n'))); } @@ -97,6 +107,8 @@ export function useGitDiff(url: string, fromRef: string, toRef: string, files: s }, [fromQuery.status, toQuery.status]); return { + isLoading: fromQuery.isLoading || toQuery.isLoading, + areDiff: Boolean((fromQuery.data || []).length), patches, fromQuery, toQuery,