mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-14 11:29:42 +00:00
feat(secrets-ui): Improve SecretDashboard table to support multiple changes on a single commit
This commit is contained in:
@@ -9,6 +9,8 @@ export type TSecretFolder = {
|
||||
name: string;
|
||||
description?: string;
|
||||
parentId?: string | null;
|
||||
isPending?: boolean;
|
||||
pendingAction?: string;
|
||||
};
|
||||
|
||||
export type TSecretFolderWithPath = TSecretFolder & { path: string };
|
||||
|
||||
@@ -2,6 +2,10 @@ import { MutationOptions, useMutation, useQueryClient } from "@tanstack/react-qu
|
||||
|
||||
import { apiRequest } from "@app/config/request";
|
||||
import { dashboardKeys } from "@app/hooks/api/dashboard/queries";
|
||||
import {
|
||||
PendingChanges,
|
||||
PendingSecretUpdate
|
||||
} from "@app/pages/secret-manager/SecretDashboardPage/SecretMainPage.store";
|
||||
|
||||
import { commitKeys } from "../folderCommits/queries";
|
||||
import { secretApprovalRequestKeys } from "../secretApprovalRequest/queries";
|
||||
@@ -420,3 +424,100 @@ export const useBackfillSecretReference = () =>
|
||||
return data.message;
|
||||
}
|
||||
});
|
||||
|
||||
export const useCreateCommit = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return useMutation<
|
||||
object,
|
||||
object,
|
||||
{
|
||||
workspaceId: string;
|
||||
environment: string;
|
||||
secretPath: string;
|
||||
pendingChanges: PendingChanges;
|
||||
message: string;
|
||||
}
|
||||
>({
|
||||
mutationFn: async ({ workspaceId, environment, secretPath, pendingChanges, message }) => {
|
||||
const transformedSecretUpdates = pendingChanges.secrets
|
||||
.filter((change) => change.type === "update")
|
||||
.map((change: PendingSecretUpdate) => {
|
||||
const updatePayload: any = {
|
||||
secretKey: change.secretKey
|
||||
};
|
||||
|
||||
// Only include fields that actually changed
|
||||
if (change.newSecretName) {
|
||||
updatePayload.newSecretName = change.newSecretName;
|
||||
}
|
||||
if (change.secretValue !== undefined) {
|
||||
updatePayload.secretValue = change.secretValue;
|
||||
}
|
||||
if (change.secretComment !== undefined) {
|
||||
updatePayload.secretComment = change.secretComment;
|
||||
}
|
||||
if (change.skipMultilineEncoding !== undefined) {
|
||||
updatePayload.skipMultilineEncoding = change.skipMultilineEncoding;
|
||||
}
|
||||
if (change.tags) {
|
||||
updatePayload.tagIds = change.tags.map((tag) => tag.id);
|
||||
}
|
||||
if (change.secretMetadata) {
|
||||
updatePayload.secretMetadata = change.secretMetadata;
|
||||
}
|
||||
|
||||
return updatePayload;
|
||||
});
|
||||
const { data } = await apiRequest.post("/api/v1/pit/batch/commit", {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath,
|
||||
changes: {
|
||||
secrets: {
|
||||
create:
|
||||
pendingChanges.secrets
|
||||
.filter((change) => change.type === "create")
|
||||
.map((change) => ({
|
||||
secretKey: change.secretKey,
|
||||
secretValue: change.secretValue,
|
||||
secretComment: change.secretComment,
|
||||
skipMultilineEncoding: change.skipMultilineEncoding,
|
||||
tagIds: change.tags?.map((tag) => tag.id),
|
||||
secretMetadata: change.secretMetadata
|
||||
})) || [],
|
||||
update: transformedSecretUpdates,
|
||||
delete: pendingChanges.secrets.filter((change) => change.type === "delete") || []
|
||||
},
|
||||
folders: {
|
||||
create: pendingChanges.folders.filter((change) => change.type === "create") || [],
|
||||
update: pendingChanges.folders.filter((change) => change.type === "update") || [],
|
||||
delete: pendingChanges.folders.filter((change) => change.type === "delete") || []
|
||||
}
|
||||
},
|
||||
message
|
||||
});
|
||||
return data;
|
||||
},
|
||||
onSuccess: (_, { workspaceId, environment, secretPath }) => {
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: dashboardKeys.getDashboardSecrets({ projectId: workspaceId, secretPath })
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: secretKeys.getProjectSecret({ workspaceId, environment, secretPath })
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: secretSnapshotKeys.list({ environment, workspaceId, directory: secretPath })
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: secretSnapshotKeys.count({ environment, workspaceId, directory: secretPath })
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: commitKeys.count({ workspaceId, environment, directory: secretPath })
|
||||
});
|
||||
queryClient.invalidateQueries({
|
||||
queryKey: commitKeys.history({ workspaceId, environment, directory: secretPath })
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: secretApprovalRequestKeys.count({ workspaceId }) });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -66,6 +66,8 @@ export type SecretV3RawSanitized = {
|
||||
isRotatedSecret?: boolean;
|
||||
secretReminderRecipients?: SecretReminderRecipient[];
|
||||
rotationId?: string;
|
||||
isPending?: boolean;
|
||||
pendingAction?: "create" | "update" | "delete";
|
||||
};
|
||||
|
||||
export type SecretV3Raw = {
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ export const generateCommitText = (commits: { op: CommitType }[] = [], isReplica
|
||||
if (score[CommitType.DELETE])
|
||||
text.push(
|
||||
<span className="deleted-commit">
|
||||
{Boolean(text.length) && "and"}
|
||||
{Boolean(text.length) && " and "}
|
||||
{score[CommitType.DELETE]} Secret{score[CommitType.DELETE] !== 1 && "s"}
|
||||
<span className="text-red-600"> Deleted</span>
|
||||
</span>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-case-declarations */
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { Helmet } from "react-helmet";
|
||||
import { useTranslation } from "react-i18next";
|
||||
@@ -46,12 +47,14 @@ import { useGetProjectSecretsDetails } from "@app/hooks/api/dashboard";
|
||||
import { DashboardSecretsOrderBy } from "@app/hooks/api/dashboard/types";
|
||||
import { useGetFolderCommitsCount } from "@app/hooks/api/folderCommits";
|
||||
import { OrderByDirection } from "@app/hooks/api/generic/types";
|
||||
import { useCreateCommit } from "@app/hooks/api/secrets/mutations";
|
||||
import { hasSecretReadValueOrDescribePermission } from "@app/lib/fn/permission";
|
||||
import { SecretRotationListView } from "@app/pages/secret-manager/SecretDashboardPage/components/SecretRotationListView";
|
||||
|
||||
import { SecretTableResourceCount } from "../OverviewPage/components/SecretTableResourceCount";
|
||||
import { SecretV2MigrationSection } from "../OverviewPage/components/SecretV2MigrationSection";
|
||||
import { ActionBar } from "./components/ActionBar";
|
||||
import { CommitForm } from "./components/CommitForm";
|
||||
import { CreateSecretForm } from "./components/CreateSecretForm";
|
||||
import { DynamicSecretListView } from "./components/DynamicSecretListView";
|
||||
import { FolderListView } from "./components/FolderListView";
|
||||
@@ -61,8 +64,11 @@ import { SecretImportListView } from "./components/SecretImportListView";
|
||||
import { SecretListView, SecretNoAccessListView } from "./components/SecretListView";
|
||||
import { SnapshotView } from "./components/SnapshotView";
|
||||
import {
|
||||
PendingChanges,
|
||||
PopUpNames,
|
||||
StoreProvider,
|
||||
useBatchMode,
|
||||
useBatchModeActions,
|
||||
usePopUpAction,
|
||||
usePopUpState,
|
||||
useSelectedSecretActions,
|
||||
@@ -90,8 +96,11 @@ const Page = () => {
|
||||
});
|
||||
|
||||
const { permission } = useProjectPermission();
|
||||
const { mutateAsync: createCommit } = useCreateCommit();
|
||||
|
||||
const [isVisible, setIsVisible] = useState(false);
|
||||
const { isBatchMode, pendingChanges } = useBatchMode();
|
||||
const { loadPendingChanges, setExistingKeys } = useBatchModeActions();
|
||||
|
||||
const {
|
||||
offset,
|
||||
@@ -121,6 +130,22 @@ const Page = () => {
|
||||
const projectSlug = currentWorkspace?.slug || "";
|
||||
const secretPath = (routerQueryParams.secretPath as string) || "/";
|
||||
|
||||
useEffect(() => {
|
||||
if (isBatchMode && workspaceId && environment && secretPath) {
|
||||
loadPendingChanges({ workspaceId, environment, secretPath });
|
||||
}
|
||||
}, [isBatchMode, workspaceId, environment, secretPath, loadPendingChanges]);
|
||||
|
||||
const handleCreateCommit = (changes: PendingChanges, message: string) => {
|
||||
createCommit({
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath,
|
||||
pendingChanges: changes,
|
||||
message
|
||||
});
|
||||
};
|
||||
|
||||
const canReadSecret = hasSecretReadValueOrDescribePermission(
|
||||
permission,
|
||||
ProjectPermissionSecretActions.DescribeSecret,
|
||||
@@ -350,6 +375,16 @@ const Page = () => {
|
||||
noAccessSecretCount
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (data && isBatchMode) {
|
||||
const existingSecretKeys = [...(secrets?.map((s) => s.key) || [])];
|
||||
|
||||
const existingFolderNames = folders?.map((f) => f.name) || [];
|
||||
|
||||
setExistingKeys(existingSecretKeys, existingFolderNames);
|
||||
}
|
||||
}, [data, isBatchMode, setExistingKeys, secrets, importedSecrets, folders]);
|
||||
|
||||
const handleSortToggle = () =>
|
||||
setOrderDirection((state) =>
|
||||
state === OrderByDirection.ASC ? OrderByDirection.DESC : OrderByDirection.ASC
|
||||
@@ -476,6 +511,134 @@ const Page = () => {
|
||||
setFilter(defaultFilterState);
|
||||
setDebouncedSearchFilter("");
|
||||
};
|
||||
|
||||
const getMergedSecretsWithPending = () => {
|
||||
if (!isBatchMode || pendingChanges.secrets.length === 0) {
|
||||
return secrets;
|
||||
}
|
||||
|
||||
const mergedSecrets = [...(secrets || [])];
|
||||
|
||||
pendingChanges.secrets.forEach((change) => {
|
||||
switch (change.type) {
|
||||
case "create":
|
||||
mergedSecrets.unshift({
|
||||
id: change.id,
|
||||
key: change.secretKey,
|
||||
value: change.secretValue,
|
||||
comment: change.secretComment || "",
|
||||
skipMultilineEncoding: change.skipMultilineEncoding || false,
|
||||
tags: change.tags?.map((tag) => ({ id: tag.id, slug: tag.slug })) || [],
|
||||
secretMetadata: change.secretMetadata || [],
|
||||
createdAt: new Date().toISOString(),
|
||||
updatedAt: new Date().toISOString(),
|
||||
version: 1,
|
||||
isPending: true,
|
||||
pendingAction: "create"
|
||||
} as any);
|
||||
break;
|
||||
|
||||
case "update":
|
||||
const updateIndex = mergedSecrets.findIndex((s) => s.key === change.secretKey);
|
||||
if (updateIndex >= 0) {
|
||||
mergedSecrets[updateIndex] = {
|
||||
...mergedSecrets[updateIndex],
|
||||
key: change.newSecretName || change.secretKey,
|
||||
value:
|
||||
change.secretValue !== undefined
|
||||
? change.secretValue
|
||||
: mergedSecrets[updateIndex].value,
|
||||
comment:
|
||||
change.secretComment !== undefined
|
||||
? change.secretComment
|
||||
: mergedSecrets[updateIndex].comment,
|
||||
skipMultilineEncoding:
|
||||
change.skipMultilineEncoding !== undefined
|
||||
? change.skipMultilineEncoding
|
||||
: mergedSecrets[updateIndex].skipMultilineEncoding,
|
||||
secretMetadata: change.secretMetadata || mergedSecrets[updateIndex].secretMetadata,
|
||||
isPending: true,
|
||||
pendingAction: "update"
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
const deleteIndex = mergedSecrets.findIndex((s) => s.key === change.secretKey);
|
||||
if (deleteIndex >= 0) {
|
||||
mergedSecrets[deleteIndex] = {
|
||||
...mergedSecrets[deleteIndex],
|
||||
isPending: true,
|
||||
pendingAction: "delete"
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
return mergedSecrets;
|
||||
};
|
||||
|
||||
const getMergedFoldersWithPending = () => {
|
||||
if (!isBatchMode || pendingChanges.folders.length === 0) {
|
||||
return folders;
|
||||
}
|
||||
|
||||
const mergedFolders = [...(folders || [])];
|
||||
|
||||
pendingChanges.folders.forEach((change) => {
|
||||
switch (change.type) {
|
||||
case "create":
|
||||
mergedFolders.unshift({
|
||||
id: change.id,
|
||||
name: change.folderName,
|
||||
description: change.description,
|
||||
parentId: null,
|
||||
isPending: true,
|
||||
pendingAction: "create"
|
||||
} as any);
|
||||
break;
|
||||
|
||||
case "update":
|
||||
const updateIndex = mergedFolders.findIndex((f) => f.id === change.id);
|
||||
if (updateIndex >= 0) {
|
||||
mergedFolders[updateIndex] = {
|
||||
...mergedFolders[updateIndex],
|
||||
name: change.folderName,
|
||||
description:
|
||||
change.description !== undefined
|
||||
? change.description
|
||||
: mergedFolders[updateIndex].description,
|
||||
isPending: true,
|
||||
pendingAction: "update"
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
case "delete":
|
||||
const deleteIndex = mergedFolders.findIndex((f) => f.id === change.id);
|
||||
if (deleteIndex >= 0) {
|
||||
mergedFolders[deleteIndex] = {
|
||||
...mergedFolders[deleteIndex],
|
||||
isPending: true,
|
||||
pendingAction: "delete"
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
return mergedFolders;
|
||||
};
|
||||
|
||||
const mergedSecrets = getMergedSecretsWithPending();
|
||||
const mergedFolders = getMergedFoldersWithPending();
|
||||
return (
|
||||
<div className="container mx-auto flex max-w-7xl flex-col text-mineshaft-50 dark:[color-scheme:dark]">
|
||||
<SecretV2MigrationSection />
|
||||
@@ -487,6 +650,7 @@ const Page = () => {
|
||||
projectSlug={projectSlug}
|
||||
secretPath={secretPath}
|
||||
isVisible={isVisible}
|
||||
isBatchMode={isBatchMode}
|
||||
filter={filter}
|
||||
tags={tags}
|
||||
onVisibilityToggle={handleToggleVisibility}
|
||||
@@ -559,9 +723,9 @@ const Page = () => {
|
||||
importedSecrets={importedSecrets}
|
||||
/>
|
||||
)}
|
||||
{Boolean(folders?.length) && (
|
||||
{Boolean(mergedFolders?.length) && (
|
||||
<FolderListView
|
||||
folders={folders}
|
||||
folders={mergedFolders}
|
||||
environment={environment}
|
||||
workspaceId={workspaceId}
|
||||
secretPath={secretPath}
|
||||
@@ -579,9 +743,9 @@ const Page = () => {
|
||||
{canReadSecretRotations && Boolean(secretRotations?.length) && (
|
||||
<SecretRotationListView secretRotations={secretRotations} />
|
||||
)}
|
||||
{canReadSecret && Boolean(secrets?.length) && (
|
||||
{canReadSecret && Boolean(mergedSecrets?.length) && (
|
||||
<SecretListView
|
||||
secrets={secrets}
|
||||
secrets={mergedSecrets}
|
||||
tags={tags}
|
||||
isVisible={isVisible}
|
||||
environment={environment}
|
||||
@@ -592,6 +756,17 @@ const Page = () => {
|
||||
usedBySecretSyncs={usedBySecretSyncs}
|
||||
/>
|
||||
)}
|
||||
{(pendingChanges.secrets.length > 0 || pendingChanges.folders.length > 0) && (
|
||||
<CommitForm
|
||||
onCommit={async (changes, commitMessage) => {
|
||||
await handleCreateCommit(changes, commitMessage);
|
||||
}}
|
||||
environment={environment}
|
||||
workspaceId={workspaceId}
|
||||
secretPath={secretPath}
|
||||
isCommitting={false}
|
||||
/>
|
||||
)}
|
||||
{noAccessSecretCount > 0 && <SecretNoAccessListView count={noAccessSecretCount} />}
|
||||
{!canReadSecret &&
|
||||
!canReadDynamicSecret &&
|
||||
@@ -633,6 +808,7 @@ const Page = () => {
|
||||
secretPath={secretPath}
|
||||
autoCapitalize={currentWorkspace?.autoCapitalization}
|
||||
isProtectedBranch={isProtectedBranch}
|
||||
isBatchMode={isBatchMode}
|
||||
/>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable no-nested-ternary */
|
||||
import { createContext, ReactNode, useContext, useEffect, useRef } from "react";
|
||||
import { useRouter } from "@tanstack/react-router";
|
||||
import { createStore, StateCreator, StoreApi, useStore } from "zustand";
|
||||
@@ -8,6 +9,158 @@ import { SecretV3RawSanitized } from "@app/hooks/api/secrets/types";
|
||||
// akhilmhdh: Don't remove this file if ur thinking why use zustand just for selected selects state
|
||||
// This is first step and the whole secret crud will be moved to this global page scope state
|
||||
// this will allow more stuff like undo grouping stuffs etc
|
||||
|
||||
// Base interface for all pending changes
|
||||
export interface BasePendingChange {
|
||||
id: string;
|
||||
timestamp: number;
|
||||
}
|
||||
|
||||
// Secret-related change types
|
||||
export interface PendingSecretCreate extends BasePendingChange {
|
||||
resourceType: "secret";
|
||||
type: "create";
|
||||
secretKey: string;
|
||||
secretValue: string;
|
||||
secretComment?: string;
|
||||
skipMultilineEncoding?: boolean;
|
||||
tags?: { id: string; slug: string }[];
|
||||
secretMetadata?: { key: string; value: string }[];
|
||||
originalKey?: string;
|
||||
}
|
||||
|
||||
export interface PendingSecretUpdate extends BasePendingChange {
|
||||
resourceType: "secret";
|
||||
type: "update";
|
||||
secretKey: string;
|
||||
newSecretName?: string;
|
||||
originalValue?: string;
|
||||
secretValue?: string;
|
||||
originalComment?: string;
|
||||
secretComment?: string;
|
||||
originalSkipMultilineEncoding?: boolean;
|
||||
skipMultilineEncoding?: boolean;
|
||||
originalTags?: { id: string; slug: string }[];
|
||||
tags?: { id: string; slug: string }[];
|
||||
originalSecretMetadata?: { key: string; value: string }[];
|
||||
secretMetadata?: { key: string; value: string }[];
|
||||
}
|
||||
|
||||
export interface PendingSecretDelete extends BasePendingChange {
|
||||
resourceType: "secret";
|
||||
type: "delete";
|
||||
secretKey: string;
|
||||
secretValue: string;
|
||||
}
|
||||
|
||||
// Folder-related change types
|
||||
export interface PendingFolderCreate extends BasePendingChange {
|
||||
resourceType: "folder";
|
||||
type: "create";
|
||||
id: string;
|
||||
folderName: string;
|
||||
description?: string;
|
||||
parentPath: string;
|
||||
}
|
||||
|
||||
export interface PendingFolderUpdate extends BasePendingChange {
|
||||
resourceType: "folder";
|
||||
type: "update";
|
||||
originalFolderName: string;
|
||||
folderName: string;
|
||||
id: string;
|
||||
originalDescription?: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface PendingFolderDelete extends BasePendingChange {
|
||||
resourceType: "folder";
|
||||
type: "delete";
|
||||
id: string;
|
||||
folderName: string;
|
||||
folderPath: string;
|
||||
}
|
||||
|
||||
// Union types for each resource
|
||||
export type PendingSecretChange = PendingSecretCreate | PendingSecretUpdate | PendingSecretDelete;
|
||||
export type PendingFolderChange = PendingFolderCreate | PendingFolderUpdate | PendingFolderDelete;
|
||||
export type PendingChange = PendingSecretChange | PendingFolderChange;
|
||||
|
||||
// Grouped changes for better processing
|
||||
export interface PendingChanges {
|
||||
secrets: PendingSecretChange[];
|
||||
folders: PendingFolderChange[];
|
||||
}
|
||||
|
||||
// Context interface for batch operations
|
||||
export interface BatchContext {
|
||||
workspaceId: string;
|
||||
environment: string;
|
||||
secretPath: string;
|
||||
}
|
||||
|
||||
const STORAGE_KEY = "infisical_pending_changes";
|
||||
|
||||
const generateContextKey = (workspaceId: string, environment: string, secretPath: string) => {
|
||||
return `${workspaceId}_${environment}_${secretPath}`;
|
||||
};
|
||||
|
||||
const savePendingChangesToStorage = (
|
||||
changes: PendingChanges,
|
||||
workspaceId: string,
|
||||
environment: string,
|
||||
secretPath: string
|
||||
) => {
|
||||
const key = `${STORAGE_KEY}_${generateContextKey(workspaceId, environment, secretPath)}`;
|
||||
try {
|
||||
localStorage.setItem(key, JSON.stringify(changes));
|
||||
} catch (error) {
|
||||
console.warn("Failed to save pending changes to localStorage:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const loadPendingChangesFromStorage = (
|
||||
workspaceId: string,
|
||||
environment: string,
|
||||
secretPath: string
|
||||
): PendingChanges => {
|
||||
const key = `${STORAGE_KEY}_${generateContextKey(workspaceId, environment, secretPath)}`;
|
||||
const stored = localStorage.getItem(key);
|
||||
if (!stored) return { secrets: [], folders: [] };
|
||||
|
||||
try {
|
||||
const parsed = JSON.parse(stored);
|
||||
if (Array.isArray(parsed)) {
|
||||
return {
|
||||
secrets: parsed.filter(
|
||||
(change: any) => !change.resourceType || change.resourceType === "secret"
|
||||
),
|
||||
folders: []
|
||||
};
|
||||
}
|
||||
return {
|
||||
secrets: parsed.secrets || [],
|
||||
folders: parsed.folders || []
|
||||
};
|
||||
} catch (error) {
|
||||
console.warn("Failed to parse pending changes from localStorage:", error);
|
||||
return { secrets: [], folders: [] };
|
||||
}
|
||||
};
|
||||
|
||||
const clearPendingChangesFromStorage = (
|
||||
workspaceId: string,
|
||||
environment: string,
|
||||
secretPath: string
|
||||
) => {
|
||||
const key = `${STORAGE_KEY}_${generateContextKey(workspaceId, environment, secretPath)}`;
|
||||
try {
|
||||
localStorage.removeItem(key);
|
||||
} catch (error) {
|
||||
console.warn("Failed to clear pending changes from localStorage:", error);
|
||||
}
|
||||
};
|
||||
|
||||
type SelectedSecretState = {
|
||||
selectedSecret: Record<string, SecretV3RawSanitized>;
|
||||
action: {
|
||||
@@ -16,14 +169,16 @@ type SelectedSecretState = {
|
||||
set: (secrets: Record<string, SecretV3RawSanitized>) => void;
|
||||
};
|
||||
};
|
||||
const createSelectedSecretStore: StateCreator<SelectedSecretState> = (set) => ({
|
||||
|
||||
const createSelectedSecretStore: StateCreator<CombinedState, [], [], SelectedSecretState> = (
|
||||
set
|
||||
) => ({
|
||||
selectedSecret: {},
|
||||
action: {
|
||||
toggle: (secret) =>
|
||||
set((state) => {
|
||||
const isChecked = Boolean(state.selectedSecret?.[secret.id]);
|
||||
const newChecks = { ...state.selectedSecret };
|
||||
// remove selection if its present else add it
|
||||
if (isChecked) delete newChecks[secret.id];
|
||||
else newChecks[secret.id] = secret;
|
||||
return { selectedSecret: newChecks };
|
||||
@@ -33,6 +188,332 @@ const createSelectedSecretStore: StateCreator<SelectedSecretState> = (set) => ({
|
||||
}
|
||||
});
|
||||
|
||||
const cleanupRevertedFields = (update: PendingSecretUpdate): PendingSecretUpdate => {
|
||||
const cleaned = { ...update };
|
||||
|
||||
if (cleaned.secretValue === cleaned.originalValue) {
|
||||
cleaned.secretValue = undefined;
|
||||
}
|
||||
|
||||
if (cleaned.secretComment === cleaned.originalComment) {
|
||||
cleaned.secretComment = undefined;
|
||||
}
|
||||
|
||||
if (cleaned.skipMultilineEncoding === cleaned.originalSkipMultilineEncoding) {
|
||||
cleaned.skipMultilineEncoding = undefined;
|
||||
}
|
||||
|
||||
// For arrays, compare stringified versions
|
||||
if (JSON.stringify(cleaned.tags) === JSON.stringify(cleaned.originalTags)) {
|
||||
cleaned.tags = undefined;
|
||||
}
|
||||
|
||||
if (JSON.stringify(cleaned.secretMetadata) === JSON.stringify(cleaned.originalSecretMetadata)) {
|
||||
cleaned.secretMetadata = undefined;
|
||||
}
|
||||
|
||||
// If the new name is the same as original key, remove it
|
||||
if (cleaned.newSecretName === cleaned.secretKey) {
|
||||
cleaned.newSecretName = undefined;
|
||||
}
|
||||
|
||||
return cleaned;
|
||||
};
|
||||
|
||||
type BatchModeState = {
|
||||
isBatchMode: boolean;
|
||||
pendingChanges: PendingChanges;
|
||||
existingSecretKeys: Set<string>;
|
||||
existingFolderNames: Set<string>;
|
||||
currentContext: BatchContext | null;
|
||||
batchActions: {
|
||||
addPendingChange: (change: PendingChange, context: BatchContext) => void;
|
||||
loadPendingChanges: (context: BatchContext) => void;
|
||||
clearAllPendingChanges: (context: BatchContext) => void;
|
||||
setExistingKeys: (secretKeys: string[], folderNames: string[]) => void;
|
||||
getTotalPendingChangesCount: () => number;
|
||||
removePendingChange: (changeId: string, resourceType: string, context: BatchContext) => void;
|
||||
};
|
||||
};
|
||||
|
||||
const createBatchModeStore: StateCreator<CombinedState, [], [], BatchModeState> = (set, get) => ({
|
||||
isBatchMode: true, // Always enabled by default
|
||||
pendingChanges: { secrets: [], folders: [] },
|
||||
currentContext: null,
|
||||
existingSecretKeys: new Set<string>(),
|
||||
existingFolderNames: new Set<string>(),
|
||||
batchActions: {
|
||||
addPendingChange: (change: PendingChange, context: BatchContext) =>
|
||||
set((state) => {
|
||||
const newChanges = { ...state.pendingChanges };
|
||||
|
||||
if (change.resourceType === "folder") {
|
||||
if (
|
||||
change.type === "create" &&
|
||||
(state.existingFolderNames.has(change.folderName) ||
|
||||
newChanges.folders.some((f) => f.folderName === change.folderName))
|
||||
) {
|
||||
return { pendingChanges: newChanges };
|
||||
}
|
||||
if (
|
||||
change.type === "update" &&
|
||||
change.folderName !== change.originalFolderName &&
|
||||
(state.existingFolderNames.has(change.folderName) ||
|
||||
newChanges.folders.some((f) => f.folderName === change.folderName))
|
||||
) {
|
||||
return { pendingChanges: newChanges };
|
||||
}
|
||||
}
|
||||
|
||||
if (change.resourceType === "secret") {
|
||||
if (
|
||||
change.type === "create" &&
|
||||
(state.existingSecretKeys.has(change.secretKey) ||
|
||||
newChanges.secrets.some((s) => s.secretKey === change.secretKey))
|
||||
) {
|
||||
return { pendingChanges: newChanges };
|
||||
}
|
||||
if (
|
||||
change.type === "update" &&
|
||||
change.newSecretName &&
|
||||
change.newSecretName !== change.secretKey &&
|
||||
(state.existingSecretKeys.has(change.newSecretName) ||
|
||||
newChanges.secrets.some(
|
||||
(s) =>
|
||||
(s.secretKey === change.newSecretName ||
|
||||
(s.type === "update" && s.newSecretName === change.newSecretName)) &&
|
||||
s.id !== change.id
|
||||
))
|
||||
) {
|
||||
return { pendingChanges: newChanges };
|
||||
}
|
||||
}
|
||||
|
||||
if (change.resourceType === "secret") {
|
||||
const secretChanges = [...newChanges.secrets];
|
||||
|
||||
if (change.type === "create") {
|
||||
const existingCreateIndex = secretChanges.findIndex(
|
||||
(c) =>
|
||||
c.type === "create" &&
|
||||
(c.secretKey === change.secretKey || c.secretKey === change.originalKey)
|
||||
);
|
||||
|
||||
if (existingCreateIndex >= 0) {
|
||||
secretChanges[existingCreateIndex] = {
|
||||
...secretChanges[existingCreateIndex],
|
||||
...change,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
} else {
|
||||
secretChanges.push(change);
|
||||
}
|
||||
} else if (change.type === "update") {
|
||||
const existingCreateIndex = secretChanges.findIndex(
|
||||
(c) => c.type === "create" && c.id === change.id
|
||||
);
|
||||
|
||||
if (existingCreateIndex >= 0) {
|
||||
const existingCreate = secretChanges[existingCreateIndex] as PendingSecretCreate;
|
||||
secretChanges[existingCreateIndex] = {
|
||||
...existingCreate,
|
||||
secretKey: change.newSecretName || change.secretKey || existingCreate.secretKey,
|
||||
secretValue:
|
||||
change.secretValue !== undefined
|
||||
? change.secretValue
|
||||
: existingCreate.secretValue,
|
||||
secretComment:
|
||||
change.secretComment !== undefined
|
||||
? change.secretComment
|
||||
: existingCreate.secretComment,
|
||||
skipMultilineEncoding:
|
||||
change.skipMultilineEncoding !== undefined
|
||||
? change.skipMultilineEncoding
|
||||
: existingCreate.skipMultilineEncoding,
|
||||
tags: change.tags !== undefined ? change.tags : existingCreate.tags,
|
||||
secretMetadata:
|
||||
change.secretMetadata !== undefined
|
||||
? change.secretMetadata
|
||||
: existingCreate.secretMetadata,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
} else {
|
||||
const existingUpdateIndex = secretChanges.findIndex(
|
||||
(c) => c.type === "update" && c.id === change.id
|
||||
);
|
||||
|
||||
if (existingUpdateIndex >= 0) {
|
||||
const existingUpdate = secretChanges[existingUpdateIndex] as PendingSecretUpdate;
|
||||
|
||||
const improvedUpdate: PendingSecretUpdate = {
|
||||
...existingUpdate,
|
||||
secretKey: existingUpdate.secretKey,
|
||||
originalValue: existingUpdate.originalValue,
|
||||
originalComment: existingUpdate.originalComment,
|
||||
originalSkipMultilineEncoding: existingUpdate.originalSkipMultilineEncoding,
|
||||
originalTags: existingUpdate.originalTags,
|
||||
originalSecretMetadata: existingUpdate.originalSecretMetadata,
|
||||
|
||||
newSecretName:
|
||||
change.newSecretName !== undefined
|
||||
? change.newSecretName
|
||||
: existingUpdate.newSecretName,
|
||||
secretValue:
|
||||
change.secretValue !== undefined
|
||||
? change.secretValue
|
||||
: existingUpdate.secretValue,
|
||||
secretComment:
|
||||
change.secretComment !== undefined
|
||||
? change.secretComment
|
||||
: existingUpdate.secretComment,
|
||||
skipMultilineEncoding:
|
||||
change.skipMultilineEncoding !== undefined
|
||||
? change.skipMultilineEncoding
|
||||
: existingUpdate.skipMultilineEncoding,
|
||||
tags: change.tags !== undefined ? change.tags : existingUpdate.tags,
|
||||
secretMetadata:
|
||||
change.secretMetadata !== undefined
|
||||
? change.secretMetadata
|
||||
: existingUpdate.secretMetadata,
|
||||
|
||||
timestamp: Date.now()
|
||||
};
|
||||
|
||||
const cleanedUpdate = cleanupRevertedFields(improvedUpdate);
|
||||
|
||||
secretChanges[existingUpdateIndex] = cleanedUpdate;
|
||||
} else {
|
||||
secretChanges.push(change);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
secretChanges.push(change);
|
||||
}
|
||||
|
||||
newChanges.secrets = secretChanges;
|
||||
} else if (change.resourceType === "folder") {
|
||||
const folderChanges = [...newChanges.folders];
|
||||
|
||||
if (change.type === "create") {
|
||||
const existingCreateIndex = folderChanges.findIndex(
|
||||
(c) => c.type === "create" && c.folderName === change.folderName
|
||||
);
|
||||
|
||||
if (existingCreateIndex >= 0) {
|
||||
folderChanges[existingCreateIndex] = {
|
||||
...folderChanges[existingCreateIndex],
|
||||
...change,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
} else {
|
||||
folderChanges.push(change);
|
||||
}
|
||||
} else if (change.type === "update") {
|
||||
const existingCreateIndex = folderChanges.findIndex(
|
||||
(c) => c.type === "create" && c.folderName === change.originalFolderName
|
||||
);
|
||||
|
||||
if (existingCreateIndex >= 0) {
|
||||
const existingCreate = folderChanges[existingCreateIndex] as PendingFolderCreate;
|
||||
folderChanges[existingCreateIndex] = {
|
||||
...existingCreate,
|
||||
folderName: change.folderName || existingCreate.folderName,
|
||||
description:
|
||||
change.description !== undefined
|
||||
? change.description
|
||||
: existingCreate.description,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
} else {
|
||||
const existingUpdateIndex = folderChanges.findIndex(
|
||||
(c) => c.type === "update" && c.id === change.id
|
||||
);
|
||||
|
||||
if (existingUpdateIndex >= 0) {
|
||||
const existingUpdate = folderChanges[existingUpdateIndex] as PendingFolderUpdate;
|
||||
|
||||
folderChanges[existingUpdateIndex] = {
|
||||
...existingUpdate,
|
||||
originalFolderName: existingUpdate.originalFolderName,
|
||||
originalDescription: existingUpdate.originalDescription,
|
||||
|
||||
folderName:
|
||||
change.folderName !== undefined ? change.folderName : existingUpdate.folderName,
|
||||
description:
|
||||
change.description !== undefined
|
||||
? change.description
|
||||
: existingUpdate.description,
|
||||
|
||||
timestamp: Date.now()
|
||||
};
|
||||
} else {
|
||||
folderChanges.push(change);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
folderChanges.push(change);
|
||||
}
|
||||
|
||||
newChanges.folders = folderChanges;
|
||||
}
|
||||
|
||||
savePendingChangesToStorage(
|
||||
newChanges,
|
||||
context.workspaceId,
|
||||
context.environment,
|
||||
context.secretPath
|
||||
);
|
||||
return { pendingChanges: newChanges };
|
||||
}),
|
||||
|
||||
removePendingChange: (changeId: string, resourceType: string, context: BatchContext) =>
|
||||
set((state) => {
|
||||
const newChanges = { ...state.pendingChanges };
|
||||
|
||||
if (resourceType === "secret") {
|
||||
newChanges.secrets = newChanges.secrets.filter((c) => c.id !== changeId);
|
||||
} else if (resourceType === "folder") {
|
||||
newChanges.folders = newChanges.folders.filter((c) => c.id !== changeId);
|
||||
}
|
||||
|
||||
savePendingChangesToStorage(
|
||||
newChanges,
|
||||
context.workspaceId,
|
||||
context.environment,
|
||||
context.secretPath
|
||||
);
|
||||
return { pendingChanges: newChanges };
|
||||
}),
|
||||
|
||||
loadPendingChanges: (context) => {
|
||||
const changes = loadPendingChangesFromStorage(
|
||||
context.workspaceId,
|
||||
context.environment,
|
||||
context.secretPath
|
||||
);
|
||||
set({ pendingChanges: changes });
|
||||
},
|
||||
|
||||
clearAllPendingChanges: (context) => {
|
||||
clearPendingChangesFromStorage(context.workspaceId, context.environment, context.secretPath);
|
||||
set({
|
||||
pendingChanges: { secrets: [], folders: [] }
|
||||
});
|
||||
},
|
||||
|
||||
setExistingKeys: (secretKeys, folderNames) =>
|
||||
set({
|
||||
existingSecretKeys: new Set(secretKeys),
|
||||
existingFolderNames: new Set(folderNames)
|
||||
}),
|
||||
|
||||
getTotalPendingChangesCount: () => {
|
||||
const state = get();
|
||||
return state.pendingChanges.secrets.length + state.pendingChanges.folders.length;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export enum PopUpNames {
|
||||
CreateSecretForm = "create-secret-form"
|
||||
}
|
||||
@@ -58,13 +539,14 @@ const createPopUpStore: StateCreator<PopUpState> = (set) => ({
|
||||
}
|
||||
});
|
||||
|
||||
type CombinedState = SelectedSecretState & PopUpState;
|
||||
type CombinedState = SelectedSecretState & PopUpState & BatchModeState;
|
||||
const StoreContext = createContext<StoreApi<CombinedState> | null>(null);
|
||||
export const StoreProvider = ({ children }: { children: ReactNode }) => {
|
||||
const storeRef = useRef<StoreApi<CombinedState>>(
|
||||
createStore<CombinedState>((...a) => ({
|
||||
...createSelectedSecretStore(...a),
|
||||
...createPopUpStore(...a)
|
||||
...createPopUpStore(...a),
|
||||
...createBatchModeStore(...a)
|
||||
}))
|
||||
);
|
||||
const router = useRouter();
|
||||
@@ -99,3 +581,17 @@ export const useSelectedSecretActions = () => useStoreContext(useShallow((state)
|
||||
export const usePopUpState = (id: PopUpNames) =>
|
||||
useStoreContext(useShallow((state) => state.popUp?.[id] || { isOpen: false }));
|
||||
export const usePopUpAction = () => useStoreContext(useShallow((state) => state.popUpActions));
|
||||
|
||||
export const useBatchMode = () =>
|
||||
useStoreContext(
|
||||
useShallow((state) => ({
|
||||
isBatchMode: state.isBatchMode,
|
||||
pendingChanges: state.pendingChanges,
|
||||
currentContext: state.currentContext,
|
||||
totalChangesCount: state.batchActions.getTotalPendingChangesCount(),
|
||||
secretChangesCount: state.pendingChanges.secrets.length,
|
||||
folderChangesCount: state.pendingChanges.folders.length
|
||||
}))
|
||||
);
|
||||
|
||||
export const useBatchModeActions = () => useStoreContext(useShallow((state) => state.batchActions));
|
||||
|
||||
+27
@@ -79,7 +79,9 @@ import { ApiErrorTypes, SecretType, TApiErrors, WsTag } from "@app/hooks/api/typ
|
||||
import { SecretSearchInput } from "@app/pages/secret-manager/OverviewPage/components/SecretSearchInput";
|
||||
|
||||
import {
|
||||
PendingFolderCreate,
|
||||
PopUpNames,
|
||||
useBatchModeActions,
|
||||
usePopUpAction,
|
||||
useSelectedSecretActions,
|
||||
useSelectedSecrets
|
||||
@@ -109,6 +111,7 @@ type Props = {
|
||||
filter: Filter;
|
||||
tags?: WsTag[];
|
||||
isVisible?: boolean;
|
||||
isBatchMode?: boolean;
|
||||
snapshotCount: number;
|
||||
isSnapshotCountLoading?: boolean;
|
||||
protectedBranchPolicyName?: string;
|
||||
@@ -137,6 +140,7 @@ export const ActionBar = ({
|
||||
filter,
|
||||
tags = [],
|
||||
isVisible,
|
||||
isBatchMode,
|
||||
snapshotCount,
|
||||
isSnapshotCountLoading,
|
||||
onSearchChange,
|
||||
@@ -174,6 +178,7 @@ export const ActionBar = ({
|
||||
options: { onSuccess: undefined }
|
||||
});
|
||||
const queryClient = useQueryClient();
|
||||
const { addPendingChange } = useBatchModeActions();
|
||||
|
||||
const selectedSecrets = useSelectedSecrets();
|
||||
const { reset: resetSelectedSecret } = useSelectedSecretActions();
|
||||
@@ -183,6 +188,28 @@ export const ActionBar = ({
|
||||
|
||||
const handleFolderCreate = async (folderName: string, description: string | null) => {
|
||||
try {
|
||||
if (isBatchMode) {
|
||||
const folderId = `${folderName}`;
|
||||
const pendingFolderCreate: PendingFolderCreate = {
|
||||
id: folderId,
|
||||
resourceType: "folder",
|
||||
type: "create",
|
||||
folderName,
|
||||
description: description || undefined,
|
||||
parentPath: secretPath,
|
||||
timestamp: Date.now()
|
||||
};
|
||||
|
||||
addPendingChange(pendingFolderCreate, {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
|
||||
handlePopUpClose("addFolder");
|
||||
return;
|
||||
}
|
||||
|
||||
await createFolder({
|
||||
name: folderName,
|
||||
path: secretPath,
|
||||
|
||||
+7
-2
@@ -8,7 +8,12 @@ import { TextArea } from "@app/components/v2/TextArea/TextArea";
|
||||
|
||||
type Props = {
|
||||
onCreateFolder?: (folderName: string, description: string | null) => Promise<void>;
|
||||
onUpdateFolder?: (folderName: string, description: string | null) => Promise<void>;
|
||||
onUpdateFolder?: (
|
||||
folderName: string,
|
||||
description: string | null,
|
||||
oldFolderName?: string,
|
||||
oldFolderDescription?: string
|
||||
) => Promise<void>;
|
||||
isEdit?: boolean;
|
||||
defaultFolderName?: string;
|
||||
defaultDescription?: string;
|
||||
@@ -69,7 +74,7 @@ export const FolderForm = ({
|
||||
const descriptionShaped = description && description.trim() !== "" ? description : null;
|
||||
|
||||
if (isEdit) {
|
||||
await onUpdateFolder?.(name, descriptionShaped);
|
||||
await onUpdateFolder?.(name, descriptionShaped, defaultFolderName, defaultDescription);
|
||||
} else {
|
||||
await onCreateFolder?.(name, descriptionShaped);
|
||||
}
|
||||
|
||||
+595
@@ -0,0 +1,595 @@
|
||||
/* eslint-disable jsx-a11y/label-has-associated-control */
|
||||
import React, { useState } from "react";
|
||||
import { faCodeCommit, faFolder, faKey } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
|
||||
import {
|
||||
Badge,
|
||||
Button,
|
||||
FontAwesomeSymbol,
|
||||
IconButton,
|
||||
Input,
|
||||
Modal,
|
||||
ModalContent
|
||||
} from "@app/components/v2";
|
||||
|
||||
import {
|
||||
PendingChange,
|
||||
PendingChanges,
|
||||
useBatchMode,
|
||||
useBatchModeActions
|
||||
} from "../../SecretMainPage.store";
|
||||
import { FontAwesomeSpriteName } from "../SecretListView/SecretListView.utils";
|
||||
|
||||
interface CommitFormProps {
|
||||
onCommit: (changes: PendingChanges, commitMessage: string) => Promise<void>;
|
||||
isCommitting?: boolean;
|
||||
environment: string;
|
||||
workspaceId: string;
|
||||
secretPath: string;
|
||||
}
|
||||
|
||||
interface ChangeTableProps {
|
||||
change: PendingChange;
|
||||
environment: string;
|
||||
workspaceId: string;
|
||||
secretPath: string;
|
||||
}
|
||||
|
||||
const TagsList: React.FC<{ tags?: { id: string; slug: string }[]; className?: string }> = ({
|
||||
tags,
|
||||
className = ""
|
||||
}) => {
|
||||
if (!tags || tags.length === 0) {
|
||||
return <span className={`italic text-mineshaft-400 ${className}`}>(no tags)</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`flex flex-wrap gap-1 ${className}`}>
|
||||
{tags.map((tag) => (
|
||||
<Badge key={tag.id} variant="primary" className="text-xs">
|
||||
{tag.slug}
|
||||
</Badge>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const MetadataList: React.FC<{
|
||||
metadata?: { key: string; value: string }[];
|
||||
className?: string;
|
||||
}> = ({ metadata, className = "" }) => {
|
||||
if (!metadata || metadata.length === 0) {
|
||||
return <span className={`italic text-mineshaft-400 ${className}`}>(no metadata)</span>;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className={`space-y-1 ${className}`}>
|
||||
{metadata.map((item) => (
|
||||
<div key={item.key} className="flex items-center gap-2 text-xs">
|
||||
<span className="font-medium text-mineshaft-300">{item.key}:</span>
|
||||
<span className="font-mono text-mineshaft-100">{item.value}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const ComparisonTableRow: React.FC<{
|
||||
label: string;
|
||||
previousValue: React.ReactNode;
|
||||
newValue: React.ReactNode;
|
||||
hideIfSame?: boolean;
|
||||
}> = ({ label, previousValue, newValue, hideIfSame = false }) => {
|
||||
const isSame = hideIfSame && String(previousValue) === String(newValue);
|
||||
|
||||
if (isSame) return null;
|
||||
|
||||
return (
|
||||
<tr className="border-b border-mineshaft-700 last:border-b-0">
|
||||
<td className="w-24 py-3 pl-4 align-top font-medium text-mineshaft-300">{label}:</td>
|
||||
<td className="w-1/2 px-3 py-3 align-top">
|
||||
<div className="text-red-400 opacity-80">{previousValue}</div>
|
||||
</td>
|
||||
<td className="w-1/2 py-3 pr-4 align-top">
|
||||
<div className="text-green-400">{newValue}</div>
|
||||
</td>
|
||||
</tr>
|
||||
);
|
||||
};
|
||||
|
||||
const ChangeTable: React.FC<ChangeTableProps> = ({
|
||||
change,
|
||||
environment,
|
||||
workspaceId,
|
||||
secretPath
|
||||
}) => {
|
||||
const getChangeBadge = (type: PendingChange["type"]) => {
|
||||
switch (type) {
|
||||
case "create":
|
||||
return <Badge variant="success">Created</Badge>;
|
||||
case "update":
|
||||
return <Badge variant="primary">Updated</Badge>;
|
||||
case "delete":
|
||||
return <Badge variant="danger">Deleted</Badge>;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
const renderSecretChanges = () => {
|
||||
if (change.resourceType !== "secret") return null;
|
||||
|
||||
if (change.type === "create") {
|
||||
return (
|
||||
<div className="mt-3 overflow-hidden rounded-md border border-mineshaft-700 bg-mineshaft-900">
|
||||
<table className="w-full text-sm">
|
||||
<tbody>
|
||||
<tr className="border-b border-mineshaft-700">
|
||||
<td className="w-24 py-3 pl-4 font-medium text-mineshaft-300">Key:</td>
|
||||
<td className="px-3 py-3 font-mono text-mineshaft-100" colSpan={2}>
|
||||
{change.secretKey}
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="border-b border-mineshaft-700">
|
||||
<td className="w-24 py-3 pl-4 font-medium text-mineshaft-300">Value:</td>
|
||||
<td className="px-3 py-3" colSpan={2}>
|
||||
<div className="max-w-md break-all px-2 py-1 font-mono text-xs text-mineshaft-100">
|
||||
{change.secretValue || (
|
||||
<span className="italic text-mineshaft-400">(empty)</span>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{change.secretComment !== undefined && change.secretComment !== "" && (
|
||||
<tr className="border-b border-mineshaft-700">
|
||||
<td className="w-24 py-3 pl-4 font-medium text-mineshaft-300">Comment:</td>
|
||||
<td className="px-3 py-3 text-mineshaft-100" colSpan={2}>
|
||||
{change.secretComment}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{change.tags && change.tags.length > 0 && (
|
||||
<tr className="border-b border-mineshaft-700">
|
||||
<td className="w-24 py-3 pl-4 font-medium text-mineshaft-300">Tags:</td>
|
||||
<td className="px-3 py-3" colSpan={2}>
|
||||
<TagsList tags={change.tags} />
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{change.secretMetadata && change.secretMetadata.length > 0 && (
|
||||
<tr className="border-b border-mineshaft-700 last:border-b-0">
|
||||
<td className="w-24 py-3 pl-4 font-medium text-mineshaft-300">Metadata:</td>
|
||||
<td className="px-3 py-3" colSpan={2}>
|
||||
<MetadataList metadata={change.secretMetadata} />
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (change.type === "update") {
|
||||
const hasKeyChange = change.newSecretName && change.secretKey !== change.newSecretName;
|
||||
const hasValueChange = change.secretValue !== change.originalValue;
|
||||
const hasCommentChange = change.secretComment !== change.originalComment;
|
||||
const hasMultilineChange =
|
||||
change.skipMultilineEncoding !== change.originalSkipMultilineEncoding;
|
||||
const hasTagsChange = JSON.stringify(change.tags) !== JSON.stringify(change.originalTags);
|
||||
const hasMetadataChange =
|
||||
JSON.stringify(change.secretMetadata) !== JSON.stringify(change.originalSecretMetadata);
|
||||
|
||||
const hasChanges = [
|
||||
hasKeyChange,
|
||||
hasValueChange,
|
||||
hasCommentChange,
|
||||
hasMultilineChange,
|
||||
hasTagsChange,
|
||||
hasMetadataChange
|
||||
].some(Boolean);
|
||||
|
||||
if (!hasChanges) return null;
|
||||
|
||||
return (
|
||||
<div className="mt-3 overflow-hidden rounded-md border border-mineshaft-700 bg-mineshaft-900">
|
||||
<table className="w-full text-sm">
|
||||
<tbody>
|
||||
{hasKeyChange && (
|
||||
<ComparisonTableRow
|
||||
label="Key"
|
||||
previousValue={<span className="font-mono">{change.secretKey}</span>}
|
||||
newValue={<span className="font-mono">{change.newSecretName}</span>}
|
||||
/>
|
||||
)}
|
||||
{hasValueChange && (
|
||||
<ComparisonTableRow
|
||||
label="Value"
|
||||
previousValue={
|
||||
<div className="max-w-md break-all rounded">
|
||||
{change.originalValue || <span className="italic">(empty)</span>}
|
||||
</div>
|
||||
}
|
||||
newValue={
|
||||
<div className="max-w-md break-all rounded">
|
||||
{change.secretValue || <span className="italic">(empty)</span>}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{hasCommentChange && (
|
||||
<ComparisonTableRow
|
||||
label="Comment"
|
||||
previousValue={change.originalComment || <span className="italic">(empty)</span>}
|
||||
newValue={change.secretComment || <span className="italic">(empty)</span>}
|
||||
/>
|
||||
)}
|
||||
{hasMultilineChange && (
|
||||
<ComparisonTableRow
|
||||
label="Multiline"
|
||||
previousValue={change.originalSkipMultilineEncoding ? "Enabled" : "Disabled"}
|
||||
newValue={change.skipMultilineEncoding ? "Enabled" : "Disabled"}
|
||||
/>
|
||||
)}
|
||||
{hasTagsChange && (
|
||||
<ComparisonTableRow
|
||||
label="Tags"
|
||||
previousValue={<TagsList tags={change.originalTags} />}
|
||||
newValue={<TagsList tags={change.tags} />}
|
||||
/>
|
||||
)}
|
||||
{hasMetadataChange && (
|
||||
<ComparisonTableRow
|
||||
label="Metadata"
|
||||
previousValue={<MetadataList metadata={change.originalSecretMetadata} />}
|
||||
newValue={<MetadataList metadata={change.secretMetadata} />}
|
||||
/>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (change.type === "delete") {
|
||||
return (
|
||||
<div className="mt-3 overflow-hidden rounded-md border border-red-700 bg-red-900/20">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-red-600 bg-red-800/30">
|
||||
<th className="w-24 py-2 pl-4 text-left text-xs font-medium text-red-300">Field</th>
|
||||
<th className="px-3 py-2 text-left text-xs font-medium text-red-300">
|
||||
Deleted Value
|
||||
</th>
|
||||
<th className="w-8" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr className="border-b border-red-700">
|
||||
<td className="w-24 py-3 pl-4 font-medium text-red-300">Key:</td>
|
||||
<td className="px-3 py-3 font-mono text-red-100 line-through" colSpan={2}>
|
||||
{change.secretKey}
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="border-b border-red-700 last:border-b-0">
|
||||
<td className="w-24 py-3 pl-4 font-medium text-red-300">Value:</td>
|
||||
<td className="px-3 py-3" colSpan={2}>
|
||||
<div className="max-w-md break-all rounded bg-red-800/50 px-2 py-1 font-mono text-xs text-red-100 line-through">
|
||||
{change.secretValue || <span className="italic">(empty)</span>}
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const renderFolderChanges = () => {
|
||||
if (change.resourceType !== "folder") return null;
|
||||
|
||||
if (change.type === "create") {
|
||||
return (
|
||||
<div className="mt-3 overflow-hidden rounded-md border border-mineshaft-700 bg-mineshaft-900">
|
||||
<table className="w-full text-sm">
|
||||
<tbody>
|
||||
<tr className="border-b border-mineshaft-700">
|
||||
<td className="w-24 py-3 pl-4 font-medium text-mineshaft-300">Name:</td>
|
||||
<td className="px-3 py-3 font-mono text-mineshaft-100" colSpan={2}>
|
||||
{change.folderName}
|
||||
</td>
|
||||
</tr>
|
||||
{change.description !== undefined && change.description !== "" && (
|
||||
<tr className="border-b border-mineshaft-700 last:border-b-0">
|
||||
<td className="w-24 py-3 pl-4 font-medium text-mineshaft-300">Description:</td>
|
||||
<td className="px-3 py-3 text-mineshaft-100" colSpan={2}>
|
||||
{change.description}
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (change.type === "update") {
|
||||
const hasNameChange = change.folderName !== change.originalFolderName;
|
||||
const hasDescriptionChange = change.description !== change.originalDescription;
|
||||
|
||||
const hasChanges = [hasNameChange, hasDescriptionChange].some(Boolean);
|
||||
|
||||
if (!hasChanges) return null;
|
||||
|
||||
return (
|
||||
<div className="mt-3 overflow-hidden rounded-md border border-mineshaft-700 bg-mineshaft-900">
|
||||
<table className="w-full text-sm">
|
||||
<tbody>
|
||||
{hasNameChange && (
|
||||
<ComparisonTableRow
|
||||
label="Name"
|
||||
previousValue={<span className="font-mono">{change.originalFolderName}</span>}
|
||||
newValue={<span className="font-mono">{change.folderName}</span>}
|
||||
/>
|
||||
)}
|
||||
{hasDescriptionChange && (
|
||||
<ComparisonTableRow
|
||||
label="Description"
|
||||
previousValue={
|
||||
change.originalDescription || <span className="italic">(empty)</span>
|
||||
}
|
||||
newValue={change.description || <span className="italic">(empty)</span>}
|
||||
/>
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (change.type === "delete") {
|
||||
return (
|
||||
<div className="mt-3 overflow-hidden rounded-md border border-red-700 bg-red-900/20">
|
||||
<table className="w-full text-sm">
|
||||
<thead>
|
||||
<tr className="border-b border-red-600 bg-red-800/30">
|
||||
<th className="w-24 py-2 pl-4 text-left text-xs font-medium text-red-300">Field</th>
|
||||
<th className="px-3 py-2 text-left text-xs font-medium text-red-300">
|
||||
Deleted Value
|
||||
</th>
|
||||
<th className="w-8" />
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr className="border-b border-red-700 last:border-b-0">
|
||||
<td className="w-24 py-3 pl-4 font-medium text-red-300">Name:</td>
|
||||
<td className="px-3 py-3 font-mono text-red-100 line-through" colSpan={2}>
|
||||
{change.folderName}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
const getChangeName = () => {
|
||||
if (change.resourceType === "secret") {
|
||||
return change.type === "update" ? change.newSecretName || change.secretKey : change.secretKey;
|
||||
}
|
||||
if (change.resourceType === "folder") {
|
||||
return change.type === "update" ? change.originalFolderName : change.folderName;
|
||||
}
|
||||
return "Unknown";
|
||||
};
|
||||
|
||||
const { removePendingChange } = useBatchModeActions();
|
||||
|
||||
const handleDeletePending = (changeType: string, id: string) => {
|
||||
removePendingChange(id, changeType, {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="py-2 shadow-sm">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="font-medium text-mineshaft-100">{getChangeName()}</span>
|
||||
{getChangeBadge(change.type)}
|
||||
</div>
|
||||
<IconButton
|
||||
ariaLabel="delete-change"
|
||||
variant="plain"
|
||||
colorSchema="danger"
|
||||
size="sm"
|
||||
onClick={() => handleDeletePending(change.resourceType, change.id)}
|
||||
>
|
||||
<FontAwesomeSymbol symbolName={FontAwesomeSpriteName.Close} className="h-4 w-4" />
|
||||
</IconButton>
|
||||
</div>
|
||||
{change.resourceType === "secret" ? renderSecretChanges() : renderFolderChanges()}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const CommitForm: React.FC<CommitFormProps> = ({
|
||||
onCommit,
|
||||
isCommitting = false,
|
||||
environment,
|
||||
workspaceId,
|
||||
secretPath
|
||||
}) => {
|
||||
const { isBatchMode, pendingChanges, totalChangesCount } = useBatchMode();
|
||||
|
||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||
const [commitMessage, setCommitMessage] = useState("");
|
||||
const { clearAllPendingChanges } = useBatchModeActions();
|
||||
|
||||
if (!isBatchMode || totalChangesCount === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const handleCommit = async () => {
|
||||
if (!commitMessage.trim()) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await onCommit(pendingChanges, commitMessage);
|
||||
clearAllPendingChanges({
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
setIsModalOpen(false);
|
||||
setCommitMessage("");
|
||||
} catch (error) {
|
||||
console.error("Failed to commit changes:", error);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
{/* Floating Panel */}
|
||||
{!isModalOpen && (
|
||||
<div className="fixed bottom-4 z-40 w-80 self-center rounded-lg border border-mineshaft-600 bg-mineshaft-800 shadow-2xl">
|
||||
<div className="flex w-full justify-center border-b border-mineshaft-600 px-4 py-3">
|
||||
<div className="flex w-full items-center justify-between">
|
||||
<div className="flex items-center gap-2">
|
||||
<FontAwesomeIcon icon={faCodeCommit} className="text-primary" />
|
||||
<span className="font-medium text-mineshaft-100">Ready to Commit</span>
|
||||
</div>
|
||||
<Badge variant="primary" className="text-xs">
|
||||
{totalChangesCount} change{totalChangesCount !== 1 ? "s" : ""}
|
||||
</Badge>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="p-3">
|
||||
<Button
|
||||
onClick={() => setIsModalOpen(true)}
|
||||
className="w-full"
|
||||
isDisabled={totalChangesCount === 0}
|
||||
colorSchema="secondary"
|
||||
>
|
||||
Review & Commit
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Commit Modal */}
|
||||
<Modal isOpen={isModalOpen} onOpenChange={setIsModalOpen}>
|
||||
<ModalContent
|
||||
title={
|
||||
<div className="flex items-center gap-2">
|
||||
<FontAwesomeIcon icon={faCodeCommit} className="text-primary" />
|
||||
Commit Changes
|
||||
<Badge variant="primary" className="ml-2">
|
||||
{totalChangesCount} change{totalChangesCount !== 1 ? "s" : ""}
|
||||
</Badge>
|
||||
</div>
|
||||
}
|
||||
className="max-h-[90vh] max-w-5xl"
|
||||
>
|
||||
<div className="space-y-6">
|
||||
<p className="text-mineshaft-300">
|
||||
Write a commit message and review the changes you're about to commit.
|
||||
</p>
|
||||
|
||||
{/* Changes List */}
|
||||
<div className="space-y-6">
|
||||
<div className="max-h-96 space-y-4 overflow-y-auto pr-2">
|
||||
{/* Folder Changes */}
|
||||
{pendingChanges.folders.length > 0 && (
|
||||
<div>
|
||||
<h4 className="mb-4 flex items-center gap-2 border-b border-mineshaft-700 pb-2 text-sm font-semibold text-mineshaft-200">
|
||||
<FontAwesomeIcon icon={faFolder} className="text-mineshaft-300" />
|
||||
Folders ({pendingChanges.folders.length})
|
||||
</h4>
|
||||
<div className="space-y-3">
|
||||
{pendingChanges.folders.map((change) => (
|
||||
<ChangeTable
|
||||
key={change.id}
|
||||
change={change}
|
||||
environment={environment}
|
||||
workspaceId={workspaceId}
|
||||
secretPath={secretPath}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Secret Changes */}
|
||||
{pendingChanges.secrets.length > 0 && (
|
||||
<div>
|
||||
<h4 className="mb-4 flex items-center gap-2 border-b border-mineshaft-700 pb-2 text-sm font-semibold text-mineshaft-200">
|
||||
<FontAwesomeIcon icon={faKey} className="text-mineshaft-300" />
|
||||
Secrets ({pendingChanges.secrets.length})
|
||||
</h4>
|
||||
<div className="space-y-3">
|
||||
{pendingChanges.secrets.map((change) => (
|
||||
<ChangeTable
|
||||
key={change.id}
|
||||
change={change}
|
||||
environment={environment}
|
||||
workspaceId={workspaceId}
|
||||
secretPath={secretPath}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Commit Message */}
|
||||
<div>
|
||||
<label className="mb-2 block text-sm font-medium text-mineshaft-200">
|
||||
Commit Message <span className="text-red-400">*</span>
|
||||
</label>
|
||||
<Input
|
||||
value={commitMessage}
|
||||
onChange={(e) => setCommitMessage(e.target.value)}
|
||||
placeholder="Describe your changes..."
|
||||
className="w-full"
|
||||
required
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Action Buttons */}
|
||||
<div className="flex justify-end gap-3 border-t border-mineshaft-600 pt-4">
|
||||
<Button
|
||||
variant="outline_bg"
|
||||
onClick={() => setIsModalOpen(false)}
|
||||
isDisabled={isCommitting}
|
||||
>
|
||||
Cancel
|
||||
</Button>
|
||||
<Button
|
||||
onClick={handleCommit}
|
||||
isLoading={isCommitting}
|
||||
isDisabled={isCommitting || !commitMessage.trim()}
|
||||
leftIcon={<FontAwesomeIcon icon={faCodeCommit} />}
|
||||
colorSchema="primary"
|
||||
>
|
||||
{isCommitting ? "Committing..." : "Commit Changes"}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1 @@
|
||||
export { CommitForm } from "./CommitForm";
|
||||
+30
-2
@@ -14,7 +14,12 @@ import { getKeyValue } from "@app/helpers/parseEnvVar";
|
||||
import { useCreateSecretV3, useCreateWsTag, useGetWsTags } from "@app/hooks/api";
|
||||
import { SecretType } from "@app/hooks/api/types";
|
||||
|
||||
import { PopUpNames, usePopUpAction } from "../../SecretMainPage.store";
|
||||
import {
|
||||
PendingSecretCreate,
|
||||
PopUpNames,
|
||||
useBatchModeActions,
|
||||
usePopUpAction
|
||||
} from "../../SecretMainPage.store";
|
||||
|
||||
const typeSchema = z.object({
|
||||
key: z.string().trim().min(1, { message: "Secret key is required" }),
|
||||
@@ -31,6 +36,7 @@ type Props = {
|
||||
// modal props
|
||||
autoCapitalize?: boolean;
|
||||
isProtectedBranch?: boolean;
|
||||
isBatchMode?: boolean;
|
||||
};
|
||||
|
||||
export const CreateSecretForm = ({
|
||||
@@ -38,7 +44,8 @@ export const CreateSecretForm = ({
|
||||
workspaceId,
|
||||
secretPath = "/",
|
||||
autoCapitalize = true,
|
||||
isProtectedBranch = false
|
||||
isProtectedBranch = false,
|
||||
isBatchMode = false
|
||||
}: Props) => {
|
||||
const {
|
||||
register,
|
||||
@@ -53,6 +60,7 @@ export const CreateSecretForm = ({
|
||||
|
||||
const { mutateAsync: createSecretV3 } = useCreateSecretV3();
|
||||
const createWsTag = useCreateWsTag();
|
||||
const { addPendingChange } = useBatchModeActions();
|
||||
|
||||
const { permission } = useProjectPermission();
|
||||
const canReadTags = permission.can(ProjectPermissionActions.Read, ProjectPermissionSub.Tags);
|
||||
@@ -85,6 +93,26 @@ export const CreateSecretForm = ({
|
||||
|
||||
const handleFormSubmit = async ({ key, value, tags }: TFormSchema) => {
|
||||
try {
|
||||
if (isBatchMode) {
|
||||
const pendingSecretCreate: PendingSecretCreate = {
|
||||
id: key,
|
||||
type: "create",
|
||||
secretKey: key,
|
||||
secretValue: value || "",
|
||||
secretComment: "",
|
||||
tags: tags?.map((el) => ({ id: el.value, slug: el.label })),
|
||||
timestamp: Date.now(),
|
||||
resourceType: "secret"
|
||||
};
|
||||
addPendingChange(pendingSecretCreate, {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
closePopUp(PopUpNames.CreateSecretForm);
|
||||
reset();
|
||||
return;
|
||||
}
|
||||
await createSecretV3({
|
||||
environment,
|
||||
workspaceId,
|
||||
|
||||
+171
-49
@@ -2,6 +2,7 @@ import { subject } from "@casl/ability";
|
||||
import { faClose, faFolder, faInfoCircle, faPencilSquare } from "@fortawesome/free-solid-svg-icons";
|
||||
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
||||
import { useNavigate, useSearch } from "@tanstack/react-router";
|
||||
import { twMerge } from "tailwind-merge";
|
||||
|
||||
import { createNotification } from "@app/components/notifications";
|
||||
import { ProjectPermissionCan } from "@app/components/permissions";
|
||||
@@ -13,6 +14,13 @@ import { usePopUp } from "@app/hooks";
|
||||
import { useDeleteFolder, useUpdateFolder } from "@app/hooks/api";
|
||||
import { TSecretFolder } from "@app/hooks/api/secretFolders/types";
|
||||
|
||||
import {
|
||||
PendingFolderCreate,
|
||||
PendingFolderDelete,
|
||||
PendingFolderUpdate,
|
||||
useBatchMode,
|
||||
useBatchModeActions
|
||||
} from "../../SecretMainPage.store";
|
||||
import { FolderForm } from "../ActionBar/FolderForm";
|
||||
|
||||
type Props = {
|
||||
@@ -42,10 +50,60 @@ export const FolderListView = ({
|
||||
|
||||
const { mutateAsync: updateFolder } = useUpdateFolder();
|
||||
const { mutateAsync: deleteFolder } = useDeleteFolder();
|
||||
const { isBatchMode } = useBatchMode();
|
||||
const { addPendingChange, removePendingChange } = useBatchModeActions();
|
||||
|
||||
const handleFolderUpdate = async (newFolderName: string, newFolderDescription: string | null) => {
|
||||
const handleFolderUpdate = async (
|
||||
newFolderName: string,
|
||||
newFolderDescription: string | null,
|
||||
oldFolderName?: string,
|
||||
oldFolderDescription?: string
|
||||
) => {
|
||||
try {
|
||||
const { id: folderId } = popUp.updateFolder.data as TSecretFolder;
|
||||
const { id: folderId, pendingAction, isPending } = popUp.updateFolder.data as TSecretFolder;
|
||||
|
||||
if (isBatchMode) {
|
||||
const isEditingPendingCreation = isPending && pendingAction === "create";
|
||||
|
||||
if (isEditingPendingCreation) {
|
||||
const updatedCreate: PendingFolderCreate = {
|
||||
id: folderId,
|
||||
type: "create",
|
||||
folderName: newFolderName,
|
||||
description: newFolderDescription || undefined,
|
||||
parentPath: secretPath,
|
||||
timestamp: Date.now(),
|
||||
resourceType: "folder"
|
||||
};
|
||||
|
||||
addPendingChange(updatedCreate, {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
} else {
|
||||
const updateChange: PendingFolderUpdate = {
|
||||
id: folderId,
|
||||
type: "update",
|
||||
originalFolderName: oldFolderName || "",
|
||||
folderName: newFolderName,
|
||||
originalDescription: oldFolderDescription,
|
||||
description: newFolderDescription || undefined,
|
||||
timestamp: Date.now(),
|
||||
resourceType: "folder"
|
||||
};
|
||||
|
||||
addPendingChange(updateChange, {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
}
|
||||
|
||||
handlePopUpClose("updateFolder");
|
||||
return;
|
||||
}
|
||||
|
||||
await updateFolder({
|
||||
folderId,
|
||||
name: newFolderName,
|
||||
@@ -68,15 +126,45 @@ export const FolderListView = ({
|
||||
}
|
||||
};
|
||||
|
||||
const handleDeletePending = (id: string) => {
|
||||
removePendingChange(id, "folder", {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
};
|
||||
|
||||
const handleFolderDelete = async () => {
|
||||
try {
|
||||
const { id: folderId } = popUp.deleteFolder.data as TSecretFolder;
|
||||
const folderData = popUp.deleteFolder?.data as TSecretFolder;
|
||||
|
||||
if (isBatchMode) {
|
||||
const pendingFolderDelete: PendingFolderDelete = {
|
||||
id: folderData.id,
|
||||
folderName: folderData.name,
|
||||
folderPath: secretPath,
|
||||
resourceType: "folder",
|
||||
type: "delete",
|
||||
timestamp: Date.now()
|
||||
};
|
||||
|
||||
addPendingChange(pendingFolderDelete, {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
|
||||
handlePopUpClose("deleteFolder");
|
||||
return;
|
||||
}
|
||||
|
||||
await deleteFolder({
|
||||
folderId,
|
||||
folderId: folderData.id,
|
||||
path: secretPath,
|
||||
environment,
|
||||
projectId: workspaceId
|
||||
});
|
||||
|
||||
handlePopUpClose("deleteFolder");
|
||||
createNotification({
|
||||
type: "success",
|
||||
@@ -91,7 +179,10 @@ export const FolderListView = ({
|
||||
}
|
||||
};
|
||||
|
||||
const handleFolderClick = (name: string) => {
|
||||
const handleFolderClick = (name: string, isPending?: boolean) => {
|
||||
if (isPending) {
|
||||
return;
|
||||
}
|
||||
const path = `${secretPathQueryparam === "/" ? "" : secretPathQueryparam}/${name}`;
|
||||
navigate({
|
||||
search: (el) => ({ ...el, secretPath: path })
|
||||
@@ -100,10 +191,16 @@ export const FolderListView = ({
|
||||
|
||||
return (
|
||||
<>
|
||||
{folders.map(({ name, id, description }) => (
|
||||
{folders.map(({ name, id, description, pendingAction, isPending }) => (
|
||||
<div
|
||||
key={id}
|
||||
className="group flex cursor-pointer border-b border-mineshaft-600 hover:bg-mineshaft-700"
|
||||
className={twMerge(
|
||||
"group flex cursor-pointer border-b border-mineshaft-600 hover:bg-mineshaft-700",
|
||||
isPending && "bg-mineshaft-700/60",
|
||||
pendingAction === "delete" && "border-l-2 border-l-red-600/75",
|
||||
pendingAction === "update" && "border-l-2 border-l-yellow-600/75",
|
||||
pendingAction === "create" && "border-l-2 border-l-green-600/75"
|
||||
)}
|
||||
>
|
||||
<div className="flex w-11 items-center px-5 py-3 text-yellow-700">
|
||||
<FontAwesomeIcon icon={faFolder} />
|
||||
@@ -113,9 +210,9 @@ export const FolderListView = ({
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onKeyDown={(evt) => {
|
||||
if (evt.key === "Enter") handleFolderClick(name);
|
||||
if (evt.key === "Enter") handleFolderClick(name, isPending);
|
||||
}}
|
||||
onClick={() => handleFolderClick(name)}
|
||||
onClick={() => handleFolderClick(name, isPending)}
|
||||
>
|
||||
{name}
|
||||
{description && (
|
||||
@@ -128,46 +225,71 @@ export const FolderListView = ({
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-center space-x-4 border-l border-mineshaft-600 px-3 py-3">
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Edit}
|
||||
a={subject(ProjectPermissionSub.SecretFolders, { environment, secretPath })}
|
||||
renderTooltip
|
||||
allowedLabel="Edit"
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<IconButton
|
||||
ariaLabel="edit-folder"
|
||||
variant="plain"
|
||||
size="sm"
|
||||
className="p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => handlePopUpOpen("updateFolder", { id, name, description })}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
<FontAwesomeIcon icon={faPencilSquare} size="lg" />
|
||||
</IconButton>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Delete}
|
||||
a={subject(ProjectPermissionSub.SecretFolders, { environment, secretPath })}
|
||||
renderTooltip
|
||||
allowedLabel="Delete"
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<IconButton
|
||||
ariaLabel="delete-folder"
|
||||
variant="plain"
|
||||
size="md"
|
||||
className="p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => handlePopUpOpen("deleteFolder", { id, name })}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
<FontAwesomeIcon icon={faClose} size="lg" />
|
||||
</IconButton>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
</div>
|
||||
{isPending ? (
|
||||
<div className="flex items-center space-x-4 border-l border-mineshaft-600 px-3 py-3">
|
||||
<IconButton
|
||||
ariaLabel="edit-folder"
|
||||
variant="plain"
|
||||
size="sm"
|
||||
className="p-0 opacity-0 group-hover:opacity-100"
|
||||
isDisabled
|
||||
onClick={() => {}}
|
||||
>
|
||||
<FontAwesomeIcon icon={faPencilSquare} size="lg" />
|
||||
</IconButton>
|
||||
|
||||
<IconButton
|
||||
ariaLabel="delete-folder"
|
||||
variant="plain"
|
||||
size="md"
|
||||
className="p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => handleDeletePending(id)}
|
||||
>
|
||||
<FontAwesomeIcon icon={faClose} size="lg" />
|
||||
</IconButton>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex items-center space-x-4 border-l border-mineshaft-600 px-3 py-3">
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Edit}
|
||||
a={subject(ProjectPermissionSub.SecretFolders, { environment, secretPath })}
|
||||
renderTooltip
|
||||
allowedLabel="Edit"
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<IconButton
|
||||
ariaLabel="edit-folder"
|
||||
variant="plain"
|
||||
size="sm"
|
||||
className="p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => handlePopUpOpen("updateFolder", { id, name, description })}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
<FontAwesomeIcon icon={faPencilSquare} size="lg" />
|
||||
</IconButton>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Delete}
|
||||
a={subject(ProjectPermissionSub.SecretFolders, { environment, secretPath })}
|
||||
renderTooltip
|
||||
allowedLabel="Delete"
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<IconButton
|
||||
ariaLabel="delete-folder"
|
||||
variant="plain"
|
||||
size="md"
|
||||
className="p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => handlePopUpOpen("deleteFolder", { id, name })}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
<FontAwesomeIcon icon={faClose} size="lg" />
|
||||
</IconButton>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
))}
|
||||
<Modal
|
||||
|
||||
+336
-273
@@ -57,6 +57,7 @@ import {
|
||||
TFormSchema
|
||||
} from "./SecretListView.utils";
|
||||
import { CollapsibleSecretImports } from "./CollapsibleSecretImports";
|
||||
import { useBatchModeActions } from "../../SecretMainPage.store";
|
||||
|
||||
export const HIDDEN_SECRET_VALUE = "******";
|
||||
export const HIDDEN_SECRET_VALUE_API_MASK = "<hidden-by-infisical>";
|
||||
@@ -86,6 +87,8 @@ type Props = {
|
||||
isImported: boolean;
|
||||
}[];
|
||||
}[];
|
||||
isPending?: boolean;
|
||||
pendingAction?: "create" | "update" | "delete";
|
||||
};
|
||||
|
||||
export const SecretItem = memo(
|
||||
@@ -102,7 +105,9 @@ export const SecretItem = memo(
|
||||
environment,
|
||||
secretPath,
|
||||
handleSecretShare,
|
||||
importedBy
|
||||
importedBy,
|
||||
isPending,
|
||||
pendingAction
|
||||
}: Props) => {
|
||||
const { handlePopUpOpen, handlePopUpToggle, handlePopUpClose, popUp } = usePopUp([
|
||||
"editSecret"
|
||||
@@ -110,6 +115,15 @@ export const SecretItem = memo(
|
||||
const { currentWorkspace } = useWorkspace();
|
||||
const { permission } = useProjectPermission();
|
||||
const { isRotatedSecret } = secret;
|
||||
const { removePendingChange } = useBatchModeActions();
|
||||
|
||||
const handleDeletePending = (pendingSecret: SecretV3RawSanitized) => {
|
||||
removePendingChange(pendingSecret.id, "secret", {
|
||||
workspaceId: currentWorkspace.id,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
};
|
||||
|
||||
const canEditSecretValue = permission.can(
|
||||
ProjectPermissionSecretActions.Edit,
|
||||
@@ -273,14 +287,19 @@ export const SecretItem = memo(
|
||||
className={twMerge(
|
||||
"border-b border-mineshaft-600 bg-mineshaft-800 shadow-none hover:bg-mineshaft-700",
|
||||
isDirty && "border-primary-400/50",
|
||||
isRotatedSecret && "bg-mineshaft-700/60"
|
||||
isRotatedSecret && "bg-mineshaft-700/60",
|
||||
isPending && "bg-mineshaft-700/60",
|
||||
pendingAction === "delete" && "border-l-2 border-l-red-600/75",
|
||||
pendingAction === "update" && "border-l-2 border-l-yellow-600/75",
|
||||
pendingAction === "create" && "border-l-2 border-l-green-600/75"
|
||||
)}
|
||||
>
|
||||
<div className="group flex">
|
||||
<div
|
||||
className={twMerge(
|
||||
"flex h-11 w-11 items-center justify-center px-4 py-3 text-mineshaft-300",
|
||||
isDirty && "text-primary"
|
||||
isDirty && "text-primary",
|
||||
isPending && "ml-[-2px]"
|
||||
)}
|
||||
>
|
||||
{secret.isRotatedSecret ? (
|
||||
@@ -364,7 +383,9 @@ export const SecretItem = memo(
|
||||
control={control}
|
||||
render={({ field }) => (
|
||||
<InfisicalSecretInput
|
||||
isReadOnly={isReadOnly || isRotatedSecret}
|
||||
isReadOnly={
|
||||
isReadOnly || isRotatedSecret || (isPending && pendingAction !== "update")
|
||||
}
|
||||
key="secret-value"
|
||||
isVisible={isVisible && !secretValueHidden}
|
||||
canEditButNotView={secretValueHidden && !isOverriden}
|
||||
@@ -377,275 +398,160 @@ export const SecretItem = memo(
|
||||
)}
|
||||
/>
|
||||
)}
|
||||
<div
|
||||
key="actions"
|
||||
className="flex h-full flex-shrink-0 self-start transition-all group-hover:gap-x-2"
|
||||
>
|
||||
<Tooltip content="Copy secret">
|
||||
<IconButton
|
||||
isDisabled={secret.secretValueHidden}
|
||||
ariaLabel="copy-value"
|
||||
variant="plain"
|
||||
size="sm"
|
||||
className="w-0 overflow-hidden p-0 group-hover:w-5"
|
||||
onClick={copyTokenToClipboard}
|
||||
>
|
||||
<FontAwesomeSymbol
|
||||
className="h-3.5 w-3"
|
||||
symbolName={
|
||||
isSecValueCopied
|
||||
? FontAwesomeSpriteName.Check
|
||||
: FontAwesomeSpriteName.ClipboardCopy
|
||||
}
|
||||
/>
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Edit}
|
||||
a={subject(ProjectPermissionSub.Secrets, {
|
||||
environment,
|
||||
secretPath,
|
||||
secretName,
|
||||
secretTags: selectedTagSlugs
|
||||
})}
|
||||
{pendingAction !== "create" && pendingAction !== "delete" && (
|
||||
<div
|
||||
key="actions"
|
||||
className="flex h-full flex-shrink-0 self-start transition-all group-hover:gap-x-2"
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Modal>
|
||||
<ModalTrigger asChild>
|
||||
<IconButton
|
||||
className="w-0 overflow-hidden p-0 group-hover:w-5"
|
||||
variant="plain"
|
||||
size="md"
|
||||
ariaLabel="reference-tree"
|
||||
isDisabled={!isAllowed || !hasSecretReference(secret?.value)}
|
||||
>
|
||||
<Tooltip
|
||||
content={
|
||||
hasSecretReference(secret?.value)
|
||||
? "Secret Reference Tree"
|
||||
: "Secret does not contain references"
|
||||
}
|
||||
>
|
||||
<FontAwesomeSymbol
|
||||
className="h-3.5 w-3.5"
|
||||
symbolName={FontAwesomeSpriteName.SecretReferenceTree}
|
||||
/>
|
||||
</Tooltip>
|
||||
</IconButton>
|
||||
</ModalTrigger>
|
||||
<ModalContent
|
||||
title="Secret Reference Details"
|
||||
subTitle="Visual breakdown of secrets referenced by this secret."
|
||||
onOpenAutoFocus={(e) => e.preventDefault()} // prevents secret input from displaying value on open
|
||||
>
|
||||
<SecretReferenceTree
|
||||
secretPath={secretPath}
|
||||
environment={environment}
|
||||
secretKey={secret?.key}
|
||||
/>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<DropdownMenu>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Edit}
|
||||
a={subject(ProjectPermissionSub.Secrets, {
|
||||
environment,
|
||||
secretPath,
|
||||
secretName,
|
||||
secretTags: selectedTagSlugs
|
||||
})}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<DropdownMenuTrigger asChild disabled={!isAllowed}>
|
||||
<IconButton
|
||||
ariaLabel="tags"
|
||||
variant="plain"
|
||||
size="sm"
|
||||
className={twMerge(
|
||||
"w-0 overflow-hidden p-0 group-hover:w-5 data-[state=open]:w-5",
|
||||
hasTagsApplied && "w-5 text-primary"
|
||||
)}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
<Tooltip content="Tags">
|
||||
<FontAwesomeSymbol
|
||||
className="h-3.5 w-3.5"
|
||||
symbolName={FontAwesomeSpriteName.Tags}
|
||||
/>
|
||||
</Tooltip>
|
||||
</IconButton>
|
||||
</DropdownMenuTrigger>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Add tags to this secret</DropdownMenuLabel>
|
||||
{tags.map((tag) => {
|
||||
const { id: tagId, slug, color } = tag;
|
||||
|
||||
const isTagSelected = selectedTagsGroupById?.[tagId];
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleTagSelect(tag)}
|
||||
key={`${secret.id}-${tagId}`}
|
||||
icon={
|
||||
isTagSelected && (
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.CheckedCircle}
|
||||
className="h-3 w-3"
|
||||
/>
|
||||
)
|
||||
}
|
||||
iconPos="right"
|
||||
>
|
||||
<div className="flex items-center">
|
||||
<div
|
||||
className="mr-2 h-2 w-2 rounded-full"
|
||||
style={{ background: color || "#bec2c8" }}
|
||||
/>
|
||||
{slug}
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
<DropdownMenuItem className="px-1.5" asChild>
|
||||
<Button
|
||||
size="xs"
|
||||
className="w-full"
|
||||
colorSchema="primary"
|
||||
variant="outline_bg"
|
||||
leftIcon={
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.Tags}
|
||||
className="h-3 w-3"
|
||||
/>
|
||||
}
|
||||
onClick={onCreateTag}
|
||||
>
|
||||
Create a tag
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Edit}
|
||||
a={subject(ProjectPermissionSub.Secrets, {
|
||||
environment,
|
||||
secretPath,
|
||||
secretName,
|
||||
secretTags: selectedTagSlugs
|
||||
})}
|
||||
renderTooltip
|
||||
allowedLabel="Override"
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Tooltip content="Copy secret">
|
||||
<IconButton
|
||||
ariaLabel="override-value"
|
||||
isDisabled={!isAllowed}
|
||||
isDisabled={secret.secretValueHidden}
|
||||
ariaLabel="copy-value"
|
||||
variant="plain"
|
||||
size="sm"
|
||||
onClick={handleOverrideClick}
|
||||
className={twMerge(
|
||||
"w-0 overflow-hidden p-0 group-hover:w-5",
|
||||
isOverriden && "w-5 text-primary"
|
||||
)}
|
||||
className="w-0 overflow-hidden p-0 group-hover:w-5"
|
||||
onClick={copyTokenToClipboard}
|
||||
>
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.Override}
|
||||
className="h-3.5 w-3.5"
|
||||
/>
|
||||
</IconButton>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<Popover>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Edit}
|
||||
a={subject(ProjectPermissionSub.Secrets, {
|
||||
environment,
|
||||
secretPath,
|
||||
secretName,
|
||||
secretTags: selectedTagSlugs
|
||||
})}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<PopoverTrigger asChild disabled={!isAllowed}>
|
||||
<IconButton
|
||||
className={twMerge(
|
||||
"w-0 overflow-hidden p-0 group-hover:w-5",
|
||||
hasComment && "w-5 text-primary"
|
||||
)}
|
||||
variant="plain"
|
||||
size="md"
|
||||
ariaLabel="add-comment"
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
<Tooltip content="Comment">
|
||||
<FontAwesomeSymbol
|
||||
className="h-3.5 w-3.5"
|
||||
symbolName={FontAwesomeSpriteName.Comment}
|
||||
/>
|
||||
</Tooltip>
|
||||
</IconButton>
|
||||
</PopoverTrigger>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<IconButton
|
||||
isDisabled={secret.secretValueHidden || !currentWorkspace.secretSharing}
|
||||
className="w-0 overflow-hidden p-0 group-hover:w-5"
|
||||
variant="plain"
|
||||
size="md"
|
||||
ariaLabel="share-secret"
|
||||
onClick={handleSecretShare}
|
||||
>
|
||||
<Tooltip content="Share Secret">
|
||||
<FontAwesomeSymbol
|
||||
className="h-3.5 w-3.5"
|
||||
symbolName={FontAwesomeSpriteName.ShareSecret}
|
||||
/>
|
||||
</Tooltip>
|
||||
</IconButton>
|
||||
<PopoverContent
|
||||
className="w-auto border border-mineshaft-600 bg-mineshaft-800 p-2 drop-shadow-2xl"
|
||||
sticky="always"
|
||||
>
|
||||
<FormControl label="Comment" className="mb-0">
|
||||
<TextArea
|
||||
className="border border-mineshaft-600 text-sm"
|
||||
rows={8}
|
||||
cols={30}
|
||||
{...register("comment")}
|
||||
/>
|
||||
</FormControl>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
</div>
|
||||
<AnimatePresence mode="wait">
|
||||
{!isDirty ? (
|
||||
<motion.div
|
||||
key="options"
|
||||
className="flex h-10 flex-shrink-0 items-center space-x-4 px-[0.64rem]"
|
||||
initial={{ x: 0, opacity: 0 }}
|
||||
animate={{ x: 0, opacity: 1 }}
|
||||
exit={{ x: 10, opacity: 0 }}
|
||||
>
|
||||
<Tooltip content="More">
|
||||
<IconButton
|
||||
ariaLabel="more"
|
||||
variant="plain"
|
||||
size="md"
|
||||
className="h-5 w-4 p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => onDetailViewSecret(secret)}
|
||||
>
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.More}
|
||||
className="h-5 w-4"
|
||||
className="h-3.5 w-3"
|
||||
symbolName={
|
||||
isSecValueCopied
|
||||
? FontAwesomeSpriteName.Check
|
||||
: FontAwesomeSpriteName.ClipboardCopy
|
||||
}
|
||||
/>
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Delete}
|
||||
I={ProjectPermissionActions.Edit}
|
||||
a={subject(ProjectPermissionSub.Secrets, {
|
||||
environment,
|
||||
secretPath,
|
||||
secretName,
|
||||
secretTags: selectedTagSlugs
|
||||
})}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<Modal>
|
||||
<ModalTrigger asChild>
|
||||
<IconButton
|
||||
className="w-0 overflow-hidden p-0 group-hover:w-5"
|
||||
variant="plain"
|
||||
size="md"
|
||||
ariaLabel="reference-tree"
|
||||
isDisabled={!isAllowed || !hasSecretReference(secret?.value)}
|
||||
>
|
||||
<Tooltip
|
||||
content={
|
||||
hasSecretReference(secret?.value)
|
||||
? "Secret Reference Tree"
|
||||
: "Secret does not contain references"
|
||||
}
|
||||
>
|
||||
<FontAwesomeSymbol
|
||||
className="h-3.5 w-3.5"
|
||||
symbolName={FontAwesomeSpriteName.SecretReferenceTree}
|
||||
/>
|
||||
</Tooltip>
|
||||
</IconButton>
|
||||
</ModalTrigger>
|
||||
<ModalContent
|
||||
title="Secret Reference Details"
|
||||
subTitle="Visual breakdown of secrets referenced by this secret."
|
||||
onOpenAutoFocus={(e) => e.preventDefault()} // prevents secret input from displaying value on open
|
||||
>
|
||||
<SecretReferenceTree
|
||||
secretPath={secretPath}
|
||||
environment={environment}
|
||||
secretKey={secret?.key}
|
||||
/>
|
||||
</ModalContent>
|
||||
</Modal>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<DropdownMenu>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Edit}
|
||||
a={subject(ProjectPermissionSub.Secrets, {
|
||||
environment,
|
||||
secretPath,
|
||||
secretName,
|
||||
secretTags: selectedTagSlugs
|
||||
})}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<DropdownMenuTrigger asChild disabled={!isAllowed}>
|
||||
<IconButton
|
||||
ariaLabel="tags"
|
||||
variant="plain"
|
||||
size="sm"
|
||||
className={twMerge(
|
||||
"w-0 overflow-hidden p-0 group-hover:w-5 data-[state=open]:w-5",
|
||||
hasTagsApplied && "w-5 text-primary"
|
||||
)}
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
<Tooltip content="Tags">
|
||||
<FontAwesomeSymbol
|
||||
className="h-3.5 w-3.5"
|
||||
symbolName={FontAwesomeSpriteName.Tags}
|
||||
/>
|
||||
</Tooltip>
|
||||
</IconButton>
|
||||
</DropdownMenuTrigger>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuLabel>Add tags to this secret</DropdownMenuLabel>
|
||||
{tags.map((tag) => {
|
||||
const { id: tagId, slug, color } = tag;
|
||||
|
||||
const isTagSelected = selectedTagsGroupById?.[tagId];
|
||||
return (
|
||||
<DropdownMenuItem
|
||||
onClick={() => handleTagSelect(tag)}
|
||||
key={`${secret.id}-${tagId}`}
|
||||
icon={
|
||||
isTagSelected && (
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.CheckedCircle}
|
||||
className="h-3 w-3"
|
||||
/>
|
||||
)
|
||||
}
|
||||
iconPos="right"
|
||||
>
|
||||
<div className="flex items-center">
|
||||
<div
|
||||
className="mr-2 h-2 w-2 rounded-full"
|
||||
style={{ background: color || "#bec2c8" }}
|
||||
/>
|
||||
{slug}
|
||||
</div>
|
||||
</DropdownMenuItem>
|
||||
);
|
||||
})}
|
||||
<DropdownMenuItem className="px-1.5" asChild>
|
||||
<Button
|
||||
size="xs"
|
||||
className="w-full"
|
||||
colorSchema="primary"
|
||||
variant="outline_bg"
|
||||
leftIcon={
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.Tags}
|
||||
className="h-3 w-3"
|
||||
/>
|
||||
}
|
||||
onClick={onCreateTag}
|
||||
>
|
||||
Create a tag
|
||||
</Button>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Edit}
|
||||
a={subject(ProjectPermissionSub.Secrets, {
|
||||
environment,
|
||||
secretPath,
|
||||
@@ -653,26 +559,183 @@ export const SecretItem = memo(
|
||||
secretTags: selectedTagSlugs
|
||||
})}
|
||||
renderTooltip
|
||||
allowedLabel={isRotatedSecret ? "Cannot Delete Rotated Secret" : "Delete"} // just using label for isRotatedSecret, disabled below
|
||||
allowedLabel="Override"
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<IconButton
|
||||
ariaLabel="delete-value"
|
||||
ariaLabel="override-value"
|
||||
isDisabled={!isAllowed}
|
||||
variant="plain"
|
||||
colorSchema="danger"
|
||||
size="md"
|
||||
className="p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => onDeleteSecret(secret)}
|
||||
isDisabled={!isAllowed || isRotatedSecret}
|
||||
size="sm"
|
||||
onClick={handleOverrideClick}
|
||||
className={twMerge(
|
||||
"w-0 overflow-hidden p-0 group-hover:w-5",
|
||||
isOverriden && "w-5 text-primary"
|
||||
)}
|
||||
>
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.Close}
|
||||
className="h-5 w-4"
|
||||
symbolName={FontAwesomeSpriteName.Override}
|
||||
className="h-3.5 w-3.5"
|
||||
/>
|
||||
</IconButton>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
</motion.div>
|
||||
<Popover>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Edit}
|
||||
a={subject(ProjectPermissionSub.Secrets, {
|
||||
environment,
|
||||
secretPath,
|
||||
secretName,
|
||||
secretTags: selectedTagSlugs
|
||||
})}
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<PopoverTrigger asChild disabled={!isAllowed}>
|
||||
<IconButton
|
||||
className={twMerge(
|
||||
"w-0 overflow-hidden p-0 group-hover:w-5",
|
||||
hasComment && "w-5 text-primary"
|
||||
)}
|
||||
variant="plain"
|
||||
size="md"
|
||||
ariaLabel="add-comment"
|
||||
isDisabled={!isAllowed}
|
||||
>
|
||||
<Tooltip content="Comment">
|
||||
<FontAwesomeSymbol
|
||||
className="h-3.5 w-3.5"
|
||||
symbolName={FontAwesomeSpriteName.Comment}
|
||||
/>
|
||||
</Tooltip>
|
||||
</IconButton>
|
||||
</PopoverTrigger>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
<IconButton
|
||||
isDisabled={secret.secretValueHidden || !currentWorkspace.secretSharing}
|
||||
className="w-0 overflow-hidden p-0 group-hover:w-5"
|
||||
variant="plain"
|
||||
size="md"
|
||||
ariaLabel="share-secret"
|
||||
onClick={handleSecretShare}
|
||||
>
|
||||
<Tooltip content="Share Secret">
|
||||
<FontAwesomeSymbol
|
||||
className="h-3.5 w-3.5"
|
||||
symbolName={FontAwesomeSpriteName.ShareSecret}
|
||||
/>
|
||||
</Tooltip>
|
||||
</IconButton>
|
||||
<PopoverContent
|
||||
className="w-auto border border-mineshaft-600 bg-mineshaft-800 p-2 drop-shadow-2xl"
|
||||
sticky="always"
|
||||
>
|
||||
<FormControl label="Comment" className="mb-0">
|
||||
<TextArea
|
||||
className="border border-mineshaft-600 text-sm"
|
||||
rows={8}
|
||||
cols={30}
|
||||
{...register("comment")}
|
||||
/>
|
||||
</FormControl>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<AnimatePresence mode="wait">
|
||||
{!isDirty ? (
|
||||
isPending ? (
|
||||
<motion.div
|
||||
key="options"
|
||||
className="flex h-10 flex-shrink-0 items-center space-x-4 px-[0.64rem]"
|
||||
initial={{ x: 0, opacity: 0 }}
|
||||
animate={{ x: 0, opacity: 1 }}
|
||||
exit={{ x: 10, opacity: 0 }}
|
||||
>
|
||||
<Tooltip content="More">
|
||||
<IconButton
|
||||
ariaLabel="more"
|
||||
variant="plain"
|
||||
size="md"
|
||||
className="h-5 w-4 p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => onDetailViewSecret(secret)}
|
||||
isDisabled={pendingAction !== "update"}
|
||||
>
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.More}
|
||||
className="h-5 w-4"
|
||||
/>
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
||||
<IconButton
|
||||
ariaLabel="delete-value"
|
||||
variant="plain"
|
||||
colorSchema="danger"
|
||||
size="md"
|
||||
className="p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => handleDeletePending(secret)}
|
||||
>
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.Close}
|
||||
className="h-5 w-4"
|
||||
/>
|
||||
</IconButton>
|
||||
</motion.div>
|
||||
) : (
|
||||
<motion.div
|
||||
key="options"
|
||||
className="flex h-10 flex-shrink-0 items-center space-x-4 px-[0.64rem]"
|
||||
initial={{ x: 0, opacity: 0 }}
|
||||
animate={{ x: 0, opacity: 1 }}
|
||||
exit={{ x: 10, opacity: 0 }}
|
||||
>
|
||||
<Tooltip content="More">
|
||||
<IconButton
|
||||
ariaLabel="more"
|
||||
variant="plain"
|
||||
size="md"
|
||||
className="h-5 w-4 p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => onDetailViewSecret(secret)}
|
||||
>
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.More}
|
||||
className="h-5 w-4"
|
||||
/>
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<ProjectPermissionCan
|
||||
I={ProjectPermissionActions.Delete}
|
||||
a={subject(ProjectPermissionSub.Secrets, {
|
||||
environment,
|
||||
secretPath,
|
||||
secretName,
|
||||
secretTags: selectedTagSlugs
|
||||
})}
|
||||
renderTooltip
|
||||
allowedLabel={isRotatedSecret ? "Cannot Delete Rotated Secret" : "Delete"} // just using label for isRotatedSecret, disabled below
|
||||
>
|
||||
{(isAllowed) => (
|
||||
<IconButton
|
||||
ariaLabel="delete-value"
|
||||
variant="plain"
|
||||
colorSchema="danger"
|
||||
size="md"
|
||||
className="p-0 opacity-0 group-hover:opacity-100"
|
||||
onClick={() => onDeleteSecret(secret)}
|
||||
isDisabled={!isAllowed || isRotatedSecret}
|
||||
>
|
||||
<FontAwesomeSymbol
|
||||
symbolName={FontAwesomeSpriteName.Close}
|
||||
className="h-5 w-4"
|
||||
/>
|
||||
</IconButton>
|
||||
)}
|
||||
</ProjectPermissionCan>
|
||||
</motion.div>
|
||||
)
|
||||
) : (
|
||||
<motion.div
|
||||
key="options-save"
|
||||
|
||||
+175
-15
@@ -17,7 +17,16 @@ import { secretSnapshotKeys } from "@app/hooks/api/secretSnapshots/queries";
|
||||
import { WsTag } from "@app/hooks/api/types";
|
||||
import { AddShareSecretModal } from "@app/pages/organization/SecretSharingPage/components/ShareSecret/AddShareSecretModal";
|
||||
|
||||
import { useSelectedSecretActions, useSelectedSecrets } from "../../SecretMainPage.store";
|
||||
import {
|
||||
PendingSecretChange,
|
||||
PendingSecretCreate,
|
||||
PendingSecretDelete,
|
||||
PendingSecretUpdate,
|
||||
useBatchMode,
|
||||
useBatchModeActions,
|
||||
useSelectedSecretActions,
|
||||
useSelectedSecrets
|
||||
} from "../../SecretMainPage.store";
|
||||
import { CollapsibleSecretImports } from "./CollapsibleSecretImports";
|
||||
import { SecretDetailSidebar } from "./SecretDetailSidebar";
|
||||
import { HIDDEN_SECRET_VALUE, HIDDEN_SECRET_VALUE_API_MASK, SecretItem } from "./SecretItem";
|
||||
@@ -63,22 +72,19 @@ export const SecretListView = ({
|
||||
|
||||
// strip of side effect queries
|
||||
const { mutateAsync: createSecretV3 } = useCreateSecretV3({
|
||||
options: {
|
||||
onSuccess: undefined
|
||||
}
|
||||
options: { onSuccess: undefined }
|
||||
});
|
||||
const { mutateAsync: updateSecretV3 } = useUpdateSecretV3({
|
||||
options: {
|
||||
onSuccess: undefined
|
||||
}
|
||||
options: { onSuccess: undefined }
|
||||
});
|
||||
const { mutateAsync: deleteSecretV3 } = useDeleteSecretV3({
|
||||
options: {
|
||||
onSuccess: undefined
|
||||
}
|
||||
options: { onSuccess: undefined }
|
||||
});
|
||||
|
||||
const selectedSecrets = useSelectedSecrets();
|
||||
const { toggle: toggleSelectedSecret } = useSelectedSecretActions();
|
||||
const { isBatchMode, pendingChanges } = useBatchMode();
|
||||
const { addPendingChange } = useBatchModeActions();
|
||||
|
||||
const handleSecretOperation = async (
|
||||
operation: "create" | "update" | "delete",
|
||||
@@ -170,11 +176,56 @@ export const SecretListView = ({
|
||||
);
|
||||
};
|
||||
|
||||
function getTrueOriginalSecret(
|
||||
currentSecret: SecretV3RawSanitized,
|
||||
pendingSecrets: PendingSecretChange[]
|
||||
): Omit<SecretV3RawSanitized, "tags"> & {
|
||||
tags?: { id: string; slug: string }[];
|
||||
} {
|
||||
// Find if there's already a pending change for this secret
|
||||
const existingChange = pendingSecrets.find((change) => change.id === currentSecret.id);
|
||||
|
||||
if (!existingChange || existingChange.type === "create") {
|
||||
// If no existing change or it's a creation, current secret is the original
|
||||
return {
|
||||
...currentSecret,
|
||||
tags: currentSecret.tags?.map((tag) => ({
|
||||
id: tag.id,
|
||||
slug: tag.slug
|
||||
}))
|
||||
};
|
||||
}
|
||||
|
||||
if (existingChange.type === "update") {
|
||||
// If there's an existing update, reconstruct the original from the stored original values
|
||||
return {
|
||||
...currentSecret,
|
||||
key: existingChange.secretKey, // Original key
|
||||
value: existingChange.originalValue || currentSecret.value,
|
||||
comment: existingChange.originalComment || currentSecret.comment,
|
||||
skipMultilineEncoding:
|
||||
existingChange.originalSkipMultilineEncoding ?? currentSecret.skipMultilineEncoding,
|
||||
tags:
|
||||
existingChange.originalTags?.map((tag) => ({
|
||||
id: tag.id,
|
||||
slug: tag.slug
|
||||
})) || currentSecret.tags,
|
||||
secretMetadata: existingChange.originalSecretMetadata || currentSecret.secretMetadata
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
...currentSecret,
|
||||
tags: currentSecret.tags?.map((tag) => ({ id: tag.id, slug: tag.slug }))
|
||||
};
|
||||
}
|
||||
|
||||
// Improved handleSaveSecret function
|
||||
const handleSaveSecret = useCallback(
|
||||
async (
|
||||
orgSecret: SecretV3RawSanitized,
|
||||
modSecret: Omit<SecretV3RawSanitized, "tags"> & {
|
||||
tags?: { id: string }[];
|
||||
tags?: { id: string; name?: string }[];
|
||||
secretMetadata?: { key: string; value: string }[];
|
||||
},
|
||||
cb?: () => void
|
||||
@@ -192,7 +243,9 @@ export const SecretListView = ({
|
||||
reminderNote,
|
||||
reminderRecipients,
|
||||
secretMetadata,
|
||||
isReminderEvent
|
||||
isReminderEvent,
|
||||
isPending,
|
||||
pendingAction
|
||||
} = modSecret;
|
||||
const hasKeyChanged = oldKey !== key && key;
|
||||
|
||||
@@ -246,6 +299,79 @@ export const SecretListView = ({
|
||||
|
||||
// shared secret change
|
||||
if (!isSharedSecUnchanged && !personalAction) {
|
||||
if (isBatchMode) {
|
||||
const isEditingPendingCreation = isPending && pendingAction === "create";
|
||||
|
||||
if (isEditingPendingCreation) {
|
||||
const updatedCreate: PendingSecretCreate = {
|
||||
id: orgSecret.id,
|
||||
type: "create",
|
||||
secretKey: key,
|
||||
secretValue: value || "",
|
||||
secretComment: comment || "",
|
||||
skipMultilineEncoding: modSecret.skipMultilineEncoding || false,
|
||||
tags: tags?.map((tag) => ({ id: tag.id, slug: tag.name || "" })) || [],
|
||||
secretMetadata: secretMetadata || [],
|
||||
timestamp: Date.now(),
|
||||
resourceType: "secret",
|
||||
originalKey: oldKey
|
||||
};
|
||||
|
||||
addPendingChange(updatedCreate, {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
} else {
|
||||
const trueOriginalSecret = getTrueOriginalSecret(orgSecret, pendingChanges.secrets);
|
||||
|
||||
const updateChange: PendingSecretUpdate = {
|
||||
id: orgSecret.id,
|
||||
type: "update",
|
||||
secretKey: trueOriginalSecret.key,
|
||||
...(key !== trueOriginalSecret.key && { newSecretName: key }),
|
||||
...(value !== trueOriginalSecret.value && {
|
||||
originalValue: trueOriginalSecret.value,
|
||||
secretValue: value
|
||||
}),
|
||||
...(comment !== trueOriginalSecret.comment && {
|
||||
originalComment: trueOriginalSecret.comment,
|
||||
secretComment: comment
|
||||
}),
|
||||
...(modSecret.skipMultilineEncoding !==
|
||||
trueOriginalSecret.skipMultilineEncoding && {
|
||||
originalSkipMultilineEncoding: trueOriginalSecret.skipMultilineEncoding,
|
||||
skipMultilineEncoding: modSecret.skipMultilineEncoding
|
||||
}),
|
||||
...(!isSameTags && {
|
||||
originalTags:
|
||||
trueOriginalSecret.tags?.map((tag) => ({ id: tag.id, slug: tag.slug })) || [],
|
||||
tags: tags?.map((tag) => ({ id: tag.id, slug: tag.name || "" })) || []
|
||||
}),
|
||||
...(JSON.stringify(secretMetadata) !==
|
||||
JSON.stringify(trueOriginalSecret.secretMetadata) && {
|
||||
originalSecretMetadata: trueOriginalSecret.secretMetadata || [],
|
||||
secretMetadata: secretMetadata || []
|
||||
}),
|
||||
|
||||
timestamp: Date.now(),
|
||||
resourceType: "secret"
|
||||
};
|
||||
|
||||
addPendingChange(updateChange, {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
}
|
||||
|
||||
if (!isReminderEvent) {
|
||||
handlePopUpClose("secretDetail");
|
||||
}
|
||||
if (cb) cb();
|
||||
return;
|
||||
}
|
||||
|
||||
await handleSecretOperation("update", SecretType.Shared, oldKey, {
|
||||
value,
|
||||
tags: tagIds,
|
||||
@@ -314,12 +440,41 @@ export const SecretListView = ({
|
||||
});
|
||||
}
|
||||
},
|
||||
[environment, secretPath, isProtectedBranch]
|
||||
[
|
||||
environment,
|
||||
secretPath,
|
||||
isProtectedBranch,
|
||||
isBatchMode,
|
||||
workspaceId,
|
||||
addPendingChange,
|
||||
pendingChanges.secrets
|
||||
]
|
||||
);
|
||||
|
||||
const handleSecretDelete = useCallback(async () => {
|
||||
const { key, id: secretId } = popUp.deleteSecret?.data as SecretV3RawSanitized;
|
||||
const { key, id: secretId, value } = popUp.deleteSecret?.data as SecretV3RawSanitized;
|
||||
try {
|
||||
if (isBatchMode) {
|
||||
const deleteChange: PendingSecretDelete = {
|
||||
id: `${secretId}`,
|
||||
type: "delete",
|
||||
secretKey: key,
|
||||
secretValue: value || "",
|
||||
timestamp: Date.now(),
|
||||
resourceType: "secret"
|
||||
};
|
||||
|
||||
addPendingChange(deleteChange, {
|
||||
workspaceId,
|
||||
environment,
|
||||
secretPath
|
||||
});
|
||||
|
||||
handlePopUpClose("deleteSecret");
|
||||
handlePopUpClose("secretDetail");
|
||||
return;
|
||||
}
|
||||
|
||||
await handleSecretOperation("delete", SecretType.Shared, key, { secretId });
|
||||
// wrap this in another function and then reuse
|
||||
queryClient.invalidateQueries({
|
||||
@@ -362,7 +517,10 @@ export const SecretListView = ({
|
||||
(popUp.deleteSecret?.data as SecretV3RawSanitized)?.key,
|
||||
environment,
|
||||
secretPath,
|
||||
isProtectedBranch
|
||||
isProtectedBranch,
|
||||
isBatchMode,
|
||||
workspaceId,
|
||||
addPendingChange
|
||||
]);
|
||||
|
||||
// for optimization on minimise re-rendering of secret items
|
||||
@@ -401,6 +559,8 @@ export const SecretListView = ({
|
||||
value: secret.valueOverride ?? secret.value
|
||||
})
|
||||
}
|
||||
isPending={secret.isPending}
|
||||
pendingAction={secret.pendingAction}
|
||||
/>
|
||||
))}
|
||||
<DeleteActionModal
|
||||
|
||||
Reference in New Issue
Block a user