/* * Copyright 2020 EPAM Systems * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { Button, Icons, Tooltip } from "@drill4j/ui-kit"; import React from "react"; import { getModalPath } from "common"; import { Link } from "react-router-dom"; import tw, { styled } from "twin.macro"; import { ConditionSetting, QualityGateStatus, QualityGate as QualityGateType } from "types"; import { useFilteredData } from "hooks"; import { useResultFilterState } from "common/contexts"; export const QualityGate = () => { const { status = "FAILED" } = useFilteredData("/data/quality-gate") || {}; const conditionSettings = useFilteredData("/data/quality-gate-settings") || []; const configured = conditionSettings.some(({ enabled }) => enabled); const { isEmptyFilterResult } = useResultFilterState(); return (
QUALITY GATE
{!configured && !isEmptyFilterResult && (
Configure quality gate conditions to
define whether your build passes or not.
)} >
)}
{getQualityGateSection(isEmptyFilterResult, configured, status)}
); }; const StatusWrapper = styled(Link)(({ status }: { status?: QualityGateStatus }) => [ tw`flex items-center h-8 text-14`, status === "PASSED" && tw`text-green-default cursor-pointer`, status === "FAILED" && tw`text-red-default cursor-pointer`, ]); const StatusTitle = styled.div` ${tw`ml-2 font-bold lowercase`} &::first-letter { ${tw`uppercase`} } `; const getQualityGateSection = (isEmptyFilterResult: boolean, configured: boolean, status: QualityGateStatus) => { const StatusIcon = Icons[status]; if (isEmptyFilterResult) { return (
n/a
); } if (!configured) { return ( ); } return ( {status} ); };