From: Stas Vilchik Date: Tue, 3 Oct 2017 09:11:36 +0000 (+0200) Subject: fix quality gates deletion/renaming X-Git-Tag: 6.6-RC1~69 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=951b3159029a368917e080e7c3d3886707fc8922;p=sonarqube.git fix quality gates deletion/renaming --- 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 { export interface QualityGate { isDefault?: boolean; - id: string; + id: number; name: string; } @@ -36,7 +36,7 @@ export function fetchQualityGates(): Promise { 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 { return post('/api/qualitygates/select', { gateId, projectKey }).catch(throwGlobalError); } export function dissociateGateWithProject( - gateId: string, + gateId: number, projectKey: string ): Promise { 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 { ); } - 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; + onChange: (oldGate: number | undefined, newGate: number) => Promise; } interface State { @@ -62,12 +62,14 @@ export default class Form extends React.PureComponent { 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 { 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 { 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(
)).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(); - wrapper.find('Select').prop('onChange')({ value: 'bar' }); - expect(onChange).lastCalledWith(undefined, 'bar'); + wrapper.find('Select').prop('onChange')({ value: 2 }); + expect(onChange).lastCalledWith(undefined, 2); - wrapper.setProps({ gate: randomGate('foo') }); - wrapper.find('Select').prop('onChange')({ value: 'bar' }); - expect(onChange).lastCalledWith('foo', 'bar'); + wrapper.setProps({ gate: randomGate(1) }); + wrapper.find('Select').prop('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]}