Skip to content

Commit

Permalink
chore: add slider control (appsmithorg#39058)
Browse files Browse the repository at this point in the history
## Description
Add slider control for UQI forms.

![Снимок экрана 2025-02-06 в 10 04
22](https://github.com/user-attachments/assets/4aea28c8-5cc0-4b82-96b8-ca3645789c4b)

## Automation

/ok-to-test tags="@tag.Datasource"

### 🔍 Cypress test results
<!-- This is an auto-generated comment: Cypress test results  -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/13173679109>
> Commit: 2aa1362
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=13173679109&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Datasource`
> Spec:
> <hr>Thu, 06 Feb 2025 07:59:48 UTC
<!-- end of auto-generated comment: Cypress test results  -->


## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [x] No


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

- **New Features**
- Introduced an interactive slider control for forms, allowing users to
adjust numerical values with ease.
- Enhanced form input options by integrating the slider into the
existing control suite for a smoother, more intuitive user experience.
- Added a new form control type, "SLIDER", to expand the available input
options.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
  • Loading branch information
KelvinOm authored Feb 6, 2025
1 parent 3f5d6a6 commit 583973b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/formControls/BaseControl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface ControlData {
errorText?: string;
showError?: boolean;
encrypted?: boolean;
title?: string; // used as label for control component
subtitle?: string;
showLineNumbers?: boolean;
url?: string;
Expand Down
47 changes: 47 additions & 0 deletions src/components/formControls/SliderControl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from "react";
import { Field, type WrappedFieldInputProps } from "redux-form";
import BaseControl from "./BaseControl";
import type { ControlProps } from "./BaseControl";
import { Slider, type SliderProps } from "@appsmith/ads";

export interface SliderControlProps
extends ControlProps,
Omit<SliderProps, "id" | "label"> {}

export class SliderControl extends BaseControl<SliderControlProps> {
render() {
const { configProperty, ...rest } = this.props;

return (
<Field
component={renderSliderControl}
name={configProperty}
props={{ ...rest }}
/>
);
}

getControlType(): string {
return "SLIDER";
}
}

const renderSliderControl = (
props: {
input?: WrappedFieldInputProps;
} & SliderControlProps,
) => {
const { input, maxValue, minValue, step, title } = props;

return (
<Slider
defaultValue={input?.value}
// use title as label because UQI label form placed above the component witch breaks the layout
label={title}
maxValue={maxValue}
minValue={minValue}
onChangeEnd={input?.onChange}
step={step}
/>
);
};
9 changes: 9 additions & 0 deletions src/utils/formControl/FormControlRegistry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ import type { MultipleFilePickerControlProps } from "components/formControls/Mul
import type { RadioButtonControlProps } from "components/formControls/RadioButtonControl";
import RadioButtonControl from "components/formControls/RadioButtonControl";
import { RagIntegrations } from "ee/components/formControls/Rag";
import {
SliderControl,
type SliderControlProps,
} from "components/formControls/SliderControl";

/**
* NOTE: If you are adding a component that uses FormControl
Expand Down Expand Up @@ -199,6 +203,11 @@ class FormControlRegistry {
},
},
);
FormControlFactory.registerControlBuilder(formControlTypes.SLIDER, {
buildPropertyControl(controlProps: SliderControlProps): JSX.Element {
return <SliderControl {...controlProps} />;
},
});
}
}

Expand Down
1 change: 1 addition & 0 deletions src/utils/formControl/formControlTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ export default {
MULTIPLE_FILE_PICKER: "MULTIPLE_FILE_PICKER",
RADIO_BUTTON: "RADIO_BUTTON",
RAG_INTEGRATIONS: "RAG_INTEGRATIONS",
SLIDER: "SLIDER",
};

0 comments on commit 583973b

Please sign in to comment.