diff --git a/app/client/packages/design-system/ads/src/Icon/Icon.provider.tsx b/app/client/packages/design-system/ads/src/Icon/Icon.provider.tsx index 611ccff4f2a4..d12bc1f519d5 100644 --- a/app/client/packages/design-system/ads/src/Icon/Icon.provider.tsx +++ b/app/client/packages/design-system/ads/src/Icon/Icon.provider.tsx @@ -1103,10 +1103,6 @@ const ContentTypeRaw = importSvg( async () => import("../__assets__/icons/ads/content-type-raw.svg"), ); -const CloudIconV2 = importSvg( - async () => import("../__assets__/icons/ads/cloudy-line.svg"), -); - const NotionIcon = importSvg( async () => import("../__assets__/icons/ads/notion.svg"), ); @@ -1229,7 +1225,6 @@ const ICON_LOOKUP = { "close-modal": CloseLineIcon, "close-x": CloseLineIcon, "cloud-off-line": CloudOfflineIcon, - "cloud-v2": CloudIconV2, "collapse-control": CollapseIcon, "column-freeze": ColumnFreeze, "column-unfreeze": SubtractIcon, diff --git a/app/client/src/api/interceptors/request/apiRequestInterceptor.ts b/app/client/src/api/interceptors/request/apiRequestInterceptor.ts index 4a9d2ed633cc..5371cbbcf23c 100644 --- a/app/client/src/api/interceptors/request/apiRequestInterceptor.ts +++ b/app/client/src/api/interceptors/request/apiRequestInterceptor.ts @@ -30,7 +30,6 @@ 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 const branch = getCurrentGitBranch(state) || getQueryParamsObject().branch; return _addGitBranchHeader(config, { branch }); diff --git a/app/client/src/ce/entities/FeatureFlag.ts b/app/client/src/ce/entities/FeatureFlag.ts index 4e3020fd98e2..d3048a86f9f1 100644 --- a/app/client/src/ce/entities/FeatureFlag.ts +++ b/app/client/src/ce/entities/FeatureFlag.ts @@ -48,7 +48,6 @@ export const FEATURE_FLAG = { "release_table_html_column_type_enabled", release_gs_all_sheets_options_enabled: "release_gs_all_sheets_options_enabled", - release_git_modularisation_enabled: "release_git_modularisation_enabled", ab_premium_datasources_view_enabled: "ab_premium_datasources_view_enabled", kill_session_recordings_enabled: "kill_session_recordings_enabled", config_mask_session_recordings_enabled: @@ -96,7 +95,6 @@ export const DEFAULT_FEATURE_FLAG_VALUE: FeatureFlags = { release_evaluation_scope_cache: false, release_table_html_column_type_enabled: false, release_gs_all_sheets_options_enabled: false, - release_git_modularisation_enabled: false, ab_premium_datasources_view_enabled: false, kill_session_recordings_enabled: false, config_user_session_recordings_enabled: true, diff --git a/app/client/src/ce/navigation/FocusStrategy/AppIDEFocusStrategy.ts b/app/client/src/ce/navigation/FocusStrategy/AppIDEFocusStrategy.ts index fe5440f22f27..5729a7e8c59d 100644 --- a/app/client/src/ce/navigation/FocusStrategy/AppIDEFocusStrategy.ts +++ b/app/client/src/ce/navigation/FocusStrategy/AppIDEFocusStrategy.ts @@ -2,6 +2,7 @@ import { all, select, take } from "redux-saga/effects"; import type { FocusPath, FocusStrategy } from "sagas/FocusRetentionSaga"; import type { AppsmithLocationState } from "utils/history"; import { NavigationMethod } from "utils/history"; +import { getCurrentGitBranch } from "selectors/gitSyncSelectors"; import type { FocusEntityInfo } from "navigation/FocusEntity"; import { FocusEntity, @@ -17,7 +18,6 @@ import { widgetListURL, } from "ee/RouteBuilder"; import AppIDEFocusElements from "../FocusElements/AppIDE"; -import { selectGitApplicationCurrentBranch } from "selectors/gitModSelectors"; function shouldSetState( prevPath: string, @@ -86,17 +86,8 @@ const isPageChange = (prevPath: string, currentPath: string) => { ); }; -export const createEditorFocusInfoKey = ( - basePageId: string, - branch: string | null = null, -) => { - const r = branch - ? `EDITOR_STATE.${basePageId}#${branch}` - : `EDITOR_STATE.${basePageId}`; - - return r; -}; - +export const createEditorFocusInfoKey = (basePageId: string, branch?: string) => + `EDITOR_STATE.${basePageId}#${branch}`; export const createEditorFocusInfo = (basePageId: string, branch?: string) => ({ key: createEditorFocusInfoKey(basePageId, branch), entityInfo: { @@ -118,9 +109,7 @@ export const AppIDEFocusStrategy: FocusStrategy = { return []; } - const branch: string | undefined = yield select( - selectGitApplicationCurrentBranch, - ); + const branch: string | undefined = yield select(getCurrentGitBranch); const entities: Array<{ entityInfo: FocusEntityInfo; key: string }> = []; const prevEntityInfo = identifyEntityFromPath(previousPath); const currentEntityInfo = identifyEntityFromPath(currentPath); @@ -147,9 +136,7 @@ export const AppIDEFocusStrategy: FocusStrategy = { return entities; }, *getEntitiesForStore(path: string, currentPath: string) { - const branch: string | undefined = yield select( - selectGitApplicationCurrentBranch, - ); + const branch: string | undefined = yield select(getCurrentGitBranch); const entities: Array = []; const currentFocusEntityInfo = identifyEntityFromPath(currentPath); const prevFocusEntityInfo = identifyEntityFromPath(path); @@ -192,9 +179,7 @@ export const AppIDEFocusStrategy: FocusStrategy = { appState: EditorState.EDITOR, params: prevFocusEntityInfo.params, }, - key: branch - ? `EDITOR_STATE.${prevFocusEntityInfo.params.basePageId}#${branch}` - : `EDITOR_STATE.${prevFocusEntityInfo.params.basePageId}`, + key: `EDITOR_STATE.${prevFocusEntityInfo.params.basePageId}#${branch}`, }); } diff --git a/app/client/src/ce/pages/Applications/CreateNewAppsOption.test.tsx b/app/client/src/ce/pages/Applications/CreateNewAppsOption.test.tsx index 06940dc36fcc..180268afb6a9 100644 --- a/app/client/src/ce/pages/Applications/CreateNewAppsOption.test.tsx +++ b/app/client/src/ce/pages/Applications/CreateNewAppsOption.test.tsx @@ -9,10 +9,6 @@ import CreateNewAppsOption from "./CreateNewAppsOption"; import { BrowserRouter as Router } from "react-router-dom"; import { unitTestBaseMockStore } from "layoutSystems/common/dropTarget/unitTestUtils"; -jest.mock("selectors/gitModSelectors", () => ({ - selectCombinedPreviewMode: jest.fn(() => false), -})); - const defaultStoreState = { ...unitTestBaseMockStore, tenant: { diff --git a/app/client/src/ce/pages/Applications/index.tsx b/app/client/src/ce/pages/Applications/index.tsx index 19b45abd74e1..edd2b60af280 100644 --- a/app/client/src/ce/pages/Applications/index.tsx +++ b/app/client/src/ce/pages/Applications/index.tsx @@ -122,6 +122,7 @@ import { MOBILE_MAX_WIDTH } from "constants/AppConstants"; import { Indices } from "constants/Layers"; import ImportModal from "pages/common/ImportModal"; import SharedUserList from "pages/common/SharedUserList"; +import GitSyncModal from "pages/Editor/gitSync/GitSyncModal"; import ReconnectDatasourceModal from "pages/Editor/gitSync/ReconnectDatasourceModal"; import RepoLimitExceededErrorModal from "pages/Editor/gitSync/RepoLimitExceededErrorModal"; import AnalyticsUtil from "ee/utils/AnalyticsUtil"; @@ -132,15 +133,6 @@ import { getAssetUrl } from "ee/utils/airgapHelpers"; import { ASSETS_CDN_URL } from "constants/ThirdPartyConstants"; import { LayoutSystemTypes } from "layoutSystems/types"; import { getIsAnvilLayoutEnabled } from "layoutSystems/anvil/integrations/selectors"; -import OldGitSyncModal from "pages/Editor/gitSync/GitSyncModal"; -import { useGitModEnabled } from "pages/Editor/gitSync/hooks/modHooks"; -import { GitImportModal as NewGitImportModal } from "git"; - -function GitImportModal() { - const isGitModEnabled = useGitModEnabled(); - - return isGitModEnabled ? : ; -} export const { cloudHosting } = getAppsmithConfigs(); @@ -963,7 +955,7 @@ export function ApplicationsSection(props: any) { isMobile={isMobile} > {workspacesListComponent} - + ); diff --git a/app/client/src/ce/pages/Editor/IDE/MainPane/useRoutes.tsx b/app/client/src/ce/pages/Editor/IDE/MainPane/useRoutes.tsx index 8f16afc63327..cac3ae6f84a8 100644 --- a/app/client/src/ce/pages/Editor/IDE/MainPane/useRoutes.tsx +++ b/app/client/src/ce/pages/Editor/IDE/MainPane/useRoutes.tsx @@ -34,12 +34,12 @@ import DataSourceEditor from "pages/Editor/DataSourceEditor"; import DatasourceBlankState from "pages/Editor/DataSourceEditor/DatasourceBlankState"; import type { RouteProps } from "react-router"; import { useSelector } from "react-redux"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { lazy, Suspense } from "react"; import React from "react"; import { retryPromise } from "utils/AppsmithUtils"; import Skeleton from "widgets/Skeleton"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; const FirstTimeUserOnboardingChecklist = lazy(async () => retryPromise( @@ -67,7 +67,7 @@ export interface RouteReturnType extends RouteProps { */ function useRoutes(path: string): RouteReturnType[] { - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); return [ { diff --git a/app/client/src/ce/reducers/index.tsx b/app/client/src/ce/reducers/index.tsx index 73842c65b5df..f6bb8801940e 100644 --- a/app/client/src/ce/reducers/index.tsx +++ b/app/client/src/ce/reducers/index.tsx @@ -77,8 +77,6 @@ import type { ActiveField } from "reducers/uiReducers/activeFieldEditorReducer"; import type { SelectedWorkspaceReduxState } from "ee/reducers/uiReducers/selectedWorkspaceReducer"; import type { ConsolidatedPageLoadState } from "reducers/uiReducers/consolidatedPageLoadReducer"; import type { BuildingBlocksReduxState } from "reducers/uiReducers/buildingBlockReducer"; -import type { GitArtifactRootReduxState, GitGlobalReduxState } from "git"; -import { gitReducer } from "git/store"; export const reducerObject = { entities: entityReducer, @@ -88,7 +86,6 @@ export const reducerObject = { settings: SettingsReducer, tenant: tenantReducer, linting: lintErrorReducer, - git: gitReducer, }; export interface AppState { @@ -179,8 +176,4 @@ export interface AppState { // TODO: Fix this the next time the file is edited // eslint-disable-next-line @typescript-eslint/no-explicit-any tenant: TenantReduxState; - git: { - global: GitGlobalReduxState; - artifacts: GitArtifactRootReduxState; - }; } diff --git a/app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx b/app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx index 97830da22ff3..dd2f5b5c4060 100644 --- a/app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx +++ b/app/client/src/ce/reducers/uiReducers/applicationsReducer.tsx @@ -25,8 +25,6 @@ import { import produce from "immer"; import { isEmpty } from "lodash"; import type { ApplicationPayload } from "entities/Application"; -import { gitConnectSuccess, type GitConnectSuccessPayload } from "git"; -import type { PayloadAction } from "@reduxjs/toolkit"; export const initialState: ApplicationsReduxState = { isSavingAppName: false, @@ -746,20 +744,6 @@ export const handlers = { isSavingNavigationSetting: false, }; }, - // git - [gitConnectSuccess.type]: ( - state: ApplicationsReduxState, - action: PayloadAction, - ) => { - return { - ...state, - currentApplication: { - ...state.currentApplication, - gitApplicationMetadata: - action.payload.responseData.gitApplicationMetadata, - }, - }; - }, }; const applicationsReducer = createReducer(initialState, handlers); diff --git a/app/client/src/ce/sagas/PageSagas.tsx b/app/client/src/ce/sagas/PageSagas.tsx index aad81e9f8720..d1c8e1e86837 100644 --- a/app/client/src/ce/sagas/PageSagas.tsx +++ b/app/client/src/ce/sagas/PageSagas.tsx @@ -75,6 +75,7 @@ import { import { IncorrectBindingError, validateResponse } from "sagas/ErrorSagas"; import type { ApiResponse } from "api/ApiResponses"; import { + combinedPreviewModeSelector, getCurrentApplicationId, getCurrentLayoutId, getCurrentPageId, @@ -127,6 +128,7 @@ import { getPageList } from "ee/selectors/entitiesSelector"; import { setPreviewModeAction } from "actions/editorActions"; import { SelectionRequestType } from "sagas/WidgetSelectUtils"; import { toast } from "@appsmith/ads"; +import { getCurrentGitBranch } from "selectors/gitSyncSelectors"; import type { MainCanvasReduxState } from "reducers/uiReducers/mainCanvasReducer"; import { UserCancelledActionExecutionError } from "sagas/ActionExecution/errorUtils"; import { getInstanceId } from "ee/selectors/tenantSelectors"; @@ -148,10 +150,6 @@ import { getIsAnvilLayout } from "layoutSystems/anvil/integrations/selectors"; import { convertToBasePageIdSelector } from "selectors/pageListSelectors"; import type { Page } from "entities/Page"; import { ConsolidatedPageLoadApi } from "api"; -import { - selectCombinedPreviewMode, - selectGitApplicationCurrentBranch, -} from "selectors/gitModSelectors"; export const checkIfMigrationIsNeeded = ( fetchPageResponse?: FetchPageResponse, @@ -174,9 +172,7 @@ export function* refreshTheApp() { const currentPageId: string = yield select(getCurrentPageId); const defaultBasePageId: string = yield select(getDefaultBasePageId); const pagesList: Page[] = yield select(getPageList); - const gitBranch: string | undefined = yield select( - selectGitApplicationCurrentBranch, - ); + const gitBranch: string = yield select(getCurrentGitBranch); const isCurrentPageIdInList = pagesList.filter((page) => page.pageId === currentPageId).length > 0; @@ -641,7 +637,7 @@ export function* saveLayoutSaga(action: ReduxAction<{ isRetry?: boolean }>) { try { const currentPageId: string = yield select(getCurrentPageId); const currentPage: Page = yield select(getPageById(currentPageId)); - const isPreviewMode: boolean = yield select(selectCombinedPreviewMode); + const isPreviewMode: boolean = yield select(combinedPreviewModeSelector); const appMode: APP_MODE | undefined = yield select(getAppMode); @@ -1405,7 +1401,7 @@ export function* setCanvasCardsStateSaga(action: ReduxAction) { } export function* setPreviewModeInitSaga(action: ReduxAction) { - const isPreviewMode: boolean = yield select(selectCombinedPreviewMode); + const isPreviewMode: boolean = yield select(combinedPreviewModeSelector); if (action.payload) { // we animate out elements and then move to the canvas diff --git a/app/client/src/ce/sagas/index.tsx b/app/client/src/ce/sagas/index.tsx index af60e7dc4b93..844f9406af82 100644 --- a/app/client/src/ce/sagas/index.tsx +++ b/app/client/src/ce/sagas/index.tsx @@ -52,7 +52,6 @@ import sendSideBySideWidgetHoverAnalyticsEventSaga from "sagas/AnalyticsSaga"; /* Sagas that are registered by a module that is designed to be independent of the core platform */ import ternSagas from "sagas/TernSaga"; -import gitSagas from "git/sagas"; export const sagas = [ initSagas, @@ -107,5 +106,4 @@ export const sagas = [ ternSagas, ideSagas, sendSideBySideWidgetHoverAnalyticsEventSaga, - gitSagas, ]; diff --git a/app/client/src/ce/selectors/entitiesSelector.ts b/app/client/src/ce/selectors/entitiesSelector.ts index 57daa5964caf..a020e93ad13a 100644 --- a/app/client/src/ce/selectors/entitiesSelector.ts +++ b/app/client/src/ce/selectors/entitiesSelector.ts @@ -51,7 +51,7 @@ import { getEntityNameAndPropertyPath } from "ee/workers/Evaluation/evaluationUt import { getFormValues } from "redux-form"; import { TEMP_DATASOURCE_ID } from "constants/Datasource"; import type { Module } from "ee/constants/ModuleConstants"; -// import { getAnvilSpaceDistributionStatus } from "layoutSystems/anvil/integrations/selectors"; +import { getAnvilSpaceDistributionStatus } from "layoutSystems/anvil/integrations/selectors"; import { getCurrentWorkflowActions, getCurrentWorkflowJSActions, @@ -159,48 +159,47 @@ export const getDatasourceStructureById = ( return state.entities.datasources.structure[id]; }; -// ! git mod - the following function is not getting used /** * Selector to indicate if the widget name should be shown/drawn on canvas */ -// export const getShouldShowWidgetName = createSelector( -// (state: AppState) => state.ui.widgetDragResize.isResizing, -// (state: AppState) => state.ui.widgetDragResize.isDragging, -// (state: AppState) => state.ui.editor.isPreviewMode, -// (state: AppState) => state.ui.widgetDragResize.isAutoCanvasResizing, -// getAnvilSpaceDistributionStatus, -// // cannot import other selectors, breaks the app -// (state) => { -// const gitMetaData = -// state.ui.applications.currentApplication?.gitApplicationMetadata; -// const isGitConnected = !!(gitMetaData && gitMetaData?.remoteUrl); -// const currentBranch = gitMetaData?.branchName; -// const { protectedBranches = [] } = state.ui.gitSync; - -// if (!isGitConnected || !currentBranch) { -// return false; -// } else { -// return protectedBranches.includes(currentBranch); -// } -// }, -// ( -// isResizing, -// isDragging, -// isPreviewMode, -// isAutoCanvasResizing, -// isDistributingSpace, -// isProtectedMode, -// ) => { -// return ( -// !isResizing && -// !isDragging && -// !isPreviewMode && -// !isAutoCanvasResizing && -// !isDistributingSpace && -// !isProtectedMode -// ); -// }, -// ); +export const getShouldShowWidgetName = createSelector( + (state: AppState) => state.ui.widgetDragResize.isResizing, + (state: AppState) => state.ui.widgetDragResize.isDragging, + (state: AppState) => state.ui.editor.isPreviewMode, + (state: AppState) => state.ui.widgetDragResize.isAutoCanvasResizing, + getAnvilSpaceDistributionStatus, + // cannot import other selectors, breaks the app + (state) => { + const gitMetaData = + state.ui.applications.currentApplication?.gitApplicationMetadata; + const isGitConnected = !!(gitMetaData && gitMetaData?.remoteUrl); + const currentBranch = gitMetaData?.branchName; + const { protectedBranches = [] } = state.ui.gitSync; + + if (!isGitConnected || !currentBranch) { + return false; + } else { + return protectedBranches.includes(currentBranch); + } + }, + ( + isResizing, + isDragging, + isPreviewMode, + isAutoCanvasResizing, + isDistributingSpace, + isProtectedMode, + ) => { + return ( + !isResizing && + !isDragging && + !isPreviewMode && + !isAutoCanvasResizing && + !isDistributingSpace && + !isProtectedMode + ); + }, +); export const getDatasourceTableColumns = (datasourceId: string, tableName: string) => (state: AppState) => { diff --git a/app/client/src/components/BottomBar/index.tsx b/app/client/src/components/BottomBar/index.tsx index 1b7ad839d868..565844eacfb4 100644 --- a/app/client/src/components/BottomBar/index.tsx +++ b/app/client/src/components/BottomBar/index.tsx @@ -1,4 +1,5 @@ -import React, { useCallback } from "react"; +import React from "react"; +import QuickGitActions from "pages/Editor/gitSync/QuickGitActions"; import { DebuggerTrigger } from "components/editorComponents/Debugger"; import HelpButton from "pages/Editor/HelpButton"; import ManualUpgrades from "./ManualUpgrades"; @@ -15,30 +16,19 @@ import { softRefreshActions } from "actions/pluginActionActions"; import { START_SWITCH_ENVIRONMENT } from "ee/constants/messages"; import { getIsAnvilEnabledInCurrentApplication } from "layoutSystems/anvil/integrations/selectors"; import PackageUpgradeStatus from "ee/components/BottomBar/PackageUpgradeStatus"; -import OldGitQuickActions from "pages/Editor/gitSync/QuickGitActions"; -import { GitQuickActions } from "git"; -import { useGitModEnabled } from "pages/Editor/gitSync/hooks/modHooks"; - -function GitActions() { - const isGitModEnabled = useGitModEnabled(); - - return isGitModEnabled ? : ; -} export default function BottomBar() { const appId = useSelector(getCurrentApplicationId) || ""; + const isPreviewMode = useSelector(previewModeSelector); + const dispatch = useDispatch(); // We check if the current application is an Anvil application. // If it is an Anvil application, we remove the Git features from the bottomBar // as they donot yet work correctly with Anvil. const isAnvilEnabled = useSelector(getIsAnvilEnabledInCurrentApplication); - const isPreviewMode = useSelector(previewModeSelector); - const isGitEnabled = !isAnvilEnabled && !isPreviewMode; - - const dispatch = useDispatch(); - const onChangeEnv = useCallback(() => { + const onChangeEnv = () => { dispatch(softRefreshActions()); - }, [dispatch]); + }; return ( @@ -51,7 +41,7 @@ export default function BottomBar() { viewMode={isPreviewMode} /> )} - {isGitEnabled && } + {!isPreviewMode && !isAnvilEnabled && } {!isPreviewMode && ( diff --git a/app/client/src/components/designSystems/appsmith/header/DeployLinkButton.tsx b/app/client/src/components/designSystems/appsmith/header/DeployLinkButton.tsx index 91eea09ab4ab..3257d962223b 100644 --- a/app/client/src/components/designSystems/appsmith/header/DeployLinkButton.tsx +++ b/app/client/src/components/designSystems/appsmith/header/DeployLinkButton.tsx @@ -1,7 +1,8 @@ import type { ReactNode } from "react"; -import React, { useCallback } from "react"; +import React from "react"; import { Menu, MenuItem, MenuContent, MenuTrigger } from "@appsmith/ads"; import { useSelector, useDispatch } from "react-redux"; +import { getIsGitConnected } from "selectors/gitSyncSelectors"; import { setIsGitSyncModalOpen } from "actions/gitSyncActions"; import { GitSyncModalTab } from "entities/GitSync"; import AnalyticsUtil from "ee/utils/AnalyticsUtil"; @@ -13,41 +14,6 @@ import { Button } from "@appsmith/ads"; import { KBEditorMenuItem } from "ee/pages/Editor/KnowledgeBase/KBEditorMenuItem"; import { useHasConnectToGitPermission } from "pages/Editor/gitSync/hooks/gitPermissionHooks"; import { getIsAnvilEnabledInCurrentApplication } from "layoutSystems/anvil/integrations/selectors"; -import { - useGitConnected, - useGitModEnabled, -} from "pages/Editor/gitSync/hooks/modHooks"; -import { GitDeployMenuItems as GitDeployMenuItemsNew } from "git"; - -function GitDeployMenuItems() { - const isGitModEnabled = useGitModEnabled(); - - const dispatch = useDispatch(); - const goToGitConnectionPopup = useCallback(() => { - AnalyticsUtil.logEvent("GS_CONNECT_GIT_CLICK", { - source: "Deploy button", - }); - - dispatch( - setIsGitSyncModalOpen({ - isOpen: true, - tab: GitSyncModalTab.GIT_CONNECTION, - }), - ); - }, [dispatch]); - - return isGitModEnabled ? ( - - ) : ( - - {CONNECT_TO_GIT_OPTION()} - - ); -} interface Props { trigger: ReactNode; @@ -55,13 +21,26 @@ interface Props { } export const DeployLinkButton = (props: Props) => { - const isGitConnected = useGitConnected(); + const dispatch = useDispatch(); + const isGitConnected = useSelector(getIsGitConnected); const isConnectToGitPermitted = useHasConnectToGitPermission(); // We check if the current application is an Anvil application. // If it is an Anvil application, we remove the Git features from the deploy button // as they donot yet work correctly with Anvil. const isAnvilEnabled = useSelector(getIsAnvilEnabledInCurrentApplication); + const goToGitConnectionPopup = () => { + AnalyticsUtil.logEvent("GS_CONNECT_GIT_CLICK", { + source: "Deploy button", + }); + dispatch( + setIsGitSyncModalOpen({ + isOpen: true, + tab: GitSyncModalTab.GIT_CONNECTION, + }), + ); + }; + return ( @@ -75,7 +54,13 @@ export const DeployLinkButton = (props: Props) => { {!isGitConnected && isConnectToGitPermitted && !isAnvilEnabled && ( - + + {CONNECT_TO_GIT_OPTION()} + )} ({ default: () =>
, })); -jest.mock("selectors/gitModSelectors", () => ({ - selectCombinedPreviewMode: jest.fn(() => false), -})); - const mockStore = configureStore([]); const storeState = { diff --git a/app/client/src/components/editorComponents/GlobalSearch/HelpBar.tsx b/app/client/src/components/editorComponents/GlobalSearch/HelpBar.tsx index 0a8fb41ffabe..c52eb62c9ef2 100644 --- a/app/client/src/components/editorComponents/GlobalSearch/HelpBar.tsx +++ b/app/client/src/components/editorComponents/GlobalSearch/HelpBar.tsx @@ -1,13 +1,14 @@ -import React, { useCallback } from "react"; +import React from "react"; import styled from "styled-components"; -import { useDispatch } from "react-redux"; +import { connect } from "react-redux"; import { getTypographyByKey, Text, TextType } from "@appsmith/ads-old"; import { Icon } from "@appsmith/ads"; import { setGlobalSearchCategory } from "actions/globalSearchActions"; import AnalyticsUtil from "ee/utils/AnalyticsUtil"; import { modText } from "utils/helpers"; import { filterCategories, SEARCH_CATEGORY_ID } from "./utils"; -import { useGitProtectedMode } from "pages/Editor/gitSync/hooks/modHooks"; +import { protectedModeSelector } from "selectors/gitSyncSelectors"; +import type { AppState } from "ee/reducers"; const StyledHelpBar = styled.button` padding: 0 var(--ads-v2-spaces-3); @@ -41,18 +42,12 @@ const StyledHelpBar = styled.button` } `; -function HelpBar() { - const isProtectedMode = useGitProtectedMode(); - - const dispatch = useDispatch(); - - const toggleShowModal = useCallback(() => { - AnalyticsUtil.logEvent("OPEN_OMNIBAR", { source: "NAVBAR_CLICK" }); - dispatch( - setGlobalSearchCategory(filterCategories[SEARCH_CATEGORY_ID.INIT]), - ); - }, [dispatch]); +interface Props { + toggleShowModal: () => void; + isProtectedMode: boolean; +} +function HelpBar({ isProtectedMode, toggleShowModal }: Props) { return ( ({ + isProtectedMode: protectedModeSelector(state), +}); + +// TODO: Fix this the next time the file is edited +// eslint-disable-next-line @typescript-eslint/no-explicit-any +const mapDispatchToProps = (dispatch: any) => ({ + toggleShowModal: () => { + AnalyticsUtil.logEvent("OPEN_OMNIBAR", { source: "NAVBAR_CLICK" }); + dispatch( + setGlobalSearchCategory(filterCategories[SEARCH_CATEGORY_ID.INIT]), + ); + }, +}); + +export default connect(mapStateToProps, mapDispatchToProps)(HelpBar); diff --git a/app/client/src/components/gitContexts/GitApplicationContextProvider.tsx b/app/client/src/components/gitContexts/GitApplicationContextProvider.tsx deleted file mode 100644 index 728636e2f6dd..000000000000 --- a/app/client/src/components/gitContexts/GitApplicationContextProvider.tsx +++ /dev/null @@ -1,36 +0,0 @@ -import React from "react"; -import { useSelector } from "react-redux"; -import { GitArtifactType, GitContextProvider } from "git"; -import { getCurrentApplication } from "ee/selectors/applicationSelectors"; -import { hasCreateNewAppPermission } from "ee/utils/permissionHelpers"; -import { setWorkspaceIdForImport } from "ee/actions/applicationActions"; -import { getCurrentAppWorkspace } from "ee/selectors/selectedWorkspaceSelectors"; -import { applicationStatusTransformer } from "git/artifact-helpers/application"; - -interface GitApplicationContextProviderProps { - children: React.ReactNode; -} - -export default function GitApplicationContextProvider({ - children, -}: GitApplicationContextProviderProps) { - const artifactType = GitArtifactType.Application; - const application = useSelector(getCurrentApplication); - const workspace = useSelector(getCurrentAppWorkspace); - const isCreateNewApplicationPermitted = hasCreateNewAppPermission( - workspace.userPermissions, - ); - - return ( - - {children} - - ); -} diff --git a/app/client/src/entities/Engine/AppEditorEngine.ts b/app/client/src/entities/Engine/AppEditorEngine.ts index a0bfb5372c20..f5b0f04b228b 100644 --- a/app/client/src/entities/Engine/AppEditorEngine.ts +++ b/app/client/src/entities/Engine/AppEditorEngine.ts @@ -1,4 +1,14 @@ import { fetchMockDatasources } from "actions/datasourceActions"; +import { + fetchGitProtectedBranchesInit, + fetchGitStatusInit, + remoteUrlInputValue, + resetPullMergeStatus, + fetchBranchesInit, + triggerAutocommitInitAction, + getGitMetadataInitAction, +} from "actions/gitSyncActions"; +import { restoreRecentEntitiesRequest } from "actions/globalSearchActions"; import { resetEditorSuccess } from "actions/initActions"; import { fetchAllPageEntityCompletion, @@ -14,6 +24,7 @@ import { ReduxActionErrorTypes, ReduxActionTypes, } from "ee/constants/ReduxActionConstants"; +import { addBranchParam } from "constants/routes"; import type { APP_MODE } from "entities/App"; import { call, fork, put, select, spawn } from "redux-saga/effects"; import type { EditConsolidatedApi } from "sagas/InitSagas"; @@ -22,9 +33,12 @@ import { reportSWStatus, waitForWidgetConfigBuild, } from "sagas/InitSagas"; -import { isGitPersistBranchEnabledSelector } from "selectors/gitSyncSelectors"; +import { + getCurrentGitBranch, + isGitPersistBranchEnabledSelector, +} from "selectors/gitSyncSelectors"; import AnalyticsUtil from "ee/utils/AnalyticsUtil"; -// import history from "utils/history"; +import history from "utils/history"; import type { AppEnginePayload } from "."; import AppEngine, { ActionsNotFoundError, @@ -57,24 +71,6 @@ import { endSpan, startNestedSpan } from "instrumentation/generateTraces"; import { getCurrentUser } from "selectors/usersSelectors"; import type { User } from "constants/userConstants"; import log from "loglevel"; -import { gitArtifactActions } from "git/store/gitArtifactSlice"; -import { restoreRecentEntitiesRequest } from "actions/globalSearchActions"; -import { - fetchBranchesInit, - fetchGitProtectedBranchesInit, - fetchGitStatusInit, - getGitMetadataInitAction, - remoteUrlInputValue, - resetPullMergeStatus, - triggerAutocommitInitAction, -} from "actions/gitSyncActions"; -import history from "utils/history"; -import { addBranchParam } from "constants/routes"; -import { - selectGitApplicationCurrentBranch, - selectGitModEnabled, -} from "selectors/gitModSelectors"; -import { applicationArtifact } from "git/artifact-helpers/application"; export default class AppEditorEngine extends AppEngine { constructor(mode: APP_MODE) { @@ -285,9 +281,6 @@ export default class AppEditorEngine extends AppEngine { const currentApplication: ApplicationPayload = yield select( getCurrentApplication, ); - const currentBranch: string | undefined = yield select( - selectGitApplicationCurrentBranch, - ); const isGitPersistBranchEnabled: boolean = yield select( isGitPersistBranchEnabledSelector, @@ -295,6 +288,7 @@ export default class AppEditorEngine extends AppEngine { if (isGitPersistBranchEnabled) { const currentUser: User = yield select(getCurrentUser); + const currentBranch: string = yield select(getCurrentGitBranch); if (currentUser?.email && currentApplication?.baseId && currentBranch) { yield setLatestGitBranchInLocal( @@ -323,15 +317,6 @@ export default class AppEditorEngine extends AppEngine { }); } - if (currentApplication?.id) { - yield put( - restoreRecentEntitiesRequest({ - applicationId: currentApplication.id, - branch: currentBranch, - }), - ); - } - if (isFirstTimeUserOnboardingComplete) { yield put({ type: ReduxActionTypes.SET_FIRST_TIME_USER_ONBOARDING_APPLICATION_IDS, @@ -374,32 +359,22 @@ export default class AppEditorEngine extends AppEngine { public *loadGit(applicationId: string, rootSpan: Span) { const loadGitSpan = startNestedSpan("AppEditorEngine.loadGit", rootSpan); - const isGitModEnabled: boolean = yield select(selectGitModEnabled); - if (isGitModEnabled) { - const currentApplication: ApplicationPayload = yield select( - getCurrentApplication, - ); + const branchInStore: string = yield select(getCurrentGitBranch); - yield put( - gitArtifactActions.initGitForEditor({ - artifactDef: applicationArtifact(currentApplication.baseId), - artifact: currentApplication, - }), - ); - } 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 + yield put( + restoreRecentEntitiesRequest({ + applicationId, + branch: branchInStore, + }), + ); + // 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); - } + if (branchInStore) { + history.replace(addBranchParam(branchInStore)); + yield fork(this.loadGitInBackground); } endSpan(loadGitSpan); @@ -408,6 +383,7 @@ export default class AppEditorEngine extends AppEngine { private *loadGitInBackground() { yield put(fetchBranchesInit()); yield put(fetchGitProtectedBranchesInit()); + yield put(fetchGitProtectedBranchesInit()); yield put(getGitMetadataInitAction()); yield put(triggerAutocommitInitAction()); yield put(fetchGitStatusInit({ compareRemote: true })); diff --git a/app/client/src/entities/Engine/index.ts b/app/client/src/entities/Engine/index.ts index b4eb39475753..aadfd66a4316 100644 --- a/app/client/src/entities/Engine/index.ts +++ b/app/client/src/entities/Engine/index.ts @@ -17,10 +17,10 @@ import history from "utils/history"; import type URLRedirect from "entities/URLRedirect/index"; import URLGeneratorFactory from "entities/URLRedirect/factory"; import { updateBranchLocally } from "actions/gitSyncActions"; +import { getCurrentGitBranch } from "selectors/gitSyncSelectors"; import { restoreIDEEditorViewMode } from "actions/ideActions"; import type { Span } from "instrumentation/types"; import { endSpan, startNestedSpan } from "instrumentation/generateTraces"; -import { selectGitApplicationCurrentBranch } from "selectors/gitModSelectors"; export interface AppEnginePayload { applicationId?: string; @@ -114,13 +114,12 @@ export default abstract class AppEngine { } const application: ApplicationPayload = yield select(getCurrentApplication); - const currentBranch: string | undefined = yield select( - selectGitApplicationCurrentBranch, - ); + const currentGitBranch: ReturnType = + yield select(getCurrentGitBranch); yield put( updateAppStore( - getPersistentAppStore(application.id, branch || currentBranch), + getPersistentAppStore(application.id, branch || currentGitBranch), ), ); const defaultPageId: string = yield select(getDefaultPageId); diff --git a/app/client/src/git/artifact-helpers/application/applicationArtifact.ts b/app/client/src/git/artifact-helpers/application/applicationArtifact.ts deleted file mode 100644 index 7337db575ac6..000000000000 --- a/app/client/src/git/artifact-helpers/application/applicationArtifact.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { GitArtifactType } from "git/constants/enums"; -import type { GitArtifactDef } from "git/store/types"; - -export default function applicationArtifact( - baseApplicationId: string, -): GitArtifactDef { - return { - artifactType: GitArtifactType.Application, - baseArtifactId: baseApplicationId, - }; -} diff --git a/app/client/src/git/artifact-helpers/application/index.ts b/app/client/src/git/artifact-helpers/application/index.ts deleted file mode 100644 index 579a99c7d975..000000000000 --- a/app/client/src/git/artifact-helpers/application/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export { default as applicationArtifact } from "./applicationArtifact"; -export { default as applicationStatusTransformer } from "./applicationStatusTransformer"; diff --git a/app/client/src/git/artifact-helpers/application/applicationStatusTransformer.ts b/app/client/src/git/artifactHelpers/application/statusTransformer.ts similarity index 62% rename from app/client/src/git/artifact-helpers/application/applicationStatusTransformer.ts rename to app/client/src/git/artifactHelpers/application/statusTransformer.ts index b803cddfea66..9ac95d9c424e 100644 --- a/app/client/src/git/artifact-helpers/application/applicationStatusTransformer.ts +++ b/app/client/src/git/artifactHelpers/application/statusTransformer.ts @@ -1,11 +1,6 @@ import type { FetchStatusResponseData } from "git/requests/fetchStatusRequest.types"; import { objectKeys } from "@appsmith/utils"; -import { - createMessage, - NOT_PUSHED_YET, - TRY_TO_PULL, -} from "ee/constants/messages"; -import type { StatusTreeStruct } from "git/components/StatusChanges/types"; +import type { StatusTreeStruct } from "git/components/StatusChanges/StatusTree"; const ICON_LOOKUP = { query: "query", @@ -13,29 +8,19 @@ const ICON_LOOKUP = { page: "page-line", datasource: "database-2-line", jsLib: "package", - settings: "settings-v3", - theme: "sip-line", - remote: "git-commit", - package: "package", - module: "package", - moduleInstance: "package", }; interface TreeNodeDef { subject: string; verb: string; type: keyof typeof ICON_LOOKUP; - extra?: string; } function createTreeNode(nodeDef: TreeNodeDef) { - let message = `${nodeDef.subject} ${nodeDef.verb}`; - - if (nodeDef.extra) { - message += ` ${nodeDef.extra}`; - } - - return { icon: ICON_LOOKUP[nodeDef.type], message }; + return { + icon: ICON_LOOKUP[nodeDef.type], + message: `${nodeDef.subject} ${nodeDef.verb}`, + }; } function determineVerbForDefs(defs: TreeNodeDef[]) { @@ -60,11 +45,7 @@ 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" }), - ) - .map(createTreeNode), + children: nodeDefs.map(createTreeNode), }; } @@ -144,10 +125,6 @@ function statusPageTransformer(status: FetchStatusResponseData) { tree.push({ ...createTreeNode(pageDef), children }); }); - tree.sort((a, b) => - a.message.localeCompare(b.message, undefined, { sensitivity: "base" }), - ); - objectKeys(pageDefLookup).forEach((page) => { if (!pageEntityDefLookup[page]) { tree.push(createTreeNode(pageDefLookup[page])); @@ -209,121 +186,13 @@ function statusJsLibTransformer(status: FetchStatusResponseData) { return tree; } -function statusRemoteCountTransformer(status: FetchStatusResponseData) { - const { aheadCount, behindCount } = status; - const tree = [] as StatusTreeStruct[]; - - if (behindCount > 0) { - tree.push( - createTreeNode({ - subject: `${behindCount} commit${behindCount > 1 ? "s" : ""}`, - verb: "behind", - type: "remote", - extra: createMessage(TRY_TO_PULL), - }), - ); - } - - if (aheadCount > 0) { - tree.push( - createTreeNode({ - subject: `${aheadCount} commit${aheadCount > 1 ? "s" : ""}`, - verb: "ahead", - type: "remote", - extra: createMessage(NOT_PUSHED_YET), - }), - ); - } - - return tree; -} - -function statusSettingsTransformer(status: FetchStatusResponseData) { - const { modified } = status; - const tree = [] as StatusTreeStruct[]; - - if (modified.includes("application.json")) { - tree.push( - createTreeNode({ - subject: "Application settings", - verb: "modified", - type: "settings", - }), - ); - } - - return tree; -} - -function statusThemeTransformer(status: FetchStatusResponseData) { - const { modified } = status; - const tree = [] as StatusTreeStruct[]; - - if (modified.includes("theme.json")) { - tree.push( - createTreeNode({ - subject: "Theme", - verb: "modified", - type: "theme", - }), - ); - } - - return tree; -} - -function statusPackagesTransformer(status: FetchStatusResponseData) { - const { - modifiedModuleInstances = 0, - modifiedModules = 0, - modifiedPackages = 0, - } = status; - const tree = [] as StatusTreeStruct[]; - - if (modifiedPackages > 0) { - tree.push( - createTreeNode({ - subject: `${modifiedPackages} package${modifiedPackages > 1 ? "s" : ""}`, - verb: "modified", - type: "package", - }), - ); - } - - if (modifiedModules > 0) { - tree.push( - createTreeNode({ - subject: `${modifiedModules} module${modifiedModules > 1 ? "s" : ""}`, - verb: "modified", - type: "module", - }), - ); - } - - if (modifiedModuleInstances > 0) { - tree.push( - createTreeNode({ - subject: `${modifiedModuleInstances} module instance${modifiedModuleInstances > 1 ? "s" : ""}`, - verb: "modified", - type: "moduleInstance", - }), - ); - } - - return tree; -} - export default function applicationStatusTransformer( status: FetchStatusResponseData, ) { const tree = [ - ...statusRemoteCountTransformer(status), ...statusPageTransformer(status), ...statusDatasourceTransformer(status), ...statusJsLibTransformer(status), - ...statusSettingsTransformer(status), - ...statusThemeTransformer(status), - ...statusPackagesTransformer(status), ] as StatusTreeStruct[]; return tree; diff --git a/app/client/src/git/ce/components/GitModals/index.tsx b/app/client/src/git/ce/components/GitModals/index.tsx index 8bd094fa1ffe..a5fcb8c7be36 100644 --- a/app/client/src/git/ce/components/GitModals/index.tsx +++ b/app/client/src/git/ce/components/GitModals/index.tsx @@ -1,6 +1,5 @@ import ConflictErrorModal from "git/components/ConflictErrorModal"; import ConnectModal from "git/components/ConnectModal"; -import ConnectSuccessModal from "git/components/ConnectSuccessModal"; import DisableAutocommitModal from "git/components/DisableAutocommitModal"; import DisconnectModal from "git/components/DisconnectModal"; import OpsModal from "git/components/OpsModal"; @@ -11,7 +10,6 @@ function GitModals() { return ( <> - diff --git a/app/client/src/git/ce/hooks/useDefaultBranch.ts b/app/client/src/git/ce/hooks/useDefaultBranch.ts index 53a0f4a1fb01..6bc27c1c08c0 100644 --- a/app/client/src/git/ce/hooks/useDefaultBranch.ts +++ b/app/client/src/git/ce/hooks/useDefaultBranch.ts @@ -1,11 +1,17 @@ -import useArtifactSelector from "git/hooks/useArtifactSelector"; -import { selectDefaultBranch } from "git/store/selectors/gitArtifactSelectors"; +import { useGitContext } from "git/components/GitContextProvider"; +import { selectDefaultBranch } from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; +import { useSelector } from "react-redux"; function useDefaultBranch() { - const defaultBranch = useArtifactSelector(selectDefaultBranch); + const { artifactDef } = useGitContext(); + + const defaultBranch = useSelector((state: GitRootState) => + selectDefaultBranch(state, artifactDef), + ); return { - defaultBranch: defaultBranch ?? null, + defaultBranch, }; } diff --git a/app/client/src/git/components/ConflictErrorModal/ConflictErrorModalView.tsx b/app/client/src/git/components/ConflictErrorModal/ConflictErrorModalView.tsx index 5090e39c7643..d59ff023af40 100644 --- a/app/client/src/git/components/ConflictErrorModal/ConflictErrorModalView.tsx +++ b/app/client/src/git/components/ConflictErrorModal/ConflictErrorModalView.tsx @@ -6,7 +6,7 @@ import { CONFLICTS_FOUND_WHILE_PULLING_CHANGES, } from "ee/constants/messages"; -import { Button, Flex } from "@appsmith/ads"; +import { Button } from "@appsmith/ads"; import noop from "lodash/noop"; import ConflictError from "../ConflictError"; @@ -62,12 +62,18 @@ function ConflictErrorModalView({ >
- - +
+
{createMessage(CONFLICTS_FOUND_WHILE_PULLING_CHANGES)} - +
diff --git a/app/client/src/git/components/ConflictErrorModal/index.tsx b/app/client/src/git/components/ConflictErrorModal/index.tsx index a67a429aff35..db9568836032 100644 --- a/app/client/src/git/components/ConflictErrorModal/index.tsx +++ b/app/client/src/git/components/ConflictErrorModal/index.tsx @@ -3,11 +3,11 @@ import ConflictErrorModalView from "./ConflictErrorModalView"; import useOps from "git/hooks/useOps"; export default function ConflictErrorModal() { - const { isConflictErrorModalOpen, toggleConflictErrorModal } = useOps(); + const { conflictErrorModalOpen, toggleConflictErrorModal } = useOps(); return ( ); diff --git a/app/client/src/git/components/ConnectModal/ConnectInitialize/AddDeployKey.test.tsx b/app/client/src/git/components/ConnectModal/ConnectInitialize/AddDeployKey.test.tsx new file mode 100644 index 000000000000..176dc5247887 --- /dev/null +++ b/app/client/src/git/components/ConnectModal/ConnectInitialize/AddDeployKey.test.tsx @@ -0,0 +1,231 @@ +import React from "react"; +import { render, screen, fireEvent, waitFor } from "@testing-library/react"; +import type { AddDeployKeyProps } from "./AddDeployKey"; +import AddDeployKey from "./AddDeployKey"; +import AnalyticsUtil from "ee/utils/AnalyticsUtil"; +import "@testing-library/jest-dom"; + +jest.mock("ee/utils/AnalyticsUtil", () => ({ + logEvent: jest.fn(), +})); + +jest.mock("copy-to-clipboard", () => ({ + __esModule: true, + default: () => true, +})); + +const DEFAULT_DOCS_URL = + "https://docs.appsmith.com/advanced-concepts/version-control-with-git/connecting-to-git-repository"; + +const defaultProps: AddDeployKeyProps = { + connectError: null, + isLoading: false, + onChange: jest.fn(), + value: { + gitProvider: "github", + isAddedDeployKey: false, + remoteUrl: "git@github.com:owner/repo.git", + }, + fetchSSHKey: jest.fn(), + generateSSHKey: jest.fn(), + isFetchSSHKeyLoading: false, + isGenerateSSHKeyLoading: false, + sshPublicKey: "ecdsa-sha2-nistp256 AAAAE2VjZHNhAAAIBaj...", +}; + +describe("AddDeployKey Component", () => { + beforeEach(() => { + jest.clearAllMocks(); + }); + + it("renders without crashing and shows default UI", () => { + render(); + expect( + screen.getByText("Add deploy key & give write access"), + ).toBeInTheDocument(); + expect(screen.getByRole("combobox")).toBeInTheDocument(); + // Should show ECDSA by default since sshKeyPair includes "ecdsa" + expect( + screen.getByText(defaultProps.sshPublicKey as string), + ).toBeInTheDocument(); + expect( + screen.getByText("I've added the deploy key and gave it write access"), + ).toBeInTheDocument(); + }); + + it("calls fetchSSHKey if modal is open and not importing", () => { + render(); + expect(defaultProps.fetchSSHKey).toHaveBeenCalledTimes(1); + }); + + it("does not call fetchSSHKey if importing", () => { + render(); + expect(defaultProps.fetchSSHKey).not.toHaveBeenCalled(); + }); + + it("shows dummy key loader if loading keys", () => { + render( + , + ); + // The actual key text should not be displayed + expect(screen.queryByText("ecdsa-sha2-nistp256")).not.toBeInTheDocument(); + }); + + it("changes SSH key type when user selects a different type and triggers generateSSHKey if needed", async () => { + const generateSSHKey = jest.fn(); + + render( + , + ); + + fireEvent.mouseDown(screen.getByRole("combobox")); + const rsaOption = screen.getByText("RSA 4096"); + + fireEvent.click(rsaOption); + + await waitFor(() => { + expect(generateSSHKey).toHaveBeenCalledWith("RSA", false); + }); + }); + + it("displays a generic error when errorData is provided and error code is not AE-GIT-4032 or AE-GIT-4033", () => { + // eslint-disable-next-line react-perf/jsx-no-new-object-as-prop + const connectError = { + code: "GENERIC-ERROR", + errorType: "Some Error", + message: "Something went wrong", + }; + + render(); + expect(screen.getByText("Some Error")).toBeInTheDocument(); + expect(screen.getByText("Something went wrong")).toBeInTheDocument(); + }); + + it("displays a misconfiguration error if error code is AE-GIT-4032", () => { + // eslint-disable-next-line react-perf/jsx-no-new-object-as-prop + const connectError = { + code: "AE-GIT-4032", + errorType: "SSH Key Error", + message: "SSH Key misconfiguration", + }; + + render(); + expect(screen.getByText("SSH key misconfiguration")).toBeInTheDocument(); + expect( + screen.getByText( + "It seems that your SSH key hasn't been added to your repository. To proceed, please revisit the steps below and configure your SSH key correctly.", + ), + ).toBeInTheDocument(); + }); + + it("invokes onChange callback when checkbox is toggled", () => { + const onChange = jest.fn(); + + render(); + const checkbox = screen.getByTestId("t--added-deploy-key-checkbox"); + + fireEvent.click(checkbox); + expect(onChange).toHaveBeenCalledWith({ isAddedDeployKey: true }); + }); + + it("calls AnalyticsUtil on copy button click", () => { + render(); + const copyButton = screen.getByTestId("t--copy-generic"); + + fireEvent.click(copyButton); + expect(AnalyticsUtil.logEvent).toHaveBeenCalledWith( + "GS_COPY_SSH_KEY_BUTTON_CLICK", + ); + }); + + it("hides copy button when connectLoading is true", () => { + render(); + expect(screen.queryByTestId("t--copy-generic")).not.toBeInTheDocument(); + }); + + it("shows repository settings link if gitProvider is known and not 'others'", () => { + render(); + const link = screen.getByRole("link", { name: "repository settings." }); + + expect(link).toHaveAttribute( + "href", + "https://github.com/owner/repo/settings/keys", + ); + }); + + it("does not show repository link if gitProvider = 'others'", () => { + render( + , + ); + expect( + screen.queryByRole("link", { name: "repository settings." }), + ).not.toBeInTheDocument(); + }); + + it("shows collapsible section if gitProvider is not 'others'", () => { + render( + , + ); + expect( + screen.getByText("How to paste SSH Key in repo and give write access?"), + ).toBeInTheDocument(); + expect(screen.getByAltText("Add deploy key in gitlab")).toBeInTheDocument(); + }); + + it("does not display collapsible if gitProvider = 'others'", () => { + render( + , + ); + expect( + screen.queryByText("How to paste SSH Key in repo and give write access?"), + ).not.toBeInTheDocument(); + }); + + it("uses default documentation link if none provided", () => { + render(); + const docsLink = screen.getByRole("link", { name: "Read Docs" }); + + expect(docsLink).toHaveAttribute("href", DEFAULT_DOCS_URL); + }); + + it("generates SSH key if none is present and conditions are met", async () => { + const fetchSSHKey = jest.fn(); + const generateSSHKey = jest.fn(); + + render( + , + ); + + expect(fetchSSHKey).toHaveBeenCalledTimes(1); + + await waitFor(() => { + expect(generateSSHKey).toHaveBeenCalledWith("ECDSA", false); + }); + }); +}); diff --git a/app/client/src/git/components/ConnectModal/ConnectInitialize/AddDeployKey.tsx b/app/client/src/git/components/ConnectModal/ConnectInitialize/AddDeployKey.tsx index 09dcb7df1122..75a4a7a50e86 100644 --- a/app/client/src/git/components/ConnectModal/ConnectInitialize/AddDeployKey.tsx +++ b/app/client/src/git/components/ConnectModal/ConnectInitialize/AddDeployKey.tsx @@ -135,83 +135,93 @@ const DEPLOY_DOCS_URL = "https://docs.appsmith.com/advanced-concepts/version-control-with-git/connecting-to-git-repository"; export interface AddDeployKeyProps { - error: GitApiError | null; - isSubmitLoading: boolean; - isSSHKeyLoading: boolean; + connectError: GitApiError | null; + fetchSSHKey: () => void; + generateSSHKey: (keyType: string, isImport?: boolean) => void; + isFetchSSHKeyLoading: boolean; + isGenerateSSHKeyLoading: boolean; + isImport?: boolean; + isLoading: boolean; onChange: (args: Partial) => void; - onFetchSSHKey?: () => void; - onGenerateSSHKey: (keyType: string) => void; sshPublicKey: string | null; value: Partial | null; } function AddDeployKey({ - error = null, - isSSHKeyLoading = false, - isSubmitLoading = false, + connectError = null, + fetchSSHKey = noop, + generateSSHKey = noop, + isFetchSSHKeyLoading = false, + isGenerateSSHKeyLoading = false, + isImport = false, + isLoading = false, onChange = noop, - onFetchSSHKey = noop, - onGenerateSSHKey = noop, sshPublicKey = null, value = null, }: AddDeployKeyProps) { const [fetched, setFetched] = useState(false); - const [keyType, setKeyType] = useState(); + const [sshKeyType, setSshKeyType] = useState(); useEffect( function fetchKeyPairOnInitEffect() { - if (!fetched) { - onFetchSSHKey(); - setFetched(true); - // doesn't support callback anymore - // fetchSSHKey({ - // onSuccessCallback: () => { - // setFetched(true); - // }, - // onErrorCallback: () => { - // setFetched(true); - // }, - // }); + if (!isImport) { + if (!fetched) { + fetchSSHKey(); + setFetched(true); + // doesn't support callback anymore + // fetchSSHKey({ + // onSuccessCallback: () => { + // setFetched(true); + // }, + // onErrorCallback: () => { + // setFetched(true); + // }, + // }); + } + } else { + if (!fetched) { + setFetched(true); + } } }, - [fetched, onFetchSSHKey], + [isImport, fetched, fetchSSHKey], ); useEffect( function setSSHKeyTypeonInitEffect() { - if (fetched && !isSSHKeyLoading) { + if (fetched && !isFetchSSHKeyLoading) { if (sshPublicKey && sshPublicKey.includes("rsa")) { - setKeyType("RSA"); + setSshKeyType("RSA"); } else if ( !sshPublicKey && value?.remoteUrl && value.remoteUrl.toString().toLocaleLowerCase().includes("azure") ) { - setKeyType("RSA"); + setSshKeyType("RSA"); } else { - setKeyType("ECDSA"); + setSshKeyType("ECDSA"); } } }, - [fetched, sshPublicKey, value?.remoteUrl, isSSHKeyLoading], + [fetched, sshPublicKey, isFetchSSHKeyLoading, value?.remoteUrl], ); useEffect( function generateSSHOnInitEffect() { if ( - (keyType && !sshPublicKey) || - (keyType && !sshPublicKey?.includes(keyType.toLowerCase())) + (sshKeyType && !sshPublicKey) || + (sshKeyType && !sshPublicKey?.includes(sshKeyType.toLowerCase())) ) { - onGenerateSSHKey(keyType); + generateSSHKey(sshKeyType, isImport); // doesn't support callback anymore - // generateSSHKey(keyType, { + // generateSSHKey(sshKeyType, { // onSuccessCallback: () => { // toast.show("SSH Key generated successfully", { kind: "success" }); // }, // }); } }, - [keyType, sshPublicKey, onGenerateSSHKey], + [sshKeyType, sshPublicKey, generateSSHKey, isImport], ); const repositorySettingsUrl = getRepositorySettingsUrl( @@ -219,7 +229,7 @@ function AddDeployKey({ value?.remoteUrl, ); - // const loading = isFetchSSHKeyLoading || isGenerateSSHKeyLoading; + const loading = isFetchSSHKeyLoading || isGenerateSSHKeyLoading; const onCopy = useCallback(() => { AnalyticsUtil.logEvent("GS_COPY_SSH_KEY_BUTTON_CLICK"); @@ -234,19 +244,19 @@ function AddDeployKey({ return ( <> - {error && - error.code !== "AE-GIT-4033" && - error.code !== "AE-GIT-4032" && ( + {connectError && + connectError.code !== "AE-GIT-4033" && + connectError.code !== "AE-GIT-4032" && ( - {error.errorType} + {connectError.errorType} - {error.message} + {connectError.message} )} {/* hardcoding message because server doesn't support feature flag. Will change this later */} - {error && error.code === "AE-GIT-4032" && ( + {connectError && connectError.code === "AE-GIT-4032" && ( {createMessage(ERROR_SSH_KEY_MISCONF_TITLE)} @@ -291,20 +301,20 @@ function AddDeployKey({ Now, give write access to it. - + - {!isSSHKeyLoading ? ( + {!loading ? ( - {keyType} + {sshKeyType} {sshPublicKey} - {!isSubmitLoading && ( + {!isLoading && ( { @@ -168,19 +169,19 @@ describe("ChooseGitProvider Component", () => { }); it("clicking on 'Import via git' link calls onImportFromCalloutLinkClick", () => { - const onOpenImport = jest.fn(); + const mockSetImportWorkspaceId = jest.fn(); render( , ); fireEvent.click(screen.getByText("Import via git")); - expect(onOpenImport).toHaveBeenCalledTimes(1); + expect(mockSetImportWorkspaceId).toHaveBeenCalledTimes(1); }); it("when isImport = true, shows a checkbox for existing repo", () => { @@ -213,11 +214,11 @@ describe("ChooseGitProvider Component", () => { }); it("respects canCreateNewArtifact and device conditions for links", () => { - // If onOpenImport is null, "Import via git" should not appear even if conditions are met + // If canCreateNewArtifact is false, "Import via git" should not appear even if conditions are met render( , ); diff --git a/app/client/src/git/components/ConnectModal/ConnectInitialize/ChooseGitProvider.tsx b/app/client/src/git/components/ConnectModal/ConnectInitialize/ChooseGitProvider.tsx index b8aceed5baf4..d24c31de20de 100644 --- a/app/client/src/git/components/ConnectModal/ConnectInitialize/ChooseGitProvider.tsx +++ b/app/client/src/git/components/ConnectModal/ConnectInitialize/ChooseGitProvider.tsx @@ -34,7 +34,9 @@ import { } from "ee/constants/messages"; import log from "loglevel"; import type { ConnectFormDataState } from "./types"; +import history from "utils/history"; import { useIsMobileDevice } from "utils/hooks/useDeviceDetect"; +import AnalyticsUtil from "ee/utils/AnalyticsUtil"; const WellInnerContainer = styled.div` padding-left: 16px; @@ -51,17 +53,21 @@ export type GitProvider = (typeof GIT_PROVIDERS)[number]; interface ChooseGitProviderProps { artifactType: string; + isCreateArtifactPermitted: boolean; isImport?: boolean; onChange: (args: Partial) => void; - onOpenImport: (() => void) | null; + setImportWorkspaceId: () => void; + toggleConnectModal: (open: boolean) => void; value: Partial; } function ChooseGitProvider({ artifactType, + isCreateArtifactPermitted, isImport = false, onChange = noop, - onOpenImport = null, + setImportWorkspaceId = noop, + toggleConnectModal = noop, value = {}, }: ChooseGitProviderProps) { const isMobile = useIsMobileDevice(); @@ -91,19 +97,19 @@ function ChooseGitProvider({ [onChange], ); - // const handleClickOnImport = useCallback(() => { - // toggleConnectModal(false); - // history.push("/applications"); - // setImportWorkspaceId(); - // toggleConnectModal(true); - // AnalyticsUtil.logEvent("GS_IMPORT_VIA_GIT_DURING_GC"); - // }, [setImportWorkspaceId, toggleConnectModal]); + const handleClickOnImport = useCallback(() => { + toggleConnectModal(false); + history.push("/applications"); + setImportWorkspaceId(); + toggleConnectModal(true); + AnalyticsUtil.logEvent("GS_IMPORT_VIA_GIT_DURING_GC"); + }, [setImportWorkspaceId, toggleConnectModal]); const importCalloutLinks = useMemo(() => { - return !isMobile && onOpenImport && typeof onOpenImport === "function" - ? [{ children: "Import via git", onClick: onOpenImport }] + return !isMobile && isCreateArtifactPermitted + ? [{ children: "Import via git", onClick: handleClickOnImport }] : []; - }, [onOpenImport, isMobile]); + }, [handleClickOnImport, isCreateArtifactPermitted, isMobile]); return ( <> @@ -202,7 +208,7 @@ function ChooseGitProvider({ )} - {!isImport && onOpenImport && value?.gitEmptyRepoExists === "no" ? ( + {!isImport && value?.gitEmptyRepoExists === "no" ? ( {createMessage(IMPORT_ARTIFACT_IF_NOT_EMPTY, artifactType)} diff --git a/app/client/src/git/components/ConnectModal/ConnectInitialize/GenerateSSH.test.tsx b/app/client/src/git/components/ConnectModal/ConnectInitialize/GenerateSSH.test.tsx index fc53b8531a4f..d082ee44546d 100644 --- a/app/client/src/git/components/ConnectModal/ConnectInitialize/GenerateSSH.test.tsx +++ b/app/client/src/git/components/ConnectModal/ConnectInitialize/GenerateSSH.test.tsx @@ -16,7 +16,7 @@ const defaultProps = { gitProvider: "github" as GitProvider, remoteUrl: "", }, - error: null, + connectError: null, }; describe("GenerateSSH Component", () => { @@ -38,7 +38,7 @@ describe("GenerateSSH Component", () => { code: "AE-GIT-4033", }; - render(); + render(); expect( screen.getByText("The repo you added isn't empty"), ).toBeInTheDocument(); @@ -55,7 +55,7 @@ describe("GenerateSSH Component", () => { code: "SOME_OTHER_ERROR", }; - render(); + render(); expect( screen.queryByText("The repo you added isn't empty"), ).not.toBeInTheDocument(); diff --git a/app/client/src/git/components/ConnectModal/ConnectInitialize/GenerateSSH.tsx b/app/client/src/git/components/ConnectModal/ConnectInitialize/GenerateSSH.tsx index 6a8b7536f903..5318b0bd8554 100644 --- a/app/client/src/git/components/ConnectModal/ConnectInitialize/GenerateSSH.tsx +++ b/app/client/src/git/components/ConnectModal/ConnectInitialize/GenerateSSH.tsx @@ -41,13 +41,17 @@ interface GenerateSSHState { interface GenerateSSHProps { onChange: (args: Partial) => void; value: Partial; - error: GitApiError | null; + connectError: GitApiError | null; } const CONNECTING_TO_GIT_DOCS_URL = "https://docs.appsmith.com/advanced-concepts/version-control-with-git/connecting-to-git-repository"; -function GenerateSSH({ error, onChange = noop, value = {} }: GenerateSSHProps) { +function GenerateSSH({ + connectError, + onChange = noop, + value = {}, +}: GenerateSSHProps) { const [isTouched, setIsTouched] = useState(false); const isInvalid = isTouched && @@ -65,7 +69,7 @@ function GenerateSSH({ error, onChange = noop, value = {} }: GenerateSSHProps) { return ( <> {/* hardcoding messages because server doesn't support feature flag. Will change this later */} - {error && error?.code === "AE-GIT-4033" && ( + {connectError && connectError?.code === "AE-GIT-4033" && ( {createMessage(ERROR_REPO_NOT_EMPTY_TITLE)} diff --git a/app/client/src/git/components/ConnectModal/ConnectInitialize/index.test.tsx b/app/client/src/git/components/ConnectModal/ConnectInitialize/index.test.tsx index 21f46cf03525..6ac8b83b0761 100644 --- a/app/client/src/git/components/ConnectModal/ConnectInitialize/index.test.tsx +++ b/app/client/src/git/components/ConnectModal/ConnectInitialize/index.test.tsx @@ -21,15 +21,19 @@ jest.mock("@appsmith/ads", () => ({ const defaultProps = { artifactType: "Application", - error: null, - onFetchSSHKey: jest.fn(), - onGenerateSSHKey: jest.fn(), - isSubmitLoading: false, - isSSHKeyLoading: false, + connect: jest.fn(), + connectError: null, + fetchSSHKey: jest.fn(), + generateSSHKey: jest.fn(), + gitImport: jest.fn(), + isConnectLoading: false, + isFetchSSHKeyLoading: false, + isGenerateSSHKeyLoading: false, + isGitImportLoading: false, isImport: false, - onSubmit: jest.fn(), - onOpenImport: null, sshPublicKey: "ssh-rsa AAAAB3...", + isCreateArtifactPermitted: true, + setImportWorkspaceId: jest.fn(), toggleConnectModal: jest.fn(), }; @@ -122,7 +126,7 @@ describe("ConnectModal Component", () => { completeAddDeployKeyStep(); await waitFor(() => { - expect(defaultProps.onSubmit).toHaveBeenCalledWith( + expect(defaultProps.connect).toHaveBeenCalledWith( expect.objectContaining({ remoteUrl: "git@example.com:user/repo.git", gitProfile: { @@ -135,14 +139,14 @@ describe("ConnectModal Component", () => { }); }); - it("calls onSubmit on completing AddDeployKey step in import mode", async () => { + it("calls gitImport on completing AddDeployKey step in import mode", async () => { render(); completeChooseProviderStep(true); completeGenerateSSHKeyStep(); completeAddDeployKeyStep(); await waitFor(() => { - expect(defaultProps.onSubmit).toHaveBeenCalledWith( + expect(defaultProps.gitImport).toHaveBeenCalledWith( expect.objectContaining({ remoteUrl: "git@example.com:user/repo.git", gitProfile: { @@ -163,11 +167,13 @@ describe("ConnectModal Component", () => { message: "", }; - rerender(); + rerender( + , + ); }); const { rerender } = render( - , + , ); completeChooseProviderStep(); @@ -210,7 +216,7 @@ describe("ConnectModal Component", () => { }); it("renders loading state and removes buttons when connecting", () => { - render(); + render(); expect( screen.getByText("Please wait while we connect to Git..."), ).toBeInTheDocument(); diff --git a/app/client/src/git/components/ConnectModal/ConnectInitialize/index.tsx b/app/client/src/git/components/ConnectModal/ConnectInitialize/index.tsx index 72ba9d797c1d..05046d250d09 100644 --- a/app/client/src/git/components/ConnectModal/ConnectInitialize/index.tsx +++ b/app/client/src/git/components/ConnectModal/ConnectInitialize/index.tsx @@ -71,31 +71,41 @@ interface StyledModalFooterProps { loading?: boolean; } -export interface ConnectInitializeProps { +interface ConnectModalViewProps { artifactType: string; - error: GitApiError | null; + connect: (params: ConnectRequestParams) => void; + connectError: GitApiError | null; + fetchSSHKey: () => void; + generateSSHKey: (keyType: string) => void; + gitImport: (params: GitImportRequestParams) => void; + isConnectLoading: boolean; + isCreateArtifactPermitted: boolean; + isFetchSSHKeyLoading: boolean; + isGenerateSSHKeyLoading: boolean; + isGitImportLoading: boolean; isImport: boolean; - isSSHKeyLoading: boolean; - isSubmitLoading: boolean; - onFetchSSHKey: () => void; - onGenerateSSHKey: (keyType: string) => void; - onOpenImport: (() => void) | null; - onSubmit: (params: ConnectRequestParams | GitImportRequestParams) => void; + setImportWorkspaceId: () => void; sshPublicKey: string | null; + toggleConnectModal: (open: boolean) => void; } function ConnectInitialize({ artifactType, - error = null, + connect = noop, + connectError = null, + fetchSSHKey = noop, + generateSSHKey = noop, + gitImport = noop, + isConnectLoading = false, + isCreateArtifactPermitted = false, + isFetchSSHKeyLoading = false, + isGenerateSSHKeyLoading = false, + isGitImportLoading = false, isImport = false, - isSSHKeyLoading = false, - isSubmitLoading = false, - onFetchSSHKey = noop, - onGenerateSSHKey = noop, - onOpenImport = null, - onSubmit = noop, + setImportWorkspaceId = noop, sshPublicKey = null, -}: ConnectInitializeProps) { + toggleConnectModal = noop, +}: ConnectModalViewProps) { const nextStepText = { [GIT_CONNECT_STEPS.CHOOSE_PROVIDER]: createMessage(CONFIGURE_GIT), [GIT_CONNECT_STEPS.GENERATE_SSH_KEY]: createMessage(GENERATE_SSH_KEY_STEP), @@ -117,8 +127,8 @@ function ConnectInitialize({ GIT_CONNECT_STEPS.CHOOSE_PROVIDER, ); - // const isSubmitLoading = - // (!isImport && isConnectLoading) || (isImport && isGitImportLoading); + const isLoading = + (!isImport && isConnectLoading) || (isImport && isGitImportLoading); const currentIndex = steps.findIndex((s) => s.key === activeStep); @@ -171,40 +181,43 @@ function ConnectInitialize({ }; if (formData.remoteUrl) { - onSubmit({ - remoteUrl: formData.remoteUrl, - gitProfile, - }); - // if (!isImport) { - // AnalyticsUtil.logEvent( - // "GS_CONNECT_BUTTON_ON_GIT_SYNC_MODAL_CLICK", - // { repoUrl: formData?.remoteUrl, connectFlow: "v2" }, - // ); - // connect({ - // remoteUrl: formData.remoteUrl, - // gitProfile, - // }); - // } else { - // gitImport({ - // remoteUrl: formData.remoteUrl, - // gitProfile, - // }); - // } + if (!isImport) { + AnalyticsUtil.logEvent( + "GS_CONNECT_BUTTON_ON_GIT_SYNC_MODAL_CLICK", + { repoUrl: formData?.remoteUrl, connectFlow: "v2" }, + ); + connect({ + remoteUrl: formData.remoteUrl, + gitProfile, + }); + } else { + gitImport({ + remoteUrl: formData.remoteUrl, + gitProfile, + }); + } } break; } } } - }, [activeStep, currentIndex, formData.remoteUrl, onSubmit]); + }, [ + activeStep, + connect, + currentIndex, + formData.remoteUrl, + gitImport, + isImport, + ]); useEffect( function changeStepOnErrorEffect() { - if (error?.code === GitErrorCodes.REPO_NOT_EMPTY) { + if (connectError?.code === GitErrorCodes.REPO_NOT_EMPTY) { setActiveStep(GIT_CONNECT_STEPS.GENERATE_SSH_KEY); } }, - [error?.code], + [connectError?.code], ); return ( @@ -223,38 +236,45 @@ function ConnectInitialize({ {activeStep === GIT_CONNECT_STEPS.CHOOSE_PROVIDER && ( )} {activeStep === GIT_CONNECT_STEPS.GENERATE_SSH_KEY && ( - + )} {activeStep === GIT_CONNECT_STEPS.ADD_DEPLOY_KEY && ( )} - - {isSubmitLoading && ( + + {isLoading && ( )} - {!isSubmitLoading && ( + {!isLoading && ( - - - - + <> + + + + + + + + + ); } -export default ConnectSuccessModalView; +export default ConnectSuccess; diff --git a/app/client/src/git/components/ConnectModal/index.tsx b/app/client/src/git/components/ConnectModal/index.tsx index 651626e933a7..a8f268132d95 100644 --- a/app/client/src/git/components/ConnectModal/index.tsx +++ b/app/client/src/git/components/ConnectModal/index.tsx @@ -1,78 +1,67 @@ -import React, { useCallback } from "react"; +import React from "react"; import ConnectModalView from "./ConnectModalView"; import { useGitContext } from "../GitContextProvider"; import useConnect from "git/hooks/useConnect"; -import { GitArtifactType } from "git/constants/enums"; -import type { ConnectRequestParams } from "git/requests/connectRequest.types"; -import AnalyticsUtil from "ee/utils/AnalyticsUtil"; -import useSSHKey from "git/hooks/useSSHKey"; -import useImport from "git/hooks/useImport"; -import history from "utils/history"; +import useMetadata from "git/hooks/useMetadata"; +import useSettings from "git/hooks/useSettings"; -function ConnectModal() { +interface ConnectModalProps { + isImport?: boolean; +} + +function ConnectModal({ isImport = false }: ConnectModalProps) { const { artifactDef, isCreateArtifactPermitted, setImportWorkspaceId } = useGitContext(); const { connect, connectError, - isConnectLoading, - isConnectModalOpen, - toggleConnectModal, - } = useConnect(); - const { toggleImportModal } = useImport(); - const { fetchSSHKey, generateSSHKey, + gitImport, + isConnectLoading, + isConnectModalOpen, isFetchSSHKeyLoading, isGenerateSSHKeyLoading, + isGitImportLoading, resetFetchSSHKey, resetGenerateSSHKey, sshKey, - } = useSSHKey(); + toggleConnectModal, + } = useConnect(); + const { isGitConnected, metadata } = useMetadata(); + const { toggleSettingsModal } = useSettings(); - const artifactType = artifactDef?.artifactType ?? GitArtifactType.Application; + const { artifactType } = artifactDef; const sshPublicKey = sshKey?.publicKey ?? null; - const isSSHKeyLoading = isFetchSSHKeyLoading || isGenerateSSHKeyLoading; - - const onSubmit = useCallback( - (params: ConnectRequestParams) => { - AnalyticsUtil.logEvent("GS_CONNECT_BUTTON_ON_GIT_SYNC_MODAL_CLICK", { - repoUrl: params?.remoteUrl, - connectFlow: "v2", - }); - connect(params); - }, - [connect], - ); - - const onOpenImport = useCallback(() => { - toggleConnectModal(false); - history.push("/applications"); - setImportWorkspaceId(); - toggleImportModal(true); - AnalyticsUtil.logEvent("GS_IMPORT_VIA_GIT_DURING_GC"); - }, [setImportWorkspaceId, toggleConnectModal, toggleImportModal]); - - const resetSSHKey = useCallback(() => { - resetFetchSSHKey(); - resetGenerateSSHKey(); - }, [resetFetchSSHKey, resetGenerateSSHKey]); + const remoteUrl = metadata?.remoteUrl ?? null; + const repoName = metadata?.repoName ?? null; + const defaultBranch = metadata?.defaultBranchName ?? null; return ( ); } diff --git a/app/client/src/git/components/ConnectSuccessModal/index.tsx b/app/client/src/git/components/ConnectSuccessModal/index.tsx deleted file mode 100644 index c492e5aa4bb3..000000000000 --- a/app/client/src/git/components/ConnectSuccessModal/index.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import React from "react"; -import ConnectSuccessModalView from "./ConnectSuccessModalView"; -import useMetadata from "git/hooks/useMetadata"; -import useConnect from "git/hooks/useConnect"; -import useSettings from "git/hooks/useSettings"; - -function ConnectSuccessModal() { - const { isConnectSuccessModalOpen, toggleConnectSuccessModal } = useConnect(); - const { toggleSettingsModal } = useSettings(); - - const { metadata } = useMetadata(); - - const remoteUrl = metadata?.remoteUrl ?? null; - const repoName = metadata?.repoName ?? null; - const defaultBranch = metadata?.defaultBranchName ?? null; - - return ( - - ); -} - -export default ConnectSuccessModal; diff --git a/app/client/src/git/components/DeployMenuItems/DeployMenuItemsView.tsx b/app/client/src/git/components/DeployMenuItems/DeployMenuItemsView.tsx deleted file mode 100644 index 09ce5be3178a..000000000000 --- a/app/client/src/git/components/DeployMenuItems/DeployMenuItemsView.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import React, { useCallback } from "react"; -import { MenuItem } from "@appsmith/ads"; -import { CONNECT_TO_GIT_OPTION, createMessage } from "ee/constants/messages"; -import AnalyticsUtil from "ee/utils/AnalyticsUtil"; -import noop from "lodash/noop"; - -interface DeployMenuItemsViewProps { - toggleConnectModal: (open: boolean) => void; -} - -function DeployMenuItemsView({ - toggleConnectModal = noop, -}: DeployMenuItemsViewProps) { - const handleClickOnConnect = useCallback(() => { - AnalyticsUtil.logEvent("GS_CONNECT_GIT_CLICK", { - source: "Deploy button", - }); - toggleConnectModal(true); - }, [toggleConnectModal]); - - return ( - - {createMessage(CONNECT_TO_GIT_OPTION)} - - ); -} - -export default DeployMenuItemsView; diff --git a/app/client/src/git/components/DeployMenuItems/index.tsx b/app/client/src/git/components/DeployMenuItems/index.tsx deleted file mode 100644 index de6c61f9af9b..000000000000 --- a/app/client/src/git/components/DeployMenuItems/index.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import useConnect from "git/hooks/useConnect"; -import React from "react"; -import DeployMenuItemsView from "./DeployMenuItemsView"; - -function DeployMenuItems() { - const { toggleConnectModal } = useConnect(); - - return ; -} - -export default DeployMenuItems; diff --git a/app/client/src/git/components/GitContextProvider/index.tsx b/app/client/src/git/components/GitContextProvider/index.tsx index 89736de113eb..4d4b88b4f6ad 100644 --- a/app/client/src/git/components/GitContextProvider/index.tsx +++ b/app/client/src/git/components/GitContextProvider/index.tsx @@ -2,12 +2,14 @@ import React, { createContext, useCallback, useContext, useMemo } from "react"; import type { GitArtifactType } from "git/constants/enums"; import type { ApplicationPayload } from "entities/Application"; import type { FetchStatusResponseData } from "git/requests/fetchStatusRequest.types"; +import type { StatusTreeStruct } from "../StatusChanges/StatusTree"; import { useDispatch } from "react-redux"; -import type { GitArtifactDef } from "git/store/types"; -import type { StatusTreeStruct } from "../StatusChanges/types"; export interface GitContextValue { - artifactDef: GitArtifactDef | null; + artifactDef: { + artifactType: keyof typeof GitArtifactType; + baseArtifactId: string; + }; artifact: ApplicationPayload | null; statusTransformer: ( status: FetchStatusResponseData, @@ -25,8 +27,8 @@ export const useGitContext = () => { }; interface GitContextProviderProps { - artifactType: keyof typeof GitArtifactType | null; - baseArtifactId: string | null; + artifactType: keyof typeof GitArtifactType; + baseArtifactId: string; artifact: ApplicationPayload | null; isCreateArtifactPermitted: boolean; setWorkspaceIdForImport: (params: { @@ -48,13 +50,10 @@ export default function GitContextProvider({ setWorkspaceIdForImport, statusTransformer, }: GitContextProviderProps) { - const artifactDef = useMemo(() => { - if (artifactType && baseArtifactId) { - return { artifactType, baseArtifactId }; - } - - return null; - }, [artifactType, baseArtifactId]); + const artifactDef = useMemo( + () => ({ artifactType, baseArtifactId }), + [artifactType, baseArtifactId], + ); const dispatch = useDispatch(); diff --git a/app/client/src/git/components/GlobalProfile/GlobalProfileView.tsx b/app/client/src/git/components/GlobalProfile/GlobalProfileView.tsx deleted file mode 100644 index ddb2d7935387..000000000000 --- a/app/client/src/git/components/GlobalProfile/GlobalProfileView.tsx +++ /dev/null @@ -1,148 +0,0 @@ -import React, { useCallback, useEffect, useState } from "react"; -import { - createMessage, - AUTHOR_EMAIL, - AUTHOR_NAME, - SUBMIT, -} from "ee/constants/messages"; -import { Classes } from "@blueprintjs/core"; -import { Button, Input, toast } from "@appsmith/ads"; -import { emailValidator } from "@appsmith/ads-old"; -import styled from "styled-components"; -import type { FetchGlobalProfileResponseData } from "git/requests/fetchGlobalProfileRequest.types"; -import type { UpdateGlobalProfileInitPayload } from "git/store/actions/updateGlobalProfileActions"; -import noop from "lodash/noop"; - -const Wrapper = styled.div` - width: 320px; - & > div { - margin-bottom: 16px; - } -`; - -const FieldWrapper = styled.div` - .user-profile-image-picker { - width: 166px; - margin-top: 4px; - } -`; - -const Loader = styled.div` - height: 38px; - width: 320px; - border-radius: 0; -`; - -interface GlobalProfileViewProps { - globalProfile: FetchGlobalProfileResponseData | null; - isFetchGlobalProfileLoading: boolean; - isUpdateGlobalProfileLoading: boolean; - updateGlobalProfile: (data: UpdateGlobalProfileInitPayload) => void; -} - -export default function GlobalProfileView({ - globalProfile = null, - isFetchGlobalProfileLoading = false, - isUpdateGlobalProfileLoading = false, - updateGlobalProfile = noop, -}: GlobalProfileViewProps) { - const [areFormValuesUpdated, setAreFormValuesUpdated] = useState(false); - - const [authorName, setAuthorNameInState] = useState( - globalProfile?.authorName, - ); - const [authorEmail, setAuthorEmailInState] = useState( - globalProfile?.authorEmail, - ); - - const isSubmitDisabled = !authorName || !authorEmail || !areFormValuesUpdated; - - const isLoading = isFetchGlobalProfileLoading || isUpdateGlobalProfileLoading; - - const setAuthorName = useCallback( - (value: string) => { - setAuthorNameInState(value); - - if (authorName) setAreFormValuesUpdated(true); - }, - [authorName], - ); - - const setAuthorEmail = useCallback( - (value: string) => { - setAuthorEmailInState(value); - - if (authorEmail) setAreFormValuesUpdated(true); - }, - [authorEmail], - ); - - const onClickUpdate = useCallback(() => { - if (authorName && authorEmail && emailValidator(authorEmail).isValid) { - setAreFormValuesUpdated(false); - updateGlobalProfile({ authorName, authorEmail }); - } else { - toast.show("Please enter valid user details"); - } - }, [authorEmail, authorName, updateGlobalProfile]); - - useEffect( - function resetOnInitEffect() { - setAreFormValuesUpdated(false); - setAuthorNameInState(globalProfile?.authorName ?? ""); - setAuthorEmailInState(globalProfile?.authorEmail ?? ""); - }, - [globalProfile], - ); - - return ( - - - {isLoading && } - {!isLoading && ( - - )} - - - {isLoading && } - {!isLoading && ( - - )} - - -
- -
-
-
- ); -} diff --git a/app/client/src/git/components/GlobalProfile/index.tsx b/app/client/src/git/components/GlobalProfile/index.tsx deleted file mode 100644 index 5ecc06e70c87..000000000000 --- a/app/client/src/git/components/GlobalProfile/index.tsx +++ /dev/null @@ -1,23 +0,0 @@ -import useGlobalProfile from "git/hooks/useGlobalProfile"; -import React from "react"; -import GlobalProfileView from "./GlobalProfileView"; - -function GlobalProfile() { - const { - globalProfile, - isFetchGlobalProfileLoading, - isUpdateGlobalProfileLoading, - updateGlobalProfile, - } = useGlobalProfile(); - - return ( - - ); -} - -export default GlobalProfile; diff --git a/app/client/src/git/components/ImportModal/index.tsx b/app/client/src/git/components/ImportModal/index.tsx index 8192fa9e88a7..f55a468d702b 100644 --- a/app/client/src/git/components/ImportModal/index.tsx +++ b/app/client/src/git/components/ImportModal/index.tsx @@ -1,51 +1,8 @@ -import React, { useCallback } from "react"; -import ConnectModalView from "../ConnectModal/ConnectModalView"; -import type { GitImportRequestParams } from "git/requests/gitImportRequest.types"; -import useImport from "git/hooks/useImport"; -import useGlobalSSHKey from "git/hooks/useGlobalSSHKey"; -import noop from "lodash/noop"; +import React from "react"; +import ConnectModal from "../ConnectModal"; function ImportModal() { - const { - gitImport, - gitImportError, - isGitImportLoading, - isImportModalOpen, - toggleImportModal, - } = useImport(); - const { - fetchGlobalSSHKey, - globalSSHKey, - isFetchGlobalSSHKeyLoading, - resetGlobalSSHKey, - } = useGlobalSSHKey(); - - const sshPublicKey = globalSSHKey?.publicKey ?? null; - - const onSubmit = useCallback( - (params: GitImportRequestParams) => { - gitImport(params); - }, - [gitImport], - ); - - return ( - - ); + return ; } export default ImportModal; diff --git a/app/client/src/git/components/OpsModal/TabDeploy/DeployPreview.tsx b/app/client/src/git/components/OpsModal/TabDeploy/DeployPreview.tsx index 311019abdc24..79abbe1439dc 100644 --- a/app/client/src/git/components/OpsModal/TabDeploy/DeployPreview.tsx +++ b/app/client/src/git/components/OpsModal/TabDeploy/DeployPreview.tsx @@ -1,4 +1,4 @@ -import React, { useCallback, useEffect, useState } from "react"; +import React from "react"; import styled from "styled-components"; import { useSelector } from "react-redux"; @@ -15,47 +15,32 @@ import SuccessTick from "pages/common/SuccessTick"; import { howMuchTimeBeforeText } from "utils/helpers"; import AnalyticsUtil from "ee/utils/AnalyticsUtil"; import { viewerURL } from "ee/RouteBuilder"; -import { Icon, Link, Text } from "@appsmith/ads"; +import { Link, Text } from "@appsmith/ads"; +import { importSvg } from "@appsmith/ads-old"; -const StyledIcon = styled(Icon)` - svg { - width: 30px; - height: 30px; - } -`; +const CloudyIcon = importSvg( + async () => import("assets/icons/ads/cloudy-line.svg"), +); const Container = styled.div` display: flex; flex: 1; flex-direction: row; gap: ${(props) => props.theme.spaces[6]}px; -`; - -interface DeployPreviewProps { - isCommitSuccess: boolean; -} - -export default function DeployPreview({ isCommitSuccess }: DeployPreviewProps) { - const [showSuccess, setShowSuccess] = useState(false); - useEffect( - function startTimerForCommitSuccessEffect() { - if (isCommitSuccess) { - setShowSuccess(true); - const timer = setTimeout(() => { - setShowSuccess(false); - }, 5000); + .cloud-icon { + stroke: var(--ads-v2-color-fg); + } +`; - return () => clearTimeout(timer); - } - }, - [isCommitSuccess], - ); +export default function DeployPreview() { + // ! case: should reset after timer + const showSuccess = false; const basePageId = useSelector(getCurrentBasePageId); const lastDeployedAt = useSelector(getApplicationLastDeployedAt); - const showDeployPreview = useCallback(() => { + const showDeployPreview = () => { AnalyticsUtil.logEvent("GS_LAST_DEPLOYED_PREVIEW_LINK_CLICK", { source: "GIT_DEPLOY_MODAL", }); @@ -64,7 +49,7 @@ export default function DeployPreview({ isCommitSuccess }: DeployPreviewProps) { }); window.open(path, "_blank"); - }, [basePageId]); + }; const lastDeployedAtMsg = lastDeployedAt ? `${createMessage(LATEST_DP_SUBTITLE)} ${howMuchTimeBeforeText( @@ -81,7 +66,7 @@ export default function DeployPreview({ isCommitSuccess }: DeployPreviewProps) { {showSuccess ? ( ) : ( - + )}
diff --git a/app/client/src/git/components/OpsModal/TabDeploy/TabDeployView.tsx b/app/client/src/git/components/OpsModal/TabDeploy/TabDeployView.tsx index a2db0f28805d..d22c93f79b97 100644 --- a/app/client/src/git/components/OpsModal/TabDeploy/TabDeployView.tsx +++ b/app/client/src/git/components/OpsModal/TabDeploy/TabDeployView.tsx @@ -108,7 +108,6 @@ function TabDeployView({ statusBehindCount = 0, statusIsClean = false, }: TabDeployViewProps) { - const [hasSubmitted, setHasSubmitted] = useState(false); const hasChangesToCommit = !statusIsClean; const commitInputRef = useRef(null); const [commitMessage, setCommitMessage] = useState( @@ -158,10 +157,6 @@ function TabDeployView({ ((pullRequired && !isConflicting) || (statusBehindCount > 0 && statusIsClean)); - const isCommitSuccess = useMemo(() => { - return hasSubmitted && !isCommitLoading; - }, [isCommitLoading, hasSubmitted]); - useEffect( function focusCommitInputEffect() { if (!commitInputDisabled && commitInputRef.current) { @@ -205,7 +200,6 @@ function TabDeployView({ }); if (currentBranch) { - setHasSubmitted(true); commit(commitMessage.trim()); } }, [commit, commitMessage, currentBranch]); @@ -359,9 +353,7 @@ function TabDeployView({ /> )} - {!pullRequired && !isConflicting && ( - - )} + {!pullRequired && !isConflicting && }
diff --git a/app/client/src/git/components/OpsModal/index.tsx b/app/client/src/git/components/OpsModal/index.tsx index 66ea3ddf0182..114439c29902 100644 --- a/app/client/src/git/components/OpsModal/index.tsx +++ b/app/client/src/git/components/OpsModal/index.tsx @@ -1,15 +1,14 @@ import React from "react"; import OpsModalView from "./OpsModalView"; +import useProtectedBranches from "git/hooks/useProtectedBranches"; import useMetadata from "git/hooks/useMetadata"; import useStatus from "git/hooks/useStatus"; import useOps from "git/hooks/useOps"; -import useProtectedMode from "git/hooks/useProtectedMode"; -import { GitOpsTab } from "git/constants/enums"; export default function OpsModal() { - const { isOpsModalOpen, opsModalTab, toggleOpsModal } = useOps(); + const { opsModalOpen, opsModalTab, toggleOpsModal } = useOps(); const { fetchStatus } = useStatus(); - const isProtectedMode = useProtectedMode(); + const { isProtectedMode } = useProtectedBranches(); const { metadata } = useMetadata(); @@ -18,9 +17,9 @@ export default function OpsModal() { return ( diff --git a/app/client/src/git/components/ProtectedBranchCallout/ProtectedBranchCalloutView.tsx b/app/client/src/git/components/ProtectedBranchCallout/ProtectedBranchCalloutView.tsx deleted file mode 100644 index 89b37bbfa239..000000000000 --- a/app/client/src/git/components/ProtectedBranchCallout/ProtectedBranchCalloutView.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import React, { useCallback, useMemo } from "react"; -import { Callout } from "@appsmith/ads"; -import styled from "styled-components"; -import { - BRANCH_PROTECTION_CALLOUT_CREATE_BRANCH, - BRANCH_PROTECTION_CALLOUT_MSG, - BRANCH_PROTECTION_CALLOUT_UNPROTECT, - BRANCH_PROTECTION_CALLOUT_UNPROTECT_LOADING, - createMessage, -} from "ee/constants/messages"; -import { noop } from "lodash"; -import type { FetchProtectedBranchesResponseData } from "git/requests/fetchProtectedBranchesRequest.types"; - -export const PROTECTED_CALLOUT_HEIGHT = 70; - -const StyledCallout = styled(Callout)` - height: ${PROTECTED_CALLOUT_HEIGHT}px; - overflow-y: hidden; -`; - -interface ProtectedBranchCalloutViewProps { - currentBranch: string | null; - isUpdateProtectedBranchesLoading: boolean; - protectedBranches: FetchProtectedBranchesResponseData | null; - toggleBranchPopup: (isOpen: boolean) => void; - updateProtectedBranches: (branches: string[]) => void; -} - -function ProtectedBranchCalloutView({ - currentBranch = null, - isUpdateProtectedBranchesLoading = false, - protectedBranches = null, - toggleBranchPopup = noop, - updateProtectedBranches = noop, -}: ProtectedBranchCalloutViewProps) { - const handleClickOnNewBranch = useCallback(() => { - toggleBranchPopup(true); - }, [toggleBranchPopup]); - - const handleClickOnUnprotect = useCallback(() => { - const allBranches = protectedBranches || []; - const remainingBranches = allBranches.filter( - (protectedBranch) => protectedBranch !== currentBranch, - ); - - updateProtectedBranches(remainingBranches); - }, [currentBranch, protectedBranches, updateProtectedBranches]); - - const links = useMemo( - () => [ - { - key: "create-branch", - "data-testid": "t--git-protected-create-branch-cta", - children: createMessage(BRANCH_PROTECTION_CALLOUT_CREATE_BRANCH), - onClick: handleClickOnNewBranch, - }, - { - key: "unprotect", - "data-testid": "t--git-protected-unprotect-branch-cta", - children: isUpdateProtectedBranchesLoading - ? createMessage(BRANCH_PROTECTION_CALLOUT_UNPROTECT_LOADING) - : createMessage(BRANCH_PROTECTION_CALLOUT_UNPROTECT), - onClick: handleClickOnUnprotect, - isDisabled: isUpdateProtectedBranchesLoading, - }, - ], - [ - handleClickOnNewBranch, - handleClickOnUnprotect, - isUpdateProtectedBranchesLoading, - ], - ); - - return ( - - {createMessage(BRANCH_PROTECTION_CALLOUT_MSG)} - - ); -} - -export default ProtectedBranchCalloutView; diff --git a/app/client/src/git/components/ProtectedBranchCallout/index.tsx b/app/client/src/git/components/ProtectedBranchCallout/index.tsx deleted file mode 100644 index aca08dfc1e87..000000000000 --- a/app/client/src/git/components/ProtectedBranchCallout/index.tsx +++ /dev/null @@ -1,33 +0,0 @@ -import React from "react"; -import ProtectedBranchCalloutView from "./ProtectedBranchCalloutView"; -import useProtectedBranches from "git/hooks/useProtectedBranches"; -import useCurrentBranch from "git/hooks/useCurrentBranch"; -import useBranches from "git/hooks/useBranches"; -import useProtectedMode from "git/hooks/useProtectedMode"; - -function ProtectedBranchCallout() { - const isProtectedMode = useProtectedMode(); - const currentBranch = useCurrentBranch(); - const { toggleBranchPopup } = useBranches(); - const { - isUpdateProtectedBranchesLoading, - protectedBranches, - updateProtectedBranches, - } = useProtectedBranches(); - - if (!isProtectedMode) { - return null; - } - - return ( - - ); -} - -export default ProtectedBranchCallout; diff --git a/app/client/src/git/components/QuickActions/QuickActionsView.test.tsx b/app/client/src/git/components/QuickActions/QuickActionsView.test.tsx index f6bc193bfc7e..6e696ddffe55 100644 --- a/app/client/src/git/components/QuickActions/QuickActionsView.test.tsx +++ b/app/client/src/git/components/QuickActions/QuickActionsView.test.tsx @@ -29,7 +29,7 @@ describe("QuickActionsView Component", () => { isConnectPermitted: true, isDiscardLoading: false, isFetchStatusLoading: false, - isConnected: false, + isGitConnected: false, isProtectedMode: false, isPullFailing: false, isPullLoading: false, @@ -48,7 +48,7 @@ describe("QuickActionsView Component", () => { jest.clearAllMocks(); }); - it("should render ConnectButton when isConnected is false", () => { + it("should render ConnectButton when isGitConnected is false", () => { render( @@ -57,10 +57,10 @@ describe("QuickActionsView Component", () => { expect(screen.getByTestId("connect-button")).toBeInTheDocument(); }); - it("should render QuickActionButtons when isConnected is true", () => { + it("should render QuickActionButtons when isGitConnected is true", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, }; const { container } = render( @@ -86,7 +86,7 @@ describe("QuickActionsView Component", () => { it("should render Statusbar when isAutocommitEnabled and isPollingAutocommit are true", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, isAutocommitEnabled: true, isAutocommitPolling: true, }; @@ -106,7 +106,7 @@ describe("QuickActionsView Component", () => { it("should call onCommitClick when commit button is clicked", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, }; const { container } = render( @@ -131,7 +131,7 @@ describe("QuickActionsView Component", () => { it("should call onPullClick when pull button is clicked", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, isDiscardLoading: false, isPullLoading: false, isFetchStatusLoading: false, @@ -159,7 +159,7 @@ describe("QuickActionsView Component", () => { it("should call onMerge when merge button is clicked", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, }; const { container } = render( @@ -184,7 +184,7 @@ describe("QuickActionsView Component", () => { it("should call onSettingsClick when settings button is clicked", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, }; const { container } = render( @@ -209,7 +209,7 @@ describe("QuickActionsView Component", () => { it("should disable commit button when isProtectedMode is true", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, isProtectedMode: true, }; @@ -228,7 +228,7 @@ describe("QuickActionsView Component", () => { it("should show loading state on pull button when showPullLoadingState is true", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, isPullLoading: true, }; @@ -250,7 +250,7 @@ describe("QuickActionsView Component", () => { it("should display changesToCommit count on commit button", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, statusChangeCount: 5, }; @@ -267,7 +267,7 @@ describe("QuickActionsView Component", () => { it("should not display count on commit button when isProtectedMode is true", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, isProtectedMode: true, statusChangeCount: 5, }; @@ -292,7 +292,7 @@ describe("QuickActionsView Component", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, }; const { container } = render( @@ -310,7 +310,7 @@ describe("QuickActionsView Component", () => { it("should show behindCount on pull button", () => { const props = { ...defaultProps, - isConnected: true, + isGitConnected: true, statusBehindCount: 3, statusIsClean: true, }; diff --git a/app/client/src/git/components/QuickActions/QuickActionsView.tsx b/app/client/src/git/components/QuickActions/QuickActionsView.tsx index 274dd00f3dba..396984788015 100644 --- a/app/client/src/git/components/QuickActions/QuickActionsView.tsx +++ b/app/client/src/git/components/QuickActions/QuickActionsView.tsx @@ -33,7 +33,7 @@ interface QuickActionsViewProps { isConnectPermitted: boolean; isDiscardLoading: boolean; isFetchStatusLoading: boolean; - isConnected: boolean; + isGitConnected: boolean; isProtectedMode: boolean; isPullFailing: boolean; isPullLoading: boolean; @@ -57,10 +57,10 @@ function QuickActionsView({ isAutocommitEnabled = false, isAutocommitPolling = false, isBranchPopupOpen = false, - isConnected = false, isConnectPermitted = false, isDiscardLoading = false, isFetchStatusLoading = false, + isGitConnected = false, isProtectedMode = false, isPullFailing = false, isPullLoading = false, @@ -131,7 +131,7 @@ function QuickActionsView({ toggleConnectModal(true); }, [toggleConnectModal]); - return isConnected ? ( + return isGitConnected ? ( ); diff --git a/app/client/src/git/components/StatusChanges/StatusChangesView.tsx b/app/client/src/git/components/StatusChanges/StatusChangesView.tsx index f8e6f0c41dfa..c3768c0d866c 100644 --- a/app/client/src/git/components/StatusChanges/StatusChangesView.tsx +++ b/app/client/src/git/components/StatusChanges/StatusChangesView.tsx @@ -1,19 +1,14 @@ import type { FetchStatusResponseData } from "git/requests/fetchStatusRequest.types"; import React, { useMemo } from "react"; +import type { StatusTreeStruct } from "./StatusTree"; import StatusTree from "./StatusTree"; -import { Callout, Text } from "@appsmith/ads"; +import { Text } from "@appsmith/ads"; import { createMessage } from "@appsmith/ads-old"; import { CHANGES_SINCE_LAST_DEPLOYMENT, FETCH_GIT_STATUS, } from "ee/constants/messages"; -import StatusLoader from "./StatusLoader"; -import type { StatusTreeStruct } from "./types"; -import styled from "styled-components"; - -const CalloutContainer = styled.div` - margin-top: 16px; -`; +import StatusLoader from "pages/Editor/gitSync/components/StatusLoader"; const noopStatusTransformer = () => null; @@ -54,11 +49,6 @@ export default function StatusChangesView({ {createMessage(CHANGES_SINCE_LAST_DEPLOYMENT)} - {status.migrationMessage ? ( - - {status.migrationMessage} - - ) : null} ); } diff --git a/app/client/src/git/components/StatusChanges/StatusLoader.tsx b/app/client/src/git/components/StatusChanges/StatusLoader.tsx index 9026b75b38fa..bc0427bd6521 100644 --- a/app/client/src/git/components/StatusChanges/StatusLoader.tsx +++ b/app/client/src/git/components/StatusChanges/StatusLoader.tsx @@ -6,18 +6,16 @@ const LoaderWrapper = styled.div` display: flex; flex-direction: row; align-items: center; - margin-bottom: 8px; -`; - -const LoaderText = styled(Text)` - margin-left: 8px; + margin-top: ${(props) => `${props.theme.spaces[3]}px`}; `; function StatusLoader({ loaderMsg }: { loaderMsg: string }) { return ( - {loaderMsg} + + {loaderMsg} + ); } diff --git a/app/client/src/git/components/StatusChanges/StatusTree.tsx b/app/client/src/git/components/StatusChanges/StatusTree.tsx index 437163d394df..289d2d28b796 100644 --- a/app/client/src/git/components/StatusChanges/StatusTree.tsx +++ b/app/client/src/git/components/StatusChanges/StatusTree.tsx @@ -7,17 +7,12 @@ import { Text, } from "@appsmith/ads"; import clsx from "clsx"; -import styled from "styled-components"; -import type { StatusTreeStruct } from "./types"; -const StyledCollapsible = styled(Collapsible)` - gap: 0; -`; - -const StyledCollapsibleHeader = styled(CollapsibleHeader)` - padding-top: 0; - padding-bottom: 0; -`; +export interface StatusTreeStruct { + icon: string; + message: string; + children?: StatusTreeStruct[]; +} interface StatusTreeNodeProps { icon: string; @@ -48,31 +43,29 @@ interface SingleStatusTreeProps { function SingleStatusTree({ depth = 1, tree }: SingleStatusTreeProps) { if (!tree) return null; - const noEmphasis = depth > 1 && !tree.children; - if (!tree.children) { return ( 2} /> ); } return ( - - + + - + {tree.children.map((child, index) => ( ))} - + ); } diff --git a/app/client/src/git/components/StatusChanges/types.ts b/app/client/src/git/components/StatusChanges/types.ts deleted file mode 100644 index 61a8e074714b..000000000000 --- a/app/client/src/git/components/StatusChanges/types.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface StatusTreeStruct { - icon: string; - message: string; - children?: StatusTreeStruct[]; -} diff --git a/app/client/src/git/components/index.tsx b/app/client/src/git/components/index.tsx new file mode 100644 index 000000000000..c3a1640dbd01 --- /dev/null +++ b/app/client/src/git/components/index.tsx @@ -0,0 +1,3 @@ +export { default as GitModals } from "git/ee/components/GitModals"; +export { default as GitImportModal } from "./ImportModal"; +export { default as GitQuickActions } from "./QuickActions"; diff --git a/app/client/src/git/hooks/useArtifactSelector.ts b/app/client/src/git/hooks/useArtifactSelector.ts deleted file mode 100644 index dba2a0808bf3..000000000000 --- a/app/client/src/git/hooks/useArtifactSelector.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { useGitContext } from "git/components/GitContextProvider"; -import type { GitArtifactDef, GitRootState } from "git/store/types"; -import { useSelector } from "react-redux"; -import type { Tail } from "redux-saga/effects"; - -/** - * This hook is used to select data from the redux store based on the artifactDef. - **/ -export default function useArtifactSelector< - // need any type to properly infer the return type - /* eslint-disable @typescript-eslint/no-explicit-any */ - Fn extends (state: any, artifactDef: GitArtifactDef, ...args: any[]) => any, ->(selector: Fn, ...args: Tail>>): ReturnType | null { - const { artifactDef } = useGitContext(); - - return useSelector((state: GitRootState) => { - if (typeof selector !== "function" || !artifactDef) { - return null; - } - - const { artifactType, baseArtifactId } = artifactDef; - - if (!state.git?.artifacts?.[artifactType]?.[baseArtifactId]) { - return null; - } - - return selector(state, artifactDef, ...args); - }); -} diff --git a/app/client/src/git/hooks/useAutocommit.ts b/app/client/src/git/hooks/useAutocommit.ts index 91ad0e8aaae5..73d7d955caca 100644 --- a/app/client/src/git/hooks/useAutocommit.ts +++ b/app/client/src/git/hooks/useAutocommit.ts @@ -6,50 +6,50 @@ import { selectAutocommitPolling, selectToggleAutocommitState, selectTriggerAutocommitState, -} from "git/store/selectors/gitArtifactSelectors"; +} from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function useAutocommit() { const { artifactDef } = useGitContext(); const dispatch = useDispatch(); - const toggleAutocommitState = useArtifactSelector( - selectToggleAutocommitState, + const toggleAutocommitState = useSelector((state: GitRootState) => + selectToggleAutocommitState(state, artifactDef), ); - const triggerAutocommitState = useArtifactSelector( - selectTriggerAutocommitState, + const triggerAutocommitState = useSelector((state: GitRootState) => + selectTriggerAutocommitState(state, artifactDef), ); const toggleAutocommit = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.toggleAutocommitInit({ artifactDef })); - } + dispatch(gitArtifactActions.toggleAutocommitInit(artifactDef)); }, [artifactDef, dispatch]); - const isAutocommitDisableModalOpen = useArtifactSelector( - selectAutocommitDisableModalOpen, + const isAutocommitDisableModalOpen = useSelector((state: GitRootState) => + selectAutocommitDisableModalOpen(state, artifactDef), ); const toggleAutocommitDisableModal = useCallback( (open: boolean) => { - if (artifactDef) { - dispatch( - gitArtifactActions.toggleAutocommitDisableModal({ - artifactDef, - open, - }), - ); - } + dispatch( + gitArtifactActions.toggleAutocommitDisableModal({ + ...artifactDef, + open, + }), + ); }, [artifactDef, dispatch], ); - const isAutocommitEnabled = useArtifactSelector(selectAutocommitEnabled); + const isAutocommitEnabled = useSelector((state: GitRootState) => + selectAutocommitEnabled(state, artifactDef), + ); - const isAutocommitPolling = useArtifactSelector(selectAutocommitPolling); + const isAutocommitPolling = useSelector((state: GitRootState) => + selectAutocommitPolling(state, artifactDef), + ); return { isToggleAutocommitLoading: toggleAutocommitState?.loading ?? false, @@ -57,9 +57,9 @@ export default function useAutocommit() { toggleAutocommit, isTriggerAutocommitLoading: triggerAutocommitState?.loading ?? false, triggerAutocommitError: triggerAutocommitState?.error ?? null, - isAutocommitDisableModalOpen: isAutocommitDisableModalOpen ?? false, + isAutocommitDisableModalOpen, toggleAutocommitDisableModal, - isAutocommitEnabled: isAutocommitEnabled ?? false, - isAutocommitPolling: isAutocommitPolling ?? false, + isAutocommitEnabled, + isAutocommitPolling, }; } diff --git a/app/client/src/git/hooks/useBranches.ts b/app/client/src/git/hooks/useBranches.ts index fe85a318b8d4..4a0ecead44d7 100644 --- a/app/client/src/git/hooks/useBranches.ts +++ b/app/client/src/git/hooks/useBranches.ts @@ -8,105 +8,103 @@ import { selectCreateBranchState, selectDeleteBranchState, selectCurrentBranch, -} from "git/store/selectors/gitArtifactSelectors"; +} from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function useBranches() { - const { artifact, artifactDef } = useGitContext(); - const artifactId = artifact?.id; + const { artifactDef } = useGitContext(); const dispatch = useDispatch(); // fetch branches - const branchesState = useArtifactSelector(selectFetchBranchesState); - + const branchesState = useSelector((state: GitRootState) => + selectFetchBranchesState(state, artifactDef), + ); const fetchBranches = useCallback(() => { - if (artifactDef && artifactId) { - dispatch( - gitArtifactActions.fetchBranchesInit({ - artifactId, - artifactDef, - pruneBranches: true, - }), - ); - } - }, [artifactDef, artifactId, dispatch]); + dispatch( + gitArtifactActions.fetchBranchesInit({ + ...artifactDef, + pruneBranches: true, + }), + ); + }, [artifactDef, dispatch]); // create branch - const createBranchState = useArtifactSelector(selectCreateBranchState); + const createBranchState = useSelector((state: GitRootState) => + selectCreateBranchState(state, artifactDef), + ); const createBranch = useCallback( (branchName: string) => { - if (artifactDef && artifactId) { - dispatch( - gitArtifactActions.createBranchInit({ - artifactDef, - artifactId, - branchName, - }), - ); - } + dispatch( + gitArtifactActions.createBranchInit({ + ...artifactDef, + branchName, + }), + ); }, - [artifactDef, artifactId, dispatch], + [artifactDef, dispatch], ); // delete branch - const deleteBranchState = useArtifactSelector(selectDeleteBranchState); + const deleteBranchState = useSelector((state: GitRootState) => + selectDeleteBranchState(state, artifactDef), + ); const deleteBranch = useCallback( (branchName: string) => { - if (artifactDef && artifactId) { - dispatch( - gitArtifactActions.deleteBranchInit({ - artifactId, - artifactDef, - branchName, - }), - ); - } + dispatch( + gitArtifactActions.deleteBranchInit({ + ...artifactDef, + branchName, + }), + ); }, - [artifactDef, artifactId, dispatch], + [artifactDef, dispatch], ); // checkout branch - const checkoutBranchState = useArtifactSelector(selectCheckoutBranchState); + const checkoutBranchState = useSelector((state: GitRootState) => + selectCheckoutBranchState(state, artifactDef), + ); const checkoutBranch = useCallback( (branchName: string) => { - if (artifactDef && artifactId) { - dispatch( - gitArtifactActions.checkoutBranchInit({ - artifactDef, - artifactId, - branchName, - }), - ); - } + dispatch( + gitArtifactActions.checkoutBranchInit({ + ...artifactDef, + branchName, + }), + ); }, - [artifactDef, artifactId, dispatch], + [artifactDef, dispatch], ); - const checkoutDestBranch = useArtifactSelector(selectCheckoutDestBranch); + const checkoutDestBranch = useSelector((state: GitRootState) => + selectCheckoutDestBranch(state, artifactDef), + ); // derived - const currentBranch = useArtifactSelector(selectCurrentBranch); + const currentBranch = useSelector((state: GitRootState) => + selectCurrentBranch(state, artifactDef), + ); // git branch list popup - const isBranchPopupOpen = useArtifactSelector(selectBranchPopupOpen); + const isBranchPopupOpen = useSelector((state: GitRootState) => + selectBranchPopupOpen(state, artifactDef), + ); const toggleBranchPopup = useCallback( (open: boolean) => { - if (artifactDef) { - dispatch( - gitArtifactActions.toggleBranchPopup({ - artifactDef, - open, - }), - ); - } + dispatch( + gitArtifactActions.toggleBranchPopup({ + ...artifactDef, + open, + }), + ); }, [artifactDef, dispatch], ); return { - branches: branchesState?.value ?? null, + branches: branchesState?.value, isFetchBranchesLoading: branchesState?.loading ?? false, fetchBranchesError: branchesState?.error ?? null, fetchBranches, @@ -121,7 +119,7 @@ export default function useBranches() { checkoutBranch, checkoutDestBranch, currentBranch: currentBranch ?? null, - isBranchPopupOpen: isBranchPopupOpen ?? false, + isBranchPopupOpen, toggleBranchPopup, }; } diff --git a/app/client/src/git/hooks/useCommit.ts b/app/client/src/git/hooks/useCommit.ts index 6a468046a84b..56f78cc11bcd 100644 --- a/app/client/src/git/hooks/useCommit.ts +++ b/app/client/src/git/hooks/useCommit.ts @@ -1,43 +1,38 @@ import { useGitContext } from "git/components/GitContextProvider"; import { gitArtifactActions } from "git/store/gitArtifactSlice"; -import { selectCommitState } from "git/store/selectors/gitArtifactSelectors"; +import { selectCommitState } from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function useCommit() { - const { artifact, artifactDef } = useGitContext(); - const artifactId = artifact?.id; - + const { artifactDef } = useGitContext(); const dispatch = useDispatch(); - const commitState = useArtifactSelector(selectCommitState); + const commitState = useSelector((state: GitRootState) => + selectCommitState(state, artifactDef), + ); const commit = useCallback( (commitMessage: string) => { - if (artifactDef && artifactId) { - dispatch( - gitArtifactActions.commitInit({ - artifactId, - artifactDef, - commitMessage, - doPush: true, - }), - ); - } + dispatch( + gitArtifactActions.commitInit({ + ...artifactDef, + commitMessage, + doPush: true, + }), + ); }, - [artifactDef, artifactId, dispatch], + [artifactDef, dispatch], ); const clearCommitError = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.clearCommitError({ artifactDef })); - } + dispatch(gitArtifactActions.clearCommitError(artifactDef)); }, [artifactDef, dispatch]); return { isCommitLoading: commitState?.loading ?? false, - commitError: commitState?.error ?? null, + commitError: commitState?.error, commit, clearCommitError, }; diff --git a/app/client/src/git/hooks/useConnect.ts b/app/client/src/git/hooks/useConnect.ts index 884addac0fd7..1064ce7ff26e 100644 --- a/app/client/src/git/hooks/useConnect.ts +++ b/app/client/src/git/hooks/useConnect.ts @@ -4,53 +4,82 @@ import { gitArtifactActions } from "git/store/gitArtifactSlice"; import { selectConnectModalOpen, selectConnectState, - selectConnectSuccessModalOpen, -} from "git/store/selectors/gitArtifactSelectors"; + selectFetchSSHKeysState, + selectGenerateSSHKeyState, + selectGitImportState, +} from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useSelector } from "react-redux"; export default function useConnect() { const { artifactDef } = useGitContext(); const dispatch = useDispatch(); - const connectState = useArtifactSelector(selectConnectState); + const connectState = useSelector((state: GitRootState) => + selectConnectState(state, artifactDef), + ); const connect = useCallback( (params: ConnectRequestParams) => { - if (artifactDef) { - dispatch(gitArtifactActions.connectInit({ artifactDef, ...params })); - } + dispatch(gitArtifactActions.connectInit({ ...artifactDef, ...params })); }, [artifactDef, dispatch], ); - const isConnectModalOpen = useArtifactSelector(selectConnectModalOpen); + const gitImportState = useSelector((state: GitRootState) => + selectGitImportState(state, artifactDef), + ); - const toggleConnectModal = useCallback( - (open: boolean) => { - if (artifactDef) { - dispatch(gitArtifactActions.toggleConnectModal({ artifactDef, open })); - } + const gitImport = useCallback( + (params) => { + dispatch(gitArtifactActions.gitImportInit({ ...artifactDef, ...params })); + }, + [artifactDef, dispatch], + ); + + const fetchSSHKeyState = useSelector((state: GitRootState) => + selectFetchSSHKeysState(state, artifactDef), + ); + + const fetchSSHKey = useCallback(() => { + dispatch(gitArtifactActions.fetchSSHKeyInit(artifactDef)); + }, [artifactDef, dispatch]); + + const resetFetchSSHKey = useCallback(() => { + dispatch(gitArtifactActions.resetFetchSSHKey(artifactDef)); + }, [artifactDef, dispatch]); + + const generateSSHKeyState = useSelector((state: GitRootState) => + selectGenerateSSHKeyState(state, artifactDef), + ); + + const generateSSHKey = useCallback( + (keyType: string, isImport: boolean = false) => { + dispatch( + gitArtifactActions.generateSSHKeyInit({ + ...artifactDef, + keyType, + isImport, + }), + ); }, [artifactDef, dispatch], ); - const isConnectSuccessModalOpen = useArtifactSelector( - selectConnectSuccessModalOpen, + const resetGenerateSSHKey = useCallback(() => { + dispatch(gitArtifactActions.resetGenerateSSHKey(artifactDef)); + }, [artifactDef, dispatch]); + + const isConnectModalOpen = useSelector((state: GitRootState) => + selectConnectModalOpen(state, artifactDef), ); - const toggleConnectSuccessModal = useCallback( + const toggleConnectModal = useCallback( (open: boolean) => { - if (artifactDef) { - dispatch( - gitArtifactActions.toggleConnectSuccessModal({ - artifactDef, - open, - }), - ); - } + dispatch(gitArtifactActions.toggleConnectModal({ ...artifactDef, open })); }, [artifactDef, dispatch], ); @@ -59,9 +88,19 @@ export default function useConnect() { isConnectLoading: connectState?.loading ?? false, connectError: connectState?.error ?? null, connect, - isConnectModalOpen: isConnectModalOpen ?? false, + isGitImportLoading: gitImportState?.loading ?? false, + gitImportError: gitImportState?.error ?? null, + gitImport, + sshKey: fetchSSHKeyState?.value ?? null, + isFetchSSHKeyLoading: fetchSSHKeyState?.loading ?? false, + fetchSSHKeyError: fetchSSHKeyState?.error ?? null, + fetchSSHKey, + resetFetchSSHKey, + isGenerateSSHKeyLoading: generateSSHKeyState?.loading ?? false, + generateSSHKeyError: generateSSHKeyState?.error ?? null, + generateSSHKey, + resetGenerateSSHKey, + isConnectModalOpen, toggleConnectModal, - isConnectSuccessModalOpen: isConnectSuccessModalOpen ?? false, - toggleConnectSuccessModal, }; } diff --git a/app/client/src/git/hooks/useConnected.ts b/app/client/src/git/hooks/useConnected.ts deleted file mode 100644 index 39cfa55ca245..000000000000 --- a/app/client/src/git/hooks/useConnected.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { selectConnected } from "git/store/selectors/gitArtifactSelectors"; -import useArtifactSelector from "./useArtifactSelector"; - -export default function useConnected() { - const isConnected = useArtifactSelector(selectConnected); - - return isConnected ?? false; -} diff --git a/app/client/src/git/hooks/useCurrentBranch.ts b/app/client/src/git/hooks/useCurrentBranch.ts deleted file mode 100644 index 797d8d598ba5..000000000000 --- a/app/client/src/git/hooks/useCurrentBranch.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { selectCurrentBranch } from "git/store/selectors/gitArtifactSelectors"; -import useArtifactSelector from "./useArtifactSelector"; - -export default function useCurrentBranch() { - const currentBranch = useArtifactSelector(selectCurrentBranch); - - return currentBranch; -} diff --git a/app/client/src/git/hooks/useDiscard.ts b/app/client/src/git/hooks/useDiscard.ts index 19818cb7f8fa..2f71c11608f9 100644 --- a/app/client/src/git/hooks/useDiscard.ts +++ b/app/client/src/git/hooks/useDiscard.ts @@ -1,26 +1,24 @@ import { useGitContext } from "git/components/GitContextProvider"; import { gitArtifactActions } from "git/store/gitArtifactSlice"; -import { selectDiscardState } from "git/store/selectors/gitArtifactSelectors"; +import { selectDiscardState } from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function useDiscard() { const { artifactDef } = useGitContext(); const dispatch = useDispatch(); - const discardState = useArtifactSelector(selectDiscardState); + const discardState = useSelector((state: GitRootState) => + selectDiscardState(state, artifactDef), + ); const discard = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.discardInit({ artifactDef })); - } + dispatch(gitArtifactActions.discardInit(artifactDef)); }, [artifactDef, dispatch]); const clearDiscardError = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.clearDiscardError({ artifactDef })); - } + dispatch(gitArtifactActions.clearDiscardError(artifactDef)); }, [artifactDef, dispatch]); return { diff --git a/app/client/src/git/hooks/useDisconnect.ts b/app/client/src/git/hooks/useDisconnect.ts index 42fd878319fd..36dfd2cf8cf9 100644 --- a/app/client/src/git/hooks/useDisconnect.ts +++ b/app/client/src/git/hooks/useDisconnect.ts @@ -4,10 +4,10 @@ import { selectDisconnectArtifactName, selectDisconnectBaseArtifactId, selectDisconnectState, -} from "git/store/selectors/gitArtifactSelectors"; +} from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function useDisconnect() { const { artifact, artifactDef } = useGitContext(); @@ -15,38 +15,30 @@ export default function useDisconnect() { const dispatch = useDispatch(); - const disconnectState = useArtifactSelector(selectDisconnectState); + const disconnectState = useSelector((state: GitRootState) => + selectDisconnectState(state, artifactDef), + ); const disconnect = useCallback(() => { - if (artifactDef) { - dispatch( - gitArtifactActions.disconnectInit({ - artifactDef, - }), - ); - } + dispatch(gitArtifactActions.disconnectInit(artifactDef)); }, [artifactDef, dispatch]); - const disconnectBaseArtifactId = useArtifactSelector( - selectDisconnectBaseArtifactId, + const disconnectBaseArtifactId = useSelector((state: GitRootState) => + selectDisconnectBaseArtifactId(state, artifactDef), ); - const disconnectArtifactName = useArtifactSelector( - selectDisconnectArtifactName, + const disconnectArtifactName = useSelector((state: GitRootState) => + selectDisconnectArtifactName(state, artifactDef), ); const openDisconnectModal = useCallback(() => { - if (artifactDef) { - dispatch( - gitArtifactActions.openDisconnectModal({ artifactDef, artifactName }), - ); - } + dispatch( + gitArtifactActions.openDisconnectModal({ ...artifactDef, artifactName }), + ); }, [artifactDef, artifactName, dispatch]); const closeDisconnectModal = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.closeDisconnectModal({ artifactDef })); - } + dispatch(gitArtifactActions.closeDisconnectModal(artifactDef)); }, [artifactDef, dispatch]); return { diff --git a/app/client/src/git/hooks/useGitPermissions.ts b/app/client/src/git/hooks/useGitPermissions.ts index 13ca2404a161..3279dcd3e00e 100644 --- a/app/client/src/git/hooks/useGitPermissions.ts +++ b/app/client/src/git/hooks/useGitPermissions.ts @@ -10,46 +10,47 @@ import { useMemo } from "react"; export default function useGitPermissions() { const { artifact, artifactDef } = useGitContext(); + const { artifactType } = artifactDef; const isConnectPermitted = useMemo(() => { if (artifact) { - if (artifactDef?.artifactType === GitArtifactType.Application) { + if (artifactType === GitArtifactType.Application) { return hasConnectToGitPermission(artifact.userPermissions); } } return false; - }, [artifact, artifactDef?.artifactType]); + }, [artifact, artifactType]); const isManageDefaultBranchPermitted = useMemo(() => { if (artifact) { - if (artifactDef?.artifactType === GitArtifactType.Application) { + if (artifactType === GitArtifactType.Application) { return hasManageDefaultBranchPermission(artifact.userPermissions); } } return false; - }, [artifact, artifactDef?.artifactType]); + }, [artifact, artifactType]); const isManageProtectedBranchesPermitted = useMemo(() => { if (artifact) { - if (artifactDef?.artifactType === GitArtifactType.Application) { + if (artifactType === GitArtifactType.Application) { return hasManageProtectedBranchesPermission(artifact.userPermissions); } } return false; - }, [artifact, artifactDef?.artifactType]); + }, [artifact, artifactType]); const isManageAutocommitPermitted = useMemo(() => { if (artifact) { - if (artifactDef?.artifactType === GitArtifactType.Application) { + if (artifactType === GitArtifactType.Application) { return hasManageAutoCommitPermission(artifact.userPermissions); } } return false; - }, [artifact, artifactDef?.artifactType]); + }, [artifact, artifactType]); return { isConnectPermitted, diff --git a/app/client/src/git/hooks/useGlobalProfile.ts b/app/client/src/git/hooks/useGlobalProfile.ts index 3cc3a80aad98..f319f9c1f5db 100644 --- a/app/client/src/git/hooks/useGlobalProfile.ts +++ b/app/client/src/git/hooks/useGlobalProfile.ts @@ -1,9 +1,9 @@ import type { UpdateGlobalProfileRequestParams } from "git/requests/updateGlobalProfileRequest.types"; -import { gitGlobalActions } from "git/store/gitGlobalSlice"; +import { gitConfigActions } from "git/store/gitConfigSlice"; import { selectFetchGlobalProfileState, selectUpdateGlobalProfileState, -} from "git/store/selectors/gitGlobalSelectors"; +} from "git/store/selectors/gitConfigSelectors"; import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; @@ -16,7 +16,7 @@ export default function useGlobalProfile() { ); const fetchGlobalProfile = useCallback(() => { - dispatch(gitGlobalActions.fetchGlobalProfileInit()); + dispatch(gitConfigActions.fetchGlobalProfileInit()); }, [dispatch]); const updateGlobalProfileState = useSelector((state: GitRootState) => @@ -25,7 +25,7 @@ export default function useGlobalProfile() { const updateGlobalProfile = useCallback( (params: UpdateGlobalProfileRequestParams) => { - dispatch(gitGlobalActions.updateGlobalProfileInit(params)); + dispatch(gitConfigActions.updateGlobalProfileInit(params)); }, [dispatch], ); diff --git a/app/client/src/git/hooks/useGlobalSSHKey.ts b/app/client/src/git/hooks/useGlobalSSHKey.ts deleted file mode 100644 index ac7216045a6a..000000000000 --- a/app/client/src/git/hooks/useGlobalSSHKey.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { useCallback } from "react"; -import { useDispatch, useSelector } from "react-redux"; -import { selectFetchGlobalSSHKeyState } from "git/store/selectors/gitGlobalSelectors"; -import { gitGlobalActions } from "git/store/gitGlobalSlice"; - -export default function useGlobalSSHKey() { - const dispatch = useDispatch(); - - const globalSSHKeyState = useSelector(selectFetchGlobalSSHKeyState); - - const fetchGlobalSSHKey = useCallback( - (keyType: string) => { - dispatch(gitGlobalActions.fetchGlobalSSHKeyInit({ keyType })); - }, - [dispatch], - ); - - const resetGlobalSSHKey = useCallback(() => { - dispatch(gitGlobalActions.resetGlobalSSHKey()); - }, [dispatch]); - - return { - globalSSHKey: globalSSHKeyState?.value ?? null, - globalSSHKeyError: globalSSHKeyState?.error ?? null, - isFetchGlobalSSHKeyLoading: globalSSHKeyState?.loading ?? false, - fetchGlobalSSHKey, - resetGlobalSSHKey, - }; -} diff --git a/app/client/src/git/hooks/useImport.ts b/app/client/src/git/hooks/useImport.ts deleted file mode 100644 index 62069b888d68..000000000000 --- a/app/client/src/git/hooks/useImport.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { useCallback } from "react"; -import { useDispatch, useSelector } from "react-redux"; -import { - selectGitImportState, - selectImportModalOpen, -} from "git/store/selectors/gitGlobalSelectors"; -import { gitGlobalActions } from "git/store/gitGlobalSlice"; -import type { GitImportRequestParams } from "git/requests/gitImportRequest.types"; - -export default function useImport() { - const dispatch = useDispatch(); - - const gitImportState = useSelector(selectGitImportState); - - const gitImport = useCallback( - (params: GitImportRequestParams) => { - dispatch(gitGlobalActions.gitImportInit(params)); - }, - [dispatch], - ); - - const isImportModalOpen = useSelector(selectImportModalOpen); - - const toggleImportModal = useCallback( - (open: boolean) => { - dispatch(gitGlobalActions.toggleImportModal({ open })); - }, - [dispatch], - ); - - return { - isGitImportLoading: gitImportState?.loading ?? false, - gitImportError: gitImportState?.error ?? null, - gitImport, - isImportModalOpen: isImportModalOpen ?? false, - toggleImportModal, - }; -} diff --git a/app/client/src/git/hooks/useLocalProfile.ts b/app/client/src/git/hooks/useLocalProfile.ts index 8d77899a7602..e770ad6356bc 100644 --- a/app/client/src/git/hooks/useLocalProfile.ts +++ b/app/client/src/git/hooks/useLocalProfile.ts @@ -4,40 +4,36 @@ import { gitArtifactActions } from "git/store/gitArtifactSlice"; import { selectFetchLocalProfileState, selectUpdateLocalProfileState, -} from "git/store/selectors/gitArtifactSelectors"; +} from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function useLocalProfile() { const { artifactDef } = useGitContext(); const dispatch = useDispatch(); - const fetchLocalProfileState = useArtifactSelector( - selectFetchLocalProfileState, + const fetchLocalProfileState = useSelector((state: GitRootState) => + selectFetchLocalProfileState(state, artifactDef), ); const fetchLocalProfile = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.fetchLocalProfileInit({ artifactDef })); - } + dispatch(gitArtifactActions.fetchLocalProfileInit(artifactDef)); }, [artifactDef, dispatch]); - const updateLocalProfileState = useArtifactSelector( - selectUpdateLocalProfileState, + const updateLocalProfileState = useSelector((state: GitRootState) => + selectUpdateLocalProfileState(state, artifactDef), ); const updateLocalProfile = useCallback( (params: UpdateLocalProfileRequestParams) => { - if (artifactDef) { - dispatch( - gitArtifactActions.updateLocalProfileInit({ - artifactDef, - ...params, - }), - ); - } + dispatch( + gitArtifactActions.updateLocalProfileInit({ + ...artifactDef, + ...params, + }), + ); }, [artifactDef, dispatch], ); diff --git a/app/client/src/git/hooks/useMerge.ts b/app/client/src/git/hooks/useMerge.ts index 8fa79b16049f..f7394601b191 100644 --- a/app/client/src/git/hooks/useMerge.ts +++ b/app/client/src/git/hooks/useMerge.ts @@ -3,10 +3,10 @@ import { gitArtifactActions } from "git/store/gitArtifactSlice"; import { selectMergeState, selectMergeStatusState, -} from "git/store/selectors/gitArtifactSelectors"; +} from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function useMerge() { const { artifact, artifactDef } = useGitContext(); @@ -14,46 +14,44 @@ export default function useMerge() { const dispatch = useDispatch(); // merge - const mergeState = useArtifactSelector(selectMergeState); + const mergeState = useSelector((state: GitRootState) => + selectMergeState(state, artifactDef), + ); const merge = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.mergeInit({ artifactDef })); - } + dispatch(gitArtifactActions.mergeInit(artifactDef)); }, [artifactDef, dispatch]); // merge status - const mergeStatusState = useArtifactSelector(selectMergeStatusState); + const mergeStatusState = useSelector((state: GitRootState) => + selectMergeStatusState(state, artifactDef), + ); const fetchMergeStatus = useCallback( (sourceBranch: string, destinationBranch: string) => { - if (artifactDef) { - dispatch( - gitArtifactActions.fetchMergeStatusInit({ - artifactDef, - artifactId: artifactId ?? "", - sourceBranch, - destinationBranch, - }), - ); - } + dispatch( + gitArtifactActions.fetchMergeStatusInit({ + ...artifactDef, + artifactId: artifactId ?? "", + sourceBranch, + destinationBranch, + }), + ); }, [artifactId, artifactDef, dispatch], ); const clearMergeStatus = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.clearMergeStatus({ artifactDef })); - } + dispatch(gitArtifactActions.clearMergeStatus(artifactDef)); }, [artifactDef, dispatch]); return { isMergeLoading: mergeState?.loading ?? false, - mergeError: mergeState?.error ?? null, + mergeError: mergeState?.error, merge, - mergeStatus: mergeStatusState?.value ?? null, + mergeStatus: mergeStatusState?.value, isFetchMergeStatusLoading: mergeStatusState?.loading ?? false, - fetchMergeStatusError: mergeStatusState?.error ?? null, + fetchMergeStatusError: mergeStatusState?.error, fetchMergeStatus, clearMergeStatus, }; diff --git a/app/client/src/git/hooks/useMetadata.ts b/app/client/src/git/hooks/useMetadata.ts index 2ccd15d7ec89..9bd5356ad763 100644 --- a/app/client/src/git/hooks/useMetadata.ts +++ b/app/client/src/git/hooks/useMetadata.ts @@ -1,12 +1,26 @@ -import { selectMetadataState } from "git/store/selectors/gitArtifactSelectors"; -import useArtifactSelector from "./useArtifactSelector"; +import { useGitContext } from "git/components/GitContextProvider"; +import { + selectGitConnected, + selectMetadataState, +} from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; +import { useSelector } from "react-redux"; export default function useMetadata() { - const metadataState = useArtifactSelector(selectMetadataState); + const { artifactDef } = useGitContext(); + + const metadataState = useSelector((state: GitRootState) => + selectMetadataState(state, artifactDef), + ); + + const isGitConnected = useSelector((state: GitRootState) => + selectGitConnected(state, artifactDef), + ); return { metadata: metadataState?.value ?? null, isFetchMetadataLoading: metadataState?.loading ?? false, fetchMetadataError: metadataState?.error ?? null, + isGitConnected, }; } diff --git a/app/client/src/git/hooks/useOps.ts b/app/client/src/git/hooks/useOps.ts index 9b15bd035d85..32eec997cf25 100644 --- a/app/client/src/git/hooks/useOps.ts +++ b/app/client/src/git/hooks/useOps.ts @@ -5,10 +5,10 @@ import { selectConflictErrorModalOpen, selectOpsModalOpen, selectOpsModalTab, -} from "git/store/selectors/gitArtifactSelectors"; +} from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function useOps() { const { artifactDef } = useGitContext(); @@ -16,40 +16,42 @@ export default function useOps() { const dispatch = useDispatch(); // ops modal - const opsModalOpen = useArtifactSelector(selectOpsModalOpen); + const opsModalOpen = useSelector((state: GitRootState) => + selectOpsModalOpen(state, artifactDef), + ); - const opsModalTab = useArtifactSelector(selectOpsModalTab); + const opsModalTab = useSelector((state: GitRootState) => + selectOpsModalTab(state, artifactDef), + ); const toggleOpsModal = useCallback( (open: boolean, tab: keyof typeof GitOpsTab = GitOpsTab.Deploy) => { - if (artifactDef) { - dispatch(gitArtifactActions.toggleOpsModal({ artifactDef, open, tab })); - } + dispatch( + gitArtifactActions.toggleOpsModal({ ...artifactDef, open, tab }), + ); }, [artifactDef, dispatch], ); // conflict error modal - const conflictErrorModalOpen = useArtifactSelector( - selectConflictErrorModalOpen, + const conflictErrorModalOpen = useSelector((state: GitRootState) => + selectConflictErrorModalOpen(state, artifactDef), ); const toggleConflictErrorModal = useCallback( (open: boolean) => { - if (artifactDef) { - dispatch( - gitArtifactActions.toggleConflictErrorModal({ artifactDef, open }), - ); - } + dispatch( + gitArtifactActions.toggleConflictErrorModal({ ...artifactDef, open }), + ); }, [artifactDef, dispatch], ); return { opsModalTab, - isOpsModalOpen: opsModalOpen ?? false, + opsModalOpen, toggleOpsModal, - isConflictErrorModalOpen: conflictErrorModalOpen ?? false, + conflictErrorModalOpen, toggleConflictErrorModal, }; } diff --git a/app/client/src/git/hooks/useProtectedBranches.ts b/app/client/src/git/hooks/useProtectedBranches.ts index 6ec68ee23b74..fa3b2ef89307 100644 --- a/app/client/src/git/hooks/useProtectedBranches.ts +++ b/app/client/src/git/hooks/useProtectedBranches.ts @@ -2,55 +2,55 @@ import { useGitContext } from "git/components/GitContextProvider"; import { gitArtifactActions } from "git/store/gitArtifactSlice"; import { selectFetchProtectedBranchesState, + selectProtectedMode, selectUpdateProtectedBranchesState, -} from "git/store/selectors/gitArtifactSelectors"; +} from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; function useProtectedBranches() { const { artifactDef } = useGitContext(); const dispatch = useDispatch(); - const fetchProtectedBranchesState = useArtifactSelector( - selectFetchProtectedBranchesState, + const fetchProtectedBranchesState = useSelector((state: GitRootState) => + selectFetchProtectedBranchesState(state, artifactDef), ); const fetchProtectedBranches = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.fetchProtectedBranchesInit({ artifactDef })); - } + dispatch(gitArtifactActions.fetchProtectedBranchesInit(artifactDef)); }, [dispatch, artifactDef]); - const updateProtectedBranchesState = useArtifactSelector( - selectUpdateProtectedBranchesState, + const updateProtectedBranchesState = useSelector((state: GitRootState) => + selectUpdateProtectedBranchesState(state, artifactDef), ); const updateProtectedBranches = useCallback( (branches: string[]) => { - if (artifactDef) { - dispatch( - gitArtifactActions.updateProtectedBranchesInit({ - artifactDef, - branchNames: branches, - }), - ); - } + dispatch( + gitArtifactActions.updateProtectedBranchesInit({ + ...artifactDef, + branchNames: branches, + }), + ); }, [dispatch, artifactDef], ); + const isProtectedMode = useSelector((state: GitRootState) => + selectProtectedMode(state, artifactDef), + ); + return { - protectedBranches: fetchProtectedBranchesState?.value ?? null, - isFetchProtectedBranchesLoading: - fetchProtectedBranchesState?.loading ?? false, - fetchProtectedBranchesError: fetchProtectedBranchesState?.error ?? null, + protectedBranches: fetchProtectedBranchesState.value, + isFetchProtectedBranchesLoading: fetchProtectedBranchesState.loading, + fetchProtectedBranchesError: fetchProtectedBranchesState.error, fetchProtectedBranches, - isUpdateProtectedBranchesLoading: - updateProtectedBranchesState?.loading ?? false, - updateProtectedBranchesError: updateProtectedBranchesState?.error ?? null, + isUpdateProtectedBranchesLoading: updateProtectedBranchesState.loading, + updateProtectedBranchesError: updateProtectedBranchesState.error, updateProtectedBranches, + isProtectedMode, }; } diff --git a/app/client/src/git/hooks/useProtectedMode.ts b/app/client/src/git/hooks/useProtectedMode.ts deleted file mode 100644 index e8e86e9f04a2..000000000000 --- a/app/client/src/git/hooks/useProtectedMode.ts +++ /dev/null @@ -1,8 +0,0 @@ -import { selectProtectedMode } from "git/store/selectors/gitArtifactSelectors"; -import useArtifactSelector from "./useArtifactSelector"; - -export default function useProtectedMode() { - const isProtectedMode = useArtifactSelector(selectProtectedMode); - - return isProtectedMode ?? false; -} diff --git a/app/client/src/git/hooks/usePull.ts b/app/client/src/git/hooks/usePull.ts index 19900c98f38e..992866f2c277 100644 --- a/app/client/src/git/hooks/usePull.ts +++ b/app/client/src/git/hooks/usePull.ts @@ -1,26 +1,26 @@ import { useGitContext } from "git/components/GitContextProvider"; import { gitArtifactActions } from "git/store/gitArtifactSlice"; -import { selectPullState } from "git/store/selectors/gitArtifactSelectors"; +import { selectPullState } from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function usePull() { const { artifact, artifactDef } = useGitContext(); const artifactId = artifact?.id; const dispatch = useDispatch(); - const pullState = useArtifactSelector(selectPullState); + const pullState = useSelector((state: GitRootState) => + selectPullState(state, artifactDef), + ); const pull = useCallback(() => { - if (artifactDef) { - dispatch( - gitArtifactActions.pullInit({ - artifactDef, - artifactId: artifactId ?? "", - }), - ); - } + dispatch( + gitArtifactActions.pullInit({ + ...artifactDef, + artifactId: artifactId ?? "", + }), + ); }, [artifactDef, artifactId, dispatch]); return { diff --git a/app/client/src/git/hooks/useSSHKey.ts b/app/client/src/git/hooks/useSSHKey.ts deleted file mode 100644 index 93c95ade8d31..000000000000 --- a/app/client/src/git/hooks/useSSHKey.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { useGitContext } from "git/components/GitContextProvider"; -import { gitArtifactActions } from "git/store/gitArtifactSlice"; -import { - selectFetchSSHKeysState, - selectGenerateSSHKeyState, -} from "git/store/selectors/gitArtifactSelectors"; -import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; - -export default function useSSHKey() { - const { artifactDef } = useGitContext(); - - const dispatch = useDispatch(); - - const fetchSSHKeyState = useArtifactSelector(selectFetchSSHKeysState); - - const fetchSSHKey = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.fetchSSHKeyInit({ artifactDef })); - } - }, [artifactDef, dispatch]); - - const resetFetchSSHKey = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.resetFetchSSHKey({ artifactDef })); - } - }, [artifactDef, dispatch]); - - const generateSSHKeyState = useArtifactSelector(selectGenerateSSHKeyState); - - const generateSSHKey = useCallback( - (keyType: string) => { - if (artifactDef) { - dispatch( - gitArtifactActions.generateSSHKeyInit({ - artifactDef, - keyType, - }), - ); - } - }, - [artifactDef, dispatch], - ); - - const resetGenerateSSHKey = useCallback(() => { - if (artifactDef) { - dispatch(gitArtifactActions.resetGenerateSSHKey({ artifactDef })); - } - }, [artifactDef, dispatch]); - - return { - sshKey: fetchSSHKeyState?.value ?? null, - isFetchSSHKeyLoading: fetchSSHKeyState?.loading ?? false, - fetchSSHKeyError: fetchSSHKeyState?.error ?? null, - fetchSSHKey, - resetFetchSSHKey, - isGenerateSSHKeyLoading: generateSSHKeyState?.loading ?? false, - generateSSHKeyError: generateSSHKeyState?.error ?? null, - generateSSHKey, - resetGenerateSSHKey, - }; -} diff --git a/app/client/src/git/hooks/useSettings.ts b/app/client/src/git/hooks/useSettings.ts index 0a8b48aa368c..d94f9c0e530b 100644 --- a/app/client/src/git/hooks/useSettings.ts +++ b/app/client/src/git/hooks/useSettings.ts @@ -4,37 +4,39 @@ import { gitArtifactActions } from "git/store/gitArtifactSlice"; import { selectSettingsModalOpen, selectSettingsModalTab, -} from "git/store/selectors/gitArtifactSelectors"; +} from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function useSettings() { const { artifactDef } = useGitContext(); const dispatch = useDispatch(); - const settingsModalOpen = useArtifactSelector(selectSettingsModalOpen); + const settingsModalOpen = useSelector((state: GitRootState) => + selectSettingsModalOpen(state, artifactDef), + ); - const settingsModalTab = useArtifactSelector(selectSettingsModalTab); + const settingsModalTab = useSelector((state: GitRootState) => + selectSettingsModalTab(state, artifactDef), + ); const toggleSettingsModal = useCallback( ( open: boolean, tab: keyof typeof GitSettingsTab = GitSettingsTab.General, ) => { - if (artifactDef) { - dispatch( - gitArtifactActions.toggleSettingsModal({ artifactDef, open, tab }), - ); - } + dispatch( + gitArtifactActions.toggleSettingsModal({ ...artifactDef, open, tab }), + ); }, [artifactDef, dispatch], ); return { isSettingsModalOpen: settingsModalOpen ?? false, - settingsModalTab: settingsModalTab, + settingsModalTab: settingsModalTab ?? GitSettingsTab.General, toggleSettingsModal, }; } diff --git a/app/client/src/git/hooks/useStatus.ts b/app/client/src/git/hooks/useStatus.ts index 37a5584911aa..97b09b57498a 100644 --- a/app/client/src/git/hooks/useStatus.ts +++ b/app/client/src/git/hooks/useStatus.ts @@ -1,33 +1,31 @@ import { useGitContext } from "git/components/GitContextProvider"; import { gitArtifactActions } from "git/store/gitArtifactSlice"; -import { selectStatusState } from "git/store/selectors/gitArtifactSelectors"; +import { selectStatusState } from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitRootState } from "git/store/types"; import { useCallback } from "react"; -import { useDispatch } from "react-redux"; -import useArtifactSelector from "./useArtifactSelector"; +import { useDispatch, useSelector } from "react-redux"; export default function useStatus() { - const { artifact, artifactDef } = useGitContext(); - const artifactId = artifact?.id; + const { artifactDef } = useGitContext(); const dispatch = useDispatch(); - const statusState = useArtifactSelector(selectStatusState); + const statusState = useSelector((state: GitRootState) => + selectStatusState(state, artifactDef), + ); const fetchStatus = useCallback(() => { - if (artifactDef && artifactId) { - dispatch( - gitArtifactActions.fetchStatusInit({ - artifactId, - artifactDef, - compareRemote: true, - }), - ); - } - }, [artifactDef, artifactId, dispatch]); + dispatch( + gitArtifactActions.fetchStatusInit({ + ...artifactDef, + compareRemote: true, + }), + ); + }, [artifactDef, dispatch]); return { - status: statusState?.value ?? null, + status: statusState?.value, isFetchStatusLoading: statusState?.loading ?? false, - fetchStatusError: statusState?.error ?? null, + fetchStatusError: statusState?.error, fetchStatus, }; } diff --git a/app/client/src/git/index.ts b/app/client/src/git/index.ts deleted file mode 100644 index 892ca77d7f43..000000000000 --- a/app/client/src/git/index.ts +++ /dev/null @@ -1,39 +0,0 @@ -// enums -export { GitArtifactType, GitOpsTab } from "./constants/enums"; - -// components -export { default as GitContextProvider } from "./components/GitContextProvider"; -export { default as GitModals } from "./ee/components/GitModals"; -export { default as GitImportModal } from "./components/ImportModal"; -export { default as GitQuickActions } from "./components/QuickActions"; -export { default as GitProtectedBranchCallout } from "./components/ProtectedBranchCallout"; -export { default as GitGlobalProfile } from "./components/GlobalProfile"; -export { default as GitDeployMenuItems } from "./components/DeployMenuItems"; - -// hooks -export { default as useGitCurrentBranch } from "./hooks/useCurrentBranch"; -export { default as useGitProtectedMode } from "./hooks/useProtectedMode"; -export { default as useGitConnected } from "./hooks/useConnected"; -export { default as useGitOps } from "./hooks/useOps"; - -// actions -import { gitGlobalActions } from "./store/gitGlobalSlice"; -export const fetchGitGlobalProfile = gitGlobalActions.fetchGlobalProfileInit; -export const toggleGitImportModal = gitGlobalActions.toggleImportModal; - -import { gitArtifactActions } from "./store/gitArtifactSlice"; -export const gitConnectSuccess = gitArtifactActions.connectSuccess; - -// selectors -export { - selectCurrentBranch as selectGitCurrentBranch, - selectProtectedMode as selectGitProtectedMode, -} from "./store/selectors/gitArtifactSelectors"; - -// types -export type { - GitArtifactDef, - GitArtifactRootReduxState, - GitGlobalReduxState, -} from "./store/types"; -export type { ConnectSuccessPayload as GitConnectSuccessPayload } from "./store/actions/connectActions"; diff --git a/app/client/src/git/requests/connectRequest.types.ts b/app/client/src/git/requests/connectRequest.types.ts index d47cc4114b21..7e31cf32bf82 100644 --- a/app/client/src/git/requests/connectRequest.types.ts +++ b/app/client/src/git/requests/connectRequest.types.ts @@ -1,5 +1,4 @@ import type { ApiResponse } from "api/types"; -import type { ApplicationPayload } from "entities/Application"; export interface ConnectRequestParams { remoteUrl: string; @@ -10,6 +9,20 @@ export interface ConnectRequestParams { }; } -export interface ConnectResponseData extends ApplicationPayload {} +export interface ConnectResponseData { + id: string; + baseId: string; + gitApplicationMetadata: { + branchName: string; + browserSupportedRemoteUrl: string; + defaultApplicationId: string; + defaultArtifactId: string; + defaultBranchName: string; + isRepoPrivate: boolean; + lastCommitedAt: string; + remoteUrl: string; + repoName: string; + }; +} export type ConnectResponse = ApiResponse; diff --git a/app/client/src/git/requests/disconnectRequest.types.ts b/app/client/src/git/requests/disconnectRequest.types.ts index b1cd5827d951..2cbf5969ccca 100644 --- a/app/client/src/git/requests/disconnectRequest.types.ts +++ b/app/client/src/git/requests/disconnectRequest.types.ts @@ -1,6 +1,7 @@ import type { ApiResponse } from "api/types"; -import type { ApplicationPayload } from "entities/Application"; -export interface DisconnectResponseData extends ApplicationPayload {} +export interface DisconnectResponseData { + [key: string]: string; +} export type DisconnectResponse = ApiResponse; diff --git a/app/client/src/git/requests/fetchGlobalSSHKeyRequest.ts b/app/client/src/git/requests/fetchGlobalSSHKeyRequest.ts deleted file mode 100644 index 00d900637f42..000000000000 --- a/app/client/src/git/requests/fetchGlobalSSHKeyRequest.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { AxiosPromise } from "axios"; -import { GIT_BASE_URL } from "./constants"; -import Api from "api/Api"; -import type { - FetchGlobalSSHKeyRequestParams, - FetchGlobalSSHKeyResponse, -} from "./fetchGlobalSSHKeyRequest.types"; - -export default async function fetchGlobalSSHKeyRequest( - params: FetchGlobalSSHKeyRequestParams, -): AxiosPromise { - const url = `${GIT_BASE_URL}/import/keys?keyType=${params.keyType}`; - - return Api.get(url); -} diff --git a/app/client/src/git/requests/fetchGlobalSSHKeyRequest.types.ts b/app/client/src/git/requests/fetchGlobalSSHKeyRequest.types.ts deleted file mode 100644 index 7b092ceccff2..000000000000 --- a/app/client/src/git/requests/fetchGlobalSSHKeyRequest.types.ts +++ /dev/null @@ -1,15 +0,0 @@ -import type { ApiResponse } from "api/types"; - -export interface FetchGlobalSSHKeyRequestParams { - keyType: string; -} - -export interface FetchGlobalSSHKeyResponseData { - publicKey: string; - docUrl: string; - isRegeneratedKey: boolean; - regeneratedKey: boolean; -} - -export type FetchGlobalSSHKeyResponse = - ApiResponse; diff --git a/app/client/src/git/requests/fetchStatusRequest.types.ts b/app/client/src/git/requests/fetchStatusRequest.types.ts index feb064d3618d..c4400688b794 100644 --- a/app/client/src/git/requests/fetchStatusRequest.types.ts +++ b/app/client/src/git/requests/fetchStatusRequest.types.ts @@ -24,7 +24,6 @@ export interface FetchStatusResponseData { modifiedDatasources: number; modifiedJSLibs: number; modifiedJSObjects: number; - modifiedPackages: number; modifiedModuleInstances: number; modifiedModules: number; modifiedPages: number; diff --git a/app/client/src/git/requests/generateSSHKeyRequest.ts b/app/client/src/git/requests/generateSSHKeyRequest.ts index b0bea4f20ff8..896426347f30 100644 --- a/app/client/src/git/requests/generateSSHKeyRequest.ts +++ b/app/client/src/git/requests/generateSSHKeyRequest.ts @@ -3,14 +3,16 @@ import type { GenerateSSHKeyRequestParams, GenerateSSHKeyResponse, } from "./generateSSHKeyRequest.types"; -import { APPLICATION_BASE_URL } from "./constants"; +import { APPLICATION_BASE_URL, GIT_BASE_URL } from "./constants"; import Api from "api/Api"; export default async function generateSSHKeyRequest( baseApplicationId: string, params: GenerateSSHKeyRequestParams, ): AxiosPromise { - const url = `${APPLICATION_BASE_URL}/ssh-keypair/${baseApplicationId}?keyType=${params.keyType}`; + const url = params.isImport + ? `${GIT_BASE_URL}/import/keys?keyType=${params.keyType}` + : `${APPLICATION_BASE_URL}/ssh-keypair/${baseApplicationId}?keyType=${params.keyType}`; - return Api.post(url); + return params.isImport ? Api.get(url) : Api.post(url); } diff --git a/app/client/src/git/requests/generateSSHKeyRequest.types.ts b/app/client/src/git/requests/generateSSHKeyRequest.types.ts index fbc4a4c0e959..45374e42d5b1 100644 --- a/app/client/src/git/requests/generateSSHKeyRequest.types.ts +++ b/app/client/src/git/requests/generateSSHKeyRequest.types.ts @@ -2,6 +2,7 @@ import type { ApiResponse } from "api/types"; export interface GenerateSSHKeyRequestParams { keyType: string; + isImport: boolean; } export interface GenerateSSHKeyResponseData { diff --git a/app/client/src/git/requests/gitImportRequest.types.ts b/app/client/src/git/requests/gitImportRequest.types.ts index 4eb29b11a88b..9f76b379c9cc 100644 --- a/app/client/src/git/requests/gitImportRequest.types.ts +++ b/app/client/src/git/requests/gitImportRequest.types.ts @@ -1,6 +1,4 @@ import type { ApiResponse } from "api/types"; -import type { ApplicationResponsePayload } from "ee/api/ApplicationApi"; -import type { Datasource } from "entities/Datasource"; export interface GitImportRequestParams { remoteUrl: string; @@ -12,9 +10,19 @@ export interface GitImportRequestParams { } export interface GitImportResponseData { - application: ApplicationResponsePayload; - isPartialImport: boolean; - unconfiguredDatasourceList?: Datasource[]; + id: string; + baseId: string; + gitApplicationMetadata: { + branchName: string; + browserSupportedRemoteUrl: string; + defaultApplicationId: string; + defaultArtifactId: string; + defaultBranchName: string; + isRepoPrivate: boolean; + lastCommitedAt: string; + remoteUrl: string; + repoName: string; + }; } export type GitImportResponse = ApiResponse; diff --git a/app/client/src/git/sagas/checkoutBranchSaga.ts b/app/client/src/git/sagas/checkoutBranchSaga.ts index 7fc454f36bc0..34e48434626c 100644 --- a/app/client/src/git/sagas/checkoutBranchSaga.ts +++ b/app/client/src/git/sagas/checkoutBranchSaga.ts @@ -25,7 +25,8 @@ import { captureException } from "@sentry/react"; export default function* checkoutBranchSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef, artifactId, branchName } = action.payload; + const { artifactType, baseArtifactId, branchName } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: CheckoutBranchResponse | undefined; try { @@ -33,12 +34,12 @@ export default function* checkoutBranchSaga( branchName, }; - response = yield call(checkoutBranchRequest, artifactId, params); + response = yield call(checkoutBranchRequest, baseArtifactId, params); const isValidResponse: boolean = yield validateResponse(response); if (response && isValidResponse) { - if (artifactDef.artifactType === GitArtifactType.Application) { - yield put(gitArtifactActions.checkoutBranchSuccess({ artifactDef })); + if (artifactType === GitArtifactType.Application) { + yield put(gitArtifactActions.checkoutBranchSuccess(basePayload)); const trimmedBranch = branchName.replace(/^origin\//, ""); const destinationHref = addBranchParam(trimmedBranch); @@ -48,7 +49,7 @@ export default function* checkoutBranchSaga( yield put( gitArtifactActions.toggleBranchPopup({ - artifactDef, + ...basePayload, open: false, }), ); @@ -117,7 +118,7 @@ export default function* checkoutBranchSaga( yield put( gitArtifactActions.checkoutBranchError({ - artifactDef, + ...basePayload, error, }), ); diff --git a/app/client/src/git/sagas/commitSaga.ts b/app/client/src/git/sagas/commitSaga.ts index 7ebcb70b9a71..159021acc145 100644 --- a/app/client/src/git/sagas/commitSaga.ts +++ b/app/client/src/git/sagas/commitSaga.ts @@ -17,7 +17,8 @@ import { validateResponse } from "sagas/ErrorSagas"; export default function* commitSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef, artifactId } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: CommitResponse | undefined; @@ -27,21 +28,20 @@ export default function* commitSaga( doPush: action.payload.doPush, }; - response = yield call(commitRequest, artifactId, params); + response = yield call(commitRequest, baseArtifactId, params); const isValidResponse: boolean = yield validateResponse(response, false); if (isValidResponse) { - yield put(gitArtifactActions.commitSuccess({ artifactDef })); + yield put(gitArtifactActions.commitSuccess(basePayload)); yield put( gitArtifactActions.fetchStatusInit({ - artifactDef, - artifactId, + ...basePayload, compareRemote: true, }), ); - if (artifactDef.artifactType === GitArtifactType.Application) { + if (artifactType === GitArtifactType.Application) { // ! case for updating lastDeployedAt in application manually? } } @@ -52,13 +52,13 @@ export default function* commitSaga( if (error.code === GitErrorCodes.REPO_LIMIT_REACHED) { yield put( gitArtifactActions.toggleRepoLimitErrorModal({ - artifactDef, + ...basePayload, open: true, }), ); } - yield put(gitArtifactActions.commitError({ artifactDef, error })); + yield put(gitArtifactActions.commitError({ ...basePayload, error })); } else { log.error(e); captureException(e); diff --git a/app/client/src/git/sagas/connectSaga.ts b/app/client/src/git/sagas/connectSaga.ts index b6de0cdea53e..b13c2f6c2c2a 100644 --- a/app/client/src/git/sagas/connectSaga.ts +++ b/app/client/src/git/sagas/connectSaga.ts @@ -8,7 +8,7 @@ import { GitArtifactType, GitErrorCodes } from "../constants/enums"; import type { GitArtifactPayloadAction } from "../store/types"; import type { ConnectInitPayload } from "../store/actions/connectActions"; -import { call, put, select } from "redux-saga/effects"; +import { call, put } from "redux-saga/effects"; // Internal dependencies import { validateResponse } from "sagas/ErrorSagas"; @@ -17,12 +17,12 @@ import history from "utils/history"; import { addBranchParam } from "constants/routes"; import log from "loglevel"; import { captureException } from "@sentry/react"; -import { getCurrentPageId } from "selectors/editorSelectors"; export default function* connectSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: ConnectResponse | undefined; @@ -32,50 +32,34 @@ export default function* connectSaga( gitProfile: action.payload.gitProfile, }; - response = yield call(connectRequest, artifactDef.baseArtifactId, params); + response = yield call(connectRequest, baseArtifactId, params); const isValidResponse: boolean = yield validateResponse(response, false); if (response && isValidResponse) { - yield put( - gitArtifactActions.connectSuccess({ - artifactDef, - responseData: response.data, - }), - ); + yield put(gitArtifactActions.connectSuccess(basePayload)); // needs to happen only when artifactType is application - if (artifactDef.artifactType === GitArtifactType.Application) { - const pageId: string = yield select(getCurrentPageId); - - yield put(fetchPageAction(pageId)); - - const branch = response.data?.gitApplicationMetadata?.branchName; - - if (branch) { - const newUrl = addBranchParam(branch); + if (artifactType === GitArtifactType.Application) { + const { branchedPageId } = action.payload; - history.replace(newUrl); + if (branchedPageId) { + yield put(fetchPageAction(branchedPageId)); } + const branch = response.data.gitApplicationMetadata.branchName; + const newUrl = addBranchParam(branch); + + history.replace(newUrl); // ! case for updating lastDeployedAt in application manually? } yield put( gitArtifactActions.initGitForEditor({ - artifactDef, + ...basePayload, artifact: response.data, }), ); - yield put( - gitArtifactActions.toggleConnectModal({ artifactDef, open: false }), - ); - yield put( - gitArtifactActions.toggleConnectSuccessModal({ - artifactDef, - open: true, - }), - ); } } catch (e) { if (response && response.responseMeta.error) { @@ -84,13 +68,13 @@ export default function* connectSaga( if (GitErrorCodes.REPO_LIMIT_REACHED === error.code) { yield put( gitArtifactActions.toggleRepoLimitErrorModal({ - artifactDef, + ...basePayload, open: true, }), ); } - yield put(gitArtifactActions.connectError({ artifactDef, error })); + yield put(gitArtifactActions.connectError({ ...basePayload, error })); } else { log.error(e); captureException(e); diff --git a/app/client/src/git/sagas/createBranchSaga.ts b/app/client/src/git/sagas/createBranchSaga.ts index d8aa65418977..7796f43d74bd 100644 --- a/app/client/src/git/sagas/createBranchSaga.ts +++ b/app/client/src/git/sagas/createBranchSaga.ts @@ -16,8 +16,8 @@ import log from "loglevel"; export default function* createBranchSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef, artifactId } = action.payload; - const basePayload = { artifactDef }; + const { artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: CreateBranchResponse | undefined; try { @@ -25,29 +25,27 @@ export default function* createBranchSaga( branchName: action.payload.branchName, }; - response = yield call(createBranchRequest, artifactId, params); + response = yield call(createBranchRequest, baseArtifactId, params); const isValidResponse: boolean = yield validateResponse(response); if (isValidResponse) { yield put(gitArtifactActions.createBranchSuccess(basePayload)); yield put( gitArtifactActions.toggleBranchPopup({ - artifactDef, + ...basePayload, open: false, }), ); yield put( gitArtifactActions.fetchBranchesInit({ - artifactDef, - artifactId, + ...basePayload, pruneBranches: true, }), ); yield put( gitArtifactActions.checkoutBranchInit({ - artifactDef, - artifactId, + ...basePayload, branchName: action.payload.branchName, }), ); @@ -58,7 +56,7 @@ export default function* createBranchSaga( yield put( gitArtifactActions.createBranchError({ - artifactDef, + ...basePayload, error, }), ); diff --git a/app/client/src/git/sagas/deleteBranchSaga.ts b/app/client/src/git/sagas/deleteBranchSaga.ts index ecf560889f1c..4f6bdde2f7fc 100644 --- a/app/client/src/git/sagas/deleteBranchSaga.ts +++ b/app/client/src/git/sagas/deleteBranchSaga.ts @@ -16,7 +16,8 @@ import { captureException } from "@sentry/react"; export default function* deleteBranchSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef, artifactId } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: DeleteBranchResponse | undefined; try { @@ -24,19 +25,14 @@ export default function* deleteBranchSaga( branchName: action.payload.branchName, }; - response = yield call( - deleteBranchRequest, - artifactDef.baseArtifactId, - params, - ); + response = yield call(deleteBranchRequest, baseArtifactId, params); const isValidResponse: boolean = yield validateResponse(response); if (isValidResponse) { - yield put(gitArtifactActions.deleteBranchSuccess({ artifactDef })); + yield put(gitArtifactActions.deleteBranchSuccess(basePayload)); yield put( gitArtifactActions.fetchBranchesInit({ - artifactDef, - artifactId, + ...basePayload, pruneBranches: true, }), ); @@ -45,7 +41,12 @@ export default function* deleteBranchSaga( if (response && response.responseMeta.error) { const { error } = response.responseMeta; - yield put(gitArtifactActions.deleteBranchError({ artifactDef, error })); + yield put( + gitArtifactActions.deleteBranchError({ + ...basePayload, + error, + }), + ); } else { log.error(e); captureException(e); diff --git a/app/client/src/git/sagas/disconnectSaga.ts b/app/client/src/git/sagas/disconnectSaga.ts index ef6315c25cd5..3dc25f1ff079 100644 --- a/app/client/src/git/sagas/disconnectSaga.ts +++ b/app/client/src/git/sagas/disconnectSaga.ts @@ -12,30 +12,26 @@ import { validateResponse } from "sagas/ErrorSagas"; import history from "utils/history"; export default function* disconnectSaga(action: GitArtifactPayloadAction) { - const { artifactDef } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const artifactDef = { artifactType, baseArtifactId }; let response: DisconnectResponse | undefined; try { - response = yield call(disconnectRequest, artifactDef.baseArtifactId); + response = yield call(disconnectRequest, baseArtifactId); const isValidResponse: boolean = yield validateResponse(response); if (response && isValidResponse) { - yield put(gitArtifactActions.disconnectSuccess({ artifactDef })); + yield put(gitArtifactActions.disconnectSuccess(artifactDef)); const url = new URL(window.location.href); url.searchParams.delete(GIT_BRANCH_QUERY_KEY); - history.replace(url.toString().slice(url.origin.length)); - yield put(gitArtifactActions.unmount({ artifactDef })); - yield put( - gitArtifactActions.initGitForEditor({ - artifactDef, - artifact: response.data, - }), - ); - yield put(gitArtifactActions.closeDisconnectModal({ artifactDef })); + history.push(url.toString().slice(url.origin.length)); + yield put(gitArtifactActions.closeDisconnectModal(artifactDef)); + // !case: why? + // yield put(importAppViaGitStatusReset()); yield put( gitArtifactActions.toggleOpsModal({ - artifactDef, + ...artifactDef, open: false, tab: GitOpsTab.Deploy, }), @@ -56,7 +52,7 @@ export default function* disconnectSaga(action: GitArtifactPayloadAction) { if (response && response.responseMeta.error) { const { error } = response.responseMeta; - yield put(gitArtifactActions.disconnectError({ artifactDef, error })); + yield put(gitArtifactActions.disconnectError({ ...artifactDef, error })); } else { log.error(e); captureException(e); diff --git a/app/client/src/git/sagas/fetchBranchesSaga.ts b/app/client/src/git/sagas/fetchBranchesSaga.ts index 5141db03e34f..465310e01a4f 100644 --- a/app/client/src/git/sagas/fetchBranchesSaga.ts +++ b/app/client/src/git/sagas/fetchBranchesSaga.ts @@ -14,7 +14,8 @@ import { captureException } from "@sentry/react"; export default function* fetchBranchesSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef, artifactId } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: FetchBranchesResponse | undefined; try { @@ -22,13 +23,13 @@ export default function* fetchBranchesSaga( pruneBranches: action.payload.pruneBranches, }; - response = yield call(fetchBranchesRequest, artifactId, params); + response = yield call(fetchBranchesRequest, baseArtifactId, params); const isValidResponse: boolean = yield validateResponse(response, false); if (response && isValidResponse) { yield put( gitArtifactActions.fetchBranchesSuccess({ - artifactDef, + ...basePayload, responseData: response.data, }), ); @@ -39,7 +40,7 @@ export default function* fetchBranchesSaga( yield put( gitArtifactActions.fetchBranchesError({ - artifactDef, + ...basePayload, error, }), ); diff --git a/app/client/src/git/sagas/fetchGlobalProfileSaga.ts b/app/client/src/git/sagas/fetchGlobalProfileSaga.ts index 86713acf8787..71e7ca1a9c29 100644 --- a/app/client/src/git/sagas/fetchGlobalProfileSaga.ts +++ b/app/client/src/git/sagas/fetchGlobalProfileSaga.ts @@ -1,12 +1,12 @@ import { call, put } from "redux-saga/effects"; import fetchGlobalProfileRequest from "../requests/fetchGlobalProfileRequest"; import type { FetchGlobalProfileResponse } from "../requests/fetchGlobalProfileRequest.types"; +import { gitConfigActions } from "../store/gitConfigSlice"; // internal dependencies import { validateResponse } from "sagas/ErrorSagas"; import log from "loglevel"; import { captureException } from "@sentry/react"; -import { gitGlobalActions } from "git/store/gitGlobalSlice"; export default function* fetchGlobalProfileSaga() { let response: FetchGlobalProfileResponse | undefined; @@ -18,7 +18,7 @@ export default function* fetchGlobalProfileSaga() { if (response && isValidResponse) { yield put( - gitGlobalActions.fetchGlobalProfileSuccess({ + gitConfigActions.fetchGlobalProfileSuccess({ responseData: response.data, }), ); @@ -28,7 +28,7 @@ export default function* fetchGlobalProfileSaga() { const { error } = response.responseMeta; yield put( - gitGlobalActions.fetchGlobalProfileError({ + gitConfigActions.fetchGlobalProfileError({ error, }), ); diff --git a/app/client/src/git/sagas/fetchGlobalSSHKeySaga.ts b/app/client/src/git/sagas/fetchGlobalSSHKeySaga.ts deleted file mode 100644 index e72711961844..000000000000 --- a/app/client/src/git/sagas/fetchGlobalSSHKeySaga.ts +++ /dev/null @@ -1,44 +0,0 @@ -import { captureException } from "@sentry/react"; -import fetchGlobalSSHKeyRequest from "git/requests/fetchGlobalSSHKeyRequest"; -import type { - GenerateSSHKeyRequestParams, - GenerateSSHKeyResponse, -} from "git/requests/generateSSHKeyRequest.types"; -import type { FetchGlobalSSHKeyInitPayload } from "git/store/actions/fetchGlobalSSHKeyActions"; -import { gitGlobalActions } from "git/store/gitGlobalSlice"; -import type { GitArtifactPayloadAction } from "git/store/types"; -import log from "loglevel"; -import { call, put } from "redux-saga/effects"; -import { validateResponse } from "sagas/ErrorSagas"; - -export function* fetchGlobalSSHKeySaga( - action: GitArtifactPayloadAction, -) { - let response: GenerateSSHKeyResponse | undefined; - - try { - const params: GenerateSSHKeyRequestParams = { - keyType: action.payload.keyType, - }; - - response = yield call(fetchGlobalSSHKeyRequest, params); - const isValidResponse: boolean = yield validateResponse(response); - - if (response && isValidResponse) { - yield put( - gitGlobalActions.fetchGlobalSSHKeySuccess({ - responseData: response.data, - }), - ); - } - } catch (e) { - if (response && response.responseMeta.error) { - const { error } = response.responseMeta; - - yield put(gitGlobalActions.fetchGlobalSSHKeyError({ error })); - } else { - log.error(e); - captureException(e); - } - } -} diff --git a/app/client/src/git/sagas/fetchLocalProfileSaga.ts b/app/client/src/git/sagas/fetchLocalProfileSaga.ts index 28f24ef2198d..c568129beab9 100644 --- a/app/client/src/git/sagas/fetchLocalProfileSaga.ts +++ b/app/client/src/git/sagas/fetchLocalProfileSaga.ts @@ -10,17 +10,18 @@ import { captureException } from "@sentry/react"; export default function* fetchLocalProfileSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: FetchLocalProfileResponse | undefined; try { - response = yield call(fetchLocalProfileRequest, artifactDef.baseArtifactId); + response = yield call(fetchLocalProfileRequest, baseArtifactId); const isValidResponse: boolean = yield validateResponse(response); if (response && isValidResponse) { yield put( gitArtifactActions.fetchLocalProfileSuccess({ - artifactDef, + ...basePayload, responseData: response.data, }), ); @@ -30,7 +31,7 @@ export default function* fetchLocalProfileSaga( const { error } = response.responseMeta; yield put( - gitArtifactActions.fetchLocalProfileError({ artifactDef, error }), + gitArtifactActions.fetchLocalProfileError({ ...basePayload, error }), ); } else { log.error(e); diff --git a/app/client/src/git/sagas/fetchMergeStatusSaga.ts b/app/client/src/git/sagas/fetchMergeStatusSaga.ts index 024954b017c5..684233de206d 100644 --- a/app/client/src/git/sagas/fetchMergeStatusSaga.ts +++ b/app/client/src/git/sagas/fetchMergeStatusSaga.ts @@ -14,7 +14,8 @@ import { validateResponse } from "sagas/ErrorSagas"; export default function* fetchMergeStatusSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef, artifactId } = action.payload; + const { artifactId, artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: FetchMergeStatusResponse | undefined; try { @@ -29,7 +30,7 @@ export default function* fetchMergeStatusSaga( if (response && isValidResponse) { yield put( gitArtifactActions.fetchMergeStatusSuccess({ - artifactDef, + ...basePayload, responseData: response.data, }), ); @@ -39,7 +40,10 @@ export default function* fetchMergeStatusSaga( const { error } = response.responseMeta; yield put( - gitArtifactActions.fetchMergeStatusError({ artifactDef, error }), + gitArtifactActions.fetchMergeStatusError({ + ...basePayload, + error, + }), ); } else { log.error(e); diff --git a/app/client/src/git/sagas/fetchMetadataSaga.ts b/app/client/src/git/sagas/fetchMetadataSaga.ts index 9f8285847ee7..3e2029b6c6b8 100644 --- a/app/client/src/git/sagas/fetchMetadataSaga.ts +++ b/app/client/src/git/sagas/fetchMetadataSaga.ts @@ -8,17 +8,18 @@ import { call, put } from "redux-saga/effects"; import { validateResponse } from "sagas/ErrorSagas"; export default function* fetchMetadataSaga(action: GitArtifactPayloadAction) { - const { artifactDef } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: FetchMetadataResponse | undefined; try { - response = yield call(fetchMetadataRequest, artifactDef.baseArtifactId); + response = yield call(fetchMetadataRequest, baseArtifactId); const isValidResponse: boolean = yield validateResponse(response, false); if (response && isValidResponse) { yield put( gitArtifactActions.fetchMetadataSuccess({ - artifactDef, + ...basePayload, responseData: response.data, }), ); @@ -29,7 +30,7 @@ export default function* fetchMetadataSaga(action: GitArtifactPayloadAction) { yield put( gitArtifactActions.fetchMetadataError({ - artifactDef, + ...basePayload, error, }), ); diff --git a/app/client/src/git/sagas/fetchProtectedBranchesSaga.ts b/app/client/src/git/sagas/fetchProtectedBranchesSaga.ts index 62f36f8ce93c..9c81123ea26f 100644 --- a/app/client/src/git/sagas/fetchProtectedBranchesSaga.ts +++ b/app/client/src/git/sagas/fetchProtectedBranchesSaga.ts @@ -10,21 +10,19 @@ import { validateResponse } from "sagas/ErrorSagas"; export default function* fetchProtectedBranchesSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: FetchProtectedBranchesResponse | undefined; try { - response = yield call( - fetchProtectedBranchesRequest, - artifactDef.baseArtifactId, - ); + response = yield call(fetchProtectedBranchesRequest, baseArtifactId); const isValidResponse: boolean = yield validateResponse(response); if (response && isValidResponse) { yield put( gitArtifactActions.fetchProtectedBranchesSuccess({ - artifactDef, + ...basePayload, responseData: response.data, }), ); @@ -35,7 +33,7 @@ export default function* fetchProtectedBranchesSaga( yield put( gitArtifactActions.fetchProtectedBranchesError({ - artifactDef, + ...basePayload, error, }), ); diff --git a/app/client/src/git/sagas/fetchSSHKeySaga.ts b/app/client/src/git/sagas/fetchSSHKeySaga.ts index 16736e92f5d1..02f797edae66 100644 --- a/app/client/src/git/sagas/fetchSSHKeySaga.ts +++ b/app/client/src/git/sagas/fetchSSHKeySaga.ts @@ -8,17 +8,18 @@ import { call, put } from "redux-saga/effects"; import { validateResponse } from "sagas/ErrorSagas"; export function* fetchSSHKeySaga(action: GitArtifactPayloadAction) { - const { artifactDef } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const artifactDef = { artifactType, baseArtifactId }; let response: FetchSSHKeyResponse | undefined; try { - response = yield call(fetchSSHKeyRequest, artifactDef.baseArtifactId); + response = yield call(fetchSSHKeyRequest, baseArtifactId); const isValidResponse: boolean = yield validateResponse(response, false); if (response && isValidResponse) { yield put( gitArtifactActions.fetchSSHKeySuccess({ - artifactDef, + ...artifactDef, responseData: response.data, }), ); @@ -27,7 +28,7 @@ export function* fetchSSHKeySaga(action: GitArtifactPayloadAction) { if (response && response.responseMeta.error) { const { error } = response.responseMeta; - yield put(gitArtifactActions.fetchSSHKeyError({ artifactDef, error })); + yield put(gitArtifactActions.fetchSSHKeyError({ ...artifactDef, error })); } else { log.error(e); captureException(e); diff --git a/app/client/src/git/sagas/fetchStatusSaga.ts b/app/client/src/git/sagas/fetchStatusSaga.ts index 733f18cce776..4c714a22c0da 100644 --- a/app/client/src/git/sagas/fetchStatusSaga.ts +++ b/app/client/src/git/sagas/fetchStatusSaga.ts @@ -11,17 +11,18 @@ import { validateResponse } from "sagas/ErrorSagas"; export default function* fetchStatusSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef, artifactId } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: FetchStatusResponse | undefined; try { - response = yield call(fetchStatusRequest, artifactId); + response = yield call(fetchStatusRequest, baseArtifactId); const isValidResponse: boolean = yield validateResponse(response); if (response && isValidResponse) { yield put( gitArtifactActions.fetchStatusSuccess({ - artifactDef, + ...basePayload, responseData: response.data, }), ); @@ -32,7 +33,7 @@ export default function* fetchStatusSaga( yield put( gitArtifactActions.fetchStatusError({ - artifactDef, + ...basePayload, error, }), ); diff --git a/app/client/src/git/sagas/generateSSHKeySaga.ts b/app/client/src/git/sagas/generateSSHKeySaga.ts index afbccf24b2e6..09773f9dc0d4 100644 --- a/app/client/src/git/sagas/generateSSHKeySaga.ts +++ b/app/client/src/git/sagas/generateSSHKeySaga.ts @@ -15,25 +15,23 @@ import { validateResponse } from "sagas/ErrorSagas"; export function* generateSSHKeySaga( action: GitArtifactPayloadAction, ) { - const { artifactDef } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const artifactDef = { artifactType, baseArtifactId }; let response: GenerateSSHKeyResponse | undefined; try { const params: GenerateSSHKeyRequestParams = { keyType: action.payload.keyType, + isImport: action.payload.isImport, }; - response = yield call( - generateSSHKeyRequest, - artifactDef.baseArtifactId, - params, - ); + response = yield call(generateSSHKeyRequest, baseArtifactId, params); const isValidResponse: boolean = yield validateResponse(response); if (response && isValidResponse) { yield put( gitArtifactActions.generateSSHKeySuccess({ - artifactDef, + ...artifactDef, responseData: response.data, }), ); @@ -45,13 +43,15 @@ export function* generateSSHKeySaga( if (GitErrorCodes.REPO_LIMIT_REACHED === error.code) { yield put( gitArtifactActions.toggleRepoLimitErrorModal({ - artifactDef, + ...artifactDef, open: true, }), ); } - yield put(gitArtifactActions.generateSSHKeyError({ artifactDef, error })); + yield put( + gitArtifactActions.generateSSHKeyError({ ...artifactDef, error }), + ); } else { log.error(e); captureException(e); diff --git a/app/client/src/git/sagas/gitImportSaga.ts b/app/client/src/git/sagas/gitImportSaga.ts deleted file mode 100644 index ecf3d718ae08..000000000000 --- a/app/client/src/git/sagas/gitImportSaga.ts +++ /dev/null @@ -1,92 +0,0 @@ -import log from "loglevel"; -import { call, put, select } from "redux-saga/effects"; -import { validateResponse } from "sagas/ErrorSagas"; -import history from "utils/history"; -import { toast } from "@appsmith/ads"; -import type { PayloadAction } from "@reduxjs/toolkit"; -import { captureException } from "@sentry/react"; -import gitImportRequest from "git/requests/gitImportRequest"; -import type { GitImportResponse } from "git/requests/gitImportRequest.types"; -import type { GitImportInitPayload } from "git/store/actions/gitImportActions"; -import { gitGlobalActions } from "git/store/gitGlobalSlice"; -import { createMessage, IMPORT_APP_SUCCESSFUL } from "ee/constants/messages"; -import { builderURL } from "ee/RouteBuilder"; -import { getWorkspaceIdForImport } from "ee/selectors/applicationSelectors"; -import { showReconnectDatasourceModal } from "ee/actions/applicationActions"; -import type { Workspace } from "ee/constants/workspaceConstants"; -import { getFetchedWorkspaces } from "ee/selectors/workspaceSelectors"; - -export default function* gitImportSaga( - action: PayloadAction, -) { - const { ...params } = action.payload; - const workspaceId: string = yield select(getWorkspaceIdForImport); - - let response: GitImportResponse | undefined; - - try { - response = yield call(gitImportRequest, workspaceId, params); - const isValidResponse: boolean = yield validateResponse(response); - - if (response && isValidResponse) { - const allWorkspaces: Workspace[] = yield select(getFetchedWorkspaces); - const currentWorkspace = allWorkspaces.filter( - (el: Workspace) => el.id === workspaceId, - ); - - if (currentWorkspace.length > 0) { - const { application, isPartialImport, unconfiguredDatasourceList } = - response.data; - - yield put(gitGlobalActions.gitImportSuccess()); - yield put(gitGlobalActions.toggleImportModal({ open: false })); - - // there is configuration-missing datasources - if (isPartialImport) { - yield put( - showReconnectDatasourceModal({ - application: application, - unConfiguredDatasourceList: unconfiguredDatasourceList ?? [], - workspaceId, - }), - ); - } else { - let basePageId = ""; - - if (application.pages && application.pages.length > 0) { - const defaultPage = application.pages.find( - (eachPage) => !!eachPage.isDefault, - ); - - basePageId = defaultPage ? defaultPage.baseId : ""; - } - - const pageURL = builderURL({ - basePageId, - }); - - history.push(pageURL); - toast.show(createMessage(IMPORT_APP_SUCCESSFUL), { - kind: "success", - }); - } - } - } - } catch (e) { - // const isRepoLimitReachedError: boolean = yield call( - // handleRepoLimitReachedError, - // response, - // ); - - // if (isRepoLimitReachedError) return; - - if (response?.responseMeta?.error) { - yield put( - gitGlobalActions.gitImportError({ error: response.responseMeta.error }), - ); - } else { - log.error(e); - captureException(e); - } - } -} diff --git a/app/client/src/git/sagas/index.ts b/app/client/src/git/sagas/index.ts index 61c0a0747330..13e19bd4c9f8 100644 --- a/app/client/src/git/sagas/index.ts +++ b/app/client/src/git/sagas/index.ts @@ -8,6 +8,7 @@ import { import type { TakeableChannel } from "redux-saga"; import type { PayloadAction } from "@reduxjs/toolkit"; import { objectKeys } from "@appsmith/utils"; +import { gitConfigActions } from "../store/gitConfigSlice"; import { gitArtifactActions } from "../store/gitArtifactSlice"; import connectSaga from "./connectSaga"; import commitSaga from "./commitSaga"; @@ -36,9 +37,6 @@ import { blockingActionSagas as blockingActionSagasExtended, nonBlockingActionSagas as nonBlockingActionSagasExtended, } from "git/ee/sagas"; -import { gitGlobalActions } from "git/store/gitGlobalSlice"; -import { fetchGlobalSSHKeySaga } from "./fetchGlobalSSHKeySaga"; -import gitImportSaga from "./gitImportSaga"; const blockingActionSagas: Record< string, @@ -52,9 +50,6 @@ const blockingActionSagas: Record< [gitArtifactActions.connectInit.type]: connectSaga, [gitArtifactActions.disconnectInit.type]: disconnectSaga, - // import - [gitGlobalActions.gitImportInit.type]: gitImportSaga, - // ops [gitArtifactActions.commitInit.type]: commitSaga, [gitArtifactActions.fetchStatusInit.type]: fetchStatusSaga, @@ -70,8 +65,8 @@ const blockingActionSagas: Record< // user profiles [gitArtifactActions.fetchLocalProfileInit.type]: fetchLocalProfileSaga, [gitArtifactActions.updateLocalProfileInit.type]: updateLocalProfileSaga, - [gitGlobalActions.fetchGlobalProfileInit.type]: fetchGlobalProfileSaga, - [gitGlobalActions.updateGlobalProfileInit.type]: updateGlobalProfileSaga, + [gitConfigActions.fetchGlobalProfileInit.type]: fetchGlobalProfileSaga, + [gitConfigActions.updateGlobalProfileInit.type]: updateGlobalProfileSaga, // protected branches [gitArtifactActions.fetchProtectedBranchesInit.type]: @@ -98,7 +93,6 @@ const nonBlockingActionSagas: Record< // ssh key [gitArtifactActions.fetchSSHKeyInit.type]: fetchSSHKeySaga, [gitArtifactActions.generateSSHKeyInit.type]: generateSSHKeySaga, - [gitGlobalActions.fetchGlobalSSHKeyInit.type]: fetchGlobalSSHKeySaga, // EE ...nonBlockingActionSagasExtended, diff --git a/app/client/src/git/sagas/initGitSaga.ts b/app/client/src/git/sagas/initGitSaga.ts index b880b1854c41..aa50efce17b1 100644 --- a/app/client/src/git/sagas/initGitSaga.ts +++ b/app/client/src/git/sagas/initGitSaga.ts @@ -7,25 +7,24 @@ import { put, take } from "redux-saga/effects"; export default function* initGitForEditorSaga( action: GitArtifactPayloadAction, ) { - const { artifact, artifactDef } = action.payload; - const artifactId = artifact?.id; + const { artifact, artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; - yield put(gitArtifactActions.mount({ artifactDef })); + yield put(gitArtifactActions.mount(basePayload)); - if (artifactId && artifactDef.artifactType === GitArtifactType.Application) { - if (!!artifact?.gitApplicationMetadata?.remoteUrl) { - yield put(gitArtifactActions.fetchMetadataInit({ artifactDef })); + if (artifactType === GitArtifactType.Application) { + if (!!artifact.gitApplicationMetadata?.remoteUrl) { + yield put(gitArtifactActions.fetchMetadataInit(basePayload)); yield take(gitArtifactActions.fetchMetadataSuccess.type); yield put( - gitArtifactActions.triggerAutocommitInit({ artifactDef, artifactId }), - ); - yield put( - gitArtifactActions.fetchBranchesInit({ artifactDef, artifactId }), - ); - yield put(gitArtifactActions.fetchProtectedBranchesInit({ artifactDef })); - yield put( - gitArtifactActions.fetchStatusInit({ artifactDef, artifactId }), + gitArtifactActions.triggerAutocommitInit({ + ...basePayload, + artifactId: artifact.id, + }), ); + yield put(gitArtifactActions.fetchBranchesInit(basePayload)); + yield put(gitArtifactActions.fetchProtectedBranchesInit(basePayload)); + yield put(gitArtifactActions.fetchStatusInit(basePayload)); } } } diff --git a/app/client/src/git/sagas/pullSaga.ts b/app/client/src/git/sagas/pullSaga.ts index 07347326e3e0..eafb4a5c098b 100644 --- a/app/client/src/git/sagas/pullSaga.ts +++ b/app/client/src/git/sagas/pullSaga.ts @@ -4,7 +4,7 @@ import type { PullResponse } from "git/requests/pullRequest.types"; import type { PullInitPayload } from "git/store/actions/pullActions"; import { gitArtifactActions } from "git/store/gitArtifactSlice"; import type { GitArtifactPayloadAction } from "git/store/types"; -import { selectCurrentBranch } from "git/store/selectors/gitArtifactSelectors"; +import { selectCurrentBranch } from "git/store/selectors/gitSingleArtifactSelectors"; // internal dependencies import { validateResponse } from "sagas/ErrorSagas"; @@ -17,7 +17,8 @@ import { captureException } from "@sentry/react"; export default function* pullSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef, artifactId } = action.payload; + const { artifactId, artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: PullResponse | undefined; try { @@ -25,12 +26,12 @@ export default function* pullSaga( const isValidResponse: boolean = yield validateResponse(response); if (response && isValidResponse) { - yield put(gitArtifactActions.pullSuccess({ artifactDef })); + yield put(gitArtifactActions.pullSuccess(basePayload)); const currentBasePageId: string = yield select(getCurrentBasePageId); const currentBranch: string = yield select( selectCurrentBranch, - artifactDef, + basePayload, ); yield put( @@ -50,7 +51,7 @@ export default function* pullSaga( // yield put(setIsGitErrorPopupVisible({ isVisible: true })); // } - yield put(gitArtifactActions.pullError({ artifactDef, error })); + yield put(gitArtifactActions.pullError({ ...basePayload, error })); } else { log.error(e); captureException(e); diff --git a/app/client/src/git/sagas/toggleAutocommitSaga.ts b/app/client/src/git/sagas/toggleAutocommitSaga.ts index 4f97d0289543..cf8b0e923c67 100644 --- a/app/client/src/git/sagas/toggleAutocommitSaga.ts +++ b/app/client/src/git/sagas/toggleAutocommitSaga.ts @@ -10,23 +10,24 @@ import { validateResponse } from "sagas/ErrorSagas"; export default function* toggleAutocommitSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const artifactDef = { artifactType, baseArtifactId }; let response: ToggleAutocommitResponse | undefined; try { - response = yield call(toggleAutocommitRequest, artifactDef.baseArtifactId); + response = yield call(toggleAutocommitRequest, baseArtifactId); const isValidResponse: boolean = yield validateResponse(response); if (isValidResponse) { - yield put(gitArtifactActions.toggleAutocommitSuccess({ artifactDef })); - yield put(gitArtifactActions.fetchMetadataInit({ artifactDef })); + yield put(gitArtifactActions.toggleAutocommitSuccess(artifactDef)); + yield put(gitArtifactActions.fetchMetadataInit(artifactDef)); } } catch (e) { if (response && response.responseMeta.error) { const { error } = response.responseMeta; yield put( - gitArtifactActions.toggleAutocommitError({ artifactDef, error }), + gitArtifactActions.toggleAutocommitError({ ...artifactDef, error }), ); } else { log.error(e); diff --git a/app/client/src/git/sagas/triggerAutocommitSaga.ts b/app/client/src/git/sagas/triggerAutocommitSaga.ts index 6725fb0d59f9..d0b316f594ec 100644 --- a/app/client/src/git/sagas/triggerAutocommitSaga.ts +++ b/app/client/src/git/sagas/triggerAutocommitSaga.ts @@ -1,5 +1,8 @@ import { triggerAutocommitSuccessAction } from "actions/gitSyncActions"; -import { AutocommitStatusState } from "git/constants/enums"; +import { + AutocommitStatusState, + type GitArtifactType, +} from "git/constants/enums"; import fetchAutocommitProgressRequest from "git/requests/fetchAutocommitProgressRequest"; import type { FetchAutocommitProgressResponse, @@ -12,8 +15,8 @@ import type { } from "git/requests/triggerAutocommitRequest.types"; import type { TriggerAutocommitInitPayload } from "git/store/actions/triggerAutocommitActions"; import { gitArtifactActions } from "git/store/gitArtifactSlice"; -import { selectAutocommitEnabled } from "git/store/selectors/gitArtifactSelectors"; -import type { GitArtifactDef, GitArtifactPayloadAction } from "git/store/types"; +import { selectAutocommitEnabled } from "git/store/selectors/gitSingleArtifactSelectors"; +import type { GitArtifactPayloadAction } from "git/store/types"; import { call, cancel, @@ -36,7 +39,8 @@ const AUTOCOMMIT_WHITELISTED_STATES = [ ]; interface PollAutocommitProgressParams { - artifactDef: GitArtifactDef; + artifactType: keyof typeof GitArtifactType; + baseArtifactId: string; artifactId: string; } @@ -53,7 +57,8 @@ function isAutocommitHappening( } function* pollAutocommitProgressSaga(params: PollAutocommitProgressParams) { - const { artifactDef, artifactId } = params; + const { artifactId, artifactType, baseArtifactId } = params; + const basePayload = { artifactType, baseArtifactId }; let triggerResponse: TriggerAutocommitResponse | undefined; try { @@ -61,14 +66,14 @@ function* pollAutocommitProgressSaga(params: PollAutocommitProgressParams) { const isValidResponse: boolean = yield validateResponse(triggerResponse); if (triggerResponse && isValidResponse) { - yield put(gitArtifactActions.triggerAutocommitSuccess({ artifactDef })); + yield put(gitArtifactActions.triggerAutocommitSuccess(basePayload)); } } catch (e) { if (triggerResponse && triggerResponse.responseMeta.error) { const { error } = triggerResponse.responseMeta; yield put( - gitArtifactActions.triggerAutocommitError({ artifactDef, error }), + gitArtifactActions.triggerAutocommitError({ ...basePayload, error }), ); } else { log.error(e); @@ -80,47 +85,39 @@ function* pollAutocommitProgressSaga(params: PollAutocommitProgressParams) { try { if (isAutocommitHappening(triggerResponse?.data)) { - yield put( - gitArtifactActions.pollAutocommitProgressStart({ artifactDef }), - ); + yield put(gitArtifactActions.pollAutocommitProgressStart(basePayload)); while (true) { - yield put( - gitArtifactActions.fetchAutocommitProgressInit({ artifactDef }), - ); + yield put(gitArtifactActions.fetchAutocommitProgressInit(basePayload)); progressResponse = yield call( fetchAutocommitProgressRequest, - artifactDef.baseArtifactId, + baseArtifactId, ); const isValidResponse: boolean = yield validateResponse(progressResponse); if (isValidResponse && !isAutocommitHappening(progressResponse?.data)) { - yield put( - gitArtifactActions.pollAutocommitProgressStop({ artifactDef }), - ); + yield put(gitArtifactActions.pollAutocommitProgressStop(basePayload)); } if (!isValidResponse) { - yield put( - gitArtifactActions.pollAutocommitProgressStop({ artifactDef }), - ); + yield put(gitArtifactActions.pollAutocommitProgressStop(basePayload)); } yield delay(AUTOCOMMIT_POLL_DELAY); } } else { - yield put(gitArtifactActions.pollAutocommitProgressStop({ artifactDef })); + yield put(gitArtifactActions.pollAutocommitProgressStop(basePayload)); } } catch (e) { - yield put(gitArtifactActions.pollAutocommitProgressStop({ artifactDef })); + yield put(gitArtifactActions.pollAutocommitProgressStop(basePayload)); if (progressResponse && progressResponse.responseMeta.error) { const { error } = progressResponse.responseMeta; yield put( gitArtifactActions.fetchAutocommitProgressError({ - artifactDef, + ...basePayload, error, }), ); @@ -134,14 +131,15 @@ function* pollAutocommitProgressSaga(params: PollAutocommitProgressParams) { export default function* triggerAutocommitSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef, artifactId } = action.payload; + const { artifactId, artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; const isAutocommitEnabled: boolean = yield select( selectAutocommitEnabled, - artifactDef, + basePayload, ); if (isAutocommitEnabled) { - const params = { artifactDef, artifactId }; + const params = { artifactType, baseArtifactId, artifactId }; const pollTask: Task = yield fork(pollAutocommitProgressSaga, params); yield take(gitArtifactActions.pollAutocommitProgressStop.type); diff --git a/app/client/src/git/sagas/updateGlobalProfileSaga.ts b/app/client/src/git/sagas/updateGlobalProfileSaga.ts index d7466b1ed007..2ce98fe47fb4 100644 --- a/app/client/src/git/sagas/updateGlobalProfileSaga.ts +++ b/app/client/src/git/sagas/updateGlobalProfileSaga.ts @@ -6,12 +6,12 @@ import type { UpdateGlobalProfileRequestParams, UpdateGlobalProfileResponse, } from "../requests/updateGlobalProfileRequest.types"; +import { gitConfigActions } from "../store/gitConfigSlice"; // internal dependencies import { validateResponse } from "sagas/ErrorSagas"; import log from "loglevel"; import { captureException } from "@sentry/react"; -import { gitGlobalActions } from "git/store/gitGlobalSlice"; export default function* updateGlobalProfileSaga( action: PayloadAction, @@ -29,14 +29,14 @@ export default function* updateGlobalProfileSaga( const isValidResponse: boolean = yield validateResponse(response, true); if (response && isValidResponse) { - yield put(gitGlobalActions.updateGlobalProfileSuccess()); - yield put(gitGlobalActions.fetchGlobalProfileInit()); + yield put(gitConfigActions.updateGlobalProfileSuccess()); + yield put(gitConfigActions.fetchGlobalProfileInit()); } } catch (e) { if (response && response.responseMeta.error) { const { error } = response.responseMeta; - yield put(gitGlobalActions.updateGlobalProfileError({ error })); + yield put(gitConfigActions.updateGlobalProfileError({ error })); } else { log.error(e); captureException(e); diff --git a/app/client/src/git/sagas/updateLocalProfileSaga.ts b/app/client/src/git/sagas/updateLocalProfileSaga.ts index 3b7253a391fe..74579562b058 100644 --- a/app/client/src/git/sagas/updateLocalProfileSaga.ts +++ b/app/client/src/git/sagas/updateLocalProfileSaga.ts @@ -14,7 +14,8 @@ import { captureException } from "@sentry/react"; export default function* updateLocalProfileSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const basePayload = { artifactType, baseArtifactId }; let response: UpdateLocalProfileResponse | undefined; try { @@ -24,24 +25,20 @@ export default function* updateLocalProfileSaga( useGlobalProfile: action.payload.useGlobalProfile, }; - response = yield call( - updateLocalProfileRequest, - artifactDef.baseArtifactId, - params, - ); + response = yield call(updateLocalProfileRequest, baseArtifactId, params); const isValidResponse: boolean = yield validateResponse(response); if (isValidResponse) { - yield put(gitArtifactActions.updateLocalProfileSuccess({ artifactDef })); - yield put(gitArtifactActions.fetchLocalProfileInit({ artifactDef })); + yield put(gitArtifactActions.updateLocalProfileSuccess(basePayload)); + yield put(gitArtifactActions.fetchLocalProfileInit(basePayload)); } } catch (e) { if (response && response.responseMeta.error) { const { error } = response.responseMeta; yield put( - gitArtifactActions.updateLocalProfileError({ artifactDef, error }), + gitArtifactActions.updateLocalProfileError({ ...basePayload, error }), ); } else { log.error(e); diff --git a/app/client/src/git/sagas/updateProtectedBranchesSaga.ts b/app/client/src/git/sagas/updateProtectedBranchesSaga.ts index f24b20ee9290..3f7bd121270e 100644 --- a/app/client/src/git/sagas/updateProtectedBranchesSaga.ts +++ b/app/client/src/git/sagas/updateProtectedBranchesSaga.ts @@ -14,7 +14,8 @@ import { validateResponse } from "sagas/ErrorSagas"; export default function* updateProtectedBranchesSaga( action: GitArtifactPayloadAction, ) { - const { artifactDef } = action.payload; + const { artifactType, baseArtifactId } = action.payload; + const artifactDef = { artifactType, baseArtifactId }; let response: UpdateProtectedBranchesResponse | undefined; try { @@ -24,16 +25,14 @@ export default function* updateProtectedBranchesSaga( response = yield call( updateProtectedBranchesRequest, - artifactDef.baseArtifactId, + baseArtifactId, params, ); const isValidResponse: boolean = yield validateResponse(response); if (response && isValidResponse) { - yield put( - gitArtifactActions.updateProtectedBranchesSuccess({ artifactDef }), - ); - yield put(gitArtifactActions.fetchProtectedBranchesInit({ artifactDef })); + yield put(gitArtifactActions.updateProtectedBranchesSuccess(artifactDef)); + yield put(gitArtifactActions.fetchProtectedBranchesInit(artifactDef)); } } catch (e) { if (response && response.responseMeta.error) { @@ -41,7 +40,7 @@ export default function* updateProtectedBranchesSaga( yield put( gitArtifactActions.updateProtectedBranchesError({ - artifactDef, + ...artifactDef, error, }), ); diff --git a/app/client/src/git/store/actions/checkoutBranchActions.ts b/app/client/src/git/store/actions/checkoutBranchActions.ts index e9451a614d7f..c771d1887e34 100644 --- a/app/client/src/git/store/actions/checkoutBranchActions.ts +++ b/app/client/src/git/store/actions/checkoutBranchActions.ts @@ -1,13 +1,12 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitAsyncErrorPayload } from "../types"; import type { CheckoutBranchRequestParams } from "git/requests/checkoutBranchRequest.types"; -export interface CheckoutBranchInitPayload extends CheckoutBranchRequestParams { - artifactId: string; -} +export interface CheckoutBranchInitPayload + extends CheckoutBranchRequestParams {} export const checkoutBranchInitAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { state.apiResponses.checkoutBranch.loading = true; state.apiResponses.checkoutBranch.error = null; state.ui.checkoutDestBranch = action.payload.branchName; @@ -15,16 +14,18 @@ export const checkoutBranchInitAction = return state; }); -export const checkoutBranchSuccessAction = createArtifactAction((state) => { - state.apiResponses.checkoutBranch.loading = false; - state.apiResponses.checkoutBranch.error = null; - state.ui.checkoutDestBranch = null; +export const checkoutBranchSuccessAction = createSingleArtifactAction( + (state) => { + state.apiResponses.checkoutBranch.loading = false; + state.apiResponses.checkoutBranch.error = null; + state.ui.checkoutDestBranch = null; - return state; -}); + return state; + }, +); export const checkoutBranchErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.checkoutBranch.loading = false; diff --git a/app/client/src/git/store/actions/commitActions.ts b/app/client/src/git/store/actions/commitActions.ts index 876463e803a9..9ebb8d37db60 100644 --- a/app/client/src/git/store/actions/commitActions.ts +++ b/app/client/src/git/store/actions/commitActions.ts @@ -1,12 +1,10 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitAsyncErrorPayload } from "../types"; import type { CommitRequestParams } from "git/requests/commitRequest.types"; -export interface CommitInitPayload extends CommitRequestParams { - artifactId: string; -} +export interface CommitInitPayload extends CommitRequestParams {} -export const commitInitAction = createArtifactAction( +export const commitInitAction = createSingleArtifactAction( (state) => { state.apiResponses.commit.loading = true; state.apiResponses.commit.error = null; @@ -15,24 +13,23 @@ export const commitInitAction = createArtifactAction( }, ); -export const commitSuccessAction = createArtifactAction((state) => { +export const commitSuccessAction = createSingleArtifactAction((state) => { state.apiResponses.commit.loading = false; return state; }); -export const commitErrorAction = createArtifactAction( - (state, action) => { +export const commitErrorAction = + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.commit.loading = false; state.apiResponses.commit.error = error; return state; - }, -); + }); -export const clearCommitErrorAction = createArtifactAction((state) => { +export const clearCommitErrorAction = createSingleArtifactAction((state) => { state.apiResponses.commit.error = null; return state; diff --git a/app/client/src/git/store/actions/connectActions.ts b/app/client/src/git/store/actions/connectActions.ts index 9e5e2bcf10b1..7fed98500000 100644 --- a/app/client/src/git/store/actions/connectActions.ts +++ b/app/client/src/git/store/actions/connectActions.ts @@ -1,13 +1,12 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; -import type { GitAsyncErrorPayload, GitAsyncSuccessPayload } from "../types"; -import type { - ConnectRequestParams, - ConnectResponseData, -} from "git/requests/connectRequest.types"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; +import type { GitAsyncErrorPayload } from "../types"; +import type { ConnectRequestParams } from "git/requests/connectRequest.types"; -export interface ConnectInitPayload extends ConnectRequestParams {} +export interface ConnectInitPayload extends ConnectRequestParams { + branchedPageId?: string; +} -export const connectInitAction = createArtifactAction( +export const connectInitAction = createSingleArtifactAction( (state) => { state.apiResponses.connect.loading = true; state.apiResponses.connect.error = null; @@ -16,24 +15,18 @@ export const connectInitAction = createArtifactAction( }, ); -export interface ConnectSuccessPayload - extends GitAsyncSuccessPayload {} +export const connectSuccessAction = createSingleArtifactAction((state) => { + state.apiResponses.connect.loading = false; -export const connectSuccessAction = createArtifactAction( - (state) => { - state.apiResponses.connect.loading = false; - - return state; - }, -); + return state; +}); -export const connectErrorAction = createArtifactAction( - (state, action) => { +export const connectErrorAction = + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.connect.loading = false; state.apiResponses.connect.error = error; return state; - }, -); + }); diff --git a/app/client/src/git/store/actions/createBranchActions.ts b/app/client/src/git/store/actions/createBranchActions.ts index 010a7550888f..be0e08445de2 100644 --- a/app/client/src/git/store/actions/createBranchActions.ts +++ b/app/client/src/git/store/actions/createBranchActions.ts @@ -1,27 +1,25 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitAsyncErrorPayload } from "../types"; import type { CreateBranchRequestParams } from "git/requests/createBranchRequest.types"; -export interface CreateBranchInitPayload extends CreateBranchRequestParams { - artifactId: string; -} +export interface CreateBranchInitPayload extends CreateBranchRequestParams {} export const createBranchInitAction = - createArtifactAction((state) => { + createSingleArtifactAction((state) => { state.apiResponses.createBranch.loading = true; state.apiResponses.createBranch.error = null; return state; }); -export const createBranchSuccessAction = createArtifactAction((state) => { +export const createBranchSuccessAction = createSingleArtifactAction((state) => { state.apiResponses.createBranch.loading = false; return state; }); export const createBranchErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.createBranch.loading = false; diff --git a/app/client/src/git/store/actions/deleteBranchActions.ts b/app/client/src/git/store/actions/deleteBranchActions.ts index 0656886f39d4..09296625f0d6 100644 --- a/app/client/src/git/store/actions/deleteBranchActions.ts +++ b/app/client/src/git/store/actions/deleteBranchActions.ts @@ -1,27 +1,25 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitAsyncErrorPayload } from "../types"; import type { DeleteBranchRequestParams } from "../../requests/deleteBranchRequest.types"; -export interface DeleteBranchInitPayload extends DeleteBranchRequestParams { - artifactId: string; -} +export interface DeleteBranchInitPayload extends DeleteBranchRequestParams {} export const deleteBranchInitAction = - createArtifactAction((state) => { + createSingleArtifactAction((state) => { state.apiResponses.deleteBranch.loading = true; state.apiResponses.deleteBranch.error = null; return state; }); -export const deleteBranchSuccessAction = createArtifactAction((state) => { +export const deleteBranchSuccessAction = createSingleArtifactAction((state) => { state.apiResponses.deleteBranch.loading = false; return state; }); export const deleteBranchErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.deleteBranch.loading = false; diff --git a/app/client/src/git/store/actions/discardActions.ts b/app/client/src/git/store/actions/discardActions.ts index 0f514cd0e585..35d37c0a6d0e 100644 --- a/app/client/src/git/store/actions/discardActions.ts +++ b/app/client/src/git/store/actions/discardActions.ts @@ -1,20 +1,20 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitArtifactErrorPayloadAction } from "../types"; -export const discardInitAction = createArtifactAction((state) => { +export const discardInitAction = createSingleArtifactAction((state) => { state.apiResponses.discard.loading = true; state.apiResponses.discard.error = null; return state; }); -export const discardSuccessAction = createArtifactAction((state) => { +export const discardSuccessAction = createSingleArtifactAction((state) => { state.apiResponses.discard.loading = false; return state; }); -export const discardErrorAction = createArtifactAction( +export const discardErrorAction = createSingleArtifactAction( (state, action: GitArtifactErrorPayloadAction) => { const { error } = action.payload; @@ -25,7 +25,7 @@ export const discardErrorAction = createArtifactAction( }, ); -export const clearDiscardErrorAction = createArtifactAction((state) => { +export const clearDiscardErrorAction = createSingleArtifactAction((state) => { state.apiResponses.discard.error = null; return state; diff --git a/app/client/src/git/store/actions/disconnectActions.ts b/app/client/src/git/store/actions/disconnectActions.ts index 082aa91b7970..dba26c0de629 100644 --- a/app/client/src/git/store/actions/disconnectActions.ts +++ b/app/client/src/git/store/actions/disconnectActions.ts @@ -1,20 +1,20 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitArtifactErrorPayloadAction } from "../types"; -export const disconnectInitAction = createArtifactAction((state) => { +export const disconnectInitAction = createSingleArtifactAction((state) => { state.apiResponses.disconnect.loading = true; state.apiResponses.disconnect.error = null; return state; }); -export const disconnectSuccessAction = createArtifactAction((state) => { +export const disconnectSuccessAction = createSingleArtifactAction((state) => { state.apiResponses.disconnect.loading = false; return state; }); -export const disconnectErrorAction = createArtifactAction( +export const disconnectErrorAction = createSingleArtifactAction( (state, action: GitArtifactErrorPayloadAction) => { const { error } = action.payload; diff --git a/app/client/src/git/store/actions/fetchAutocommitProgressActions.ts b/app/client/src/git/store/actions/fetchAutocommitProgressActions.ts index bbde6e4dd649..a7d92793e4aa 100644 --- a/app/client/src/git/store/actions/fetchAutocommitProgressActions.ts +++ b/app/client/src/git/store/actions/fetchAutocommitProgressActions.ts @@ -1,7 +1,7 @@ import type { GitAsyncErrorPayload } from "../types"; -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; -export const fetchAutocommitProgressInitAction = createArtifactAction( +export const fetchAutocommitProgressInitAction = createSingleArtifactAction( (state) => { state.apiResponses.autocommitProgress.loading = true; state.apiResponses.autocommitProgress.error = null; @@ -10,7 +10,7 @@ export const fetchAutocommitProgressInitAction = createArtifactAction( }, ); -export const fetchAutocommitProgressSuccessAction = createArtifactAction( +export const fetchAutocommitProgressSuccessAction = createSingleArtifactAction( (state) => { state.apiResponses.autocommitProgress.loading = false; @@ -19,7 +19,7 @@ export const fetchAutocommitProgressSuccessAction = createArtifactAction( ); export const fetchAutocommitProgressErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.autocommitProgress.loading = false; diff --git a/app/client/src/git/store/actions/fetchBranchesActions.ts b/app/client/src/git/store/actions/fetchBranchesActions.ts index 6758ad918eb0..e83ce0325e59 100644 --- a/app/client/src/git/store/actions/fetchBranchesActions.ts +++ b/app/client/src/git/store/actions/fetchBranchesActions.ts @@ -3,21 +3,19 @@ import type { FetchBranchesResponseData, } from "../../requests/fetchBranchesRequest.types"; import type { GitAsyncErrorPayload, GitAsyncSuccessPayload } from "../types"; -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; -export interface FetchBranchesInitPayload extends FetchBranchesRequestParams { - artifactId: string; -} +export interface FetchBranchesInitPayload extends FetchBranchesRequestParams {} export const fetchBranchesInitAction = - createArtifactAction((state) => { + createSingleArtifactAction((state) => { state.apiResponses.branches.loading = true; state.apiResponses.branches.error = null; return state; }); -export const fetchBranchesSuccessAction = createArtifactAction< +export const fetchBranchesSuccessAction = createSingleArtifactAction< GitAsyncSuccessPayload >((state, action) => { state.apiResponses.branches.loading = false; @@ -27,7 +25,7 @@ export const fetchBranchesSuccessAction = createArtifactAction< }); export const fetchBranchesErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.branches.loading = false; diff --git a/app/client/src/git/store/actions/fetchGlobalProfileActions.ts b/app/client/src/git/store/actions/fetchGlobalProfileActions.ts index bc2d0b6b92a3..7cfb2390b021 100644 --- a/app/client/src/git/store/actions/fetchGlobalProfileActions.ts +++ b/app/client/src/git/store/actions/fetchGlobalProfileActions.ts @@ -2,11 +2,11 @@ import type { FetchGlobalProfileResponseData } from "git/requests/fetchGlobalPro import type { GitAsyncSuccessPayload, GitAsyncErrorPayload, - GitGlobalReduxState, + GitConfigReduxState, } from "../types"; import type { PayloadAction } from "@reduxjs/toolkit"; -export const fetchGlobalProfileInitAction = (state: GitGlobalReduxState) => { +export const fetchGlobalProfileInitAction = (state: GitConfigReduxState) => { state.globalProfile.loading = true; state.globalProfile.error = null; @@ -14,7 +14,7 @@ export const fetchGlobalProfileInitAction = (state: GitGlobalReduxState) => { }; export const fetchGlobalProfileSuccessAction = ( - state: GitGlobalReduxState, + state: GitConfigReduxState, action: PayloadAction>, ) => { state.globalProfile.loading = false; @@ -24,7 +24,7 @@ export const fetchGlobalProfileSuccessAction = ( }; export const fetchGlobalProfileErrorAction = ( - state: GitGlobalReduxState, + state: GitConfigReduxState, action: PayloadAction, ) => { const { error } = action.payload; diff --git a/app/client/src/git/store/actions/fetchGlobalSSHKeyActions.ts b/app/client/src/git/store/actions/fetchGlobalSSHKeyActions.ts deleted file mode 100644 index de9add1c5ee0..000000000000 --- a/app/client/src/git/store/actions/fetchGlobalSSHKeyActions.ts +++ /dev/null @@ -1,55 +0,0 @@ -import type { - FetchGlobalSSHKeyRequestParams, - FetchGlobalSSHKeyResponseData, -} from "git/requests/fetchGlobalSSHKeyRequest.types"; -import type { - GitAsyncSuccessPayload, - GitAsyncErrorPayload, - GitGlobalReduxState, -} from "../types"; -import type { PayloadAction } from "@reduxjs/toolkit"; - -export interface FetchGlobalSSHKeyInitPayload - extends FetchGlobalSSHKeyRequestParams {} - -export const fetchGlobalSSHKeyInitAction = ( - state: GitGlobalReduxState, - // need action to better define action type - // eslint-disable-next-line @typescript-eslint/no-unused-vars - action: PayloadAction, -) => { - state.globalSSHKey.loading = true; - state.globalSSHKey.error = null; - - return state; -}; - -export const fetchGlobalSSHKeySuccessAction = ( - state: GitGlobalReduxState, - action: PayloadAction>, -) => { - state.globalSSHKey.loading = false; - state.globalSSHKey.value = action.payload.responseData; - - return state; -}; - -export const fetchGlobalSSHKeyErrorAction = ( - state: GitGlobalReduxState, - action: PayloadAction, -) => { - const { error } = action.payload; - - state.globalSSHKey.loading = false; - state.globalSSHKey.error = error; - - return state; -}; - -export const resetGlobalSSHKeyAction = (state: GitGlobalReduxState) => { - state.globalSSHKey.loading = false; - state.globalSSHKey.value = null; - state.globalSSHKey.error = null; - - return state; -}; diff --git a/app/client/src/git/store/actions/fetchLocalProfileActions.ts b/app/client/src/git/store/actions/fetchLocalProfileActions.ts index 33a62514f44c..3559a2814c35 100644 --- a/app/client/src/git/store/actions/fetchLocalProfileActions.ts +++ b/app/client/src/git/store/actions/fetchLocalProfileActions.ts @@ -3,16 +3,18 @@ import type { GitArtifactErrorPayloadAction, GitAsyncSuccessPayload, } from "../types"; -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; -export const fetchLocalProfileInitAction = createArtifactAction((state) => { - state.apiResponses.localProfile.loading = true; - state.apiResponses.localProfile.error = null; +export const fetchLocalProfileInitAction = createSingleArtifactAction( + (state) => { + state.apiResponses.localProfile.loading = true; + state.apiResponses.localProfile.error = null; - return state; -}); + return state; + }, +); -export const fetchLocalProfileSuccessAction = createArtifactAction< +export const fetchLocalProfileSuccessAction = createSingleArtifactAction< GitAsyncSuccessPayload >((state, action) => { state.apiResponses.localProfile.loading = false; @@ -21,7 +23,7 @@ export const fetchLocalProfileSuccessAction = createArtifactAction< return state; }); -export const fetchLocalProfileErrorAction = createArtifactAction( +export const fetchLocalProfileErrorAction = createSingleArtifactAction( (state, action: GitArtifactErrorPayloadAction) => { const { error } = action.payload; diff --git a/app/client/src/git/store/actions/fetchMergeStatusActions.ts b/app/client/src/git/store/actions/fetchMergeStatusActions.ts index 26b72829fadd..65ed313114cb 100644 --- a/app/client/src/git/store/actions/fetchMergeStatusActions.ts +++ b/app/client/src/git/store/actions/fetchMergeStatusActions.ts @@ -1,5 +1,5 @@ import type { GitAsyncSuccessPayload, GitAsyncErrorPayload } from "../types"; -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { FetchMergeStatusRequestParams, FetchMergeStatusResponseData, @@ -11,14 +11,14 @@ export interface FetchMergeStatusInitPayload } export const fetchMergeStatusInitAction = - createArtifactAction((state) => { + createSingleArtifactAction((state) => { state.apiResponses.mergeStatus.loading = true; state.apiResponses.mergeStatus.error = null; return state; }); -export const fetchMergeStatusSuccessAction = createArtifactAction< +export const fetchMergeStatusSuccessAction = createSingleArtifactAction< GitAsyncSuccessPayload >((state, action) => { state.apiResponses.mergeStatus.loading = false; @@ -28,7 +28,7 @@ export const fetchMergeStatusSuccessAction = createArtifactAction< }); export const fetchMergeStatusErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.mergeStatus.loading = false; @@ -37,7 +37,7 @@ export const fetchMergeStatusErrorAction = return state; }); -export const clearMergeStatusAction = createArtifactAction((state) => { +export const clearMergeStatusAction = createSingleArtifactAction((state) => { state.apiResponses.mergeStatus.loading = false; state.apiResponses.mergeStatus.error = null; state.apiResponses.mergeStatus.value = null; diff --git a/app/client/src/git/store/actions/fetchMetadataActions.ts b/app/client/src/git/store/actions/fetchMetadataActions.ts index 6e7a9f2f1e3d..176413dfbaaa 100644 --- a/app/client/src/git/store/actions/fetchMetadataActions.ts +++ b/app/client/src/git/store/actions/fetchMetadataActions.ts @@ -1,15 +1,15 @@ import type { GitAsyncErrorPayload, GitAsyncSuccessPayload } from "../types"; -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { FetchMetadataResponseData } from "git/requests/fetchMetadataRequest.types"; -export const fetchMetadataInitAction = createArtifactAction((state) => { +export const fetchMetadataInitAction = createSingleArtifactAction((state) => { state.apiResponses.metadata.loading = true; state.apiResponses.metadata.error = null; return state; }); -export const fetchMetadataSuccessAction = createArtifactAction< +export const fetchMetadataSuccessAction = createSingleArtifactAction< GitAsyncSuccessPayload >((state, action) => { state.apiResponses.metadata.loading = false; @@ -19,7 +19,7 @@ export const fetchMetadataSuccessAction = createArtifactAction< }); export const fetchMetadataErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.metadata.loading = false; diff --git a/app/client/src/git/store/actions/fetchProtectedBranchesActions.ts b/app/client/src/git/store/actions/fetchProtectedBranchesActions.ts index 1ad38bf4096c..dc66ff2290c0 100644 --- a/app/client/src/git/store/actions/fetchProtectedBranchesActions.ts +++ b/app/client/src/git/store/actions/fetchProtectedBranchesActions.ts @@ -1,8 +1,8 @@ import type { GitAsyncSuccessPayload, GitAsyncErrorPayload } from "../types"; -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { FetchProtectedBranchesResponseData } from "git/requests/fetchProtectedBranchesRequest.types"; -export const fetchProtectedBranchesInitAction = createArtifactAction( +export const fetchProtectedBranchesInitAction = createSingleArtifactAction( (state) => { state.apiResponses.protectedBranches.loading = true; state.apiResponses.protectedBranches.error = null; @@ -11,7 +11,7 @@ export const fetchProtectedBranchesInitAction = createArtifactAction( }, ); -export const fetchProtectedBranchesSuccessAction = createArtifactAction< +export const fetchProtectedBranchesSuccessAction = createSingleArtifactAction< GitAsyncSuccessPayload >((state, action) => { state.apiResponses.protectedBranches.loading = false; @@ -21,7 +21,7 @@ export const fetchProtectedBranchesSuccessAction = createArtifactAction< }); export const fetchProtectedBranchesErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.protectedBranches.loading = false; diff --git a/app/client/src/git/store/actions/fetchSSHKeyActions.ts b/app/client/src/git/store/actions/fetchSSHKeyActions.ts index 386dd4643411..828cf6ebcb75 100644 --- a/app/client/src/git/store/actions/fetchSSHKeyActions.ts +++ b/app/client/src/git/store/actions/fetchSSHKeyActions.ts @@ -1,15 +1,15 @@ import type { GitAsyncErrorPayload, GitAsyncSuccessPayload } from "../types"; -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { FetchSSHKeyResponseData } from "git/requests/fetchSSHKeyRequest.types"; -export const fetchSSHKeyInitAction = createArtifactAction((state) => { +export const fetchSSHKeyInitAction = createSingleArtifactAction((state) => { state.apiResponses.sshKey.loading = true; state.apiResponses.sshKey.error = null; return state; }); -export const fetchSSHKeySuccessAction = createArtifactAction< +export const fetchSSHKeySuccessAction = createSingleArtifactAction< GitAsyncSuccessPayload >((state, action) => { state.apiResponses.sshKey.loading = false; @@ -20,7 +20,7 @@ export const fetchSSHKeySuccessAction = createArtifactAction< }); export const fetchSSHKeyErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.sshKey.loading = false; @@ -29,7 +29,7 @@ export const fetchSSHKeyErrorAction = return state; }); -export const resetFetchSSHKeyAction = createArtifactAction((state) => { +export const resetFetchSSHKeyAction = createSingleArtifactAction((state) => { state.apiResponses.sshKey.loading = false; state.apiResponses.sshKey.error = null; state.apiResponses.sshKey.value = null; diff --git a/app/client/src/git/store/actions/fetchStatusActions.ts b/app/client/src/git/store/actions/fetchStatusActions.ts index 47097593260b..1121e368d012 100644 --- a/app/client/src/git/store/actions/fetchStatusActions.ts +++ b/app/client/src/git/store/actions/fetchStatusActions.ts @@ -3,21 +3,19 @@ import type { FetchStatusResponseData, } from "git/requests/fetchStatusRequest.types"; import type { GitAsyncErrorPayload, GitAsyncSuccessPayload } from "../types"; -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; -export interface FetchStatusInitPayload extends FetchStatusRequestParams { - artifactId: string; -} +export interface FetchStatusInitPayload extends FetchStatusRequestParams {} export const fetchStatusInitAction = - createArtifactAction((state) => { + createSingleArtifactAction((state) => { state.apiResponses.status.loading = true; state.apiResponses.status.error = null; return state; }); -export const fetchStatusSuccessAction = createArtifactAction< +export const fetchStatusSuccessAction = createSingleArtifactAction< GitAsyncSuccessPayload >((state, action) => { state.apiResponses.status.loading = false; @@ -27,7 +25,7 @@ export const fetchStatusSuccessAction = createArtifactAction< }); export const fetchStatusErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.status.loading = false; diff --git a/app/client/src/git/store/actions/generateSSHKeyActions.ts b/app/client/src/git/store/actions/generateSSHKeyActions.ts index 569d7d9995c2..fa70c3a1ba28 100644 --- a/app/client/src/git/store/actions/generateSSHKeyActions.ts +++ b/app/client/src/git/store/actions/generateSSHKeyActions.ts @@ -2,21 +2,21 @@ import type { GenerateSSHKeyRequestParams, GenerateSSHKeyResponseData, } from "git/requests/generateSSHKeyRequest.types"; -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitAsyncErrorPayload, GitAsyncSuccessPayload } from "../types"; export interface GenerateSSHKeyInitPayload extends GenerateSSHKeyRequestParams {} export const generateSSHKeyInitAction = - createArtifactAction((state) => { + createSingleArtifactAction((state) => { state.apiResponses.generateSSHKey.loading = true; state.apiResponses.generateSSHKey.error = null; return state; }); -export const generateSSHKeySuccessAction = createArtifactAction< +export const generateSSHKeySuccessAction = createSingleArtifactAction< GitAsyncSuccessPayload >((state, action) => { state.apiResponses.generateSSHKey.loading = false; @@ -27,7 +27,7 @@ export const generateSSHKeySuccessAction = createArtifactAction< }); export const generateSSHKeyErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.generateSSHKey.loading = false; @@ -36,7 +36,7 @@ export const generateSSHKeyErrorAction = return state; }); -export const resetGenerateSSHKeyAction = createArtifactAction((state) => { +export const resetGenerateSSHKeyAction = createSingleArtifactAction((state) => { state.apiResponses.generateSSHKey.loading = false; state.apiResponses.generateSSHKey.error = null; diff --git a/app/client/src/git/store/actions/gitImportActions.ts b/app/client/src/git/store/actions/gitImportActions.ts index 30e9c7417b2d..49411b55dd55 100644 --- a/app/client/src/git/store/actions/gitImportActions.ts +++ b/app/client/src/git/store/actions/gitImportActions.ts @@ -1,35 +1,25 @@ -import type { PayloadAction } from "@reduxjs/toolkit"; -import type { GitAsyncErrorPayload, GitGlobalReduxState } from "../types"; -import type { GitImportRequestParams } from "git/requests/gitImportRequest.types"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; +import type { GitAsyncErrorPayload } from "../types"; -export interface GitImportInitPayload extends GitImportRequestParams {} - -export const gitImportInitAction = ( - state: GitGlobalReduxState, - // need type for better import - // eslint-disable-next-line @typescript-eslint/no-unused-vars - action: PayloadAction, -) => { - state.gitImport.loading = true; - state.gitImport.error = null; +export const gitImportInitAction = createSingleArtifactAction((state) => { + state.apiResponses.gitImport.loading = true; + state.apiResponses.gitImport.error = null; return state; -}; +}); -export const gitImportSuccessAction = (state: GitGlobalReduxState) => { - state.gitImport.loading = false; +export const gitImportSuccessAction = createSingleArtifactAction((state) => { + state.apiResponses.gitImport.loading = false; return state; -}; +}); -export const gitImportErrorAction = ( - state: GitGlobalReduxState, - action: PayloadAction, -) => { - const { error } = action.payload; +export const gitImportErrorAction = + createSingleArtifactAction((state, action) => { + const { error } = action.payload; - state.gitImport.loading = false; - state.gitImport.error = error; + state.apiResponses.gitImport.loading = false; + state.apiResponses.gitImport.error = error; - return state; -}; + return state; + }); diff --git a/app/client/src/git/store/actions/initGitActions.ts b/app/client/src/git/store/actions/initGitActions.ts index ebe588555a24..d93cf955eeec 100644 --- a/app/client/src/git/store/actions/initGitActions.ts +++ b/app/client/src/git/store/actions/initGitActions.ts @@ -1,11 +1,15 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; -import type { ApplicationPayload } from "entities/Application"; +import type { FetchMetadataResponseData } from "git/requests/fetchMetadataRequest.types"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; export interface InitGitForEditorPayload { - artifact: ApplicationPayload | null; + artifact: { + id: string; + baseId: string; + gitApplicationMetadata?: Partial; + }; } export const initGitForEditorAction = - createArtifactAction((state) => { + createSingleArtifactAction((state) => { return state; }); diff --git a/app/client/src/git/store/actions/mergeActions.ts b/app/client/src/git/store/actions/mergeActions.ts index 0d4e67eea8fe..5bb17a351ce6 100644 --- a/app/client/src/git/store/actions/mergeActions.ts +++ b/app/client/src/git/store/actions/mergeActions.ts @@ -1,20 +1,20 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitArtifactErrorPayloadAction } from "../types"; -export const mergeInitAction = createArtifactAction((state) => { +export const mergeInitAction = createSingleArtifactAction((state) => { state.apiResponses.merge.loading = true; state.apiResponses.merge.error = null; return state; }); -export const mergeSuccessAction = createArtifactAction((state) => { +export const mergeSuccessAction = createSingleArtifactAction((state) => { state.apiResponses.merge.loading = false; return state; }); -export const mergeErrorAction = createArtifactAction( +export const mergeErrorAction = createSingleArtifactAction( (state, action: GitArtifactErrorPayloadAction) => { const { error } = action.payload; diff --git a/app/client/src/git/store/actions/mountActions.ts b/app/client/src/git/store/actions/mountActions.ts index 8d35126d9502..07a08ee2b566 100644 --- a/app/client/src/git/store/actions/mountActions.ts +++ b/app/client/src/git/store/actions/mountActions.ts @@ -1,31 +1,26 @@ import type { PayloadAction } from "@reduxjs/toolkit"; -import type { - GitArtifactBasePayload, - GitArtifactRootReduxState, -} from "../types"; -import { gitArtifactInitialState } from "../helpers/initialState"; +import type { GitArtifactBasePayload, GitArtifactReduxState } from "../types"; +import { gitSingleArtifactInitialState } from "../helpers/gitSingleArtifactInitialState"; // ! This might be removed later export const mountAction = ( - state: GitArtifactRootReduxState, + state: GitArtifactReduxState, action: PayloadAction, ) => { - const { artifactDef } = action.payload; - const { artifactType, baseArtifactId } = artifactDef; + const { artifactType, baseArtifactId } = action.payload; state[artifactType] ??= {}; - state[artifactType][baseArtifactId] ??= gitArtifactInitialState; + state[artifactType][baseArtifactId] ??= gitSingleArtifactInitialState; return state; }; export const unmountAction = ( - state: GitArtifactRootReduxState, + state: GitArtifactReduxState, action: PayloadAction, ) => { - const { artifactDef } = action.payload; - const { artifactType, baseArtifactId } = artifactDef; + const { artifactType, baseArtifactId } = action.payload; delete state?.[artifactType]?.[baseArtifactId]; diff --git a/app/client/src/git/store/actions/pullActions.ts b/app/client/src/git/store/actions/pullActions.ts index 48d3398e18c6..00a0d00f2033 100644 --- a/app/client/src/git/store/actions/pullActions.ts +++ b/app/client/src/git/store/actions/pullActions.ts @@ -1,24 +1,26 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitAsyncErrorPayload } from "../types"; export interface PullInitPayload { artifactId: string; } -export const pullInitAction = createArtifactAction((state) => { - state.apiResponses.pull.loading = true; - state.apiResponses.pull.error = null; +export const pullInitAction = createSingleArtifactAction( + (state) => { + state.apiResponses.pull.loading = true; + state.apiResponses.pull.error = null; - return state; -}); + return state; + }, +); -export const pullSuccessAction = createArtifactAction((state) => { +export const pullSuccessAction = createSingleArtifactAction((state) => { state.apiResponses.pull.loading = false; return state; }); -export const pullErrorAction = createArtifactAction( +export const pullErrorAction = createSingleArtifactAction( (state, action) => { const { error } = action.payload; diff --git a/app/client/src/git/store/actions/repoLimitErrorModalActions.ts b/app/client/src/git/store/actions/repoLimitErrorModalActions.ts index a2c96bac7721..b1867c1d5926 100644 --- a/app/client/src/git/store/actions/repoLimitErrorModalActions.ts +++ b/app/client/src/git/store/actions/repoLimitErrorModalActions.ts @@ -1,14 +1,16 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; interface ToggleRepoLimitModalActionPayload { open: boolean; } export const toggleRepoLimitErrorModalAction = - createArtifactAction((state, action) => { - const { open } = action.payload; + createSingleArtifactAction( + (state, action) => { + const { open } = action.payload; - state.ui.repoLimitErrorModalOpen = open; + state.ui.repoLimitErrorModalOpen = open; - return state; - }); + return state; + }, + ); diff --git a/app/client/src/git/store/actions/toggleAutocommitActions.ts b/app/client/src/git/store/actions/toggleAutocommitActions.ts index d9c700cbb457..96721698196f 100644 --- a/app/client/src/git/store/actions/toggleAutocommitActions.ts +++ b/app/client/src/git/store/actions/toggleAutocommitActions.ts @@ -1,20 +1,24 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitArtifactErrorPayloadAction } from "../types"; -export const toggleAutocommitInitAction = createArtifactAction((state) => { - state.apiResponses.toggleAutocommit.loading = true; - state.apiResponses.toggleAutocommit.error = null; +export const toggleAutocommitInitAction = createSingleArtifactAction( + (state) => { + state.apiResponses.toggleAutocommit.loading = true; + state.apiResponses.toggleAutocommit.error = null; - return state; -}); + return state; + }, +); -export const toggleAutocommitSuccessAction = createArtifactAction((state) => { - state.apiResponses.toggleAutocommit.loading = false; +export const toggleAutocommitSuccessAction = createSingleArtifactAction( + (state) => { + state.apiResponses.toggleAutocommit.loading = false; - return state; -}); + return state; + }, +); -export const toggleAutocommitErrorAction = createArtifactAction( +export const toggleAutocommitErrorAction = createSingleArtifactAction( (state, action: GitArtifactErrorPayloadAction) => { const { error } = action.payload; diff --git a/app/client/src/git/store/actions/triggerAutocommitActions.ts b/app/client/src/git/store/actions/triggerAutocommitActions.ts index da8075bc347f..28e88ecd2f16 100644 --- a/app/client/src/git/store/actions/triggerAutocommitActions.ts +++ b/app/client/src/git/store/actions/triggerAutocommitActions.ts @@ -1,4 +1,4 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitAsyncErrorPayload } from "../types"; export interface TriggerAutocommitInitPayload { @@ -6,21 +6,23 @@ export interface TriggerAutocommitInitPayload { } export const triggerAutocommitInitAction = - createArtifactAction((state) => { + createSingleArtifactAction((state) => { state.apiResponses.triggerAutocommit.loading = true; state.apiResponses.triggerAutocommit.error = null; return state; }); -export const triggerAutocommitSuccessAction = createArtifactAction((state) => { - state.apiResponses.triggerAutocommit.loading = false; +export const triggerAutocommitSuccessAction = createSingleArtifactAction( + (state) => { + state.apiResponses.triggerAutocommit.loading = false; - return state; -}); + return state; + }, +); export const triggerAutocommitErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.triggerAutocommit.loading = false; @@ -29,7 +31,7 @@ export const triggerAutocommitErrorAction = return state; }); -export const pollAutocommitProgressStartAction = createArtifactAction( +export const pollAutocommitProgressStartAction = createSingleArtifactAction( (state) => { state.ui.autocommitPolling = true; @@ -37,7 +39,7 @@ export const pollAutocommitProgressStartAction = createArtifactAction( }, ); -export const pollAutocommitProgressStopAction = createArtifactAction( +export const pollAutocommitProgressStopAction = createSingleArtifactAction( (state) => { state.ui.autocommitPolling = false; diff --git a/app/client/src/git/store/actions/uiActions.ts b/app/client/src/git/store/actions/uiActions.ts index 162382c3b876..577d1dfa3d10 100644 --- a/app/client/src/git/store/actions/uiActions.ts +++ b/app/client/src/git/store/actions/uiActions.ts @@ -1,7 +1,5 @@ import type { GitOpsTab, GitSettingsTab } from "git/constants/enums"; -import { createArtifactAction } from "../helpers/createArtifactAction"; -import type { GitGlobalReduxState } from "../types"; -import type { PayloadAction } from "@reduxjs/toolkit"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; // connect modal export interface ToggleConnectModalPayload { @@ -9,7 +7,7 @@ export interface ToggleConnectModalPayload { } export const toggleConnectModalAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { open } = action.payload; state.ui.connectModalOpen = open; @@ -17,54 +15,27 @@ export const toggleConnectModalAction = return state; }); -export interface ToggleConnectSuccessModalPayload { - open: boolean; -} - -export const toggleConnectSuccessModalAction = - createArtifactAction((state, action) => { - const { open } = action.payload; - - state.ui.connectSuccessModalOpen = open; - - return state; - }); - -export interface ToggleImportModalPayload { - open: boolean; -} - -export const toggleImportModalAction = ( - state: GitGlobalReduxState, - action: PayloadAction, -) => { - const { open } = action.payload; - - state.isImportModalOpen = open; - - return state; -}; - // disconnect modal export interface OpenDisconnectModalPayload { artifactName: string; } export const openDisconnectModalAction = - createArtifactAction((state, action) => { - state.ui.disconnectBaseArtifactId = - action.payload.artifactDef.baseArtifactId; + createSingleArtifactAction((state, action) => { + state.ui.disconnectBaseArtifactId = action.payload.baseArtifactId; state.ui.disconnectArtifactName = action.payload.artifactName; return state; }); -export const closeDisconnectModalAction = createArtifactAction((state) => { - state.ui.disconnectBaseArtifactId = null; - state.ui.disconnectArtifactName = null; +export const closeDisconnectModalAction = createSingleArtifactAction( + (state) => { + state.ui.disconnectBaseArtifactId = null; + state.ui.disconnectArtifactName = null; - return state; -}); + return state; + }, +); // ops modal @@ -73,16 +44,15 @@ export interface ToggleOpsModalPayload { tab: keyof typeof GitOpsTab; } -export const toggleOpsModalAction = createArtifactAction( - (state, action) => { +export const toggleOpsModalAction = + createSingleArtifactAction((state, action) => { const { open, tab } = action.payload; state.ui.opsModalOpen = open; state.ui.opsModalTab = tab; return state; - }, -); + }); // settings modal export interface ToggleSettingsModalPayload { @@ -91,7 +61,7 @@ export interface ToggleSettingsModalPayload { } export const toggleSettingsModalAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { open, tab } = action.payload; state.ui.settingsModalOpen = open; @@ -106,28 +76,29 @@ interface ToggleAutocommitDisableModalPayload { } export const toggleAutocommitDisableModalAction = - createArtifactAction((state, action) => { - const { open } = action.payload; + createSingleArtifactAction( + (state, action) => { + const { open } = action.payload; - state.ui.autocommitDisableModalOpen = open; + state.ui.autocommitDisableModalOpen = open; - return state; - }); + return state; + }, + ); // branch popup interface BranchPopupPayload { open: boolean; } -export const toggleBranchPopupAction = createArtifactAction( - (state, action) => { +export const toggleBranchPopupAction = + createSingleArtifactAction((state, action) => { const { open } = action.payload; state.ui.branchPopupOpen = open; return state; - }, -); + }); // error modals interface ToggleRepoLimitModalPayload { @@ -135,7 +106,7 @@ interface ToggleRepoLimitModalPayload { } export const toggleRepoLimitErrorModalAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { open } = action.payload; state.ui.repoLimitErrorModalOpen = open; @@ -148,10 +119,12 @@ interface ToggleConflictErrorModalPayload { } export const toggleConflictErrorModalAction = - createArtifactAction((state, action) => { - const { open } = action.payload; + createSingleArtifactAction( + (state, action) => { + const { open } = action.payload; - state.ui.conflictErrorModalOpen = open; + state.ui.conflictErrorModalOpen = open; - return state; - }); + return state; + }, + ); diff --git a/app/client/src/git/store/actions/updateGlobalProfileActions.ts b/app/client/src/git/store/actions/updateGlobalProfileActions.ts index 3549672deb56..b4d25b0b57d7 100644 --- a/app/client/src/git/store/actions/updateGlobalProfileActions.ts +++ b/app/client/src/git/store/actions/updateGlobalProfileActions.ts @@ -1,14 +1,14 @@ import type { UpdateGlobalProfileRequestParams } from "git/requests/updateGlobalProfileRequest.types"; -import type { GitAsyncErrorPayload, GitGlobalReduxState } from "../types"; +import type { GitAsyncErrorPayload, GitConfigReduxState } from "../types"; import type { PayloadAction } from "@reduxjs/toolkit"; export interface UpdateGlobalProfileInitPayload extends UpdateGlobalProfileRequestParams {} type UpdateGlobalProfileInitAction = ( - state: GitGlobalReduxState, + state: GitConfigReduxState, action: PayloadAction, -) => GitGlobalReduxState; +) => GitConfigReduxState; export const updateGlobalProfileInitAction: UpdateGlobalProfileInitAction = ( state, @@ -20,7 +20,7 @@ export const updateGlobalProfileInitAction: UpdateGlobalProfileInitAction = ( }; export const updateGlobalProfileSuccessAction = ( - state: GitGlobalReduxState, + state: GitConfigReduxState, ) => { state.updateGlobalProfile.loading = false; @@ -28,7 +28,7 @@ export const updateGlobalProfileSuccessAction = ( }; export const updateGlobalProfileErrorAction = ( - state: GitGlobalReduxState, + state: GitConfigReduxState, action: PayloadAction, ) => { const { error } = action.payload; diff --git a/app/client/src/git/store/actions/updateLocalProfileActions.ts b/app/client/src/git/store/actions/updateLocalProfileActions.ts index 84ac561a5026..717bb388cb9b 100644 --- a/app/client/src/git/store/actions/updateLocalProfileActions.ts +++ b/app/client/src/git/store/actions/updateLocalProfileActions.ts @@ -1,4 +1,4 @@ -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitAsyncErrorPayload } from "../types"; import type { UpdateLocalProfileRequestParams } from "git/requests/updateLocalProfileRequest.types"; @@ -6,21 +6,23 @@ export interface UpdateLocalProfileInitPayload extends UpdateLocalProfileRequestParams {} export const updateLocalProfileInitAction = - createArtifactAction((state) => { + createSingleArtifactAction((state) => { state.apiResponses.updateLocalProfile.loading = true; state.apiResponses.updateLocalProfile.error = null; return state; }); -export const updateLocalProfileSuccessAction = createArtifactAction((state) => { - state.apiResponses.updateLocalProfile.loading = false; +export const updateLocalProfileSuccessAction = createSingleArtifactAction( + (state) => { + state.apiResponses.updateLocalProfile.loading = false; - return state; -}); + return state; + }, +); export const updateLocalProfileErrorAction = - createArtifactAction((state, action) => { + createSingleArtifactAction((state, action) => { const { error } = action.payload; state.apiResponses.updateLocalProfile.loading = false; diff --git a/app/client/src/git/store/actions/updateProtectedBranchesActions.ts b/app/client/src/git/store/actions/updateProtectedBranchesActions.ts index a19926b673f9..6e45bf0dcca5 100644 --- a/app/client/src/git/store/actions/updateProtectedBranchesActions.ts +++ b/app/client/src/git/store/actions/updateProtectedBranchesActions.ts @@ -1,19 +1,19 @@ import type { UpdateProtectedBranchesRequestParams } from "git/requests/updateProtectedBranchesRequest.types"; -import { createArtifactAction } from "../helpers/createArtifactAction"; +import { createSingleArtifactAction } from "../helpers/createSingleArtifactAction"; import type { GitArtifactErrorPayloadAction } from "../types"; export interface UpdateProtectedBranchesInitPayload extends UpdateProtectedBranchesRequestParams {} export const updateProtectedBranchesInitAction = - createArtifactAction((state) => { + createSingleArtifactAction((state) => { state.apiResponses.updateProtectedBranches.loading = true; state.apiResponses.updateProtectedBranches.error = null; return state; }); -export const updateProtectedBranchesSuccessAction = createArtifactAction( +export const updateProtectedBranchesSuccessAction = createSingleArtifactAction( (state) => { state.apiResponses.updateProtectedBranches.loading = false; @@ -21,7 +21,7 @@ export const updateProtectedBranchesSuccessAction = createArtifactAction( }, ); -export const updateProtectedBranchesErrorAction = createArtifactAction( +export const updateProtectedBranchesErrorAction = createSingleArtifactAction( (state, action: GitArtifactErrorPayloadAction) => { const { error } = action.payload; diff --git a/app/client/src/git/store/gitArtifactSlice.ts b/app/client/src/git/store/gitArtifactSlice.ts index 15bbb4de65d2..924785f80c76 100644 --- a/app/client/src/git/store/gitArtifactSlice.ts +++ b/app/client/src/git/store/gitArtifactSlice.ts @@ -1,5 +1,5 @@ import { createSlice } from "@reduxjs/toolkit"; -import type { GitArtifactRootReduxState } from "./types"; +import type { GitArtifactReduxState } from "./types"; import { mountAction, unmountAction } from "./actions/mountActions"; import { connectErrorAction, @@ -62,7 +62,6 @@ import { openDisconnectModalAction, closeDisconnectModalAction, toggleAutocommitDisableModalAction, - toggleConnectSuccessModalAction, } from "./actions/uiActions"; import { checkoutBranchErrorAction, @@ -120,6 +119,11 @@ import { disconnectInitAction, disconnectSuccessAction, } from "./actions/disconnectActions"; +import { + gitImportErrorAction, + gitImportInitAction, + gitImportSuccessAction, +} from "./actions/gitImportActions"; import { fetchSSHKeyErrorAction, fetchSSHKeyInitAction, @@ -133,7 +137,7 @@ import { resetGenerateSSHKeyAction, } from "./actions/generateSSHKeyActions"; -const initialState: GitArtifactRootReduxState = {}; +const initialState: GitArtifactReduxState = {}; export const gitArtifactSlice = createSlice({ name: "git/artifact", @@ -152,6 +156,9 @@ export const gitArtifactSlice = createSlice({ connectInit: connectInitAction, connectSuccess: connectSuccessAction, connectError: connectErrorAction, + gitImportInit: gitImportInitAction, + gitImportSuccess: gitImportSuccessAction, + gitImportError: gitImportErrorAction, fetchSSHKeyInit: fetchSSHKeyInitAction, fetchSSHKeySuccess: fetchSSHKeySuccessAction, fetchSSHKeyError: fetchSSHKeyErrorAction, @@ -164,7 +171,6 @@ export const gitArtifactSlice = createSlice({ disconnectSuccess: disconnectSuccessAction, disconnectError: disconnectErrorAction, toggleConnectModal: toggleConnectModalAction, - toggleConnectSuccessModal: toggleConnectSuccessModalAction, openDisconnectModal: openDisconnectModalAction, closeDisconnectModal: closeDisconnectModalAction, toggleRepoLimitErrorModal: toggleRepoLimitErrorModalAction, diff --git a/app/client/src/git/store/gitConfigSlice.ts b/app/client/src/git/store/gitConfigSlice.ts new file mode 100644 index 000000000000..a07a45d9730b --- /dev/null +++ b/app/client/src/git/store/gitConfigSlice.ts @@ -0,0 +1,29 @@ +import { createSlice } from "@reduxjs/toolkit"; +import { + fetchGlobalProfileErrorAction, + fetchGlobalProfileInitAction, + fetchGlobalProfileSuccessAction, +} from "./actions/fetchGlobalProfileActions"; +import { + updateGlobalProfileErrorAction, + updateGlobalProfileInitAction, + updateGlobalProfileSuccessAction, +} from "./actions/updateGlobalProfileActions"; +import { gitConfigInitialState } from "./helpers/gitConfigInitialState"; + +export const gitConfigSlice = createSlice({ + name: "git/config", + initialState: gitConfigInitialState, + reducers: { + fetchGlobalProfileInit: fetchGlobalProfileInitAction, + fetchGlobalProfileSuccess: fetchGlobalProfileSuccessAction, + fetchGlobalProfileError: fetchGlobalProfileErrorAction, + updateGlobalProfileInit: updateGlobalProfileInitAction, + updateGlobalProfileSuccess: updateGlobalProfileSuccessAction, + updateGlobalProfileError: updateGlobalProfileErrorAction, + }, +}); + +export const gitConfigActions = gitConfigSlice.actions; + +export const gitConfigReducer = gitConfigSlice.reducer; diff --git a/app/client/src/git/store/gitGlobalSlice.ts b/app/client/src/git/store/gitGlobalSlice.ts deleted file mode 100644 index 4a26f5d6132f..000000000000 --- a/app/client/src/git/store/gitGlobalSlice.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { createSlice } from "@reduxjs/toolkit"; -import { - fetchGlobalProfileErrorAction, - fetchGlobalProfileInitAction, - fetchGlobalProfileSuccessAction, -} from "./actions/fetchGlobalProfileActions"; -import { - updateGlobalProfileErrorAction, - updateGlobalProfileInitAction, - updateGlobalProfileSuccessAction, -} from "./actions/updateGlobalProfileActions"; -import { gitGlobalInitialState } from "./helpers/initialState"; -import { toggleImportModalAction } from "./actions/uiActions"; -import { - gitImportErrorAction, - gitImportInitAction, - gitImportSuccessAction, -} from "./actions/gitImportActions"; -import { - fetchGlobalSSHKeyErrorAction, - fetchGlobalSSHKeyInitAction, - fetchGlobalSSHKeySuccessAction, - resetGlobalSSHKeyAction, -} from "./actions/fetchGlobalSSHKeyActions"; - -export const gitGlobalSlice = createSlice({ - name: "git/config", - initialState: gitGlobalInitialState, - reducers: { - fetchGlobalProfileInit: fetchGlobalProfileInitAction, - fetchGlobalProfileSuccess: fetchGlobalProfileSuccessAction, - fetchGlobalProfileError: fetchGlobalProfileErrorAction, - updateGlobalProfileInit: updateGlobalProfileInitAction, - updateGlobalProfileSuccess: updateGlobalProfileSuccessAction, - updateGlobalProfileError: updateGlobalProfileErrorAction, - fetchGlobalSSHKeyInit: fetchGlobalSSHKeyInitAction, - fetchGlobalSSHKeySuccess: fetchGlobalSSHKeySuccessAction, - fetchGlobalSSHKeyError: fetchGlobalSSHKeyErrorAction, - resetGlobalSSHKey: resetGlobalSSHKeyAction, - gitImportInit: gitImportInitAction, - gitImportSuccess: gitImportSuccessAction, - gitImportError: gitImportErrorAction, - toggleImportModal: toggleImportModalAction, - }, -}); - -export const gitGlobalActions = gitGlobalSlice.actions; - -export const gitGlobalReducer = gitGlobalSlice.reducer; diff --git a/app/client/src/git/store/helpers/createArtifactAction.ts b/app/client/src/git/store/helpers/createArtifactAction.ts deleted file mode 100644 index c138af710d53..000000000000 --- a/app/client/src/git/store/helpers/createArtifactAction.ts +++ /dev/null @@ -1,35 +0,0 @@ -import type { - GitArtifactBasePayload, - GitArtifactPayloadAction, - GitArtifactReduxState, - GitArtifactRootReduxState, -} from "../types"; -import { gitArtifactInitialState } from "./initialState"; - -type ArtifactStateCb = ( - artifactState: GitArtifactReduxState, - action: GitArtifactPayloadAction, -) => GitArtifactReduxState; - -export const createArtifactAction = ( - artifactStateCb: ArtifactStateCb, -) => { - return ( - state: GitArtifactRootReduxState, - action: GitArtifactPayloadAction, - ) => { - const { artifactType, baseArtifactId } = action.payload.artifactDef; - - state[artifactType] ??= {}; - state[artifactType][baseArtifactId] ??= gitArtifactInitialState; - - const artifactState = state[artifactType][baseArtifactId]; - - state[artifactType][baseArtifactId] = artifactStateCb( - artifactState, - action, - ); - - return state; - }; -}; diff --git a/app/client/src/git/store/helpers/createSingleArtifactAction.ts b/app/client/src/git/store/helpers/createSingleArtifactAction.ts new file mode 100644 index 000000000000..2e0642959be8 --- /dev/null +++ b/app/client/src/git/store/helpers/createSingleArtifactAction.ts @@ -0,0 +1,35 @@ +import type { + GitArtifactBasePayload, + GitArtifactPayloadAction, + GitArtifactReduxState, + GitSingleArtifactReduxState, +} from "../types"; +import { gitSingleArtifactInitialState } from "./gitSingleArtifactInitialState"; + +type SingleArtifactStateCb = ( + singleArtifactState: GitSingleArtifactReduxState, + action: GitArtifactPayloadAction, +) => GitSingleArtifactReduxState; + +export const createSingleArtifactAction = ( + singleArtifactStateCb: SingleArtifactStateCb, +) => { + return ( + state: GitArtifactReduxState, + action: GitArtifactPayloadAction, + ) => { + const { artifactType, baseArtifactId } = action.payload; + + state[artifactType] ??= {}; + state[artifactType][baseArtifactId] ??= gitSingleArtifactInitialState; + + const singleArtifactState = state[artifactType][baseArtifactId]; + + state[artifactType][baseArtifactId] = singleArtifactStateCb( + singleArtifactState, + action, + ); + + return state; + }; +}; diff --git a/app/client/src/git/store/helpers/gitConfigInitialState.ts b/app/client/src/git/store/helpers/gitConfigInitialState.ts new file mode 100644 index 000000000000..7017399dfb16 --- /dev/null +++ b/app/client/src/git/store/helpers/gitConfigInitialState.ts @@ -0,0 +1,13 @@ +import type { GitConfigReduxState } from "../types"; + +export const gitConfigInitialState: GitConfigReduxState = { + globalProfile: { + value: null, + loading: false, + error: null, + }, + updateGlobalProfile: { + loading: false, + error: null, + }, +}; diff --git a/app/client/src/git/store/helpers/gitSingleArtifactInitialState.ts b/app/client/src/git/store/helpers/gitSingleArtifactInitialState.ts new file mode 100644 index 000000000000..b17c93a126cb --- /dev/null +++ b/app/client/src/git/store/helpers/gitSingleArtifactInitialState.ts @@ -0,0 +1,138 @@ +import { + gitArtifactAPIResponsesInitialState as gitArtifactAPIResponsesInitialStateExtended, + gitArtifactUIInitialState as gitArtifactUIInitialStateExtended, +} from "git/ee/store/helpers/initialState"; +import { GitOpsTab, GitSettingsTab } from "../../constants/enums"; +import type { + GitSingleArtifactAPIResponsesReduxState, + GitSingleArtifactUIReduxState, + GitSingleArtifactReduxState, +} from "../types"; + +const gitSingleArtifactInitialUIState: GitSingleArtifactUIReduxState = { + connectModalOpen: false, + disconnectBaseArtifactId: null, + disconnectArtifactName: null, + branchPopupOpen: false, + checkoutDestBranch: null, + opsModalOpen: false, + opsModalTab: GitOpsTab.Deploy, + settingsModalOpen: false, + settingsModalTab: GitSettingsTab.General, + autocommitDisableModalOpen: false, + autocommitPolling: false, + conflictErrorModalOpen: false, + repoLimitErrorModalOpen: false, + // EE + ...gitArtifactUIInitialStateExtended, +}; + +const gitSingleArtifactInitialAPIResponses: GitSingleArtifactAPIResponsesReduxState = + { + metadata: { + value: null, + loading: false, + error: null, + }, + connect: { + loading: false, + error: null, + }, + gitImport: { + loading: false, + error: null, + }, + status: { + value: null, + loading: false, + error: null, + }, + commit: { + loading: false, + error: null, + }, + pull: { + loading: false, + error: null, + }, + discard: { + loading: false, + error: null, + }, + mergeStatus: { + value: null, + loading: false, + error: null, + }, + merge: { + loading: false, + error: null, + }, + branches: { + value: null, + loading: false, + error: null, + }, + checkoutBranch: { + loading: false, + error: null, + }, + createBranch: { + loading: false, + error: null, + }, + deleteBranch: { + loading: false, + error: null, + }, + localProfile: { + value: null, + loading: false, + error: null, + }, + updateLocalProfile: { + loading: false, + error: null, + }, + disconnect: { + loading: false, + error: null, + }, + protectedBranches: { + value: null, + loading: false, + error: null, + }, + updateProtectedBranches: { + loading: false, + error: null, + }, + autocommitProgress: { + loading: false, + error: null, + }, + toggleAutocommit: { + loading: false, + error: null, + }, + triggerAutocommit: { + loading: false, + error: null, + }, + generateSSHKey: { + loading: false, + error: null, + }, + sshKey: { + value: null, + loading: false, + error: null, + }, + // EE + ...gitArtifactAPIResponsesInitialStateExtended, + }; + +export const gitSingleArtifactInitialState: GitSingleArtifactReduxState = { + ui: gitSingleArtifactInitialUIState, + apiResponses: gitSingleArtifactInitialAPIResponses, +}; diff --git a/app/client/src/git/store/helpers/initialState.ts b/app/client/src/git/store/helpers/initialState.ts deleted file mode 100644 index 382833be2782..000000000000 --- a/app/client/src/git/store/helpers/initialState.ts +++ /dev/null @@ -1,157 +0,0 @@ -import { - gitArtifactAPIResponsesInitialState as gitArtifactAPIResponsesInitialStateExtended, - gitArtifactUIInitialState as gitArtifactUIInitialStateExtended, -} from "git/ee/store/helpers/initialState"; -import { GitOpsTab, GitSettingsTab } from "../../constants/enums"; -import type { - GitArtifactAPIResponsesReduxState, - GitArtifactUIReduxState, - GitArtifactReduxState, - GitGlobalReduxState, -} from "../types"; - -const gitArtifactInitialUIState: GitArtifactUIReduxState = { - connectModalOpen: false, - connectSuccessModalOpen: false, - disconnectBaseArtifactId: null, - disconnectArtifactName: null, - branchPopupOpen: false, - checkoutDestBranch: null, - opsModalOpen: false, - opsModalTab: GitOpsTab.Deploy, - settingsModalOpen: false, - settingsModalTab: GitSettingsTab.General, - autocommitDisableModalOpen: false, - autocommitPolling: false, - conflictErrorModalOpen: false, - repoLimitErrorModalOpen: false, - // EE - ...gitArtifactUIInitialStateExtended, -}; - -const gitArtifactInitialAPIResponses: GitArtifactAPIResponsesReduxState = { - metadata: { - value: null, - loading: false, - error: null, - }, - connect: { - loading: false, - error: null, - }, - status: { - value: null, - loading: false, - error: null, - }, - commit: { - loading: false, - error: null, - }, - pull: { - loading: false, - error: null, - }, - discard: { - loading: false, - error: null, - }, - mergeStatus: { - value: null, - loading: false, - error: null, - }, - merge: { - loading: false, - error: null, - }, - branches: { - value: null, - loading: false, - error: null, - }, - checkoutBranch: { - loading: false, - error: null, - }, - createBranch: { - loading: false, - error: null, - }, - deleteBranch: { - loading: false, - error: null, - }, - localProfile: { - value: null, - loading: false, - error: null, - }, - updateLocalProfile: { - loading: false, - error: null, - }, - disconnect: { - loading: false, - error: null, - }, - protectedBranches: { - value: null, - loading: false, - error: null, - }, - updateProtectedBranches: { - loading: false, - error: null, - }, - autocommitProgress: { - loading: false, - error: null, - }, - toggleAutocommit: { - loading: false, - error: null, - }, - triggerAutocommit: { - loading: false, - error: null, - }, - generateSSHKey: { - loading: false, - error: null, - }, - sshKey: { - value: null, - loading: false, - error: null, - }, - // EE - ...gitArtifactAPIResponsesInitialStateExtended, -}; - -export const gitArtifactInitialState: GitArtifactReduxState = { - ui: gitArtifactInitialUIState, - apiResponses: gitArtifactInitialAPIResponses, -}; - -export const gitGlobalInitialState: GitGlobalReduxState = { - globalProfile: { - value: null, - loading: false, - error: null, - }, - updateGlobalProfile: { - loading: false, - error: null, - }, - globalSSHKey: { - value: null, - loading: false, - error: null, - }, - gitImport: { - loading: false, - error: null, - }, - isImportModalOpen: false, -}; diff --git a/app/client/src/git/store/index.ts b/app/client/src/git/store/index.ts index 6d210139ada4..f5337e564f97 100644 --- a/app/client/src/git/store/index.ts +++ b/app/client/src/git/store/index.ts @@ -1,8 +1,8 @@ import { combineReducers } from "@reduxjs/toolkit"; import { gitArtifactReducer } from "./gitArtifactSlice"; -import { gitGlobalReducer } from "./gitGlobalSlice"; +import { gitConfigReducer } from "./gitConfigSlice"; export const gitReducer = combineReducers({ artifacts: gitArtifactReducer, - global: gitGlobalReducer, + config: gitConfigReducer, }); diff --git a/app/client/src/git/store/selectors/gitConfigSelectors.ts b/app/client/src/git/store/selectors/gitConfigSelectors.ts new file mode 100644 index 000000000000..be31a23cda5e --- /dev/null +++ b/app/client/src/git/store/selectors/gitConfigSelectors.ts @@ -0,0 +1,12 @@ +import type { GitRootState } from "../types"; + +export const selectGitConfig = (state: GitRootState) => { + return state.git.config; +}; + +// global profile +export const selectFetchGlobalProfileState = (state: GitRootState) => + selectGitConfig(state).globalProfile; + +export const selectUpdateGlobalProfileState = (state: GitRootState) => + selectGitConfig(state).updateGlobalProfile; diff --git a/app/client/src/git/store/selectors/gitGlobalSelectors.ts b/app/client/src/git/store/selectors/gitGlobalSelectors.ts deleted file mode 100644 index 1d1fdb555d0c..000000000000 --- a/app/client/src/git/store/selectors/gitGlobalSelectors.ts +++ /dev/null @@ -1,21 +0,0 @@ -import type { GitRootState } from "../types"; - -export const selectGitGlobal = (state: GitRootState) => { - return state.git.global; -}; - -// global profile -export const selectFetchGlobalProfileState = (state: GitRootState) => - selectGitGlobal(state).globalProfile; - -export const selectUpdateGlobalProfileState = (state: GitRootState) => - selectGitGlobal(state).updateGlobalProfile; - -export const selectImportModalOpen = (state: GitRootState) => - selectGitGlobal(state).isImportModalOpen; - -export const selectGitImportState = (state: GitRootState) => - selectGitGlobal(state).gitImport; - -export const selectFetchGlobalSSHKeyState = (state: GitRootState) => - selectGitGlobal(state).globalSSHKey; diff --git a/app/client/src/git/store/selectors/gitArtifactSelectors.ts b/app/client/src/git/store/selectors/gitSingleArtifactSelectors.ts similarity index 92% rename from app/client/src/git/store/selectors/gitArtifactSelectors.ts rename to app/client/src/git/store/selectors/gitSingleArtifactSelectors.ts index 5bf8267df889..845a2cfe41fe 100644 --- a/app/client/src/git/store/selectors/gitArtifactSelectors.ts +++ b/app/client/src/git/store/selectors/gitSingleArtifactSelectors.ts @@ -1,4 +1,10 @@ -import type { GitArtifactDef, GitRootState } from "../types"; +import type { GitArtifactType } from "git/constants/enums"; +import type { GitRootState } from "../types"; + +export interface GitArtifactDef { + artifactType: keyof typeof GitArtifactType; + baseArtifactId: string; +} export const selectGitArtifact = ( state: GitRootState, @@ -15,7 +21,7 @@ export const selectMetadataState = ( artifactDef: GitArtifactDef, ) => selectGitArtifact(state, artifactDef)?.apiResponses.metadata; -export const selectConnected = ( +export const selectGitConnected = ( state: GitRootState, artifactDef: GitArtifactDef, ) => !!selectMetadataState(state, artifactDef)?.value; @@ -26,6 +32,11 @@ export const selectConnectState = ( artifactDef: GitArtifactDef, ) => selectGitArtifact(state, artifactDef)?.apiResponses.connect; +export const selectGitImportState = ( + state: GitRootState, + artifactDef: GitArtifactDef, +) => selectGitArtifact(state, artifactDef)?.apiResponses.gitImport; + export const selectFetchSSHKeysState = ( state: GitRootState, artifactDef: GitArtifactDef, @@ -41,11 +52,6 @@ export const selectConnectModalOpen = ( artifactDef: GitArtifactDef, ) => selectGitArtifact(state, artifactDef)?.ui.connectModalOpen; -export const selectConnectSuccessModalOpen = ( - state: GitRootState, - artifactDef: GitArtifactDef, -) => selectGitArtifact(state, artifactDef)?.ui.connectSuccessModalOpen; - export const selectDisconnectState = ( state: GitRootState, artifactDef: GitArtifactDef, @@ -111,14 +117,11 @@ export const selectConflictErrorModalOpen = ( export const selectCurrentBranch = ( state: GitRootState, - // need this to preserve interface - // eslint-disable-next-line @typescript-eslint/no-unused-vars artifactDef: GitArtifactDef, ) => { - return ( - state?.ui?.applications?.currentApplication?.gitApplicationMetadata - ?.branchName ?? null - ); + const gitMetadataState = selectMetadataState(state, artifactDef).value; + + return gitMetadataState?.branchName; }; export const selectFetchBranchesState = ( @@ -217,8 +220,10 @@ export const selectProtectedMode = ( artifactDef: GitArtifactDef, ) => { const currentBranch = selectCurrentBranch(state, artifactDef); - const protectedBranches = - selectFetchProtectedBranchesState(state, artifactDef)?.value ?? []; + const protectedBranches = selectFetchProtectedBranchesState( + state, + artifactDef, + ).value; return protectedBranches?.includes(currentBranch ?? "") ?? false; }; diff --git a/app/client/src/git/store/types.ts b/app/client/src/git/store/types.ts index 90a2e72998a5..ccb67a2e7a8b 100644 --- a/app/client/src/git/store/types.ts +++ b/app/client/src/git/store/types.ts @@ -17,7 +17,6 @@ import type { GitArtifactAPIResponsesReduxState as GitArtifactAPIResponsesReduxStateExtended, GitArtifactUIReduxState as GitArtifactUIReduxStateExtended, } from "git/ee/store/types"; -import type { FetchGlobalSSHKeyResponseData } from "git/requests/fetchGlobalSSHKeyRequest.types"; export interface GitApiError extends ApiResponseError { errorType?: string; @@ -34,10 +33,11 @@ export interface GitAsyncStateWithoutValue { loading: boolean; error: GitApiError | null; } -export interface GitArtifactAPIResponsesReduxState +export interface GitSingleArtifactAPIResponsesReduxState extends GitArtifactAPIResponsesReduxStateExtended { metadata: GitAsyncState; connect: GitAsyncStateWithoutValue; + gitImport: GitAsyncStateWithoutValue; status: GitAsyncState; commit: GitAsyncStateWithoutValue; pull: GitAsyncStateWithoutValue; @@ -60,10 +60,9 @@ export interface GitArtifactAPIResponsesReduxState generateSSHKey: GitAsyncStateWithoutValue; } -export interface GitArtifactUIReduxState +export interface GitSingleArtifactUIReduxState extends GitArtifactUIReduxStateExtended { connectModalOpen: boolean; - connectSuccessModalOpen: boolean; disconnectBaseArtifactId: string | null; disconnectArtifactName: string | null; branchPopupOpen: boolean; @@ -77,51 +76,30 @@ export interface GitArtifactUIReduxState conflictErrorModalOpen: boolean; repoLimitErrorModalOpen: boolean; } - -export interface GitArtifactDef { - artifactType: keyof typeof GitArtifactType; - baseArtifactId: string; +export interface GitSingleArtifactReduxState { + ui: GitSingleArtifactUIReduxState; + apiResponses: GitSingleArtifactAPIResponsesReduxState; } + export interface GitArtifactReduxState { - ui: GitArtifactUIReduxState; - apiResponses: GitArtifactAPIResponsesReduxState; + [key: string]: Record; } -export interface GitGlobalReduxState { +export interface GitConfigReduxState { globalProfile: GitAsyncState; updateGlobalProfile: GitAsyncStateWithoutValue; - gitImport: GitAsyncStateWithoutValue; - globalSSHKey: GitAsyncState; - // ui - isImportModalOpen: boolean; -} - -export type GitArtifactRootReduxState = Record< - string, - Record ->; - -export interface GitReduxState { - artifacts: GitArtifactRootReduxState; - global: GitGlobalReduxState; } export interface GitRootState { - // will have to remove this later, once metadata is fixed - ui: { - applications: { - currentApplication?: { - gitApplicationMetadata?: { - branchName: string; - }; - }; - }; + git: { + artifacts: GitArtifactReduxState; + config: GitConfigReduxState; }; - git: GitReduxState; } export interface GitArtifactBasePayload { - artifactDef: GitArtifactDef; + artifactType: keyof typeof GitArtifactType; + baseArtifactId: string; } export interface GitAsyncErrorPayload { diff --git a/app/client/src/layoutSystems/anvil/common/hooks/detachedWidgetHooks.ts b/app/client/src/layoutSystems/anvil/common/hooks/detachedWidgetHooks.ts index 6bf86d26a55d..c3ad4a82bd8d 100644 --- a/app/client/src/layoutSystems/anvil/common/hooks/detachedWidgetHooks.ts +++ b/app/client/src/layoutSystems/anvil/common/hooks/detachedWidgetHooks.ts @@ -1,6 +1,7 @@ import { useWidgetBorderStyles } from "./useWidgetBorderStyles"; import { useDispatch, useSelector } from "react-redux"; import { useWidgetSelection } from "utils/hooks/useWidgetSelection"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { SELECT_ANVIL_WIDGET_CUSTOM_EVENT } from "layoutSystems/anvil/utils/constants"; import log from "loglevel"; import { useEffect, useMemo } from "react"; @@ -8,7 +9,6 @@ import { getAnvilWidgetDOMId } from "layoutSystems/common/utils/LayoutElementPos import { getCurrentlyOpenAnvilDetachedWidgets } from "layoutSystems/anvil/integrations/modalSelectors"; import { getCanvasWidgetsStructure } from "ee/selectors/entitiesSelector"; import type { CanvasWidgetStructure } from "WidgetProvider/constants"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; /** * This hook is used to select and focus on a detached widget * As detached widgets are outside of the layout flow, we need to access the correct element in the DOM @@ -17,7 +17,7 @@ import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; */ export function useHandleDetachedWidgetSelect(widgetId: string) { const dispatch = useDispatch(); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const className = getAnvilWidgetDOMId(widgetId); const element = document.querySelector(`.${className}`); diff --git a/app/client/src/layoutSystems/anvil/common/hooks/useWidgetBorderStyles.ts b/app/client/src/layoutSystems/anvil/common/hooks/useWidgetBorderStyles.ts index 1213f9134b3a..fea0cc19424c 100644 --- a/app/client/src/layoutSystems/anvil/common/hooks/useWidgetBorderStyles.ts +++ b/app/client/src/layoutSystems/anvil/common/hooks/useWidgetBorderStyles.ts @@ -7,8 +7,8 @@ import { getWidgetsDistributingSpace, } from "layoutSystems/anvil/integrations/selectors"; import { useSelector } from "react-redux"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { isWidgetFocused, isWidgetSelected } from "selectors/widgetSelectors"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; export function useWidgetBorderStyles(widgetId: string, widgetType: string) { /** Selectors */ @@ -32,7 +32,7 @@ export function useWidgetBorderStyles(widgetId: string, widgetType: string) { const widgetsEffectedBySpaceDistribution = useSelector( getWidgetsDistributingSpace, ); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); /** EO selectors */ diff --git a/app/client/src/layoutSystems/anvil/editor/AnvilEditorWidgetOnion.tsx b/app/client/src/layoutSystems/anvil/editor/AnvilEditorWidgetOnion.tsx index 839c055f0f40..f5a6505a2be2 100644 --- a/app/client/src/layoutSystems/anvil/editor/AnvilEditorWidgetOnion.tsx +++ b/app/client/src/layoutSystems/anvil/editor/AnvilEditorWidgetOnion.tsx @@ -4,7 +4,7 @@ import type { BaseWidgetProps } from "widgets/BaseWidgetHOC/withBaseWidgetHOC"; import { AnvilWidgetComponent } from "../common/widgetComponent/AnvilWidgetComponent"; import { getWidgetSizeConfiguration } from "../utils/widgetUtils"; import { useSelector } from "react-redux"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { AnvilEditorFlexComponent } from "./AnvilEditorFlexComponent"; import { AnvilFlexComponent } from "../common/AnvilFlexComponent"; import { SKELETON_WIDGET_TYPE } from "constants/WidgetConstants"; @@ -25,7 +25,7 @@ import { SKELETON_WIDGET_TYPE } from "constants/WidgetConstants"; * @returns Enhanced Widget */ export const AnvilEditorWidgetOnion = (props: BaseWidgetProps) => { - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const { widgetSize, WidgetWrapper } = useMemo(() => { return { widgetSize: getWidgetSizeConfiguration(props.type, props, isPreviewMode), diff --git a/app/client/src/layoutSystems/anvil/editor/hooks/useAnvilWidgetHover.ts b/app/client/src/layoutSystems/anvil/editor/hooks/useAnvilWidgetHover.ts index e51d921bf1bd..abdb88561f68 100644 --- a/app/client/src/layoutSystems/anvil/editor/hooks/useAnvilWidgetHover.ts +++ b/app/client/src/layoutSystems/anvil/editor/hooks/useAnvilWidgetHover.ts @@ -2,7 +2,7 @@ import type { AppState } from "ee/reducers"; import { getAnvilSpaceDistributionStatus } from "layoutSystems/anvil/integrations/selectors"; import { useCallback, useEffect } from "react"; import { useSelector } from "react-redux"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { isWidgetFocused } from "selectors/widgetSelectors"; import { useWidgetSelection } from "utils/hooks/useWidgetSelection"; @@ -12,7 +12,7 @@ export const useAnvilWidgetHover = ( ) => { // Retrieve state from the Redux store const isFocused = useSelector(isWidgetFocused(widgetId)); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isDistributingSpace = useSelector(getAnvilSpaceDistributionStatus); const isDragging = useSelector( (state: AppState) => state.ui.widgetDragResize.isDragging, diff --git a/app/client/src/layoutSystems/anvil/integrations/sagas/LayoutElementPositionsSaga.ts b/app/client/src/layoutSystems/anvil/integrations/sagas/LayoutElementPositionsSaga.ts index 2cddcc974bc8..a882919710b1 100644 --- a/app/client/src/layoutSystems/anvil/integrations/sagas/LayoutElementPositionsSaga.ts +++ b/app/client/src/layoutSystems/anvil/integrations/sagas/LayoutElementPositionsSaga.ts @@ -8,7 +8,7 @@ import log from "loglevel"; import type { AppState } from "ee/reducers"; import { ReduxActionTypes } from "ee/constants/ReduxActionConstants"; import { APP_MODE } from "entities/App"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { getAppMode } from "ee/selectors/entitiesSelector"; import type { RefObject } from "react"; import { getAnvilSpaceDistributionStatus } from "../selectors"; @@ -87,7 +87,7 @@ function* readAndUpdateLayoutElementPositions() { // The positions are used only in the editor, so we should not be running this saga // in the viewer or the preview mode. - const isPreviewMode: boolean = yield select(selectCombinedPreviewMode); + const isPreviewMode: boolean = yield select(combinedPreviewModeSelector); const appMode: APP_MODE = yield select(getAppMode); if (isPreviewMode || appMode === APP_MODE.PUBLISHED) { diff --git a/app/client/src/layoutSystems/anvil/layoutComponents/components/zone/useZoneMinWidth.ts b/app/client/src/layoutSystems/anvil/layoutComponents/components/zone/useZoneMinWidth.ts index c8ba600c5fb6..fe49ee655230 100644 --- a/app/client/src/layoutSystems/anvil/layoutComponents/components/zone/useZoneMinWidth.ts +++ b/app/client/src/layoutSystems/anvil/layoutComponents/components/zone/useZoneMinWidth.ts @@ -3,20 +3,22 @@ import { ChildrenMapContext } from "layoutSystems/anvil/context/childrenMapConte import type { WidgetProps } from "widgets/BaseWidget"; import { RenderModes } from "constants/WidgetConstants"; import { useSelector } from "react-redux"; -import { getRenderMode } from "selectors/editorSelectors"; +import { + combinedPreviewModeSelector, + getRenderMode, +} from "selectors/editorSelectors"; import type { SizeConfig } from "WidgetProvider/constants"; import { getWidgetSizeConfiguration } from "layoutSystems/anvil/utils/widgetUtils"; import type { CanvasWidgetsReduxState } from "reducers/entityReducers/canvasWidgetsReducer"; import { getWidgets } from "sagas/selectors"; import isObject from "lodash/isObject"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; export function useZoneMinWidth() { const childrenMap: Record = useContext(ChildrenMapContext); const widgets: CanvasWidgetsReduxState = useSelector(getWidgets); const renderMode: RenderModes = useSelector(getRenderMode); - const isPreviewMode: boolean = useSelector(selectCombinedPreviewMode); + const isPreviewMode: boolean = useSelector(combinedPreviewModeSelector); if (renderMode === RenderModes.CANVAS && !isPreviewMode) return "auto"; diff --git a/app/client/src/layoutSystems/anvil/sectionSpaceDistributor/SectionSpaceDistributor.tsx b/app/client/src/layoutSystems/anvil/sectionSpaceDistributor/SectionSpaceDistributor.tsx index 25e94d38d9e8..fd719bfd1f6f 100644 --- a/app/client/src/layoutSystems/anvil/sectionSpaceDistributor/SectionSpaceDistributor.tsx +++ b/app/client/src/layoutSystems/anvil/sectionSpaceDistributor/SectionSpaceDistributor.tsx @@ -2,7 +2,7 @@ import { getLayoutElementPositions } from "layoutSystems/common/selectors"; import type { LayoutElementPosition } from "layoutSystems/common/types"; import React, { useMemo } from "react"; import { useSelector } from "react-redux"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import type { WidgetLayoutProps } from "../utils/anvilTypes"; import { getWidgetByID } from "sagas/selectors"; import { getDefaultSpaceDistributed } from "./utils/spaceRedistributionSagaUtils"; @@ -113,7 +113,7 @@ export const SectionSpaceDistributor = ( props: SectionSpaceDistributorProps, ) => { const { zones } = props; - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isWidgetSelectionBlocked = useSelector(getWidgetSelectionBlock); const isDragging = useSelector( (state) => state.ui.widgetDragResize.isDragging, diff --git a/app/client/src/layoutSystems/anvil/viewer/AnvilViewerWidgetOnion.tsx b/app/client/src/layoutSystems/anvil/viewer/AnvilViewerWidgetOnion.tsx index 763785755918..99ca7dddf492 100644 --- a/app/client/src/layoutSystems/anvil/viewer/AnvilViewerWidgetOnion.tsx +++ b/app/client/src/layoutSystems/anvil/viewer/AnvilViewerWidgetOnion.tsx @@ -5,7 +5,7 @@ import { AnvilWidgetComponent } from "../common/widgetComponent/AnvilWidgetCompo import type { SizeConfig } from "WidgetProvider/constants"; import { getWidgetSizeConfiguration } from "../utils/widgetUtils"; import { useSelector } from "react-redux"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; /** * AnvilViewerWidgetOnion @@ -20,7 +20,7 @@ import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; * @returns Enhanced Widget */ export const AnvilViewerWidgetOnion = (props: BaseWidgetProps) => { - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const widgetSize: SizeConfig = useMemo( () => getWidgetSizeConfiguration(props.type, props, isPreviewMode), [isPreviewMode, props.type], diff --git a/app/client/src/layoutSystems/autolayout/common/FlexComponent.tsx b/app/client/src/layoutSystems/autolayout/common/FlexComponent.tsx index 334ca9fd95ec..20edbf4ce0d8 100644 --- a/app/client/src/layoutSystems/autolayout/common/FlexComponent.tsx +++ b/app/client/src/layoutSystems/autolayout/common/FlexComponent.tsx @@ -4,7 +4,10 @@ import styled from "styled-components"; import { WIDGET_PADDING } from "constants/WidgetConstants"; import { useSelector } from "react-redux"; -import { snipingModeSelector } from "selectors/editorSelectors"; +import { + combinedPreviewModeSelector, + snipingModeSelector, +} from "selectors/editorSelectors"; import { getIsResizing } from "selectors/widgetSelectors"; import { useClickToSelectWidget } from "utils/hooks/useClickToSelectWidget"; import { usePositionedContainerZIndex } from "utils/hooks/usePositionedContainerZIndex"; @@ -13,7 +16,6 @@ import { RESIZE_BORDER_BUFFER } from "layoutSystems/common/resizer/common"; import { checkIsDropTarget } from "WidgetProvider/factory/helpers"; import type { FlexComponentProps } from "../../autolayout/utils/types"; import { useHoverToFocusWidget } from "utils/hooks/useHoverToFocusWidget"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; const FlexWidget = styled.div` position: relative; @@ -56,7 +58,7 @@ export function FlexComponent(props: FlexComponentProps) { )} t--widget-${props.widgetName.toLowerCase()}`, [props.parentId, props.widgetId, props.widgetType, props.widgetName], ); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isResizing = useSelector(getIsResizing); const widgetDimensionsViewCss = { diff --git a/app/client/src/layoutSystems/common/dropTarget/DropTargetComponent.tsx b/app/client/src/layoutSystems/common/dropTarget/DropTargetComponent.tsx index fcb93c9205a6..d1df63825448 100644 --- a/app/client/src/layoutSystems/common/dropTarget/DropTargetComponent.tsx +++ b/app/client/src/layoutSystems/common/dropTarget/DropTargetComponent.tsx @@ -21,7 +21,10 @@ import { } from "actions/autoHeightActions"; import { useDispatch } from "react-redux"; import { getDragDetails } from "sagas/selectors"; -import { getOccupiedSpacesSelectorForContainer } from "selectors/editorSelectors"; +import { + combinedPreviewModeSelector, + getOccupiedSpacesSelectorForContainer, +} from "selectors/editorSelectors"; import { getCanvasSnapRows } from "utils/WidgetPropsUtils"; import { useAutoHeightUIState } from "utils/hooks/autoHeightUIHooks"; import { useShowPropertyPane } from "utils/hooks/dragResizeHooks"; @@ -39,7 +42,6 @@ import { import DragLayerComponent from "./DragLayerComponent"; import Onboarding from "./OnBoarding"; import { isDraggingBuildingBlockToCanvas } from "selectors/buildingBlocksSelectors"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; export type DropTargetComponentProps = PropsWithChildren<{ snapColumnSpace: number; @@ -194,7 +196,7 @@ function useUpdateRows( export function DropTargetComponent(props: DropTargetComponentProps) { // Get if this is in preview mode. - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isAppSettingsPaneWithNavigationTabOpen = useSelector( getIsAppSettingsPaneWithNavigationTabOpen, ); diff --git a/app/client/src/layoutSystems/common/resizer/ModalResizableLayer.tsx b/app/client/src/layoutSystems/common/resizer/ModalResizableLayer.tsx index 1a516b9623fe..559556bbbf42 100644 --- a/app/client/src/layoutSystems/common/resizer/ModalResizableLayer.tsx +++ b/app/client/src/layoutSystems/common/resizer/ModalResizableLayer.tsx @@ -19,9 +19,11 @@ import { } from "./ResizeStyledComponents"; import type { UIElementSize } from "./ResizableUtils"; import { useModalWidth } from "widgets/ModalWidget/component/useModalWidth"; -import { snipingModeSelector } from "selectors/editorSelectors"; +import { + combinedPreviewModeSelector, + snipingModeSelector, +} from "selectors/editorSelectors"; import { getWidgetSelectionBlock } from "../../../selectors/ui"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; const minSize = 100; /** @@ -99,7 +101,7 @@ export const ModalResizableLayer = ({ widgetType: "MODAL_WIDGET", }); }; - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isSnipingMode = useSelector(snipingModeSelector); const isWidgetSelectionBlocked = useSelector(getWidgetSelectionBlock); const enableResizing = diff --git a/app/client/src/layoutSystems/common/resizer/ResizableComponent.tsx b/app/client/src/layoutSystems/common/resizer/ResizableComponent.tsx index fb5aca05d16f..f0336f382b87 100644 --- a/app/client/src/layoutSystems/common/resizer/ResizableComponent.tsx +++ b/app/client/src/layoutSystems/common/resizer/ResizableComponent.tsx @@ -17,7 +17,10 @@ import { FixedLayoutResizable } from "layoutSystems/fixedlayout/common/resizer/F import { SelectionRequestType } from "sagas/WidgetSelectUtils"; import { getIsAutoLayout } from "selectors/canvasSelectors"; import { getIsAppSettingsPaneWithNavigationTabOpen } from "selectors/appSettingsPaneSelectors"; -import { snipingModeSelector } from "selectors/editorSelectors"; +import { + combinedPreviewModeSelector, + snipingModeSelector, +} from "selectors/editorSelectors"; import { getParentToOpenSelector, isWidgetFocused, @@ -66,7 +69,6 @@ import { getAltBlockWidgetSelection, getWidgetSelectionBlock, } from "selectors/ui"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; export type ResizableComponentProps = WidgetProps & { paddingOffset: number; @@ -81,7 +83,7 @@ export const ResizableComponent = memo(function ResizableComponent( const isAutoLayout = useSelector(getIsAutoLayout); const Resizable = isAutoLayout ? AutoLayoutResizable : FixedLayoutResizable; const isSnipingMode = useSelector(snipingModeSelector); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isWidgetSelectionBlock = useSelector(getWidgetSelectionBlock); const isAltWidgetSelectionBlock = useSelector(getAltBlockWidgetSelection); const isAppSettingsPaneWithNavigationTabOpen: boolean = useSelector( diff --git a/app/client/src/layoutSystems/common/utils/LayoutElementPositionsObserver/usePositionObserver.ts b/app/client/src/layoutSystems/common/utils/LayoutElementPositionsObserver/usePositionObserver.ts index 9c981c66f397..1d5a9c38f354 100644 --- a/app/client/src/layoutSystems/common/utils/LayoutElementPositionsObserver/usePositionObserver.ts +++ b/app/client/src/layoutSystems/common/utils/LayoutElementPositionsObserver/usePositionObserver.ts @@ -3,7 +3,7 @@ import { useEffect } from "react"; import { positionObserver } from "."; import { APP_MODE } from "entities/App"; import { useSelector } from "react-redux"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { getAppMode } from "ee/selectors/entitiesSelector"; import { getAnvilLayoutDOMId, getAnvilWidgetDOMId } from "./utils"; import { LayoutComponentTypes } from "layoutSystems/anvil/utils/anvilTypes"; @@ -13,7 +13,7 @@ export function useObserveDetachedWidget(widgetId: string) { // We don't need the observer in preview mode or the published app // This is because the positions need to be observed only to enable // editor features - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const appMode = useSelector(getAppMode); if (isPreviewMode || appMode === APP_MODE.PUBLISHED) { @@ -54,7 +54,7 @@ export function usePositionObserver( }, ref: RefObject, ) { - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const appMode = useSelector(getAppMode); useEffect(() => { diff --git a/app/client/src/layoutSystems/common/widgetName/index.tsx b/app/client/src/layoutSystems/common/widgetName/index.tsx index 8d5770b995a0..bb8c265946e5 100644 --- a/app/client/src/layoutSystems/common/widgetName/index.tsx +++ b/app/client/src/layoutSystems/common/widgetName/index.tsx @@ -8,6 +8,7 @@ import { SelectionRequestType } from "sagas/WidgetSelectUtils"; import { getIsAppSettingsPaneWithNavigationTabOpen } from "selectors/appSettingsPaneSelectors"; import { hideErrors } from "selectors/debuggerSelectors"; import { + combinedPreviewModeSelector, getIsAutoLayout, snipingModeSelector, } from "selectors/editorSelectors"; @@ -30,7 +31,6 @@ import { RESIZE_BORDER_BUFFER } from "layoutSystems/common/resizer/common"; import { Layers } from "constants/Layers"; import memoize from "micro-memoize"; import { NavigationMethod } from "utils/history"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; const WidgetTypes = WidgetFactory.widgetTypes; @@ -78,7 +78,7 @@ interface WidgetNameComponentProps { export function WidgetNameComponent(props: WidgetNameComponentProps) { const dispatch = useDispatch(); const isSnipingMode = useSelector(snipingModeSelector); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isAppSettingsPaneWithNavigationTabOpen = useSelector( getIsAppSettingsPaneWithNavigationTabOpen, ); diff --git a/app/client/src/layoutSystems/fixedlayout/common/autoHeightOverlay/index.tsx b/app/client/src/layoutSystems/fixedlayout/common/autoHeightOverlay/index.tsx index 48015d2efff1..89519283f7cb 100644 --- a/app/client/src/layoutSystems/fixedlayout/common/autoHeightOverlay/index.tsx +++ b/app/client/src/layoutSystems/fixedlayout/common/autoHeightOverlay/index.tsx @@ -3,7 +3,7 @@ import type { CSSProperties } from "react"; import React, { memo } from "react"; import { useSelector } from "react-redux"; import { getIsAppSettingsPaneWithNavigationTabOpen } from "selectors/appSettingsPaneSelectors"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import type { WidgetProps } from "widgets/BaseWidget"; import AutoHeightOverlayWithStateContext from "./AutoHeightOverlayWithStateContext"; @@ -31,7 +31,7 @@ const AutoHeightOverlayContainer: React.FC = selectedWidgets, } = useSelector((state: AppState) => state.ui.widgetDragResize); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isAppSettingsPaneWithNavigationTabOpen = useSelector( getIsAppSettingsPaneWithNavigationTabOpen, ); diff --git a/app/client/src/layoutSystems/fixedlayout/editor/FixedLayoutCanvasArenas/CanvasSelectionArena.tsx b/app/client/src/layoutSystems/fixedlayout/editor/FixedLayoutCanvasArenas/CanvasSelectionArena.tsx index c299eaef18db..c0cf29167981 100644 --- a/app/client/src/layoutSystems/fixedlayout/editor/FixedLayoutCanvasArenas/CanvasSelectionArena.tsx +++ b/app/client/src/layoutSystems/fixedlayout/editor/FixedLayoutCanvasArenas/CanvasSelectionArena.tsx @@ -21,6 +21,7 @@ import { getIsDraggingForSelection, } from "selectors/canvasSelectors"; import { + combinedPreviewModeSelector, getCurrentApplicationLayout, getCurrentPageId, } from "selectors/editorSelectors"; @@ -30,7 +31,6 @@ import type { XYCord } from "layoutSystems/common/canvasArenas/ArenaTypes"; import { useCanvasDragToScroll } from "layoutSystems/common/canvasArenas/useCanvasDragToScroll"; import { StickyCanvasArena } from "layoutSystems/common/canvasArenas/StickyCanvasArena"; import { getWidgetSelectionBlock } from "../../../../selectors/ui"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; export interface SelectedArenaDimensions { top: number; @@ -71,7 +71,7 @@ export function CanvasSelectionArena({ (parentWidget && parentWidget.detachFromLayout) ); const appMode = useSelector(getAppMode); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isWidgetSelectionBlocked = useSelector(getWidgetSelectionBlock); const isAppSettingsPaneWithNavigationTabOpen = useSelector( getIsAppSettingsPaneWithNavigationTabOpen, diff --git a/app/client/src/pages/AppViewer/Navigation/Sidebar.tsx b/app/client/src/pages/AppViewer/Navigation/Sidebar.tsx index 5ad23ff2e567..3b6b80aa7328 100644 --- a/app/client/src/pages/AppViewer/Navigation/Sidebar.tsx +++ b/app/client/src/pages/AppViewer/Navigation/Sidebar.tsx @@ -12,7 +12,10 @@ import ShareButton from "./components/ShareButton"; import PrimaryCTA from "../PrimaryCTA"; import { useHref } from "pages/Editor/utils"; import { builderURL } from "ee/RouteBuilder"; -import { getCurrentBasePageId } from "selectors/editorSelectors"; +import { + combinedPreviewModeSelector, + getCurrentBasePageId, +} from "selectors/editorSelectors"; import type { User } from "constants/userConstants"; import SidebarProfileComponent from "./components/SidebarProfileComponent"; import CollapseButton from "./components/CollapseButton"; @@ -33,7 +36,6 @@ import MenuItemContainer from "./components/MenuItemContainer"; import BackToAppsButton from "./components/BackToAppsButton"; import { IDE_HEADER_HEIGHT } from "@appsmith/ads"; import { BOTTOM_BAR_HEIGHT } from "components/BottomBar/constants"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; interface SidebarProps { currentApplicationDetails?: ApplicationPayload; @@ -79,7 +81,7 @@ export function Sidebar(props: SidebarProps) { const isPinned = useSelector(getAppSidebarPinned); const [isOpen, setIsOpen] = useState(true); const { x } = useMouse(); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isAppSettingsPaneWithNavigationTabOpen = useSelector( getIsAppSettingsPaneWithNavigationTabOpen, ); diff --git a/app/client/src/pages/AppViewer/Navigation/TopInline.tsx b/app/client/src/pages/AppViewer/Navigation/TopInline.tsx index af09e8497fd1..f15dd093ff21 100644 --- a/app/client/src/pages/AppViewer/Navigation/TopInline.tsx +++ b/app/client/src/pages/AppViewer/Navigation/TopInline.tsx @@ -5,12 +5,14 @@ import MenuItem from "./components/MenuItem"; import { Container } from "./TopInline.styled"; import MenuItemContainer from "./components/MenuItemContainer"; import MoreDropdownButton from "./components/MoreDropdownButton"; -import { getCanvasWidth } from "selectors/editorSelectors"; +import { + combinedPreviewModeSelector, + getCanvasWidth, +} from "selectors/editorSelectors"; import { useSelector } from "react-redux"; import { getIsAppSettingsPaneWithNavigationTabOpen } from "selectors/appSettingsPaneSelectors"; import { throttle } from "lodash"; import type { NavigationProps } from "./constants"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; export function TopInline(props: NavigationProps) { const { currentApplicationDetails, pages } = props; @@ -21,7 +23,7 @@ export function TopInline(props: NavigationProps) { const maxMenuItemWidth = 220; const [maxMenuItemsThatCanFit, setMaxMenuItemsThatCanFit] = useState(0); const { width: screenWidth } = useWindowSizeHooks(); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isAppSettingsPaneWithNavigationTabOpen = useSelector( getIsAppSettingsPaneWithNavigationTabOpen, ); diff --git a/app/client/src/pages/AppViewer/PrimaryCTA.test.tsx b/app/client/src/pages/AppViewer/PrimaryCTA.test.tsx index 63b76d0e0fcc..3b03a559fbfb 100644 --- a/app/client/src/pages/AppViewer/PrimaryCTA.test.tsx +++ b/app/client/src/pages/AppViewer/PrimaryCTA.test.tsx @@ -7,11 +7,6 @@ import { lightTheme } from "selectors/themeSelectors"; import PrimaryCTA from "./PrimaryCTA"; import configureStore from "redux-mock-store"; -jest.mock("pages/Editor/gitSync/hooks/modHooks", () => ({ - ...jest.requireActual("pages/Editor/gitSync/hooks/modHooks"), - useGitProtectedMode: jest.fn(() => false), -})); - jest.mock("react-router", () => ({ ...jest.requireActual("react-router"), useHistory: () => ({ push: jest.fn() }), diff --git a/app/client/src/pages/AppViewer/PrimaryCTA.tsx b/app/client/src/pages/AppViewer/PrimaryCTA.tsx index 97d0363bbf5f..9e2816166454 100644 --- a/app/client/src/pages/AppViewer/PrimaryCTA.tsx +++ b/app/client/src/pages/AppViewer/PrimaryCTA.tsx @@ -25,8 +25,8 @@ import { Icon, Tooltip } from "@appsmith/ads"; import { getApplicationNameTextColor } from "./utils"; import { ButtonVariantTypes } from "components/constants"; import { setPreviewModeInitAction } from "actions/editorActions"; +import { protectedModeSelector } from "selectors/gitSyncSelectors"; import { getCurrentApplication } from "ee/selectors/applicationSelectors"; -import { useGitProtectedMode } from "pages/Editor/gitSync/hooks/modHooks"; /** * --------------------------------------------------------------------------------------------------- @@ -67,7 +67,7 @@ function PrimaryCTA(props: Props) { const canEdit = isPermitted(userPermissions, permissionRequired); const [isForkModalOpen, setIsForkModalOpen] = useState(false); const isPreviewMode = useSelector(previewModeSelector); - const isProtectedMode = useGitProtectedMode(); + const isProtectedMode = useSelector(protectedModeSelector); const dispatch = useDispatch(); const location = useLocation(); const queryParams = new URLSearchParams(location.search); diff --git a/app/client/src/pages/Editor/AppSettingsPane/AppSettings/ImportAppSettings.tsx b/app/client/src/pages/Editor/AppSettingsPane/AppSettings/ImportAppSettings.tsx index b721e7c5c7af..8da3b25343c3 100644 --- a/app/client/src/pages/Editor/AppSettingsPane/AppSettings/ImportAppSettings.tsx +++ b/app/client/src/pages/Editor/AppSettingsPane/AppSettings/ImportAppSettings.tsx @@ -8,8 +8,8 @@ import ImportModal from "pages/common/ImportModal"; import React from "react"; import { useSelector } from "react-redux"; import { getCurrentApplicationId } from "selectors/editorSelectors"; +import { getIsGitConnected } from "selectors/gitSyncSelectors"; import styled from "styled-components"; -import { useGitConnected } from "pages/Editor/gitSync/hooks/modHooks"; const SettingWrapper = styled.div` display: flex; @@ -21,7 +21,7 @@ const SettingWrapper = styled.div` export function ImportAppSettings() { const appId = useSelector(getCurrentApplicationId); const workspace = useSelector(getCurrentAppWorkspace); - const isGitConnected = useGitConnected(); + const isGitConnected = useSelector(getIsGitConnected); const [isModalOpen, setIsModalOpen] = React.useState(false); function handleClose() { diff --git a/app/client/src/pages/Editor/Canvas.tsx b/app/client/src/pages/Editor/Canvas.tsx index c34f2fc358c8..742e6d8a74b1 100644 --- a/app/client/src/pages/Editor/Canvas.tsx +++ b/app/client/src/pages/Editor/Canvas.tsx @@ -5,7 +5,7 @@ import * as Sentry from "@sentry/react"; import { useDispatch, useSelector } from "react-redux"; import type { CanvasWidgetStructure } from "WidgetProvider/constants"; import useWidgetFocus from "utils/hooks/useWidgetFocus"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { getSelectedAppTheme } from "selectors/appThemingSelectors"; import { getViewportClassName } from "layoutSystems/autolayout/utils/AutoLayoutUtils"; import { @@ -44,7 +44,7 @@ const Wrapper = styled.section<{ `; const Canvas = (props: CanvasProps) => { const { canvasWidth } = props; - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isAppSettingsPaneWithNavigationTabOpen = useSelector( getIsAppSettingsPaneWithNavigationTabOpen, ); diff --git a/app/client/src/pages/Editor/GlobalHotKeys/GlobalHotKeys.tsx b/app/client/src/pages/Editor/GlobalHotKeys/GlobalHotKeys.tsx index 1e01349df831..651f57e792c0 100644 --- a/app/client/src/pages/Editor/GlobalHotKeys/GlobalHotKeys.tsx +++ b/app/client/src/pages/Editor/GlobalHotKeys/GlobalHotKeys.tsx @@ -45,8 +45,8 @@ import { toast } from "@appsmith/ads"; import { showDebuggerFlag } from "selectors/debuggerSelectors"; import { getIsFirstTimeUserOnboardingEnabled } from "selectors/onboardingSelectors"; import WalkthroughContext from "components/featureWalkthrough/walkthroughContext"; +import { protectedModeSelector } from "selectors/gitSyncSelectors"; import { setPreviewModeInitAction } from "actions/editorActions"; -import { selectGitApplicationProtectedMode } from "selectors/gitModSelectors"; interface Props { copySelectedWidget: () => void; @@ -372,17 +372,15 @@ class GlobalHotKeys extends React.Component { } } -const mapStateToProps = (state: AppState) => { - return { - selectedWidget: getLastSelectedWidget(state), - selectedWidgets: getSelectedWidgets(state), - isDebuggerOpen: showDebuggerFlag(state), - appMode: getAppMode(state), - isPreviewMode: previewModeSelector(state), - isProtectedMode: selectGitApplicationProtectedMode(state), - isSignpostingEnabled: getIsFirstTimeUserOnboardingEnabled(state), - }; -}; +const mapStateToProps = (state: AppState) => ({ + selectedWidget: getLastSelectedWidget(state), + selectedWidgets: getSelectedWidgets(state), + isDebuggerOpen: showDebuggerFlag(state), + appMode: getAppMode(state), + isPreviewMode: previewModeSelector(state), + isProtectedMode: protectedModeSelector(state), + isSignpostingEnabled: getIsFirstTimeUserOnboardingEnabled(state), +}); // TODO: Fix this the next time the file is edited // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/app/client/src/pages/Editor/IDE/Header/DeployButton.tsx b/app/client/src/pages/Editor/IDE/Header/DeployButton.tsx deleted file mode 100644 index 843da728dddf..000000000000 --- a/app/client/src/pages/Editor/IDE/Header/DeployButton.tsx +++ /dev/null @@ -1,131 +0,0 @@ -import { Button, Tooltip } from "@appsmith/ads"; -import { objectKeys } from "@appsmith/utils"; -import { showConnectGitModal } from "actions/gitSyncActions"; -import { publishApplication } from "ee/actions/applicationActions"; -import { getCurrentApplication } from "ee/selectors/applicationSelectors"; -import type { NavigationSetting } from "constants/AppConstants"; -import { - createMessage, - DEPLOY_BUTTON_TOOLTIP, - DEPLOY_MENU_OPTION, - PACKAGE_UPGRADING_ACTION_STATUS, -} from "ee/constants/messages"; -import { getIsPackageUpgrading } from "ee/selectors/packageSelectors"; -import AnalyticsUtil from "ee/utils/AnalyticsUtil"; -import { useGitOps, useGitProtectedMode } from "git"; -import { - useGitConnected, - useGitModEnabled, -} from "pages/Editor/gitSync/hooks/modHooks"; -import React, { useCallback } from "react"; -import { useDispatch, useSelector } from "react-redux"; -import { - getCurrentApplicationId, - getIsPublishingApplication, -} from "selectors/editorSelectors"; -import styled from "styled-components"; - -// This wrapper maintains pointer events for tooltips when the child button is disabled. -// Without this, disabled buttons won't trigger tooltips because they have pointer-events: none -const StyledTooltipTarget = styled.span` - display: inline-block; -`; - -function DeployButton() { - const applicationId = useSelector(getCurrentApplicationId); - const currentApplication = useSelector(getCurrentApplication); - const isPackageUpgrading = useSelector(getIsPackageUpgrading); - const isProtectedMode = useGitProtectedMode(); - const isDeployDisabled = isPackageUpgrading || isProtectedMode; - const isPublishing = useSelector(getIsPublishingApplication); - const isGitConnected = useGitConnected(); - const isGitModEnabled = useGitModEnabled(); - const { toggleOpsModal } = useGitOps(); - - const deployTooltipText = isPackageUpgrading - ? createMessage(PACKAGE_UPGRADING_ACTION_STATUS, "deploy this app") - : createMessage(DEPLOY_BUTTON_TOOLTIP); - - const dispatch = useDispatch(); - - const handlePublish = useCallback(() => { - if (applicationId) { - dispatch(publishApplication(applicationId)); - - const appName = currentApplication ? currentApplication.name : ""; - const pageCount = currentApplication?.pages?.length; - const navigationSettingsWithPrefix: Record< - string, - NavigationSetting[keyof NavigationSetting] - > = {}; - - if (currentApplication?.applicationDetail?.navigationSetting) { - const settingKeys = objectKeys( - currentApplication.applicationDetail.navigationSetting, - ) as Array; - - settingKeys.map((key: keyof NavigationSetting) => { - if (currentApplication?.applicationDetail?.navigationSetting?.[key]) { - const value: NavigationSetting[keyof NavigationSetting] = - currentApplication.applicationDetail.navigationSetting[key]; - - navigationSettingsWithPrefix[`navigationSetting_${key}`] = value; - } - }); - } - - AnalyticsUtil.logEvent("PUBLISH_APP", { - appId: applicationId, - appName, - pageCount, - ...navigationSettingsWithPrefix, - isPublic: !!currentApplication?.isPublic, - templateTitle: currentApplication?.forkedFromTemplateTitle, - }); - } - }, [applicationId, currentApplication, dispatch]); - - const handleClickDeploy = useCallback(() => { - if (isGitConnected) { - if (isGitModEnabled) { - toggleOpsModal(true); - } else { - dispatch(showConnectGitModal()); - } - - AnalyticsUtil.logEvent("GS_DEPLOY_GIT_CLICK", { - source: "Deploy button", - }); - } else { - handlePublish(); - } - }, [ - dispatch, - handlePublish, - isGitConnected, - isGitModEnabled, - toggleOpsModal, - ]); - - return ( - - - - - - ); -} - -export default DeployButton; diff --git a/app/client/src/pages/Editor/IDE/Header/index.tsx b/app/client/src/pages/Editor/IDE/Header/index.tsx index c26b641ba40d..f8e75cda9db7 100644 --- a/app/client/src/pages/Editor/IDE/Header/index.tsx +++ b/app/client/src/pages/Editor/IDE/Header/index.tsx @@ -1,6 +1,7 @@ -import React, { useState } from "react"; +import React, { useCallback, useState } from "react"; import { Flex, + Tooltip, Divider, Modal, ModalContent, @@ -10,6 +11,7 @@ import { TabsList, Tab, TabPanel, + Button, Link, IDEHeader, IDEHeaderTitle, @@ -22,15 +24,19 @@ import { APPLICATION_INVITE, COMMUNITY_TEMPLATES, createMessage, + DEPLOY_BUTTON_TOOLTIP, + DEPLOY_MENU_OPTION, IN_APP_EMBED_SETTING, INVITE_TAB, HEADER_TITLES, + PACKAGE_UPGRADING_ACTION_STATUS, } from "ee/constants/messages"; import EditorName from "pages/Editor/EditorName"; import { getCurrentApplicationId, getCurrentPageId, getIsPageSaving, + getIsPublishingApplication, getPageById, getPageSavingError, } from "selectors/editorSelectors"; @@ -40,7 +46,10 @@ import { getIsErroredSavingAppName, getIsSavingAppName, } from "ee/selectors/applicationSelectors"; -import { updateApplication } from "ee/actions/applicationActions"; +import { + publishApplication, + updateApplication, +} from "ee/actions/applicationActions"; import { getCurrentAppWorkspace } from "ee/selectors/selectedWorkspaceSelectors"; import { Omnibar } from "pages/Editor/commons/Omnibar"; import ToggleModeButton from "pages/Editor/ToggleModeButton"; @@ -53,6 +62,13 @@ import DeployLinkButtonDialog from "components/designSystems/appsmith/header/Dep import { useFeatureFlag } from "utils/hooks/useFeatureFlag"; import { FEATURE_FLAG } from "ee/entities/FeatureFlag"; import { getAppsmithConfigs } from "ee/configs"; +import { + getIsGitConnected, + protectedModeSelector, +} from "selectors/gitSyncSelectors"; +import { showConnectGitModal } from "actions/gitSyncActions"; +import AnalyticsUtil from "ee/utils/AnalyticsUtil"; +import type { NavigationSetting } from "constants/AppConstants"; import { useHref } from "pages/Editor/utils"; import { viewerURL } from "ee/RouteBuilder"; import HelpBar from "components/editorComponents/GlobalSearch/HelpBar"; @@ -64,8 +80,7 @@ import { APPLICATIONS_URL } from "constants/routes"; import { useNavigationMenuData } from "../../EditorName/useNavigationMenuData"; import useLibraryHeaderTitle from "ee/pages/Editor/IDE/Header/useLibraryHeaderTitle"; import { AppsmithLink } from "pages/Editor/AppsmithLink"; -import DeployButton from "./DeployButton"; -import GitApplicationContextProvider from "components/gitContexts/GitApplicationContextProvider"; +import { getIsPackageUpgrading } from "ee/selectors/packageSelectors"; const StyledDivider = styled(Divider)` height: 50%; @@ -73,6 +88,12 @@ const StyledDivider = styled(Divider)` margin-right: 8px; `; +// This wrapper maintains pointer events for tooltips when the child button is disabled. +// Without this, disabled buttons won't trigger tooltips because they have pointer-events: none +const StyledTooltipTarget = styled.span` + display: inline-block; +`; + const { cloudHosting } = getAppsmithConfigs(); interface HeaderTitleProps { @@ -116,11 +137,19 @@ const Header = () => { const currentApplication = useSelector(getCurrentApplication); const isErroredSavingName = useSelector(getIsErroredSavingAppName); const applicationList = useSelector(getApplicationList); + const isProtectedMode = useSelector(protectedModeSelector); + const isPackageUpgrading = useSelector(getIsPackageUpgrading); + const isPublishing = useSelector(getIsPublishingApplication); + const isGitConnected = useSelector(getIsGitConnected); const pageId = useSelector(getCurrentPageId) as string; const currentPage = useSelector(getPageById(pageId)); const appState = useCurrentAppState(); const isSaving = useSelector(getIsPageSaving); const pageSaveError = useSelector(getPageSavingError); + const isDeployDisabled = isPackageUpgrading || isProtectedMode; + const deployTooltipText = isPackageUpgrading + ? createMessage(PACKAGE_UPGRADING_ACTION_STATUS, "deploy this app") + : createMessage(DEPLOY_BUTTON_TOOLTIP); // states const [isPopoverOpen, setIsPopoverOpen] = useState(false); const [showModal, setShowModal] = useState(false); @@ -150,8 +179,56 @@ const Header = () => { dispatch(updateApplication(id, data)); }; + const handlePublish = useCallback(() => { + if (applicationId) { + dispatch(publishApplication(applicationId)); + + const appName = currentApplication ? currentApplication.name : ""; + const pageCount = currentApplication?.pages?.length; + const navigationSettingsWithPrefix: Record< + string, + NavigationSetting[keyof NavigationSetting] + > = {}; + + if (currentApplication?.applicationDetail?.navigationSetting) { + const settingKeys = Object.keys( + currentApplication.applicationDetail.navigationSetting, + ) as Array; + + settingKeys.map((key: keyof NavigationSetting) => { + if (currentApplication?.applicationDetail?.navigationSetting?.[key]) { + const value: NavigationSetting[keyof NavigationSetting] = + currentApplication.applicationDetail.navigationSetting[key]; + + navigationSettingsWithPrefix[`navigationSetting_${key}`] = value; + } + }); + } + + AnalyticsUtil.logEvent("PUBLISH_APP", { + appId: applicationId, + appName, + pageCount, + ...navigationSettingsWithPrefix, + isPublic: !!currentApplication?.isPublic, + templateTitle: currentApplication?.forkedFromTemplateTitle, + }); + } + }, [applicationId, currentApplication, dispatch]); + + const handleClickDeploy = useCallback(() => { + if (isGitConnected) { + dispatch(showConnectGitModal()); + AnalyticsUtil.logEvent("GS_DEPLOY_GIT_CLICK", { + source: "Deploy button", + }); + } else { + handlePublish(); + } + }, [dispatch, handlePublish, isGitConnected]); + return ( - + <> }> @@ -261,13 +338,30 @@ const Header = () => { showModal={showPublishCommunityTemplateModal} />
- + + + + + +
-
+ ); }; diff --git a/app/client/src/pages/Editor/IDE/Layout/AnimatedLayout.tsx b/app/client/src/pages/Editor/IDE/Layout/AnimatedLayout.tsx index d58e70910a3f..952b3542c3f8 100644 --- a/app/client/src/pages/Editor/IDE/Layout/AnimatedLayout.tsx +++ b/app/client/src/pages/Editor/IDE/Layout/AnimatedLayout.tsx @@ -2,6 +2,7 @@ import React from "react"; import { useGridLayoutTemplate } from "./hooks/useGridLayoutTemplate"; import EditorWrapperContainer from "pages/Editor/commons/EditorWrapperContainer"; import { AnimatedGridLayout, LayoutArea } from "components/AnimatedGridLayout"; +import { useSelector } from "react-redux"; import BottomBar from "components/BottomBar"; import Sidebar from "../Sidebar"; import LeftPane from "../LeftPane"; @@ -9,28 +10,10 @@ import MainPane from "../MainPane"; import RightPane from "../RightPane"; import { Areas } from "./constants"; import ProtectedCallout from "../ProtectedCallout"; -import { useGitModEnabled } from "pages/Editor/gitSync/hooks/modHooks"; -import { - GitProtectedBranchCallout as GitProtectedBranchCalloutNew, - useGitProtectedMode, -} from "git"; - -function GitProtectedBranchCallout() { - const isGitModEnabled = useGitModEnabled(); - const isProtectedMode = useGitProtectedMode(); - - if (isGitModEnabled) { - return ; - } - - if (isProtectedMode) { - return ; - } - - return null; -} +import { protectedModeSelector } from "selectors/gitSyncSelectors"; function AnimatedLayout() { + const isProtectedMode = useSelector(protectedModeSelector); const { areas, columns, rows } = useGridLayoutTemplate(); if (columns.length === 0) { @@ -39,7 +22,7 @@ function AnimatedLayout() { return ( <> - + {isProtectedMode && } ; - } - - if (isProtectedMode) { - return ; - } - - return null; -} const GridContainer = styled.div` display: grid; @@ -44,13 +26,14 @@ const LayoutContainer = styled.div<{ name: string }>` `; export const StaticLayout = React.memo(() => { + const isProtectedMode = useSelector(protectedModeSelector); const { areas, columns } = useGridLayoutTemplate(); const isSidebarVisible = columns[0] !== "0px"; return ( <> - + {isProtectedMode && } { const [windowWidth] = useWindowDimensions(); @@ -20,7 +20,7 @@ export const useEditorStateLeftPaneWidth = (): number => { const { segment } = useCurrentEditorState(); const propertyPaneWidth = useSelector(getPropertyPaneWidth); const isPreviewMode = useSelector(previewModeSelector); - const isProtectedMode = useGitProtectedMode(); + const isProtectedMode = useSelector(protectedModeSelector); useEffect( function updateWidth() { diff --git a/app/client/src/pages/Editor/IDE/Layout/hooks/useGridLayoutTemplate.ts b/app/client/src/pages/Editor/IDE/Layout/hooks/useGridLayoutTemplate.ts index bf97ce71790b..b2dc0558af59 100644 --- a/app/client/src/pages/Editor/IDE/Layout/hooks/useGridLayoutTemplate.ts +++ b/app/client/src/pages/Editor/IDE/Layout/hooks/useGridLayoutTemplate.ts @@ -7,6 +7,7 @@ import { useCurrentAppState } from "../../hooks/useCurrentAppState"; import { getPropertyPaneWidth } from "selectors/propertyPaneSelectors"; import { previewModeSelector } from "selectors/editorSelectors"; import { getIDEViewMode } from "selectors/ideSelectors"; +import { protectedModeSelector } from "selectors/gitSyncSelectors"; import { EditorEntityTab, EditorState, @@ -19,7 +20,6 @@ import { } from "constants/AppConstants"; import { useEditorStateLeftPaneWidth } from "./useEditorStateLeftPaneWidth"; import { type Area, Areas, SIDEBAR_WIDTH } from "../constants"; -import { useGitProtectedMode } from "pages/Editor/gitSync/hooks/modHooks"; interface ReturnValue { areas: Area[][]; @@ -43,7 +43,7 @@ function useGridLayoutTemplate(): ReturnValue { const appState = useCurrentAppState(); const isPreviewMode = useSelector(previewModeSelector); const editorMode = useSelector(getIDEViewMode); - const isProtectedMode = useGitProtectedMode(); + const isProtectedMode = useSelector(protectedModeSelector); React.useEffect( function updateIDEColumns() { diff --git a/app/client/src/pages/Editor/IDE/ProtectedCallout.test.tsx b/app/client/src/pages/Editor/IDE/ProtectedCallout.test.tsx index d735d5663d88..2a60c70f3f86 100644 --- a/app/client/src/pages/Editor/IDE/ProtectedCallout.test.tsx +++ b/app/client/src/pages/Editor/IDE/ProtectedCallout.test.tsx @@ -3,11 +3,11 @@ import { render } from "@testing-library/react"; import { merge } from "lodash"; import { Provider } from "react-redux"; import configureStore from "redux-mock-store"; +import IDE from "."; import { BrowserRouter } from "react-router-dom"; import "@testing-library/jest-dom"; import { ReduxActionTypes } from "ee/constants/ReduxActionConstants"; import store from "store"; -import ProtectedCallout from "./ProtectedCallout"; // TODO: Fix this the next time the file is edited // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -64,7 +64,7 @@ describe("Protected callout test cases", () => { const { getByTestId } = render( - + , ); @@ -72,6 +72,33 @@ describe("Protected callout test cases", () => { expect(getByTestId("t--git-protected-branch-callout")).toBeInTheDocument(); }); + it("should not render the protected view if branch is not protected", () => { + const store = getMockStore({ + ui: { + applications: { + currentApplication: { + gitApplicationMetadata: { + branchName: "branch-1", + }, + }, + }, + gitSync: { + protectedBranches: ["main"], + }, + }, + }); + const { queryByTestId } = render( + + + + + , + ); + + expect( + queryByTestId("t--git-protected-branch-callout"), + ).not.toBeInTheDocument(); + }); it("should unprotect only the current branch if clicked on unprotect cta", () => { const store = getMockStore({ ui: { @@ -90,7 +117,7 @@ describe("Protected callout test cases", () => { const { queryByTestId } = render( - + , ); diff --git a/app/client/src/pages/Editor/IDE/hooks.test.tsx b/app/client/src/pages/Editor/IDE/hooks.test.tsx index 9e5e40d6e98f..0a12538bf260 100644 --- a/app/client/src/pages/Editor/IDE/hooks.test.tsx +++ b/app/client/src/pages/Editor/IDE/hooks.test.tsx @@ -6,12 +6,6 @@ import { useGetPageFocusUrl } from "./hooks"; // eslint-disable-next-line @typescript-eslint/no-restricted-imports import { createEditorFocusInfo } from "../../../ce/navigation/FocusStrategy/AppIDEFocusStrategy"; -const mockUseGitCurrentBranch = jest.fn(() => null); - -jest.mock("../gitSync/hooks/modHooks", () => ({ - useGitCurrentBranch: () => mockUseGitCurrentBranch(), -})); - describe("useGetPageFocusUrl", () => { const pages = PageFactory.buildList(4); @@ -48,7 +42,6 @@ describe("useGetPageFocusUrl", () => { const wrapper = hookWrapper({ initialState: state }); it("works for JS focus history", () => { - mockUseGitCurrentBranch.mockReturnValue(null); const { result } = renderHook(() => useGetPageFocusUrl(pages[0].pageId), { wrapper, }); @@ -90,13 +83,10 @@ describe("useGetPageFocusUrl", () => { it("returns correct state when branches exist", () => { const branch = "featureBranch"; - - mockUseGitCurrentBranch.mockReturnValue(branch); const page1FocusHistoryWithBranch = createEditorFocusInfo( pages[0].pageId, branch, ); - const state = getIDETestState({ pages, focusHistory: { diff --git a/app/client/src/pages/Editor/IDE/hooks.ts b/app/client/src/pages/Editor/IDE/hooks.ts index 6d356af8626b..178a02e94222 100644 --- a/app/client/src/pages/Editor/IDE/hooks.ts +++ b/app/client/src/pages/Editor/IDE/hooks.ts @@ -15,6 +15,7 @@ import { widgetListURL, } from "ee/RouteBuilder"; import { getCurrentFocusInfo } from "selectors/focusHistorySelectors"; +import { getCurrentGitBranch } from "selectors/gitSyncSelectors"; import { getIsAltFocusWidget, getWidgetSelectionBlock } from "selectors/ui"; import { altFocusWidget, setWidgetSelectionBlock } from "actions/widgetActions"; import { useJSAdd } from "ee/pages/Editor/IDE/EditorPane/JS/hooks"; @@ -26,7 +27,6 @@ import { closeJSActionTab } from "actions/jsActionActions"; import { closeQueryActionTab } from "actions/pluginActionActions"; import { getCurrentBasePageId } from "selectors/editorSelectors"; import { getCurrentEntityInfo } from "../utils"; -import { useGitCurrentBranch } from "../gitSync/hooks/modHooks"; import { useEditorType } from "ee/hooks"; import { useParentEntityInfo } from "ee/hooks/datasourceEditorHooks"; import { useBoolean } from "usehooks-ts"; @@ -102,8 +102,7 @@ export const useSegmentNavigation = (): { export const useGetPageFocusUrl = (basePageId: string): string => { const [focusPageUrl, setFocusPageUrl] = useState(builderURL({ basePageId })); - const branch = useGitCurrentBranch(); - + const branch = useSelector(getCurrentGitBranch); const editorStateFocusInfo = useSelector((appState) => getCurrentFocusInfo(appState, createEditorFocusInfoKey(basePageId, branch)), ); diff --git a/app/client/src/pages/Editor/WidgetsEditor/components/LayoutSystemBasedPageViewer.tsx b/app/client/src/pages/Editor/WidgetsEditor/components/LayoutSystemBasedPageViewer.tsx index 935e67cd90f0..a430ed2fd02e 100644 --- a/app/client/src/pages/Editor/WidgetsEditor/components/LayoutSystemBasedPageViewer.tsx +++ b/app/client/src/pages/Editor/WidgetsEditor/components/LayoutSystemBasedPageViewer.tsx @@ -8,9 +8,9 @@ import { getCurrentPageId, previewModeSelector, } from "selectors/editorSelectors"; +import { protectedModeSelector } from "selectors/gitSyncSelectors"; import { getAppSettingsPaneContext } from "selectors/appSettingsPaneSelectors"; import { useShowSnapShotBanner } from "pages/Editor/CanvasLayoutConversion/hooks/useShowSnapShotBanner"; -import { useGitProtectedMode } from "pages/Editor/gitSync/hooks/modHooks"; /** * LayoutSystemBasedPageViewer @@ -25,7 +25,7 @@ export const LayoutSystemBasedPageViewer = ({ }) => { const currentPageId = useSelector(getCurrentPageId); const isPreviewMode = useSelector(previewModeSelector); - const isProtectedMode = useGitProtectedMode(); + const isProtectedMode = useSelector(protectedModeSelector); const appSettingsPaneContext = useSelector(getAppSettingsPaneContext); const canvasWidth = useSelector(getCanvasWidth); const shouldShowSnapShotBanner = useShowSnapShotBanner( diff --git a/app/client/src/pages/Editor/WidgetsEditor/components/NavigationAdjustedPageViewer.tsx b/app/client/src/pages/Editor/WidgetsEditor/components/NavigationAdjustedPageViewer.tsx index 6eb0f1ff10a6..7ec7cdd62ec4 100644 --- a/app/client/src/pages/Editor/WidgetsEditor/components/NavigationAdjustedPageViewer.tsx +++ b/app/client/src/pages/Editor/WidgetsEditor/components/NavigationAdjustedPageViewer.tsx @@ -4,7 +4,7 @@ import { EditorState } from "ee/entities/IDE/constants"; import { useCurrentAppState } from "pages/Editor/IDE/hooks/useCurrentAppState"; import { getIsAppSettingsPaneWithNavigationTabOpen } from "selectors/appSettingsPaneSelectors"; import { useSelector } from "react-redux"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { PageViewWrapper } from "pages/AppViewer/AppPage"; import classNames from "classnames"; import { APP_MODE } from "entities/App"; @@ -27,7 +27,7 @@ import { getIsAnvilLayout } from "layoutSystems/anvil/integrations/selectors"; export const NavigationAdjustedPageViewer = (props: { children: ReactNode; }) => { - const isPreview = useSelector(selectCombinedPreviewMode); + const isPreview = useSelector(combinedPreviewModeSelector); const currentApplicationDetails = useSelector(getCurrentApplication); const isAppSidebarPinned = useSelector(getAppSidebarPinned); const sidebarWidth = useSelector(getSidebarWidth); diff --git a/app/client/src/pages/Editor/WidgetsEditor/components/NavigationPreview.tsx b/app/client/src/pages/Editor/WidgetsEditor/components/NavigationPreview.tsx index 8f2aa0e23c24..0478d6f63439 100644 --- a/app/client/src/pages/Editor/WidgetsEditor/components/NavigationPreview.tsx +++ b/app/client/src/pages/Editor/WidgetsEditor/components/NavigationPreview.tsx @@ -2,7 +2,7 @@ import type { LegacyRef } from "react"; import React, { forwardRef } from "react"; import classNames from "classnames"; import { useSelector } from "react-redux"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { Navigation } from "pages/AppViewer/Navigation"; import { useCurrentAppState } from "pages/Editor/IDE/hooks/useCurrentAppState"; import { EditorState } from "ee/entities/IDE/constants"; @@ -22,7 +22,7 @@ const NavigationPreview = forwardRef( const appState = useCurrentAppState(); const isAppSettingsPaneWithNavigationTabOpen = appState === EditorState.SETTINGS && isNavigationSelectedInSettings; - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); return (
{ const allowDragToSelect = useAllowEditorDragToSelect(); const { isAutoHeightWithLimitsChanging } = useAutoHeightUIState(); const dispatch = useDispatch(); - const isCombinedPreviewMode = useSelector(selectCombinedPreviewMode); + const isCombinedPreviewMode = useSelector(combinedPreviewModeSelector); const handleWrapperClick = useCallback( (e) => { diff --git a/app/client/src/pages/Editor/WidgetsEditor/components/WidgetEditorNavigation.tsx b/app/client/src/pages/Editor/WidgetsEditor/components/WidgetEditorNavigation.tsx index d7b7d2869271..852c210685ee 100644 --- a/app/client/src/pages/Editor/WidgetsEditor/components/WidgetEditorNavigation.tsx +++ b/app/client/src/pages/Editor/WidgetsEditor/components/WidgetEditorNavigation.tsx @@ -7,7 +7,7 @@ import { getIsAppSettingsPaneWithNavigationTabOpen, } from "selectors/appSettingsPaneSelectors"; import { useSelector } from "react-redux"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { getCurrentApplication } from "ee/selectors/applicationSelectors"; /** @@ -20,7 +20,7 @@ import { getCurrentApplication } from "ee/selectors/applicationSelectors"; export const useNavigationPreviewHeight = () => { const [navigationHeight, setNavigationHeight] = useState(0); const navigationPreviewRef = useRef(null); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const appSettingsPaneContext = useSelector(getAppSettingsPaneContext); const currentApplicationDetails = useSelector(getCurrentApplication); @@ -54,7 +54,7 @@ type DivRef = React.Ref; */ export const WidgetEditorNavigation = forwardRef( (props, navigationPreviewRef: DivRef) => { - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isNavigationSelectedInSettings = useSelector( getIsAppSettingsPaneWithNavigationTabOpen, ); diff --git a/app/client/src/pages/Editor/commons/EditorWrapperContainer.tsx b/app/client/src/pages/Editor/commons/EditorWrapperContainer.tsx index 3b34d1beecd4..990004cbbec5 100644 --- a/app/client/src/pages/Editor/commons/EditorWrapperContainer.tsx +++ b/app/client/src/pages/Editor/commons/EditorWrapperContainer.tsx @@ -2,11 +2,11 @@ import React from "react"; import styled from "styled-components"; import classNames from "classnames"; import { useSelector } from "react-redux"; +import { combinedPreviewModeSelector } from "../../../selectors/editorSelectors"; +import { protectedModeSelector } from "selectors/gitSyncSelectors"; import { IDE_HEADER_HEIGHT } from "@appsmith/ads"; import { BOTTOM_BAR_HEIGHT } from "../../../components/BottomBar/constants"; import { PROTECTED_CALLOUT_HEIGHT } from "../IDE/ProtectedCallout"; -import { useGitProtectedMode } from "../gitSync/hooks/modHooks"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; interface EditorWrapperContainerProps { children: React.ReactNode; @@ -25,8 +25,8 @@ const Wrapper = styled.div<{ `; function EditorWrapperContainer({ children }: EditorWrapperContainerProps) { - const isCombinedPreviewMode = useSelector(selectCombinedPreviewMode); - const isProtectedMode = useGitProtectedMode(); + const isCombinedPreviewMode = useSelector(combinedPreviewModeSelector); + const isProtectedMode = useSelector(protectedModeSelector); return (
{props.showSuccess ? ( diff --git a/app/client/src/pages/Editor/gitSync/hooks/modHooks.ts b/app/client/src/pages/Editor/gitSync/hooks/modHooks.ts deleted file mode 100644 index e4d4b7fb4b7a..000000000000 --- a/app/client/src/pages/Editor/gitSync/hooks/modHooks.ts +++ /dev/null @@ -1,44 +0,0 @@ -// temp file will be removed after git mod is fully rolled out - -import { useSelector } from "react-redux"; -import { - getCurrentGitBranch, - getIsGitConnected, - protectedModeSelector, -} from "selectors/gitSyncSelectors"; -import { - useGitProtectedMode as useGitProtectedModeNew, - useGitCurrentBranch as useGitCurrentBranchNew, - useGitConnected as useGitConnectedNew, -} from "git"; -import { selectGitModEnabled } from "selectors/gitModSelectors"; - -export function useGitModEnabled() { - const isGitModEnabled = useSelector(selectGitModEnabled); - - return isGitModEnabled; -} - -export function useGitCurrentBranch() { - const isGitModEnabled = useGitModEnabled(); - const currentBranchOld = useSelector(getCurrentGitBranch) ?? null; - const currentBranchNew = useGitCurrentBranchNew(); - - return isGitModEnabled ? currentBranchNew : currentBranchOld; -} - -export function useGitProtectedMode() { - const isGitModEnabled = useGitModEnabled(); - const isProtectedModeOld = useSelector(protectedModeSelector); - const isProtectedModeNew = useGitProtectedModeNew(); - - return isGitModEnabled ? isProtectedModeNew : isProtectedModeOld; -} - -export function useGitConnected() { - const isGitModEnabled = useGitModEnabled(); - const isGitConnectedOld = useSelector(getIsGitConnected); - const isGitConnectedNew = useGitConnectedNew(); - - return isGitModEnabled ? isGitConnectedNew : isGitConnectedOld; -} diff --git a/app/client/src/pages/Editor/index.tsx b/app/client/src/pages/Editor/index.tsx index 746b7ca56733..a7bfff34f2cb 100644 --- a/app/client/src/pages/Editor/index.tsx +++ b/app/client/src/pages/Editor/index.tsx @@ -25,9 +25,12 @@ import { getTheme, ThemeMode } from "selectors/themeSelectors"; import { ThemeProvider } from "styled-components"; import type { Theme } from "constants/DefaultTheme"; import GlobalHotKeys from "./GlobalHotKeys"; +import GitSyncModal from "pages/Editor/gitSync/GitSyncModal"; +import DisconnectGitModal from "pages/Editor/gitSync/DisconnectGitModal"; import { setupPageAction, updateCurrentPage } from "actions/pageActions"; import { getCurrentPageId } from "selectors/editorSelectors"; import { getSearchQuery } from "utils/helpers"; +import RepoLimitExceededErrorModal from "./gitSync/RepoLimitExceededErrorModal"; import ImportedApplicationSuccessModal from "./gitSync/ImportSuccessModal"; import { getIsBranchUpdated } from "../utils"; import { APP_MODE } from "entities/App"; @@ -39,40 +42,16 @@ import SignpostingOverlay from "pages/Editor/FirstTimeUserOnboarding/Overlay"; import { editorInitializer } from "../../utils/editor/EditorUtils"; import { widgetInitialisationSuccess } from "../../actions/widgetActions"; import urlBuilder from "ee/entities/URLRedirect/URLAssembly"; +import DisableAutocommitModal from "./gitSync/DisableAutocommitModal"; +import GitSettingsModal from "./gitSync/GitSettingsModal"; +import ReconfigureCDKeyModal from "ee/components/gitComponents/ReconfigureCDKeyModal"; +import DisableCDModal from "ee/components/gitComponents/DisableCDModal"; import { PartialExportModal } from "components/editorComponents/PartialImportExport/PartialExportModal"; import { PartialImportModal } from "components/editorComponents/PartialImportExport/PartialImportModal"; import type { Page } from "entities/Page"; import { AppCURLImportModal } from "ee/pages/Editor/CurlImport"; import { IDE_HEADER_HEIGHT } from "@appsmith/ads"; import GeneratePageModal from "./GeneratePage"; -import { GitModals as NewGitModals } from "git"; -import GitSyncModal from "./gitSync/GitSyncModal"; -import GitSettingsModal from "./gitSync/GitSettingsModal"; -import DisconnectGitModal from "./gitSync/DisconnectGitModal"; -import DisableAutocommitModal from "./gitSync/DisableAutocommitModal"; -import ReconfigureCDKeyModal from "ee/components/gitComponents/ReconfigureCDKeyModal"; -import DisableCDModal from "ee/components/gitComponents/DisableCDModal"; -import RepoLimitExceededErrorModal from "./gitSync/RepoLimitExceededErrorModal"; -import { useGitModEnabled } from "./gitSync/hooks/modHooks"; -import GitApplicationContextProvider from "components/gitContexts/GitApplicationContextProvider"; - -function GitModals() { - const isGitModEnabled = useGitModEnabled(); - - return isGitModEnabled ? ( - - ) : ( - <> - - - - - - - - - ); -} interface EditorProps { currentApplicationId?: string; @@ -216,20 +195,24 @@ class Editor extends Component { {`${this.props.currentApplicationName} | Editor | Appsmith`} - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + +
diff --git a/app/client/src/pages/UserProfile/index.tsx b/app/client/src/pages/UserProfile/index.tsx index f77d74fedb50..a715171bc31d 100644 --- a/app/client/src/pages/UserProfile/index.tsx +++ b/app/client/src/pages/UserProfile/index.tsx @@ -3,23 +3,12 @@ import PageWrapper from "pages/common/PageWrapper"; import styled from "styled-components"; import { Tabs, Tab, TabsList, TabPanel } from "@appsmith/ads"; import General from "./General"; -import OldGitConfig from "./GitConfig"; +import GitConfig from "./GitConfig"; import { useLocation } from "react-router"; import { GIT_PROFILE_ROUTE } from "constants/routes"; import { BackButton } from "components/utils/helperComponents"; import { useDispatch } from "react-redux"; import { fetchGlobalGitConfigInit } from "actions/gitSyncActions"; -import { useGitModEnabled } from "pages/Editor/gitSync/hooks/modHooks"; -import { - fetchGitGlobalProfile, - GitGlobalProfile as GitGlobalProfileNew, -} from "git"; - -function GitGlobalProfile() { - const isGitModEnabled = useGitModEnabled(); - - return isGitModEnabled ? : ; -} const ProfileWrapper = styled.div` width: 978px; @@ -36,7 +25,6 @@ const ProfileWrapper = styled.div` function UserProfile() { const location = useLocation(); const dispatch = useDispatch(); - const isGitModEnabled = useGitModEnabled(); let initialTab = "general"; const tabs = [ @@ -51,7 +39,7 @@ function UserProfile() { tabs.push({ key: "gitConfig", title: "Git user config", - panelComponent: , + panelComponent: , icon: "git-branch", }); @@ -61,16 +49,10 @@ function UserProfile() { const [selectedTab, setSelectedTab] = useState(initialTab); - useEffect( - function fetchGlobalGitConfigOnInitEffect() { - if (isGitModEnabled) { - dispatch(fetchGitGlobalProfile()); - } else { - dispatch(fetchGlobalGitConfigInit()); - } - }, - [dispatch, isGitModEnabled], - ); + useEffect(() => { + // onMount Fetch Global config + dispatch(fetchGlobalGitConfigInit()); + }, []); return ( diff --git a/app/client/src/pages/common/ImportModal.tsx b/app/client/src/pages/common/ImportModal.tsx index 12cefc5dec8c..b19974788529 100644 --- a/app/client/src/pages/common/ImportModal.tsx +++ b/app/client/src/pages/common/ImportModal.tsx @@ -30,8 +30,6 @@ import { import useMessages from "ee/hooks/importModal/useMessages"; import useMethods from "ee/hooks/importModal/useMethods"; import { getIsAnvilLayoutEnabled } from "layoutSystems/anvil/integrations/selectors"; -import { useGitModEnabled } from "pages/Editor/gitSync/hooks/modHooks"; -import { toggleGitImportModal } from "git"; const TextWrapper = styled.div` padding: 0; @@ -205,7 +203,6 @@ function ImportModal(props: ImportModalProps) { toEditor = false, workspaceId, } = props; - const isGitModEnabled = useGitModEnabled(); const { mainDescription, title } = useMessages(); const { appFileToBeUploaded, @@ -226,21 +223,15 @@ function ImportModal(props: ImportModalProps) { setWorkspaceIdForImport({ editorId: editorId || "", workspaceId }), ); - if (isGitModEnabled) { - dispatch( - toggleGitImportModal({ - open: true, - }), - ); - } else { - dispatch( - setIsGitSyncModalOpen({ - isOpen: true, - tab: GitSyncModalTab.GIT_CONNECTION, - }), - ); - } - }, [dispatch, editorId, isGitModEnabled, onClose, workspaceId]); + dispatch( + setIsGitSyncModalOpen({ + isOpen: true, + tab: GitSyncModalTab.GIT_CONNECTION, + }), + ); + + // dispatch(setIsReconnectingDatasourcesModalOpen({ isOpen: true })); + }, []); useEffect(() => { // finished of importing application diff --git a/app/client/src/sagas/ActionExecution/StoreActionSaga.ts b/app/client/src/sagas/ActionExecution/StoreActionSaga.ts index ee6d99630ffd..4bcd909aabf0 100644 --- a/app/client/src/sagas/ActionExecution/StoreActionSaga.ts +++ b/app/client/src/sagas/ActionExecution/StoreActionSaga.ts @@ -4,6 +4,7 @@ import localStorage from "utils/localStorage"; import { updateAppStore } from "actions/pageActions"; import AppsmithConsole from "utils/AppsmithConsole"; import { getAppStoreData } from "ee/selectors/entitiesSelector"; +import { getCurrentGitBranch } from "selectors/gitSyncSelectors"; import { getCurrentApplicationId } from "selectors/editorSelectors"; import type { AppStoreState } from "reducers/entityReducers/appReducer"; import { Severity, LOG_CATEGORY } from "entities/AppsmithConsole"; @@ -12,7 +13,6 @@ import type { TRemoveValueDescription, TStoreValueDescription, } from "workers/Evaluation/fns/storeFns"; -import { selectGitApplicationCurrentBranch } from "selectors/gitModSelectors"; type StoreOperation = | TStoreValueDescription @@ -21,9 +21,7 @@ type StoreOperation = export function* handleStoreOperations(triggers: StoreOperation[]) { const applicationId: string = yield select(getCurrentApplicationId); - const branch: string | undefined = yield select( - selectGitApplicationCurrentBranch, - ); + const branch: string | undefined = yield select(getCurrentGitBranch); const appStoreName = getAppStoreName(applicationId, branch); const existingLocalStore = localStorage.getItem(appStoreName) || "{}"; let parsedLocalStore = JSON.parse(existingLocalStore); diff --git a/app/client/src/sagas/DatasourcesSagas.ts b/app/client/src/sagas/DatasourcesSagas.ts index 841be4eae950..189fe5b80bc4 100644 --- a/app/client/src/sagas/DatasourcesSagas.ts +++ b/app/client/src/sagas/DatasourcesSagas.ts @@ -714,7 +714,6 @@ function* redirectAuthorizationCodeSaga( const { contextId, contextType, datasourceId, pluginType } = actionPayload.payload; const isImport: string = yield select(getWorkspaceIdForImport); - // ! git mod - not sure how to handle this, there is no definition for the artifact used here const branchName: string | undefined = yield select(getCurrentGitBranch); if (pluginType === PluginType.API) { diff --git a/app/client/src/sagas/FocusRetentionSaga.ts b/app/client/src/sagas/FocusRetentionSaga.ts index e92be7bae11b..45232d9560dc 100644 --- a/app/client/src/sagas/FocusRetentionSaga.ts +++ b/app/client/src/sagas/FocusRetentionSaga.ts @@ -18,10 +18,10 @@ import type { AppsmithLocationState } from "utils/history"; import type { Action } from "entities/Action"; import { getAction, getPlugin } from "ee/selectors/entitiesSelector"; import type { Plugin } from "api/PluginApi"; +import { getCurrentGitBranch } from "selectors/gitSyncSelectors"; import { getIDETypeByUrl } from "ee/entities/IDE/utils"; import { getIDEFocusStrategy } from "ee/navigation/FocusStrategy"; import { IDE_TYPE } from "ee/entities/IDE/constants"; -import { selectGitApplicationCurrentBranch } from "selectors/gitModSelectors"; export interface FocusPath { key: string; @@ -123,9 +123,7 @@ class FocusRetention { } public *handleRemoveFocusHistory(url: string) { - const branch: string | undefined = yield select( - selectGitApplicationCurrentBranch, - ); + const branch: string | undefined = yield select(getCurrentGitBranch); const removeKeys: string[] = []; const focusEntityInfo = identifyEntityFromPath(url); diff --git a/app/client/src/sagas/GlobalSearchSagas.ts b/app/client/src/sagas/GlobalSearchSagas.ts index 93e29c0b29dc..17cf81e719b3 100644 --- a/app/client/src/sagas/GlobalSearchSagas.ts +++ b/app/client/src/sagas/GlobalSearchSagas.ts @@ -21,20 +21,18 @@ import { } from "selectors/editorSelectors"; import type { RecentEntity } from "components/editorComponents/GlobalSearch/utils"; import log from "loglevel"; +import { getCurrentGitBranch } from "selectors/gitSyncSelectors"; import type { FocusEntity, FocusEntityInfo } from "navigation/FocusEntity"; import { convertToPageIdSelector } from "selectors/pageListSelectors"; -import { selectGitApplicationCurrentBranch } from "selectors/gitModSelectors"; const getRecentEntitiesKey = (applicationId: string, branch?: string) => branch ? `${applicationId}-${branch}` : applicationId; export function* updateRecentEntitySaga(entityInfo: FocusEntityInfo) { try { - const applicationId: string = yield select(getCurrentApplicationId); + const branch: string | undefined = yield select(getCurrentGitBranch); - const branch: string | undefined = yield select( - selectGitApplicationCurrentBranch, - ); + const applicationId: string = yield select(getCurrentApplicationId); const recentEntitiesRestored: boolean = yield select( (state: AppState) => state.ui.globalSearch.recentEntitiesRestored, diff --git a/app/client/src/sagas/autoHeightSagas/helpers.ts b/app/client/src/sagas/autoHeightSagas/helpers.ts index 3ac3086a9d53..da276f65d769 100644 --- a/app/client/src/sagas/autoHeightSagas/helpers.ts +++ b/app/client/src/sagas/autoHeightSagas/helpers.ts @@ -11,7 +11,7 @@ import type { } from "reducers/entityReducers/canvasWidgetsReducer"; import { select } from "redux-saga/effects"; import { getWidgetMetaProps, getWidgets } from "sagas/selectors"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { getAppMode } from "ee/selectors/entitiesSelector"; import { isAutoHeightEnabledForWidget } from "widgets/WidgetUtils"; import { getCanvasHeightOffset } from "utils/WidgetSizeUtils"; @@ -20,7 +20,7 @@ import type { DataTree } from "entities/DataTree/dataTreeTypes"; import { getDataTree } from "selectors/dataTreeSelectors"; export function* shouldWidgetsCollapse() { - const isPreviewMode: boolean = yield select(selectCombinedPreviewMode); + const isPreviewMode: boolean = yield select(combinedPreviewModeSelector); const appMode: APP_MODE = yield select(getAppMode); return isPreviewMode || appMode === APP_MODE.PUBLISHED; diff --git a/app/client/src/selectors/debuggerSelectors.tsx b/app/client/src/selectors/debuggerSelectors.tsx index 624fae4f290f..89c2c46df479 100644 --- a/app/client/src/selectors/debuggerSelectors.tsx +++ b/app/client/src/selectors/debuggerSelectors.tsx @@ -11,8 +11,8 @@ import { isWidget, } from "ee/workers/Evaluation/evaluationUtils"; import { getDataTree } from "./dataTreeSelectors"; +import { combinedPreviewModeSelector } from "./editorSelectors"; import type { CanvasDebuggerState } from "reducers/uiReducers/debuggerReducer"; -import { selectCombinedPreviewMode } from "./gitModSelectors"; interface ErrorObejct { [k: string]: Log; @@ -169,7 +169,7 @@ export const getDebuggerOpen = (state: AppState) => state.ui.debugger.isOpen; export const showDebuggerFlag = createSelector( getDebuggerOpen, - selectCombinedPreviewMode, + combinedPreviewModeSelector, (isOpen, isPreview) => isOpen && !isPreview, ); diff --git a/app/client/src/selectors/editorSelectors.tsx b/app/client/src/selectors/editorSelectors.tsx index 39bd1d46c1b6..ee3560dd5034 100644 --- a/app/client/src/selectors/editorSelectors.tsx +++ b/app/client/src/selectors/editorSelectors.tsx @@ -990,3 +990,9 @@ export const getGsheetToken = (state: AppState) => export const getGsheetProjectID = (state: AppState) => state.entities.datasources.gsheetProjectID; + +export const combinedPreviewModeSelector = createSelector( + previewModeSelector, + protectedModeSelector, + (isPreviewMode, isProtectedMode) => isPreviewMode || isProtectedMode, +); diff --git a/app/client/src/selectors/gitModSelectors.ts b/app/client/src/selectors/gitModSelectors.ts deleted file mode 100644 index 35fe32fbbff7..000000000000 --- a/app/client/src/selectors/gitModSelectors.ts +++ /dev/null @@ -1,50 +0,0 @@ -// temp file will be removed after git mod is fully rolled out - -import { selectFeatureFlags } from "ee/selectors/featureFlagsSelectors"; -import { createSelector } from "reselect"; -import { getCurrentGitBranch, protectedModeSelector } from "./gitSyncSelectors"; -import { - selectGitCurrentBranch as selectGitCurrentBranchNew, - selectGitProtectedMode as selectGitProtectedModeNew, -} from "git"; -import { - getCurrentBaseApplicationId, - previewModeSelector, -} from "./editorSelectors"; -import { applicationArtifact } from "git/artifact-helpers/application"; - -export const selectGitModEnabled = createSelector( - selectFeatureFlags, - (featureFlags) => featureFlags.release_git_modularisation_enabled ?? false, -); - -export const selectGitApplicationArtifactDef = createSelector( - getCurrentBaseApplicationId, - (baseApplicationId) => applicationArtifact(baseApplicationId), -); - -export const selectGitApplicationCurrentBranch = createSelector( - selectGitModEnabled, - getCurrentGitBranch, - (state) => - selectGitCurrentBranchNew(state, selectGitApplicationArtifactDef(state)), - (isGitModEnabled, currentBranchOld, currentBranchNew) => { - return isGitModEnabled ? currentBranchNew : currentBranchOld; - }, -); - -export const selectGitApplicationProtectedMode = createSelector( - selectGitModEnabled, - protectedModeSelector, - (state) => - selectGitProtectedModeNew(state, selectGitApplicationArtifactDef(state)), - (isGitModEnabled, protectedModeOld, protectedModeNew) => { - return isGitModEnabled ? protectedModeNew : protectedModeOld; - }, -); - -export const selectCombinedPreviewMode = createSelector( - previewModeSelector, - selectGitApplicationProtectedMode, - (isPreviewMode, isProtectedMode) => isPreviewMode || isProtectedMode, -); diff --git a/app/client/src/selectors/widgetDragSelectors.ts b/app/client/src/selectors/widgetDragSelectors.ts index 21d5848d5175..0a2b35eb7e1f 100644 --- a/app/client/src/selectors/widgetDragSelectors.ts +++ b/app/client/src/selectors/widgetDragSelectors.ts @@ -1,9 +1,11 @@ import type { AppState } from "ee/reducers"; import { createSelector } from "reselect"; import { getIsAppSettingsPaneWithNavigationTabOpen } from "./appSettingsPaneSelectors"; -import { snipingModeSelector } from "./editorSelectors"; +import { + combinedPreviewModeSelector, + snipingModeSelector, +} from "./editorSelectors"; import { getWidgetSelectionBlock } from "./ui"; -import { selectCombinedPreviewMode } from "./gitModSelectors"; export const getIsDragging = (state: AppState) => state.ui.widgetDragResize.isDragging; @@ -21,7 +23,7 @@ export const getShouldAllowDrag = createSelector( getIsResizing, getIsDragging, getIsDraggingDisabledInEditor, - selectCombinedPreviewMode, + combinedPreviewModeSelector, snipingModeSelector, getIsAppSettingsPaneWithNavigationTabOpen, getWidgetSelectionBlock, diff --git a/app/client/src/selectors/widgetSelectors.ts b/app/client/src/selectors/widgetSelectors.ts index 35d648da50bf..4d45777ef4c9 100644 --- a/app/client/src/selectors/widgetSelectors.ts +++ b/app/client/src/selectors/widgetSelectors.ts @@ -21,8 +21,8 @@ import { APP_MODE } from "entities/App"; import { getIsTableFilterPaneVisible } from "selectors/tableFilterSelectors"; import { getIsAutoHeightWithLimitsChanging } from "utils/hooks/autoHeightUIHooks"; import { getIsPropertyPaneVisible } from "./propertyPaneSelectors"; +import { combinedPreviewModeSelector } from "./editorSelectors"; import { getIsAnvilLayout } from "layoutSystems/anvil/integrations/selectors"; -import { selectCombinedPreviewMode } from "./gitModSelectors"; export const getIsDraggingOrResizing = (state: AppState) => state.ui.widgetDragResize.isResizing || state.ui.widgetDragResize.isDragging; @@ -186,7 +186,7 @@ export const shouldWidgetIgnoreClicksSelector = (widgetId: string) => { (state: AppState) => state.ui.widgetDragResize.isDragging, (state: AppState) => state.ui.canvasSelection.isDraggingForSelection, getAppMode, - selectCombinedPreviewMode, + combinedPreviewModeSelector, getIsAutoHeightWithLimitsChanging, getAltBlockWidgetSelection, ( diff --git a/app/client/src/utils/hooks/useAllowEditorDragToSelect.ts b/app/client/src/utils/hooks/useAllowEditorDragToSelect.ts index a09f5492d648..e074a099ac70 100644 --- a/app/client/src/utils/hooks/useAllowEditorDragToSelect.ts +++ b/app/client/src/utils/hooks/useAllowEditorDragToSelect.ts @@ -1,11 +1,13 @@ import type { AppState } from "ee/reducers"; -import { snipingModeSelector } from "selectors/editorSelectors"; +import { + snipingModeSelector, + combinedPreviewModeSelector, +} from "selectors/editorSelectors"; import { useSelector } from "react-redux"; import { getIsAppSettingsPaneWithNavigationTabOpen } from "selectors/appSettingsPaneSelectors"; import { getLayoutSystemType } from "selectors/layoutSystemSelectors"; import { LayoutSystemTypes } from "layoutSystems/types"; import { getWidgetSelectionBlock } from "../../selectors/ui"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; export const useAllowEditorDragToSelect = () => { // This state tells us whether a `ResizableComponent` is resizing @@ -40,7 +42,7 @@ export const useAllowEditorDragToSelect = () => { // True when any widget is dragging or resizing, including this one const isResizingOrDragging = !!isResizing || !!isDragging || !!isSelecting; const isSnipingMode = useSelector(snipingModeSelector); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const isAppSettingsPaneWithNavigationTabOpen = useSelector( getIsAppSettingsPaneWithNavigationTabOpen, ); diff --git a/app/client/src/utils/hooks/useHoverToFocusWidget.ts b/app/client/src/utils/hooks/useHoverToFocusWidget.ts index a6cf7962de9a..10e5f764f06e 100644 --- a/app/client/src/utils/hooks/useHoverToFocusWidget.ts +++ b/app/client/src/utils/hooks/useHoverToFocusWidget.ts @@ -2,7 +2,7 @@ import { useWidgetSelection } from "./useWidgetSelection"; import { useSelector } from "react-redux"; import { isWidgetFocused } from "selectors/widgetSelectors"; import { getAnvilSpaceDistributionStatus } from "layoutSystems/anvil/integrations/selectors"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import type { AppState } from "ee/reducers"; import type React from "react"; import { useCurrentAppState } from "pages/Editor/IDE/hooks/useCurrentAppState"; @@ -35,7 +35,7 @@ export const useHoverToFocusWidget = ( const isResizingOrDragging = isResizing || isDragging; // This state tells us whether space redistribution is in process const isDistributingSpace = useSelector(getAnvilSpaceDistributionStatus); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); // When mouse is over this draggable const handleMouseOver = (e: React.MouseEvent) => { focusWidget && diff --git a/app/client/src/widgets/ChartWidget/component/index.test.tsx b/app/client/src/widgets/ChartWidget/component/index.test.tsx index ee53792993a8..8c043acb36a3 100644 --- a/app/client/src/widgets/ChartWidget/component/index.test.tsx +++ b/app/client/src/widgets/ChartWidget/component/index.test.tsx @@ -22,11 +22,6 @@ import { APP_MODE } from "entities/App"; // eslint-disable-next-line @typescript-eslint/no-explicit-any let container: any; -jest.mock("selectors/gitModSelectors", () => ({ - ...jest.requireActual("selectors/gitModSelectors"), - selectCombinedPreviewMode: jest.fn(() => false), -})); - describe("Chart Widget", () => { const seriesData1: ChartData = { seriesName: "series1", diff --git a/app/client/src/widgets/ChartWidget/component/index.tsx b/app/client/src/widgets/ChartWidget/component/index.tsx index f2a3280bd7a1..4ed693b142c3 100644 --- a/app/client/src/widgets/ChartWidget/component/index.tsx +++ b/app/client/src/widgets/ChartWidget/component/index.tsx @@ -28,7 +28,7 @@ import { CustomEChartIFrameComponent } from "./CustomEChartIFrameComponent"; import type { AppState } from "ee/reducers"; import { connect } from "react-redux"; import { getWidgetPropsForPropertyPane } from "selectors/propertyPaneSelectors"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { getAppMode } from "ee/selectors/applicationSelectors"; import { APP_MODE } from "entities/App"; // Leaving this require here. Ref: https://stackoverflow.com/questions/41292559/could-not-find-a-declaration-file-for-module-module-name-path-to-module-nam/42505940#42505940 @@ -406,7 +406,7 @@ export const mapStateToProps = ( state: AppState, ownProps: ChartComponentProps, ) => { - const isPreviewMode = selectCombinedPreviewMode(state); + const isPreviewMode = combinedPreviewModeSelector(state); const appMode = getAppMode(state); return { diff --git a/app/client/src/widgets/CustomWidget/component/index.tsx b/app/client/src/widgets/CustomWidget/component/index.tsx index a3cf98d4afbb..eb6740b48cd0 100644 --- a/app/client/src/widgets/CustomWidget/component/index.tsx +++ b/app/client/src/widgets/CustomWidget/component/index.tsx @@ -19,7 +19,7 @@ import type { BoxShadow } from "components/designSystems/appsmith/WidgetStyleCon import type { Color } from "constants/Colors"; import { connect } from "react-redux"; import type { AppState } from "ee/reducers"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; import { getWidgetPropsForPropertyPane } from "selectors/propertyPaneSelectors"; import AnalyticsUtil from "ee/utils/AnalyticsUtil"; import { EVENTS } from "./customWidgetscript"; @@ -311,7 +311,7 @@ export const mapStateToProps = ( state: AppState, ownProps: CustomComponentProps, ) => { - const isPreviewMode = selectCombinedPreviewMode(state); + const isPreviewMode = combinedPreviewModeSelector(state); return { needsOverlay: diff --git a/app/client/src/widgets/IframeWidget/component/index.tsx b/app/client/src/widgets/IframeWidget/component/index.tsx index b16f5bdb2fcb..1958ebd55e36 100644 --- a/app/client/src/widgets/IframeWidget/component/index.tsx +++ b/app/client/src/widgets/IframeWidget/component/index.tsx @@ -9,7 +9,7 @@ import { getAppMode } from "ee/selectors/applicationSelectors"; import { APP_MODE } from "entities/App"; import type { RenderMode } from "constants/WidgetConstants"; import { getAppsmithConfigs } from "ee/configs"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; +import { combinedPreviewModeSelector } from "selectors/editorSelectors"; interface IframeContainerProps { borderColor?: string; @@ -145,7 +145,7 @@ function IframeComponent(props: IframeComponentProps) { }, [srcDoc]); const appMode = useSelector(getAppMode); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const selectedWidget = useSelector(getWidgetPropsForPropertyPane); return ( diff --git a/app/client/src/widgets/withWidgetProps.tsx b/app/client/src/widgets/withWidgetProps.tsx index 5a0f13d6c19d..73dfd519687b 100644 --- a/app/client/src/widgets/withWidgetProps.tsx +++ b/app/client/src/widgets/withWidgetProps.tsx @@ -25,6 +25,7 @@ import { getMetaWidget, getIsAutoLayoutMobileBreakPoint, getCanvasWidth, + combinedPreviewModeSelector, } from "selectors/editorSelectors"; import { createCanvasWidget, @@ -49,7 +50,6 @@ import { isWidgetSelectedForPropertyPane } from "selectors/propertyPaneSelectors import WidgetFactory from "WidgetProvider/factory"; import { getIsAnvilLayout } from "layoutSystems/anvil/integrations/selectors"; import { endSpan, startRootSpan } from "instrumentation/generateTraces"; -import { selectCombinedPreviewMode } from "selectors/gitModSelectors"; const WIDGETS_WITH_CHILD_WIDGETS = ["LIST_WIDGET", "FORM_WIDGET"]; const WIDGETS_REQUIRING_SELECTED_ANCESTRY = ["MODAL_WIDGET", "TABS_WIDGET"]; @@ -69,7 +69,7 @@ function withWidgetProps(WrappedWidget: typeof BaseWidget) { } = props; const span = startRootSpan("withWidgetProps", { widgetType: type }); - const isPreviewMode = useSelector(selectCombinedPreviewMode); + const isPreviewMode = useSelector(combinedPreviewModeSelector); const canvasWidget = useSelector((state: AppState) => getWidget(state, widgetId), diff --git a/app/client/test/testUtils.tsx b/app/client/test/testUtils.tsx index 0d57bddfc09a..9b99d698bb90 100644 --- a/app/client/test/testUtils.tsx +++ b/app/client/test/testUtils.tsx @@ -49,12 +49,9 @@ interface State { } const setupState = (state?: State) => { let reduxStore = store; - window.history.pushState({}, "Appsmith", state?.url || "/"); - if (state && (state.initialState || state.featureFlags)) { reduxStore = testStore(state.initialState || {}); - if (state.featureFlags) { reduxStore.dispatch( fetchFeatureFlagsSuccess({ @@ -64,12 +61,10 @@ const setupState = (state?: State) => { ); } } - if (state && state.sagasToRun) { reduxStore = testStoreWithTestMiddleWare(reduxStore.getState()); testSagaMiddleware.run(() => rootSaga(state.sagasToRun)); } - const defaultTheme = getCurrentThemeDetails(reduxStore.getState()); return { reduxStore, defaultTheme }; @@ -81,7 +76,6 @@ const customRender = ( options?: Omit, ) => { const { defaultTheme, reduxStore } = setupState(state); - return render( @@ -98,7 +92,6 @@ const customRender = ( const hookWrapper = (state: State) => { return ({ children }: { children: ReactElement }) => { const { defaultTheme, reduxStore } = setupState(state); - return (