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

chore: git mod - integration app #38315

Merged
merged 137 commits into from
Dec 30, 2024
Merged

chore: git mod - integration app #38315

merged 137 commits into from
Dec 30, 2024

Conversation

brayn003
Copy link
Contributor

@brayn003 brayn003 commented Dec 23, 2024

Description

  • Git mod integration with applications behind feature flag

Fixes #37815
Fixes #37816
Fixes #37817
Fixes #37818
Fixes #37819
Fixes #37820

Automation

/ok-to-test tags="@tag.All"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/12526603607
Commit: 19f3ca0
Cypress dashboard.
Tags: @tag.All
Spec:


Sat, 28 Dec 2024 15:57:13 UTC

Communication

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

  • Yes
  • No

Summary by CodeRabbit

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced various new hooks for Git functionalities, including useGitModEnabled, useGitCurrentBranch, useGitProtectedMode, and useGitConnected.
    • Added a new component DeployButton to manage deployment actions.
    • Integrated ConnectSuccessModal to enhance user feedback upon successful Git connection.
    • Added GitImportModal for improved Git import functionality.
    • Introduced GlobalProfileView for managing and displaying user profile information.
    • Added a new icon, CloudIconV2, to the icon provider.
    • Implemented fetchGlobalSSHKey and gitImport sagas for better state management.
  • Improvements

    • Enhanced handling of Git-related states and actions across multiple components and sagas.
    • Streamlined selector usage for determining preview mode by replacing combinedPreviewModeSelector with selectCombinedPreviewMode.
    • Updated the DeployPreview component to manage success feedback and handle commit operations more effectively.
    • Improved the StatusChangesView component by adding a callout for migration messages.
    • Added new transformers for application status handling.
  • Bug Fixes

    • Updated error handling and loading states across various actions and components to improve reliability.
  • Refactor

    • Refactored action creators to use createArtifactAction instead of createSingleArtifactAction for consistency and clarity.
    • Consolidated Git import and connection logic to improve modularity and maintainability.
    • Modified the Header component to utilize GitApplicationContextProvider for managing Git-related state.
    • Updated various components to utilize the new selectCombinedPreviewMode selector for improved state management.
    • Refactored the DeployPreview component to enhance its functionality and styling consistency.
    • Enhanced the applicationStatusTransformer to handle multiple status transformations.

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: 1

🧹 Nitpick comments (6)
app/client/src/selectors/gitModSelectors.ts (4)

1-1: Track temporary file removal

Consider creating a tracking issue for removing this file once Git modularization is fully rolled out to prevent technical debt accumulation.

Would you like me to create a GitHub issue to track the removal of this temporary file?


20-31: Consider adding return type annotation

