From 1a55dff687b72eeb17597e0859707bcb83286007 Mon Sep 17 00:00:00 2001 From: Piyush Gupta Date: Thu, 9 Oct 2025 20:48:25 +0530 Subject: [PATCH] fix: tag editor modal --- .../tags/CreateTagModal/CreateTagModal.tsx | 18 +++++++++---- .../components/SecretListView/SecretItem.tsx | 6 ++--- .../SecretListView/SecretListView.tsx | 26 ++++++++++++++++++- 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/frontend/src/components/tags/CreateTagModal/CreateTagModal.tsx b/frontend/src/components/tags/CreateTagModal/CreateTagModal.tsx index d48b7d95f..75c240ffb 100644 --- a/frontend/src/components/tags/CreateTagModal/CreateTagModal.tsx +++ b/frontend/src/components/tags/CreateTagModal/CreateTagModal.tsx @@ -17,6 +17,7 @@ import { } from "@app/components/v2"; import { useProject } from "@app/context"; import { useCreateWsTag } from "@app/hooks/api"; +import { SecretV3RawSanitized, WsTag } from "@app/hooks/api/types"; import { slugSchema } from "@app/lib/schemas"; export const secretTagsColors = [ @@ -85,6 +86,8 @@ const isValidHexColor = (hexColor: string) => { type Props = { isOpen?: boolean; onToggle: (isOpen: boolean) => void; + append: (data: WsTag) => void; + currentSecret?: SecretV3RawSanitized; }; const createTagSchema = z.object({ @@ -100,7 +103,7 @@ type TagColor = { name: string; }; -export const CreateTagModal = ({ isOpen, onToggle }: Props): JSX.Element => { +export const CreateTagModal = ({ isOpen, onToggle, append, currentSecret }: Props): JSX.Element => { const { control, reset, @@ -128,11 +131,12 @@ export const CreateTagModal = ({ isOpen, onToggle }: Props): JSX.Element => { const onFormSubmit = async ({ slug, color }: FormData) => { try { - await createWsTag({ + const data = await createWsTag({ projectId, tagColor: color, tagSlug: slug }); + append(data); onToggle(false); reset(); createNotification({ @@ -151,8 +155,12 @@ export const CreateTagModal = ({ isOpen, onToggle }: Props): JSX.Element => { return (
{ isDisabled={isSubmitting} isLoading={isSubmitting} > - Create + {currentSecret ? "Create and Add" : "Create"} @@ -927,7 +927,7 @@ export const SecretItem = memo( className="h-3 w-3" /> } - onClick={onCreateTag} + onClick={() => onCreateTag(secret)} > Create a tag diff --git a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretListView.tsx b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretListView.tsx index 4fc314bdd..bd43e1271 100644 --- a/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretListView.tsx +++ b/frontend/src/pages/secret-manager/SecretDashboardPage/components/SecretListView/SecretListView.tsx @@ -465,6 +465,22 @@ export const SecretListView = ({ [environment, secretPath, isProtectedBranch, isBatchMode, projectId, addPendingChange] ); + // Function to append newly created tag to the current secret + const append = useCallback( + (newTag: WsTag) => { + const currentSecret = popUp.createTag.data as SecretV3RawSanitized; + if (!currentSecret) return; + + const updatedTags = [...(currentSecret.tags || []), { id: newTag.id, slug: newTag.slug }]; + + handleSaveSecret(currentSecret, { + ...currentSecret, + tags: updatedTags + }); + }, + [popUp.createTag.data, handleSaveSecret] + ); + const handleSecretDelete = useCallback(async () => { const { key, @@ -552,7 +568,13 @@ export const SecretListView = ({ ]); // for optimization on minimise re-rendering of secret items - const onCreateTag = useCallback(() => handlePopUpOpen("createTag"), []); + const onCreateTag = useCallback((secret?: SecretV3RawSanitized) => { + if (secret) { + handlePopUpOpen("createTag", secret); + } else { + handlePopUpOpen("createTag"); + } + }, []); const onDeleteSecret = useCallback( (sec: SecretV3RawSanitized) => handlePopUpOpen("deleteSecret", sec), [] @@ -640,6 +662,8 @@ export const SecretListView = ({ handlePopUpToggle("createTag", isOpen)} + append={append} + currentSecret={popUp.createTag.data} />