diff --git a/.gitignore b/.gitignore index 8d9bcfba4528..ce30cb8280c7 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,7 @@ app/client/yalc.lock .idea .fleet/* app/client/.fleet/* +.lens # Observability related local storage utils/observability/tempo-data/* diff --git a/app/client/src/git-artifact-helpers/application/sagas/applicationImportFromGitSaga.ts b/app/client/src/git-artifact-helpers/application/sagas/applicationImportFromGitSaga.ts new file mode 100644 index 000000000000..f77549611140 --- /dev/null +++ b/app/client/src/git-artifact-helpers/application/sagas/applicationImportFromGitSaga.ts @@ -0,0 +1,54 @@ +import { toast } from "@appsmith/ads"; +import { createMessage, IMPORT_APP_SUCCESSFUL } from "ee/constants/messages"; +import { builderURL } from "ee/RouteBuilder"; +import { showReconnectDatasourceModal } from "ee/actions/applicationActions"; +import type { ApplicationResponsePayload } from "ee/api/ApplicationApi"; +import type { GitImportSuccessPayload } from "git/store/actions/gitImportActions"; +import type { GitArtifactPayloadAction } from "git/store/types"; +import { put } from "redux-saga/effects"; +import history from "utils/history"; + +export default function* applicationImportFromGitSaga( + action: GitArtifactPayloadAction, +) { + const { responseData } = action.payload; + const { isPartialImport, unConfiguredDatasourceList } = responseData; + + const application = + (responseData.application as ApplicationResponsePayload) ?? null; + + if (!application) return; + + // there is configuration-missing datasources + if (isPartialImport) { + yield put( + showReconnectDatasourceModal({ + application: application as ApplicationResponsePayload, + unConfiguredDatasourceList: unConfiguredDatasourceList ?? [], + workspaceId: application?.workspaceId ?? "", + }), + ); + } else { + let basePageId = ""; + + if (application.pages && application.pages.length > 0) { + const defaultPage = application.pages.find( + (eachPage) => !!eachPage.isDefault, + ); + + basePageId = defaultPage ? defaultPage.baseId : ""; + } + + const branch = application?.gitApplicationMetadata?.branchName; + + const pageURL = builderURL({ + basePageId, + branch, + }); + + history.push(pageURL); + toast.show(createMessage(IMPORT_APP_SUCCESSFUL), { + kind: "success", + }); + } +} diff --git a/app/client/src/git-artifact-helpers/application/sagas/index.ts b/app/client/src/git-artifact-helpers/application/sagas/index.ts index d6d98ee95b36..e4942f06beae 100644 --- a/app/client/src/git-artifact-helpers/application/sagas/index.ts +++ b/app/client/src/git-artifact-helpers/application/sagas/index.ts @@ -5,12 +5,15 @@ import { gitCheckoutBranchSuccess, gitConnectSuccess, gitDiscardSuccess, + gitImportSuccess, gitPullSuccess, } from "git/store"; +import applicationImportFromGitSaga from "./applicationImportFromGitSaga"; export default function* gitApplicationSagas() { yield all([ takeLatest(gitConnectSuccess.type, applicationConnectToGitSaga), + takeLatest(gitImportSuccess.type, applicationImportFromGitSaga), takeLatest(gitDiscardSuccess.type, applicationRedirectToClosestEntitySaga), takeLatest( gitCheckoutBranchSuccess.type, diff --git a/app/client/src/git/requests/gitImportRequest.types.ts b/app/client/src/git/requests/gitImportRequest.types.ts index 034dc7aed402..bfa4def95548 100644 --- a/app/client/src/git/requests/gitImportRequest.types.ts +++ b/app/client/src/git/requests/gitImportRequest.types.ts @@ -1,6 +1,6 @@ import type { ApiResponse } from "api/types"; -import type { ApplicationResponsePayload } from "ee/api/ApplicationApi"; import type { Datasource } from "entities/Datasource"; +import type { GitApplicationArtifact, GitPackageArtifact } from "git/types"; export interface GitImportRequestParams { remoteUrl: string; @@ -12,7 +12,8 @@ export interface GitImportRequestParams { } export interface GitImportResponseData { - application: ApplicationResponsePayload; + application?: GitApplicationArtifact; + package?: GitPackageArtifact; isPartialImport: boolean; unConfiguredDatasourceList?: Datasource[]; } diff --git a/app/client/src/git/sagas/gitImportSaga.ts b/app/client/src/git/sagas/gitImportSaga.ts index e6b1bdfeb311..5f55c4772ebc 100644 --- a/app/client/src/git/sagas/gitImportSaga.ts +++ b/app/client/src/git/sagas/gitImportSaga.ts @@ -1,18 +1,11 @@ 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 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"; import { GitErrorCodes } from "git/constants/enums"; import { selectGitApiContractsEnabled } from "git/store/selectors/gitFeatureFlagSelectors"; import handleApiErrors from "./helpers/handleApiErrors"; @@ -39,52 +32,10 @@ export default function* gitImportSaga( const isValidResponse: boolean = yield validateResponse(response); if (response && isValidResponse) { - const allWorkspaces: Workspace[] = yield select(getFetchedWorkspaces); - const currentWorkspace = allWorkspaces.filter( - (el: Workspace) => el.id === workspaceId, + yield put( + gitGlobalActions.gitImportSuccess({ responseData: response.data }), ); - - 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 branch = - response.data?.application?.gitApplicationMetadata?.branchName; - - const pageURL = builderURL({ - basePageId, - branch, - }); - - history.push(pageURL); - toast.show(createMessage(IMPORT_APP_SUCCESSFUL), { - kind: "success", - }); - } - } + yield put(gitGlobalActions.toggleImportModal({ open: false })); } } catch (e) { const error = handleApiErrors(e as Error, response); diff --git a/app/client/src/git/store/actions/gitImportActions.ts b/app/client/src/git/store/actions/gitImportActions.ts index 30e9c7417b2d..a823ca7b6d4b 100644 --- a/app/client/src/git/store/actions/gitImportActions.ts +++ b/app/client/src/git/store/actions/gitImportActions.ts @@ -1,12 +1,19 @@ import type { PayloadAction } from "@reduxjs/toolkit"; -import type { GitAsyncErrorPayload, GitGlobalReduxState } from "../types"; -import type { GitImportRequestParams } from "git/requests/gitImportRequest.types"; +import type { + GitAsyncErrorPayload, + GitAsyncSuccessPayload, + GitGlobalReduxState, +} from "../types"; +import type { + GitImportRequestParams, + GitImportResponseData, +} from "git/requests/gitImportRequest.types"; export interface GitImportInitPayload extends GitImportRequestParams {} export const gitImportInitAction = ( state: GitGlobalReduxState, - // need type for better import + // need this here to preserve interface // eslint-disable-next-line @typescript-eslint/no-unused-vars action: PayloadAction, ) => { @@ -16,7 +23,15 @@ export const gitImportInitAction = ( return state; }; -export const gitImportSuccessAction = (state: GitGlobalReduxState) => { +export type GitImportSuccessPayload = + GitAsyncSuccessPayload; + +export const gitImportSuccessAction = ( + state: GitGlobalReduxState, + // need this here to preserve interface + // eslint-disable-next-line @typescript-eslint/no-unused-vars + action: PayloadAction, +) => { state.gitImport.loading = false; return state; diff --git a/app/client/src/git/store/index.ts b/app/client/src/git/store/index.ts index 3e298092e32f..990e50a361af 100644 --- a/app/client/src/git/store/index.ts +++ b/app/client/src/git/store/index.ts @@ -17,3 +17,4 @@ export const gitDiscardSuccess = gitArtifactActions.discardSuccess; export const gitCheckoutBranchSuccess = gitArtifactActions.checkoutBranchSuccess; export const gitPullSuccess = gitArtifactActions.pullSuccess; +export const gitImportSuccess = gitGlobalActions.gitImportSuccess;