Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: auto redirect from datasource page to module editor #35164

Merged
merged 2 commits into from
Jul 25, 2024

Conversation

ashit-rath
Copy link
Contributor

@ashit-rath ashit-rath commented Jul 25, 2024

Description

When create datasource is initiated from the API editor by clicking "Save as datasource", it fixes the redirection back to the API editor when Save is clicked for modules in package editor.

This PR also refactors the usage of typing of actionRouteInfo and introduces parentEntityId instead of using pageId, moduleId, workflowId separately.

This fix also verifies the sanity of

  1. API in apps
  2. API in workflows

Fixes #31506

Automation

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

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/10093685845
Commit: 785cbe3
Cypress dashboard.
Tags: @tag.Datasource,@tag.Sanity
Spec:


Thu, 25 Jul 2024 12:39:50 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced a new function to retrieve the current module ID, enhancing state management.
    • Added support for handling parentEntityId in various data source sagas.
  • Bug Fixes

    • Improved type safety for action handling in sagas.
  • Tests

    • Added a new test suite for the handleDatasourceCreatedSaga to validate its behavior upon datasource creation.

@ashit-rath ashit-rath requested a review from ayushpahwa as a code owner July 25, 2024 02:21
Copy link
Contributor

coderabbitai bot commented Jul 25, 2024

Walkthrough

The recent changes enhance state management and saga handling in the application, particularly regarding datasource operations. A new selector, getCurrentModuleId, retrieves the current module ID, while the datasourcePaneReducer has been updated to reflect structural changes in its state. The sagas have also been refined for improved type safety and correct handling of entity IDs, resulting in a more robust and maintainable codebase.

Changes

Files Change Summary
app/client/src/ce/selectors/modulesSelector.ts Added getCurrentModuleId function to retrieve the current module ID.
app/client/src/reducers/uiReducers/datasourcePaneReducer.ts Renamed pageId to parentEntityId in DatasourcePaneReduxState; simplified action type.
app/client/src/sagas/ApiPaneSagas.ts Changed handleDatasourceCreatedSaga to be exported; updated actionRouteInfo for better type safety.
app/client/src/sagas/DatasourcesSagas.ts Enhanced handling of datasource actions with new parentEntityId; improved type safety in sagas.
app/client/src/sagas/__tests__/ApiPaneSagas.test.ts Added tests for handleDatasourceCreatedSaga to ensure correct URL redirection.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant APIEditor
    participant DatasourceConfig

    User->>APIEditor: Click on Save Datasource
    APIEditor->>DatasourceConfig: Redirect to datasource config page
    User->>DatasourceConfig: Save datasource
    DatasourceConfig->>APIEditor: Redirect to correct API editor page
Loading

Assessment against linked issues

