Skip to content

Commit 2ac8dbc

Browse files
authored
Merge pull request #118 from sapcc/info_button
fix: base quota information
2 parents 64c7aa0 + 12b87cc commit 2ac8dbc

File tree

5 files changed

+38
-31
lines changed

5 files changed

+38
-31
lines changed

.changeset/dry-pianos-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sapcc/limes-ui": patch
3+
---
4+
5+
Change indicator for additional resource info from an icon to a button.

src/components/mainView/Resource.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import React from "react";
1818
import { globalStore, createCommitmentStore } from "../StoreProvider";
1919
import { t } from "../../lib/utils";
2020
import { CustomZones, PanelType } from "../../lib/constants";
21-
import { Button, Icon, Stack } from "@cloudoperators/juno-ui-components";
21+
import { Button, Stack } from "@cloudoperators/juno-ui-components";
2222
import { Link } from "react-router";
2323
import { ProjectBadges } from "../shared/LimesBadges";
2424
import { isAZUnaware } from "../../lib/utils";
@@ -112,16 +112,18 @@ const Resource = (props) => {
112112
gap="1"
113113
distribution={canEdit && !editableResource && "between"}
114114
>
115-
<Stack>
116-
{displayName}
115+
<Stack gap="2">
116+
<div className="m-auto">{displayName}</div>
117117
{resourceHasQuota && !isPanelView && (
118-
<Icon
118+
<Button
119119
data-testid="detailedResourceInfo"
120120
icon={displayResourceInfo ? "expandMore" : "chevronRight"}
121-
title={displayResourceInfo ? "hide info" : "display info"}
121+
label="Explain"
122122
onClick={() => {
123123
setDisplayResourceInfo(!displayResourceInfo);
124124
}}
125+
title={displayResourceInfo ? "hide info" : "display info for this resource"}
126+
size="small"
125127
/>
126128
)}
127129
</Stack>

src/components/resourceBar/ResourceInfo.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ const ResourceInfo = (props) => {
4848
infos.push(getPaygInfo());
4949
}
5050
if (!scope.isCluster()) {
51-
infos.push(getBaseQuotaInfo());
51+
infos.push(...getBaseQuotaInfo());
5252
}
5353
infos.push(...getNegativeRemainingQuotaInfo());
5454

@@ -82,8 +82,15 @@ const ResourceInfo = (props) => {
8282

8383
function getBaseQuotaInfo() {
8484
const baseQuotaAZ = locateBaseQuotaAZ(resource);
85-
if (!baseQuotaAZ) return;
86-
return BaseQuotaLabels.AVAILABLE(unit.format(baseQuotaAZ.quota), az);
85+
const sections = [];
86+
if (!baseQuotaAZ) return sections;
87+
const totalQuota = unit.format(resource.quota);
88+
const remainingBaseQuota = unit.format(baseQuotaAZ.quota);
89+
const deductedBaseQuota = unit.format(resource.quota - baseQuotaAZ.quota);
90+
!az && sections.push(BaseQuotaLabels.REMAINING({ totalQuota, remainingBaseQuota, deductedBaseQuota }));
91+
!az && sections.push(BaseQuotaLabels.BASEINFO);
92+
az && az.name != CustomZones.UNKNOWN && sections.push(BaseQuotaLabels.AZINFO(az));
93+
return sections;
8794
}
8895

8996
function getNegativeRemainingQuotaInfo() {
@@ -108,7 +115,7 @@ const ResourceInfo = (props) => {
108115
return (
109116
<IntroBox className="my-1 text-sm">
110117
{resourceInfos.map((info, index) => (
111-
<p key={index}>{info}</p>
118+
<div key={index}>{info}</div>
112119
))}
113120
</IntroBox>
114121
);

src/components/resourceBar/ResourceInfo.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,16 +117,12 @@ describe("Resource info tests", () => {
117117
// AZ info should contain the info addition.
118118
props.az = { name: "AZ1" };
119119
rerender(<ResourceInfo {...props} />);
120-
expect(screen.getByTestId(/BaseQuota.AVAILABLE/i)).toBeInTheDocument();
121-
expect(screen.getByText("1 GiB")).toBeInTheDocument();
122-
expect(screen.getByTestId(/BaseQuota.ADDITION/i)).toBeInTheDocument();
123120
expect(screen.getByTestId(/BaseQuota.AZ/i)).toBeInTheDocument();
124121

125122
// unknown AZ info should contain specific info.
126123
props.az = { name: CustomZones.UNKNOWN };
127124
rerender(<ResourceInfo {...props} />);
128-
expect(screen.getByTestId(/BaseQuota.ADDITION/i)).toBeInTheDocument();
129-
expect(screen.getByTestId(/BaseQuota.UNKNOWN/i)).toBeInTheDocument();
125+
expect(screen.queryByTestId(/BaseQuota.AZ/i)).not.toBeInTheDocument();
130126

131127
// Provided AZ's without a base quota AZ should not display info.
132128
props.resource = {

src/components/resourceBar/resourceInfoLabels.js

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616

1717
import React from "react";
18-
import { CustomZones } from "../../lib/constants";
1918

2019
export const UnknownAZLabel = (
2120
<span data-testid="UnknownAZ">
@@ -50,22 +49,20 @@ export const PAYGLabels = {
5049
};
5150

5251
export const BaseQuotaLabels = {
53-
AVAILABLE: (amount, az) => (
54-
<>
55-
<span data-testid="BaseQuota.AVAILABLE">
56-
Available base quota: <strong>{amount}</strong>.{" "}
57-
</span>{" "}
58-
{az && (
59-
<span data-testid="BaseQuota.ADDITION">
60-
{az.name === CustomZones.UNKNOWN ? (
61-
<span data-testid="BaseQuota.UNKNOWN">Usage assigns</span>
62-
) : (
63-
<span data-testid="BaseQuota.AZ">Commitments and usage assign</span>
64-
)}{" "}
65-
base quota to this AZ.
66-
</span>
67-
)}
68-
</>
52+
REMAINING: ({ totalQuota, remainingBaseQuota, deductedBaseQuota }) => (
53+
<p data-testid="BaseQuota.AVAILABLE">
54+
Base quota: <strong>{remainingBaseQuota}</strong> out of the original <strong>{totalQuota}</strong> are still
55+
available. <strong>{deductedBaseQuota}</strong> have been deducted because of AZ-aware quotas based on existing
56+
commitments and usage.
57+
</p>
58+
),
59+
AZINFO: () => (
60+
<span data-testid="BaseQuota.AZ">
61+
Resources in this AZ can also be deployed using the region-wide base quota seen above.
62+
</span>
63+
),
64+
BASEINFO: (
65+
<span>Base quota can be used to deploy into any AZ of your choice. Quota does not incur costs until used.</span>
6966
),
7067
};
7168

0 commit comments

Comments
 (0)