diff --git a/apps/platform/src/app/(main)/project/[project]/@variable/page.tsx b/apps/platform/src/app/(main)/project/[project]/@variable/page.tsx index 6338dd46..3c628736 100644 --- a/apps/platform/src/app/(main)/project/[project]/@variable/page.tsx +++ b/apps/platform/src/app/(main)/project/[project]/@variable/page.tsx @@ -33,11 +33,17 @@ import { ContextMenuTrigger } from '@/components/ui/context-menu' import EditVariableDialog from '@/components/ui/edit-variable-dialog' +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip' interface VariablePageProps { currentProject: Project | undefined } +interface EditVariableDetails { + variableName: string; + variableNote: string; +} + function VariablePage({ currentProject }: VariablePageProps): React.JSX.Element { @@ -49,6 +55,10 @@ function VariablePage({ const [isDeleteDialogOpen, setIsDeleteDialogOpen] = useState(false) const [isEditDialogOpen, setIsEditDialogOpen] = useState(false) const [selectedVariableSlug, setSelectedVariableSlug] = useState(null) + const [editVariableDetails, setEditVariableDetails] = useState({ + variableName: '', + variableNote: '', + }) //Environments table toggle logic const toggleSection = (id: string) => { @@ -65,25 +75,24 @@ function VariablePage({ const toggleDeleteDialog = (variableSlug: string) => { setIsDeleteDialogOpen(!isDeleteDialogOpen) - if( selectedVariableSlug === null ){ + if (selectedVariableSlug === null) { setSelectedVariableSlug(variableSlug) - } - else{ + } else { setSelectedVariableSlug(null) } } - const toggleEditDialog = (variableSlug: string) => { + const toggleEditDialog = (variableSlug: string, variableName: string, variableNote: string | null) => { setIsEditDialogOpen(!isEditDialogOpen) - if( selectedVariableSlug === null ){ + if (selectedVariableSlug === null) { setSelectedVariableSlug(variableSlug) - } - else{ + setEditVariableDetails({ variableName, variableNote: variableNote ?? '' }) + } else { setSelectedVariableSlug(null) + setEditVariableDetails({variableName: '', variableNote: ''}) } } - useEffect(() => { const getAllVariables = async () => { if (!currentProject) { @@ -154,7 +163,18 @@ function VariablePage({ {variable.variable.name} - + {variable.variable.note ? ( + + + + + + +

{variable.variable.note}

+
+
+
+ ) : null}
@@ -237,7 +257,7 @@ function VariablePage({ Show Version History toggleEditDialog(variable.variable.slug)} + onSelect={() => toggleEditDialog(variable.variable.slug, variable.variable.name, variable.variable.note)} className="h-[33%] w-[15.938rem] text-xs font-semibold tracking-wide" > Edit @@ -264,14 +284,15 @@ function VariablePage({ {/* Edit variable dialog */} {isEditDialogOpen && ( - toggleEditDialog('')} + //Passing empty strings just to bypass the error -- we don't need the arguments while closing the dialog + onClose={() => toggleEditDialog('', '', '')} variableSlug={selectedVariableSlug} + variableName={editVariableDetails.variableName} + variableNote={editVariableDetails.variableNote} /> )} -
)}
diff --git a/apps/platform/src/components/ui/edit-variable-dialog.tsx b/apps/platform/src/components/ui/edit-variable-dialog.tsx index 8b96cd13..96786072 100644 --- a/apps/platform/src/components/ui/edit-variable-dialog.tsx +++ b/apps/platform/src/components/ui/edit-variable-dialog.tsx @@ -1,102 +1,108 @@ 'use client' import { useState } from 'react' -import { Button } from "@/components/ui/button" -import { Input } from "@/components/ui/input" -import { Textarea } from "@/components/ui/textarea" -import { Label } from "@/components/ui/label" +import { Button } from '@/components/ui/button' +import { Input } from '@/components/ui/input' +import { Textarea } from '@/components/ui/textarea' +import { Label } from '@/components/ui/label' import { Dialog, DialogContent, DialogHeader, DialogTitle, - DialogDescription, -} from "@/components/ui/dialog" + DialogDescription +} from '@/components/ui/dialog' import { UpdateVariableRequest } from '@keyshade/schema' import ControllerInstance from '@/lib/controller-instance' import { toast } from 'sonner' function EditVariableDialog({ - isOpen, - onClose, - variableSlug + isOpen, + onClose, + variableSlug, + variableName, + variableNote, }: { - isOpen: boolean - onClose: () => void - variableSlug: string | null + isOpen: boolean + onClose: () => void + variableSlug: string | null + variableName: string + variableNote: string }) { - - const [variableName, setVariableName] = useState("") - const [extraNote, setExtraNote] = useState("") + const [newVariableName, setNewVariableName] = useState(variableName) + const [extraNote, setExtraNote] = useState(variableNote) const updateVariable = async () => { - - if( variableSlug === null ){ - return + if (variableSlug === null) { + return } const request: UpdateVariableRequest = { - variableSlug, - name: variableName === '' ? undefined : variableName, - note: extraNote === '' ? undefined : extraNote, - entries: undefined, + variableSlug, + name: newVariableName === variableName ? undefined : newVariableName, + note: extraNote === '' ? undefined : extraNote, + entries: undefined } - const { success, error } = await ControllerInstance.getInstance().variableController.updateVariable( + const { success, error } = + await ControllerInstance.getInstance().variableController.updateVariable( request, {} - ) + ) - if( success ){ - toast.success('Variable edited successfully', { - // eslint-disable-next-line react/no-unstable-nested-components -- we need to nest the description - description: () => ( -

- You successfully edited the variable -

- ) - }) + if (success) { + toast.success('Variable edited successfully', { + // eslint-disable-next-line react/no-unstable-nested-components -- we need to nest the description + description: () => ( +

+ You successfully edited the variable +

+ ) + }) } - if( error ){ - // eslint-disable-next-line no-console -- we need to log the error - console.error("Error while updating variable: ", error) + if (error) { + // eslint-disable-next-line no-console -- we need to log the error + console.error('Error while updating variable: ', error) } onClose() - } return (
- + - Edit this variable + + Edit this variable + Edit the variable name or the note
-
-