Skip to content

Commit cd55188

Browse files
feat: allow restoring secret values from history (#121)
* feat: allow restoring secret values from history * feat: added label to the restore button * fix: button ui --------- Co-authored-by: Nimish <nimish@phase.dev> Co-authored-by: Nimish <85357445+nimish-ks@users.noreply.github.com>
1 parent 26b92d6 commit cd55188

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

frontend/components/environments/SecretPropertyDiffs.tsx

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import { SecretEventType, SecretTagType, SecretType } from '@/apollo/graphql'
22
import { areTagsAreSame } from '@/utils/tags'
33
import { Tag } from './SecretRow'
4+
import { FaRedoAlt, FaUndoAlt } from 'react-icons/fa'
5+
import { Button } from '../common/Button'
46

57
export const SecretPropertyDiffs = (props: {
68
secret: SecretType
79
historyItem: SecretEventType
810
index: number
11+
handlePropertyChange: Function
912
}) => {
10-
const { secret, historyItem, index } = props
13+
const { secret, historyItem, index, handlePropertyChange } = props
1114

1215
const previousItem = secret.history![index - 1]!
1316

@@ -25,6 +28,10 @@ export const SecretPropertyDiffs = (props: {
2528
return removedTags
2629
}
2730

31+
const handleRestoreValue = (value: string) => {
32+
handlePropertyChange(secret.id, 'value', value)
33+
}
34+
2835
return (
2936
<>
3037
{historyItem!.key !== previousItem.key && (
@@ -40,14 +47,26 @@ export const SecretPropertyDiffs = (props: {
4047
)}
4148

4249
{historyItem!.value !== previousItem.value && (
43-
<div className="pl-3 font-mono">
44-
<span className="text-neutral-500 mr-2">VALUE:</span>
45-
<s className="bg-red-200 dark:bg-red-950 text-red-500 ph-no-capture">
46-
{previousItem.value}
47-
</s>
48-
<span className="bg-emerald-100 dark:bg-emerald-950 text-emerald-500 ph-no-capture">
49-
{historyItem!.value}
50-
</span>
50+
<div className="pl-3 font-mono space-y-1">
51+
<div className="flex items-center gap-2">
52+
<span className="text-neutral-500 mr-2">VALUE:</span>
53+
</div>
54+
<div className="flex flex-col">
55+
<div className="flex items-center justify-between bg-red-200 dark:bg-red-950">
56+
<s className=" text-red-500 ph-no-capture">{previousItem.value}</s>
57+
<Button
58+
variant="outline"
59+
onClick={() => handleRestoreValue(previousItem.value)}
60+
title="Restore this value"
61+
>
62+
<FaRedoAlt />
63+
<span className="font-sans text-xs">Restore</span>
64+
</Button>
65+
</div>
66+
<span className="bg-emerald-100 dark:bg-emerald-950 text-emerald-500 ph-no-capture">
67+
{historyItem!.value}
68+
</span>
69+
</div>
5170
</div>
5271
)}
5372

frontend/components/environments/SecretRow.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,8 @@ const TagsDialog = (props: {
240240
)
241241
}
242242

243-
const HistoryDialog = (props: { secret: SecretType }) => {
244-
const { secret } = props
243+
const HistoryDialog = (props: { secret: SecretType; handlePropertyChange: Function }) => {
244+
const { secret, handlePropertyChange } = props
245245

246246
const [isOpen, setIsOpen] = useState<boolean>(false)
247247

@@ -358,6 +358,7 @@ const HistoryDialog = (props: { secret: SecretType }) => {
358358
secret={secret}
359359
historyItem={historyItem!}
360360
index={index}
361+
handlePropertyChange={handlePropertyChange}
361362
/>
362363
)}
363364
</div>
@@ -887,7 +888,7 @@ export default function SecretRow(props: {
887888
</div>
888889

889890
<div className="opacity-0 group-hover:opacity-100 transition-opacity ease">
890-
<HistoryDialog secret={secret} />
891+
<HistoryDialog secret={secret} handlePropertyChange={handlePropertyChange} />
891892
</div>
892893

893894
<div

0 commit comments

Comments
 (0)