From 5d327d0ed0684ae3611a620d4e4e2d98342a4e2e Mon Sep 17 00:00:00 2001 From: Joshen Lim Date: Mon, 7 Aug 2023 11:06:50 +0800 Subject: [PATCH] Fix pull requests + preview branches section not using the parent project ref to pull data when on a preview branch --- .../interfaces/BranchManagement/BranchManagement.tsx | 10 +++++----- .../interfaces/BranchManagement/PreviewBranches.tsx | 11 ++++++++--- .../interfaces/BranchManagement/PullRequests.tsx | 11 ++++++++--- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/studio/components/interfaces/BranchManagement/BranchManagement.tsx b/studio/components/interfaces/BranchManagement/BranchManagement.tsx index 5cd9623eb07..4590a688e83 100644 --- a/studio/components/interfaces/BranchManagement/BranchManagement.tsx +++ b/studio/components/interfaces/BranchManagement/BranchManagement.tsx @@ -36,16 +36,16 @@ const BranchManagement = () => { const { ui } = useStore() const router = useRouter() const { ref } = useParams() - const projectDetails = useSelectedProject() + const project = useSelectedProject() const selectedOrg = useSelectedOrganization() const hasAccessToBranching = selectedOrg?.opt_in_tags?.includes('PREVIEW_BRANCHES_OPT_IN') ?? false + const hasBranchEnabled = project?.is_branch_enabled - const isBranch = projectDetails?.parent_project_ref !== undefined - const hasBranchEnabled = projectDetails?.is_branch_enabled + const isBranch = project?.parent_project_ref !== undefined const projectRef = - projectDetails !== undefined ? (isBranch ? projectDetails.parent_project_ref : ref) : undefined + project !== undefined ? (isBranch ? project.parent_project_ref : ref) : undefined const snap = useAppUiStateSnapshot() const [showCreateBranch, setShowCreateBranch] = useState(false) @@ -64,7 +64,7 @@ const BranchManagement = () => { ?.filter((integration) => integration.integration.name === 'GitHub') .flatMap((integration) => integration.connections) const githubConnection = githubConnections?.find( - (connection) => connection.supabase_project_ref === ref + (connection) => connection.supabase_project_ref === projectRef ) const { data: branches } = useBranchesQuery({ projectRef }) diff --git a/studio/components/interfaces/BranchManagement/PreviewBranches.tsx b/studio/components/interfaces/BranchManagement/PreviewBranches.tsx index 6b11a67ae32..4580d704189 100644 --- a/studio/components/interfaces/BranchManagement/PreviewBranches.tsx +++ b/studio/components/interfaces/BranchManagement/PreviewBranches.tsx @@ -5,7 +5,7 @@ import { BranchContainer, BranchHeader, BranchPanel } from './BranchPanels' import { useParams } from 'common' import { useGithubPullRequestsQuery } from 'data/integrations/integrations-github-pull-requests-query' import { partition } from 'lodash' -import { useSelectedOrganization } from 'hooks' +import { useSelectedOrganization, useSelectedProject } from 'hooks' import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only' import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader' import AlertError from 'components/ui/AlertError' @@ -22,8 +22,13 @@ const PreviewBranches = ({ onSelectDeleteBranch, }: PreviewBranchesProps) => { const { ref } = useParams() + const project = useSelectedProject() const selectedOrg = useSelectedOrganization() + const isBranch = project?.parent_project_ref !== undefined + const projectRef = + project !== undefined ? (isBranch ? project.parent_project_ref : ref) : undefined + const { data: integrations } = useOrgIntegrationsQuery({ orgSlug: selectedOrg?.slug, }) @@ -33,7 +38,7 @@ const PreviewBranches = ({ integration.organization.slug === selectedOrg?.slug ) const githubConnection = githubIntegration?.connections.find( - (connection) => connection.supabase_project_ref === ref + (connection) => connection.supabase_project_ref === projectRef ) const [repoOwner, repoName] = githubConnection?.metadata.name.split('/') || [] @@ -43,7 +48,7 @@ const PreviewBranches = ({ isLoading: isLoadingBranches, isError: isErrorBranches, isSuccess: isSuccessBranches, - } = useBranchesQuery({ projectRef: ref }) + } = useBranchesQuery({ projectRef }) const [[mainBranch], previewBranches] = partition(branches, (branch) => branch.is_default) const { data: allPullRequests } = useGithubPullRequestsQuery({ diff --git a/studio/components/interfaces/BranchManagement/PullRequests.tsx b/studio/components/interfaces/BranchManagement/PullRequests.tsx index 882840d6693..0a6f0154283 100644 --- a/studio/components/interfaces/BranchManagement/PullRequests.tsx +++ b/studio/components/interfaces/BranchManagement/PullRequests.tsx @@ -5,7 +5,7 @@ import { useParams } from 'common' import { Branch, useBranchesQuery } from 'data/branches/branches-query' import { useGithubPullRequestsQuery } from 'data/integrations/integrations-github-pull-requests-query' import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only' -import { useSelectedOrganization } from 'hooks' +import { useSelectedOrganization, useSelectedProject } from 'hooks' import { BranchContainer, BranchHeader, PullRequestPanel } from './BranchPanels' import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader' import AlertError from 'components/ui/AlertError' @@ -22,9 +22,14 @@ const PullRequests = ({ onSelectDeleteBranch, }: PullRequestsProps) => { const { ref } = useParams() + const project = useSelectedProject() const selectedOrg = useSelectedOrganization() const pullRequestUrl = generateCreatePullRequestURL() + const isBranch = project?.parent_project_ref !== undefined + const projectRef = + project !== undefined ? (isBranch ? project.parent_project_ref : ref) : undefined + const { data: integrations, isLoading: isLoadingIntegrations } = useOrgIntegrationsQuery({ orgSlug: selectedOrg?.slug, }) @@ -35,11 +40,11 @@ const PullRequests = ({ ) const githubConnection = githubIntegration?.connections?.find( - (connection) => connection.supabase_project_ref === ref + (connection) => connection.supabase_project_ref === projectRef ) const [repoOwner, repoName] = githubConnection?.metadata.name.split('/') || [] - const { data: branches, isLoading: isLoadingBranches } = useBranchesQuery({ projectRef: ref }) + const { data: branches, isLoading: isLoadingBranches } = useBranchesQuery({ projectRef }) const mainBranch = branches?.find((branch) => branch.is_default) const {