From: stanislavh Date: Wed, 19 Jul 2023 09:29:00 +0000 (+0200) Subject: SONAR-19850 Refetch component after the change of main branch X-Git-Tag: 10.2.0.77647~327 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=935db01509142ef55b584e89fd7f1737dcd33fc6;p=sonarqube.git SONAR-19850 Refetch component after the change of main branch --- 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; }