-
Notifications
You must be signed in to change notification settings - Fork 558
/
Copy pathFleetAppDetailsModal.tsx
134 lines (120 loc) · 3.45 KB
/
FleetAppDetailsModal.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import React, { useState } from "react";
import { stringToClipboard } from "utilities/copy_text";
import {
LEARN_MORE_ABOUT_BASE_LINK,
PLATFORM_DISPLAY_NAMES,
} from "utilities/constants";
import Modal from "components/Modal";
import DataSet from "components/DataSet";
import TooltipWrapper from "components/TooltipWrapper";
import TooltipTruncatedText from "components/TooltipTruncatedText";
import Button from "components/buttons/Button";
import Icon from "components/Icon";
import CustomLink from "components/CustomLink";
const baseClass = "fleet-app-details-modal";
interface IFleetAppDetailsModalProps {
name: string;
platform: string;
version: string;
slug?: string;
url?: string;
onCancel: () => void;
}
const SLUG_TOOLTIP_MESSAGE = (
<>
Used to manage apps in Gitops.{" "}
<CustomLink
newTab
url={`${LEARN_MORE_ABOUT_BASE_LINK}/gitops`}
text="Learn more"
variant="tooltip-link"
/>
</>
);
const URL_TOOLTIP_MESSAGE = (
<>
Fleet downloads the package from the URL and stores it.
<br />
Hosts download it from Fleet before install.
</>
);
const FleetAppDetailsModal = ({
name,
platform,
version,
slug,
url,
onCancel,
}: IFleetAppDetailsModalProps) => {
const [copyMessage, setCopyMessage] = useState("");
const onCopySlug = (evt: React.MouseEvent) => {
evt.preventDefault();
stringToClipboard(slug)
.then(() => setCopyMessage("Copied!"))
.catch(() => setCopyMessage("Copy failed"));
// Clear message after 1 second
setTimeout(() => setCopyMessage(""), 1000);
return false;
};
return (
<Modal className={baseClass} title="Software details" onExit={onCancel}>
<>
<div className={`${baseClass}__modal-content`}>
<DataSet title="Name" value={name} />
<DataSet title="Version" value={version} />
{slug && (
<DataSet
title={
<TooltipWrapper
tipContent={SLUG_TOOLTIP_MESSAGE}
position="top-start"
>
Fleet-maintained app slug
</TooltipWrapper>
}
value={
<>
{slug}{" "}
<div className={`${baseClass}__action-overlay`}>
{copyMessage && (
<div
className={`${baseClass}__copy-message`}
>{`${copyMessage} `}</div>
)}
</div>
<Button
variant="unstyled"
className={`${baseClass}__copy-secret-icon`}
onClick={onCopySlug}
>
<Icon name="copy" />
</Button>
</>
}
/>
)}
<DataSet title="Platform" value={PLATFORM_DISPLAY_NAMES[platform]} />
{url && (
<DataSet
title={
<TooltipWrapper
tipContent={URL_TOOLTIP_MESSAGE}
position="top-start"
>
URL
</TooltipWrapper>
}
value={<TooltipTruncatedText value={url} />}
/>
)}
</div>
<div className="modal-cta-wrap">
<Button onClick={onCancel} variant="brand">
Done
</Button>
</div>
</>
</Modal>
);
};
export default FleetAppDetailsModal;