]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20607 Remove unecessary isDefault assertion (#9625)
authorAndrey Luiz <andrey.luiz@sonarsource.com>
Thu, 12 Oct 2023 12:18:46 +0000 (14:18 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 12 Oct 2023 20:02:51 +0000 (20:02 +0000)
server/sonar-web/src/main/js/apps/quality-gates/components/App.tsx
server/sonar-web/src/main/js/apps/quality-gates/components/Details.tsx
server/sonar-web/src/main/js/apps/quality-gates/components/DetailsContent.tsx
server/sonar-web/src/main/js/apps/quality-gates/utils.ts

index 4eaeb02b60f9e24627e48a9a8e1fdc4d542fac50..b4eed74db870102a460bfadbd5c32150ffdc6eb9 100644 (file)
@@ -162,7 +162,6 @@ class App extends React.PureComponent<Props, State> {
                 <Details
                   qualityGateName={name}
                   onSetDefault={this.handleSetDefault}
-                  qualityGates={this.state.qualityGates}
                   refreshQualityGates={this.fetchQualityGates}
                 />
               </StyledContentWrapper>
index 695f6e41b78da25928bb9ad9cfa35c4684e51dec..e54437d6ad008aef56d6ec5dbd4e61d2bf386aa6 100644 (file)
@@ -26,14 +26,13 @@ import { fetchQualityGate } from '../../../api/quality-gates';
 import { addGlobalSuccessMessage } from '../../../helpers/globalMessages';
 import { translate } from '../../../helpers/l10n';
 import { Condition, QualityGate } from '../../../types/types';
-import { addCondition, checkIfDefault, deleteCondition, replaceCondition } from '../utils';
+import { addCondition, deleteCondition, replaceCondition } from '../utils';
 import DetailsContent from './DetailsContent';
 import DetailsHeader from './DetailsHeader';
 
 interface Props {
   qualityGateName: string;
   onSetDefault: (qualityGate: QualityGate) => void;
-  qualityGates: QualityGate[];
   refreshQualityGates: () => Promise<void>;
 }
 
@@ -159,16 +158,11 @@ export default class Details extends React.PureComponent<Props, State> {
               <Helmet defer={false} title={qualityGate.name} />
               <DetailsHeader
                 onSetDefault={this.handleSetDefault}
-                qualityGate={{
-                  ...qualityGate,
-                  // isDefault isn't acually returned by the 'show' endpoint, so qualityGate is incomplete
-                  isDefault: checkIfDefault(qualityGate, this.props.qualityGates),
-                }}
+                qualityGate={qualityGate}
                 refreshItem={this.fetchDetails}
                 refreshList={refreshQualityGates}
               />
               <DetailsContent
-                isDefault={checkIfDefault(qualityGate, this.props.qualityGates)}
                 onAddCondition={this.handleAddCondition}
                 onRemoveCondition={this.handleRemoveCondition}
                 onSaveCondition={this.handleSaveCondition}
index 4afd92318dd38b91f2cb39778a14d93f8242a805..b65ddc0e4d477405f8edf3db191e6e6806a1501d 100644 (file)
@@ -27,7 +27,6 @@ import Projects from './Projects';
 import QualityGatePermissions from './QualityGatePermissions';
 
 export interface DetailsContentProps {
-  isDefault?: boolean;
   onAddCondition: (condition: Condition) => void;
   onRemoveCondition: (Condition: Condition) => void;
   onSaveCondition: (newCondition: Condition, oldCondition: Condition) => void;
@@ -36,12 +35,12 @@ export interface DetailsContentProps {
 }
 
 export function DetailsContent(props: DetailsContentProps) {
-  const { isDefault, qualityGate, updatedConditionId } = props;
+  const { qualityGate, updatedConditionId } = props;
   const actions = qualityGate.actions || {};
 
   return (
     <div>
-      {isDefault &&
+      {qualityGate.isDefault &&
         (qualityGate.conditions === undefined || qualityGate.conditions.length === 0) && (
           <FlagMessage className="sw-mb-4" variant="warning">
             {translate('quality_gates.is_default_no_conditions')}
@@ -68,7 +67,7 @@ export function DetailsContent(props: DetailsContentProps) {
             </DocumentationTooltip>
           </SubTitle>
 
-          {isDefault ? (
+          {qualityGate.isDefault ? (
             <p className="sw-body-sm sw-mb-2">{translate('quality_gates.projects_for_default')}</p>
           ) : (
             <Projects
index de01ea907f8816fe6464e4c9832b0f71ef3fdce9..31ad1ffdae7f21a72038d3b6b314a651cb02a439 100644 (file)
@@ -190,10 +190,6 @@ export function getCorrectCaycCondition(condition: Condition) {
   return CAYC_CONDITIONS[conditionMetric];
 }
 
-export function checkIfDefault(qualityGate: QualityGate, list: QualityGate[]): boolean {
-  return list.find((candidate) => candidate.name === qualityGate.name)?.isDefault ?? false;
-}
-
 export function addCondition(qualityGate: QualityGate, condition: Condition): QualityGate {
   const oldConditions = qualityGate.conditions || [];
   const conditions = [...oldConditions, condition];