## Description
- This PR adds setter methods to update widget property
programmatically.
Example:-
`Input1.setText("setter methods are cool!");`
Docs link :
https://docs.appsmith.com/reference/widgets
For any selected widget check the `Methods` section
#### PR fixes following issue(s)
Fixes
#### Type of change
- New feature (non-breaking change which adds functionality)
## Testing
>
#### How Has This Been Tested?
- [x] Manual
- [x] Jest
- [x] Cypress
>
>
#### Test Plan
https://github.com/appsmithorg/TestSmith/issues/2409
#### Issues raised during DP testing
- [x] [Errors are not logged in the
debugger](https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1564017346)
separate GitHub issue
https://github.com/appsmithorg/appsmith/issues/24609
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1564155545
( `setVisibility("false")` )
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1580525843
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1576582825
- Blocker for testing
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1577956441
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1577930108
- Not a issue (lint error query)
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1593471791
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1591440488
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1586747864
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1596738201
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1598541537
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1611413076
- [x]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1612621567
- [ ]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1619654507
- [ ]
https://github.com/appsmithorg/appsmith/pull/23441#issuecomment-1621256722
>
>
## Checklist:
#### Dev activity
- [ ] My code follows the style guidelines of this project
- [ ] 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
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] 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/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change)
have been covered
- [x] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest)
- [x] 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
---------
Co-authored-by: Rishabh Rathod <rishabh.rathod@appsmith.com>
170 lines
4.9 KiB
TypeScript
170 lines
4.9 KiB
TypeScript
import { Positioning, ResponsiveBehavior } from "utils/autoLayout/constants";
|
|
import { Colors } from "constants/Colors";
|
|
import { FILL_WIDGET_MIN_WIDTH } from "constants/minWidthConstants";
|
|
import { GridDefaults, WidgetHeightLimits } from "constants/WidgetConstants";
|
|
import type { WidgetProps } from "widgets/BaseWidget";
|
|
import { BlueprintOperationTypes } from "widgets/constants";
|
|
|
|
import IconSVG from "./icon.svg";
|
|
import Widget from "./widget";
|
|
|
|
export const CONFIG = {
|
|
type: Widget.getWidgetType(),
|
|
name: "Tabs",
|
|
iconSVG: IconSVG,
|
|
needsMeta: true,
|
|
isCanvas: true,
|
|
// TODO(abhinav): Default config like these are not serializable
|
|
// So they will not work with Redux state and they might break
|
|
// evaluations. One way to handle these types of properties is to
|
|
// define them in a Map which the platform understands to have
|
|
// them stored only in the WidgetFactory.
|
|
canvasHeightOffset: (props: WidgetProps): number => {
|
|
let offset =
|
|
props.borderWidth && props.borderWidth > 1
|
|
? Math.ceil(
|
|
(2 * parseInt(props.borderWidth, 10) || 0) /
|
|
GridDefaults.DEFAULT_GRID_ROW_HEIGHT,
|
|
)
|
|
: 0;
|
|
|
|
if (props.shouldShowTabs === true) {
|
|
offset += 4;
|
|
}
|
|
return offset;
|
|
},
|
|
features: {
|
|
dynamicHeight: {
|
|
sectionIndex: 1,
|
|
active: true,
|
|
},
|
|
},
|
|
defaults: {
|
|
responsiveBehavior: ResponsiveBehavior.Fill,
|
|
minWidth: FILL_WIDGET_MIN_WIDTH,
|
|
rows: WidgetHeightLimits.MIN_CANVAS_HEIGHT_IN_ROWS + 5,
|
|
columns: 24,
|
|
shouldScrollContents: false,
|
|
widgetName: "Tabs",
|
|
animateLoading: true,
|
|
borderWidth: 1,
|
|
borderColor: Colors.GREY_5,
|
|
backgroundColor: Colors.WHITE,
|
|
minDynamicHeight: WidgetHeightLimits.MIN_CANVAS_HEIGHT_IN_ROWS + 5,
|
|
tabsObj: {
|
|
tab1: {
|
|
label: "Tab 1",
|
|
id: "tab1",
|
|
widgetId: "",
|
|
isVisible: true,
|
|
index: 0,
|
|
positioning: Positioning.Vertical,
|
|
},
|
|
tab2: {
|
|
label: "Tab 2",
|
|
id: "tab2",
|
|
widgetId: "",
|
|
isVisible: true,
|
|
index: 1,
|
|
positioning: Positioning.Vertical,
|
|
},
|
|
},
|
|
shouldShowTabs: true,
|
|
defaultTab: "Tab 1",
|
|
blueprint: {
|
|
view: [
|
|
{
|
|
type: "CANVAS_WIDGET",
|
|
position: { left: 0, top: 0 },
|
|
props: {
|
|
detachFromLayout: true,
|
|
canExtend: true,
|
|
isVisible: true,
|
|
isDisabled: false,
|
|
shouldScrollContents: false,
|
|
tabId: "tab1",
|
|
tabName: "Tab 1",
|
|
children: [],
|
|
version: 1,
|
|
bottomRow: WidgetHeightLimits.MIN_CANVAS_HEIGHT_IN_ROWS,
|
|
},
|
|
},
|
|
{
|
|
type: "CANVAS_WIDGET",
|
|
position: { left: 0, top: 0 },
|
|
props: {
|
|
detachFromLayout: true,
|
|
canExtend: true,
|
|
isVisible: true,
|
|
isDisabled: false,
|
|
shouldScrollContents: false,
|
|
tabId: "tab2",
|
|
tabName: "Tab 2",
|
|
children: [],
|
|
version: 1,
|
|
bottomRow: WidgetHeightLimits.MIN_CANVAS_HEIGHT_IN_ROWS,
|
|
},
|
|
},
|
|
],
|
|
operations: [
|
|
{
|
|
type: BlueprintOperationTypes.MODIFY_PROPS,
|
|
fn: (widget: WidgetProps & { children?: WidgetProps[] }) => {
|
|
const tabs = Object.values({ ...widget.tabsObj });
|
|
const tabIds: Record<string, string> = (
|
|
widget.children || []
|
|
).reduce((idsObj, eachChild) => {
|
|
idsObj = { ...idsObj, [eachChild.tabId]: eachChild.widgetId };
|
|
return idsObj;
|
|
}, {});
|
|
const tabsObj = tabs.reduce((obj: any, tab: any) => {
|
|
const newTab = { ...tab };
|
|
newTab.widgetId = tabIds[newTab.id];
|
|
obj[newTab.id] = newTab;
|
|
return obj;
|
|
}, {});
|
|
const updatePropertyMap = [
|
|
{
|
|
widgetId: widget.widgetId,
|
|
propertyName: "tabsObj",
|
|
propertyValue: tabsObj,
|
|
},
|
|
];
|
|
return updatePropertyMap;
|
|
},
|
|
},
|
|
],
|
|
},
|
|
version: 3,
|
|
},
|
|
properties: {
|
|
derived: Widget.getDerivedPropertiesMap(),
|
|
default: Widget.getDefaultPropertiesMap(),
|
|
meta: Widget.getMetaPropertiesMap(),
|
|
config: Widget.getPropertyPaneConfig(),
|
|
contentConfig: Widget.getPropertyPaneContentConfig(),
|
|
styleConfig: Widget.getPropertyPaneStyleConfig(),
|
|
stylesheetConfig: Widget.getStylesheetConfig(),
|
|
autocompleteDefinitions: Widget.getAutocompleteDefinitions(),
|
|
setterConfig: Widget.getSetterConfig(),
|
|
},
|
|
autoLayout: {
|
|
widgetSize: [
|
|
{
|
|
viewportMinWidth: 0,
|
|
configuration: () => {
|
|
return {
|
|
minWidth: "280px",
|
|
minHeight: "300px",
|
|
};
|
|
},
|
|
},
|
|
],
|
|
disableResizeHandles: {
|
|
vertical: true,
|
|
},
|
|
},
|
|
};
|
|
|
|
export default Widget;
|