]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10994 Connect BranchStatus component to new branch store
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Wed, 6 Mar 2019 15:28:10 +0000 (16:28 +0100)
committersonartech <sonartech@sonarsource.com>
Fri, 29 Mar 2019 08:44:57 +0000 (09:44 +0100)
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenuItem.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenuItem-test.tsx.snap
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMeta-test.tsx.snap
server/sonar-web/src/main/js/apps/projectBranches/components/BranchRow.tsx
server/sonar-web/src/main/js/apps/projectBranches/components/__tests__/__snapshots__/BranchRow-test.tsx.snap
server/sonar-web/src/main/js/components/common/BranchStatus.tsx
server/sonar-web/src/main/js/components/common/__tests__/BranchStatus-test.tsx

index f05afbd4bfe075995d191bff79d0d33dd4b94d5e..8455831806e3ec78b6c1874dfd6ec9b93fdb555e 100644 (file)
@@ -69,7 +69,7 @@ export default function ComponentNavBranchesMenuItem({ branchLike, ...props }: P
           )}
         </div>
         <div className="big-spacer-left note">
-          <BranchStatus branchLike={branchLike} />
+          <BranchStatus branchLike={branchLike} component={props.component.key} />
         </div>
       </Link>
     </li>
index 9eb4704aa4335761910201691df68f898ea2eff6..f72338ef2e842b64cdd57269d32a265b560b0c6f 100644 (file)
@@ -95,7 +95,7 @@ export function ComponentNavMeta({ branchLike, component, currentUser, warnings
                 <DetachIcon className="little-spacer-left" size={12} />
               </a>
             )}
-          <BranchStatus branchLike={branchLike} />
+          <BranchStatus branchLike={branchLike} component={component.key} />
         </div>
       )}
     </div>
index 3d0620b4377c9adbc22af3e4b6e4631aa6f1ebd5..04c1bf0c7919f83b18c048e26d9df4955123e538 100644 (file)
@@ -42,13 +42,14 @@ exports[`renders main branch 1`] = `
     <div
       className="big-spacer-left note"
     >
-      <BranchStatus
+      <Connect(BranchStatus)
         branchLike={
           Object {
             "isMain": true,
             "name": "master",
           }
         }
+        component="component"
       />
     </div>
   </Link>
@@ -97,7 +98,7 @@ exports[`renders short-living branch 1`] = `
     <div
       className="big-spacer-left note"
     >
