mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-15 08:34:52 +00:00
Merge pull request #312 from Infisical/secret-tagging
Added tags to secrets in the dashboard
This commit is contained in:
@@ -2,4 +2,5 @@ export * from './auth';
|
||||
export * from './keys';
|
||||
export * from './serviceTokens';
|
||||
export * from './subscriptions';
|
||||
export * from './tags';
|
||||
export * from './workspace';
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
export { useGetWsTags } from './queries';
|
||||
export { useCreateWsTag } from './queries';
|
||||
export { useDeleteWsTag } from './queries';
|
||||
@@ -0,0 +1,62 @@
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
||||
|
||||
import { apiRequest } from '@app/config/request';
|
||||
|
||||
import {
|
||||
CreateTagDTO,
|
||||
CreateTagRes,
|
||||
DeleteTagDTO,
|
||||
DeleteWsTagRes,
|
||||
UserWsTags
|
||||
} from './types';
|
||||
|
||||
|
||||
const workspaceTags = {
|
||||
getWsTags: (workspaceID: string) => ['workspace-tags', { workspaceID }] as const
|
||||
};
|
||||
|
||||
const fetchWsTag = async (workspaceID: string) => {
|
||||
const { data } = await apiRequest.get<{ workspaceTags: UserWsTags }>(
|
||||
`/api/v2/workspace/${workspaceID}/tags`
|
||||
);
|
||||
|
||||
return data.workspaceTags;
|
||||
};
|
||||
|
||||
export const useGetWsTags = (workspaceID: string) =>
|
||||
useQuery({
|
||||
queryKey: workspaceTags.getWsTags(workspaceID),
|
||||
queryFn: () => fetchWsTag(workspaceID),
|
||||
enabled: Boolean(workspaceID)
|
||||
});
|
||||
|
||||
export const useCreateWsTag = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<CreateTagRes, {}, CreateTagDTO>({
|
||||
mutationFn: async ({ workspaceID, tagName, tagSlug }) => {
|
||||
const { data } = await apiRequest.post(`/api/v2/workspace/${workspaceID}/tags`, {
|
||||
name: tagName,
|
||||
slug: tagSlug
|
||||
})
|
||||
return data;
|
||||
},
|
||||
onSuccess: (tagData) => {
|
||||
queryClient.invalidateQueries(workspaceTags.getWsTags(tagData?.workspace));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
export const useDeleteWsTag = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation<DeleteWsTagRes, {}, DeleteTagDTO>({
|
||||
mutationFn: async ({ tagID }) => {
|
||||
const { data } = await apiRequest.delete(`/api/v2/workspace/tags/${tagID}`);
|
||||
return data
|
||||
},
|
||||
onSuccess: (tagData) => {
|
||||
queryClient.invalidateQueries(workspaceTags.getWsTags(tagData?.workspace));
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,39 @@
|
||||
export type UserWsTags = WsTag[];
|
||||
|
||||
export type WsTag = {
|
||||
_id: string;
|
||||
name: string;
|
||||
slug: string;
|
||||
workspace: string;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
__v: number;
|
||||
}
|
||||
|
||||
export type WorkspaceTag = { _id: string; name: string; slug: string };
|
||||
|
||||
export type CreateTagDTO = {
|
||||
workspaceID: string;
|
||||
tagSlug: string;
|
||||
tagName: string;
|
||||
};
|
||||
|
||||
export type CreateTagRes = {
|
||||
name: string;
|
||||
slug: string;
|
||||
workspace: string;
|
||||
createdAt: string;
|
||||
user: string;
|
||||
_id: string;
|
||||
};
|
||||
|
||||
export type DeleteTagDTO = { tagID: string; };
|
||||
|
||||
export type DeleteWsTagRes = {
|
||||
name: string;
|
||||
slug: string;
|
||||
workspace: string;
|
||||
createdAt: string;
|
||||
user: string;
|
||||
_id: string;
|
||||
};
|
||||
@@ -9,5 +9,6 @@ export type {
|
||||
RenameWorkspaceDTO,
|
||||
UpdateEnvironmentDTO,
|
||||
Workspace,
|
||||
WorkspaceEnv
|
||||
WorkspaceEnv,
|
||||
WorkspaceTag
|
||||
} from './workspace/types';
|
||||
|
||||
@@ -5,5 +5,4 @@ export {
|
||||
useGetUserWorkspaces,
|
||||
useGetWorkspaceById,
|
||||
useRenameWorkspace,
|
||||
useUpdateWsEnvironment
|
||||
} from './queries';
|
||||
useUpdateWsEnvironment} from './queries';
|
||||
|
||||
@@ -7,6 +7,7 @@ export type Workspace = {
|
||||
};
|
||||
|
||||
export type WorkspaceEnv = { name: string; slug: string };
|
||||
export type WorkspaceTag = { _id: string; name: string; slug: string };
|
||||
|
||||
// mutation dto
|
||||
export type RenameWorkspaceDTO = { workspaceID: string; newWorkspaceName: string };
|
||||
|
||||
Reference in New Issue
Block a user