-
Notifications
You must be signed in to change notification settings - Fork 25
/
WarningMessage.tsx
71 lines (67 loc) · 2.05 KB
/
WarningMessage.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
import { List, Tooltip } from "@canonical/react-components";
import type { ListItem } from "@canonical/react-components/dist/components/List/List";
import { Link } from "react-router-dom";
import ModelDetailsLink from "components/ModelDetailsLink";
import type { ModelData } from "store/juju/types";
import { getModelStatusGroupData } from "store/juju/utils/models";
import urls from "urls";
import { getUserName } from "utils";
type Props = {
/**
* The full model data.
*/
model: ModelData;
};
/**
Warning message for the model name cell.
@return The react component for the warning message.
*/
const WarningMessage = ({ model }: Props) => {
const { messages } = getModelStatusGroupData(model);
if (!messages.length) {
return null;
}
const ownerTag = model?.info?.["owner-tag"] ?? "";
const userName = getUserName(ownerTag);
const modelName = model.model.name;
const link = (
<ModelDetailsLink modelName={modelName} ownerTag={ownerTag}>
{messages[0].message}
</ModelDetailsLink>
);
const list: ListItem[] = messages.slice(0, 5).map((message) => {
const unitId = message.unitId ? message.unitId.replace("/", "-") : null;
const appName = message.appName;
return {
className: "u-truncate",
content: (
<>
{unitId || appName}:{" "}
<Link
to={
unitId
? urls.model.unit({ userName, modelName, appName, unitId })
: urls.model.app.index({ userName, modelName, appName })
}
>
{message.message}
</Link>
</>
),
};
});
const remainder = messages.slice(5);
if (remainder.length) {
list.push(`+${remainder.length} more...`);
}
return (
<Tooltip
positionElementClassName="p-tooltip__position-element--inline"
tooltipClassName="p-tooltip--constrain-width"
message={<List className="u-no-margin--bottom" items={list} />}
>
<span className="model-table-list_error-message">{link}</span>
</Tooltip>
);
};
export default WarningMessage;