fix(pull-requests): shared state + not settling? (#9332)
Co-authored-by: maria-rcks <[email protected]>
This commit is contained in:
1 parent
48ba76bc26
commit
854541a04e
9 files changed
+440
-166
No files matched your search
@@ -63,7 +63,7 @@ import { useProjects } from "~/state/entities";
|
||||
import { useEnvironments } from "~/state/environments";
|
||||
import { useEnvironmentQuery } from "~/state/query";
|
||||
import { useLiveRefresh } from "~/hooks/useLiveRefresh";
|
||||
import { pullRequestEnvironment } from "~/state/pullRequests";
|
||||
import { pullRequestEnvironment, useSharedPullRequestSummary } from "~/state/pullRequests";
|
||||
import { useAtomCommand } from "~/state/use-atom-command";
|
||||
import { vcsEnvironment } from "~/state/vcs";
|
||||
import { formatRelativeTimeLabel } from "~/timestampFormat";
|
||||
@@ -476,14 +476,8 @@ export function PullRequestDetailPanel({
|
||||
onActed?: () => void;
|
||||
/** Page-owned detail columns use this to clear the selected pull request. */
|
||||
onClose?: () => void;
|
||||
/** Keeps surrounding thread state in step with refreshed host state. */
|
||||
onStateChange?: (status: {
|
||||
projectId: string;
|
||||
repository: string;
|
||||
number: number;
|
||||
state: PullRequestState;
|
||||
isDraft: boolean;
|
||||
}) => void;
|
||||
/** Keeps surrounding inferred thread state in step with refreshed host state. */
|
||||
onStateChange?: (status: { repository: string; number: number; state: PullRequestState }) => void;
|
||||
/**
|
||||
* Beside a thread, the checkout affordance disappears: the panel is showing that thread's
|
||||
* own pull request, so the branch is already under the reader's feet — and checking it out
|
||||
@@ -606,11 +600,19 @@ export function PullRequestDetailPanel({
|
||||
reference.repository,
|
||||
reference.number,
|
||||
]);
|
||||
const coreDetail = resolveDisplayedPullRequestDetail({
|
||||
const resolvedCoreDetail = resolveDisplayedPullRequestDetail({
|
||||
live: detailQuery.data,
|
||||
cached: cachedDetail,
|
||||
reference,
|
||||
});
|
||||
const sharedSummary = useSharedPullRequestSummary(environmentId, reference, resolvedCoreDetail);
|
||||
const coreDetail = useMemo(
|
||||
() =>
|
||||
resolvedCoreDetail === null || sharedSummary === null || sharedSummary === resolvedCoreDetail
|
||||
? resolvedCoreDetail
|
||||
: { ...resolvedCoreDetail, ...sharedSummary },
|
||||
[resolvedCoreDetail, sharedSummary],
|
||||
);
|
||||
const activity = activityQuery.data;
|
||||
const detail = useMemo(
|
||||
() =>
|
||||
@@ -674,16 +676,14 @@ export function PullRequestDetailPanel({
|
||||
}
|
||||
activityRevision.current = next;
|
||||
}, [activityQuery.refresh, coreDetail, pullRequestKey]);
|
||||
useEffect(() => {
|
||||
if (!detail) return;
|
||||
useLayoutEffect(() => {
|
||||
if (!resolvedCoreDetail) return;
|
||||
onStateChange?.({
|
||||
projectId: detail.projectId,
|
||||
repository: detail.repository,
|
||||
number: detail.number,
|
||||
state: detail.state,
|
||||
isDraft: detail.isDraft,
|
||||
repository: resolvedCoreDetail.repository,
|
||||
number: resolvedCoreDetail.number,
|
||||
state: resolvedCoreDetail.state,
|
||||
});
|
||||
}, [detail, onStateChange]);
|
||||
}, [onStateChange, resolvedCoreDetail]);
|
||||
// Core detail is cheap enough to re-read while this stays open. Activity is heavier, so the
|
||||
// revision effect above reads it only after this same pull request reports a change. Keyed by
|
||||
// the pull request rather than by the panel, because this one panel shows a different pull
|
||||
|
||||
Reference in new issue
Block a user