While the implementation is correct, adding an explicit return type would improve type safety and documentation.

 export function selectGitCurrentBranch(
   state: AppState,
   artifactDef: GitArtifactDef,
-) {
+): string {

33-44: Add return type for consistency

Similar to the previous function, adding an explicit return type would improve type safety.

 export function selectGitProtectedMode(
   state: AppState,
   artifactDef: GitArtifactDef,
-) {
+): boolean {

46-57: Optimize selector composition

The current implementation might cause unnecessary recalculations due to the nested selector. Consider flattening the selectors for better memoization.

 export const selectCombinedPreviewMode = createSelector(
   protectedModeSelector,
-  (state: AppState) => {
-    const baseApplicationId = getCurrentBaseApplicationId(state);
-
-    return selectGitProtectedMode(
-      state,
-      applicationArtifact(baseApplicationId),
-    );
-  },
+  getCurrentBaseApplicationId,
+  (state: AppState, baseApplicationId: string) => 
+    selectGitProtectedMode(state, applicationArtifact(baseApplicationId)),
   (isPreviewMode, isProtectedMode) => isPreviewMode || isProtectedMode,
 );
app/client/src/git/components/GitContextProvider/index.tsx (1)

51-57: Consider explicit null check for type safety

The implementation looks good, but we could make the type checking more explicit.

Consider this minor improvement:

  const artifactDef = useMemo(() => {
-   if (artifactType && baseArtifactId) {
+   if (artifactType !== null && baseArtifactId !== null) {
      return { artifactType, baseArtifactId };
    }
    return null;
  }, [artifactType, baseArtifactId]);

This makes the null checking more explicit and TypeScript-friendly.

app/client/src/git/store/selectors/gitArtifactSelectors.ts (1)

114-121: Add TODO explaining interface preservation strategy.

While the implementation is correct, consider adding a TODO comment explaining the long-term plan for the interface, as keeping unused parameters might confuse future maintainers.

 export const selectCurrentBranch = (
   state: GitRootState,
-  // need this to preserve interface
-  // eslint-disable-next-line @typescript-eslint/no-unused-vars
+  // TODO: artifactDef parameter preserved for interface compatibility.
+  // Plan to remove in future when all consumers are migrated to new state structure.
+  // eslint-disable-next-line @typescript-eslint/no-unused-vars
   artifactDef: GitArtifactDef,
 ) => {
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 741d1f0 and 4b18bae.

📒 Files selected for processing (9)
  • app/client/src/git/artifact-helpers/application/applicationStatusTransformer.ts (4 hunks)
  • app/client/src/git/components/GitContextProvider/index.tsx (3 hunks)
  • app/client/src/git/components/StatusChanges/StatusChangesView.tsx (2 hunks)
  • app/client/src/git/components/StatusChanges/StatusLoader.tsx (1 hunks)
  • app/client/src/git/components/StatusChanges/StatusTree.tsx (2 hunks)
  • app/client/src/git/components/StatusChanges/types.ts (1 hunks)
  • app/client/src/git/requests/fetchStatusRequest.types.ts (1 hunks)
  • app/client/src/git/store/selectors/gitArtifactSelectors.ts (5 hunks)
  • app/client/src/selectors/gitModSelectors.ts (1 hunks)
🔇 Additional comments (29)
app/client/src/git/requests/fetchStatusRequest.types.ts (1)

27-27: Ensure usage and test coverage for the new field.

You’ve added a numeric modifiedPackages property. Verify that all relevant components handle its potential range (including zero or large values) properly, and confirm that the new field is adequately tested to avoid runtime errors or inconsistencies.

Run the following script to locate references in the codebase and confirm consistent usage:

✅ Verification successful

The modifiedPackages field is properly handled and tested

The field is well-integrated across the codebase with proper null checks and type safety:

  • Used in selectors (gitSyncSelectors.tsx) for status calculations
  • Properly handled in UI components with null coalescing (StaticChange.tsx)
  • Covered in tests (index.test.tsx)
  • Correctly transformed in status processing (applicationStatusTransformer.ts) with proper pluralization
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: search for references of the new property 'modifiedPackages' across the repo

rg -A 3 "modifiedPackages"

Length of output: 3941

app/client/src/selectors/gitModSelectors.ts (1)

15-18: LGTM! Clean feature flag implementation

The selector is well-implemented with proper memoization and fallback handling.

app/client/src/git/components/StatusChanges/types.ts (1)

1-5: Solid approach in defining the StatusTreeStruct interface.
The interface is straightforward, typed, and flexible enough to handle hierarchical structures for displaying status messages.

app/client/src/git/components/StatusChanges/StatusLoader.tsx (3)

9-10: Good alignment for consistent spacing.
Switching to a bottom margin ensures a consistent look and feel.


12-13: Better use of styled-components for LoaderText.
Using a styled component is cleaner and reduces inline styling.


20-20: Proper usage of the newly introduced LoaderText.
This makes the loader message more semantically clear and consistent.

app/client/src/git/components/StatusChanges/StatusChangesView.tsx (3)

4-4: Neat reorganization of imports.
Pointing StatusTreeStruct to a separate file and using relative imports for StatusLoader enhances maintainability.

Also applies to: 10-11


14-16: Consistent styling approach with CalloutContainer.
Centralizing the top margin promotes consistency across different components.


57-61: Providing contextual feedback via Callout.
Displaying migrationMessage in a callout is an effective way to inform users about migration-related details.

app/client/src/git/components/StatusChanges/StatusTree.tsx (5)

10-11: Well-structured imports.
Importing styled and StatusTreeStruct aligns perfectly with the refactored architecture.


13-20: Introducing styled components for Collapsible usage.
This enhances stylistic control and keeps consistency with other styled components.


51-52: Smart approach to determine emphasis based on depth.
The noEmphasis flag is a neat way to style nested items differently.


58-58: Passing through the noEmphasis prop.
Consistent use of the noEmphasis flag in nested tree nodes.


64-65: Refactoring to StyledCollapsible and conditional spacing.
Adopting the styled collapsible and adjusting the spacing for child items is a clean and maintainable approach.

Also applies to: 67-67, 69-69, 75-75

app/client/src/git/components/GitContextProvider/index.tsx (2)

6-6: LGTM: Clean type import

The import is properly typed and follows TypeScript best practices.


10-10: Verify null handling in consuming components

The interface changes now allow null values for artifactDef, artifactType, and baseArtifactId. While this adds flexibility, it requires careful null checking in consuming components.

Let's verify the null handling in components that consume these values:

Also applies to: 28-29

✅ Verification successful

Proper null handling is implemented

The codebase shows consistent and safe handling of the nullable artifactDef:

  • Optional chaining (?.) is used when accessing artifactDef properties in components like useGitPermissions and ConnectModal
  • Null checks using if (artifactDef) are present in all hooks before dispatching actions
  • Default values are provided where needed (e.g., artifactDef?.artifactType ?? GitArtifactType.Application)
  • Redux selectors safely handle null values through optional chaining
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct usage of artifactDef, artifactType, and baseArtifactId
# to ensure proper null checking

# Look for usage of artifactDef from GitContext
ast-grep --pattern 'const { artifactDef } = useGitContext();'

# Look for optional chaining or null checks
rg 'artifactDef\?' app/client/src/git

Length of output: 1856


Script:

#!/bin/bash
# Let's check for direct usage of artifactDef without optional chaining
rg "artifactDef\." app/client/src/git -A 2

# Also check for null checks using if statements
rg "if.*artifactDef" app/client/src/git -A 2

# Let's also check the hooks that destructure artifactDef
ast-grep --pattern 'const { artifactDef } = useGitContext();
  $$$
  return'

Length of output: 39723

app/client/src/git/store/selectors/gitArtifactSelectors.ts (3)

18-21: LGTM! Function rename improves clarity.

The removal of the redundant "Git" prefix from the selector name is a good improvement, while maintaining the same reliable implementation.


220-222: LGTM! Null safety properly handled.

The addition of null coalescing operator provides proper fallback to an empty array, preventing potential runtime errors.


44-48: Verify modal state handling across components.

The new selector follows the established pattern correctly. Let's verify its usage:

✅ Verification successful

Modal state implementation is properly integrated and used correctly

The new selector is correctly implemented and integrated:

  • Used in useConnect hook to manage modal state
  • Properly consumed by ConnectSuccessModal component
  • Follows the established pattern in the codebase for modal state management
  • State updates handled through proper actions in the Redux store

The implementation maintains type safety and follows the existing patterns for Git-related UI state management.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for components using this new modal state
rg -l "selectConnectSuccessModalOpen|connectSuccessModalOpen" --type ts --type tsx

Length of output: 112


Script:

#!/bin/bash
# Search for components using this new modal state with correct file type flags
rg -l "selectConnectSuccessModalOpen|connectSuccessModalOpen" --type typescript --type tsx

# Also search for any UI components that might be handling connect success modal
rg -l "ConnectSuccessModal" --type typescript --type tsx

# Look for any modal state handling patterns in git-related components
rg "modal.*open.*git" --type typescript --type tsx

Length of output: 307


Script:

#!/bin/bash
# Search using just file extensions instead of type flags
rg -l "selectConnectSuccessModalOpen|connectSuccessModalOpen" -g "*.ts" -g "*.tsx"

# Search for connect success modal components
rg -l "ConnectSuccessModal" -g "*.ts" -g "*.tsx"

# Look for git-related modal state patterns
rg "modal.*open.*git" -g "*.ts" -g "*.tsx"

# Also check the artifact definition file to understand the modal state structure
fd -e ts -e tsx "GitArtifactDef" --exec cat {}

Length of output: 874


Script:

#!/bin/bash
# Check the implementation of ConnectSuccessModal and its usage
cat app/client/src/git/components/ConnectSuccessModal/index.tsx
cat app/client/src/git/components/ConnectSuccessModal/ConnectSuccessModalView.tsx

# Check how the modal state is used in the connect hook
cat app/client/src/git/hooks/useConnect.ts

# Check the UI state structure in types
cat app/client/src/git/store/types.ts

Length of output: 13351

app/client/src/git/artifact-helpers/application/applicationStatusTransformer.ts (10)

3-7: Use of imported constants from messages
This straightforward import looks fine, and the usage aligns well with the existing message structure.


16-21: Icons for new resource types
Assigning these icons appears consistent and provides clear visual cues for each resource.


28-28: Optional 'extra' field
Allowing an optional message is a neat approach for flexible node descriptions.


32-38: Appending 'extra' in createTreeNode
Simple and clear logic for building the final message string.


63-67: Sorting node definitions by subject
Sorting ensures consistent ordering of children in the tree. Nicely done.


147-150: Sorting the final tree
Sorting the top-level nodes by message maintains consistency in display order.


212-239: statusRemoteCountTransformer
Effectively conveys the behind/ahead status with appended helpful messages.


241-256: statusSettingsTransformer
Clean check for application.json modifications with a suitable fallback.


258-273: statusThemeTransformer
Consistent handling for theme changes. No issues found.


320-320: Integration of new transformer calls
All relevant status transformer functions are now aggregated and returned. This finalizes the comprehensive view of changes.

Also applies to: 324-324, 325-325, 326-326

@brayn003 brayn003 requested a review from ashit-rath December 24, 2024 18:58
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

🧹 Nitpick comments (3)
app/client/src/components/editorComponents/ApiResponseView.test.tsx (1)

20-22: Consider testing both preview mode states.
Mocking selectCombinedPreviewMode to return false ensures a predictable environment for this test. However, consider adding a test case with it returning true to cover different preview mode scenarios and validate component behavior under both conditions.

app/client/src/ce/pages/Applications/CreateNewAppsOption.test.tsx (1)

12-14: Add a scenario to validate the selectCombinedPreviewMode returning true.

Currently, the function is mocked to always return false. Consider adding a scenario to ensure coverage when the selector returns true as well, which will help in validating any logic that depends on the preview mode being enabled.

app/client/src/git/artifact-helpers/application/applicationStatusTransformer.ts (1)

63-67: Consider memoizing the sort comparator function

The sort comparator function is recreated on each call. Consider extracting it to a constant for better performance.

+const sortBySubject = (a: TreeNodeDef, b: TreeNodeDef) =>
+  a.subject.localeCompare(b.subject, undefined, { sensitivity: "base" });

 function createTreeNodeGroup(nodeDefs: TreeNodeDef[], subject: string) {
   return {
     icon: ICON_LOOKUP[nodeDefs[0].type],
     message: `${nodeDefs.length} ${subject} ${determineVerbForDefs(nodeDefs)}`,
     children: nodeDefs
-      .sort((a, b) =>
-        a.subject.localeCompare(b.subject, undefined, { sensitivity: "base" }),
-      )
+      .sort(sortBySubject)
       .map(createTreeNode),
   };
 }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b18bae and 059417b.

📒 Files selected for processing (3)
  • app/client/src/ce/pages/Applications/CreateNewAppsOption.test.tsx (1 hunks)
  • app/client/src/components/editorComponents/ApiResponseView.test.tsx (1 hunks)
  • app/client/src/git/artifact-helpers/application/applicationStatusTransformer.ts (4 hunks)
🔇 Additional comments (5)
app/client/src/git/artifact-helpers/application/applicationStatusTransformer.ts (5)

3-28: LGTM: Interface and constant changes are well-structured

The additions to ICON_LOOKUP and TreeNodeDef interface are consistent with the module's purpose and maintain type safety.


212-239: LGTM: Remote count transformer implementation

The function properly handles both ahead and behind counts with appropriate messages.


241-273: LGTM: Settings and theme transformers

Both transformers correctly handle their respective JSON file modifications.


306-306: Typo in plural logic for module instance

Line 306 references modifiedPackages instead of modifiedModuleInstances.


320-326: LGTM: Main transformer function updates

The new transformers are properly integrated into the main transformer function.

@brayn003 brayn003 removed request for ayushpahwa, a team and jacquesikot December 24, 2024 21:10
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

🧹 Nitpick comments (1)
app/client/src/ce/navigation/FocusStrategy/AppIDEFocusStrategy.ts (1)

123-127: Consider caching the Git branch selection.

The Git branch selection is performed in a generator function that might be called frequently. Consider memoizing the branch selection if performance becomes a concern.

+// Add to the top of the file with other imports
+import { createSelector } from 'reselect';
+
+const getGitBranchForApp = createSelector(
+  [getCurrentBaseApplicationId, selectGitCurrentBranch],
+  (baseApplicationId, gitBranch) => gitBranch
+);
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e678dd9 and 5fd6853.

📒 Files selected for processing (1)
  • app/client/src/ce/navigation/FocusStrategy/AppIDEFocusStrategy.ts (5 hunks)
🔇 Additional comments (3)
app/client/src/ce/navigation/FocusStrategy/AppIDEFocusStrategy.ts (3)

20-22: LGTM: Clean import additions for Git module integration.

The new imports properly separate concerns between editor state and Git functionality.


91-100: Verify the impact of null branch parameter.

The function now handles null branch parameter gracefully, but we should ensure this doesn't affect existing focus retention behavior.

✅ Verification successful

Null branch parameter handling is safe and consistent with existing behavior

The implementation is correct and safe because:

  • The test cases show that the code already expects and handles both formats (EDITOR_STATE.{id} and EDITOR_STATE.{id}#{branch})
  • The same branching logic is consistently used across the codebase, including in the focus retention logic
  • All existing usages pass the branch parameter explicitly
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing usages of createEditorFocusInfoKey to verify compatibility
rg -A 2 "createEditorFocusInfoKey\(" --type ts

Length of output: 560


Script:

#!/bin/bash
# Let's check how getCurrentFocusInfo is implemented to understand the focus retention behavior
ast-grep --pattern 'function getCurrentFocusInfo($_) { $$$ }'

# Also check for any other functions that might be using the focus info key
rg "EDITOR_STATE\." --type ts -B 2 -A 2

Length of output: 2588


154-158: Ensure consistent branch handling across state transitions.

The branch handling in getEntitiesForStore matches getEntitiesForSet, maintaining consistency. However, verify that the branch state is properly maintained during navigation.

Also applies to: 201-203

✅ Verification successful

Let me search for branch state handling during navigation to verify the concern.


Let me try a different search pattern to analyze the branch handling during navigation.


Branch state handling is properly maintained during navigation

The codebase shows consistent branch handling across state transitions:

  1. AppIDEFocusStrategy.ts correctly retrieves and uses branch information in both getEntitiesForStore and getEntitiesForSet methods
  2. Branch state is properly maintained through selectors (selectGitCurrentBranch, getCurrentGitBranch)
  3. Navigation components consistently use branch information for state management and URL handling
  4. Tests verify branch state preservation during navigation (AppIDEFocusStrategy.test.ts)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potential inconsistencies in branch handling
rg -A 3 "branch[\"']?\s*[=:]" --type ts

Length of output: 44321


Script:

#!/bin/bash
# Search for branch handling in navigation-related files
ast-grep --pattern 'function* $FUNC($$$) {
  $$$
  branch$$$
  $$$
}'

Length of output: 71


Script:

#!/bin/bash
# Search for navigation-related files and their branch handling
rg -A 5 "getEntitiesForStore|getEntitiesForSet" --type ts

# Also check for branch-related state transitions
rg -A 5 "selectGitCurrentBranch|getCurrentGitBranch" --type ts

Length of output: 30268

Copy link
Contributor

@ashit-rath ashit-rath left a comment

Choose a reason for hiding this comment

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

@brayn003 I understand such integration leads to such large PRs but I noticed there were a lot of refactors as well, like filename changes, function changes and new components which could have been avoided and focused more on the integration part. As an author it can be very tempting to do everything in a single PR but it has negative side-effects and especially for reviewing, it shifts the focus from the right stuff and becomes very tedious and time consuming. Let's aim for smaller PRs

@@ -30,6 +30,7 @@ const blockAirgappedRoutes = (config: InternalAxiosRequestConfig) => {

const addGitBranchHeader = (config: InternalAxiosRequestConfig) => {
const state = store.getState();
// ! git mod - not sure how to replace this, we could directly read state if required
Copy link
Contributor

Choose a reason for hiding this comment

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

In your git folder where you have API requests; why not create an HOC for the Api class that injects branch as header. IIRC the config property that .get .post accept has an option to pass additional headers

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would ideally want to remove this from the interceptor logic and pass it with the api explicitly. But not tampering this right now

basePageId: string,
branch: string | null = null,
) =>
branch
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we changing these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Branch can either be undefined or null. With the old implementation - when branch is not present it would return either EDITOR_STATE.pageid.undefined or EDITOR_STATE.pageid.null. This creates issues. So, I have modified the logic to ignore branch totally when it is either undefined or null

app/client/src/ce/reducers/index.tsx Outdated Show resolved Hide resolved
Comment on lines +750 to +762
[gitConnectSuccess.type]: (
state: ApplicationsReduxState,
action: PayloadAction<GitConnectSuccessPayload>,
) => {
return {
...state,
currentApplication: {
...state.currentApplication,
gitApplicationMetadata:
action.payload.responseData.gitApplicationMetadata,
},
};
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to do this in the applicationsReducer?

Copy link
Contributor Author

@brayn003 brayn003 Dec 27, 2024

Choose a reason for hiding this comment

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

we do the same thing with old implementation as well. Didn't want to change it too much. Will revisit later

app/client/src/ce/sagas/index.tsx Outdated Show resolved Hide resolved
@@ -179,7 +198,9 @@ export const AppIDEFocusStrategy: FocusStrategy = {
appState: EditorState.EDITOR,
params: prevFocusEntityInfo.params,
},
key: `EDITOR_STATE.${prevFocusEntityInfo.params.basePageId}#${branch}`,
key: branch
? `EDITOR_STATE.${prevFocusEntityInfo.params.basePageId}#${branch}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we changing this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Branch can either be undefined or null. With the old implementation - when branch is not present it would return either EDITOR_STATE.pageid.undefined or EDITOR_STATE.pageid.null. This creates issues. So, I have modified the logic to ignore branch totally when it is either undefined or null

}
}

export const selectCombinedPreviewMode = createSelector(
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggestion

// Selector to get the artifact definition based on the current base application ID
const selectArtifactDef = createSelector(
  getCurrentBaseApplicationId,
  (baseApplicationId) => applicationArtifact(baseApplicationId)
);

// Improved selectCombinedPreviewMode selector
export const selectCombinedPreviewMode = createSelector(
  previewModeSelector,
  selectArtifactDef,
  (state: AppState) => state, // Pass the entire state for downstream selectors
  (isPreviewMode, artifactDef, state) => {
    const isProtectedMode = selectGitProtectedMode(state, artifactDef);
    return isPreviewMode || isProtectedMode;
  }
);

Comment on lines 36 to 41
const baseApplicationId: string = yield select(getCurrentBaseApplicationId);

const branch: string | undefined = yield select(
selectGitCurrentBranch,
applicationArtifact(baseApplicationId),
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be a selector like getCurrentBranchForApplication? I noticed this block being used in multiple places

@brayn003
Copy link
Contributor Author

Yes my bad 🙈

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: 1

🧹 Nitpick comments (4)
app/client/src/entities/Engine/AppEditorEngine.ts (1)

27-27: Remove commented import statement

The history import is commented out on line 27 but then imported again on line 71. Remove the commented import to maintain clean code.

-// import history from "utils/history";

Also applies to: 71-71

app/client/src/sagas/FocusRetentionSaga.ts (1)

126-128: Removing focus history per branch
Including the branch in the focus-history key is a solid step to ensure that focus states remain per-branch.

If you need to handle multiple branch transitions, consider caching or cleaning old keys to prevent stale focus states.

app/client/src/selectors/gitModSelectors.ts (1)

1-2: Temporary file notice
A clear comment indicating temporary status. Keep a reminder to remove or finalize the file once the feature is fully rolled out.

app/client/src/ce/navigation/FocusStrategy/AppIDEFocusStrategy.ts (1)

121-123: Consider type consistency with createEditorFocusInfo

The branch type should match the createEditorFocusInfo parameter type for consistency.

-    const branch: string | undefined = yield select(
+    const branch: string | null = yield select(
       selectGitApplicationCurrentBranch,
     );
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5fd6853 and 83579a9.

📒 Files selected for processing (12)
  • app/client/src/ce/navigation/FocusStrategy/AppIDEFocusStrategy.ts (5 hunks)
  • app/client/src/ce/reducers/index.tsx (3 hunks)
  • app/client/src/ce/sagas/PageSagas.tsx (4 hunks)
  • app/client/src/ce/sagas/index.tsx (2 hunks)
  • app/client/src/entities/Engine/AppEditorEngine.ts (5 hunks)
  • app/client/src/entities/Engine/index.ts (2 hunks)
  • app/client/src/pages/Editor/GlobalHotKeys/GlobalHotKeys.tsx (2 hunks)
  • app/client/src/sagas/ActionExecution/StoreActionSaga.ts (2 hunks)
  • app/client/src/sagas/FocusRetentionSaga.ts (2 hunks)
  • app/client/src/sagas/GlobalSearchSagas.ts (1 hunks)
  • app/client/src/selectors/gitModSelectors.ts (1 hunks)
  • app/client/src/widgets/withWidgetProps.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • app/client/src/ce/sagas/index.tsx
  • app/client/src/widgets/withWidgetProps.tsx
  • app/client/src/ce/reducers/index.tsx
  • app/client/src/entities/Engine/index.ts
  • app/client/src/ce/sagas/PageSagas.tsx
🔇 Additional comments (20)
app/client/src/pages/Editor/GlobalHotKeys/GlobalHotKeys.tsx (1)

49-49: Nice import usage.
This new import name is clear and consistent with the broader gitModSelectors naming.

app/client/src/entities/Engine/AppEditorEngine.ts (3)

326-333: LGTM: Recent entities restoration implementation

The implementation correctly handles the restoration of recent entities with proper null checks for the application ID and optional branch parameter.


379-389: LGTM: Git module feature flag implementation

Clean implementation of the Git module initialization with proper feature flag check.


390-402: Verify cleanup of forked saga

The forked saga might need cleanup when the component unmounts. Consider using a cancellable pattern.

Also, consider optimizing the disabled state:

 } else {
   const currentBranch: string = yield select(
     selectGitApplicationCurrentBranch,
   );

-  // init of temporary remote url from old application
-  yield put(remoteUrlInputValue({ tempRemoteUrl: "" }));
   // add branch query to path and fetch status

   if (currentBranch) {
     history.replace(addBranchParam(currentBranch));
     yield fork(this.loadGitInBackground);
   }
 }
app/client/src/sagas/ActionExecution/StoreActionSaga.ts (2)

15-15: Switch to updated Git selector
The import of selectGitApplicationCurrentBranch reflects the new approach of obtaining the branch details. Good job keeping the code aligned with the modular Git structure.


24-26: Confirm branch usage
Using selectGitApplicationCurrentBranch here ensures we're always fetching the latest branch info. Verify that all references to the old selector are removed to maintain consistency.

app/client/src/sagas/GlobalSearchSagas.ts (2)

26-26: Adoption of new Git branch selector
Replacing getCurrentGitBranch with selectGitApplicationCurrentBranch is consistent with the modular approach. No issues observed.


35-37: Ensure consistent usage across sagas
This saga now relies on selectGitApplicationCurrentBranch. Double-check all other sagas also use the updated selector to avoid mismatches.

app/client/src/sagas/FocusRetentionSaga.ts (1)

24-24: Updated import for branch retrieval
Swapping out the old getCurrentGitBranch import with selectGitApplicationCurrentBranch is aligned with modular Git enhancements.

app/client/src/selectors/gitModSelectors.ts (8)

3-5: Selective imports
Consolidating the needed selectors in one file helps maintain a single source of truth for Git configurations.


6-9: Modular approach
The git imports for new branch and protected mode selectors align well with the modularization plan.


10-14: Editor selectors
Good usage of existing editor selectors and artifact helpers in tandem with the new Git modular approach.


16-19: Feature flag detection
selectGitModEnabled gracefully defaults to false if the flag is undefined, preventing accidental feature exposure.


21-24: Application artifact resolution
This approach to retrieve application artifacts by base ID keeps the logic clean and consistent.


26-34: Branch selection logic
The selector provides a neat fallback to the old or new branch logic, depending on the feature-flag state. This prevents breaking changes for existing flows.


36-44: Protected mode toggling
Mirroring the branch selection logic for protectedMode ensures consistent gating with the Git mod flag.


46-50: Preview mode combination
Combining the standard preview mode with the Git-protected mode in a single selector is clean and avoids branching logic duplication.

app/client/src/ce/navigation/FocusStrategy/AppIDEFocusStrategy.ts (3)

20-20: LGTM: Import change aligns with Git modularization

The switch to selectGitApplicationCurrentBranch from gitModSelectors is consistent with the Git module integration objectives.


89-98: LGTM: Improved branch handling in key generation

The changes address the previously discussed issues with undefined/null branch handling, providing a cleaner key format.


150-152: Ensure consistent branch handling across focus storage

Two suggestions:

  1. Align branch type with createEditorFocusInfo
  2. Verify the changes don't break existing focus storage
-    const branch: string | undefined = yield select(
+    const branch: string | null = yield select(
       selectGitApplicationCurrentBranch,
     );

Also applies to: 195-197

@brayn003 brayn003 added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Dec 27, 2024
@brayn003 brayn003 requested a review from ashit-rath December 27, 2024 10:15
ashit-rath
ashit-rath previously approved these changes Dec 27, 2024
@brayn003 brayn003 merged commit 692e394 into release Dec 30, 2024
92 checks passed
@brayn003 brayn003 deleted the chore/git-mod-10 branch December 30, 2024 10:23
brayn003 added a commit that referenced this pull request Dec 31, 2024
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 2025
## Description
- Git mod integration with applications behind feature flag

Fixes appsmithorg#37815 
Fixes appsmithorg#37816 
Fixes appsmithorg#37817 
Fixes appsmithorg#37818 
Fixes appsmithorg#37819 
Fixes appsmithorg#37820 


## Automation

/ok-to-test tags="@tag.All"

### 🔍 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/12526603607>
> Commit: 19f3ca0
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12526603607&attempt=2"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.All`
> Spec:
> <hr>Sat, 28 Dec 2024 15:57:13 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

## Summary by CodeRabbit

## Release Notes

- **New Features**
- Introduced various new hooks for Git functionalities, including
`useGitModEnabled`, `useGitCurrentBranch`, `useGitProtectedMode`, and
`useGitConnected`.
	- Added a new component `DeployButton` to manage deployment actions.
- Integrated `ConnectSuccessModal` to enhance user feedback upon
successful Git connection.
	- Added `GitImportModal` for improved Git import functionality.
- Introduced `GlobalProfileView` for managing and displaying user
profile information.
	- Added a new icon, `CloudIconV2`, to the icon provider.
- Implemented `fetchGlobalSSHKey` and `gitImport` sagas for better state
management.

- **Improvements**
- Enhanced handling of Git-related states and actions across multiple
components and sagas.
- Streamlined selector usage for determining preview mode by replacing
`combinedPreviewModeSelector` with `selectCombinedPreviewMode`.
- Updated the `DeployPreview` component to manage success feedback and
handle commit operations more effectively.
- Improved the `StatusChangesView` component by adding a callout for
migration messages.
	- Added new transformers for application status handling.

- **Bug Fixes**
- Updated error handling and loading states across various actions and
components to improve reliability.

- **Refactor**
- Refactored action creators to use `createArtifactAction` instead of
`createSingleArtifactAction` for consistency and clarity.
- Consolidated Git import and connection logic to improve modularity and
maintainability.
- Modified the `Header` component to utilize
`GitApplicationContextProvider` for managing Git-related state.
- Updated various components to utilize the new
`selectCombinedPreviewMode` selector for improved state management.
- Refactored the `DeployPreview` component to enhance its functionality
and styling consistency.
- Enhanced the `applicationStatusTransformer` to handle multiple status
transformations.
<!-- 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
ok-to-test Required label for CI Packages & Git Pod All issues belonging to Packages and Git Packages Pod issues that belong to the packages pod potential-duplicate This label marks issues that are potential duplicates of already open issues skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo
Projects
None yet
2 participants