PromucFlow_constructor/app/client/src/components/propertyControls/StepControl.tsx
albinAppsmith 7efe8cf09e
fix: Map widget zoom control suffix (#25031)
## Description

PR fixes the zoom level control suffix getting appended twice in the map
widget property pane. Also this PR has fixed the text getting selected
behaviour while clicking on add and subtract icon inside the number
input.

#### PR fixes following issue(s)
Fixes #24819

#### Media


https://github.com/appsmithorg/appsmith/assets/87797149/ec6f4a0b-b428-492b-b6c5-6dff97f4247a



#### Type of change

- Bug fix (non-breaking change which fixes an issue)


## Testing

#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [ ] Manual
- [ ] Jest
- [ ] Cypress
>
>
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-07-07 18:28:47 +05:30

100 lines
2.4 KiB
TypeScript

import React from "react";
import type { ControlProps } from "./BaseControl";
import BaseControl from "./BaseControl";
import { NumberInput } from "design-system";
import type { DSEventDetail } from "utils/AppsmithUtils";
import {
DSEventTypes,
DS_EVENT,
emitInteractionAnalyticsEvent,
} from "utils/AppsmithUtils";
const MIN = 0;
const MAX = 100;
class StepControl extends BaseControl<StepControlProps> {
componentRef = React.createRef<HTMLInputElement>();
componentDidMount() {
this.componentRef.current?.addEventListener(
DS_EVENT,
this.handleAdsEvent as (arg0: Event) => void,
);
}
componentWillUnmount() {
this.componentRef.current?.removeEventListener(
DS_EVENT,
this.handleAdsEvent as (arg0: Event) => void,
);
}
handleAdsEvent = (e: CustomEvent<DSEventDetail>) => {
if (
e.detail.component === "StepComponent" &&
e.detail.event === DSEventTypes.KEYPRESS
) {
emitInteractionAnalyticsEvent(this.componentRef.current, {
key: e.detail.meta.key,
});
e.stopPropagation();
}
};
getStepTypeControls = () => {
const { stepType } = this.props;
if (stepType === "ZOOM_PERCENTAGE") {
return {
min: MIN,
max: MAX,
steps: 5,
suffix: "%",
};
}
return {
min: MIN,
max: MAX,
steps: 1,
};
};
render() {
const { max, min, steps, suffix } = this.getStepTypeControls();
return (
<NumberInput
max={max}
min={min}
// TODO: UI builders -> confirm isUpdatedViaKeyboard is needed going forward
onChange={(value: string | undefined, isUpdatedViaKeyboard = false) => {
const v = value ? parseFloat(value.replace(/[^0-9.-]+/g, "")) : 0;
this.updateProperty(this.props.propertyName, v, isUpdatedViaKeyboard);
}}
ref={this.componentRef}
scale={steps}
suffix={suffix}
value={this.props.propertyValue}
/>
);
}
static getControlType() {
return "STEP";
}
static canDisplayValueInUI(config: StepControlProps, value: any): boolean {
let steps = 1;
if (config.stepType === "ZOOM_PERCENTAGE") {
steps = 5;
}
return value >= MIN && value <= MAX && value % steps === 0;
}
}
export type StepType = "ZOOM_PERCENTAGE";
export interface StepControlProps extends ControlProps {
stepType: StepType;
}
export default StepControl;