From ec45e70770eb7c35e872e8fc408a8c8545b1a4c7 Mon Sep 17 00:00:00 2001 From: Johannes Batzill Date: Mon, 18 Sep 2023 20:56:14 +0000 Subject: [PATCH] [UI] Fix PR Refreshing, Code Comment Canceling (#519) --- web/src/components/Changes/Changes.tsx | 33 +- .../CommitRangeDropdown.tsx | 15 +- .../components/CommitsView/CommitsView.tsx | 6 +- web/src/components/DiffViewer/DiffViewer.tsx | 456 +++++++++--------- .../components/DiffViewer/DiffViewerUtils.tsx | 18 +- web/src/pages/Compare/Compare.tsx | 3 +- .../PullRequest/Conversation/Conversation.tsx | 9 +- web/src/pages/PullRequest/PullRequest.tsx | 88 ++-- .../PullRequestCommits/PullRequestCommits.tsx | 6 +- .../RepositoryCommit/RepositoryCommit.tsx | 3 +- 10 files changed, 321 insertions(+), 316 deletions(-) diff --git a/web/src/components/Changes/Changes.tsx b/web/src/components/Changes/Changes.tsx index 22cbabf02..9ee1312d6 100644 --- a/web/src/components/Changes/Changes.tsx +++ b/web/src/components/Changes/Changes.tsx @@ -14,7 +14,7 @@ import * as Diff2Html from 'diff2html' import cx from 'classnames' import { useHistory } from 'react-router-dom' import { useGet } from 'restful-react' -import { noop } from 'lodash-es' +import { isEqual, noop } from 'lodash-es' import { useStrings } from 'framework/strings' import type { GitInfoProps } from 'utils/GitUtils' import { PullRequestSection, formatNumber, getErrorMessage, voidFn } from 'utils/Utils' @@ -48,7 +48,7 @@ interface ChangesProps extends Pick { pullRequestMetadata?: TypesPullReq className?: string onCommentUpdate: () => void - prHasChanged?: boolean + prStatsChanged: Number onDataReady?: (data: DiffFileEntry[]) => void defaultCommitRange?: string[] scrollElement: HTMLElement @@ -62,9 +62,9 @@ export const Changes: React.FC = ({ emptyTitle, emptyMessage, pullRequestMetadata, - onCommentUpdate, className, - prHasChanged, + onCommentUpdate, + prStatsChanged, onDataReady, defaultCommitRange, scrollElement @@ -197,24 +197,31 @@ export const Changes: React.FC = ({ // happens after some comments are authored. useEffect( function setActivitiesIfNotSet() { - if (prActivities) { - setActivities(prActivities) + if (!prActivities || isEqual(activities, prActivities)) { + return } + + setActivities(prActivities) + }, [prActivities] ) useEffect(() => { - if (prHasChanged) { - refetchActivities() + if (readOnly) { + return } - }, [prHasChanged, refetchActivities]) + + refetchActivities() + }, [prStatsChanged]) useEffect(() => { - if (prHasChanged) { - refetchFileViews() + if (readOnly) { + return } - }, [prHasChanged, refetchFileViews]) + + refetchFileViews() + }, [prStatsChanged]) useEffect(() => { const _raw = rawDiff && typeof rawDiff === 'string' ? rawDiff : '' @@ -335,7 +342,7 @@ export const Changes: React.FC = ({ // is changed. Making it easier to control states inside DiffView itself, as it does not // have to deal with any view configuration 0} // render in readonly mode in case a commit is selected key={viewStyle + index + lineBreaks} diff={diff} viewStyle={viewStyle} diff --git a/web/src/components/Changes/CommitRangeDropdown/CommitRangeDropdown.tsx b/web/src/components/Changes/CommitRangeDropdown/CommitRangeDropdown.tsx index 2900c5496..39370bdaf 100644 --- a/web/src/components/Changes/CommitRangeDropdown/CommitRangeDropdown.tsx +++ b/web/src/components/Changes/CommitRangeDropdown/CommitRangeDropdown.tsx @@ -79,11 +79,8 @@ const CommitRangeDropdown: React.FC = ({ // clicked commit is outside of current range - extend it! const extendedArray = getCommitRange([...current, selectedCommitSHA], allCommitsSHA) - // Are all commits selected, then return AllCommits explicitly - if (extendedArray.length === allCommits.length) { - return [] - } - + // NOTE: this CAN contain all commits - we let it through for consistent user experience. + // This way, the user sees selected exactly what they clicked on (+ we don't have to handle single commit pr differently) return extendedArray }) } @@ -142,9 +139,11 @@ const CommitRangeDropdown: React.FC = ({ color={Color.GREY_700} font={{ variation: FontVariation.BODY2 }} margin={{ right: 'medium' }}> - {selectedCommits.length && selectedCommits.length !== allCommitsSHA.length - ? `${selectedCommits.length} ${selectedCommits.length > 1 ? getString('commits') : getString('commit')}` - : getString('allCommits')} + { + areAllCommitsSelected + ? getString('allCommits') + : `${selectedCommits.length} ${selectedCommits.length > 1 ? getString('commits') : getString('commit')}` + } ) diff --git a/web/src/components/CommitsView/CommitsView.tsx b/web/src/components/CommitsView/CommitsView.tsx index 1945bd5e0..a017decfc 100644 --- a/web/src/components/CommitsView/CommitsView.tsx +++ b/web/src/components/CommitsView/CommitsView.tsx @@ -32,7 +32,7 @@ interface CommitsViewProps extends Pick { commits: TypesCommit[] | null emptyTitle: string emptyMessage: string - prHasChanged?: boolean + prStatsChanged?: Number handleRefresh?: () => void showFileHistoryIcons?: boolean resourcePath?: string @@ -46,7 +46,7 @@ export function CommitsView({ emptyTitle, emptyMessage, handleRefresh = noop, - prHasChanged, + prStatsChanged, showFileHistoryIcons = false, resourcePath = '', setActiveTab, @@ -186,7 +186,7 @@ export function CommitsView({ - {!prHasChanged ? null : ( + {!prStatsChanged ? null : (