Skip to content

Commit 252b662

Browse files
committed
chore: allow values above maximum for progress circle
1 parent 29b4f10 commit 252b662

10 files changed

Lines changed: 88 additions & 8 deletions

File tree

‎packages/pluggableWidgets/progress-circle-web/CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- We added the "Allow values above maximum" property. When enabled, a progress value higher than the maximum no longer shows an error: the circle stays full, the percentage label shows the actual value (for example 120%), and the widget gets the `widget-progress-circle-overflow` class so you can style it.
12+
913
## [3.3.3] - 2026-02-10
1014

1115
### Added

‎packages/pluggableWidgets/progress-circle-web/src/ProgressCircle.editorConfig.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ export function check(values: ProgressCirclePreviewProps): Problem[] {
8787
});
8888
}
8989
if (
90+
!values.allowValueAboveMax &&
9091
values.staticCurrentValue !== null &&
9192
values.staticMaxValue !== null &&
9293
values.staticCurrentValue > values.staticMaxValue

‎packages/pluggableWidgets/progress-circle-web/src/ProgressCircle.editorPreview.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ export function preview(props: ProgressCirclePreviewProps): ReactElement {
3939
minValue={minValue}
4040
maxValue={maxValue}
4141
onClick={undefined}
42+
allowValueAboveMax={props.allowValueAboveMax}
4243
label={
4344
props.showLabel ? (
4445
props.labelType === "custom" ? (
4546
<props.customLabel.renderer>
4647
<div />
4748
</props.customLabel.renderer>
4849
) : props.labelType === "percentage" ? (
49-
`${calculatePercentage(currentValue, minValue, maxValue)}%`
50+
`${calculatePercentage(currentValue, minValue, maxValue, props.allowValueAboveMax)}%`
5051
) : (
5152
props.labelText
5253
)

‎packages/pluggableWidgets/progress-circle-web/src/ProgressCircle.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,13 @@ export const ProgressCircle: FunctionComponent<ProgressCircleContainerProps> = p
4040
minValue={minValue}
4141
maxValue={maxValue}
4242
onClick={props.onClick ? onClick : undefined}
43+
allowValueAboveMax={props.allowValueAboveMax}
4344
label={
4445
props.showLabel
4546
? props.labelType === "custom"
4647
? props.customLabel
4748
: props.labelType === "percentage"
48-
? `${calculatePercentage(currentValue, minValue, maxValue)}%`
49+
? `${calculatePercentage(currentValue, minValue, maxValue, props.allowValueAboveMax)}%`
4950
: props.labelText?.value
5051
: null
5152
}

‎packages/pluggableWidgets/progress-circle-web/src/ProgressCircle.xml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@
7474
<description />
7575
<returnType type="Decimal" />
7676
</property>
77+
<property key="allowValueAboveMax" type="boolean" defaultValue="false">
78+
<caption>Allow values above maximum</caption>
79+
<description>Show progress values higher than the maximum value instead of an error. The circle stays full and the percentage label shows the actual value.</description>
80+
</property>
7781
<systemProperty key="Visibility" />
7882
</propertyGroup>
7983
<propertyGroup caption="Events">
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { calculatePercentage } from "../util";
2+
3+
describe("calculatePercentage", () => {
4+
it("clamps values above the maximum to 100 by default", () => {
5+
expect(calculatePercentage(150, 0, 100)).toBe(100);
6+
});
7+
8+
it("returns the actual percentage above the maximum when allowed", () => {
9+
expect(calculatePercentage(150, 0, 100, true)).toBe(150);
10+
expect(calculatePercentage(140, 20, 100, true)).toBe(150);
11+
});
12+
13+
it("returns 100 when allowed but the range is empty", () => {
14+
expect(calculatePercentage(150, 100, 100, true)).toBe(100);
15+
});
16+
17+
it("clamps values below the minimum to 0", () => {
18+
expect(calculatePercentage(-10, 0, 100, true)).toBe(0);
19+
});
20+
});

‎packages/pluggableWidgets/progress-circle-web/src/components/ProgressCircle.tsx‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export interface ProgressCircleProps {
1313
maxValue: number;
1414
onClick: (() => void) | undefined;
1515
label: ReactNode;
16+
allowValueAboveMax?: boolean;
1617
}
1718

1819
const defaultOptions: ShapeOptions = {
@@ -23,14 +24,19 @@ const defaultOptions: ShapeOptions = {
2324
trailWidth: 16
2425
};
2526

26-
function getValuesErrorMessage(currentValue: number, minValue: number, maxValue: number): string | null {
27+
function getValuesErrorMessage(
28+
currentValue: number,
29+
minValue: number,
30+
maxValue: number,
31+
allowValueAboveMax: boolean
32+
): string | null {
2733
if (maxValue < minValue) {
2834
return "Error in progress circle values: The maximum value is lower than the minimum value.";
2935
}
3036
if (currentValue < minValue) {
3137
return "Error in progress circle values: The progress value is lower than the minimum value.";
3238
}
33-
if (currentValue > maxValue) {
39+
if (currentValue > maxValue && !allowValueAboveMax) {
3440
return "Error in progress circle values: The progress value is higher than the maximum value.";
3541
}
3642
return null;
@@ -43,10 +49,12 @@ export const ProgressCircle: FunctionComponent<ProgressCircleProps> = ({
4349
minValue,
4450
maxValue,
4551
onClick,
46-
label
52+
label,
53+
allowValueAboveMax = false
4754
}) => {
4855
const [progressCircle, setProgressCircle] = useState<Circle>();
49-
const alertMessage = getValuesErrorMessage(currentValue, minValue, maxValue);
56+
const alertMessage = getValuesErrorMessage(currentValue, minValue, maxValue, allowValueAboveMax);
57+
const isOverflow = allowValueAboveMax && minValue <= maxValue && currentValue > maxValue;
5058

5159
const setProgressCircleElement = useCallback(
5260
(node: any) => {
@@ -85,6 +93,7 @@ export const ProgressCircle: FunctionComponent<ProgressCircleProps> = ({
8593
"widget-progress-circle",
8694
"widget-progress-circle-primary",
8795
"widget-progress-circle-thickness-medium",
96+
{ "widget-progress-circle-overflow": isOverflow },
8897
className
8998
)}
9099
style={style}

‎packages/pluggableWidgets/progress-circle-web/src/components/__tests__/ProgressCircle.spec.tsx‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,39 @@ describe("ProgressCircle", () => {
7171
expect(screen.getByText("100%"))?.toBeInTheDocument();
7272
});
7373

74+
describe("when values above the maximum are allowed", () => {
75+
it("keeps the circle full and shows no error", () => {
76+
renderProgressCircle({ currentValue: 120, maxValue: 100, label: "120%", allowValueAboveMax: true });
77+
expect(mockedAnimate).toHaveBeenCalledWith(1);
78+
expect(screen.getByText("120%")).toBeInTheDocument();
79+
expect(screen.queryByRole("alert")).not.toBeInTheDocument();
80+
});
81+
82+
it("adds the overflow class only when the value is above the maximum", () => {
83+
const { container, rerender } = renderProgressCircle({ currentValue: 120, allowValueAboveMax: true });
84+
expect(container.firstChild).toHaveClass("widget-progress-circle-overflow");
85+
rerender(
86+
<ProgressCircle
87+
currentValue={80}
88+
minValue={0}
89+
maxValue={100}
90+
onClick={undefined}
91+
label=""
92+
class=""
93+
allowValueAboveMax
94+
/>
95+
);
96+
expect(container.firstChild).not.toHaveClass("widget-progress-circle-overflow");
97+
});
98+
99+
it("still shows an error for a value below the minimum", () => {
100+
renderProgressCircle({ currentValue: -1, label: undefined, allowValueAboveMax: true });
101+
expect(screen.getByRole("alert")).toHaveTextContent(
102+
"Error in progress circle values: The progress value is lower than the minimum value."
103+
);
104+
});
105+
});
106+
74107
it("is not clickable when there is no onClick handler provided", () => {
75108
renderProgressCircle({ onClick: undefined, label: undefined, currentValue: -1 });
76109
const labelContainer = document.querySelector(".progress-circle-label-container");

‎packages/pluggableWidgets/progress-circle-web/src/util.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
export function calculatePercentage(currentValue: number, minValue: number, maxValue: number): number {
1+
export function calculatePercentage(
2+
currentValue: number,
3+
minValue: number,
4+
maxValue: number,
5+
allowValueAboveMax = false
6+
): number {
27
if (currentValue < minValue) {
38
return 0;
49
}
5-
if (currentValue > maxValue) {
10+
if (currentValue > maxValue && (!allowValueAboveMax || maxValue === minValue)) {
611
return 100;
712
}
813
const range = maxValue - minValue;

‎packages/pluggableWidgets/progress-circle-web/typings/ProgressCircleProps.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface ProgressCircleContainerProps {
2626
staticMaxValue: number;
2727
dynamicMaxValue?: EditableValue<Big>;
2828
expressionMaxValue?: DynamicValue<Big>;
29+
allowValueAboveMax: boolean;
2930
onClick?: ActionValue;
3031
showLabel: boolean;
3132
labelType: LabelTypeEnum;
@@ -54,6 +55,7 @@ export interface ProgressCirclePreviewProps {
5455
staticMaxValue: number | null;
5556
dynamicMaxValue: string;
5657
expressionMaxValue: string;
58+
allowValueAboveMax: boolean;
5759
onClick: {} | null;
5860
showLabel: boolean;
5961
labelType: LabelTypeEnum;

0 commit comments

Comments
 (0)