191 lines
5.1 KiB
TypeScript
191 lines
5.1 KiB
TypeScript
import { createReducer } from "utils/AppsmithUtils";
|
|
import {
|
|
ReduxAction,
|
|
ReduxActionErrorTypes,
|
|
ReduxActionTypes,
|
|
} from "constants/ReduxActionConstants";
|
|
import { GitSyncModalTab, GitConfig } from "entities/GitSync";
|
|
|
|
const initialState: GitSyncReducerState = {
|
|
isGitSyncModalOpen: false,
|
|
isCommitting: false,
|
|
isPushingToGit: false,
|
|
isCommitSuccessful: false,
|
|
isPushSuccessful: false,
|
|
activeGitSyncModalTab: GitSyncModalTab.GIT_CONNECTION,
|
|
isErrorPopupVisible: false,
|
|
gitError: `
|
|
README.md app/client/cypress/support/commands.js
|
|
app/client/src/comments/CommentsShowcaseCarousel/CommentsCarouselModal.tsx
|
|
`,
|
|
isImportAppViaGitModalOpen: false,
|
|
globalGitConfig: { authorEmail: "", authorName: "" },
|
|
localGitConfig: { authorEmail: "", authorName: "" },
|
|
};
|
|
|
|
const gitSyncReducer = createReducer(initialState, {
|
|
[ReduxActionTypes.SET_IS_GIT_SYNC_MODAL_OPEN]: (
|
|
state: GitSyncReducerState,
|
|
action: ReduxAction<{
|
|
isOpen: boolean;
|
|
tab: GitSyncModalTab;
|
|
}>,
|
|
) => {
|
|
const activeGitSyncModalTab = action.payload.tab;
|
|
|
|
return {
|
|
...state,
|
|
isGitSyncModalOpen: action.payload.isOpen,
|
|
activeGitSyncModalTab,
|
|
};
|
|
},
|
|
[ReduxActionTypes.COMMIT_TO_GIT_REPO_INIT]: (state: GitSyncReducerState) => ({
|
|
...state,
|
|
isCommitting: true,
|
|
isCommitSuccessful: false,
|
|
}),
|
|
[ReduxActionTypes.COMMIT_TO_GIT_REPO_SUCCESS]: (
|
|
state: GitSyncReducerState,
|
|
) => ({
|
|
...state,
|
|
isCommitting: false,
|
|
isCommitSuccessful: true,
|
|
}),
|
|
[ReduxActionErrorTypes.COMMIT_TO_GIT_REPO_ERROR]: (
|
|
state: GitSyncReducerState,
|
|
) => ({
|
|
...state,
|
|
isCommitting: false,
|
|
}),
|
|
[ReduxActionTypes.PUSH_TO_GIT_INIT]: (state: GitSyncReducerState) => ({
|
|
...state,
|
|
isPushingToGit: true,
|
|
isPushSuccessful: false,
|
|
}),
|
|
[ReduxActionTypes.PUSH_TO_GIT_SUCCESS]: (state: GitSyncReducerState) => ({
|
|
...state,
|
|
isPushingToGit: false,
|
|
isPushSuccessful: true,
|
|
}),
|
|
[ReduxActionErrorTypes.PUSH_TO_GIT_ERROR]: (state: GitSyncReducerState) => ({
|
|
...state,
|
|
isPushingToGit: false,
|
|
}),
|
|
[ReduxActionTypes.SHOW_ERROR_POPUP]: (
|
|
state: GitSyncReducerState,
|
|
action: ReduxAction<{ isVisible: boolean }>,
|
|
) => ({
|
|
...state,
|
|
isErrorPopupVisible: action.payload.isVisible,
|
|
}),
|
|
[ReduxActionTypes.SET_IS_IMPORT_APP_VIA_GIT_MODAL_OPEN]: (
|
|
state: GitSyncReducerState,
|
|
action: ReduxAction<{ isOpen: boolean; organizationId: string }>,
|
|
) => ({
|
|
...state,
|
|
isImportAppViaGitModalOpen: action.payload.isOpen,
|
|
organisationIdForImport: action.payload.organizationId,
|
|
}),
|
|
[ReduxActionTypes.FETCH_GLOBAL_GIT_CONFIG_INIT]: (
|
|
state: GitSyncReducerState,
|
|
) => ({
|
|
...state,
|
|
isFetchingGitConfig: true,
|
|
}),
|
|
[ReduxActionTypes.UPDATE_GLOBAL_GIT_CONFIG_INIT]: (
|
|
state: GitSyncReducerState,
|
|
) => ({
|
|
...state,
|
|
isFetchingGitConfig: true,
|
|
}),
|
|
[ReduxActionTypes.FETCH_GLOBAL_GIT_CONFIG_SUCCESS]: (
|
|
state: GitSyncReducerState,
|
|
action: ReduxAction<GitConfig>,
|
|
) => ({
|
|
...state,
|
|
globalGitConfig: action.payload,
|
|
isFetchingGitConfig: false,
|
|
}),
|
|
[ReduxActionTypes.UPDATE_GLOBAL_GIT_CONFIG_SUCCESS]: (
|
|
state: GitSyncReducerState,
|
|
action: ReduxAction<GitConfig>,
|
|
) => ({
|
|
...state,
|
|
globalGitConfig: action.payload,
|
|
isFetchingGitConfig: false,
|
|
}),
|
|
[ReduxActionErrorTypes.UPDATE_GLOBAL_GIT_CONFIG_ERROR]: (
|
|
state: GitSyncReducerState,
|
|
) => ({
|
|
...state,
|
|
isFetchingGitConfig: false,
|
|
}),
|
|
[ReduxActionErrorTypes.FETCH_GLOBAL_GIT_CONFIG_ERROR]: (
|
|
state: GitSyncReducerState,
|
|
) => ({
|
|
...state,
|
|
isFetchingGitConfig: false,
|
|
}),
|
|
|
|
[ReduxActionTypes.FETCH_LOCAL_GIT_CONFIG_INIT]: (
|
|
state: GitSyncReducerState,
|
|
) => ({
|
|
...state,
|
|
isFetchingLocalGitConfig: true,
|
|
}),
|
|
[ReduxActionTypes.UPDATE_LOCAL_GIT_CONFIG_INIT]: (
|
|
state: GitSyncReducerState,
|
|
) => ({
|
|
...state,
|
|
isFetchingLocalGitConfig: true,
|
|
}),
|
|
[ReduxActionTypes.FETCH_LOCAL_GIT_CONFIG_SUCCESS]: (
|
|
state: GitSyncReducerState,
|
|
action: ReduxAction<GitConfig>,
|
|
) => ({
|
|
...state,
|
|
localGitConfig: action.payload,
|
|
isFetchingLocalGitConfig: false,
|
|
}),
|
|
[ReduxActionTypes.UPDATE_LOCAL_GIT_CONFIG_SUCCESS]: (
|
|
state: GitSyncReducerState,
|
|
action: ReduxAction<GitConfig>,
|
|
) => ({
|
|
...state,
|
|
localGitConfig: action.payload,
|
|
isFetchingLocalGitConfig: false,
|
|
}),
|
|
[ReduxActionErrorTypes.UPDATE_LOCAL_GIT_CONFIG_ERROR]: (
|
|
state: GitSyncReducerState,
|
|
) => ({
|
|
...state,
|
|
isFetchingLocalGitConfig: false,
|
|
}),
|
|
[ReduxActionErrorTypes.FETCH_LOCAL_GIT_CONFIG_ERROR]: (
|
|
state: GitSyncReducerState,
|
|
) => ({
|
|
...state,
|
|
isFetchingLocalGitConfig: false,
|
|
}),
|
|
});
|
|
|
|
export type GitSyncReducerState = {
|
|
isGitSyncModalOpen?: boolean;
|
|
isCommitting?: boolean;
|
|
isCommitSuccessful: boolean;
|
|
isPushSuccessful: boolean;
|
|
isPushingToGit?: boolean;
|
|
activeGitSyncModalTab: GitSyncModalTab;
|
|
isImportAppViaGitModalOpen: boolean;
|
|
organizationIdForImport?: string;
|
|
isErrorPopupVisible?: boolean;
|
|
gitError?: string;
|
|
globalGitConfig: GitConfig;
|
|
isFetchingGitConfig?: boolean;
|
|
|
|
isFetchingLocalGitConfig?: boolean;
|
|
localGitConfig: GitConfig;
|
|
};
|
|
|
|
export default gitSyncReducer;
|