From 935db01509142ef55b584e89fd7f1737dcd33fc6 Mon Sep 17 00:00:00 2001 From: stanislavh Date: Wed, 19 Jul 2023 11:29:00 +0200 Subject: [PATCH] SONAR-19850 Refetch component after the change of main branch --- .../js/app/components/ComponentContainer.tsx | 1 + .../componentContext/ComponentContext.ts | 1 + .../apps/projectBranches/ProjectBranchesApp.tsx | 5 +++-- .../__tests__/ProjectBranchesApp-it.tsx | 1 + .../components/BranchLikeTabs.tsx | 16 +++++++++++----- .../main/js/helpers/testReactTestingUtils.tsx | 1 + server/sonar-web/src/main/js/types/component.ts | 1 + 7 files changed, 19 insertions(+), 7 deletions(-) diff --git a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx index 250f27e9a60..3d98cb0a5bb 100644 --- a/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx +++ b/server/sonar-web/src/main/js/app/components/ComponentContainer.tsx @@ -359,6 +359,7 @@ export class ComponentContainer extends React.PureComponent { isInProgress, isPending, onComponentChange: this.handleComponentChange, + fetchComponent: this.fetchComponent, projectBinding, }} > diff --git a/server/sonar-web/src/main/js/app/components/componentContext/ComponentContext.ts b/server/sonar-web/src/main/js/app/components/componentContext/ComponentContext.ts index 8fd8ae528ea..cc8628af211 100644 --- a/server/sonar-web/src/main/js/app/components/componentContext/ComponentContext.ts +++ b/server/sonar-web/src/main/js/app/components/componentContext/ComponentContext.ts @@ -23,4 +23,5 @@ import { ComponentContextShape } from '../../../types/component'; export const ComponentContext = React.createContext({ onComponentChange: noop, + fetchComponent: () => new Promise(noop), }); diff --git a/server/sonar-web/src/main/js/apps/projectBranches/ProjectBranchesApp.tsx b/server/sonar-web/src/main/js/apps/projectBranches/ProjectBranchesApp.tsx index a4218d59441..4890f29dd14 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/ProjectBranchesApp.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/ProjectBranchesApp.tsx @@ -28,10 +28,11 @@ import LifetimeInformation from './components/LifetimeInformation'; export interface ProjectBranchesAppProps { component: Component; + fetchComponent: () => Promise; } function ProjectBranchesApp(props: ProjectBranchesAppProps) { - const { component } = props; + const { component, fetchComponent } = props; return (
@@ -41,7 +42,7 @@ function ProjectBranchesApp(props: ProjectBranchesAppProps) { - +
); } diff --git a/server/sonar-web/src/main/js/apps/projectBranches/__tests__/ProjectBranchesApp-it.tsx b/server/sonar-web/src/main/js/apps/projectBranches/__tests__/ProjectBranchesApp-it.tsx index abb2a03c313..a93db488c41 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/__tests__/ProjectBranchesApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/__tests__/ProjectBranchesApp-it.tsx @@ -248,6 +248,7 @@ function renderProjectBranchesApp(overrides?: Partial) { diff --git a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTabs.tsx b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTabs.tsx index ac18a821f2c..e063fc2a0b3 100644 --- a/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTabs.tsx +++ b/server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTabs.tsx @@ -40,6 +40,7 @@ import SetAsMainBranchModal from './SetAsMainBranchModal'; interface Props { component: Component; + fetchComponent: () => Promise; } export enum Tabs { @@ -73,7 +74,7 @@ const TABS = [ ]; export default function BranchLikeTabs(props: Props) { - const { component } = props; + const { component, fetchComponent } = props; const [currentTab, setCurrentTab] = useState(Tabs.Branch); const [renaming, setRenaming] = useState(); const [settingAsMain, setSettingAsMain] = useState(); @@ -85,7 +86,12 @@ export default function BranchLikeTabs(props: Props) { setSettingAsMain(undefined); }; - const handleSetAsMainBranch = (branchLike: BranchLike) => { + const handleSetAsMainBranch = () => { + handleClose(); + fetchComponent(); + }; + + const handleSetAsMainBranchOption = (branchLike: BranchLike) => { if (isBranch(branchLike)) { setSettingAsMain(branchLike); } @@ -119,7 +125,7 @@ export default function BranchLikeTabs(props: Props) { displayPurgeSetting={isBranchMode} onDelete={setDeleting} onRename={setRenaming} - onSetAsMain={handleSetAsMainBranch} + onSetAsMain={handleSetAsMainBranchOption} title={title} /> @@ -134,10 +140,10 @@ export default function BranchLikeTabs(props: Props) { {settingAsMain && !isMainBranch(settingAsMain) && ( )} diff --git a/server/sonar-web/src/main/js/helpers/testReactTestingUtils.tsx b/server/sonar-web/src/main/js/helpers/testReactTestingUtils.tsx index ab12c10b69d..5a47af23c3e 100644 --- a/server/sonar-web/src/main/js/helpers/testReactTestingUtils.tsx +++ b/server/sonar-web/src/main/js/helpers/testReactTestingUtils.tsx @@ -137,6 +137,7 @@ export function renderAppWithComponentContext( onComponentChange: (changes: Partial) => { setRealComponent({ ...realComponent, ...changes }); }, + fetchComponent: jest.fn(), component: realComponent, ...omit(componentContext, 'component'), }} diff --git a/server/sonar-web/src/main/js/types/component.ts b/server/sonar-web/src/main/js/types/component.ts index 4e7a678cc5c..af998ce69d2 100644 --- a/server/sonar-web/src/main/js/types/component.ts +++ b/server/sonar-web/src/main/js/types/component.ts @@ -100,5 +100,6 @@ export interface ComponentContextShape { isInProgress?: boolean; isPending?: boolean; onComponentChange: (changes: Partial) => void; + fetchComponent: () => Promise; projectBinding?: ProjectAlmBindingResponse; } -- 2.39.5