aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main
diff options
context:
space:
mode:
authorMathieu Suen <mathieu.suen@sonarsource.com>2020-11-19 11:21:26 +0100
committersonartech <sonartech@sonarsource.com>2020-11-23 20:06:20 +0000
commitfca9924906130f85eea93f8caf64fad6a79fc317 (patch)
treeb78d1040c0b8bc3a1987e0746fbd285a17c0bf29 /server/sonar-web/src/main
parent412aeb529f65d310dcbd777a42b2fd0a8814e828 (diff)
downloadsonarqube-fca9924906130f85eea93f8caf64fad6a79fc317.tar.gz
sonarqube-fca9924906130f85eea93f8caf64fad6a79fc317.zip
Fixing codesmell
Diffstat (limited to 'server/sonar-web/src/main')
-rw-r--r--server/sonar-web/src/main/js/apps/application-console/ApplicationBranches.tsx1
-rw-r--r--server/sonar-web/src/main/js/apps/application-console/ApplicationConsoleApp.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/application-console/BranchRowActions.tsx1
-rw-r--r--server/sonar-web/src/main/js/apps/application-console/CreateBranchForm.tsx26
-rw-r--r--server/sonar-web/src/main/js/apps/application-console/ProjectBranchRow.tsx9
-rw-r--r--server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationBranches-test.tsx.snap1
6 files changed, 21 insertions, 19 deletions
diff --git a/server/sonar-web/src/main/js/apps/application-console/ApplicationBranches.tsx b/server/sonar-web/src/main/js/apps/application-console/ApplicationBranches.tsx
index c2f53284abe..bd9a2586e83 100644
--- a/server/sonar-web/src/main/js/apps/application-console/ApplicationBranches.tsx
+++ b/server/sonar-web/src/main/js/apps/application-console/ApplicationBranches.tsx
@@ -111,7 +111,6 @@ export default class ApplicationBranches extends React.PureComponent<Props, Stat
enabledProjectsKey={application.projects.map(p => p.key)}
onClose={this.handleCreateFormClose}
onCreate={this.handleCreate}
- onUpdate={() => {}}
/>
)}
</div>
diff --git a/server/sonar-web/src/main/js/apps/application-console/ApplicationConsoleApp.tsx b/server/sonar-web/src/main/js/apps/application-console/ApplicationConsoleApp.tsx
index 6a9633246c7..2c0cf5269d3 100644
--- a/server/sonar-web/src/main/js/apps/application-console/ApplicationConsoleApp.tsx
+++ b/server/sonar-web/src/main/js/apps/application-console/ApplicationConsoleApp.tsx
@@ -39,7 +39,7 @@ interface State {
loading: boolean;
}
-export default class ApplicationView extends React.PureComponent<Props, State> {
+export default class ApplicationConsoleApp extends React.PureComponent<Props, State> {
mounted = false;
state: State = {
diff --git a/server/sonar-web/src/main/js/apps/application-console/BranchRowActions.tsx b/server/sonar-web/src/main/js/apps/application-console/BranchRowActions.tsx
index 15538900ddb..0ce7924c01b 100644
--- a/server/sonar-web/src/main/js/apps/application-console/BranchRowActions.tsx
+++ b/server/sonar-web/src/main/js/apps/application-console/BranchRowActions.tsx
@@ -101,7 +101,6 @@ export default class BranchRowActions extends React.PureComponent<Props, State>
.filter(p => p.enabled)
.map(p => p.key)}
onClose={this.handleCloseForm}
- onCreate={() => {}}
onUpdate={this.handleUpdate}
/>
)}
diff --git a/server/sonar-web/src/main/js/apps/application-console/CreateBranchForm.tsx b/server/sonar-web/src/main/js/apps/application-console/CreateBranchForm.tsx
index c8fe5f4f2c3..4a34cdd8808 100644
--- a/server/sonar-web/src/main/js/apps/application-console/CreateBranchForm.tsx
+++ b/server/sonar-web/src/main/js/apps/application-console/CreateBranchForm.tsx
@@ -38,8 +38,8 @@ interface Props {
branch?: ApplicationBranch;
enabledProjectsKey: string[];
onClose: () => void;
- onCreate: (branch: ApplicationBranch) => void;
- onUpdate: (name: string) => void;
+ onCreate?: (branch: ApplicationBranch) => void;
+ onUpdate?: (name: string) => void;
}
interface BranchesList {
@@ -54,6 +54,8 @@ interface State {
selectedBranches: BranchesList;
}
+const MAX_PROJECTS_HEIGHT = 220;
+const PROJECT_HEIGHT = 22;
export default class CreateBranchForm extends React.PureComponent<Props, State> {
mounted = false;
node?: HTMLElement | null = null;
@@ -73,14 +75,14 @@ export default class CreateBranchForm extends React.PureComponent<Props, State>
const branch = this.props.branch ? this.props.branch.name : undefined;
this.setState({ loading: true });
getApplicationDetails(application.key, branch).then(
- application => {
+ ({ projects }) => {
if (this.mounted) {
- const projects = application.projects.filter(p =>
+ const enabledProjects = projects.filter(p =>
this.props.enabledProjectsKey.includes(p.key)
);
- const selected = projects.filter(p => p.selected).map(p => p.key);
+ const selected = enabledProjects.filter(p => p.selected).map(p => p.key);
const selectedBranches: BranchesList = {};
- projects.forEach(p => {
+ enabledProjects.forEach(p => {
if (!p.enabled) {
selectedBranches[p.key] = null;
} else {
@@ -95,7 +97,7 @@ export default class CreateBranchForm extends React.PureComponent<Props, State>
name: branch || '',
selected,
loading: false,
- projects,
+ projects: enabledProjects,
selectedBranches
});
}
@@ -148,7 +150,9 @@ export default class CreateBranchForm extends React.PureComponent<Props, State>
project: projectKeys,
projectBranch: projectBranches
});
- this.props.onUpdate(this.state.name);
+ if (this.props.onUpdate) {
+ this.props.onUpdate(this.state.name);
+ }
} else {
await addApplicationBranch({
application: this.props.application.key,
@@ -156,7 +160,9 @@ export default class CreateBranchForm extends React.PureComponent<Props, State>
project: projectKeys,
projectBranch: projectBranches
});
- this.props.onCreate({ name: this.state.name, isMain: false });
+ if (this.props.onCreate) {
+ this.props.onCreate({ name: this.state.name, isMain: false });
+ }
}
this.props.onClose();
};
@@ -183,7 +189,7 @@ export default class CreateBranchForm extends React.PureComponent<Props, State>
if (this.node) {
const modalTop = this.node.getBoundingClientRect().top;
const modalHeight = this.node.offsetHeight;
- const maxSelectHeight = Math.min(220, elementCount * 22 + 22);
+ const maxSelectHeight = Math.min(MAX_PROJECTS_HEIGHT, (elementCount + 1) * PROJECT_HEIGHT);
const selectBottom = selectNode.getBoundingClientRect().top + maxSelectHeight;
if (selectBottom > modalTop + modalHeight) {
this.node.classList.add('inverted-direction');
diff --git a/server/sonar-web/src/main/js/apps/application-console/ProjectBranchRow.tsx b/server/sonar-web/src/main/js/apps/application-console/ProjectBranchRow.tsx
index 8061640b298..9ce8862b8f7 100644
--- a/server/sonar-web/src/main/js/apps/application-console/ProjectBranchRow.tsx
+++ b/server/sonar-web/src/main/js/apps/application-console/ProjectBranchRow.tsx
@@ -18,6 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
+import { orderBy } from 'lodash';
import * as React from 'react';
import Checkbox from 'sonar-ui-common/components/controls/Checkbox';
import Select from 'sonar-ui-common/components/controls/Select';
@@ -58,11 +59,9 @@ export default class ProjectBranchRow extends React.PureComponent<Props, State>
}
parseBranches = (branches: Array<ApplicationBranch>) => {
- return branches
- .sort((a, b) => (a.name < b.name ? -1 : 1))
- .map(branch => {
- return { value: branch.name, label: branch.name, isMain: branch.isMain };
- });
+ return orderBy(branches, [b => b.isMain, b => b.name]).map(branch => {
+ return { value: branch.name, label: branch.name, isMain: branch.isMain };
+ });
};
setCurrentTarget = (event: React.FocusEvent<HTMLInputElement>) => {
diff --git a/server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationBranches-test.tsx.snap b/server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationBranches-test.tsx.snap
index d291936d7be..b502ef33ad5 100644
--- a/server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationBranches-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationBranches-test.tsx.snap
@@ -135,7 +135,6 @@ exports[`should render correctly: creating branch 1`] = `
}
onClose={[Function]}
onCreate={[Function]}
- onUpdate={[Function]}
/>
</div>
`;