mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 16:27:40 +00:00
Feat: added tag color widgt and changed tag popover design
This commit is contained in:
@@ -3203,6 +3203,9 @@
|
|||||||
"name": {
|
"name": {
|
||||||
"example": "any"
|
"example": "any"
|
||||||
},
|
},
|
||||||
|
"tagColor": {
|
||||||
|
"example": "any"
|
||||||
|
},
|
||||||
"slug": {
|
"slug": {
|
||||||
"example": "any"
|
"example": "any"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ import { BadRequestError, UnauthorizedRequestError } from "../../utils/errors";
|
|||||||
|
|
||||||
export const createWorkspaceTag = async (req: Request, res: Response) => {
|
export const createWorkspaceTag = async (req: Request, res: Response) => {
|
||||||
const { workspaceId } = req.params;
|
const { workspaceId } = req.params;
|
||||||
const { name, slug } = req.body;
|
const { name, slug, tagColor } = req.body;
|
||||||
|
|
||||||
const tagToCreate = {
|
const tagToCreate = {
|
||||||
name,
|
name,
|
||||||
|
tagColor,
|
||||||
workspace: new Types.ObjectId(workspaceId),
|
workspace: new Types.ObjectId(workspaceId),
|
||||||
slug,
|
slug,
|
||||||
user: new Types.ObjectId(req.user._id),
|
user: new Types.ObjectId(req.user._id),
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import { Schema, Types, model } from "mongoose";
|
|||||||
export interface ITag {
|
export interface ITag {
|
||||||
_id: Types.ObjectId;
|
_id: Types.ObjectId;
|
||||||
name: string;
|
name: string;
|
||||||
|
tagColor: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
user: Types.ObjectId;
|
user: Types.ObjectId;
|
||||||
workspace: Types.ObjectId;
|
workspace: Types.ObjectId;
|
||||||
@@ -15,6 +16,11 @@ const tagSchema = new Schema<ITag>(
|
|||||||
required: true,
|
required: true,
|
||||||
trim: true,
|
trim: true,
|
||||||
},
|
},
|
||||||
|
tagColor: {
|
||||||
|
type: String,
|
||||||
|
required: false,
|
||||||
|
trim: true,
|
||||||
|
},
|
||||||
slug: {
|
slug: {
|
||||||
type: String,
|
type: String,
|
||||||
required: true,
|
required: true,
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ router.post(
|
|||||||
}),
|
}),
|
||||||
param("workspaceId").exists().trim(),
|
param("workspaceId").exists().trim(),
|
||||||
body("name").exists().trim(),
|
body("name").exists().trim(),
|
||||||
|
body("tagColor").exists().trim(),
|
||||||
body("slug").exists().trim(),
|
body("slug").exists().trim(),
|
||||||
validateRequest,
|
validateRequest,
|
||||||
tagController.createWorkspaceTag
|
tagController.createWorkspaceTag
|
||||||
|
|||||||
@@ -1949,6 +1949,8 @@ paths:
|
|||||||
properties:
|
properties:
|
||||||
name:
|
name:
|
||||||
example: any
|
example: any
|
||||||
|
tagColor:
|
||||||
|
example: any
|
||||||
slug:
|
slug:
|
||||||
example: any
|
example: any
|
||||||
/api/v2/workspace/tags/{tagId}:
|
/api/v2/workspace/tags/{tagId}:
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
export const isValidHexColor = (hexColor: string) => {
|
||||||
|
const hexColorPattern = /^#?([0-9A-Fa-f]{3}|[0-9A-Fa-f]{6})$/;
|
||||||
|
|
||||||
|
return hexColorPattern.test(hexColor);
|
||||||
|
}
|
||||||
@@ -11,10 +11,11 @@ type Props = {
|
|||||||
color?: string;
|
color?: string;
|
||||||
styles?: Record<string, string>
|
styles?: Record<string, string>
|
||||||
isDisabled?: boolean;
|
isDisabled?: boolean;
|
||||||
|
tagColor: string;
|
||||||
} & VariantProps<typeof tagVariants>;
|
} & VariantProps<typeof tagVariants>;
|
||||||
|
|
||||||
const tagVariants = cva(
|
const tagVariants = cva(
|
||||||
"inline-flex items-center whitespace-nowrap text-sm rounded-sm mr-1.5 text-bunker-200",
|
"inline-flex items-center whitespace-nowrap text-sm rounded-sm mr-1.5 text-bunker-200 rounded-[30px] text-gray-400 ",
|
||||||
{
|
{
|
||||||
variants: {
|
variants: {
|
||||||
colorSchema: {
|
colorSchema: {
|
||||||
@@ -41,18 +42,7 @@ export const Tag = ({
|
|||||||
}: Props) => (
|
}: Props) => (
|
||||||
<div
|
<div
|
||||||
className={twMerge(tagVariants({ colorSchema, className, size }))}
|
className={twMerge(tagVariants({ colorSchema, className, size }))}
|
||||||
style={{ backgroundColor: color, ...styles }}
|
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
{onClose && (
|
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
onClick={onClose}
|
|
||||||
disabled={isDisabled}
|
|
||||||
className="ml-2 flex items-center justify-center"
|
|
||||||
>
|
|
||||||
<FontAwesomeIcon icon={faClose} />
|
|
||||||
</button>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -51,3 +51,69 @@ const plansProd: Mapping = {
|
|||||||
export const plans = plansProd || plansDev;
|
export const plans = plansProd || plansDev;
|
||||||
|
|
||||||
export const leaveConfirmDefaultMessage = "Your changes will be lost if you leave the page. Are you sure you want to continue?";
|
export const leaveConfirmDefaultMessage = "Your changes will be lost if you leave the page. Are you sure you want to continue?";
|
||||||
|
|
||||||
|
export const secretTagsColors = [
|
||||||
|
{
|
||||||
|
id: 1,
|
||||||
|
hex: '#bec2c8',
|
||||||
|
rgba: "rgb(128,128,128, 0.8)",
|
||||||
|
name: 'Grey',
|
||||||
|
selected: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2,
|
||||||
|
hex: '#95a2b3',
|
||||||
|
rgba: "rgb(0,0,255, 0.8)",
|
||||||
|
name: 'blue',
|
||||||
|
selected: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 3,
|
||||||
|
hex: '#5e6ad2',
|
||||||
|
rgba: "rgb(128,0,128, 0.8)",
|
||||||
|
name: 'Purple',
|
||||||
|
selected: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 4,
|
||||||
|
hex: '#26b5ce',
|
||||||
|
rgba: "rgb(0,128,128, 0.8)",
|
||||||
|
name: 'Teal',
|
||||||
|
selected: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 5,
|
||||||
|
hex: '#4cb782',
|
||||||
|
rgba: "rgb(0,128,0, 0.8)",
|
||||||
|
name: 'Green',
|
||||||
|
selected: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 6,
|
||||||
|
hex: '#f2c94c',
|
||||||
|
rgba: "rgb(255,255,0, 0.8)",
|
||||||
|
name: 'Yellow',
|
||||||
|
selected: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 7,
|
||||||
|
hex: '#f2994a',
|
||||||
|
rgba: "rgb(128,128,0, 0.8)",
|
||||||
|
name: 'Orange',
|
||||||
|
selected: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 8,
|
||||||
|
hex: '#f7c8c1',
|
||||||
|
rgba: "rgb(128,0,0, 0.8)",
|
||||||
|
name: 'Pink',
|
||||||
|
selected: false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 9,
|
||||||
|
hex: '#eb5757',
|
||||||
|
rgba: "rgb(255,0,0, 0.8)",
|
||||||
|
name: 'Red',
|
||||||
|
selected: false
|
||||||
|
},
|
||||||
|
]
|
||||||
@@ -7,7 +7,9 @@ import {
|
|||||||
CreateTagRes,
|
CreateTagRes,
|
||||||
DeleteTagDTO,
|
DeleteTagDTO,
|
||||||
DeleteWsTagRes,
|
DeleteWsTagRes,
|
||||||
UserWsTags
|
QueryTag,
|
||||||
|
UserWsTags,
|
||||||
|
WsTag
|
||||||
} from "./types";
|
} from "./types";
|
||||||
|
|
||||||
const workspaceTags = {
|
const workspaceTags = {
|
||||||
@@ -34,14 +36,15 @@ export const useCreateWsTag = () => {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation<CreateTagRes, {}, CreateTagDTO>({
|
return useMutation<CreateTagRes, {}, CreateTagDTO>({
|
||||||
mutationFn: async ({ workspaceID, tagName, tagSlug }) => {
|
mutationFn: async ({ workspaceID, tagName, tagColor, tagSlug }: QueryTag) => {
|
||||||
const { data } = await apiRequest.post(`/api/v2/workspace/${workspaceID}/tags`, {
|
const { data } = await apiRequest.post(`/api/v2/workspace/${workspaceID}/tags`, {
|
||||||
name: tagName,
|
name: tagName,
|
||||||
|
tagColor: tagColor,
|
||||||
slug: tagSlug
|
slug: tagSlug
|
||||||
})
|
})
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
onSuccess: (tagData) => {
|
onSuccess: (tagData: WsTag) => {
|
||||||
queryClient.invalidateQueries(workspaceTags.getWsTags(tagData?.workspace));
|
queryClient.invalidateQueries(workspaceTags.getWsTags(tagData?.workspace));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -51,11 +54,11 @@ export const useDeleteWsTag = () => {
|
|||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
return useMutation<DeleteWsTagRes, {}, DeleteTagDTO>({
|
return useMutation<DeleteWsTagRes, {}, DeleteTagDTO>({
|
||||||
mutationFn: async ({ tagID }) => {
|
mutationFn: async ({ tagID }: {tagID: string}) => {
|
||||||
const { data } = await apiRequest.delete(`/api/v2/workspace/tags/${tagID}`);
|
const { data } = await apiRequest.delete(`/api/v2/workspace/tags/${tagID}`);
|
||||||
return data
|
return data
|
||||||
},
|
},
|
||||||
onSuccess: (tagData) => {
|
onSuccess: (tagData: WsTag) => {
|
||||||
queryClient.invalidateQueries(workspaceTags.getWsTags(tagData?.workspace));
|
queryClient.invalidateQueries(workspaceTags.getWsTags(tagData?.workspace));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -38,15 +38,24 @@ export type DeleteWsTagRes = {
|
|||||||
_id: string;
|
_id: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type TagDesign = {
|
|
||||||
tagBackground: string;
|
|
||||||
tagLabel: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SecretTags = {
|
export type SecretTags = {
|
||||||
id: string;
|
id: string;
|
||||||
_id: string;
|
_id: string;
|
||||||
slug: string;
|
slug: string;
|
||||||
tagBackground: string;
|
tagColor: string;
|
||||||
tagLabel: string
|
}
|
||||||
|
|
||||||
|
export type TagColor = {
|
||||||
|
id: number;
|
||||||
|
hex: string
|
||||||
|
rgba: string
|
||||||
|
name: string
|
||||||
|
selected: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
export type QueryTag = {
|
||||||
|
workspaceID: string;
|
||||||
|
tagName: string;
|
||||||
|
tagColor: string;
|
||||||
|
tagSlug: string
|
||||||
}
|
}
|
||||||
@@ -107,6 +107,31 @@
|
|||||||
@apply bg-primary-400;
|
@apply bg-primary-400;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.tags-conic-bg {
|
||||||
|
background: conic-gradient(rgb(235, 87, 87), rgb(242, 201, 76), rgb(76, 183, 130), rgb(78, 167, 252), rgb(250, 96, 122));
|
||||||
|
}
|
||||||
|
|
||||||
|
.show-tags {
|
||||||
|
transform: translateY(10px);
|
||||||
|
transition: all 0.2s;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.hide-tags {
|
||||||
|
transform: translateY(-20px);
|
||||||
|
transition: all 0.2s;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.show-hex-input {
|
||||||
|
transform: translateY(-33px);
|
||||||
|
transition: all 0.2s;
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
.hide-hex-input {
|
||||||
|
transform: translateY(20px);
|
||||||
|
transition: all 0.2s;
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
@import "@fontsource/inter/400.css";
|
@import "@fontsource/inter/400.css";
|
||||||
@import "@fontsource/inter/500.css";
|
@import "@fontsource/inter/500.css";
|
||||||
|
|||||||
@@ -513,11 +513,12 @@ export const DashboardPage = () => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const onCreateWsTag = useCallback(
|
const onCreateWsTag = useCallback(
|
||||||
async (tagName: string) => {
|
async (tagName: string, tagColor: string) => {
|
||||||
try {
|
try {
|
||||||
await createWsTag({
|
await createWsTag({
|
||||||
workspaceID: workspaceId,
|
workspaceID: workspaceId,
|
||||||
tagName,
|
tagName,
|
||||||
|
tagColor,
|
||||||
tagSlug: tagName.replace(" ", "_")
|
tagSlug: tagName.replace(" ", "_")
|
||||||
});
|
});
|
||||||
handlePopUpClose("addTag");
|
handlePopUpClose("addTag");
|
||||||
|
|||||||
@@ -1,11 +1,21 @@
|
|||||||
|
import { useState, useEffect } from 'react';
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { yupResolver } from "@hookform/resolvers/yup";
|
import { yupResolver } from "@hookform/resolvers/yup";
|
||||||
import * as yup from "yup";
|
import * as yup from "yup";
|
||||||
|
import { secretTagsColors } from "~/const"
|
||||||
|
import {
|
||||||
|
faCheck
|
||||||
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
|
|
||||||
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||||
|
|
||||||
|
import { Button, FormControl, Input, ModalClose, Tooltip } from "@app/components/v2";
|
||||||
|
import { isValidHexColor } from "~/components/utilities/isValidHexColor";
|
||||||
|
import { TagColor } from '~/hooks/api/tags/types';
|
||||||
|
|
||||||
import { Button, FormControl, Input, ModalClose } from "@app/components/v2";
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
onCreateTag: (tagName: string) => Promise<void>;
|
onCreateTag: (tagName: string, tagColor: string) => Promise<void>;
|
||||||
};
|
};
|
||||||
|
|
||||||
const createTagSchema = yup.object({
|
const createTagSchema = yup.object({
|
||||||
@@ -23,33 +33,151 @@ export const CreateTagModal = ({ onCreateTag }: Props): JSX.Element => {
|
|||||||
resolver: yupResolver(createTagSchema)
|
resolver: yupResolver(createTagSchema)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [tagsColors, setTagsColors] = useState<TagColor>(secretTagsColors)
|
||||||
|
const [selectedTagColor, setSelectedTagColor] = useState<TagColor>({})
|
||||||
|
const [showHexInput, setShowHexInput] = useState<boolean>(false)
|
||||||
|
const [tagColor, setTagColor] = useState<string>("")
|
||||||
|
|
||||||
|
|
||||||
const onFormSubmit = async ({ name }: FormData) => {
|
const onFormSubmit = async ({ name }: FormData) => {
|
||||||
await onCreateTag(name);
|
await onCreateTag(name, tagColor);
|
||||||
reset();
|
reset();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const clonedTagColors = [...tagsColors]
|
||||||
|
for (const tagColor of clonedTagColors) {
|
||||||
|
if (tagColor.selected) {
|
||||||
|
setSelectedTagColor(tagColor)
|
||||||
|
setTagColor(tagColor.hex)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const tagsList = document.querySelector(".secret-tags-wrapper")
|
||||||
|
const tagsHexWrapper = document.querySelector(".tags-hex-wrapper")
|
||||||
|
|
||||||
|
if (showHexInput) {
|
||||||
|
tagsList?.classList.add('hide-tags')
|
||||||
|
tagsList?.classList.remove('show-tags')
|
||||||
|
tagsHexWrapper?.classList.add('show-hex-input')
|
||||||
|
tagsHexWrapper?.classList.remove('hide-hex-input')
|
||||||
|
} else {
|
||||||
|
tagsList?.classList.remove('hide-tags')
|
||||||
|
tagsList?.classList.add('show-tags')
|
||||||
|
tagsHexWrapper?.classList.remove('show-hex-input')
|
||||||
|
tagsHexWrapper?.classList.add('hide-hex-input')
|
||||||
|
}
|
||||||
|
}, [showHexInput])
|
||||||
|
|
||||||
|
const handleColorChange = (tagColor: TagColor) => {
|
||||||
|
const clonedTagColors = [...tagsColors]
|
||||||
|
const tagColorIndex = clonedTagColors.findIndex(_tagColor => _tagColor.id === tagColor.id)
|
||||||
|
const _selectedTagColor = clonedTagColors[tagColorIndex]
|
||||||
|
clonedTagColors.forEach(tagColor => {
|
||||||
|
tagColor.selected = false
|
||||||
|
})
|
||||||
|
if (selectedTagColor.id !== tagColor.id) {
|
||||||
|
_selectedTagColor.selected = !_selectedTagColor.selected
|
||||||
|
setSelectedTagColor(_selectedTagColor)
|
||||||
|
setTagColor(_selectedTagColor.hex)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<form onSubmit={handleSubmit(onFormSubmit)}>
|
<>
|
||||||
<Controller
|
<form onSubmit={handleSubmit(onFormSubmit)}>
|
||||||
control={control}
|
<Controller
|
||||||
name="name"
|
control={control}
|
||||||
defaultValue=""
|
name="name"
|
||||||
render={({ field, fieldState: { error } }) => (
|
defaultValue=""
|
||||||
<FormControl label="Tag Name" isError={Boolean(error)} errorText={error?.message}>
|
render={({ field, fieldState: { error } }) => (
|
||||||
<Input {...field} placeholder="Type your tag name" />
|
<FormControl label="Tag Name" isError={Boolean(error)} errorText={error?.message}>
|
||||||
</FormControl>
|
<Input {...field} placeholder="Type your tag name" />
|
||||||
)}
|
</FormControl>
|
||||||
/>
|
)}
|
||||||
<div className="mt-8 flex items-center">
|
/>
|
||||||
<Button className="mr-4" type="submit" isDisabled={isSubmitting} isLoading={isSubmitting}>
|
|
||||||
Create
|
<div className="mt-2">
|
||||||
</Button>
|
<label className="text-mineshaft-400">Tag color</label>
|
||||||
<ModalClose asChild>
|
<div className="flex gap-2 h-[50px]">
|
||||||
<Button variant="plain" colorSchema="secondary">
|
<div className="w-[12%] h-[2.813rem] inline-flex font-inter items-center justify-center border relative rounded-md border-mineshaft-500 bg-mineshaft-900 hover:bg-mineshaft-800">
|
||||||
Cancel
|
<div className={`w-[26px] h-[26px] rounded-full`} style={{ background: `${tagColor}` }}></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="w-[88%] h-[2.813rem] flex-wrap inline-flex gap-3 items-center border relative rounded-md border-mineshaft-500 bg-mineshaft-900 hover:bg-mineshaft-800 relative">
|
||||||
|
{
|
||||||
|
(
|
||||||
|
<div className="flex-wrap inline-flex gap-3 items-center secret-tags-wrapper pl-3">
|
||||||
|
{
|
||||||
|
tagsColors.map((tagColor: TagColor) => {
|
||||||
|
return (
|
||||||
|
<Tooltip content={`${tagColor.name}`}>
|
||||||
|
<div className={`flex items-center justify-center w-[26px] h-[26px] hover:ring-offset-2 hover:ring-2 bg-[#bec2c8] border-2 p-2 hover:shadow-lg border-transparent hover:border-black rounded-full`} key={`tag-${tagColor.id}`} style={{ backgroundColor: `${tagColor.hex}` }} onClick={() => handleColorChange(tagColor)}>
|
||||||
|
{
|
||||||
|
tagColor.selected && <FontAwesomeIcon icon={faCheck} style={{ color: `#00000070` }} />
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</Tooltip>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
<div className="flex items-center gap-2 px-2 tags-hex-wrapper" >
|
||||||
|
<div className="w-1/6 flex items-center relative rounded-md hover:bg-mineshaft-800">
|
||||||
|
{
|
||||||
|
isValidHexColor(tagColor) && (
|
||||||
|
<div className={`w-[26px] h-[26px] rounded-full flex items-center justify-center`} style={{ background: `${tagColor}` }}>
|
||||||
|
<FontAwesomeIcon icon={faCheck} style={{ color: `#00000070` }} />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
!isValidHexColor(tagColor) && (
|
||||||
|
<div class="border-dashed border bg-blue rounded-full w-[26px] h-[26px] border-mineshaft-500"></div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div className="w-10/12">
|
||||||
|
<Input
|
||||||
|
variant="plain"
|
||||||
|
className="w-full focus:text-bunker-100 focus:ring-transparent bg-transparent"
|
||||||
|
autoCapitalization={false}
|
||||||
|
value={tagColor}
|
||||||
|
onChange={(e: React.ChangeEvent<HTMLInputElement>) => setTagColor(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="w-[26px] h-[26px] flex items-center justify-center absolute top-[10px] right-[-4px] translate-x-[-50%]">
|
||||||
|
<div className="border-mineshaft-500 border h-[2.1rem] mr-4 absolute right-5"></div>
|
||||||
|
<div className={`flex items-center justify-center w-[26px] h-[26px] bg-transparent cursor-pointer hover:ring-offset-1 hover:ring-2 border-mineshaft-500 border bg-mineshaft-900 rounded-[3px] p-2 ${showHexInput ? 'tags-conic-bg rounded-full' : ''}`} onClick={() => setShowHexInput((prev) => !prev)} style={{ border: '1px solid rgba(220, 216, 254, 0.376)' }}>
|
||||||
|
{
|
||||||
|
!showHexInput && <span>#</span>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="mt-8 flex items-center">
|
||||||
|
<Button className="mr-4" type="submit" isDisabled={isSubmitting} isLoading={isSubmitting}>
|
||||||
|
Create
|
||||||
</Button>
|
</Button>
|
||||||
</ModalClose>
|
<ModalClose asChild>
|
||||||
</div>
|
<Button variant="plain" colorSchema="secondary">
|
||||||
</form>
|
Cancel
|
||||||
|
</Button>
|
||||||
|
</ModalClose>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -46,9 +46,8 @@ import {
|
|||||||
import { WsTag } from "@app/hooks/api/types";
|
import { WsTag } from "@app/hooks/api/types";
|
||||||
|
|
||||||
import { FormData, SecretActionType } from "../../DashboardPage.utils";
|
import { FormData, SecretActionType } from "../../DashboardPage.utils";
|
||||||
import { SecretTags, TagDesign } from "~/hooks/api/tags/types";
|
import { SecretTags } from "~/hooks/api/tags/types";
|
||||||
import { DesignTagModal } from "../../components/DesignTagModal";
|
import { useToggle } from "@app/hooks";
|
||||||
import { useLeaveConfirm, usePopUp, useToggle } from "@app/hooks";
|
|
||||||
|
|
||||||
const tagColors = [
|
const tagColors = [
|
||||||
{ bg: "bg-[#f1c40f]/40", text: "text-[#fcf0c3]/70" },
|
{ bg: "bg-[#f1c40f]/40", text: "text-[#fcf0c3]/70" },
|
||||||
@@ -86,9 +85,6 @@ type Props = {
|
|||||||
isKeyError?: boolean;
|
isKeyError?: boolean;
|
||||||
keyError?: string;
|
keyError?: string;
|
||||||
autoCapitalization?: boolean;
|
autoCapitalization?: boolean;
|
||||||
designObj: TagDesign & WsTag;
|
|
||||||
updateDesign: boolean;
|
|
||||||
selectedFieldIndex: number
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const SecretInputRow = memo(
|
export const SecretInputRow = memo(
|
||||||
@@ -102,7 +98,6 @@ export const SecretInputRow = memo(
|
|||||||
wsTags,
|
wsTags,
|
||||||
onCreateTagOpen,
|
onCreateTagOpen,
|
||||||
onDesignTagOpen,
|
onDesignTagOpen,
|
||||||
designObj,
|
|
||||||
onSecretDelete,
|
onSecretDelete,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
control,
|
control,
|
||||||
@@ -112,8 +107,6 @@ export const SecretInputRow = memo(
|
|||||||
keyError,
|
keyError,
|
||||||
secUniqId,
|
secUniqId,
|
||||||
autoCapitalization,
|
autoCapitalization,
|
||||||
updateDesign,
|
|
||||||
selectedFieldIndex
|
|
||||||
}: Props): JSX.Element => {
|
}: Props): JSX.Element => {
|
||||||
const isKeySubDisabled = useRef<boolean>(false);
|
const isKeySubDisabled = useRef<boolean>(false);
|
||||||
// comment management in a row
|
// comment management in a row
|
||||||
@@ -160,12 +153,10 @@ export const SecretInputRow = memo(
|
|||||||
overrideAction === SecretActionType.Created || overrideAction === SecretActionType.Modified;
|
overrideAction === SecretActionType.Created || overrideAction === SecretActionType.Modified;
|
||||||
|
|
||||||
const [editorRef, setEditorRef] = useState(isOverridden ? secValueOverride : secValue);
|
const [editorRef, setEditorRef] = useState(isOverridden ? secValueOverride : secValue);
|
||||||
const [tagDesignObj, setTagDesignObj] = useState<TagDesign & WsTag>({})
|
|
||||||
const [selectedTag, setSelectedTag] = useState<WsTag>({})
|
|
||||||
|
|
||||||
const secId = useWatch({ control, name: `secrets.${index}._id`, exact: true });
|
const secId = useWatch({ control, name: `secrets.${index}._id`, exact: true });
|
||||||
const tags =
|
const tags = useWatch({ control, name: `secrets.${index}.tags`, exact: true, defaultValue: [] }) || [];
|
||||||
useWatch({ control, name: `secrets.${index}.tags`, exact: true, defaultValue: [] }) || [];
|
|
||||||
const selectedTagIds = tags.reduce<Record<string, boolean>>(
|
const selectedTagIds = tags.reduce<Record<string, boolean>>(
|
||||||
(prev, curr) => ({ ...prev, [curr.slug]: true }),
|
(prev, curr) => ({ ...prev, [curr.slug]: true }),
|
||||||
{}
|
{}
|
||||||
@@ -190,20 +181,6 @@ export const SecretInputRow = memo(
|
|||||||
setInviteLinkCopied.on();
|
setInviteLinkCopied.on();
|
||||||
};
|
};
|
||||||
|
|
||||||
const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp([
|
|
||||||
"secretDetails",
|
|
||||||
"addTag",
|
|
||||||
"secretSnapshots",
|
|
||||||
"uploadedSecOpts",
|
|
||||||
"compareSecrets",
|
|
||||||
"folderForm",
|
|
||||||
"deleteFolder",
|
|
||||||
"upgradePlan",
|
|
||||||
"addSecretImport",
|
|
||||||
"deleteSecretImport",
|
|
||||||
"designTag"
|
|
||||||
] as const);
|
|
||||||
|
|
||||||
const onSecretOverride = () => {
|
const onSecretOverride = () => {
|
||||||
if (isOverridden) {
|
if (isOverridden) {
|
||||||
// when user created a new override but then removes
|
// when user created a new override but then removes
|
||||||
@@ -223,23 +200,14 @@ export const SecretInputRow = memo(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const onSelectTag = (selectedTag: WsTag) => {
|
const onSelectTag = (selectedTag: WsTag) => {
|
||||||
const checkBoxSelected = !selectedTagIds[selectedTag.slug]
|
|
||||||
checkBoxSelected && handlePopUpOpen('designTag')
|
|
||||||
setSelectedTag(selectedTag)
|
|
||||||
};
|
|
||||||
|
|
||||||
const onDesignWsTag = (_tagDesignObj: TagDesign) => {
|
|
||||||
setTagDesignObj(() => (_tagDesignObj))
|
|
||||||
handlePopUpClose("designTag");
|
|
||||||
const shouldAppend = !selectedTagIds[selectedTag.slug];
|
const shouldAppend = !selectedTagIds[selectedTag.slug];
|
||||||
if (shouldAppend) {
|
if (shouldAppend) {
|
||||||
append({...selectedTag, ..._tagDesignObj});
|
append(selectedTag);
|
||||||
} else {
|
} else {
|
||||||
const pos = tags.findIndex(({ slug }: {slug: string}) => selectedTag.slug === slug);
|
const pos = tags.findIndex(({ slug }: { slug: string }) => selectedTag.slug === slug);
|
||||||
remove(pos);
|
remove(pos);
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
const isCreatedSecret = !secId;
|
const isCreatedSecret = !secId;
|
||||||
const shouldBeBlockedInAddOnly = !isCreatedSecret && isAddOnly;
|
const shouldBeBlockedInAddOnly = !isCreatedSecret && isAddOnly;
|
||||||
|
|
||||||
@@ -261,27 +229,13 @@ export const SecretInputRow = memo(
|
|||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tr className="group flex flex-row hover:bg-mineshaft-700" key={index}>
|
<tr className="group flex flex-row hover:bg-mineshaft-700" key={index}>
|
||||||
<td className="flex h-10 w-10 items-center justify-center border-none px-4">
|
<td className="flex h-10 w-10 items-center justify-center border-none px-4">
|
||||||
<div className="w-10 text-center text-xs text-bunker-400">{index + 1}</div>
|
<div className="w-10 text-center text-xs text-bunker-400">{index + 1}</div>
|
||||||
</td>
|
</td>
|
||||||
{/* Add a custom design to new tag to make visible */}
|
|
||||||
<Modal
|
|
||||||
isOpen={popUp?.designTag?.isOpen}
|
|
||||||
onOpenChange={(open: boolean) => {
|
|
||||||
handlePopUpToggle("designTag", open);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<ModalContent
|
|
||||||
title={`Customise design for ${selectedTag.slug}`}
|
|
||||||
subTitle="Choose custom background and label text colors for the tag."
|
|
||||||
>
|
|
||||||
<DesignTagModal selectedTag={selectedTag} onDesignTag={onDesignWsTag} />
|
|
||||||
</ModalContent>
|
|
||||||
</Modal>
|
|
||||||
|
|
||||||
<Controller
|
<Controller
|
||||||
control={control}
|
control={control}
|
||||||
@@ -381,25 +335,68 @@ export const SecretInputRow = memo(
|
|||||||
</td>
|
</td>
|
||||||
<td className="min-w-sm flex">
|
<td className="min-w-sm flex">
|
||||||
<div className="flex h-8 items-center pl-2">
|
<div className="flex h-8 items-center pl-2">
|
||||||
{secretTags.map(({ id, _id, slug, tagBackground, tagLabel }: SecretTags, i: number) => {
|
{secretTags.map(({ id, _id, slug, tagColor }: SecretTags, i: number) => {
|
||||||
// This map lookup shouldn't ever fail, but if it does we default to the first color
|
|
||||||
const tagColor = tagColorByTagId.get(_id) || tagColors[0]
|
|
||||||
return (
|
return (
|
||||||
<Tag
|
<Popover>
|
||||||
className={cx(
|
<PopoverTrigger asChild>
|
||||||
tagColor.bg,
|
<div>
|
||||||
tagColor.text
|
<Tag
|
||||||
)}
|
isDisabled={isReadOnly || isAddOnly || isRollbackMode}
|
||||||
styles={{
|
onClose={() => remove(i)}
|
||||||
backgroundColor: tagBackground,
|
key={id}
|
||||||
color: tagLabel
|
className="cursor-pointer"
|
||||||
}}
|
>
|
||||||
isDisabled={isReadOnly || isAddOnly || isRollbackMode}
|
<div className="rounded-md rounded-full border-mineshaft-500 bg-transparent flex items-center gap-1.5 justify-around">
|
||||||
onClose={() => remove(i)}
|
<div className="w-[10px] h-[10px] rounded-full" style={{ background: tagColor ? tagColor : "#bec2c8" }}></div>
|
||||||
key={id}
|
{slug}
|
||||||
>
|
</div>
|
||||||
{slug}
|
|
||||||
</Tag>)
|
</Tag>
|
||||||
|
</div>
|
||||||
|
</PopoverTrigger>
|
||||||
|
<PopoverContent
|
||||||
|
side="left"
|
||||||
|
className="max-h-96 w-auto min-w-[200px] p-2 overflow-y-auto overflow-x-hidden border border-mineshaft-600 bg-mineshaft-800 text-bunker-200"
|
||||||
|
hideCloseBtn
|
||||||
|
>
|
||||||
|
<div className=" text-center text-sm font-medium text-bunker-200">
|
||||||
|
Add tags to {secKey || "this secret"}
|
||||||
|
</div>
|
||||||
|
<div className="flex flex-col space-y-2.5">
|
||||||
|
{wsTags?.map((wsTag) => (
|
||||||
|
<Button
|
||||||
|
variant="star"
|
||||||
|
size="md"
|
||||||
|
className={`mt-4 justify-start px-1 hover:bg-mineshaft-600 hover:border-mineshaft-500 hover:text-bunker-200 ${selectedTagIds?.[wsTag.slug] && "text-primary hover:text-primary"}`}
|
||||||
|
onClick={() => onSelectTag(wsTag)}
|
||||||
|
leftIcon={
|
||||||
|
<Checkbox
|
||||||
|
className="mr-0 data-[state=checked]:bg-primary border-mineshaft-500 border"
|
||||||
|
id="autoCapitalization"
|
||||||
|
isChecked={selectedTagIds?.[wsTag.slug]}
|
||||||
|
>
|
||||||
|
{ }
|
||||||
|
</Checkbox>
|
||||||
|
}
|
||||||
|
key={wsTag._id}
|
||||||
|
>
|
||||||
|
{wsTag.slug}
|
||||||
|
</Button>
|
||||||
|
))}
|
||||||
|
<Button
|
||||||
|
variant="star"
|
||||||
|
size="md"
|
||||||
|
className="mt-4 justify-start px-1 hover:bg-mineshaft-600 hover:border-mineshaft-500 hover:text-bunker-200"
|
||||||
|
onClick={onCreateTagOpen}
|
||||||
|
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
||||||
|
>
|
||||||
|
Add new tag
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</PopoverContent>
|
||||||
|
</Popover>
|
||||||
|
|
||||||
|
)
|
||||||
})}
|
})}
|
||||||
<div className="w-0 overflow-hidden group-hover:w-6">
|
<div className="w-0 overflow-hidden group-hover:w-6">
|
||||||
<Tooltip content="Copy value">
|
<Tooltip content="Copy value">
|
||||||
@@ -433,25 +430,22 @@ export const SecretInputRow = memo(
|
|||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent
|
<PopoverContent
|
||||||
side="left"
|
side="left"
|
||||||
className="max-h-96 w-auto min-w-[200px] overflow-y-auto overflow-x-hidden border border-mineshaft-600 bg-mineshaft-800 p-2 text-bunker-200"
|
className="max-h-96 w-auto min-w-[200px] p-2 overflow-y-auto overflow-x-hidden border border-mineshaft-600 bg-mineshaft-800 text-bunker-200"
|
||||||
hideCloseBtn
|
hideCloseBtn
|
||||||
>
|
>
|
||||||
<div className="mb-2 px-2 text-center text-sm font-medium text-bunker-200">
|
<div className=" text-center text-sm font-medium text-bunker-200">
|
||||||
Add tags to {secKey || "this secret"}
|
Add tags to {secKey || "this secret"}
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-col space-y-1">
|
<div className="flex flex-col space-y-2.5">
|
||||||
{wsTags?.map((wsTag) => (
|
{wsTags?.map((wsTag) => (
|
||||||
<Button
|
<Button
|
||||||
variant="plain"
|
variant="star"
|
||||||
size="sm"
|
size="md"
|
||||||
className={twMerge(
|
className={`mt-4 justify-start px-1 hover:bg-mineshaft-600 hover:border-mineshaft-500 hover:text-bunker-200 ${selectedTagIds?.[wsTag.slug] && "text-primary hover:text-primary"}`}
|
||||||
"justify-start bg-mineshaft-600 text-bunker-100 hover:bg-mineshaft-500",
|
|
||||||
selectedTagIds?.[wsTag.slug] && "text-primary"
|
|
||||||
)}
|
|
||||||
onClick={() => onSelectTag(wsTag)}
|
onClick={() => onSelectTag(wsTag)}
|
||||||
leftIcon={
|
leftIcon={
|
||||||
<Checkbox
|
<Checkbox
|
||||||
className="mr-0 data-[state=checked]:bg-primary"
|
className="mr-0 data-[state=checked]:bg-primary border-mineshaft-500"
|
||||||
id="autoCapitalization"
|
id="autoCapitalization"
|
||||||
isChecked={selectedTagIds?.[wsTag.slug]}
|
isChecked={selectedTagIds?.[wsTag.slug]}
|
||||||
>
|
>
|
||||||
@@ -465,9 +459,8 @@ export const SecretInputRow = memo(
|
|||||||
))}
|
))}
|
||||||
<Button
|
<Button
|
||||||
variant="star"
|
variant="star"
|
||||||
color="primary"
|
size="md"
|
||||||
size="sm"
|
className="mt-4 justify-start px-1 hover:bg-mineshaft-600 hover:border-mineshaft-500 hover:text-bunker-200"
|
||||||
className="mt-4 h-7 justify-start bg-mineshaft-600 px-1"
|
|
||||||
onClick={onCreateTagOpen}
|
onClick={onCreateTagOpen}
|
||||||
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
leftIcon={<FontAwesomeIcon icon={faPlus} />}
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user