From 9807408f12f2f07321fcc2f16a5f57c2a6bd4252 Mon Sep 17 00:00:00 2001 From: nicholas-codecov Date: Mon, 6 Jan 2025 08:41:54 -0500 Subject: [PATCH] feat: Fetch isCached Field with CommitPageDataQueryOpts - Round 2 (#3631) --- .../CommitBundleAnalysis.test.tsx | 4 ++++ .../CommitCoverage/CommitCoverage.test.jsx | 4 ++++ .../CommitDetailPage.test.tsx | 4 ++++ .../queries/CommitPageDataQueryOpts.test.tsx | 10 +++++++++- .../queries/CommitPageDataQueryOpts.tsx | 20 ++++++++++++++++++- 5 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/pages/CommitDetailPage/CommitBundleAnalysis/CommitBundleAnalysis.test.tsx b/src/pages/CommitDetailPage/CommitBundleAnalysis/CommitBundleAnalysis.test.tsx index 782c7d3bc8..68cf301ffe 100644 --- a/src/pages/CommitDetailPage/CommitBundleAnalysis/CommitBundleAnalysis.test.tsx +++ b/src/pages/CommitDetailPage/CommitBundleAnalysis/CommitBundleAnalysis.test.tsx @@ -41,6 +41,10 @@ const mockCommitPageData = ({ __typename: 'Comparison', }, bundleAnalysis: { + bundleAnalysisReport: { + __typename: 'BundleAnalysisReport', + isCached: false, + }, bundleAnalysisCompareWithParent: { __typename: firstPullRequest ? 'FirstPullRequest' diff --git a/src/pages/CommitDetailPage/CommitCoverage/CommitCoverage.test.jsx b/src/pages/CommitDetailPage/CommitCoverage/CommitCoverage.test.jsx index b4a08236e9..1b49948344 100644 --- a/src/pages/CommitDetailPage/CommitCoverage/CommitCoverage.test.jsx +++ b/src/pages/CommitDetailPage/CommitCoverage/CommitCoverage.test.jsx @@ -317,6 +317,10 @@ const mockCommitPageData = ( : 'Comparison', }, bundleAnalysis: { + bundleAnalysisReport: { + __typename: 'BundleAnalysisReport', + isCached: false, + }, bundleAnalysisCompareWithParent: { __typename: 'BundleAnalysisComparison', }, diff --git a/src/pages/CommitDetailPage/CommitDetailPage.test.tsx b/src/pages/CommitDetailPage/CommitDetailPage.test.tsx index 84365a90db..842d5650f3 100644 --- a/src/pages/CommitDetailPage/CommitDetailPage.test.tsx +++ b/src/pages/CommitDetailPage/CommitDetailPage.test.tsx @@ -53,6 +53,10 @@ const mockCommitPageData = ({ __typename: 'Comparison', }, bundleAnalysis: { + bundleAnalysisReport: { + __typename: 'BundleAnalysisReport', + isCached: false, + }, bundleAnalysisCompareWithParent: { __typename: 'BundleAnalysisComparison', }, diff --git a/src/pages/CommitDetailPage/queries/CommitPageDataQueryOpts.test.tsx b/src/pages/CommitDetailPage/queries/CommitPageDataQueryOpts.test.tsx index 456c92fbab..34e934284f 100644 --- a/src/pages/CommitDetailPage/queries/CommitPageDataQueryOpts.test.tsx +++ b/src/pages/CommitDetailPage/queries/CommitPageDataQueryOpts.test.tsx @@ -23,6 +23,10 @@ const mockCommitData = { __typename: 'Comparison', }, bundleAnalysis: { + bundleAnalysisReport: { + __typename: 'BundleAnalysisReport', + isCached: false, + }, bundleAnalysisCompareWithParent: { __typename: 'BundleAnalysisComparison', }, @@ -89,7 +93,7 @@ interface SetupArgs { isNullOwner?: boolean } -describe('useCommitPageData', () => { +describe('CommitPageData', () => { function setup({ isNotFoundError = false, isOwnerNotActivatedError = false, @@ -146,6 +150,10 @@ describe('useCommitPageData', () => { __typename: 'Comparison', }, bundleAnalysis: { + bundleAnalysisReport: { + __typename: 'BundleAnalysisReport', + isCached: false, + }, bundleAnalysisCompareWithParent: { __typename: 'BundleAnalysisComparison', }, diff --git a/src/pages/CommitDetailPage/queries/CommitPageDataQueryOpts.tsx b/src/pages/CommitDetailPage/queries/CommitPageDataQueryOpts.tsx index a1634ec141..25df363ab2 100644 --- a/src/pages/CommitDetailPage/queries/CommitPageDataQueryOpts.tsx +++ b/src/pages/CommitDetailPage/queries/CommitPageDataQueryOpts.tsx @@ -17,6 +17,16 @@ import Api from 'shared/api' import { rejectNetworkError } from 'shared/api/helpers' import A from 'ui/A' +const BundleAnalysisReportSchema = z.object({ + __typename: z.literal('BundleAnalysisReport'), + isCached: z.boolean(), +}) + +const BundleAnalysisReportUnion = z.discriminatedUnion('__typename', [ + BundleAnalysisReportSchema, + z.object({ __typename: MissingHeadReportSchema.shape.__typename }), +]) + const BundleAnalysisComparisonResult = z.union([ z.literal('BundleAnalysisComparison'), FirstPullRequestSchema.shape.__typename, @@ -54,6 +64,7 @@ const RepositorySchema = z.object({ .nullable(), bundleAnalysis: z .object({ + bundleAnalysisReport: BundleAnalysisReportUnion.nullable(), bundleAnalysisCompareWithParent: z .object({ __typename: BundleAnalysisComparisonResult, @@ -98,6 +109,12 @@ query CommitPageData($owner: String!, $repo: String!, $commitId: String!) { __typename } bundleAnalysis { + bundleAnalysisReport { + __typename + ... on BundleAnalysisReport { + isCached + } + } bundleAnalysisCompareWithParent { __typename } @@ -112,7 +129,8 @@ query CommitPageData($owner: String!, $repo: String!, $commitId: String!) { } } } -}` +} +` interface CommitPageDataQueryArgs { provider: string