Skip to content

Commit d421cc1

Browse files
authored
Merge pull request #154 from sapcc/forbid_autogrowth_fix
restrict forbid autogrowth setting to committable resources
2 parents 0f6baaf + fffd9e0 commit d421cc1

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

.changeset/grumpy-numbers-love.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+
restrict forbid autogrowth setting to committable resources

src/components/mainView/Resource.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { CustomZones, PanelType } from "../../lib/constants";
2121
import { Button, Stack } from "@cloudoperators/juno-ui-components";
2222
import { Link } from "react-router";
2323
import { ProjectBadges } from "../shared/LimesBadges";
24-
import { isAZUnaware } from "../../lib/utils";
24+
import { isAZUnaware, getResourceDurations } from "../../lib/utils";
2525
import ResourceBarBuilder from "../resourceBar/ResourceBarBuilder";
2626
import useResetCommitment from "../../hooks/useResetCommitment";
2727
import HistoricalUsage from "./subComponents/HistoricalUsage";
@@ -93,6 +93,7 @@ const Resource = (props) => {
9393
tracksQuota,
9494
} = props;
9595
const { unit: unitName, editableResource } = resource;
96+
const isCommittable = getResourceDurations(resource).length > 0 ? true : false;
9697
const { scope } = globalStore();
9798
const displayName = t(resource.name);
9899
const { isEditing } = createCommitmentStore();
@@ -170,7 +171,7 @@ const Resource = (props) => {
170171
{isAZUnaware(props.resource.per_az) && (
171172
<ProjectBadges az={props.resource.per_az[0]} unit={unitName} displayValues={true} />
172173
)}
173-
{scope.isProject() && editableResource && <ForbidAutogrowth {...forbidAutogrowthForwardProps} />}
174+
{scope.isProject() && isCommittable && <ForbidAutogrowth {...forbidAutogrowthForwardProps} />}
174175
</Stack>
175176
)}
176177
<ResourceBarBuilder

src/components/mainView/Resource.test.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ describe("Resource tests", () => {
4545
commitmentSum: 10,
4646
editableResource: true,
4747
per_az: [["az1", { projects_usage: 10 }]],
48+
commitment_config: {
49+
durations: ["1 year"],
50+
},
4851
};
4952
let forwardProps = {
5053
area: "testArea",
@@ -64,7 +67,7 @@ describe("Resource tests", () => {
6467
</StoreProvider>
6568
</PortalProvider>
6669
);
67-
const { result } = await waitFor(() => {
70+
const { rerender, result } = await waitFor(() => {
6871
return renderHook(
6972
() => ({
7073
globalStore: globalStore(),
@@ -73,18 +76,24 @@ describe("Resource tests", () => {
7376
{ wrapper }
7477
);
7578
});
76-
77-
// Project level
79+
// The forbidAutogrowth edit option is available at the project level.
7880
act(() => {
7981
result.current.globalStoreActions.setScope(scope);
8082
});
81-
// The forbidAutogrowthSwitch edit option is available for project level.
83+
expect(screen.queryByTestId("forbidAutogrowthSwitch")).toBeInTheDocument();
84+
expect(screen.getByTestId("edit/testResource")).toBeInTheDocument();
85+
expect(screen.queryByTestId("setMaxQuotaPanel")).not.toBeInTheDocument();
86+
87+
// The forbidAutogrowth edit option is only available for committable resources.
88+
delete res.commitment_config;
89+
rerender();
8290
act(() => {
8391
result.current.globalStoreActions.setScope(scope);
8492
});
85-
expect(screen.queryByTestId("forbidAutogrowthSwitch")).toBeInTheDocument();
93+
expect(screen.queryByTestId("forbidAutogrowthSwitch")).not.toBeInTheDocument();
8694
expect(screen.getByTestId("edit/testResource")).toBeInTheDocument();
8795
expect(screen.queryByTestId("setMaxQuotaPanel")).not.toBeInTheDocument();
96+
res.commitment_config = { durations: ["1 year"] };
8897

8998
// Domain level allows setting Max-Quota.
9099
scope = new Scope({ domainID: "456" });

src/components/project/ProjectQuotaDetails.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ const ProjectQuotaDetails = (props) => {
5353
<ToolTipWrapper
5454
trigger={<Icon data-testid="forbidAutogrowthInfo" icon="warning" size="18" />}
5555
content={
56-
<div>
57-
<div>Pay-As-You-Go is disabled on project level.</div>
58-
<div>This setting is more restrictive than Max-Quota.</div>
59-
</div>
56+
<span>
57+
Pay-As-You-Go is disabled on project level. <br />
58+
This setting is more restrictive than Max-Quota.
59+
</span>
6060
}
6161
/>
6262
)}

0 commit comments

Comments
 (0)