Skip to content

Commit 0808b27

Browse files
author
Rudraprasad Das
authored
chore: git mod - adding init saga and connecting components to ctx (#38088)
## Description - Adds more selectors - Adds more sagas - Introduces init steps for git - Improvements upon CtxAwareGitQuickActions Fixes #37800 Fixes #36814 ## Automation /ok-to-test tags="@tag.Git" ### 🔍 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/12295168481> > Commit: ea1ab49 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=12295168481&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Git` > Spec: > <hr>Thu, 12 Dec 2024 12:06:09 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 - **New Features** - Introduced a context provider for managing Git-related state. - Added a `GitQuickActions` component for various Git actions. - Implemented custom hooks for managing Git branches, metadata, operations, and settings. - Added Redux Saga functions for fetching Git metadata and protected branches. - Enhanced autocommit functionality with polling for progress. - Introduced actions for managing the autocommit process and fetching protected branches. - Added new actions to initialize Git for editor context and manage loading states. - **Bug Fixes** - Improved error handling in various action creators and sagas. - **Chores** - Updated action creators and types for better type safety and clarity. - Refined test cases for components to ensure accurate button selection. - Modified request functions to utilize Axios promises directly for better consistency. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 8e30a38 commit 0808b27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+784
-232
lines changed

app/client/src/git/components/CtxAwareGitQuickActions/index.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@ import useStatusChangeCount from "./hooks/useStatusChangeCount";
55

66
function CtxAwareGitQuickActions() {
77
const {
8+
autocommitEnabled,
9+
autocommitPolling,
810
discard,
911
discardLoading,
1012
fetchStatusLoading,
13+
gitConnected,
14+
protectedMode,
1115
pull,
1216
pullError,
1317
pullLoading,
@@ -17,12 +21,7 @@ function CtxAwareGitQuickActions() {
1721
toggleGitSettingsModal,
1822
} = useGitContext();
1923

20-
const isGitConnected = false;
21-
const isAutocommitEnabled = true;
22-
const isAutocommitPolling = false;
23-
const isConnectPermitted = true;
24-
const isProtectedMode = false;
25-
24+
const connectPermitted = true;
2625
const isPullFailing = !!pullError;
2726
const isStatusClean = status?.isClean ?? false;
2827
const statusBehindCount = status?.behindCount ?? 0;
@@ -31,13 +30,13 @@ function CtxAwareGitQuickActions() {
3130
return (
3231
<GitQuickActions
3332
discard={discard}
34-
isAutocommitEnabled={isAutocommitEnabled}
35-
isAutocommitPolling={isAutocommitPolling}
36-
isConnectPermitted={isConnectPermitted}
33+
isAutocommitEnabled={autocommitEnabled}
34+
isAutocommitPolling={autocommitPolling}
35+
isConnectPermitted={connectPermitted}
3736
isDiscardLoading={discardLoading}
3837
isFetchStatusLoading={fetchStatusLoading}
39-
isGitConnected={isGitConnected}
40-
isProtectedMode={isProtectedMode}
38+
isGitConnected={gitConnected}
39+
isProtectedMode={protectedMode}
4140
isPullFailing={isPullFailing}
4241
isPullLoading={pullLoading}
4342
isStatusClean={isStatusClean}

app/client/src/git/components/GitContextProvider/hooks/useGitBranches.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,18 @@ export default function useGitBranches({
113113
};
114114

115115
return {
116-
branches: branchesState?.value ?? null,
116+
branches: branchesState?.value,
117117
fetchBranchesLoading: branchesState?.loading ?? false,
118-
fetchBranchesError: branchesState?.error ?? null,
118+
fetchBranchesError: branchesState?.error,
119119
fetchBranches,
120120
createBranchLoading: createBranchState?.loading ?? false,
121-
createBranchError: createBranchState?.error ?? null,
121+
createBranchError: createBranchState?.error,
122122
createBranch,
123123
deleteBranchLoading: deleteBranchState?.loading ?? false,
124-
deleteBranchError: deleteBranchState?.error ?? null,
124+
deleteBranchError: deleteBranchState?.error,
125125
deleteBranch,
126126
checkoutBranchLoading: checkoutBranchState?.loading ?? false,
127-
checkoutBranchError: checkoutBranchState?.error ?? null,
127+
checkoutBranchError: checkoutBranchState?.error,
128128
checkoutBranch,
129129
toggleGitBranchListPopup,
130130
};

app/client/src/git/components/GitContextProvider/hooks/useGitContextValue.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ import useGitOps from "./useGitOps";
88
import useGitBranches from "./useGitBranches";
99
import useGitSettings from "./useGitSettings";
1010
import { useMemo } from "react";
11+
import type { UseGitMetadataReturnValue } from "./useGitMetadata";
12+
import useGitMetadata from "./useGitMetadata";
1113

1214
interface UseGitContextValueParams {
1315
artifactType: keyof typeof GitArtifactType;
1416
baseArtifactId: string;
1517
}
1618

1719
export interface GitContextValue
18-
extends UseGitConnectReturnValue,
20+
extends UseGitMetadataReturnValue,
21+
UseGitConnectReturnValue,
1922
UseGitOpsReturnValue,
2023
UseGitSettingsReturnValue,
2124
UseGitBranchesReturnValue {}
@@ -28,12 +31,14 @@ export default function useGitContextValue({
2831
() => ({ artifactType, baseArtifactId }),
2932
[artifactType, baseArtifactId],
3033
);
34+
const useGitMetadataReturnValue = useGitMetadata(basePayload);
3135
const useGitConnectReturnValue = useGitConnect(basePayload);
3236
const useGitOpsReturnValue = useGitOps(basePayload);
3337
const useGitBranchesReturnValue = useGitBranches(basePayload);
3438
const useGitSettingsReturnValue = useGitSettings(basePayload);
3539

3640
return {
41+
...useGitMetadataReturnValue,
3742
...useGitOpsReturnValue,
3843
...useGitBranchesReturnValue,
3944
...useGitConnectReturnValue,
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import type { GitArtifactType } from "git/constants/enums";
2+
import type { FetchGitMetadataResponseData } from "git/requests/fetchGitMetadataRequest.types";
3+
import {
4+
selectGitConnected,
5+
selectGitMetadata,
6+
} from "git/store/selectors/gitSingleArtifactSelectors";
7+
import type { GitRootState } from "git/store/types";
8+
import { useMemo } from "react";
9+
import { useSelector } from "react-redux";
10+
11+
interface UseGitMetadataParams {
12+
artifactType: keyof typeof GitArtifactType;
13+
baseArtifactId: string;
14+
}
15+
16+
export interface UseGitMetadataReturnValue {
17+
gitMetadata: FetchGitMetadataResponseData | null;
18+
fetchGitMetadataLoading: boolean;
19+
fetchGitMetadataError: string | null;
20+
gitConnected: boolean;
21+
}
22+
23+
export default function useGitMetadata({
24+
artifactType,
25+
baseArtifactId,
26+
}: UseGitMetadataParams): UseGitMetadataReturnValue {
27+
const basePayload = useMemo(
28+
() => ({ artifactType, baseArtifactId }),
29+
[artifactType, baseArtifactId],
30+
);
31+
32+
const gitMetadataState = useSelector((state: GitRootState) =>
33+
selectGitMetadata(state, basePayload),
34+
);
35+
const gitConnected = useSelector((state: GitRootState) =>
36+
selectGitConnected(state, basePayload),
37+
);
38+
39+
return {
40+
gitMetadata: gitMetadataState.value,
41+
fetchGitMetadataLoading: gitMetadataState.loading ?? false,
42+
fetchGitMetadataError: gitMetadataState.error,
43+
gitConnected: gitConnected ?? false,
44+
};
45+
}

app/client/src/git/components/GitContextProvider/hooks/useGitOps.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,24 +133,24 @@ export default function useGitOps({
133133

134134
return {
135135
commitLoading: commitState?.loading ?? false,
136-
commitError: commitState?.error ?? null,
136+
commitError: commitState?.error,
137137
commit,
138138
discardLoading: discardState?.loading ?? false,
139-
discardError: discardState?.error ?? null,
139+
discardError: discardState?.error,
140140
discard,
141-
status: statusState?.value ?? null,
141+
status: statusState?.value,
142142
fetchStatusLoading: statusState?.loading ?? false,
143-
fetchStatusError: statusState?.error ?? null,
143+
fetchStatusError: statusState?.error,
144144
fetchStatus,
145145
mergeLoading: mergeState?.loading ?? false,
146-
mergeError: mergeState?.error ?? null,
146+
mergeError: mergeState?.error,
147147
merge,
148-
mergeStatus: mergeStatusState?.value ?? null,
148+
mergeStatus: mergeStatusState?.value,
149149
fetchMergeStatusLoading: mergeStatusState?.loading ?? false,
150-
fetchMergeStatusError: mergeStatusState?.error ?? null,
150+
fetchMergeStatusError: mergeStatusState?.error,
151151
fetchMergeStatus,
152152
pullLoading: pullState?.loading ?? false,
153-
pullError: pullState?.error ?? null,
153+
pullError: pullState?.error,
154154
pull,
155155
toggleGitOpsModal,
156156
};

app/client/src/git/components/GitContextProvider/hooks/useGitSettings.ts

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
import type { GitArtifactType, GitSettingsTab } from "git/constants/enums";
2+
import type { FetchProtectedBranchesResponseData } from "git/requests/fetchProtectedBranchesRequest.types";
23
import { gitArtifactActions } from "git/store/gitArtifactSlice";
4+
import {
5+
selectAutocommitEnabled,
6+
selectAutocommitPolling,
7+
selectProtectedBranches,
8+
selectProtectedMode,
9+
} from "git/store/selectors/gitSingleArtifactSelectors";
10+
import type { GitRootState } from "git/store/types";
311
import { useMemo } from "react";
4-
import { useDispatch } from "react-redux";
12+
import { useDispatch, useSelector } from "react-redux";
513

614
interface UseGitSettingsParams {
715
artifactType: keyof typeof GitArtifactType;
816
baseArtifactId: string;
917
}
1018

1119
export interface UseGitSettingsReturnValue {
20+
autocommitEnabled: boolean;
21+
autocommitPolling: boolean;
22+
protectedBranches: FetchProtectedBranchesResponseData | null;
23+
fetchProtectedBranchesLoading: boolean;
24+
fetchProtectedBranchesError: string | null;
25+
fetchProtectedBranches: () => void;
26+
protectedMode: boolean;
1227
toggleGitSettingsModal: (
1328
open: boolean,
1429
tab: keyof typeof GitSettingsTab,
@@ -25,6 +40,33 @@ export default function useGitSettings({
2540
[artifactType, baseArtifactId],
2641
);
2742

43+
// autocommit
44+
const autocommitEnabled = useSelector((state: GitRootState) =>
45+
selectAutocommitEnabled(state, basePayload),
46+
);
47+
48+
const autocommitPolling = useSelector((state: GitRootState) =>
49+
selectAutocommitPolling(state, basePayload),
50+
);
51+
52+
// branch protection
53+
const protectedBranchesState = useSelector((state: GitRootState) =>
54+
selectProtectedBranches(state, basePayload),
55+
);
56+
57+
const fetchProtectedBranches = () => {
58+
dispatch(
59+
gitArtifactActions.fetchProtectedBranchesInit({
60+
...basePayload,
61+
}),
62+
);
63+
};
64+
65+
const protectedMode = useSelector((state: GitRootState) =>
66+
selectProtectedMode(state, basePayload),
67+
);
68+
69+
// ui
2870
const toggleGitSettingsModal = (
2971
open: boolean,
3072
tab: keyof typeof GitSettingsTab,
@@ -39,6 +81,13 @@ export default function useGitSettings({
3981
};
4082

4183
return {
84+
autocommitEnabled: autocommitEnabled ?? false,
85+
autocommitPolling: autocommitPolling ?? false,
86+
protectedBranches: protectedBranchesState.value,
87+
fetchProtectedBranchesLoading: protectedBranchesState.loading ?? false,
88+
fetchProtectedBranchesError: protectedBranchesState.error,
89+
fetchProtectedBranches,
90+
protectedMode: protectedMode ?? false,
4291
toggleGitSettingsModal,
4392
};
4493
}

app/client/src/git/components/GitContextProvider/index.tsx

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { createContext, useContext, useEffect } from "react";
1+
import React, { createContext, useContext } from "react";
22
import type { GitArtifactType } from "git/constants/enums";
33
import type { GitContextValue } from "./hooks/useGitContextValue";
44
import useGitContextValue from "./hooks/useGitContextValue";
@@ -15,24 +15,18 @@ interface GitContextProviderProps {
1515
artifactType: keyof typeof GitArtifactType;
1616
baseArtifactId: string;
1717
children: React.ReactNode;
18+
// extra
19+
// connectPermitted?: boolean;
1820
}
1921

2022
export default function GitContextProvider({
2123
artifactType,
2224
baseArtifactId,
2325
children,
26+
// connectPermitted = true,
2427
}: GitContextProviderProps) {
2528
const contextValue = useGitContextValue({ artifactType, baseArtifactId });
2629

27-
const { fetchBranches } = contextValue;
28-
29-
useEffect(
30-
function gitInitEffect() {
31-
fetchBranches();
32-
},
33-
[fetchBranches],
34-
);
35-
3630
return (
3731
<GitContext.Provider value={contextValue}>{children}</GitContext.Provider>
3832
);

app/client/src/git/components/GitQuickActions/QuickActionButton.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ describe("QuickActionButton", () => {
5050
<QuickActionButton {...defaultProps} />
5151
</ThemeProvider>,
5252
);
53-
const btn = container.getElementsByClassName("t--test-btn")[0];
53+
const btn = container.querySelectorAll(".t--test-btn button")[0];
5454

5555
fireEvent.click(btn);
5656
expect(defaultProps.onClick).toHaveBeenCalledTimes(1);

app/client/src/git/components/GitQuickActions/QuickActionButton.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ const SpinnerContainer = styled.div`
1919
padding: 0 10px;
2020
`;
2121

22-
const QuickActionButtonContainer = styled.button<{ disabled?: boolean }>`
22+
const QuickActionButtonContainer = styled.div<{ disabled?: boolean }>`
2323
margin: 0 ${(props) => props.theme.spaces[1]}px;
2424
display: block;
2525
position: relative;
2626
overflow: visible;
27-
cursor: ${({ disabled = false }) => (disabled ? "not-allowed" : "pointer")};
2827
opacity: ${({ disabled = false }) => (disabled ? 0.6 : 1)};
2928
`;
3029

@@ -57,11 +56,7 @@ function QuickActionButton({
5756
const content = capitalizeFirstLetter(tooltipText);
5857

5958
return (
60-
<QuickActionButtonContainer
61-
className={className}
62-
disabled={disabled}
63-
onClick={onClick}
64-
>
59+
<QuickActionButtonContainer className={className} disabled={disabled}>
6560
{loading ? (
6661
<SpinnerContainer className="t--loader-quick-git-action">
6762
<SpinnerLoader size="md" />
@@ -73,6 +68,7 @@ function QuickActionButton({
7368
isDisabled={disabled}
7469
isIconButton
7570
kind="tertiary"
71+
onClick={onClick}
7672
size="md"
7773
startIcon={icon}
7874
/>

0 commit comments

Comments
 (0)