]> source.dussan.org Git - sonarqube.git/commitdiff
fix Condition typing
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Wed, 23 May 2018 11:57:07 +0000 (13:57 +0200)
committerSonarTech <sonartech@sonarsource.com>
Thu, 24 May 2018 18:20:47 +0000 (20:20 +0200)
server/sonar-web/src/main/js/api/quality-gates.ts
server/sonar-web/src/main/js/app/types.ts
server/sonar-web/src/main/js/apps/quality-gates/components/Condition.tsx
server/sonar-web/src/main/js/apps/quality-gates/components/ConditionModal.tsx

index 490b48c22b15192a55aa57ab07c4d7d3845f3691..d2f212bd457d26d2ebe6753f521336da82be6abd 100644 (file)
@@ -19,7 +19,7 @@
  */
 import { getJSON, post, postJSON } from '../helpers/request';
 import throwGlobalError from '../app/utils/throwGlobalError';
-import { Condition, Metric, QualityGate } from '../app/types';
+import { Condition, Metric, QualityGate, Omit } from '../app/types';
 
 export function fetchQualityGates(data: {
   organization?: string;
@@ -78,7 +78,7 @@ export function createCondition(
   data: {
     gateId: number;
     organization?: string;
-  } & Condition
+  } & Omit<Condition, 'id'>
 ): Promise<Condition> {
   return postJSON('/api/qualitygates/create_condition', data);
 }
index 1967bb2497eb6a410cbfe30b9b4131d309fc7e34..11e29502c06be798e7bd6606f640a802b448e814 100644 (file)
@@ -84,7 +84,7 @@ interface ComponentConfiguration {
 
 export interface Condition {
   error: string;
-  id?: number;
+  id: number;
   metric: string;
   op?: string;
   period?: number;
index 587ce6af15ff829688e5847381dd65784721eb88..284a0e876d58d48bf513448022a0f4075cf9f8a5 100644 (file)
@@ -81,12 +81,10 @@ export default class Condition extends React.PureComponent<Props, State> {
   };
 
   removeCondition = (condition: ICondition) => {
-    if (condition.id !== undefined) {
-      deleteCondition({ id: condition.id, organization: this.props.organization }).then(
-        () => this.props.onRemoveCondition(condition),
-        () => {}
-      );
-    }
+    deleteCondition({ id: condition.id, organization: this.props.organization }).then(
+      () => this.props.onRemoveCondition(condition),
+      () => {}
+    );
   };
 
   render() {
index 7071337a79b7650b60e09677e1945c7f54cad30f..536fe76f0d1a3036d5e3cd563ade26457574d8b5 100644 (file)
@@ -23,7 +23,7 @@ import ConditionOperator from './ConditionOperator';
 import ThresholdInput from './ThresholdInput';
 import Period from './Period';
 import { translate, getLocalizedMetricName } from '../../../helpers/l10n';
-import { Metric, QualityGate, Condition } from '../../../app/types';
+import { Metric, QualityGate, Condition, Omit } from '../../../app/types';
 import { createCondition, updateCondition } from '../../../api/quality-gates';
 import { isDiffMetric } from '../../../helpers/measures';
 import { parseError } from '../../../helpers/request';
@@ -87,7 +87,7 @@ export default class ConditionModal extends React.PureComponent<Props, State> {
   };
 
   getUpdatedCondition = (metric: Metric) => {
-    const data: Condition = {
+    const data: Omit<Condition, 'id'> = {
       metric: metric.key,
       op: metric.type === 'RATING' ? 'GT' : this.state.op,
       warning: this.state.warning,