-
Notifications
You must be signed in to change notification settings - Fork 4.5k
chore: added import override CE #40462
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
44c644e
chore: adding override modal
2b05ddf
chore: adding functionality to import modal
6c53a10
chore: integrating override with import api
73ac3d7
chore: adding proper messaging
11abd6b
chore: minor fixes
8e3e342
chore: retain name while importing
91b03e0
chore: fixing build
84b16ad
ce changes
sondermanish 19e7e98
Merge remote-tracking branch 'origin/chore/git-import-override-1' int…
sondermanish d5435a2
chore: fixing error code
79ceda0
Merge branch 'chore/git-import-override-1' of github.com:appsmithorg/…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
app/client/src/git/components/ImportOverrideModal/ImportOverrideModalView.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { | ||
| Button, | ||
| Modal, | ||
| ModalBody, | ||
| ModalContent, | ||
| ModalFooter, | ||
| ModalHeader, | ||
| Text, | ||
| } from "@appsmith/ads"; | ||
| import { IMPORT_OVERRIDE_MODAL } from "git/ee/constants/messages"; | ||
| import useMessage from "git/hooks/useMessage"; | ||
| import noop from "lodash/noop"; | ||
| import React, { useCallback } from "react"; | ||
| import styled from "styled-components"; | ||
|
|
||
| const StyledModalContent = styled(ModalContent)` | ||
| width: 640px; | ||
| `; | ||
|
|
||
| interface ImportOverrideModalViewProps { | ||
| artifactType?: string; | ||
| isImportLoading: boolean; | ||
| isOpen: boolean; | ||
| newArtifactName: string | null; | ||
| oldArtifactName: string | null; | ||
| onImport: () => void; | ||
| onOpenChange: (open: boolean) => void; | ||
| } | ||
|
|
||
| function ImportOverrideModalView({ | ||
| artifactType = "artifact", | ||
| isImportLoading = false, | ||
| isOpen = false, | ||
| newArtifactName = null, | ||
| oldArtifactName = null, | ||
| onImport = noop, | ||
| onOpenChange = noop, | ||
| }: ImportOverrideModalViewProps) { | ||
| const modalTitle = useMessage(IMPORT_OVERRIDE_MODAL.TITLE, { artifactType }); | ||
| const modalDescription = useMessage(IMPORT_OVERRIDE_MODAL.DESCRIPTION, { | ||
| newArtifactName: newArtifactName ?? "", | ||
| oldArtifactName: oldArtifactName ?? "", | ||
| artifactType, | ||
| }); | ||
| const ctaBtnText = useMessage(IMPORT_OVERRIDE_MODAL.OVERRIDE_BTN, { | ||
| artifactType, | ||
| }); | ||
|
|
||
| const handleCancel = useCallback(() => { | ||
| onOpenChange(false); | ||
| }, [onOpenChange]); | ||
|
|
||
| const handleImport = useCallback(() => { | ||
| if (!isImportLoading) { | ||
| onImport(); | ||
| } | ||
| }, [isImportLoading, onImport]); | ||
|
|
||
| return ( | ||
| <Modal onOpenChange={onOpenChange} open={isOpen}> | ||
| <StyledModalContent> | ||
| <ModalHeader>{modalTitle}</ModalHeader> | ||
| <ModalBody> | ||
| <Text kind="body-m" renderAs="p"> | ||
| {modalDescription} | ||
| </Text> | ||
| </ModalBody> | ||
| <ModalFooter> | ||
| <Button kind="secondary" onClick={handleCancel} size="md"> | ||
| {IMPORT_OVERRIDE_MODAL.CANCEL_BTN} | ||
| </Button> | ||
| <Button | ||
| isLoading={isImportLoading} | ||
| onClick={handleImport} | ||
| size="md" | ||
| type="submit" | ||
| > | ||
| {ctaBtnText} | ||
| </Button> | ||
| </ModalFooter> | ||
| </StyledModalContent> | ||
| </Modal> | ||
| ); | ||
| } | ||
|
|
||
| export default ImportOverrideModalView; | ||
46 changes: 46 additions & 0 deletions
46
app/client/src/git/components/ImportOverrideModal/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import React, { useCallback } from "react"; | ||
| import ImportOverrideModalView from "./ImportOverrideModalView"; | ||
| import useImport from "git/hooks/useImport"; | ||
|
|
||
| function ImportOverrideModal() { | ||
| const { | ||
| gitImport, | ||
| importOverrideDetails, | ||
| isGitImportLoading, | ||
| isImportOverrideModalOpen, | ||
| resetGitImport, | ||
| resetImportOverrideDetails, | ||
| } = useImport(); | ||
|
|
||
| const handleOpenChange = useCallback( | ||
| (open: boolean) => { | ||
| if (!open && !isGitImportLoading) { | ||
| resetImportOverrideDetails(); | ||
| resetGitImport(); | ||
| } | ||
| }, | ||
| [isGitImportLoading, resetGitImport, resetImportOverrideDetails], | ||
| ); | ||
|
|
||
| const handleImport = useCallback(() => { | ||
| if (importOverrideDetails) { | ||
| const params = { ...importOverrideDetails.params, override: true }; | ||
|
|
||
| gitImport(params); | ||
| } | ||
| }, [gitImport, importOverrideDetails]); | ||
|
|
||
| return ( | ||
| <ImportOverrideModalView | ||
| artifactType={"package"} | ||
| isImportLoading={isGitImportLoading} | ||
| isOpen={isImportOverrideModalOpen} | ||
| newArtifactName={importOverrideDetails?.newArtifactName ?? null} | ||
| oldArtifactName={importOverrideDetails?.oldArtifactName ?? null} | ||
| onImport={handleImport} | ||
| onOpenChange={handleOpenChange} | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default ImportOverrideModal; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { useMemo } from "react"; | ||
|
|
||
| export default function useMessage(msg: string, args: Record<string, string>) { | ||
| return useMemo(() => { | ||
| const msgWithArgs = msg.replace(/\{\{([^}]+)\}\}/g, (match, p1) => { | ||
| // p1 is the key from {{key}} in the message | ||
| return args[p1] || match; | ||
| }); | ||
|
|
||
| return msgWithArgs; | ||
| }, [msg, args]); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,13 +2,17 @@ import { call, put, select } from "redux-saga/effects"; | |
| import { validateResponse } from "sagas/ErrorSagas"; | ||
| import type { PayloadAction } from "@reduxjs/toolkit"; | ||
| import gitImportRequest from "git/requests/gitImportRequest"; | ||
| import type { GitImportResponse } from "git/requests/gitImportRequest.types"; | ||
| import type { | ||
| GitImportRequestParams, | ||
| GitImportResponse, | ||
| } from "git/requests/gitImportRequest.types"; | ||
| import type { GitImportInitPayload } from "git/store/actions/gitImportActions"; | ||
| import { gitGlobalActions } from "git/store/gitGlobalSlice"; | ||
| import { getWorkspaceIdForImport } from "ee/selectors/applicationSelectors"; | ||
| import { GitErrorCodes } from "git/constants/enums"; | ||
| import { selectGitApiContractsEnabled } from "git/store/selectors/gitFeatureFlagSelectors"; | ||
| import handleApiErrors from "./helpers/handleApiErrors"; | ||
| import type { GitApiError } from "git/store/types"; | ||
|
|
||
| export default function* gitImportSaga( | ||
| action: PayloadAction<GitImportInitPayload>, | ||
|
|
@@ -36,6 +40,7 @@ export default function* gitImportSaga( | |
| gitGlobalActions.gitImportSuccess({ responseData: response.data }), | ||
| ); | ||
| yield put(gitGlobalActions.toggleImportModal({ open: false })); | ||
| yield put(gitGlobalActions.resetImportOverrideDetails()); | ||
| } | ||
| } catch (e) { | ||
| const error = handleApiErrors(e as Error, response); | ||
|
|
@@ -47,6 +52,38 @@ export default function* gitImportSaga( | |
| yield put(gitGlobalActions.toggleImportModal({ open: false })); | ||
| yield put(gitGlobalActions.toggleRepoLimitErrorModal({ open: true })); | ||
| } | ||
|
|
||
| if (GitErrorCodes.DUPLICATE_ARTIFACT_OVERRIDE === error.code) { | ||
| yield call(handleDuplicateArtifactOverride, error, params); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function* handleDuplicateArtifactOverride( | ||
| error: GitApiError, | ||
| params: GitImportRequestParams, | ||
| ) { | ||
| yield put(gitGlobalActions.toggleImportModal({ open: false })); | ||
|
|
||
| let artifactNames = { newArtifactName: null, oldArtifactName: null }; | ||
|
|
||
| if (error?.message) { | ||
| const jsonMatch = error.message.match(/\{.*\}/); | ||
| const jsonStr = jsonMatch ? jsonMatch[0] : null; | ||
|
|
||
| if (jsonStr) { | ||
| try { | ||
| artifactNames = JSON.parse(jsonStr); | ||
| } catch {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ideally we should log the error here |
||
| } | ||
| } | ||
|
|
||
| yield put( | ||
| gitGlobalActions.setImportOverrideDetails({ | ||
| params, | ||
| oldArtifactName: artifactNames.oldArtifactName ?? "", | ||
| newArtifactName: artifactNames.newArtifactName ?? "", | ||
| }), | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.