mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-06 13:27:22 +00:00
fix: tag editor modal
This commit is contained in:
@@ -17,6 +17,7 @@ import {
|
|||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
import { useProject } from "@app/context";
|
import { useProject } from "@app/context";
|
||||||
import { useCreateWsTag } from "@app/hooks/api";
|
import { useCreateWsTag } from "@app/hooks/api";
|
||||||
|
import { SecretV3RawSanitized, WsTag } from "@app/hooks/api/types";
|
||||||
import { slugSchema } from "@app/lib/schemas";
|
import { slugSchema } from "@app/lib/schemas";
|
||||||
|
|
||||||
export const secretTagsColors = [
|
export const secretTagsColors = [
|
||||||
@@ -85,6 +86,8 @@ const isValidHexColor = (hexColor: string) => {
|
|||||||
type Props = {
|
type Props = {
|
||||||
isOpen?: boolean;
|
isOpen?: boolean;
|
||||||
onToggle: (isOpen: boolean) => void;
|
onToggle: (isOpen: boolean) => void;
|
||||||
|
append: (data: WsTag) => void;
|
||||||
|
currentSecret?: SecretV3RawSanitized;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createTagSchema = z.object({
|
const createTagSchema = z.object({
|
||||||
@@ -100,7 +103,7 @@ type TagColor = {
|
|||||||
name: string;
|
name: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const CreateTagModal = ({ isOpen, onToggle }: Props): JSX.Element => {
|
export const CreateTagModal = ({ isOpen, onToggle, append, currentSecret }: Props): JSX.Element => {
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
reset,
|
reset,
|
||||||
@@ -128,11 +131,12 @@ export const CreateTagModal = ({ isOpen, onToggle }: Props): JSX.Element => {
|
|||||||
|
|
||||||
const onFormSubmit = async ({ slug, color }: FormData) => {
|
const onFormSubmit = async ({ slug, color }: FormData) => {
|
||||||
try {
|
try {
|
||||||
await createWsTag({
|
const data = await createWsTag({
|
||||||
projectId,
|
projectId,
|
||||||
tagColor: color,
|
tagColor: color,
|
||||||
tagSlug: slug
|
tagSlug: slug
|
||||||
});
|
});
|
||||||
|
append(data);
|
||||||
onToggle(false);
|
onToggle(false);
|
||||||
reset();
|
reset();
|
||||||
createNotification({
|
createNotification({
|
||||||
@@ -151,8 +155,12 @@ export const CreateTagModal = ({ isOpen, onToggle }: Props): JSX.Element => {
|
|||||||
return (
|
return (
|
||||||
<Modal isOpen={isOpen} onOpenChange={onToggle}>
|
<Modal isOpen={isOpen} onOpenChange={onToggle}>
|
||||||
<ModalContent
|
<ModalContent
|
||||||
title="Create tag"
|
title={currentSecret ? `Create tag for ${currentSecret.key}` : "Create tag"}
|
||||||
subTitle="Specify your tag name, and the slug will be created automatically."
|
subTitle={
|
||||||
|
currentSecret
|
||||||
|
? "Create a new tag and it will be automatically added to this secret."
|
||||||
|
: "Specify your tag name, and the slug will be created automatically."
|
||||||
|
}
|
||||||
>
|
>
|
||||||
<form onSubmit={handleSubmit(onFormSubmit)}>
|
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||||
<Controller
|
<Controller
|
||||||
@@ -253,7 +261,7 @@ export const CreateTagModal = ({ isOpen, onToggle }: Props): JSX.Element => {
|
|||||||
isDisabled={isSubmitting}
|
isDisabled={isSubmitting}
|
||||||
isLoading={isSubmitting}
|
isLoading={isSubmitting}
|
||||||
>
|
>
|
||||||
Create
|
{currentSecret ? "Create and Add" : "Create"}
|
||||||
</Button>
|
</Button>
|
||||||
<ModalClose asChild>
|
<ModalClose asChild>
|
||||||
<Button variant="plain" colorSchema="secondary">
|
<Button variant="plain" colorSchema="secondary">
|
||||||
|
|||||||
+3
-3
@@ -79,7 +79,7 @@ type Props = {
|
|||||||
isSelected?: boolean;
|
isSelected?: boolean;
|
||||||
onToggleSecretSelect: (secret: SecretV3RawSanitized) => void;
|
onToggleSecretSelect: (secret: SecretV3RawSanitized) => void;
|
||||||
tags: WsTag[];
|
tags: WsTag[];
|
||||||
onCreateTag: () => void;
|
onCreateTag: (secret?: SecretV3RawSanitized) => void;
|
||||||
environment: string;
|
environment: string;
|
||||||
secretPath: string;
|
secretPath: string;
|
||||||
onShareSecret: (sec: SecretV3RawSanitized) => void;
|
onShareSecret: (sec: SecretV3RawSanitized) => void;
|
||||||
@@ -734,7 +734,7 @@ export const SecretItem = memo(
|
|||||||
className="h-3 w-3"
|
className="h-3 w-3"
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
onClick={onCreateTag}
|
onClick={() => onCreateTag(secret)}
|
||||||
>
|
>
|
||||||
Create a tag
|
Create a tag
|
||||||
</Button>
|
</Button>
|
||||||
@@ -927,7 +927,7 @@ export const SecretItem = memo(
|
|||||||
className="h-3 w-3"
|
className="h-3 w-3"
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
onClick={onCreateTag}
|
onClick={() => onCreateTag(secret)}
|
||||||
>
|
>
|
||||||
Create a tag
|
Create a tag
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
+25
-1
@@ -465,6 +465,22 @@ export const SecretListView = ({
|
|||||||
[environment, secretPath, isProtectedBranch, isBatchMode, projectId, addPendingChange]
|
[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 handleSecretDelete = useCallback(async () => {
|
||||||
const {
|
const {
|
||||||
key,
|
key,
|
||||||
@@ -552,7 +568,13 @@ export const SecretListView = ({
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// for optimization on minimise re-rendering of secret items
|
// 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(
|
const onDeleteSecret = useCallback(
|
||||||
(sec: SecretV3RawSanitized) => handlePopUpOpen("deleteSecret", sec),
|
(sec: SecretV3RawSanitized) => handlePopUpOpen("deleteSecret", sec),
|
||||||
[]
|
[]
|
||||||
@@ -640,6 +662,8 @@ export const SecretListView = ({
|
|||||||
<CreateTagModal
|
<CreateTagModal
|
||||||
isOpen={popUp.createTag.isOpen}
|
isOpen={popUp.createTag.isOpen}
|
||||||
onToggle={(isOpen) => handlePopUpToggle("createTag", isOpen)}
|
onToggle={(isOpen) => handlePopUpToggle("createTag", isOpen)}
|
||||||
|
append={append}
|
||||||
|
currentSecret={popUp.createTag.data}
|
||||||
/>
|
/>
|
||||||
<AddShareSecretModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
<AddShareSecretModal popUp={popUp} handlePopUpToggle={handlePopUpToggle} />
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user