PromucFlow_constructor/app/client/src/components/formControls/RadioButtonControl.tsx
sneha122 88ec7c7c50
fix: gsheets all sheets option enabled behind a feature flag (#37942)
## Description
This PR adds back all sheets option which had been removed in PR:
https://github.com/appsmithorg/appsmith/pull/36125


Fixes #38002
_or_  
Fixes `Issue URL`
> [!WARNING]  
> _If no issue exists, please create an issue first, and check with the
maintainers if the issue is valid._

## Automation

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

### 🔍 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/12311024852>
> Commit: e177b648fd593b8ccc8af88c6d90c3958d7c9752
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12311024852&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Datasource, @tag.Widget`
> Spec:
> <hr>Fri, 13 Dec 2024 08:27:08 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**
- Added new options for Google Sheets permissions, enhancing user
selection capabilities.
- Introduced a feature flag to control the visibility of new Google
Sheets options.
	
- **Bug Fixes**
- Improved handling of feature flags in the datasource section
rendering, ensuring correct visibility based on flags.

- **Documentation**
- Updated test specifications for Google Sheets datasource to include
new dropdown options.

- **Chores**
- Enhanced the logic for setting default values in the
RadioButtonControl component.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: “sneha122” <“sneha@appsmith.com”>
Co-authored-by: Alex Golovanov <alex@appsmith.com>
2024-12-13 14:09:53 +05:30

74 lines
1.9 KiB
TypeScript

import React from "react";
import type { ControlProps } from "./BaseControl";
import BaseControl from "./BaseControl";
import type { ControlType } from "constants/PropertyControlConstants";
import type { WrappedFieldInputProps, WrappedFieldMetaProps } from "redux-form";
import { Field } from "redux-form";
import { Radio, RadioGroup, type SelectOptionProps } from "@appsmith/ads";
import styled from "styled-components";
class RadioButtonControl extends BaseControl<RadioButtonControlProps> {
getControlType(): ControlType {
return "RADIO_BUTTON";
}
render() {
return (
<Field
component={renderComponent}
name={this.props.configProperty}
props={{ ...this.props }}
type="radiobutton"
/>
);
}
}
type renderComponentProps = RadioButtonControlProps & {
input?: WrappedFieldInputProps;
meta?: WrappedFieldMetaProps;
options?: Array<{ label: string; value: string }>;
};
const StyledRadioGroup = styled(RadioGroup)({
display: "flex",
flexDirection: "column",
gap: "16px",
marginTop: "16px",
});
function renderComponent(props: renderComponentProps) {
const onChangeHandler = (value: string) => {
if (typeof props.input?.onChange === "function") {
props.input.onChange(value);
}
};
const options = props.options || [];
const selectedValue = props.input?.value;
const defaultValue = !!selectedValue
? selectedValue
: (props.initialValue as string);
return (
<StyledRadioGroup
data-testid={props.input?.name}
defaultValue={defaultValue}
onChange={onChangeHandler}
>
{options.map((option) => {
return (
<Radio key={option.value} value={option.value}>
{option.label}
</Radio>
);
})}
</StyledRadioGroup>
);
}
export interface RadioButtonControlProps extends ControlProps {
options: SelectOptionProps[];
}
export default RadioButtonControl;