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>;
}
<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}
import QualityGatePermissions from './QualityGatePermissions';
export interface DetailsContentProps {
- isDefault?: boolean;
onAddCondition: (condition: Condition) => void;
onRemoveCondition: (Condition: Condition) => void;
onSaveCondition: (newCondition: Condition, oldCondition: Condition) => void;
}
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')}
</DocumentationTooltip>
</SubTitle>
- {isDefault ? (
+ {qualityGate.isDefault ? (
<p className="sw-body-sm sw-mb-2">{translate('quality_gates.projects_for_default')}</p>
) : (
<Projects
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];