|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -import React, { useEffect, useState } from 'react' |
18 |
| -import Tippy from '@tippyjs/react' |
| 17 | +import { memo } from 'react' |
19 | 18 |
|
20 | 19 | import {
|
21 | 20 | getCITriggerInfo,
|
| 21 | + getParsedCIMaterialInfo, |
22 | 22 | GitProviderIcon,
|
23 | 23 | GitProviderType,
|
| 24 | + Icon, |
24 | 25 | LoadingCard,
|
25 |
| - showError, |
| 26 | + useQuery, |
26 | 27 | } from '@devtron-labs/devtron-fe-common-lib'
|
27 | 28 |
|
28 | 29 | import { ReactComponent as CommitIcon } from '../../../../assets/icons/ic-code-commit.svg'
|
29 |
| -import { ReactComponent as ICHelpOutline } from '../../../../assets/icons/ic-help-outline.svg' |
30 | 30 | import { DeployedCommitCardType } from './appDetails.type'
|
31 | 31 |
|
32 | 32 | const DeployedCommitCard = ({ cardLoading, showCommitInfoDrawer, envId, ciArtifactId }: DeployedCommitCardType) => {
|
33 |
| - const [commitId, setCommitId] = useState<string>(null) |
34 |
| - const [commitMessage, setCommitMessage] = useState<string>(null) |
35 |
| - const [noValidCommit, setNoValidCommit] = useState<boolean>(false) |
| 33 | + const { data: materials, isLoading } = useQuery({ |
| 34 | + queryFn: () => getCITriggerInfo({ envId, ciArtifactId }), |
| 35 | + queryKey: [envId, ciArtifactId], |
| 36 | + select: ({ result }) => getParsedCIMaterialInfo(result).materials ?? [], |
| 37 | + }) |
36 | 38 |
|
37 |
| - useEffect(() => { |
38 |
| - if (envId && ciArtifactId) { |
39 |
| - const params = { |
40 |
| - envId, |
41 |
| - ciArtifactId, |
42 |
| - } |
43 |
| - |
44 |
| - getCITriggerInfo(params) |
45 |
| - .then((result) => { |
46 |
| - const materials = result?.materials |
47 |
| - if (materials && materials.length > 0) { |
48 |
| - const lastCommit = materials[0]?.history[0] |
49 |
| - const shortenCommitId = lastCommit?.commit?.slice(0, 7) |
50 |
| - setCommitId(shortenCommitId) |
51 |
| - setCommitMessage(lastCommit?.message) |
52 |
| - } else { |
53 |
| - setNoValidCommit(true) |
54 |
| - } |
55 |
| - }) |
56 |
| - .catch((error) => { |
57 |
| - showError(error) |
58 |
| - setNoValidCommit(true) |
59 |
| - }) |
60 |
| - } |
61 |
| - }, [envId, ciArtifactId]) |
62 |
| - |
63 |
| - if (cardLoading) { |
| 39 | + if (cardLoading || isLoading) { |
64 | 40 | return <LoadingCard />
|
65 | 41 | }
|
66 | 42 |
|
67 |
| - if (!commitId || noValidCommit) { |
| 43 | + if (materials.length === 0 || !materials[0].history[0]?.commit?.slice(0, 7)) { |
68 | 44 | return null
|
69 | 45 | }
|
70 | 46 |
|
71 | 47 | return (
|
72 |
| - <div |
73 |
| - data-testid="deployed-commit-card" |
74 |
| - onClick={showCommitInfoDrawer} |
75 |
| - className="app-details-info-card pointer flex left bg__primary br-8 mr-12 lh-20 w-200" |
76 |
| - > |
77 |
| - <div className="app-details-info-card__top-container flex"> |
78 |
| - <div className="app-details-info-card__top-container__content"> |
79 |
| - <div className="app-details-info-card__top-container__content__title-wrapper"> |
80 |
| - <div className="fs-12 fw-4 cn-7 mr-5">Deployed commit</div> |
81 |
| - <Tippy |
82 |
| - className="default-tt" |
83 |
| - arrow={false} |
84 |
| - placement="top" |
85 |
| - content="Last deployment was triggered with this commit" |
86 |
| - maxWidth={250} |
87 |
| - > |
88 |
| - <div className="flex"> |
89 |
| - <ICHelpOutline className="icon-dim-16 mt-2" /> |
| 48 | + <div className="flexbox deployed-commit-card"> |
| 49 | + {materials.map((material) => { |
| 50 | + const lastCommit = material.history[0] |
| 51 | + |
| 52 | + return ( |
| 53 | + <div |
| 54 | + data-testid="deployed-commit-card" |
| 55 | + onClick={showCommitInfoDrawer} |
| 56 | + className="app-details-info-card pointer flex left bg__primary br-8 mr-12 lh-20 w-200" |
| 57 | + > |
| 58 | + <div className="app-details-info-card__top-container flex"> |
| 59 | + <div className="app-details-info-card__top-container__content"> |
| 60 | + <div className="app-details-info-card__top-container__content__title-wrapper"> |
| 61 | + <div className="fs-12 fw-4 cn-7 mr-5">Deployed commit</div> |
| 62 | + <Icon |
| 63 | + name="ic-help-outline" |
| 64 | + color="N500" |
| 65 | + size={14} |
| 66 | + tooltipProps={{ |
| 67 | + alwaysShowTippyOnHover: true, |
| 68 | + content: 'Last deployment was triggered with this commit', |
| 69 | + className: 'dc__mxw-250', |
| 70 | + }} |
| 71 | + /> |
| 72 | + </div> |
| 73 | + <div className="flex fs-12 fw-4"> |
| 74 | + <CommitIcon className="icon-dim-20" /> |
| 75 | + <div className="dc__ellipsis-right cn-7 ml-2 fw-4 fs-12 mono"> |
| 76 | + {lastCommit?.commit?.slice(0, 7) ?? ''} |
| 77 | + </div> |
| 78 | + </div> |
90 | 79 | </div>
|
91 |
| - </Tippy> |
92 |
| - </div> |
93 |
| - <div className="flex fs-12 fw-4"> |
94 |
| - <CommitIcon className="icon-dim-20" /> |
95 |
| - <div className="dc__ellipsis-right cn-7 ml-2 fw-4 fs-12 mono">{commitId}</div> |
| 80 | + <GitProviderIcon gitProvider={GitProviderType.GIT} size={24} /> |
| 81 | + {/* @TODO: This should be dynamic, dependent on the source */} |
| 82 | + {/* <GitHub className="github-icon" /> */} |
| 83 | + </div> |
| 84 | + <div className="app-details-info-card__bottom-container dc__content-space"> |
| 85 | + <span className="app-details-info-card__bottom-container__message fs-12 fw-4"> |
| 86 | + {lastCommit?.message ?? ''} |
| 87 | + </span> |
| 88 | + <div className="app-details-info-card__bottom-container__details fs-12 fw-6">Details</div> |
| 89 | + </div> |
96 | 90 | </div>
|
97 |
| - </div> |
98 |
| - <GitProviderIcon gitProvider={GitProviderType.GIT} size={24} /> |
99 |
| - {/* @TODO: This should be dynamic, dependent on the source */} |
100 |
| - {/* <GitHub className="github-icon" /> */} |
101 |
| - </div> |
102 |
| - <div className="app-details-info-card__bottom-container dc__content-space"> |
103 |
| - <span className="app-details-info-card__bottom-container__message fs-12 fw-4">{commitMessage}</span> |
104 |
| - <div className="app-details-info-card__bottom-container__details fs-12 fw-6">Details</div> |
105 |
| - </div> |
| 91 | + ) |
| 92 | + })} |
106 | 93 | </div>
|
107 | 94 | )
|
108 | 95 | }
|
109 | 96 |
|
110 |
| -export default React.memo(DeployedCommitCard) |
| 97 | +export default memo(DeployedCommitCard) |
0 commit comments