]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19850 Refetch component after the change of main branch
authorstanislavh <stanislav.honcharov@sonarsource.com>
Wed, 19 Jul 2023 09:29:00 +0000 (11:29 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 19 Jul 2023 20:03:06 +0000 (20:03 +0000)
server/sonar-web/src/main/js/app/components/ComponentContainer.tsx
server/sonar-web/src/main/js/app/components/componentContext/ComponentContext.ts
server/sonar-web/src/main/js/apps/projectBranches/ProjectBranchesApp.tsx
server/sonar-web/src/main/js/apps/projectBranches/__tests__/ProjectBranchesApp-it.tsx
server/sonar-web/src/main/js/apps/projectBranches/components/BranchLikeTabs.tsx
server/sonar-web/src/main/js/helpers/testReactTestingUtils.tsx
server/sonar-web/src/main/js/types/component.ts

index 250f27e9a60f30b13167bbf520ccd2f700afc68a..3d98cb0a5bbd9d77fe7895fa0bd4f59b82adc131 100644 (file)
@@ -359,6 +359,7 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
               isInProgress,
               isPending,
               onComponentChange: this.handleComponentChange,
+              fetchComponent: this.fetchComponent,
               projectBinding,
             }}
           >
index 8fd8ae528eaa4202326e29d903966973d9b83d7f..cc8628af211c4a2bb58bb2296af8bfbe3c862608 100644 (file)
@@ -23,4 +23,5 @@ import { ComponentContextShape } from '../../../types/component';
 
 export const ComponentContext = React.createContext<ComponentContextShape>({
   onComponentChange: noop,
+  fetchComponent: () => new Promise(noop),
 });
index a4218d59441beb46e203e30c84c71139032db48b..4890f29dd144440dfd6018632cd3651fc9444f2a 100644 (file)
@@ -28,10 +28,11 @@ import LifetimeInformation from './components/LifetimeInformation';
 
 export interface ProjectBranchesAppProps {
   component: Component;
+  fetchComponent: () => Promise<void>;
 }
 
 function ProjectBranchesApp(props: ProjectBranchesAppProps) {
-  const { component } = props;
+  const { component, fetchComponent } = props;
 
   return (
     <div className="page page-limited" id="project-branch-like">
@@ -41,7 +42,7 @@ function ProjectBranchesApp(props: ProjectBranchesAppProps) {
         <LifetimeInformation />
       </header>
 
-      <BranchLikeTabs component={component} />
+      <BranchLikeTabs component={component} fetchComponent={fetchComponent} />
     </div>
   );
 }
index abb2a03c313c82e02c1eba31d108ec07daef7351..a93db488c41a3e91b4af3a847b289298709a4060 100644 (file)
@@ -248,6 +248,7 @@ function renderProjectBranchesApp(overrides?: Partial<AppState>) {
     <ComponentContext.Provider
       value={{
         onComponentChange: jest.fn(),
+        fetchComponent: jest.fn(),
         component: mockComponent(),
       }}
     >
index ac18a821f2cce35b3c9d94834ca1d2d12836c23d..e063fc2a0b3b9acc88a65beef07b4bc9325ca49a 100644 (file)
@@ -40,6 +40,7 @@ import SetAsMainBranchModal from './SetAsMainBranchModal';
 
 interface Props {
   component: Component;
+  fetchComponent: () => Promise<void>;
 }
 
 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>(Tabs.Branch);
   const [renaming, setRenaming] = useState<BranchLike>();
   const [settingAsMain, setSettingAsMain] = useState<Branch>();
@@ -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}
         />
       </div>
@@ -134,10 +140,10 @@ export default function BranchLikeTabs(props: Props) {
 
       {settingAsMain && !isMainBranch(settingAsMain) && (
         <SetAsMainBranchModal
-          branch={settingAsMain}
           component={component}
+          branch={settingAsMain}
           onClose={handleClose}
-          onSetAsMain={handleClose}
+          onSetAsMain={handleSetAsMainBranch}
         />
       )}
     </>
index ab12c10b69d6a04bf68a022438a48c2a75ffefcf..5a47af23c3e20122e67c9cd208d295916f48de91 100644 (file)
@@ -137,6 +137,7 @@ export function renderAppWithComponentContext(
           onComponentChange: (changes: Partial<Component>) => {
             setRealComponent({ ...realComponent, ...changes });
           },
+          fetchComponent: jest.fn(),
           component: realComponent,
           ...omit(componentContext, 'component'),
         }}
index 4e7a678cc5c5354e884430e48c462399dfa1ce4a..af998ce69d2928e8a2759ac9bee18d024064e5f1 100644 (file)
@@ -100,5 +100,6 @@ export interface ComponentContextShape {
   isInProgress?: boolean;
   isPending?: boolean;
   onComponentChange: (changes: Partial<Component>) => void;
+  fetchComponent: () => Promise<void>;
   projectBinding?: ProjectAlmBindingResponse;
 }