PromucFlow_constructor/app/client/src/actions/metaActions.ts
Favour Ohanekwu 95fa2328a8
fix: reset widget to default value after setter method (#29151)
## Description
This PR ensures that widgets are reset to their default value after the
`setValue` setter method is used to set its value

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

#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## 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
- [ ] JUnit
- [ ] 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
- [ ] 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/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


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

- **New Features**
- Implemented a new reset functionality for widgets, allowing users to
revert to default values after changes.
  - Enhanced widget meta updates with a new reset action.

- **Bug Fixes**
- Added test cases to ensure widget reset functionality works as
expected, even after asynchronous operations.

- **Refactor**
- Refactored evaluation logic to improve handling of widget meta updates
and resets.
  - Improved action execution logic for resetting widget properties.

- **Tests**
- Expanded end-to-end regression tests to cover new reset widget
functionality.

- **Documentation**
- Updated internal documentation to reflect new action types and
evaluation processes related to widget meta updates.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Druthi Polisetty <druthi@appsmith.com>
2023-12-08 11:16:31 +01:00

131 lines
3.2 KiB
TypeScript

import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
import type { BatchAction } from "actions/batchActions";
import { batchAction } from "actions/batchActions";
import type { EvalMetaUpdates } from "@appsmith/workers/common/DataTreeEvaluator/types";
import type {
WidgetEntity,
DataTreeEntityConfig,
WidgetEntityConfig,
} from "@appsmith/entities/DataTree/types";
export interface UpdateWidgetMetaPropertyPayload {
widgetId: string;
propertyName: string;
propertyValue: unknown;
}
export interface BatchUpdateWidgetMetaPropertyPayload {
batchMetaUpdates: UpdateWidgetMetaPropertyPayload[];
}
export const updateWidgetMetaPropAndEval = (
widgetId: string,
propertyName: string,
propertyValue: unknown,
): BatchAction<UpdateWidgetMetaPropertyPayload> => {
return batchAction({
type: ReduxActionTypes.SET_META_PROP_AND_EVAL,
payload: {
widgetId,
propertyName,
propertyValue,
},
});
};
export interface ResetWidgetMetaPayload {
widgetId: string;
evaluatedWidget: WidgetEntity | undefined;
evaluatedWidgetConfig: DataTreeEntityConfig | undefined;
}
export const resetWidgetMetaProperty = (
widgetId: string,
evaluatedWidget: WidgetEntity | undefined,
evaluatedWidgetConfig: WidgetEntityConfig | undefined,
): BatchAction<ResetWidgetMetaPayload> => {
return batchAction({
type: ReduxActionTypes.RESET_WIDGET_META,
payload: {
widgetId,
evaluatedWidget,
evaluatedWidgetConfig,
},
postEvalActions: [{ type: ReduxActionTypes.RESET_WIDGET_META_EVALUATED }],
});
};
export const resetWidgetMetaUpdates = (
evalMetaUpdates: EvalMetaUpdates,
): BatchAction<ResetWidgetMetaPayload> => {
return batchAction({
type: ReduxActionTypes.RESET_WIDGET_META_UPDATES,
payload: {
evalMetaUpdates,
},
postEvalActions: [{ type: ReduxActionTypes.RESET_WIDGET_META_EVALUATED }],
});
};
export const resetChildrenMetaProperty = (
widgetId: string,
): ReduxAction<{ widgetId: string }> => {
return {
type: ReduxActionTypes.RESET_CHILDREN_WIDGET_META,
payload: {
widgetId,
},
};
};
export const updateMetaState = (evalMetaUpdates: EvalMetaUpdates) => {
return {
type: ReduxActionTypes.UPDATE_META_STATE,
payload: {
evalMetaUpdates,
},
};
};
export const triggerEvalOnMetaUpdate = () => {
return batchAction({
type: ReduxActionTypes.META_UPDATE_DEBOUNCED_EVAL,
payload: {},
});
};
export const syncBatchUpdateWidgetMetaProperties = (
batchMetaUpdates: UpdateWidgetMetaPropertyPayload[],
): ReduxAction<BatchUpdateWidgetMetaPropertyPayload> => {
return {
type: ReduxActionTypes.BATCH_UPDATE_META_PROPS,
payload: { batchMetaUpdates },
};
};
export const syncUpdateWidgetMetaProperty = (
widgetId: string,
propertyName: string,
propertyValue: unknown,
) => {
return {
type: ReduxActionTypes.SET_META_PROP,
payload: {
widgetId,
propertyName,
propertyValue,
},
};
};
export const resetWidgetsMetaState = (
widgetIdsToClear: string[],
): ReduxAction<{ widgetIdsToClear: string[] }> => {
return {
type: ReduxActionTypes.RESET_WIDGETS_META_STATE,
payload: {
widgetIdsToClear,
},
};
};