Browse Source

Fixing codesmell

tags/8.6.0.39681
Mathieu Suen 3 years ago
parent
commit
fca9924906

+ 0
- 1
server/sonar-web/src/main/js/apps/application-console/ApplicationBranches.tsx View File

@@ -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>

+ 1
- 1
server/sonar-web/src/main/js/apps/application-console/ApplicationConsoleApp.tsx View File

@@ -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 = {

+ 0
- 1
server/sonar-web/src/main/js/apps/application-console/BranchRowActions.tsx View File

@@ -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}
/>
)}

+ 16
- 10
server/sonar-web/src/main/js/apps/application-console/CreateBranchForm.tsx View File

@@ -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');

+ 4
- 5
server/sonar-web/src/main/js/apps/application-console/ProjectBranchRow.tsx View File

@@ -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>) => {

+ 0
- 1
server/sonar-web/src/main/js/apps/application-console/__tests__/__snapshots__/ApplicationBranches-test.tsx.snap View File

@@ -135,7 +135,6 @@ exports[`should render correctly: creating branch 1`] = `
}
onClose={[Function]}
onCreate={[Function]}
onUpdate={[Function]}
/>
</div>
`;

Loading…
Cancel
Save