PromucFlow_constructor/app/client/src/actions/gitSyncActions.ts
haojin111 9cfca0518f
feat: 9754 import work flow (#10453)
* updated import application modal design as v2

* updated import flow

* added title, description, uploadIcon on filepicker ads component for custom file picker

* adding modal of add credential for git import

* added "Git Import" modal

* added generating ssh key for importing flow

* fixed issue of merging

* chore: fix import

* chore: show old import modal based on feature flag

* seperated import api from connect

* added datasource list on reconnect credential modal

* chore: minor changes

* chore: move ssh keys to git sync reducer from applications reducer

* chore: minor fixes

* chore: fetch datasource config for import

* for pulling

* for review of displaying of datasource

* added reconnect datasources after git import

* fix: initialize datasource with default values

* fix: initialise redux for after updating datasource with default values

* fixed issue of git connection init when importing

* if there is a datasource config missing in import, reconnect modal should be opened

* updated logic for unconfigured datasources

* commented unnecessary code

* fixed issue of successful import

* updated import app error logic

* Add un-configured datasources to Import via file response

* Add test

* fix

* chore: refactors

* change per review

* fix: reset ssh keys / url

* Fix issue with newly created datasources not sent

* fix

* chore: minor updates

* chore: minor fix

* WIP

* added saas and rest api datasource form

* feat: fixes and updates for file import flow

* chore: close on upload

* Refactor logic ofr finding unconfigured datasources

* fix: minor fixes

* Fix issue with IsPartialImport

* fix

* Add PartialImport flag for ImportExport service

* refactoring of datasource editor form for both of importing app and editing app

* fixed collapse config

* Fix tests

* Handle redirection back to the /applications for oAuth type

* Show reconnect button on the datasources pages if the datasource configuration is skipped

* added analytic events for reconnecting datasource modal

* Fix the repo limit check for git import

* updated test of importing app from json as new work flow

* updated exported app json while testing automatically

* Add isImport flag for handling OAuth redirection in import flow

* WIP

* updated card UI for import from git title and message in import app modal

* chore: cleanup

* chore: lint

* fix: add is import query param to get token for oauth

* fix

* When the user imports the application there should not be any uncommitted changes displayed on the commit icon

* Add flag to identify OAuth redirection for git import

* Update the variable name

* refactoring reconnect datasource modal

* close git import modal when repo limit error responded

* fixed issue of restoring draft data of datasource form without save on reconnect datasource modal

* chore: update query

* updated query name of oauth redirection url

* Fix duplicate name issue in git import

* fixed rest api reconnect issue on reconnect modal

* init datasources and plugins after imported app, updated reconnect modal as new design

* added unconfigured datasource list logic when importing and updated rest api form delete button visible

* removed put default config of datasource and fixed issue on it

* Add logic to check isCOnfugred in datasource API

* Expose API to get un configured datasources for git import

* added fetch unconfigured datasource list api when redirecting form OAuth

* Remove sensitive fields from application json during export

* update put call response to check for datasourceConfig

* chore: use @appsmith for constants/messages

* chore: use download icon and Import for Importing application label

* chore: move import application text up a bit

* Fix bad merge

* chore: update skip to application tooltip text

* fixed tooltip content of skip to application CTA

* init values of datasource when importing

* updated ui of git import modal as figma design

* fixing padding issue of reconnect datasource modal

* fixed cursor issue on import app modal

* Fix issue with datasource config

* chore: make code compile

* chore: sort lines

* fixed save button issue of dbform on reconnecting modal

* fixed style of import application modal

* Fix iisue with wrong value updated to flag

* reverted from reconnection form style

* fix: update design as per slack discussions on 2022.02.23

* fix: move modal close button to the left

* Remove check for the flag and use the one from db

* Set siCOnfigured as true for mockdata sets

* updated creating datasource with isConfigured as false

* Fix NPE while importing

* fixed scrollbar issue and text alignment on reconnect datasource modal

* fixed style of form container in reconnect datasource and redirecting to app if all are configured

* remove unwanted fields from application json

* FIx NPE for file import

* fix: move close button up in import modal

* remove delete button on reconnect datasource modal

* Add isConfigured false while creating datasources

* fix: add a gap and update color

gap between git import dialog title and subtitle
update color of subtext to GREY_800

* fix: use git import feature flag

* fix: do not use older modal

* updated selecting logic of unconfigured datasource in reconnect modal

* cleanup: auto format

* cleanup: refactor react component

* cleanup: refactor some more

* cleanup: autoformat

* Fix reconnect flag for mockdatasource

* During git import set the isConfigured to false for datasources

* Remove decrypted field from the applicationJson file

* Remove decrypted field from the applicationJson file

* Add app slug to remote repo

* fixed cypress test related with git

* updated json while testing

* Changes per review

* Update the method name

* fixed cypress test related with git

* fixed migration cypress test

* set is configured field as true on tour app

* Fix issue with datasource creation for welcome tour

* fixed issue of replay_editor cypress test

Co-authored-by: Rishabh Saxena <rishabh@appsmith.com>
Co-authored-by: Anagh Hegde <anagh@appsmith.com>
Co-authored-by: Anubhav <anubhav@appsmith.com>
Co-authored-by: f0c1s <iamanubhavsaini+git@gmail.com>
2022-03-17 15:58:54 +05:30

378 lines
9.1 KiB
TypeScript

import { ReduxActionTypes } from "constants/ReduxActionConstants";
import { ConnectToGitPayload } from "api/GitSyncAPI";
import {
ReduxActionWithCallbacks,
ReduxActionErrorTypes,
} from "constants/ReduxActionConstants";
import { GitSyncModalTab, GitConfig, MergeStatus } from "entities/GitSync";
import { GitApplicationMetadata } from "api/ApplicationApi";
import { GitStatusData } from "reducers/uiReducers/gitSyncReducer";
import { ResponseMeta } from "../api/ApiResponses";
export const setIsGitSyncModalOpen = (payload: {
isOpen: boolean;
tab?: GitSyncModalTab;
}) => {
return {
type: ReduxActionTypes.SET_IS_GIT_SYNC_MODAL_OPEN,
payload,
};
};
export const setIsDisconnectGitModalOpen = (payload: boolean) => {
return {
type: ReduxActionTypes.SET_SHOULD_SHOW_DISCONNECT_GIT_MODAL,
payload,
};
};
export const commitToRepoInit = (payload: {
commitMessage: string;
doPush: boolean;
}) => ({
type: ReduxActionTypes.COMMIT_TO_GIT_REPO_INIT,
payload,
});
export const commitToRepoSuccess = () => ({
type: ReduxActionTypes.COMMIT_TO_GIT_REPO_SUCCESS,
});
export const clearCommitSuccessfulState = () => ({
type: ReduxActionTypes.CLEAR_COMMIT_SUCCESSFUL_STATE,
});
export type ConnectToGitResponse = {
gitApplicationMetadata: GitApplicationMetadata;
};
type ConnectToGitRequestParams = {
payload: ConnectToGitPayload;
onSuccessCallback?: (payload: ConnectToGitResponse) => void;
onErrorCallback?: (error: string) => void;
};
export type ConnectToGitReduxAction = ReduxActionWithCallbacks<
ConnectToGitPayload,
ConnectToGitResponse,
string
>;
export const connectToGitInit = ({
onErrorCallback,
onSuccessCallback,
payload,
}: ConnectToGitRequestParams): ConnectToGitReduxAction => ({
type: ReduxActionTypes.CONNECT_TO_GIT_INIT,
payload,
onSuccessCallback,
onErrorCallback,
});
export const connectToGitSuccess = (payload: ConnectToGitResponse) => ({
type: ReduxActionTypes.CONNECT_TO_GIT_SUCCESS,
payload,
});
export const switchGitBranchInit = (branch: string) => ({
type: ReduxActionTypes.SWITCH_GIT_BRANCH_INIT,
payload: branch,
});
export const createNewBranchInit = ({
branch,
onErrorCallback,
onSuccessCallback,
}: {
branch: string;
onSuccessCallback: () => void;
onErrorCallback: () => void;
}) => ({
type: ReduxActionTypes.CREATE_NEW_BRANCH_INIT,
payload: branch,
onErrorCallback,
onSuccessCallback,
});
export const setIsGitErrorPopupVisible = (payload: { isVisible: boolean }) => ({
type: ReduxActionTypes.SHOW_ERROR_POPUP,
payload,
});
export const showCreateBranchPopup = () => ({
type: ReduxActionTypes.SHOW_CREATE_GIT_BRANCH_POPUP,
});
export const updateGlobalGitConfigInit = (payload: GitConfig) => ({
type: ReduxActionTypes.UPDATE_GLOBAL_GIT_CONFIG_INIT,
payload,
});
export const updateGlobalGitConfigSuccess = (payload: GitConfig) => ({
type: ReduxActionTypes.UPDATE_GLOBAL_GIT_CONFIG_SUCCESS,
payload,
});
export const fetchGlobalGitConfigInit = () => ({
type: ReduxActionTypes.FETCH_GLOBAL_GIT_CONFIG_INIT,
});
export const fetchGlobalGitConfigSuccess = (payload: GitConfig) => ({
type: ReduxActionTypes.FETCH_GLOBAL_GIT_CONFIG_SUCCESS,
payload,
});
export const fetchBranchesInit = (payload?: { pruneBranches: boolean }) => ({
type: ReduxActionTypes.FETCH_BRANCHES_INIT,
payload,
});
export const fetchBranchesSuccess = (payload: any) => ({
type: ReduxActionTypes.FETCH_BRANCHES_SUCCESS,
payload,
});
// Local Git config is repo level
export const updateLocalGitConfigInit = (payload: GitConfig) => ({
type: ReduxActionTypes.UPDATE_LOCAL_GIT_CONFIG_INIT,
payload,
});
export const updateLocalGitConfigSuccess = (payload: GitConfig) => ({
type: ReduxActionTypes.UPDATE_LOCAL_GIT_CONFIG_SUCCESS,
payload,
});
export const fetchLocalGitConfigInit = () => ({
type: ReduxActionTypes.FETCH_LOCAL_GIT_CONFIG_INIT,
});
export const fetchLocalGitConfigSuccess = (payload: GitConfig) => ({
type: ReduxActionTypes.FETCH_LOCAL_GIT_CONFIG_SUCCESS,
payload,
});
export const fetchGitStatusInit = () => ({
type: ReduxActionTypes.FETCH_GIT_STATUS_INIT,
payload: null,
});
export const fetchGitStatusSuccess = (payload: GitStatusData) => ({
type: ReduxActionTypes.FETCH_GIT_STATUS_SUCCESS,
payload,
});
export const updateBranchLocally = (payload: string) => ({
type: ReduxActionTypes.UPDATE_BRANCH_LOCALLY,
payload,
});
type MergeBranchPayload = { sourceBranch: string; destinationBranch: string };
export const mergeBranchInit = (params: {
payload: { sourceBranch: string; destinationBranch: string };
onSuccessCallback: () => void;
}) => ({
type: ReduxActionTypes.MERGE_BRANCH_INIT,
...params,
});
export const mergeBranchSuccess = () => ({
type: ReduxActionTypes.MERGE_BRANCH_SUCCESS,
});
export const mergeBranchFailure = () => ({
type: ReduxActionErrorTypes.MERGE_BRANCH_ERROR,
});
export const fetchMergeStatusInit = (payload: MergeBranchPayload) => ({
type: ReduxActionTypes.FETCH_MERGE_STATUS_INIT,
payload,
});
export const fetchMergeStatusSuccess = (payload: MergeStatus) => ({
type: ReduxActionTypes.FETCH_MERGE_STATUS_SUCCESS,
payload,
});
export const fetchMergeStatusFailure = (payload: {
error: string;
show: boolean;
}) => ({
type: ReduxActionErrorTypes.FETCH_MERGE_STATUS_ERROR,
payload,
});
export const resetMergeStatus = () => ({
type: ReduxActionTypes.RESET_MERGE_STATUS,
});
export const gitPullInit = (payload?: {
triggeredFromBottomBar?: boolean;
}) => ({
type: ReduxActionTypes.GIT_PULL_INIT,
payload,
});
export const gitPullSuccess = (mergeStatus: MergeStatus) => ({
type: ReduxActionTypes.GIT_PULL_SUCCESS,
payload: mergeStatus,
});
export const resetPullMergeStatus = () => ({
type: ReduxActionTypes.RESET_PULL_MERGE_STATUS,
});
export const remoteUrlInputValue = (payload?: { tempRemoteUrl?: string }) => ({
type: ReduxActionTypes.SET_REMOTE_URL_INPUT_VALUE,
payload,
});
export const setShowRepoLimitErrorModal = (payload: boolean) => ({
type: ReduxActionTypes.SET_SHOULD_SHOW_REPO_LIMIT_ERROR_MODAL,
payload,
});
export const showConnectGitModal = () => ({
type: ReduxActionTypes.SHOW_CONNECT_GIT_MODAL,
});
export const disconnectGit = () => ({
type: ReduxActionTypes.DISCONNECT_GIT,
});
export const setDisconnectingGitApplication = (payload: {
id: string;
name: string;
}) => ({
type: ReduxActionTypes.SET_DISCONNECTING_GIT_APPLICATION,
payload,
});
export const importAppFromGit = ({
onErrorCallback,
onSuccessCallback,
payload,
}: ConnectToGitRequestParams): ConnectToGitReduxAction => ({
type: ReduxActionTypes.IMPORT_APPLICATION_FROM_GIT_INIT,
payload,
onSuccessCallback,
onErrorCallback,
});
type ErrorPayload = string;
export type GetSSHKeyResponseData = {
docUrl: string;
publicKey?: string;
};
export type GenerateSSHKeyPairResponsePayload<T> = {
responseMeta: ResponseMeta;
data: T;
};
export type GenerateSSHKeyPairReduxAction = ReduxActionWithCallbacks<
undefined,
GenerateSSHKeyPairResponsePayload<GetSSHKeyResponseData>,
ErrorPayload
>;
export type GenerateKeyParams = {
onErrorCallback?: (payload: ErrorPayload) => void;
onSuccessCallback?: (
payload: GenerateSSHKeyPairResponsePayload<GetSSHKeyResponseData>,
) => void;
payload?: undefined;
};
export const generateSSHKeyPair = ({
onErrorCallback,
onSuccessCallback,
payload,
}: GenerateKeyParams): GenerateSSHKeyPairReduxAction => {
return {
type: ReduxActionTypes.GENERATE_SSH_KEY_PAIR_INIT,
payload,
onErrorCallback,
onSuccessCallback,
};
};
export const generateSSHKeyPairSuccess = (
payload: GenerateSSHKeyPairResponsePayload<GetSSHKeyResponseData>,
) => {
return {
type: ReduxActionTypes.GENERATE_SSH_KEY_PAIR_SUCCESS,
payload,
};
};
export type GetSSHKeyPairResponsePayload<T> = {
responseMeta: ResponseMeta;
data: T;
};
export type GetSSHKeyPairReduxAction = ReduxActionWithCallbacks<
undefined,
GetSSHKeyPairResponsePayload<GetSSHKeyResponseData>,
ErrorPayload
>;
export type GetKeyParams = {
onErrorCallback?: (payload: ErrorPayload) => void;
onSuccessCallback?: (
payload: GetSSHKeyPairResponsePayload<GetSSHKeyResponseData>,
) => void;
payload?: undefined;
};
export const getSSHKeyPair = ({
onErrorCallback,
onSuccessCallback,
payload,
}: GetKeyParams): GetSSHKeyPairReduxAction => {
return {
type: ReduxActionTypes.FETCH_SSH_KEY_PAIR_INIT,
payload,
onErrorCallback,
onSuccessCallback,
};
};
export const getSSHKeyPairSuccess = (
payload: GetSSHKeyPairResponsePayload<GetSSHKeyResponseData>,
) => {
return {
type: ReduxActionTypes.FETCH_SSH_KEY_PAIR_SUCCESS,
payload,
};
};
export const getSSHKeyPairError = (payload: {
error: string;
show: boolean;
}) => {
return {
type: ReduxActionErrorTypes.FETCH_SSH_KEY_PAIR_ERROR,
payload,
};
};
export const initSSHKeyPairWithNull = () => ({
type: ReduxActionTypes.INIT_SSH_KEY_PAIR_WITH_NULL,
});
export const importAppViaGitSuccess = () => ({
type: ReduxActionTypes.IMPORT_APPLICATION_FROM_GIT_SUCCESS,
});
// todo define type
export const importAppViaGitError = (error: any) => ({
type: ReduxActionTypes.IMPORT_APPLICATION_FROM_GIT_ERROR,
payload: error,
});
export const resetSSHKeys = () => ({
type: ReduxActionTypes.RESET_SSH_KEY_PAIR,
});