forked from usebruno/bruno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: UI for OAuth2 Credentials independent of the Request Output pane
- Loading branch information
1 parent
3e113aa
commit 8462d73
Showing
14 changed files
with
138 additions
and
151 deletions.
There are no files selected for viewing
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
57 changes: 57 additions & 0 deletions
57
packages/bruno-app/src/components/CollectionSettings/Auth/OAuth2/CredentialsPreview/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,57 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { clearOauth2Cache, readOauth2CachedCredentials } from 'utils/network'; | ||
import { sendCollectionOauth2Request } from 'providers/ReduxStore/slices/collections/actions'; | ||
import toast from 'react-hot-toast'; | ||
import { useDispatch } from 'react-redux'; | ||
|
||
const CredentialsPreview = ({ collection }) => { | ||
const oauth2CredentialsAreaRef = React.createRef(); | ||
const [oauth2Credentials, setOauth2Credentials] = useState({}); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
oauth2CredentialsAreaRef.current.value = oauth2Credentials; | ||
readOauth2CachedCredentials(collection.uid).then((credentials) => setOauth2Credentials(credentials)); | ||
}, [oauth2CredentialsAreaRef]); | ||
|
||
const handleRun = async () => { | ||
dispatch(sendCollectionOauth2Request(collection.uid)); | ||
}; | ||
|
||
const handleClearCache = (e) => { | ||
clearOauth2Cache(collection?.uid) | ||
.then(() => { | ||
readOauth2CachedCredentials(collection.uid).then((credentials) => { | ||
setOauth2Credentials(credentials); | ||
toast.success('cleared cache successfully'); | ||
}); | ||
}) | ||
.catch((err) => { | ||
toast.error(err.message); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col w-full gap-1 mt-4"> | ||
<div className="flex flex-row gap-4"> | ||
<button onClick={handleRun} className="submit btn btn-sm btn-secondary w-fit"> | ||
Get Access Token | ||
</button> | ||
<button onClick={handleClearCache} className="submit btn btn-sm btn-secondary w-fit"> | ||
Clear Cache | ||
</button> | ||
</div> | ||
<div ref={oauth2CredentialsAreaRef}> | ||
<label className="block font-medium">OAuth2 Credentials</label> | ||
{Object.entries(oauth2Credentials).map(([key, value]) => ( | ||
<div key={key}> | ||
<label className="text-xs">{key}</label> | ||
<textarea className="w-full h-24 p-2 text-xs border rounded" value={value} readOnly /> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CredentialsPreview; |
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
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
57 changes: 57 additions & 0 deletions
57
packages/bruno-app/src/components/RequestPane/Auth/OAuth2/CredentialsPreview/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,57 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { clearOauth2Cache, readOauth2CachedCredentials } from 'utils/network'; | ||
import { sendRequest } from 'providers/ReduxStore/slices/collections/actions'; | ||
import toast from 'react-hot-toast'; | ||
import { useDispatch } from 'react-redux'; | ||
|
||
const CredentialsPreview = ({ item, collection }) => { | ||
const oauth2CredentialsAreaRef = React.createRef(); | ||
const [oauth2Credentials, setOauth2Credentials] = useState({}); | ||
const dispatch = useDispatch(); | ||
|
||
useEffect(() => { | ||
oauth2CredentialsAreaRef.current.value = oauth2Credentials; | ||
readOauth2CachedCredentials(collection.uid).then((credentials) => setOauth2Credentials(credentials)); | ||
}, [oauth2CredentialsAreaRef]); | ||
|
||
const handleRun = async () => { | ||
dispatch(sendRequest(item, collection.uid)); | ||
}; | ||
|
||
const handleClearCache = (e) => { | ||
clearOauth2Cache(collection?.uid) | ||
.then(() => { | ||
readOauth2CachedCredentials(collection.uid).then((credentials) => { | ||
setOauth2Credentials(credentials); | ||
toast.success('cleared cache successfully'); | ||
}); | ||
}) | ||
.catch((err) => { | ||
toast.error(err.message); | ||
}); | ||
}; | ||
|
||
return ( | ||
<div className="flex flex-col w-full gap-1 mt-4"> | ||
<div className="flex flex-row gap-4"> | ||
<button onClick={handleRun} className="submit btn btn-sm btn-secondary w-fit"> | ||
Get Access Token | ||
</button> | ||
<button onClick={handleClearCache} className="submit btn btn-sm btn-secondary w-fit"> | ||
Clear Cache | ||
</button> | ||
</div> | ||
<div ref={oauth2CredentialsAreaRef}> | ||
<label className="block font-medium">OAuth2 Credentials</label> | ||
{Object.entries(oauth2Credentials).map(([key, value]) => ( | ||
<div key={key}> | ||
<label className="text-xs">{key}</label> | ||
<textarea className="w-full h-24 p-2 text-xs border rounded" value={value} readOnly /> | ||
</div> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CredentialsPreview; |
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
Oops, something went wrong.