-      <BranchStatus
+      <Connect(BranchStatus)
         branchLike={
           Object {
             "isMain": false,
@@ -109,6 +110,7 @@ exports[`renders short-living branch 1`] = `
             "type": "SHORT",
           }
         }
+        component="component"
       />
     </div>
   </Link>
@@ -158,7 +160,7 @@ exports[`renders short-living orhpan branch 1`] = `
     <div
       className="big-spacer-left note"
     >
-      <BranchStatus
+      <Connect(BranchStatus)
         branchLike={
           Object {
             "isMain": false,
@@ -171,6 +173,7 @@ exports[`renders short-living orhpan branch 1`] = `
             "type": "SHORT",
           }
         }
+        component="component"
       />
     </div>
   </Link>
index efe7cceabd82990904e70183aca641eaf2c27860..fdd4a833114568dbc46f2c1d4d0f6ca4ecf1aaf3 100644 (file)
@@ -52,7 +52,7 @@ exports[`renders meta for pull request 1`] = `
         size={12}
       />
     </a>
-    <BranchStatus
+    <Connect(BranchStatus)
       branchLike={
         Object {
           "analysisDate": "2018-01-01",
@@ -63,6 +63,7 @@ exports[`renders meta for pull request 1`] = `
           "url": "https://example.com/pull/1234",
         }
       }
+      component="my-project"
     />
   </div>
 </div>
@@ -82,7 +83,7 @@ exports[`renders status of short-living branch 1`] = `
   <div
     className="navbar-context-meta-secondary display-inline-flex-center"
   >
-    <BranchStatus
+    <Connect(BranchStatus)
       branchLike={
         Object {
           "analysisDate": "2018-01-01",
@@ -92,6 +93,7 @@ exports[`renders status of short-living branch 1`] = `
           "type": "SHORT",
         }
       }
+      component="my-project"
     />
   </div>
 </div>
index 0bdf8ee4576cb19be14008cc9470e9cca22a480d..60011b07ab149276a57fe2c45fdafb4c7cbd7ec1 100644 (file)
@@ -157,7 +157,7 @@ export default class BranchRow extends React.PureComponent<Props, State> {
   }
 
   render() {
-    const { branchLike, isOrphan } = this.props;
+    const { branchLike, component, isOrphan } = this.props;
     const indented = (isShortLivingBranch(branchLike) || isPullRequest(branchLike)) && !isOrphan;
 
     return (
@@ -173,7 +173,7 @@ export default class BranchRow extends React.PureComponent<Props, State> {
           )}
         </td>
         <td className="thin nowrap">
-          <BranchStatus branchLike={branchLike} />
+          <BranchStatus branchLike={branchLike} component={component} />
         </td>
         <td className="thin nowrap text-right big-spacer-left">
           {branchLike.analysisDate && <DateFromNow date={branchLike.analysisDate} />}
index cc9f9c8b924fbc0f3ea25a5abf9a2f689c7c78cf..1a2b636607c3b8d9822954bfacf74f54c87bf5fb 100644 (file)
@@ -22,13 +22,14 @@ exports[`renders main branch 1`] = `
   <td
     className="thin nowrap"
   >
-    <BranchStatus
+    <Connect(BranchStatus)
       branchLike={
         Object {
           "isMain": true,
           "name": "master",
         }
       }
+      component="foo"
     />
   </td>
   <td
@@ -70,7 +71,7 @@ exports[`renders pull request 1`] = `
   <td
     className="thin nowrap"
   >
-    <BranchStatus
+    <Connect(BranchStatus)
       branchLike={
         Object {
           "base": "master",
@@ -79,6 +80,7 @@ exports[`renders pull request 1`] = `
           "title": "Feature PR",
         }
       }
+      component="foo"
     />
   </td>
   <td
@@ -122,7 +124,7 @@ exports[`renders short-living branch 1`] = `
   <td
     className="thin nowrap"
   >
-    <BranchStatus
+    <Connect(BranchStatus)
       branchLike={
         Object {
           "analysisDate": "2017-09-27T00:05:19+0000",
@@ -132,6 +134,7 @@ exports[`renders short-living branch 1`] = `
           "type": "SHORT",
         }
       }
+      component="foo"
     />
   </td>
   <td
index e0f712a68a7d9e45b352b1fc328e5525e1597ad7..61cb36b02f60b94644e75ea8b0b823743e2aebef 100644 (file)
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import * as React from 'react';
+import { connect } from 'react-redux';
 import Level from '../ui/Level';
+import { Store, getBranchStatusByBranchLike } from '../../store/rootReducer';
 
 interface Props {
   branchLike: T.BranchLike;
+  component: string;
+  status?: string;
 }
 
-export default function BranchStatus({ branchLike }: Props) {
-  if (!branchLike.status) {
+export function BranchStatus({ status }: Props) {
+  if (!status) {
     return null;
   }
 
-  return <Level level={branchLike.status.qualityGateStatus} small={true} />;
+  return <Level level={status} small={true} />;
 }
+
+const mapStateToProps = (state: Store, { branchLike, component }: Props) => {
+  const status = getBranchStatusByBranchLike(state, component, branchLike);
+  return { status };
+};
+
+export default connect(mapStateToProps)(BranchStatus);
index c09200b988059af1d2bdc5f7beb7cbbb34da8a5b..345a6ec8ae91c901fc75b80ecfe49edc99ef4272 100644 (file)
  */
 import * as React from 'react';
 import { shallow } from 'enzyme';
-import BranchStatus from '../BranchStatus';
+import { BranchStatus } from '../BranchStatus';
+import { mockLongLivingBranch } from '../../../helpers/testMocks';
 
 it('should render correctly', () => {
-  const branch: T.MainBranch = { isMain: true, name: 'foo' };
-  expect(getWrapper(branch).type()).toBeNull();
-  expect(getWrapper(branch, 'OK')).toMatchSnapshot();
-  expect(getWrapper(branch, 'ERROR')).toMatchSnapshot();
+  expect(shallowRender().type()).toBeNull();
+  expect(shallowRender('OK')).toMatchSnapshot();
+  expect(shallowRender('ERROR')).toMatchSnapshot();
 });
 
-function getWrapper(branch: T.MainBranch, qualityGateStatus?: string) {
-  if (qualityGateStatus) {
-    branch.status = { qualityGateStatus };
-  }
-  return shallow(<BranchStatus branchLike={branch} />);
+function shallowRender(status?: string) {
+  return shallow(
+    <BranchStatus branchLike={mockLongLivingBranch()} component="foo" status={status} />
+  );
 }