Objective Addressed Explanation
Redirect to the same API editor page after saving a datasource (Issue #31506)
Ensure the correct URL is constructed during datasources management

Poem

In the code, new paths we weave,
With modules and datasources to believe.
Changes sprout as functions grow,
Redirects guide us where to go.
A saga's tale, in tests we find,
Robust and clear, our code aligned! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Bug Something isn't working Low An issue that is neither critical nor breaks a user flow Module creator Issues related to the module creator side Packages Pod issues that belong to the packages pod Production labels Jul 25, 2024
@ashit-rath
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/10087095676.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 35164.
recreate: .

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
app/client/src/ce/selectors/modulesSelector.ts (1)

9-9: Ensure getCurrentModuleId returns the correct module ID.

The function currently returns an empty string. Ensure that the correct module ID is retrieved from the application state.

  • Location: app/client/src/ce/selectors/modulesSelector.ts at line 9
  • Usage: app/client/src/sagas/DatasourcesSagas.ts at line 9 and 14
Analysis chain

Ensure getCurrentModuleId returns the correct module ID.

The function currently returns an empty string. Ensure that the correct module ID is retrieved from the application state.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage and implementation of `getCurrentModuleId`.

# Test: Search for the function usage. Expect: Function should retrieve the correct module ID from the state.
rg --type typescript -A 5 $'getCurrentModuleId'

Length of output: 81


Script:

#!/bin/bash
# Description: Verify the usage and implementation of `getCurrentModuleId`.

# Test: Search for the function usage. Expect: Function should retrieve the correct module ID from the state.
rg --type ts -A 5 $'getCurrentModuleId'

Length of output: 1169

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between ddc2304 and db2db7a.

Files selected for processing (5)
  • app/client/src/ce/selectors/modulesSelector.ts (1 hunks)
  • app/client/src/reducers/uiReducers/datasourcePaneReducer.ts (2 hunks)
  • app/client/src/sagas/ApiPaneSagas.ts (3 hunks)
  • app/client/src/sagas/DatasourcesSagas.ts (5 hunks)
  • app/client/src/sagas/tests/ApiPaneSagas.test.ts (2 hunks)
Additional comments not posted (11)
app/client/src/reducers/uiReducers/datasourcePaneReducer.ts (2)

63-63: Simplify the type of action parameter.

The type of the action parameter in the STORE_AS_DATASOURCE_UPDATE case has been simplified. This change enhances type safety and maintainability.


26-26: Ensure parentEntityId is correctly populated.

The parentEntityId field replaces pageId. Ensure that this field is correctly populated and used throughout the application.

Verification successful

Let's correct the previous script to accurately search for the usage of parentEntityId across all TypeScript files.


Ensure parentEntityId is correctly populated.

The parentEntityId field is indeed used and populated throughout the application as observed in multiple instances across the codebase.

  • Examples of usage:
    • apiEditorIdURL({ parentEntityId: contextId, apiId: response.data.id })
    • parentEntityId: pageId || moduleId
    • parentEntityId: actionRouteInfo.parentEntityId || ""
    • const { parentEntityId, parentEntityKey } = resolveParentEntityMetadata(...)
    • parentEntityId: action.payload.destinationPageId

Given these instances, it can be confirmed that parentEntityId is correctly populated and used throughout the application.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage and population of `parentEntityId`.

# Test: Search for the usage of `parentEntityId`. Expect: Field should be correctly populated and used throughout the application.
rg --type typescript -A 5 $'parentEntityId'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the usage and population of `parentEntityId`.

# Find all TypeScript files and search for the usage of `parentEntityId`.
fd -e ts -x rg 'parentEntityId' {}

Length of output: 1597

app/client/src/sagas/__tests__/ApiPaneSagas.test.ts (2)

1-12: Good practice: Import necessary dependencies.

The import statements include necessary dependencies for the new test suite. This is a good practice to ensure the test functions properly.


64-140: Comprehensive test for handleDatasourceCreatedSaga.

The new test suite for handleDatasourceCreatedSaga is comprehensive and verifies the correct behavior of the saga. Ensure that all edge cases are covered.

app/client/src/sagas/ApiPaneSagas.ts (3)

590-590: Good job on exporting the function!

Exporting handleDatasourceCreatedSaga improves its usability within the application.


611-612: Great improvement on type safety!

Updating the type of actionRouteInfo to ReturnType<typeof getDatasourceActionRouteInfo> ensures more accurate type representation.


648-649: Ensure the new logic for pageId is correct.

The logic for determining pageId has been updated to use actionRouteInfo?.parentEntityId. Verify that this change aligns with the new data structure and requirements.

Verification successful

Let's correct the file type and re-run the search to verify the usage of parentEntityId in the codebase.


The new logic for pageId is correct.

The usage of parentEntityId is consistent across the codebase, indicating that it is an integral part of the data structure. The change to use actionRouteInfo?.parentEntityId aligns with this structure and is appropriate.

  • Files and lines to review:
    • app/client/src/sagas/ApiPaneSagas.ts (Lines 648-649)
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `parentEntityId` in the codebase to ensure consistency with the new data structure.

# Test: Search for `parentEntityId` usage. Expect: Consistent usage across the codebase.
rg --type typescript -A 5 $'parentEntityId'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the usage of `parentEntityId` in the codebase to ensure consistency with the new data structure.

# Test: Search for `parentEntityId` usage. Expect: Consistent usage across the codebase.
rg --type ts -A 5 'parentEntityId'

Length of output: 54483

app/client/src/sagas/DatasourcesSagas.ts (4)

1066-1067: Great improvement on type safety!

Updating the type of actionRouteInfo to ReturnType<typeof getDatasourceActionRouteInfo> ensures more accurate type representation.


1305-1305: Good addition of moduleId!

Adding moduleId enhances the flexibility of the action by allowing it to reference the current module's ID.


1405-1405: Ensure the new logic for parentEntityId is correct.

Using parentEntityId instead of pageId when pushing to history ensures the correct identifier is utilized based on the context. Verify that this change aligns with the new data structure and requirements.

Verification successful

Let's correct the file type and re-run the search to verify the usage of parentEntityId.


Ensure the new logic for parentEntityId is correct.

The usage of parentEntityId is consistent across the codebase, aligning with the new data structure and requirements. The change ensures that the correct identifier is utilized based on the context.

  • Verified instances in:
    • app/client/src/sagas/CurlImportSagas.ts
    • app/client/src/sagas/ActionSagas.ts
    • app/client/src/reducers/uiReducers/datasourcePaneReducer.ts
    • app/client/src/sagas/ApiPaneSagas.ts
    • app/client/src/pages/common/datasourceAuth/index.tsx
    • And many other files.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `parentEntityId` in the codebase to ensure consistency with the new data structure.

# Test: Search for `parentEntityId` usage. Expect: Consistent usage across the codebase.
rg --type typescript -A 5 $'parentEntityId'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the usage of `parentEntityId` in the codebase to ensure consistency with the new data structure.

# Test: Search for `parentEntityId` usage. Expect: Consistent usage across the codebase.
rg --type ts -A 5 $'parentEntityId'

Length of output: 54483


1363-1363: Ensure the new logic for parentEntityId is correct.

Including parentEntityId in the action payload, which can be either pageId or moduleId, improves flexibility. Verify that this change aligns with the new data structure and requirements.

Verification successful

Let's correct the file type and re-run the search to ensure we gather the necessary information about the usage of parentEntityId across the codebase.


Ensure the new logic for parentEntityId is correct.

The new logic for parentEntityId (i.e., pageId || moduleId) appears to be consistently used across the codebase. The change aligns with the existing data structure and requirements, as evidenced by multiple instances where parentEntityId is correctly assigned and utilized.

  • Files with relevant changes:
    • app/client/src/sagas/DatasourcesSagas.ts
    • app/client/src/sagas/ApiPaneSagas.ts
    • app/client/src/pages/common/datasourceAuth/index.tsx
    • app/client/src/pages/Editor/gitSync/ReconnectDatasourceModal.tsx
    • app/client/src/pages/Editor/IntegrationEditor/NewApi.tsx
    • app/client/src/pages/Editor/IntegrationEditor/NewQuery.tsx
    • app/client/src/pages/Editor/IntegrationEditor/DatasourceHome.tsx
    • app/client/src/pages/Editor/Explorer/Files/index.tsx
    • app/client/src/sagas/ActionSagas.ts
    • app/client/src/sagas/helpers.ts

The new logic for setting parentEntityId as pageId || moduleId is correctly integrated and should work as expected within the updated data structure.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `parentEntityId` in the codebase to ensure consistency with the new data structure.

# Test: Search for `parentEntityId` usage. Expect: Consistent usage across the codebase.
rg --type typescript -A 5 $'parentEntityId'

Length of output: 77


Script:

#!/bin/bash
# Description: Verify the usage of `parentEntityId` in the codebase to ensure consistency with the new data structure.

# Test: Search for `parentEntityId` usage. Expect: Consistent usage across the codebase.
rg --type ts -A 5 'parentEntityId'

Length of output: 54483

Copy link

Deploy-Preview-URL: https://ce-35164.dp.appsmith.com

@ashit-rath
Copy link
Contributor Author

EE DP -> https://ee-4742.dp.appsmith.com/

@kamakshibhat-appsmith
Copy link

@ashit-rath redirection not working in module editor ,

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between db2db7a and 785cbe3.

Files selected for processing (1)
  • app/client/src/sagas/ApiPaneSagas.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/sagas/ApiPaneSagas.ts

@kamakshibhat-appsmith
Copy link

Looks good @ashit-rath

Copy link
Contributor

@ayushpahwa ayushpahwa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some doubts, implementation and DP looks good.

@@ -1305,6 +1302,7 @@ function* storeAsDatasourceSaga() {
const { values } = yield select(getFormData, API_EDITOR_FORM_NAME);
const applicationId: string = yield select(getCurrentApplicationId);
const pageId: string | undefined = yield select(getCurrentPageId);
const moduleId: string | undefined = yield select(getCurrentModuleId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to get the parentEntityId from the URL instead of doing this check? If not, then should we add TODO to add workflows handling here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason for grabbing the id from URL? Also what do you expect for workflows? since it does not have a parentEntityId but only the editorId which is the workflowId

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked, seems like not needed.

jest.resetAllMocks();
});

it("should pass parentEntityId to apiEditorIdURL and redirect to correct url when in app", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also add tests for scenarios in workflows and packages. Not urgent, can park as TODO or github issue also.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we have to take care of this in EE as the URLAssembly rules are not present here. I'll create an issue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, makes sense. I confused this with EE.

@ashit-rath ashit-rath added the ok-to-test Required label for CI label Jul 25, 2024
@@ -1305,6 +1302,7 @@ function* storeAsDatasourceSaga() {
const { values } = yield select(getFormData, API_EDITOR_FORM_NAME);
const applicationId: string = yield select(getCurrentApplicationId);
const pageId: string | undefined = yield select(getCurrentPageId);
const moduleId: string | undefined = yield select(getCurrentModuleId);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked, seems like not needed.

jest.resetAllMocks();
});

it("should pass parentEntityId to apiEditorIdURL and redirect to correct url when in app", async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, makes sense. I confused this with EE.

@ashit-rath ashit-rath merged commit 213249a into release Jul 25, 2024
43 checks passed
@ashit-rath ashit-rath deleted the fix/module-ds-redirect branch July 25, 2024 13:21
MajaharZemoso pushed a commit to MajaharZemoso/appsmith that referenced this pull request Jul 28, 2024
…#35164)

## Description
When create datasource is initiated from the API editor by clicking
"Save as datasource", it fixes the redirection back to the API editor
when `Save` is clicked for modules in package editor.

This PR also refactors the usage of typing of `actionRouteInfo` and
introduces `parentEntityId` instead of using `pageId`, `moduleId`,
`workflowId` separately.

This fix also verifies the sanity of
1. API  in apps
2. API in workflows

Fixes appsmithorg#31506

## Automation

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

### 🔍 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/10093685845>
> Commit: 785cbe3
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10093685845&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Datasource,@tag.Sanity`
> Spec:
> <hr>Thu, 25 Jul 2024 12:39:50 UTC
<!-- end of auto-generated comment: Cypress test results  -->


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


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

- **New Features**
- Introduced a new function to retrieve the current module ID, enhancing
state management.
- Added support for handling `parentEntityId` in various data source
sagas.

- **Bug Fixes**
	- Improved type safety for action handling in sagas.

- **Tests**
- Added a new test suite for the `handleDatasourceCreatedSaga` to
validate its behavior upon datasource creation.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Low An issue that is neither critical nor breaks a user flow Module creator Issues related to the module creator side ok-to-test Required label for CI Packages Pod issues that belong to the packages pod Production
Projects
None yet
3 participants