aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorStas Vilchik <stas.vilchik@sonarsource.com>2017-10-03 11:11:36 +0200
committerStas Vilchik <stas.vilchik@sonarsource.com>2017-10-04 10:35:13 +0200
commit951b3159029a368917e080e7c3d3886707fc8922 (patch)
tree105dc4994914b78d547ea645b0ea011f55f00b16 /server
parent4a8a3c39893bdcf93e9caf412fd1791fd499b0e5 (diff)
downloadsonarqube-951b3159029a368917e080e7c3d3886707fc8922.tar.gz
sonarqube-951b3159029a368917e080e7c3d3886707fc8922.zip
fix quality gates deletion/renaming
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/src/main/js/api/quality-gates.ts8
-rw-r--r--server/sonar-web/src/main/js/apps/projectQualityGate/App.tsx2
-rw-r--r--server/sonar-web/src/main/js/apps/projectQualityGate/Form.tsx12
-rw-r--r--server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/Form-test.tsx20
-rw-r--r--server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/__snapshots__/Form-test.tsx.snap10
5 files changed, 27 insertions, 25 deletions
diff --git a/server/sonar-web/src/main/js/api/quality-gates.ts b/server/sonar-web/src/main/js/api/quality-gates.ts
index c4142d3958d..9857a9c2b2a 100644
--- a/server/sonar-web/src/main/js/api/quality-gates.ts
+++ b/server/sonar-web/src/main/js/api/quality-gates.ts
@@ -26,7 +26,7 @@ export function fetchQualityGatesAppDetails(): Promise<any> {
export interface QualityGate {
isDefault?: boolean;
- id: string;
+ id: number;
name: string;
}
@@ -36,7 +36,7 @@ export function fetchQualityGates(): Promise<QualityGate[]> {
r.qualitygates.map((qualityGate: any) => {
return {
...qualityGate,
- id: String(qualityGate.id),
+ id: qualityGate.id,
isDefault: qualityGate.id === r.default
};
}),
@@ -96,14 +96,14 @@ export function getGateForProject(project: string): Promise<QualityGate | undefi
}
export function associateGateWithProject(
- gateId: string,
+ gateId: number,
projectKey: string
): Promise<void | Response> {
return post('/api/qualitygates/select', { gateId, projectKey }).catch(throwGlobalError);
}
export function dissociateGateWithProject(
- gateId: string,
+ gateId: number,
projectKey: string
): Promise<void | Response> {
return post('/api/qualitygates/deselect', { gateId, projectKey }).catch(throwGlobalError);
diff --git a/server/sonar-web/src/main/js/apps/projectQualityGate/App.tsx b/server/sonar-web/src/main/js/apps/projectQualityGate/App.tsx
index 4d254a56892..0a4f20f304b 100644
--- a/server/sonar-web/src/main/js/apps/projectQualityGate/App.tsx
+++ b/server/sonar-web/src/main/js/apps/projectQualityGate/App.tsx
@@ -82,7 +82,7 @@ export default class App extends React.PureComponent<Props> {
);
}
- handleChangeGate = (oldId: string | undefined, newId: string | undefined) => {
+ handleChangeGate = (oldId: number | undefined, newId: number | undefined) => {
const { allGates } = this.state;
if ((!oldId && !newId) || !allGates) {
diff --git a/server/sonar-web/src/main/js/apps/projectQualityGate/Form.tsx b/server/sonar-web/src/main/js/apps/projectQualityGate/Form.tsx
index 7c1d7a21ed5..b5a034ccd68 100644
--- a/server/sonar-web/src/main/js/apps/projectQualityGate/Form.tsx
+++ b/server/sonar-web/src/main/js/apps/projectQualityGate/Form.tsx
@@ -26,7 +26,7 @@ import { translate } from '../../helpers/l10n';
interface Props {
allGates: QualityGate[];
gate?: QualityGate;
- onChange: (oldGate: string | undefined, newGate: string) => Promise<void>;
+ onChange: (oldGate: number | undefined, newGate: number) => Promise<void>;
}
interface State {
@@ -62,12 +62,14 @@ export default class Form extends React.PureComponent<Props, State> {
const isSet = gate == null && option.value != null;
const isUnset = gate != null && option.value == null;
- const isChanged = gate != null && gate.id !== option.value;
+ const isChanged = gate != null && gate.id !== Number(option.value);
const hasChanged = isSet || isUnset || isChanged;
if (hasChanged) {
this.setState({ loading: true });
- this.props.onChange(gate && gate.id, option.value).then(this.stopLoading, this.stopLoading);
+ this.props
+ .onChange(gate && gate.id, Number(option.value))
+ .then(this.stopLoading, this.stopLoading);
}
};
@@ -89,7 +91,7 @@ export default class Form extends React.PureComponent<Props, State> {
const { gate, allGates } = this.props;
const options: Option[] = allGates.map(gate => ({
- value: gate.id,
+ value: String(gate.id),
label: gate.name,
isDefault: gate.isDefault
}));
@@ -108,7 +110,7 @@ export default class Form extends React.PureComponent<Props, State> {
options={options}
placeholder={translate('none')}
style={{ width: 300 }}
- value={gate && gate.id}
+ value={gate && String(gate.id)}
valueRenderer={this.renderGateName}
/>
);
diff --git a/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/Form-test.tsx b/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/Form-test.tsx
index f06a73eea6d..054a7cf6111 100644
--- a/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/Form-test.tsx
+++ b/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/Form-test.tsx
@@ -22,27 +22,27 @@ import { shallow } from 'enzyme';
import Form from '../Form';
it('renders', () => {
- const foo = randomGate('foo');
- const allGates = [foo, randomGate('bar')];
+ const foo = randomGate(1);
+ const allGates = [foo, randomGate(2)];
expect(shallow(<Form allGates={allGates} gate={foo} onChange={jest.fn()} />)).toMatchSnapshot();
});
it('changes quality gate', () => {
- const allGates = [randomGate('foo'), randomGate('bar')];
+ const allGates = [randomGate(1), randomGate(2)];
const onChange = jest.fn(() => Promise.resolve());
const wrapper = shallow(<Form allGates={allGates} onChange={onChange} />);
- wrapper.find('Select').prop<Function>('onChange')({ value: 'bar' });
- expect(onChange).lastCalledWith(undefined, 'bar');
+ wrapper.find('Select').prop<Function>('onChange')({ value: 2 });
+ expect(onChange).lastCalledWith(undefined, 2);
- wrapper.setProps({ gate: randomGate('foo') });
- wrapper.find('Select').prop<Function>('onChange')({ value: 'bar' });
- expect(onChange).lastCalledWith('foo', 'bar');
+ wrapper.setProps({ gate: randomGate(1) });
+ wrapper.find('Select').prop<Function>('onChange')({ value: 2 });
+ expect(onChange).lastCalledWith(1, 2);
});
-function randomGate(id: string) {
+function randomGate(id: number) {
return {
id,
- name: id
+ name: `name-${id}`
};
}
diff --git a/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/__snapshots__/Form-test.tsx.snap b/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/__snapshots__/Form-test.tsx.snap
index fcbb0ecfff8..afa45f5e3ba 100644
--- a/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/__snapshots__/Form-test.tsx.snap
+++ b/server/sonar-web/src/main/js/apps/projectQualityGate/__tests__/__snapshots__/Form-test.tsx.snap
@@ -42,13 +42,13 @@ exports[`renders 1`] = `
},
Object {
"isDefault": undefined,
- "label": "foo",
- "value": "foo",
+ "label": "name-1",
+ "value": "1",
},
Object {
"isDefault": undefined,
- "label": "bar",
- "value": "bar",
+ "label": "name-2",
+ "value": "2",
},
]
}
@@ -64,7 +64,7 @@ exports[`renders 1`] = `
}
}
tabSelectsValue={true}
- value="foo"
+ value="1"
valueComponent={[Function]}
valueKey="value"
valueRenderer={[Function]}