-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
feat: Add the ability to optionally update an existing collection on import #3615
Open
jGowgiel
wants to merge
2
commits into
usebruno:main
Choose a base branch
from
jGowgiel:feature/optionally-update-existing-collections-on-import
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
24 changes: 24 additions & 0 deletions
24
packages/bruno-app/src/components/ConfirmCollectionImportUpdate/index.js
This file contains 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,24 @@ | ||
import Modal from 'components/Modal'; | ||
import Portal from 'components/Portal/index'; | ||
|
||
const ConfirmCollectionImportUpdate = ({ onConfirm, onCancel }) => { | ||
return ( | ||
<Portal> | ||
<Modal | ||
size="md" | ||
title="Update existing collection" | ||
confirmText="Yes" | ||
cancelText="No" | ||
disableEscapeKey={true} | ||
disableCloseOnOutsideClick={true} | ||
handleConfirm={onConfirm} | ||
handleCancel={onCancel} | ||
hideClose={true} | ||
> | ||
<div>Would you like to add to the existing collection at this location?</div> | ||
</Modal> | ||
</Portal> | ||
); | ||
}; | ||
|
||
export default ConfirmCollectionImportUpdate; |
This file contains 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 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 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 |
---|---|---|
|
@@ -185,7 +185,7 @@ export const saveFolderRoot = (collectionUid, folderUid) => (dispatch, getState) | |
|
||
export const sendCollectionOauth2Request = (collectionUid, itemUid) => (dispatch, getState) => { | ||
const state = getState(); | ||
const { globalEnvironments, activeGlobalEnvironmentUid } = state.globalEnvironments; | ||
const { globalEnvironments, activeGlobalEnvironmentUid } = state.globalEnvironments; | ||
const collection = findCollectionByUid(state.collections.collections, collectionUid); | ||
|
||
return new Promise((resolve, reject) => { | ||
|
@@ -196,7 +196,10 @@ export const sendCollectionOauth2Request = (collectionUid, itemUid) => (dispatch | |
let collectionCopy = cloneDeep(collection); | ||
|
||
// add selected global env variables to the collection object | ||
const globalEnvironmentVariables = getGlobalEnvironmentVariables({ globalEnvironments, activeGlobalEnvironmentUid }); | ||
const globalEnvironmentVariables = getGlobalEnvironmentVariables({ | ||
globalEnvironments, | ||
activeGlobalEnvironmentUid | ||
}); | ||
collectionCopy.globalEnvironmentVariables = globalEnvironmentVariables; | ||
|
||
const environment = findEnvironmentInCollection(collectionCopy, collection.activeEnvironmentUid); | ||
|
@@ -219,7 +222,7 @@ export const sendCollectionOauth2Request = (collectionUid, itemUid) => (dispatch | |
|
||
export const sendRequest = (item, collectionUid) => (dispatch, getState) => { | ||
const state = getState(); | ||
const { globalEnvironments, activeGlobalEnvironmentUid } = state.globalEnvironments; | ||
const { globalEnvironments, activeGlobalEnvironmentUid } = state.globalEnvironments; | ||
const collection = findCollectionByUid(state.collections.collections, collectionUid); | ||
|
||
return new Promise((resolve, reject) => { | ||
|
@@ -231,7 +234,10 @@ export const sendRequest = (item, collectionUid) => (dispatch, getState) => { | |
let collectionCopy = cloneDeep(collection); | ||
|
||
// add selected global env variables to the collection object | ||
const globalEnvironmentVariables = getGlobalEnvironmentVariables({ globalEnvironments, activeGlobalEnvironmentUid }); | ||
const globalEnvironmentVariables = getGlobalEnvironmentVariables({ | ||
globalEnvironments, | ||
activeGlobalEnvironmentUid | ||
}); | ||
collectionCopy.globalEnvironmentVariables = globalEnvironmentVariables; | ||
|
||
const environment = findEnvironmentInCollection(collectionCopy, collectionCopy.activeEnvironmentUid); | ||
|
@@ -297,7 +303,7 @@ export const cancelRunnerExecution = (cancelTokenUid) => (dispatch) => { | |
|
||
export const runCollectionFolder = (collectionUid, folderUid, recursive, delay) => (dispatch, getState) => { | ||
const state = getState(); | ||
const { globalEnvironments, activeGlobalEnvironmentUid } = state.globalEnvironments; | ||
const { globalEnvironments, activeGlobalEnvironmentUid } = state.globalEnvironments; | ||
const collection = findCollectionByUid(state.collections.collections, collectionUid); | ||
|
||
return new Promise((resolve, reject) => { | ||
|
@@ -308,7 +314,10 @@ export const runCollectionFolder = (collectionUid, folderUid, recursive, delay) | |
let collectionCopy = cloneDeep(collection); | ||
|
||
// add selected global env variables to the collection object | ||
const globalEnvironmentVariables = getGlobalEnvironmentVariables({ globalEnvironments, activeGlobalEnvironmentUid }); | ||
const globalEnvironmentVariables = getGlobalEnvironmentVariables({ | ||
globalEnvironments, | ||
activeGlobalEnvironmentUid | ||
}); | ||
collectionCopy.globalEnvironmentVariables = globalEnvironmentVariables; | ||
|
||
const folder = findItemInCollection(collectionCopy, folderUid); | ||
|
@@ -989,15 +998,16 @@ export const selectEnvironment = (environmentUid, collectionUid) => (dispatch, g | |
|
||
const collectionCopy = cloneDeep(collection); | ||
|
||
const environmentName = environmentUid | ||
? findEnvironmentInCollection(collectionCopy, environmentUid)?.name | ||
: null; | ||
const environmentName = environmentUid ? findEnvironmentInCollection(collectionCopy, environmentUid)?.name : null; | ||
|
||
if (environmentUid && !environmentName) { | ||
return reject(new Error('Environment not found')); | ||
} | ||
|
||
ipcRenderer.invoke('renderer:update-ui-state-snapshot', { type: 'COLLECTION_ENVIRONMENT', data: { collectionPath: collection?.pathname, environmentName }}); | ||
} | ||
|
||
ipcRenderer.invoke('renderer:update-ui-state-snapshot', { | ||
type: 'COLLECTION_ENVIRONMENT', | ||
data: { collectionPath: collection?.pathname, environmentName } | ||
}); | ||
|
||
dispatch(_selectEnvironment({ environmentUid, collectionUid })); | ||
resolve(); | ||
|
@@ -1140,11 +1150,14 @@ export const collectionAddEnvFileEvent = (payload) => (dispatch, getState) => { | |
}); | ||
}; | ||
|
||
export const importCollection = (collection, collectionLocation) => (dispatch, getState) => { | ||
export const importCollection = (collection, collectionLocation, updateExistingCollection) => (dispatch, getState) => { | ||
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. This method was materially updated, not just formatted (with a new argument). |
||
return new Promise((resolve, reject) => { | ||
const { ipcRenderer } = window; | ||
|
||
ipcRenderer.invoke('renderer:import-collection', collection, collectionLocation).then(resolve).catch(reject); | ||
ipcRenderer | ||
.invoke('renderer:import-collection', collection, collectionLocation, updateExistingCollection) | ||
.then(resolve) | ||
.catch(reject); | ||
}); | ||
}; | ||
|
||
|
@@ -1164,32 +1177,30 @@ export const saveCollectionSecurityConfig = (collectionUid, securityConfig) => ( | |
}); | ||
}; | ||
|
||
|
||
export const hydrateCollectionWithUiStateSnapshot = (payload) => (dispatch, getState) => { | ||
const collectionSnapshotData = payload; | ||
return new Promise((resolve, reject) => { | ||
const state = getState(); | ||
try { | ||
if(!collectionSnapshotData) resolve(); | ||
const { pathname, selectedEnvironment } = collectionSnapshotData; | ||
const collection = findCollectionByPathname(state.collections.collections, pathname); | ||
const collectionCopy = cloneDeep(collection); | ||
const collectionUid = collectionCopy?.uid; | ||
|
||
// update selected environment | ||
if (selectedEnvironment) { | ||
const environment = findEnvironmentInCollectionByName(collectionCopy, selectedEnvironment); | ||
if (environment) { | ||
dispatch(_selectEnvironment({ environmentUid: environment?.uid, collectionUid })); | ||
} | ||
const collectionSnapshotData = payload; | ||
return new Promise((resolve, reject) => { | ||
const state = getState(); | ||
try { | ||
if (!collectionSnapshotData) resolve(); | ||
const { pathname, selectedEnvironment } = collectionSnapshotData; | ||
const collection = findCollectionByPathname(state.collections.collections, pathname); | ||
const collectionCopy = cloneDeep(collection); | ||
const collectionUid = collectionCopy?.uid; | ||
|
||
// update selected environment | ||
if (selectedEnvironment) { | ||
const environment = findEnvironmentInCollectionByName(collectionCopy, selectedEnvironment); | ||
if (environment) { | ||
dispatch(_selectEnvironment({ environmentUid: environment?.uid, collectionUid })); | ||
} | ||
|
||
// todo: add any other redux state that you want to save | ||
|
||
resolve(); | ||
} | ||
catch(error) { | ||
reject(error); | ||
} | ||
}); | ||
}; | ||
|
||
// todo: add any other redux state that you want to save | ||
|
||
resolve(); | ||
} catch (error) { | ||
reject(error); | ||
} | ||
}); | ||
}; |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many of the changes in this file are just the result of running the existing formatter for this project.