export interface QualityGate {
isDefault?: boolean;
- id: string;
+ id: number;
name: string;
}
r.qualitygates.map((qualityGate: any) => {
return {
...qualityGate,
- id: String(qualityGate.id),
+ id: qualityGate.id,
isDefault: qualityGate.id === r.default
};
}),
}
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);
);
}
- handleChangeGate = (oldId: string | undefined, newId: string | undefined) => {
+ handleChangeGate = (oldId: number | undefined, newId: number | undefined) => {
const { allGates } = this.state;
if ((!oldId && !newId) || !allGates) {
interface Props {
allGates: QualityGate[];
gate?: QualityGate;
- onChange: (oldGate: string | undefined, newGate: string) => Promise<void>;
+ onChange: (oldGate: number | undefined, newGate: number) => Promise<void>;
}
interface 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);
}
};
const { gate, allGates } = this.props;
const options: Option[] = allGates.map(gate => ({
- value: gate.id,
+ value: String(gate.id),
label: gate.name,
isDefault: gate.isDefault
}));
options={options}
placeholder={translate('none')}
style={{ width: 300 }}
- value={gate && gate.id}
+ value={gate && String(gate.id)}
valueRenderer={this.renderGateName}
/>
);
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}`
};
}
},
Object {
"isDefault": undefined,
- "label": "foo",
- "value": "foo",
+ "label": "name-1",
+ "value": "1",
},
Object {
"isDefault": undefined,
- "label": "bar",
- "value": "bar",
+ "label": "name-2",
+ "value": "2",
},
]
}
}
}
tabSelectsValue={true}
- value="foo"
+ value="1"
valueComponent={[Function]}
valueKey="value"
valueRenderer={[Function]}