Skip to content

Commit

Permalink
chore: adding post import sagas for application
Browse files Browse the repository at this point in the history
  • Loading branch information
brayn003 committed Feb 18, 2025
1 parent 95e8e37 commit 3f30318
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -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<GitImportSuccessPayload>,
) {
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",
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions app/client/src/git/requests/gitImportRequest.types.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -12,7 +12,8 @@ export interface GitImportRequestParams {
}

export interface GitImportResponseData {
application: ApplicationResponsePayload;
application?: GitApplicationArtifact;
package?: GitPackageArtifact;
isPartialImport: boolean;
unConfiguredDatasourceList?: Datasource[];
}
Expand Down
55 changes: 3 additions & 52 deletions app/client/src/git/sagas/gitImportSaga.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
Expand Down
23 changes: 19 additions & 4 deletions app/client/src/git/store/actions/gitImportActions.ts
Original file line number Diff line number Diff line change
@@ -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<GitImportInitPayload>,
) => {
Expand All @@ -16,7 +23,15 @@ export const gitImportInitAction = (
return state;
};

export const gitImportSuccessAction = (state: GitGlobalReduxState) => {
export type GitImportSuccessPayload =
GitAsyncSuccessPayload<GitImportResponseData>;

export const gitImportSuccessAction = (
state: GitGlobalReduxState,
// need this here to preserve interface
// eslint-disable-next-line @typescript-eslint/no-unused-vars
action: GitImportSuccessPayload,
) => {
state.gitImport.loading = false;

return state;
Expand Down
1 change: 1 addition & 0 deletions app/client/src/git/store/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ export const gitDiscardSuccess = gitArtifactActions.discardSuccess;
export const gitCheckoutBranchSuccess =
gitArtifactActions.checkoutBranchSuccess;
export const gitPullSuccess = gitArtifactActions.pullSuccess;
export const gitImportSuccess = gitGlobalActions.gitImportSuccess;

0 comments on commit 3f30318

Please sign in to comment.