PromucFlow_constructor/app/client/src/ce/actions/helpers.ts
Ankita Kinger 410a55cf3c
fix: Refactoring code to fix a couple of issues related to modules on EE (#29843)
## Description

Refactoring code to fix a couple of issues related to modules on EE

#### PR fixes following issue(s)
Fixes [#29842](https://github.com/appsmithorg/appsmith/issues/29842)
[#29445](https://github.com/appsmithorg/appsmith/issues/29445)

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

## Testing

#### How Has This Been Tested?
- [x] Manual
- [ ] JUnit
- [ ] Jest
- [x] Cypress

## 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
- [x] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [x] 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**
  - Introduced a new interface for improved action context handling.
  - Added functionality to create API actions based on the editor type.
- Implemented a new hook for retrieving parent entity information in the
datasource editor.

- **Refactor**
- Updated various components to utilize the new
`ActionParentEntityTypeInterface`.
  - Enhanced reducer logic for better handling of action configurations.
  - Streamlined entity exports and imports for consistency.

- **Bug Fixes**
- Fixed redirection logic in the Datasource Blank State component for a
smoother user experience.

- **Chores**
  - Removed unused event listeners from sagas to optimize performance.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2023-12-26 11:38:00 +05:30

84 lines
2.5 KiB
TypeScript

import type { EventLocation } from "@appsmith/utils/analyticsUtilTypes";
import {
createNewApiAction,
createNewQueryAction,
} from "actions/apiPaneActions";
import { createNewJSCollection } from "actions/jsPaneActions";
import {
ActionParentEntityType,
type ActionParentEntityTypeInterface,
} from "@appsmith/entities/Engine/actionHelpers";
import { saveActionName } from "actions/pluginActionActions";
import { saveJSObjectName } from "actions/jsActionActions";
export const createNewQueryBasedOnParentEntity = (
entityId: string,
from: EventLocation,
dsId: string,
// Used in EE
// eslint-disable-next-line @typescript-eslint/no-unused-vars
parentEntityType: ActionParentEntityTypeInterface = ActionParentEntityType.PAGE,
) => {
return createNewQueryAction(entityId, from, dsId);
};
export const createNewAPIBasedOnParentEntity = (
entityId: string,
from: EventLocation,
apiType?: string,
// Used in EE
// eslint-disable-next-line @typescript-eslint/no-unused-vars
parentEntityType: ActionParentEntityTypeInterface = ActionParentEntityType.PAGE,
) => {
return createNewApiAction(entityId, from, apiType);
};
export const createNewJSCollectionBasedOnParentEntity = (
entityId: string,
from: EventLocation,
// Used in EE
// eslint-disable-next-line @typescript-eslint/no-unused-vars
parentEntityType = ActionParentEntityType.PAGE,
) => {
return createNewJSCollection(entityId, from);
};
export const saveActionNameBasedOnParentEntity = (
id: string,
name: string,
// Used in EE
// eslint-disable-next-line @typescript-eslint/no-unused-vars
parentEntityType: ActionParentEntityTypeInterface = ActionParentEntityType.PAGE,
) => {
return saveActionName({ id, name });
};
export const saveJSObjectNameBasedOnParentEntity = (
id: string,
name: string,
// Used in EE
// eslint-disable-next-line @typescript-eslint/no-unused-vars
parentEntityType: ActionParentEntityTypeInterface = ActionParentEntityType.PAGE,
) => {
return saveJSObjectName({ id, name });
};
export const createNewApiActionBasedOnEditorType = (
// eslint-disable-next-line @typescript-eslint/no-unused-vars
editorType: string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
editorId: string,
parentEntityId: string,
parentEntityType: ActionParentEntityTypeInterface,
apiType: string,
): any => {
if (parentEntityId) {
return createNewAPIBasedOnParentEntity(
parentEntityId,
"API_PANE",
apiType,
parentEntityType,
);
}
};