Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(ui): fixed lagging issues with new dashboard

akhilmhdh82995fbd020b
diff --git a/frontend/src/components/navigation/NavHeader.tsx b/frontend/src/components/navigation/NavHeader.tsx
index c8af1ce465..d807b45b73 100644
--- a/frontend/src/components/navigation/NavHeader.tsx
+++ b/frontend/src/components/navigation/NavHeader.tsx
@@ -1,3 +1,4 @@
+import Link from 'next/link';
import { useRouter } from 'next/router';
import { faAngleRight } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
@@ -21,6 +22,7 @@ import { Select, SelectItem, Tooltip } from '../v2';
* @param {string} obj.onEnvChange - the action that happens when an env is changed
* @returns
*/
+// TODO(akhilmhdh): simply this header and nav system later
export default function NavHeader({
pageName,
isProjectRelated,
@@ -38,7 +40,7 @@ export default function NavHeader({
}): JSX.Element {
const { currentWorkspace } = useWorkspace();
const { currentOrg } = useOrganization();
- const router = useRouter()
+ const router = useRouter();
return (
<div className="ml-6 flex flex-row items-center pt-8">
@@ -59,31 +61,40 @@ export default function NavHeader({
</>
)}
<FontAwesomeIcon icon={faAngleRight} className="ml-3 mr-3 text-sm text-gray-400" />
- {pageName === 'Secrets'
- ? <a className="text-sm font-semibold text-primary/80 hover:text-primary" href={`${router.asPath.split("?")[0]}`}>{pageName}</a>
- : <div className="text-sm text-gray-400">{pageName}</div>}
- {currentEnv &&
- <>
- <FontAwesomeIcon icon={faAngleRight} className="ml-3 mr-1.5 text-xs text-gray-400" />
- <div className='pl-3 rounded-md hover:bg-bunker-100/10'>
- <Tooltip content="Select environment">
- <Select
- value={userAvailableEnvs?.filter(uae => uae.name === currentEnv)[0]?.slug}
- onValueChange={(value) => {
- if (value && onEnvChange) onEnvChange(value);
- }}
- className="text-sm pl-0 font-medium text-primary/80 hover:text-primary bg-transparent"
- dropdownContainerClassName="text-bunker-200 bg-mineshaft-800 border border-mineshaft-600 drop-shadow-2xl"
- >
- {userAvailableEnvs?.map(({ name, slug }) => (
- <SelectItem value={slug} key={slug}>
- {name}
- </SelectItem>
- ))}
- </Select>
- </Tooltip>
- </div>
- </>}
+ {pageName === 'Secrets' ? (
+ <Link
+ passHref
+ legacyBehavior
+ href={{ pathname: '/dashboard/[id]', query: { id: router.query.id } }}
+ >
+ <a className="text-sm font-semibold text-primary/80 hover:text-primary">{pageName}</a>
+ </Link>
+ ) : (
+ <div className="text-sm text-gray-400">{pageName}</div>
+ )}
+ {currentEnv && (
+ <>
+ <FontAwesomeIcon icon={faAngleRight} className="ml-3 mr-1.5 text-xs text-gray-400" />
+ <div className="rounded-md pl-3 hover:bg-bunker-100/10">
+ <Tooltip content="Select environment">
+ <Select
+ value={userAvailableEnvs?.filter((uae) => uae.name === currentEnv)[0]?.slug}
+ onValueChange={(value) => {
+ if (value && onEnvChange) onEnvChange(value);
+ }}
+ className="bg-transparent pl-0 text-sm font-medium text-primary/80 hover:text-primary"
+ dropdownContainerClassName="text-bunker-200 bg-mineshaft-800 border border-mineshaft-600 drop-shadow-2xl"
+ >
+ {userAvailableEnvs?.map(({ name, slug }) => (
+ <SelectItem value={slug} key={slug}>
+ {name}
+ </SelectItem>
+ ))}
+ </Select>
+ </Tooltip>
+ </div>
+ </>
+ )}
</div>
);
}
diff --git a/frontend/src/hooks/api/secrets/index.ts b/frontend/src/hooks/api/secrets/index.ts
index c27cecfb1c..013b9aef52 100644
--- a/frontend/src/hooks/api/secrets/index.ts
+++ b/frontend/src/hooks/api/secrets/index.ts
@@ -1 +1,6 @@
-export { useBatchSecretsOp, useGetProjectSecrets, useGetSecretVersion } from './queries';
+export {
+ useBatchSecretsOp,
+ useGetProjectSecrets,
+ useGetProjectSecretsByKey,
+ useGetSecretVersion
+} from './queries';
diff --git a/frontend/src/hooks/api/secrets/queries.tsx b/frontend/src/hooks/api/secrets/queries.tsx
index 031c661d1e..ecc26c63dd 100644
--- a/frontend/src/hooks/api/secrets/queries.tsx
+++ b/frontend/src/hooks/api/secrets/queries.tsx
@@ -19,7 +19,10 @@ import {
export const secretKeys = {
// this is also used in secretSnapshot part
- getProjectSecret: (workspaceId: string, env: string | string[]) => [{ workspaceId, env }, 'secrets'],
+ getProjectSecret: (workspaceId: string, env: string | string[]) => [
+ { workspaceId, env },
+ 'secrets'
+ ],
getSecretVersion: (secretId: string) => [{ secretId }, 'secret-versions']
};
@@ -32,11 +35,11 @@ const fetchProjectEncryptedSecrets = async (workspaceId: string, env: string | s
}
});
return data.secrets;
- }
-
+ }
+
if (typeof env === 'object') {
let allEnvData: any = [];
-
+
// eslint-disable-next-line no-restricted-syntax
for (const envPoint of env) {
// eslint-disable-next-line no-await-in-loop
@@ -48,13 +51,12 @@ const fetchProjectEncryptedSecrets = async (workspaceId: string, env: string | s
});
allEnvData = allEnvData.concat(data.secrets);
}
-
+
return allEnvData;
- // eslint-disable-next-line no-else-return
+ // eslint-disable-next-line no-else-return
} else {
return null;
}
-
};
export const useGetProjectSecrets = ({
@@ -117,7 +119,10 @@ export const useGetProjectSecrets = ({
};
if (encSecret.type === 'personal') {
- personalSecrets[`${decryptedSecret.key}-${decryptedSecret.env}`] = { id: encSecret._id, value: secretValue };
+ personalSecrets[`${decryptedSecret.key}-${decryptedSecret.env}`] = {
+ id: encSecret._id,
+ value: secretValue
+ };
} else {
if (!duplicateSecretKey?.[`${decryptedSecret.key}-${decryptedSecret.env}`]) {
sharedSecrets.push(decryptedSecret);
@@ -126,17 +131,106 @@ export const useGetProjectSecrets = ({
}
});
sharedSecrets.forEach((val) => {
- if (personalSecrets?.[val.key]) {
- val.idOverride = personalSecrets[val.key].id;
- val.valueOverride = personalSecrets[val.key].value;
+ const dupKey = `${val.key}-${val.env}`;
+ if (personalSecrets?.[dupKey]) {
+ val.idOverride = personalSecrets[dupKey].id;
+ val.valueOverride = personalSecrets[dupKey].value;
val.overrideAction = 'modified';
}
});
-
return { secrets: sharedSecrets };
}
});
+export const useGetProjectSecretsByKey = ({
+ workspaceId,
+ env,
+ decryptFileKey,
+ isPaused
+}: GetProjectSecretsDTO) =>
+ useQuery({
+ // wait for all values to be available
+ enabled: Boolean(decryptFileKey && workspaceId && env) && !isPaused,
+ queryKey: secretKeys.getProjectSecret(workspaceId, env),
+ queryFn: () => fetchProjectEncryptedSecrets(workspaceId, env),
+ select: (data) => {
+ const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY') as string;
+ const latestKey = decryptFileKey;
+ const key = decryptAssymmetric({
+ ciphertext: latestKey.encryptedKey,
+ nonce: latestKey.nonce,
+ publicKey: latestKey.sender.publicKey,
+ privateKey: PRIVATE_KEY
+ });
+
+ const sharedSecrets: Record<string, DecryptedSecret[]> = {};
+ const personalSecrets: Record<string, { id: string; value: string }> = {};
+ // this used for add-only mode in dashboard
+ // type won't be there thus only one key is shown
+ const duplicateSecretKey: Record<string, boolean> = {};
+ const uniqSecKeys: Record<string, boolean> = {};
+ data.forEach((encSecret: EncryptedSecret) => {
+ const secretKey = decryptSymmetric({
+ ciphertext: encSecret.secretKeyCiphertext,
+ iv: encSecret.secretKeyIV,
+ tag: encSecret.secretKeyTag,
+ key
+ });
+ if (!uniqSecKeys?.[secretKey]) uniqSecKeys[secretKey] = true;
+
+ const secretValue = decryptSymmetric({
+ ciphertext: encSecret.secretValueCiphertext,
+ iv: encSecret.secretValueIV,
+ tag: encSecret.secretValueTag,
+ key
+ });
+
+ const secretComment = decryptSymmetric({
+ ciphertext: encSecret.secretCommentCiphertext,
+ iv: encSecret.secretCommentIV,
+ tag: encSecret.secretCommentTag,
+ key
+ });
+
+ const decryptedSecret = {
+ _id: encSecret._id,
+ env: encSecret.environment,
+ key: secretKey,
+ value: secretValue,
+ tags: encSecret.tags,
+ comment: secretComment,
+ createdAt: encSecret.createdAt,
+ updatedAt: encSecret.updatedAt
+ };
+
+ if (encSecret.type === 'personal') {
+ personalSecrets[`${decryptedSecret.key}-${decryptedSecret.env}`] = {
+ id: encSecret._id,
+ value: secretValue
+ };
+ } else {
+ if (!duplicateSecretKey?.[`${decryptedSecret.key}-${decryptedSecret.env}`]) {
+ if (!sharedSecrets?.[secretKey]) sharedSecrets[secretKey] = [];
+ sharedSecrets[secretKey].push(decryptedSecret);
+ }
+ duplicateSecretKey[`${decryptedSecret.key}-${decryptedSecret.env}`] = true;
+ }
+ });
+ Object.keys(sharedSecrets).forEach((secName) => {
+ sharedSecrets[secName].forEach((val) => {
+ const dupKey = `${val.key}-${val.env}`;
+ if (personalSecrets?.[dupKey]) {
+ val.idOverride = personalSecrets[dupKey].id;
+ val.valueOverride = personalSecrets[dupKey].value;
+ val.overrideAction = 'modified';
+ }
+ });
+ });
+
+ return { secrets: sharedSecrets, uniqueSecCount: Object.keys(uniqSecKeys).length };
+ }
+ });
+
const fetchEncryptedSecretVersion = async (secretId: string, offset: number, limit: number) => {
const { data } = await apiRequest.get<{ secretVersions: EncryptedSecretVersion[] }>(
`/api/v1/secret/${secretId}/secret-versions`,
diff --git a/frontend/src/hooks/api/secrets/types.ts b/frontend/src/hooks/api/secrets/types.ts
index 567fecc9a4..eb1157e914 100644
--- a/frontend/src/hooks/api/secrets/types.ts
+++ b/frontend/src/hooks/api/secrets/types.ts
@@ -62,6 +62,7 @@ type SecretTagArg = { _id: string; name: string; slug: string };
export type UpdateSecretArg = {
_id: string;
type: 'shared' | 'personal';
+ secretName: string;
secretKeyCiphertext: string;
secretKeyIV: string;
secretKeyTag: string;
diff --git a/frontend/src/layouts/AppLayout/AppLayout.tsx b/frontend/src/layouts/AppLayout/AppLayout.tsx
index 39a80b7b48..4c1f15ebdf 100644
--- a/frontend/src/layouts/AppLayout/AppLayout.tsx
+++ b/frontend/src/layouts/AppLayout/AppLayout.tsx
@@ -8,11 +8,7 @@ import { Controller, useForm } from 'react-hook-form';
import Link from 'next/link';
import { useRouter } from 'next/router';
import { useTranslation } from 'next-i18next';
-import {
- faBookOpen,
- faMobile,
- faPlus,
-} from '@fortawesome/free-solid-svg-icons';
+import { faBookOpen, faMobile, faPlus } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { yupResolver } from '@hookform/resolvers/yup';
import queryString from 'query-string';
@@ -110,7 +106,6 @@ export const AppLayout = ({ children }: LayoutProps) => {
) {
router.push('/noprojects');
} else if (router.asPath !== '/noprojects') {
-
// const pathSegments = router.asPath.split('/').filter(segment => segment.length > 0);
// let intendedWorkspaceId;
@@ -123,8 +118,8 @@ export const AppLayout = ({ children }: LayoutProps) => {
// .split('/')
// [router.asPath.split('/').length - 1].split('?')[0];
// }
-
- const pathSegments = router.asPath.split('/').filter(segment => segment.length > 0);
+
+ const pathSegments = router.asPath.split('/').filter((segment) => segment.length > 0);
let intendedWorkspaceId;
if (pathSegments.length >= 2 && pathSegments[0] === 'dashboard') {
@@ -140,7 +135,7 @@ export const AppLayout = ({ children }: LayoutProps) => {
// const lastPathSegment = router.asPath.split('/').pop().split('?');
// [intendedWorkspaceId] = lastPathSegment;
}
-
+
if (!intendedWorkspaceId) return;
if (!['callback', 'create', 'authorize'].includes(intendedWorkspaceId)) {
@@ -149,7 +144,8 @@ export const AppLayout = ({ children }: LayoutProps) => {
// If a user is not a member of a workspace they are trying to access, just push them to one of theirs
if (
- !['callback', 'create', 'authorize'].includes(intendedWorkspaceId) && userWorkspaces[0]?._id !== undefined &&
+ !['callback', 'create', 'authorize'].includes(intendedWorkspaceId) &&
+ userWorkspaces[0]?._id !== undefined &&
!userWorkspaces
.map((workspace: { _id: string }) => workspace._id)
.includes(intendedWorkspaceId)
@@ -240,21 +236,21 @@ export const AppLayout = ({ children }: LayoutProps) => {
return (
<>
- <div className="hidden h-screen w-full flex-col overflow-x-hidden md:flex dark">
+ <div className="dark hidden h-screen w-full flex-col overflow-x-hidden md:flex">
<Navbar />
<div className="flex flex-grow flex-col overflow-y-hidden md:flex-row">
<aside className="w-full border-r border-mineshaft-600 bg-gradient-to-tr from-mineshaft-700 via-mineshaft-800 to-mineshaft-900 md:w-60">
<nav className="items-between flex h-full flex-col justify-between">
<div>
{currentWorkspace ? (
- <div className="w-full p-4 mt-3 mb-4">
- <p className="text-xs font-semibold ml-1.5 mb-1 uppercase text-gray-400">
+ <div className="mt-3 mb-4 w-full p-4">
+ <p className="ml-1.5 mb-1 text-xs font-semibold uppercase text-gray-400">
Project
</p>
<Select
defaultValue={currentWorkspace?._id}
value={currentWorkspace?._id}
- className="w-full py-2.5 bg-mineshaft-600 font-medium truncate"
+ className="w-full truncate bg-mineshaft-600 py-2.5 font-medium"
onValueChange={(value) => {
router.push(`/dashboard/${value}`);
}}
@@ -273,7 +269,7 @@ export const AppLayout = ({ children }: LayoutProps) => {
{/* <hr className="mt-1 mb-1 h-px border-0 bg-gray-700" /> */}
<div className="w-full">
<Button
- className="w-full py-2 text-bunker-200 bg-mineshaft-700"
+ className="w-full bg-mineshaft-700 py-2 text-bunker-200"
colorSchema="primary"
variant="outline_bg"
size="sm"
@@ -286,9 +282,9 @@ export const AppLayout = ({ children }: LayoutProps) => {
</Select>
</div>
) : (
- <div className="w-full p-4 mt-3 mb-4">
+ <div className="mt-3 mb-4 w-full p-4">
<Button
- className="w-full py-2 text-bunker-200 bg-mineshaft-500 hover:bg-primary/90 hover:text-black"
+ className="w-full bg-mineshaft-500 py-2 text-bunker-200 hover:bg-primary/90 hover:text-black"
color="mineshaft"
size="sm"
onClick={() => handlePopUpOpen('addNewWs')}
@@ -331,13 +327,13 @@ export const AppLayout = ({ children }: LayoutProps) => {
</a>
</Link>
<Link href={`/activity/${currentWorkspace?._id}`} passHref>
- <MenuItem
- isSelected={router.asPath === `/activity/${currentWorkspace?._id}`}
- // icon={<FontAwesomeIcon icon={faFileLines} size="lg" />}
- icon="system-outline-168-view-headline"
- >
- Audit Logs
- </MenuItem>
+ <MenuItem
+ isSelected={router.asPath === `/activity/${currentWorkspace?._id}`}
+ // icon={<FontAwesomeIcon icon={faFileLines} size="lg" />}
+ icon="system-outline-168-view-headline"
+ >
+ Audit Logs
+ </MenuItem>
</Link>
<Link href={`/settings/project/${currentWorkspace?._id}`} passHref>
<a>
@@ -428,7 +424,7 @@ export const AppLayout = ({ children }: LayoutProps) => {
</FormControl>
)}
/>
- <div className="pl-1 mt-4">
+ <div className="mt-4 pl-1">
<Controller
control={control}
name="addMembers"
diff --git a/frontend/src/pages/dashboard/[id].tsx b/frontend/src/pages/dashboard/[id].tsx
index 9f5a0e7657..d8edf87fcd 100644
--- a/frontend/src/pages/dashboard/[id].tsx
+++ b/frontend/src/pages/dashboard/[id].tsx
@@ -1,1229 +1,44 @@
-/* eslint-disable no-nested-ternary */
-import { UIEvent, useCallback, useEffect, useRef, useState } from 'react';
+import { useTranslation } from 'react-i18next';
import Head from 'next/head';
-import Image from 'next/image';
import { useRouter } from 'next/router';
-import { useTranslation } from 'next-i18next';
-import {
- faArrowDown,
- faArrowLeft,
- faArrowUp,
- faCheck,
- faClockRotateLeft,
- faEye,
- faEyeSlash,
- faFolderOpen,
- faMagnifyingGlass,
- faPlus,
- faXmark
-} from '@fortawesome/free-solid-svg-icons';
-import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-import { Tag } from 'public/data/frequentInterfaces';
-import queryString from 'query-string';
-import Button from '@app/components/basic/buttons/Button';
-import BottonRightPopup from '@app/components/basic/popups/BottomRightPopup';
-import { useNotificationContext } from '@app/components/context/Notifications/NotificationProvider';
-import ConfirmEnvOverwriteModal from '@app/components/dashboard/ConfirmEnvOverwriteModal';
-import DownloadSecretMenu from '@app/components/dashboard/DownloadSecretsMenu';
-import DropZone from '@app/components/dashboard/DropZone';
-import KeyPair from '@app/components/dashboard/KeyPair';
-import SideBar from '@app/components/dashboard/SideBar';
-import NavHeaderSecrets from '@app/components/navigation/NavHeaderSecrets';
-import { decryptAssymmetric, decryptSymmetric } from '@app/components/utilities/cryptography/crypto';
-import guidGenerator from '@app/components/utilities/randomId';
-import encryptSecrets from '@app/components/utilities/secrets/encryptSecrets';
-import getSecretsForProject from '@app/components/utilities/secrets/getSecretsForProject';
import { getTranslatedServerSideProps } from '@app/components/utilities/withTranslateProps';
-import { IconButton } from '@app/components/v2';
-import { leaveConfirmDefaultMessage } from '@app/const';
-import getProjectSercetSnapshotsCount from '@app/ee/api/secrets/GetProjectSercetSnapshotsCount';
-import performSecretRollback from '@app/ee/api/secrets/PerformSecretRollback';
-import PITRecoverySidebar from '@app/ee/components/PITRecoverySidebar';
-import { useLeaveConfirm } from '@app/hooks';
-// import { DashboardPage } from '@app/views/DashboardPage';
+import { DashboardPage } from '@app/views/DashboardPage';
import { DashboardEnvOverview } from '@app/views/DashboardPage/DashboardEnvOverview';
-// import addSecrets from '../api/files/AddSecrets';
-// import deleteSecrets from '../api/files/DeleteSecrets';
-// import updateSecrets from '../api/files/UpdateSecrets';
-import batchSecrets from '../api/files/batchSecrets';
-import getUser from '../api/user/getUser';
-import checkUserAction from '../api/userActions/checkUserAction';
-import registerUserAction from '../api/userActions/registerUserAction';
-import getLatestFileKey from '../api/workspace/getLatestFileKey';
-import getWorkspaceEnvironments from '../api/workspace/getWorkspaceEnvironments';
-import getWorkspaces from '../api/workspace/getWorkspaces';
-import getWorkspaceTags from '../api/workspace/getWorkspaceTags';
-
-type WorkspaceEnv = {
- name: string;
- slug: string;
- isWriteDenied: boolean;
- isReadDenied: boolean;
-};
-
-interface SecretDataProps {
- pos: number;
- key: string;
- value: string | undefined;
- valueOverride: string | undefined;
- id: string;
- idOverride: string | undefined;
- comment: string;
- tags: Tag[];
-}
-
-// eslint-disable-next-line @typescript-eslint/no-unused-vars
-interface OverrideProps {
- id: string;
- keyName: string;
- value: string;
- pos: number;
- comment: string;
-}
-
-interface SnapshotProps {
- id: string;
- createdAt: string;
- version: number;
- secretVersions: {
- id: string;
- pos: number;
- environment: string;
- key: string;
- value: string;
- valueOverride: string;
- comment: string;
- tags: Tag[];
- }[];
-}
-
-interface EncryptedSecretProps {
- _id: string;
- createdAt: string;
- environment: string;
- secretCommentCiphertext: string;
- secretCommentIV: string;
- secretCommentTag: string;
- secretKeyCiphertext: string;
- secretKeyIV: string;
- secretKeyTag: string;
- secretValueCiphertext: string;
- secretValueIV: string;
- secretValueTag: string;
- type: 'personal' | 'shared';
- tags: Tag[];
-}
-
-interface SecretProps {
- key: string;
- value: string | undefined;
- type: 'personal' | 'shared';
- comment: string;
- id: string;
- tags: Tag[];
-}
-
-/**
- * this function finds the the duplicates in an array
- * @param arr - array of anything (e.g., with secret keys and types (personal/shared))
- * @returns - a list with duplicates
- */
-function findDuplicates(arr: any[]) {
- const map = new Map();
- return arr.filter((item) => {
- if (map.has(item)) {
- map.set(item, false);
- return true;
- }
- map.set(item, true);
- return false;
- });
-}
-
-/**
- * This is the main component for the dashboard (aka the screen with all the encironemnt variable & secrets)
- * @returns
- */
-export default function Dashboard() {
- const [data, setData] = useState<SecretDataProps[] | null>();
- const [initialData, setInitialData] = useState<SecretDataProps[] | null | undefined>([]);
- const [blurred, setBlurred] = useState(true);
- const [isKeyAvailable, setIsKeyAvailable] = useState(true);
- const [isNew, setIsNew] = useState(false);
- const [isLoading, setIsLoading] = useState(true);
- const [searchKeys, setSearchKeys] = useState('');
- const [errorDragAndDrop, setErrorDragAndDrop] = useState(false);
- const [sortMethod, setSortMethod] = useState('alphabetical');
- const [checkDocsPopUpVisible, setCheckDocsPopUpVisible] = useState(false);
- const [hasUserEverPushed, setHasUserEverPushed] = useState(false);
- const [sidebarSecretId, toggleSidebar] = useState('None');
- const [PITSidebarOpen, togglePITSidebar] = useState(false);
- const [sharedToHide, setSharedToHide] = useState<string[]>([]);
- const [snapshotData, setSnapshotData] = useState<SnapshotProps>();
- const [numSnapshots, setNumSnapshots] = useState<number>();
- const [saveLoading, setSaveLoading] = useState(false);
- const [autoCapitalization, setAutoCapitalization] = useState(false);
- const [dropZoneData, setDropZoneData] = useState<SecretDataProps[]>();
- const [projectTags, setProjectTags] = useState<Tag[]>([]);
-
- const { hasUnsavedChanges, setHasUnsavedChanges } = useLeaveConfirm({ initialValue: false });
+const Dashboard = () => {
const { t } = useTranslation();
-
- const { createNotification } = useNotificationContext();
const router = useRouter();
- const envInURL = queryString.parse(router.asPath.split('?')[1])?.env;
-
- const workspaceId = router.query.id as string;
- const [workspaceEnvs, setWorkspaceEnvs] = useState<WorkspaceEnv[]>([]);
-
- const [selectedSnapshotEnv, setSelectedSnapshotEnv] = useState<WorkspaceEnv>();
- const [selectedEnv, setSelectedEnv] = useState<WorkspaceEnv>();
- const [atSecretAreaTop, setAtSecretsAreaTop] = useState(true);
- const secretsTop = useRef<HTMLDivElement>(null);
-
- const onSecretsAreaScroll = (event: UIEvent<HTMLDivElement>) => {
- if (event.currentTarget.scrollTop !== 0) {
- setAtSecretsAreaTop(false);
- }
- };
-
- // TODO(akhilmhdh): change to FP
- const sortValuesHandler = (
- dataToSort: SecretDataProps[] | 1,
- specificSortMethod?: 'alphabetical' | '-alphabetical'
- ) => {
- const howToSort = specificSortMethod === undefined ? sortMethod : specificSortMethod;
- const sortedData = (dataToSort !== 1 ? dataToSort : data)!
- .sort((a, b) =>
- howToSort === 'alphabetical' ? a.key.localeCompare(b.key) : b.key.localeCompare(a.key)
- )
- .map((item: SecretDataProps, index: number) => ({
- ...item,
- pos: index
- }));
-
- setData(sortedData);
- setIsLoading(false);
- };
-
- /**
- * Reorder rows alphabetically or in the opprosite order
- */
- const reorderRows = (dataToReorder: SecretDataProps[] | 1) => {
- if (dataToReorder) {
- setSortMethod((prevSort) => (prevSort === 'alphabetical' ? '-alphabetical' : 'alphabetical'));
-
- sortValuesHandler(dataToReorder, undefined);
- }
- };
-
- useEffect(() => {
- (async () => {
- if (router.isReady && workspaceId === 'undefined') {
- router.push('/noprojects');
- } else try {
- const { push, query } = router
- const tempNumSnapshots = await getProjectSercetSnapshotsCount({
- workspaceId
- });
- setNumSnapshots(tempNumSnapshots);
- const userWorkspaces = await getWorkspaces();
- const workspace = userWorkspaces.find((wp) => wp._id === workspaceId);
- if (!workspace) {
- push(`/dashboard/${userWorkspaces?.[0]?._id}`);
- }
- setAutoCapitalization(workspace?.autoCapitalization ?? true);
-
- const accessibleEnvironments = await getWorkspaceEnvironments({ workspaceId });
- setWorkspaceEnvs(accessibleEnvironments || []);
-
- // set env
- const env = accessibleEnvironments[0] || {
- name: 'unknown',
- slug: 'unknown'
- };
- setSelectedEnv(env);
- setSelectedSnapshotEnv(env);
-
- if (query.env) {
- const index = accessibleEnvironments?.findIndex(({ slug }: { slug: string }) => slug === query.env)
-
- setSelectedEnv({
- name: accessibleEnvironments?.[index]?.name as string,
- slug: query.env as string,
- isWriteDenied: accessibleEnvironments?.[index]?.isWriteDenied as boolean,
- isReadDenied: accessibleEnvironments?.[index]?.isReadDenied as boolean
- })
- setSelectedSnapshotEnv({
- name: accessibleEnvironments?.[index]?.name as string,
- slug: query.env as string,
- isWriteDenied: accessibleEnvironments?.[index]?.isWriteDenied as boolean,
- isReadDenied: accessibleEnvironments?.[index]?.isReadDenied as boolean
- })
-
- }
-
- const user = await getUser();
- setIsNew((Date.parse(String(new Date())) - Date.parse(user.createdAt)) / 60000 < 3);
-
- const userAction = await checkUserAction({
- action: 'first_time_secrets_pushed'
- });
- setHasUserEverPushed(!!userAction);
-
- setProjectTags(await getWorkspaceTags({ workspaceId }));
- } catch (error) {
- console.log('Error', error);
- setData(undefined);
- }
- })();
- }, [workspaceId]);
-
- useEffect(() => {
- (async () => {
- try {
- setIsLoading(true);
- setBlurred(true);
- // ENV
- let dataToSort;
- if (selectedEnv) {
- dataToSort = await getSecretsForProject({
- env: selectedEnv.slug,
- setIsKeyAvailable,
- setData,
- workspaceId
- });
- setInitialData(dataToSort);
- reorderRows(dataToSort);
- } else {
- setIsLoading(false);
- }
- } catch (error) {
- console.log('Error', error);
- setData(undefined);
- }
- })();
- // eslint-disable-next-line react-hooks/exhaustive-deps
- }, [selectedEnv]);
-
- const addRow = () => {
- setIsNew(false);
- setData([
- {
- id: guidGenerator(),
- idOverride: guidGenerator(),
- pos: data!.length,
- key: '',
- value: '',
- valueOverride: undefined,
- comment: '',
- tags: []
- },
- ...data!
- ]);
- if (!atSecretAreaTop) {
- secretsTop.current?.scrollIntoView({ behavior: 'smooth' });
- }
- };
-
- const addRowToBottom = () => {
- setIsNew(false);
- setData([
- ...data!,
- {
- id: guidGenerator(),
- idOverride: guidGenerator(),
- pos: data!.length,
- key: '',
- value: '',
- valueOverride: undefined,
- comment: '',
- tags: []
- }
- ]);
- };
-
- const deleteRow = ({ ids, secretName }: { ids: string[]; secretName: string }) => {
- setHasUnsavedChanges(true);
- toggleSidebar('None');
- createNotification({
- text: `${secretName || 'Secret'} has been deleted. Remember to save changes.`,
- type: 'error'
- });
- sortValuesHandler(
- data!.filter((row: SecretDataProps) => !ids.includes(row.id)),
- sortMethod === 'alhpabetical' ? '-alphabetical' : 'alphabetical'
- );
- };
-
- const modifyValue = (value: string, id: string) => {
- setData((oldData) => oldData?.map((e) => ((e.id ? e.id : e.idOverride) === id ? { ...e, value } : e)));
- setHasUnsavedChanges(true);
- };
-
- const modifyValueOverride = (valueOverride: string | undefined, id: string) => {
- setData((oldData) => oldData?.map((e) => ((e.id ? e.id : e.idOverride) === id ? { ...e, valueOverride } : e)));
- setHasUnsavedChanges(true);
- };
-
- const modifyKey = (key: string, id: string) => {
- setData((oldData) => oldData?.map((e) => ((e.id ? e.id : e.idOverride) === id ? { ...e, key } : e)));
- setHasUnsavedChanges(true);
- };
-
- const modifyComment = (comment: string, id: string) => {
- setData((oldData) => oldData?.map((e) => ((e.id ? e.id : e.idOverride) === id ? { ...e, comment } : e)));
- setHasUnsavedChanges(true);
- };
-
- const modifyTags = (tags: Tag[], id: string) => {
- setData((oldData) => oldData?.map((e) => ((e.id ? e.id : e.idOverride) === id ? { ...e, tags } : e)));
- setHasUnsavedChanges(true);
- };
- // For speed purposes and better perforamance, we are using useCallback
- const listenChangeValue = useCallback((value: string, id: string) => {
- modifyValue(value, id);
- }, []);
+ const queryEnv = router.query.env as string;
+ const isOverviewMode = !queryEnv;
- const listenChangeValueOverride = useCallback((value: string | undefined, id: string) => {
- modifyValueOverride(value, id);
- }, []);
-
- const listenChangeKey = useCallback((value: string, id: string) => {
- modifyKey(value, id);
- }, []);
-
- const listenChangeComment = useCallback((value: string, id: string) => {
- modifyComment(value, id);
- }, []);
-
- const listenChangeTags = useCallback((value: Tag[], id: string) => {
- modifyTags(value, id);
- }, []);
-
- /**
- * Save the changes of environment variables and push them to the database
- */
- // TODO(akhilmhdh): split and make it small
- const savePush = async (dataToPush?: SecretDataProps[]) => {
- try {
- setSaveLoading(true);
- let newData: SecretDataProps[] | null | undefined;
- // dataToPush is mostly used for rollbacks, otherwise we always take the current state data
- if ((dataToPush ?? [])?.length > 0) {
- newData = dataToPush;
- } else {
- newData = data;
- }
-
- // Checking if any of the secret keys start with a number - if so, don't do anything
- const nameErrors = !newData!
- .map((secret) => !Number.isNaN(Number(secret.key.charAt(0))))
- .every((v) => v === false);
- const emptyNameError = !newData!
- .map((secret) => secret.key.length === 0)
- .every((v) => v === false);
- const duplicatesExist =
- findDuplicates(data!.map((item: SecretDataProps) => item.key)).length > 0;
-
- if (emptyNameError) {
- setSaveLoading(false);
- return createNotification({
- text: 'You can`t have empty secret names.',
- type: 'error'
- });
- }
-
- if (nameErrors) {
- setSaveLoading(false);
- return createNotification({
- text: 'Solve all name errors before saving secrets.',
- type: 'error'
- });
- }
-
- if (duplicatesExist) {
- setSaveLoading(false);
- return createNotification({
- text: 'Remove duplicated secret names before saving.',
- type: 'error'
- });
- }
-
- if (selectedEnv?.isWriteDenied) {
- setSaveLoading(false);
- return createNotification({
- text: 'You are not allowed to edit this environment',
- type: 'error'
- });
- }
-
- // Once "Save changes" is clicked, disable that button
- setHasUnsavedChanges(false);
-
- const secretsToBeDeleted = initialData!
- .filter(
- (initDataPoint) =>
- !newData!.map((newDataPoint) => newDataPoint.id).includes(initDataPoint.id)
- )
- .map((secret) => secret.id);
- console.log('delete', secretsToBeDeleted.length);
-
- const secretsToBeAdded = newData!.filter(
- (newDataPoint) =>
- !initialData!.map((initDataPoint) => initDataPoint.id).includes(newDataPoint.id)
- );
- console.log('add', secretsToBeAdded.length);
-
- const secretsToBeUpdated = newData!.filter((newDataPoint) =>
- initialData!
- .filter(
- (initDataPoint) =>
- newData!.filter((dataPoint) => dataPoint.id)
- .map((dataPoint) => dataPoint.id).includes(initDataPoint.id) &&
- (newData!.filter((dataPoint) => dataPoint.id === initDataPoint.id)[0].value !==
- initDataPoint.value ||
- newData!.filter((dataPoint) => dataPoint.id === initDataPoint.id)[0].key !==
- initDataPoint.key ||
- newData!.filter((dataPoint) => dataPoint.id === initDataPoint.id)[0].comment !==
- initDataPoint.comment ||
- JSON.stringify(newData!.filter((dataPoint) => dataPoint.id === initDataPoint.id)[0]?.tags) !==
- JSON.stringify(initDataPoint?.tags))
- )
- .map((secret) => secret.id)
- .includes(newDataPoint.id)
- );
- console.log('update', secretsToBeUpdated.length);
-
- const newOverrides = newData!.filter(
- (newDataPoint) => newDataPoint.valueOverride !== undefined
- );
- const initOverrides = initialData!.filter(
- (initDataPoint) => initDataPoint.valueOverride !== undefined
- );
-
- const overridesToBeDeleted = initOverrides
- .filter(
- (initDataPoint) =>
- !newOverrides!.map((newDataPoint) => newDataPoint.id).includes(initDataPoint.id)
- )
- .map((secret) => String(secret.idOverride));
- console.log('override delete', overridesToBeDeleted.length);
-
- const overridesToBeAdded = newOverrides!
- .filter(
- (newDataPoint) =>
- !initOverrides.map((initDataPoint) => initDataPoint.idOverride).includes(newDataPoint.idOverride)
- )
- .map((override) => ({
- pos: override.pos,
- key: override.key,
- value: String(override.valueOverride),
- valueOverride: override.valueOverride,
- comment: '',
- id: String(override.idOverride),
- idOverride: String(override.idOverride),
- tags: override.tags
- }));
- console.log('override add', overridesToBeAdded.length);
-
- const overridesToBeUpdated = newOverrides!
- .filter((newDataPoint) =>
- initOverrides
- .filter(
- (initDataPoint) =>
- newOverrides!.map((dataPoint) => dataPoint.idOverride)
- .includes(initDataPoint.idOverride) &&
- (newOverrides!.filter((dataPoint) => dataPoint.idOverride === initDataPoint.idOverride)[0]
- .valueOverride !== initDataPoint.valueOverride ||
- newOverrides!.filter((dataPoint) => dataPoint.idOverride === initDataPoint.idOverride)[0].key !==
- initDataPoint.key ||
- (newOverrides!.filter((dataPoint) => dataPoint.idOverride === initDataPoint.idOverride)[0]
- .comment || '') !== (initDataPoint.comment || '')
- ||
- (JSON.stringify(newOverrides!.filter((dataPoint) => dataPoint.idOverride === initDataPoint.idOverride)[0]?.tags) || '') !==
- (JSON.stringify(initDataPoint?.tags) || '')
- )
- )
- .map((secret) => secret.idOverride)
- .includes(newDataPoint.idOverride)
- )
- .map((override) => ({
- pos: override.pos,
- key: override.key,
- value: String(override.valueOverride),
- valueOverride: override.valueOverride,
- comment: '',
- id: String(override.idOverride),
- idOverride: String(override.idOverride),
- tags: override.tags
- }));
- console.log('override update', overridesToBeUpdated.length);
-
- const requests: any = []; // TODO: fix any
- if (secretsToBeDeleted.concat(overridesToBeDeleted).length > 0) {
- secretsToBeDeleted.concat(overridesToBeDeleted).forEach((_id: string) => {
- requests.push({
- method: 'DELETE',
- secret: {
- _id
- }
- });
- });
- }
- if (selectedEnv && secretsToBeAdded.concat(overridesToBeAdded).length > 0) {
- const secrets = await encryptSecrets({
- secretsToEncrypt: secretsToBeAdded.concat(overridesToBeAdded),
- workspaceId,
- env: selectedEnv.slug
- });
- if (secrets) {
- secrets.forEach((secret) => {
- requests.push({
- method: 'POST',
- secret: {
- type: secret.type,
- secretName: secret.secretName,
- secretKeyCiphertext: secret.secretKeyCiphertext,
- secretKeyIV: secret.secretKeyIV,
- secretKeyTag: secret.secretKeyTag,
- secretValueCiphertext: secret.secretValueCiphertext,
- secretValueIV: secret.secretValueIV,
- secretValueTag: secret.secretValueTag,
- secretCommentCiphertext: secret.secretCommentCiphertext,
- secretCommentIV: secret.secretCommentIV,
- secretCommentTag: secret.secretCommentTag,
- tags: secret.tags
- }
- })
- });
- }
- }
- if (selectedEnv && !selectedEnv.isReadDenied && secretsToBeUpdated.concat(overridesToBeUpdated).length > 0) {
- const secrets = await encryptSecrets({
- secretsToEncrypt: secretsToBeUpdated.concat(overridesToBeUpdated),
- workspaceId,
- env: selectedEnv.slug
- });
- if (secrets) {
- secrets.forEach((secret) => {
- requests.push({
- method: 'PATCH',
- secret: {
- _id: secret.id,
- type: secret.type,
- secretName: secret.secretName,
- secretKeyCiphertext: secret.secretKeyCiphertext,
- secretKeyIV: secret.secretKeyIV,
- secretKeyTag: secret.secretKeyTag,
- secretValueCiphertext: secret.secretValueCiphertext,
- secretValueIV: secret.secretValueIV,
- secretValueTag: secret.secretValueTag,
- secretCommentCiphertext: secret.secretCommentCiphertext,
- secretCommentIV: secret.secretCommentIV,
- secretCommentTag: secret.secretCommentTag,
- tags: secret.tags
- }
- });
- });
- }
- }
-
- let newSecrets;
- if (selectedEnv && requests.length > 0) {
- newSecrets = await batchSecrets({
- workspaceId,
- environment: selectedEnv.slug,
- requests
- });
- }
-
- let formattedNewDecryptedKeys;
- if (newSecrets.createdSecrets) {
- const latestKey = await getLatestFileKey({ workspaceId });
-
- const PRIVATE_KEY = localStorage.getItem('PRIVATE_KEY') as string;
-
- const tempDecryptedSecrets: SecretProps[] = [];
- if (latestKey) {
- // assymmetrically decrypt symmetric key with local private key
- const key = decryptAssymmetric({
- ciphertext: latestKey.latestKey.encryptedKey,
- nonce: latestKey.latestKey.nonce,
- publicKey: latestKey.latestKey.sender.publicKey,
- privateKey: PRIVATE_KEY
- });
-
- // decrypt secret keys, values, and comments
- newSecrets.createdSecrets.forEach((secret: EncryptedSecretProps) => {
- const plainTextKey = decryptSymmetric({
- ciphertext: secret.secretKeyCiphertext,
- iv: secret.secretKeyIV,
- tag: secret.secretKeyTag,
- key
- });
-
- let plainTextValue;
- if (secret.secretValueCiphertext !== undefined) {
- plainTextValue = decryptSymmetric({
- ciphertext: secret.secretValueCiphertext,
- iv: secret.secretValueIV,
- tag: secret.secretValueTag,
- key
- });
- } else {
- plainTextValue = undefined;
- }
-
- let plainTextComment;
- if (secret.secretCommentCiphertext) {
- plainTextComment = decryptSymmetric({
- ciphertext: secret.secretCommentCiphertext,
- iv: secret.secretCommentIV,
- tag: secret.secretCommentTag,
- key
- });
- } else {
- plainTextComment = '';
- }
-
- tempDecryptedSecrets.push({
- id: secret._id,
- key: plainTextKey,
- value: plainTextValue,
- type: secret.type,
- comment: plainTextComment,
- tags: secret.tags
- });
- });
- }
-
- const secretKeys = [...new Set(tempDecryptedSecrets.map((secret) => secret.key))];
-
- formattedNewDecryptedKeys = secretKeys.map((key, index) => ({
- id: tempDecryptedSecrets.filter((secret) => secret.key === key && secret.type === 'shared')[0]
- ?.id,
- idOverride: tempDecryptedSecrets.filter(
- (secret) => secret.key === key && secret.type === 'personal'
- )[0]?.id,
- pos: (newData?.filter(dp => !dp.id?.includes('-'))?.length ?? 0) + index,
- key,
- value: tempDecryptedSecrets.filter(
- (secret) => secret.key === key && secret.type === 'shared'
- )[0]?.value,
- valueOverride: tempDecryptedSecrets.filter(
- (secret) => secret.key === key && secret.type === 'personal'
- )[0]?.value,
- comment: tempDecryptedSecrets.filter(
- (secret) => secret.key === key && secret.type === 'shared'
- )[0]?.comment,
- tags: tempDecryptedSecrets.filter(
- (secret) => secret.key === key && secret.type === 'shared'
- )[0]?.tags
- }));
-
- setInitialData(structuredClone(newData?.filter(dp => !dp.id?.includes('-')).concat(formattedNewDecryptedKeys.filter(dk => dk.id))));
- setData(structuredClone(newData?.filter(dp => !dp.id?.includes('-')).concat(formattedNewDecryptedKeys.filter(dk => dk.id))))
- } else {
- setInitialData(structuredClone(newData));
- }
-
- // If this user has never saved environment variables before, show them a prompt to read docs
- if (!hasUserEverPushed) {
- setCheckDocsPopUpVisible(true);
- await registerUserAction({ action: 'first_time_secrets_pushed' });
- }
-
- // increasing the number of project commits
- setNumSnapshots((numSnapshots ?? 0) + 1);
- setSaveLoading(false);
- createNotification({
- text: `Successfully saved secrets.`,
- type: 'success'
- });
- } catch (error) {
- console.log("Something went wrong while saving secrets: ", error)
- createNotification({
- text: `Something went wrong while saving secrets.`,
- type: 'error'
- });
- }
- return undefined;
- };
-
- const addDataWithMerge = (newData: SecretDataProps[], preserve?: 'old' | 'new') => {
- setData((oldData) => {
- let filteredOldData = oldData!;
- let filteredNewData = newData;
- if (preserve === 'new')
- filteredOldData = oldData!.filter(
- (oldDataPoint) => !newData.find((newDataPoint) => newDataPoint.key === oldDataPoint.key)
- );
- if (preserve === 'old')
- filteredNewData = newData.filter(
- (newDataPoint) => !oldData?.find((oldDataPoint) => oldDataPoint.key === newDataPoint.key)
- );
- return filteredOldData.concat(filteredNewData);
- });
- setHasUnsavedChanges(true);
- };
-
- const addData = (newData: SecretDataProps[]) => {
- if (
- newData.some((newDataPoint) => data?.find((dataPoint) => dataPoint.key === newDataPoint.key)) // if newData contains duplicates
- ) {
- setDropZoneData(newData);
- return;
- }
- addDataWithMerge(newData);
- };
-
- const changeBlurred = () => {
- setBlurred(!blurred);
- };
-
- const deleteCertainRow = ({ ids, secretName }: { ids: string[]; secretName: string }) => {
- deleteRow({ ids, secretName });
- };
-
- const handleOnEnvironmentChange = (envSlug: string) => {
- if (hasUnsavedChanges) {
- if (!window.confirm(leaveConfirmDefaultMessage)) return;
- }
-
- const selectedWorkspaceEnv = workspaceEnvs.find(
- ({ slug }: { slug: string }) => envSlug === slug
- ) || {
- name: 'unknown',
- slug: 'unknown',
- isWriteDenied: false,
- isReadDenied: false
- };
-
- if (selectedWorkspaceEnv) {
- if (snapshotData) setSelectedSnapshotEnv(selectedWorkspaceEnv);
- else setSelectedEnv(selectedWorkspaceEnv);
- }
-
- setHasUnsavedChanges(false);
+ const onExploreEnv = (slug: string) => {
router.push({
pathname: router.pathname,
- query: { ...router.query, env: selectedWorkspaceEnv.slug },
- })
+ query: { ...router.query, env: slug }
+ });
};
- return <div>
- <Head>
- <title>{t('common:head-title', { title: t('dashboard:title') })}</title>
- <link rel="icon" href="/infisical.ico" />
- <meta property="og:image" content="/images/message.png" />
- <meta property="og:title" content={String(t('dashboard:og-title'))} />
- <meta name="og:description" content={String(t('dashboard:og-description'))} />
- </Head>
- {!envInURL
- ? <DashboardEnvOverview onEnvChange={handleOnEnvironmentChange} />
- : (data ? (
- <div className="bg-bunker-800 max-h-screen h-full relative flex flex-col justify-between text-white dark">
- <div className="flex flex-row h-full">
- <ConfirmEnvOverwriteModal
- isOpen={!!dropZoneData}
- onClose={() => setDropZoneData(undefined)}
- onOverwriteConfirm={(preserve) => {
- addDataWithMerge(dropZoneData!, preserve);
- setDropZoneData(undefined);
- }}
- duplicateKeys={
- dropZoneData
- ?.filter((newDataPoint) =>
- data?.find((dataPoint) => dataPoint.key === newDataPoint.key)
- )
- .map((duplicate) => duplicate.key) ?? []
- }
- />
- <div className="w-full max-h-96 dark:[color-scheme:dark]">
- <NavHeaderSecrets
- pageName={t('dashboard:title')}
- currentEnv={selectedEnv?.name || ''}
- isProjectRelated
- isSnapshot={snapshotData !== undefined}
- userAvailableEnvs={workspaceEnvs}
- onEnvChange={handleOnEnvironmentChange}
- />
- {checkDocsPopUpVisible && (
- <BottonRightPopup
- buttonText={t('dashboard:check-docs.button')}
- buttonLink="https://infisical.com/docs/documentation/getting-started/introduction"
- titleText={t('dashboard:check-docs.title')}
- emoji="🎉"
- textLine1={t('dashboard:check-docs.line1')}
- textLine2={t('dashboard:check-docs.line2')}
- setCheckDocsPopUpVisible={setCheckDocsPopUpVisible}
- />
- )}
- <div className="flex flex-row justify-between items-center mx-6 mt-6 mb-3 text-xl">
- {snapshotData && (
- <div className="flex justify-start max-w-sm mt-1 mr-2">
- <Button
- text={String(t('To Current'))}
- onButtonPressed={() => setSnapshotData(undefined)}
- color="mineshaft"
- size="md"
- icon={faArrowLeft}
- />
- </div>
- )}
- <div className="flex flex-row justify-start items-center text-3xl">
- <div className="font-semibold mr-4 mt-1 flex flex-row items-center">
- <p>{snapshotData ? 'Secret Snapshot' : ''}</p>
- {snapshotData && (
- <span className="bg-primary-800 text-xs ml-4 mt-1 px-1.5 rounded-md w-min">
- {new Date(snapshotData.createdAt).toLocaleString()}
- </span>
- )}
- {selectedEnv?.isReadDenied && (
- <span className="bg-primary-500 text-black text-sm ml-4 mt-1 px-1.5 rounded-md">
- Add Only Mode
- </span>
- )}
- </div>
- </div>
- <div className="flex flex-row">
- <div className="flex justify-start max-w-sm mt-1 mr-2">
- {!selectedEnv?.isReadDenied && (
- <Button
- text={String(`${numSnapshots} ${t('Commits')}`)}
- onButtonPressed={() => {
- toggleSidebar('None');
- togglePITSidebar(true);
- }}
- color="mineshaft"
- size="md"
- icon={faClockRotateLeft}
- />
- )}
- </div>
- {(data?.length !== 0 || hasUnsavedChanges) && !snapshotData && (
- <div className="flex justify-start max-w-sm mt-1">
- <Button
- text={String(t('common:save-changes'))}
- onButtonPressed={savePush}
- color="primary"
- size="md"
- active={hasUnsavedChanges}
- iconDisabled={faCheck}
- textDisabled={String(t('common:saved'))}
- loading={saveLoading}
- />
- </div>
- )}
- {snapshotData && selectedEnv && (
- <div className="flex justify-start max-w-sm mt-1">
- <Button
- text={String(t('Rollback to this snapshot'))}
- onButtonPressed={async () => {
- // Update secrets in the state only for the current environment
- const rolledBackSecrets = snapshotData.secretVersions
- .filter((row) => row.environment === selectedEnv.slug)
- .map((sv, position) => ({
- id: sv.id,
- idOverride: sv.id,
- pos: position,
- valueOverride: sv.valueOverride,
- key: sv.key,
- value: sv.value,
- comment: '',
- tags: sv.tags
- }));
+ return (
+ <>
+ <Head>
+ <title>{t('common:head-title', { title: t('dashboard:title') })}</title>
+ <link rel="icon" href="/infisical.ico" />
+ <meta property="og:image" content="/images/message.png" />
+ <meta property="og:title" content={String(t('dashboard:og-title'))} />
+ <meta name="og:description" content={String(t('dashboard:og-description'))} />
+ </Head>
+ {isOverviewMode ? (
+ <DashboardEnvOverview onEnvChange={onExploreEnv} />
+ ) : (
+ <DashboardPage envFromTop={queryEnv} />
+ )}
+ </>
+ );
+};
- // Perform the rollback globally
- const result = await performSecretRollback({ workspaceId, version: snapshotData.version });
- if (result === undefined) {
- createNotification({
- text: `Something went wrong during the rollback.`,
- type: 'error'
- });
- } else {
- setData(rolledBackSecrets);
- createNotification({
- text: `Successfully rolled back secrets.`,
- type: 'success'
- });
- setSnapshotData(undefined);
- setHasUnsavedChanges(false);
- togglePITSidebar(false);
- }
- }}
- color="primary"
- size="md"
- active={hasUnsavedChanges}
- />
- </div>
- )}
- </div>
- </div>
- <div className="mx-6 w-full pr-12">
- <div className="flex flex-col pb-1">
- <div className="w-full flex flex-row items-start">
- {(snapshotData || data?.length !== 0) && selectedEnv && (
- <>
- <div className="h-10 w-full bg-mineshaft-800 border border-mineshaft-600 hover:bg-mineshaft-700 duration-200 rounded-md flex flex-row items-center">
- <FontAwesomeIcon
- className="bg-transparent rounded-l-md py-[0.7rem] pl-4 pr-2 text-bunker-300 text-sm"
- icon={faMagnifyingGlass}
- />
- <input
- className="pl-2 text-bunker-300 rounded-r-md bg-transparent w-full h-full outline-none text-sm placeholder:hover:text-bunker-200 placeholder:focus:text-transparent"
- value={searchKeys}
- onChange={(e) => setSearchKeys(e.target.value)}
- placeholder={String(t('dashboard:search-keys'))}
- />
- </div>
- {!snapshotData && !selectedEnv.isReadDenied && (
- <div className="ml-2 min-w-max flex flex-row items-start justify-start">
- <DownloadSecretMenu data={data} env={selectedEnv.slug} />
- </div>
- )}
- <div className="ml-2 min-w-max flex flex-row items-start justify-start">
- <Button
- onButtonPressed={changeBlurred}
- color="mineshaft"
- size="icon-md"
- icon={blurred ? faEye : faEyeSlash}
- />
- </div>
- {!snapshotData && (
- <div className="relative ml-2 min-w-max flex flex-row items-start justify-end">
- <Button
- text={String(t('dashboard:add-key'))}
- onButtonPressed={addRow}
- color="mineshaft"
- icon={faPlus}
- size="md"
- />
- {isNew && (
- <span className="absolute right-0 flex h-3 w-3 items-center justify-center ml-4 mb-4">
- <span className="animate-ping absolute inline-flex rounded-full bg-primary/50 opacity-75 h-4 w-4" />
- <span className="relative inline-flex rounded-full h-3 w-3 bg-primary" />
- </span>
- )}
- </div>
- )}
- </>
- )}
- </div>
- </div>
- {isLoading ? (
- <div className="flex items-center justify-center h-full my-48">
- <Image
- src="/images/loading/loading.gif"
- height={60}
- width={100}
- alt="infisical loading indicator"
- />
- </div>
- ) : (data?.length !== 0 || snapshotData?.secretVersions) ? (
- <div className="flex flex-col w-full mt-1">
- <div
- onScroll={onSecretsAreaScroll}
- className="mt-1 max-h-[calc(100vh-280px)] overflow-hidden overflow-y-scroll no-scrollbar no-scrollbar::-webkit-scrollbar border border-mineshaft-600 rounded-md"
- >
- <div ref={secretsTop} />
- <div className="group flex flex-col items-center bg-mineshaft-800 border-b-2 border-mineshaft-500 duration-100 sticky top-0 z-[60]">
- <div className="relative flex flex-row justify-between w-full mr-auto max-h-14 items-center">
- <div className="w-[23%] border-r border-mineshaft-600 flex flex-row items-center">
- <div className='text-transparent text-xs flex items-center justify-center w-12 h-10 cursor-default'>0</div>
- <span className='px-2 text-bunker-300 font-semibold'>Key</span>
- {!snapshotData && <IconButton
- ariaLabel="copy icon"
- variant="plain"
- className="group relative ml-2"
- onClick={() => reorderRows(1)}
- >
- {sortMethod === 'alphabetical' ? <FontAwesomeIcon icon={faArrowUp} /> : <FontAwesomeIcon icon={faArrowDown} />}
- </IconButton>}
- </div>
- <div className="w-5/12 border-r border-mineshaft-600">
- <div className="flex items-center rounded-lg mt-4 md:mt-0 max-h-10">
- <div className="text-bunker-300 px-2 font-semibold h-10 flex items-center w-7/12">
- Value
- </div>
- </div>
- </div>
- <div className="w-[calc(10%)] border-r border-mineshaft-600">
- <div className="flex items-center max-h-16 overflow-hidden">
- <div className="text-bunker-300 px-2 font-semibold h-10 flex items-center w-3/12">
- Comment
- </div>
- </div>
- </div>
- <div className="w-2/12">
- <div className="flex items-center max-h-16">
- <div className="text-bunker-300 px-2 font-semibold h-10 flex items-center w-3/12">
- Tags
- </div>
- </div>
- </div>
- <div className="w-[1.5rem] h-[2.35rem] ml-auto rounded-md flex flex-row justify-center items-center" />
- <div className="w-[1.5rem] h-[2.35rem] mr-2 flex items-center justfy-center">
- <div
- onKeyDown={() => null}
- role="none"
- onClick={() => { }}
- className="invisible group-hover:visible"
- >
- <FontAwesomeIcon
- className="text-bunker-300 hover:text-red pl-2 pr-6 text-lg mt-0.5 invisible"
- icon={faXmark}
- />
- </div>
- </div>
- </div>
- </div>
- <div className="bg-mineshaft-800 rounded-b-md border-bunker-600">
- {!snapshotData &&
- data
- ?.filter((row) =>
- row.key?.toUpperCase().includes(searchKeys.toUpperCase())
- || row.tags?.map(tag => tag.name).join(" ")?.toUpperCase().includes(searchKeys.toUpperCase())
- || row.comment?.toUpperCase().includes(searchKeys.toUpperCase()))
- .filter((row) => !sharedToHide.includes(row.id))
- // .filter((row) => row.value !== undefined)
- .map((keyPair) => (
- <KeyPair
- isCapitalized={autoCapitalization}
- key={keyPair.id ? keyPair.id : keyPair.idOverride}
- keyPair={keyPair}
- modifyValue={listenChangeValue}
- modifyValueOverride={listenChangeValueOverride}
- modifyKey={listenChangeKey}
- modifyComment={listenChangeComment}
- modifyTags={listenChangeTags}
- isBlurred={blurred}
- isDuplicate={findDuplicates(data?.map((item) => item.key))?.includes(
- keyPair.key
- )}
- toggleSidebar={toggleSidebar}
- togglePITSidebar={togglePITSidebar}
- sidebarSecretId={sidebarSecretId}
- isSnapshot={false}
- deleteRow={deleteCertainRow}
- tags={projectTags}
- />
- ))}
- {snapshotData &&
- snapshotData.secretVersions
- ?.sort((a, b) => a.key.localeCompare(b.key))
- .filter((row) => row.environment === selectedSnapshotEnv?.slug)
- .filter((row) => row.key.toUpperCase().includes(searchKeys.toUpperCase()))
- .map((keyPair) => (
- <KeyPair
- isCapitalized={autoCapitalization}
- key={keyPair.id}
- keyPair={keyPair}
- modifyValue={listenChangeValue}
- modifyValueOverride={listenChangeValueOverride}
- modifyKey={listenChangeKey}
- modifyComment={listenChangeComment}
- modifyTags={listenChangeTags}
- isBlurred={blurred}
- isDuplicate={findDuplicates(data?.map((item) => item.key))?.includes(
- keyPair.key
- )}
- toggleSidebar={toggleSidebar}
- sidebarSecretId={sidebarSecretId}
- isSnapshot
- tags={projectTags}
- />
- ))}
- <div className="bg-mineshaft-800 text-sm rounded-t-md hover:bg-mineshaft-700 h-10 w-full flex flex-row items-center border-b-2 border-mineshaft-500 sticky top-0 z-[60]">
- <div className="w-10" />
- <button
- type="button"
- className="text-bunker-300 relative font-normal h-10 flex items-center w-full cursor-pointer"
- onClick={addRowToBottom}
- >
- <FontAwesomeIcon icon={faPlus} className="mr-3" />
- <span className="text-sm">Add Secret</span>
- </button>
- </div>
- </div>
- {!snapshotData && (
- <div className="w-full px-2 pt-3">
- <DropZone
- setData={addData}
- setErrorDragAndDrop={setErrorDragAndDrop}
- createNewFile={addRow}
- errorDragAndDrop={errorDragAndDrop}
- setButtonReady={setHasUnsavedChanges}
- keysExist
- numCurrentRows={data.length}
- />
- </div>
- )}
- </div>
- </div>
- ) : (
- <div className="flex flex-col items-center justify-center h-full text-xl text-gray-400 mt-28">
- {isKeyAvailable && !snapshotData && (
- <DropZone
- setData={setData}
- setErrorDragAndDrop={setErrorDragAndDrop}
- createNewFile={addRow}
- errorDragAndDrop={errorDragAndDrop}
- setButtonReady={setHasUnsavedChanges}
- numCurrentRows={data.length}
- keysExist={false}
- />
- )}
- {!isKeyAvailable && (
- <>
- <FontAwesomeIcon className="text-7xl mt-20 mb-8" icon={faFolderOpen} />
- <p>To view this file, contact your administrator for permission.</p>
- <p className="mt-1">They need to grant you access in the team tab.</p>
- </>
- )}
- </div>
- )}
- </div>
- </div>
- {sidebarSecretId !== 'None' && (
- <SideBar
- toggleSidebar={toggleSidebar}
- data={data.filter(
- (row: SecretDataProps) => row.id === sidebarSecretId && row.value !== undefined
- )}
- modifyKey={listenChangeKey}
- modifyValue={listenChangeValue}
- modifyValueOverride={listenChangeValueOverride}
- modifyComment={listenChangeComment}
- buttonReady={hasUnsavedChanges}
- workspaceEnvs={workspaceEnvs}
- selectedEnv={selectedEnv!}
- workspaceId={workspaceId}
- savePush={savePush}
- sharedToHide={sharedToHide}
- setSharedToHide={setSharedToHide}
- deleteRow={deleteCertainRow}
- />
- )}
- {PITSidebarOpen && (
- <PITRecoverySidebar
- toggleSidebar={togglePITSidebar}
- chosenSnapshot={String(snapshotData?.id ? snapshotData.id : '')}
- setSnapshotData={setSnapshotData}
- />
- )}
- </div>
- </div>
- ) : (
- <div className="relative z-10 w-10/12 mr-auto h-screen ml-2 bg-bunker-800 flex flex-col items-center justify-center">
- <Image src="/images/loading/loading.gif" height={70} width={120} alt="loading animation" />
- </div>
- ))}</div>
-}
+export default Dashboard;
Dashboard.requireAuth = true;
diff --git a/frontend/src/views/DashboardPage/DashboardEnvOverview.tsx b/frontend/src/views/DashboardPage/DashboardEnvOverview.tsx
index f4efa8583a..da0037ea82 100644
--- a/frontend/src/views/DashboardPage/DashboardEnvOverview.tsx
+++ b/frontend/src/views/DashboardPage/DashboardEnvOverview.tsx
@@ -1,50 +1,26 @@
-import { useEffect, useState } from 'react';
-import { FormProvider, useForm, useWatch } from 'react-hook-form';
+import { useEffect, useMemo, useState } from 'react';
+import { FormProvider, useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { useRouter } from 'next/router';
import { yupResolver } from '@hookform/resolvers/yup';
-import { useNotificationContext } from '@app/components/context/Notifications/NotificationProvider';
import NavHeader from '@app/components/navigation/NavHeader';
-import {
- Button,
- Modal,
- ModalContent,
- TableContainer,
- Tooltip
-} from '@app/components/v2';
+import { Button, TableContainer, Tooltip } from '@app/components/v2';
import { useWorkspace } from '@app/context';
-import { usePopUp } from '@app/hooks';
import {
- useCreateWsTag,
- useGetProjectSecrets,
+ useGetProjectSecretsByKey,
useGetUserWsEnvironments,
- useGetUserWsKey,
+ useGetUserWsKey
} from '@app/hooks/api';
import { WorkspaceEnv } from '@app/hooks/api/types';
-import { CreateTagModal } from './components/CreateTagModal';
import { EnvComparisonRow } from './components/EnvComparisonRow';
-import {
- FormData,
- schema
-} from './DashboardPage.utils';
-
+import { FormData, schema } from './DashboardPage.utils';
-export const DashboardEnvOverview = ({onEnvChange}: {onEnvChange: any;}) => {
+export const DashboardEnvOverview = ({ onEnvChange }: { onEnvChange: any }) => {
const { t } = useTranslation();
const router = useRouter();
- const { createNotification } = useNotificationContext();
- const { popUp
- // , handlePopUpOpen
- , handlePopUpToggle, handlePopUpClose } = usePopUp([
- 'secretDetails',
- 'addTag',
- 'secretSnapshots',
- 'uploadedSecOpts',
- 'compareSecrets'
- ] as const);
const [selectedEnv, setSelectedEnv] = useState<WorkspaceEnv | null>(null);
const { currentWorkspace, isLoading } = useWorkspace();
@@ -68,20 +44,15 @@ export const DashboardEnvOverview = ({onEnvChange}: {onEnvChange: any;}) => {
}
});
- const userAvailableEnvs = wsEnv?.filter(
- ({ isReadDenied }) => !isReadDenied
- );
-
- const { data: secrets, isLoading: isSecretsLoading } = useGetProjectSecrets({
+ const userAvailableEnvs = wsEnv?.filter(({ isReadDenied }) => !isReadDenied);
+
+ const { data: secrets, isLoading: isSecretsLoading } = useGetProjectSecretsByKey({
workspaceId,
- env: userAvailableEnvs?.map(env => env.slug) ?? [],
+ env: userAvailableEnvs?.map((env) => env.slug) ?? [],
decryptFileKey: latestFileKey!,
isPaused: false
});
- // mutation calls
- const { mutateAsync: createWsTag } = useCreateWsTag();
-
const method = useForm<FormData>({
// why any: well yup inferred ts expects other keys to defined as undefined
defaultValues: secrets as any,
@@ -90,39 +61,24 @@ export const DashboardEnvOverview = ({onEnvChange}: {onEnvChange: any;}) => {
resolver: yupResolver(schema)
});
- const {
- control,
- // handleSubmit,
- // getValues,
- // setValue,
- // formState: { isSubmitting, dirtyFields },
- // reset
- } = method;
- const formSecrets = useWatch({ control, name: 'secrets' });
+ const numSecretsMissingPerEnv = useMemo(() => {
+ // first get all sec in the env then subtract with total to get missing ones
+ const secPerEnvMissing: Record<string, number> = Object.fromEntries(
+ (userAvailableEnvs || [])?.map(({ slug }) => [slug, 0])
+ );
+ Object.keys(secrets?.secrets || {}).forEach((key) =>
+ secrets?.secrets?.[key].forEach((val) => {
+ secPerEnvMissing[val.env] += 1;
+ })
+ );
+ Object.keys(secPerEnvMissing).forEach((k) => {
+ secPerEnvMissing[k] = (secrets?.uniqueSecCount || 0) - secPerEnvMissing[k];
+ });
+ return secPerEnvMissing;
+ }, [secrets, userAvailableEnvs]);
const isReadOnly = selectedEnv?.isWriteDenied;
- const onCreateWsTag = async (tagName: string) => {
- try {
- await createWsTag({
- workspaceID: workspaceId,
- tagName,
- tagSlug: tagName.replace(' ', '_')
- });
- handlePopUpClose('addTag');
- createNotification({
- text: 'Successfully created a tag',
- type: 'success'
- });
- } catch (error) {
- console.error(error);
- createNotification({
- text: 'Failed to create a tag',
- type: 'error'
- });
- }
- };
-
if (isSecretsLoading || isEnvListLoading) {
return (
<div className="container mx-auto flex h-screen w-full items-center justify-center px-8 text-mineshaft-50 dark:[color-scheme:dark]">
@@ -132,9 +88,7 @@ export const DashboardEnvOverview = ({onEnvChange}: {onEnvChange: any;}) => {
}
// when secrets is not loading and secrets list is empty
- const isDashboardSecretEmpty = !isSecretsLoading && !formSecrets?.length;
-
- const numSecretsMissingPerEnv = userAvailableEnvs?.map(envir => ({[envir.slug]: [... new Set(secrets?.secrets.map((secret: any) => secret.key))].length - [... new Set(secrets?.secrets.filter(s => s.env === envir.slug).map((secret: any) => secret.key))].length})).reduce((acc, cur) => ({ ...acc, ...cur }), {})
+ const isDashboardSecretEmpty = !isSecretsLoading && !Object.keys(secrets?.secrets || {})?.length;
return (
<div className="container mx-auto max-w-full px-6 text-mineshaft-50 dark:[color-scheme:dark]">
@@ -146,55 +100,77 @@ export const DashboardEnvOverview = ({onEnvChange}: {onEnvChange: any;}) => {
</div>
<div className="mt-6 ml-1">
<p className="text-3xl font-semibold text-bunker-100">Secrets Overview</p>
- <p className="text-md text-bunker-300">Inject your secrets using
- <a
- className="text-primary/80 hover:text-primary mx-1"
- href="https://infisical.com/docs/cli/overview"
+ <p className="text-md text-bunker-300">
+ Inject your secrets using
+ <a
+ className="mx-1 text-primary/80 hover:text-primary"
+ href="https://infisical.com/docs/cli/overview"
target="_blank"
rel="noopener noreferrer"
>
Infisical CLI
- </a>
- or
- <a
- className="text-primary/80 hover:text-primary mx-1"
- href="https://infisical.com/docs/sdks/overview"
+ </a>
+ or
+ <a
+ className="mx-1 text-primary/80 hover:text-primary"
+ href="https://infisical.com/docs/sdks/overview"
target="_blank"
rel="noopener noreferrer"
>
Infisical SDKs
- </a> </p>
+ </a>
+ </p>
</div>
<div className="overflow-y-auto">
- <div className="sticky top-0 absolute flex flex-row h-10 bg-mineshaft-800 border border-mineshaft-600 rounded-md mt-8 min-w-[60.3rem]">
- <div className="sticky top-0 w-10 px-4 flex items-center justify-center border-none">
- <div className='text-center w-10 text-xs text-transparent'>{0}</div>
+ <div className="sticky top-0 mt-8 flex h-10 min-w-[60.3rem] flex-row rounded-md border border-mineshaft-600 bg-mineshaft-800">
+ <div className="sticky top-0 flex w-10 items-center justify-center border-none px-4">
+ <div className="w-10 text-center text-xs text-transparent">{0}</div>
</div>
<div className="sticky top-0 border-none">
- <div className="min-w-[200px] lg:min-w-[220px] xl:min-w-[250px] relative flex items-center justify-start h-full w-full">
+ <div className="relative flex h-full w-full min-w-[200px] items-center justify-start lg:min-w-[220px] xl:min-w-[250px]">
<div className="text-sm font-medium ">Secret</div>
</div>
</div>
- {numSecretsMissingPerEnv && userAvailableEnvs?.map(env => {
- return <div key={`header-${env.slug}`} className="flex flex-row w-full bg-mineshaft-800 rounded-md items-center border-none min-w-[11rem]">
- <div className="text-sm font-medium w-full text-center text-bunker-200/[.99] flex flex-row justify-center">
- {env.name}
- {numSecretsMissingPerEnv[env.slug] > 0 && <div className="bg-red rounded-sm h-[1.1rem] w-[1.1rem] mt-0.5 text-bunker-100 ml-2.5 text-xs border border-red-400 flex items-center justify-center cursor-default">
- <Tooltip content={`${numSecretsMissingPerEnv[env.slug]} secrets missing compared to other environments`}><span className="text-bunker-100">{numSecretsMissingPerEnv[env.slug]}</span></Tooltip>
- </div>}
- </div>
- </div>
- })}
+ {numSecretsMissingPerEnv &&
+ userAvailableEnvs?.map((env) => {
+ return (
+ <div
+ key={`header-${env.slug}`}
+ className="flex w-full min-w-[11rem] flex-row items-center rounded-md border-none bg-mineshaft-800"
+ >
+ <div className="flex w-full flex-row justify-center text-center text-sm font-medium text-bunker-200/[.99]">
+ {env.name}
+ {numSecretsMissingPerEnv[env.slug] > 0 && (
+ <div className="mt-0.5 ml-2.5 flex h-[1.1rem] w-[1.1rem] cursor-default items-center justify-center rounded-sm border border-red-400 bg-red text-xs text-bunker-100">
+ <Tooltip
+ content={`${
+ numSecretsMissingPerEnv[env.slug]
+ } secrets missing compared to other environments`}
+ >
+ <span className="text-bunker-100">
+ {numSecretsMissingPerEnv[env.slug]}
+ </span>
+ </Tooltip>
+ </div>
+ )}
+ </div>
+ </div>
+ );
+ })}
</div>
- <div className={`${isDashboardSecretEmpty ? "" : ""} flex flex-row items-start justify-center mt-3 h-full max-h-[calc(100vh-370px)] min-w-[60.3rem] flex-grow w-full overflow-x-hidden no-scrollbar no-scrollbar::-webkit-scrollbar`}>
+ <div
+ className={`${
+ isDashboardSecretEmpty ? '' : ''
+ } no-scrollbar::-webkit-scrollbar mt-3 flex h-full max-h-[calc(100vh-370px)] w-full min-w-[60.3rem] flex-grow flex-row items-start justify-center overflow-x-hidden no-scrollbar`}
+ >
{!isDashboardSecretEmpty && (
- <TableContainer className='border-none'>
- <table className="relative secret-table w-full relative bg-bunker-800">
- <tbody className="overflow-y-auto max-h-screen">
- {[... new Set(secrets?.secrets.map((secret: any) => secret.key))].map((key, index) => (
+ <TableContainer className="border-none">
+ <table className="secret-table relative w-full bg-bunker-800">
+ <tbody className="max-h-screen overflow-y-auto">
+ {Object.keys(secrets?.secrets || {}).map((key, index) => (
<EnvComparisonRow
key={`row-${key}`}
- secrets={secrets?.secrets.filter(secret => secret.key === key)}
+ secrets={secrets?.secrets?.[key]}
isReadOnly={isReadOnly}
index={index}
isSecretValueHidden
@@ -205,22 +181,23 @@ export const DashboardEnvOverview = ({onEnvChange}: {onEnvChange: any;}) => {
</table>
</TableContainer>
)}
- {isDashboardSecretEmpty &&
- <div className='flex flex-row h-40 rounded-md mt-1 w-full'>
- <div className="sticky top-0 w-10 px-4 flex items-center justify-center border-none">
- <div className='text-center w-10 text-xs text-transparent'>{0}</div>
+ {isDashboardSecretEmpty && (
+ <div className="mt-1 flex h-40 w-full flex-row rounded-md">
+ <div className="sticky top-0 flex w-10 items-center justify-center border-none px-4">
+ <div className="w-10 text-center text-xs text-transparent">{0}</div>
</div>
<div className="sticky top-0 border-none">
- <div className="min-w-[200px] lg:min-w-[220px] xl:min-w-[250px] relative flex items-center justify-start h-full w-full">
+ <div className="relative flex h-full w-full min-w-[200px] items-center justify-start lg:min-w-[220px] xl:min-w-[250px]">
<div className="text-sm font-medium text-transparent">Secret</div>
</div>
</div>
- <div className="flex flex-col w-full bg-mineshaft-800 text-bunker-300 rounded-md items-center justify-center border-none mx-2 min-w-[11rem]">
+ <div className="mx-2 flex w-full min-w-[11rem] flex-col items-center justify-center rounded-md border-none bg-mineshaft-800 text-bunker-300">
<span className="mb-1">No secrets are available in this project yet.</span>
<span>You can go into any environment to add secrets there.</span>
</div>
- </div>}
- {/* In future, we should add an option to add environments here
+ </div>
+ )}
+ {/* In future, we should add an option to add environments here
<div className="ml-10 h-full flex items-start justify-center">
<Button
leftIcon={<FontAwesomeIcon icon={faPlus}/>}
@@ -234,14 +211,22 @@ export const DashboardEnvOverview = ({onEnvChange}: {onEnvChange: any;}) => {
</Button>
</div> */}
</div>
- <div className="group flex flex-row items-center mt-4 min-w-[60.3rem]">
- <div className="w-10 h-10 px-4 flex items-center justify-center border-none"><div className='text-center w-10 text-xs text-transparent'>0</div></div>
- <div className="flex flex-row justify-between items-center min-w-[200px] lg:min-w-[220px] xl:min-w-[250px]">
+ <div className="group mt-4 flex min-w-[60.3rem] flex-row items-center">
+ <div className="flex h-10 w-10 items-center justify-center border-none px-4">
+ <div className="w-10 text-center text-xs text-transparent">0</div>
+ </div>
+ <div className="flex min-w-[200px] flex-row items-center justify-between lg:min-w-[220px] xl:min-w-[250px]">
<span className="text-transparent">0</span>
- <button type="button" className='mr-2 text-transparent'>1</button>
+ <button type="button" className="mr-2 text-transparent">
+ 1
+ </button>
</div>
- {userAvailableEnvs?.map(env => {
- return <div key={`button-${env.slug}`} className="flex flex-row w-full justify-center h-10 items-center border-none mb-1 mx-2 min-w-[11rem]">
+ {userAvailableEnvs?.map((env) => {
+ return (
+ <div
+ key={`button-${env.slug}`}
+ className="mx-2 mb-1 flex h-10 w-full min-w-[11rem] flex-row items-center justify-center border-none"
+ >
<Button
onClick={() => onEnvChange(env.slug)}
// router.push(`${router.asPath }?env=${env.slug}`)
@@ -253,23 +238,11 @@ export const DashboardEnvOverview = ({onEnvChange}: {onEnvChange: any;}) => {
Explore {env.name}
</Button>
</div>
+ );
})}
- </div>
+ </div>
</div>
</form>
- <Modal
- isOpen={popUp?.addTag?.isOpen}
- onOpenChange={(open) => {
- handlePopUpToggle('addTag', open);
- }}
- >
- <ModalContent
- title="Create tag"
- subTitle="Specify your tag name, and the slug will be created automatically."
- >
- <CreateTagModal onCreateTag={onCreateWsTag} />
- </ModalContent>
- </Modal>
</FormProvider>
</div>
);
diff --git a/frontend/src/views/DashboardPage/DashboardPage.tsx b/frontend/src/views/DashboardPage/DashboardPage.tsx
index 75a42c0df8..9a005ccac3 100644
--- a/frontend/src/views/DashboardPage/DashboardPage.tsx
+++ b/frontend/src/views/DashboardPage/DashboardPage.tsx
@@ -1,5 +1,5 @@
-import { useEffect, useState } from 'react';
-import { FormProvider, useFieldArray, useForm, useWatch } from 'react-hook-form';
+import { useEffect, useRef, useState } from 'react';
+import { FormProvider, useFieldArray, useForm } from 'react-hook-form';
import { useTranslation } from 'react-i18next';
import { useRouter } from 'next/router';
import {
@@ -90,6 +90,7 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
const { createNotification } = useNotificationContext();
const queryClient = useQueryClient();
+ const secretContainer = useRef<HTMLDivElement | null>(null);
const { popUp, handlePopUpOpen, handlePopUpToggle, handlePopUpClose } = usePopUp([
'secretDetails',
'addTag',
@@ -102,7 +103,7 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
const [snapshotId, setSnaphotId] = useState<string | null>(null);
const [selectedEnv, setSelectedEnv] = useState<WorkspaceEnv | null>(null);
const [sortDir, setSortDir] = useState<'asc' | 'desc'>('asc');
- const [deletedSecretIds, setDeletedSecretIds] = useState<string[]>([]);
+ const deletedSecretIds = useRef<string[]>([]);
const { hasUnsavedChanges, setHasUnsavedChanges } = useLeaveConfirm({ initialValue: false });
const { currentWorkspace, isLoading } = useWorkspace();
@@ -124,8 +125,8 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
onSuccess: (data) => {
// get an env with one of the access available
const env = data.find(({ isReadDenied, isWriteDenied }) => !isWriteDenied || !isReadDenied);
- if (env && data?.map(wsenv => wsenv.slug).includes(envFromTop)) {
- setSelectedEnv(data?.filter(dp => dp.slug === envFromTop)[0]);
+ if (env && data?.map((wsenv) => wsenv.slug).includes(envFromTop)) {
+ setSelectedEnv(data?.filter((dp) => dp.slug === envFromTop)[0]);
}
}
});
@@ -187,23 +188,15 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
handleSubmit,
getValues,
setValue,
- formState: { isSubmitting, dirtyFields },
+ formState: { isSubmitting, isDirty },
reset
} = method;
- const formSecrets = useWatch({ control, name: 'secrets' });
- const { fields, prepend, append, remove, update } = useFieldArray({ control, name: 'secrets' });
-
+ const { fields, prepend, append, remove } = useFieldArray({ control, name: 'secrets' });
const isRollbackMode = Boolean(snapshotId);
const isReadOnly = selectedEnv?.isWriteDenied;
const isAddOnly = selectedEnv?.isReadDenied && !selectedEnv?.isWriteDenied;
const canDoRollback = !isReadOnly && !isAddOnly;
- const isSubmitDisabled =
- isReadOnly ||
- // on add only mode the formstate becomes dirty due to secrets missing some items
- // to avoid this we check dirtyFields in isAddOnly Mode
- (isAddOnly && Object.keys(dirtyFields).length === 0) ||
- (!isRollbackMode && !isAddOnly && Object.keys(dirtyFields).length === 0) ||
- isSubmitting;
+ const isSubmitDisabled = isReadOnly || (!isRollbackMode && !isDirty) || isAddOnly || isSubmitting;
useEffect(() => {
if (!isSnapshotChanging && Boolean(snapshotId)) {
@@ -240,15 +233,16 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
// append non conflicting ones
Object.keys(uploadedSec).forEach((key) => {
if (!conflictingSecIds?.[key]) {
- append({
+ delete conflictingUploadedSec[key];
+ sec.push({
...DEFAULT_SECRET_VALUE,
key,
value: uploadedSec[key].value,
comment: uploadedSec[key].comments.join(',')
});
- delete conflictingUploadedSec[key];
}
});
+ setValue('secrets', sec, { shouldDirty: true });
if (conflictingSec.length > 0) {
handlePopUpOpen('uploadedSecOpts', { secrets: conflictingUploadedSec });
}
@@ -264,14 +258,15 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
data.forEach(({ key, index }) => {
const { value, comments } = uploadedSec[key];
const comment = comments.join(', ');
- update(index, {
+ sec[index] = {
...DEFAULT_SECRET_VALUE,
key,
value,
comment,
tags: sec[index].tags
- });
+ };
});
+ setValue('secrets', sec, { shouldDirty: true });
handlePopUpClose('uploadedSecOpts');
};
@@ -319,7 +314,12 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
const sec = isAddOnly ? userSec.filter(({ _id }) => !_id) : userSec;
// encrypt and format the secrets to batch api format
// requests = [ {method:"", secret:""} ]
- const batchedSecret = transformSecretsToBatchSecretReq(deletedSecretIds, latestFileKey, sec);
+ const batchedSecret = transformSecretsToBatchSecretReq(
+ deletedSecretIds.current,
+ latestFileKey,
+ sec,
+ secrets?.secrets
+ );
// type check
if (!selectedEnv?.slug) return;
try {
@@ -332,6 +332,7 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
text: 'Successfully saved changes',
type: 'success'
});
+ deletedSecretIds.current = [];
if (!hasUserPushed) {
await registerUserAction(USER_ACTION_PUSH);
}
@@ -355,16 +356,17 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
}
const env = wsEnv?.find((el) => el.slug === slug);
if (env) setSelectedEnv(env);
- router.push(`${router.asPath.split("?")[0]}?env=${slug}`)
+ router.push({
+ pathname: router.pathname,
+ query: { ...router.query, env: slug }
+ });
};
// record all deleted ids
// This will make final deletion easier
const onSecretDelete = (index: number, id?: string, overrideId?: string) => {
- const ids: string[] = [];
- if (id) ids.push(id);
- if (overrideId) ids.push(overrideId);
- setDeletedSecretIds((state) => [...state, ...ids]);
+ if (id) deletedSecretIds.current.push(id);
+ if (overrideId) deletedSecretIds.current.push(overrideId);
remove(index);
// just the case if this is called from drawer
handlePopUpClose('secretDetails');
@@ -400,7 +402,7 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
}
// when secrets is not loading and secrets list is empty
- const isDashboardSecretEmpty = !isSecretsLoading && !formSecrets?.length;
+ const isDashboardSecretEmpty = !isSecretsLoading && false;
// when using snapshot mode and snapshot is loading and snapshot list is empty
const isSnapshotSecretEmtpy =
isRollbackMode && !isSnapshotSecretsLoading && !snapshotSecret?.secrets?.length;
@@ -411,15 +413,17 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
);
return (
- <div className="container mx-auto max-w-full px-6 text-mineshaft-50 dark:[color-scheme:dark]">
+ <div className="container mx-auto px-6 text-mineshaft-50 dark:[color-scheme:dark]">
<FormProvider {...method}>
<form autoComplete="off">
{/* breadcrumb row */}
<div className="relative right-5">
- <NavHeader
- pageName={t('dashboard:title')}
- currentEnv={userAvailableEnvs?.filter(envir => envir.slug === envFromTop)[0].name || ''}
- isProjectRelated
+ <NavHeader
+ pageName={t('dashboard:title')}
+ currentEnv={
+ userAvailableEnvs?.filter((envir) => envir.slug === envFromTop)[0].name || ''
+ }
+ isProjectRelated
userAvailableEnvs={userAvailableEnvs}
onEnvChange={onEnvChange}
/>
@@ -445,7 +449,7 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
setSnaphotId(null);
reset({ ...secrets, isSnapshotMode: false });
}}
- className='h-10'
+ className="h-10"
>
Go back
</Button>
@@ -456,7 +460,7 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
leftIcon={<FontAwesomeIcon icon={faCodeCommit} />}
isLoading={isLoadingSnapshotCount}
isDisabled={!canDoRollback}
- className='h-10'
+ className="h-10"
>
{snapshotCount} Commits
</Button>
@@ -465,7 +469,7 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
isLoading={isSubmitting}
leftIcon={<FontAwesomeIcon icon={isRollbackMode ? faClockRotateLeft : faCheck} />}
onClick={handleSubmit(onSaveSecret)}
- className='h-10'
+ className="h-10"
>
{isRollbackMode ? 'Rollback' : 'Save Changes'}
</Button>
@@ -475,7 +479,7 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
<div className="mt-4 flex items-center space-x-2">
<div className="flex-grow">
<Input
- className="bg-mineshaft-600 h-[2.3rem] placeholder-mineshaft-50"
+ className="h-[2.3rem] bg-mineshaft-600 placeholder-mineshaft-50"
placeholder="Search keys..."
value={searchFilter}
onChange={(e) => setSearchFilter(e.target.value)}
@@ -490,12 +494,15 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
<FontAwesomeIcon icon={faDownload} />
</IconButton>
</PopoverTrigger>
- <PopoverContent className="w-auto bg-mineshaft-800 border border-mineshaft-600 p-1" hideCloseBtn>
+ <PopoverContent
+ className="w-auto border border-mineshaft-600 bg-mineshaft-800 p-1"
+ hideCloseBtn
+ >
<div className="flex flex-col space-y-2">
<Button
onClick={() => downloadSecret(getValues('secrets'), selectedEnv?.slug)}
variant="star"
- className="bg-bunker-700 h-8"
+ className="h-8 bg-bunker-700"
>
Download as .env
</Button>
@@ -514,26 +521,38 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
</IconButton>
</Tooltip>
</div>
- {!isReadOnly && !isRollbackMode && <Button
- leftIcon={<FontAwesomeIcon icon={faPlus} />}
- onClick={() => prepend(DEFAULT_SECRET_VALUE, { shouldFocus: false })}
- isDisabled={isReadOnly || isRollbackMode}
- variant="star"
- className="h-10"
- >
- Add Secret
- </Button>}
+ {!isReadOnly && !isRollbackMode && (
+ <Button
+ leftIcon={<FontAwesomeIcon icon={faPlus} />}
+ onClick={() => {
+ if (secretContainer.current) {
+ secretContainer.current.scroll({
+ top: 0,
+ behavior: 'smooth'
+ });
+ }
+ prepend(DEFAULT_SECRET_VALUE, { shouldFocus: false });
+ }}
+ isDisabled={isReadOnly || isRollbackMode}
+ variant="star"
+ className="h-10"
+ >
+ Add Secret
+ </Button>
+ )}
</div>
</div>
- <div className={`${isSecretEmpty ? "flex flex-col items-center justify-center" : ""} mt-4 h-[calc(100vh-270px)] overflow-y-scroll overflow-x-hidden no-scrollbar no-scrollbar::-webkit-scrollbar`}>
+ <div
+ className={`${
+ isSecretEmpty ? 'flex flex-col items-center justify-center' : ''
+ } no-scrollbar::-webkit-scrollbar mt-4 h-[calc(100vh-270px)] overflow-x-hidden overflow-y-scroll no-scrollbar`}
+ ref={secretContainer}
+ >
{!isSecretEmpty && (
<TableContainer>
<table className="secret-table relative">
- <SecretTableHeader
- sortDir={sortDir}
- onSort={onSortSecrets}
- />
- <tbody className="overflow-y-auto max-h-screen">
+ <SecretTableHeader sortDir={sortDir} onSort={onSortSecrets} />
+ <tbody className="max-h-screen overflow-y-auto">
{fields.map(({ id, _id }, index) => (
<SecretInputRow
key={id}
@@ -554,11 +573,11 @@ export const DashboardPage = ({ envFromTop }: { envFromTop: string }) => {
<td colSpan={3} className="hover:bg-mineshaft-700">
<button
type="button"
- className="w-[calc(100vw-400px)] h-8 ml-12 font-normal text-bunker-300 flex justify-start items-center"
+ className="ml-12 flex h-8 items-center justify-start font-normal text-bunker-300"
onClick={onAppendSecret}
>
<FontAwesomeIcon icon={faPlus} />
- <span className="w-20 ml-2">Add Secret</span>
+ <span className="ml-2 w-20">Add Secret</span>
</button>
</td>
</tr>
diff --git a/frontend/src/views/DashboardPage/DashboardPage.utils.ts b/frontend/src/views/DashboardPage/DashboardPage.utils.ts
index ef754d1c52..f62707a3d4 100644
--- a/frontend/src/views/DashboardPage/DashboardPage.utils.ts
+++ b/frontend/src/views/DashboardPage/DashboardPage.utils.ts
@@ -1,3 +1,4 @@
+/* eslint-disable @typescript-eslint/naming-convention */
import crypto from 'crypto';
import * as yup from 'yup';
@@ -6,7 +7,7 @@ import {
decryptAssymmetric,
encryptSymmetric
} from '@app/components/utilities/cryptography/crypto';
-import { BatchSecretDTO } from '@app/hooks/api/secrets/types';
+import { BatchSecretDTO, DecryptedSecret } from '@app/hooks/api/secrets/types';
export enum SecretActionType {
Created = 'created',
@@ -147,10 +148,18 @@ const encryptASecret = (randomBytes: string, key: string, value?: string, commen
};
};
+const deepCompareSecrets = (lhs: DecryptedSecret, rhs: any) =>
+ lhs.key === rhs.key &&
+ lhs.value === rhs.value &&
+ lhs.comment === rhs.comment &&
+ lhs?.valueOverride === rhs?.valueOverride &&
+ JSON.stringify(lhs.tags) === JSON.stringify(rhs.tags);
+
export const transformSecretsToBatchSecretReq = (
deletedSecretIds: string[],
latestFileKey: any,
- secrets: FormData['secrets']
+ secrets: FormData['secrets'],
+ intialValues: DecryptedSecret[] = []
) => {
// deleted secrets
const secretsToBeDeleted: BatchSecretDTO['requests'] = deletedSecretIds.map((id) => ({
@@ -171,61 +180,80 @@ export const transformSecretsToBatchSecretReq = (
})
: crypto.randomBytes(16).toString('hex');
- secrets?.forEach(
- ({ _id, idOverride, value, valueOverride, overrideAction, tags = [], comment, key }) => {
- if (!idOverride && overrideAction === SecretActionType.Created) {
- secretsToBeCreated.push({
- method: 'POST',
- secret: {
- type: 'personal',
- tags,
- ...encryptASecret(randomBytes, key, valueOverride, comment)
- }
- });
- }
- // to be created ones as they don't have server generated id
- if (!_id) {
- secretsToBeCreated.push({
- method: 'POST',
- secret: {
- type: 'shared',
- tags,
- ...encryptASecret(randomBytes, key, value, comment)
- }
- });
- return; // exit as updated and delete case won't happen when created
- }
- // has an id means this is updated one
- if (_id) {
+ secrets?.forEach((secret) => {
+ const {
+ _id,
+ idOverride,
+ value,
+ valueOverride,
+ overrideAction,
+ tags = [],
+ comment,
+ key
+ } = secret;
+ if (!idOverride && overrideAction === SecretActionType.Created) {
+ secretsToBeCreated.push({
+ method: 'POST',
+ secret: {
+ type: 'personal',
+ tags,
+ secretName: key,
+ ...encryptASecret(randomBytes, key, valueOverride, comment)
+ }
+ });
+ }
+ // to be created ones as they don't have server generated id
+ if (!_id) {
+ secretsToBeCreated.push({
+ method: 'POST',
+ secret: {
+ type: 'shared',
+ tags,
+ secretName: key,
+ ...encryptASecret(randomBytes, key, value, comment)
+ }
+ });
+ return; // exit as updated and delete case won't happen when created
+ }
+ // has an id means this is updated one
+ if (_id) {
+ // check value has changed or not
+ const initialSecretValue = intialValues?.find(({ _id: secId }) => secId === _id)!;
+ if (!deepCompareSecrets(initialSecretValue, secret)) {
secretsToBeUpdated.push({
method: 'PATCH',
secret: {
_id,
type: 'shared',
tags,
+ secretName: key,
...encryptASecret(randomBytes, key, value, comment)
}
});
}
- if (idOverride) {
- // if action is deleted meaning override has been removed but id is kept to collect at this point
- if (overrideAction === SecretActionType.Deleted) {
- secretsToBeDeleted.push({ method: 'DELETE', secret: { _id: idOverride } });
- } else {
- // if not deleted action then as id is there its an updated
+ }
+ if (idOverride) {
+ // if action is deleted meaning override has been removed but id is kept to collect at this point
+ if (overrideAction === SecretActionType.Deleted) {
+ secretsToBeDeleted.push({ method: 'DELETE', secret: { _id: idOverride } });
+ } else {
+ // if not deleted action then as id is there its an updated
+ const initialSecretValue = intialValues?.find(({ _id: secId }) => secId === _id)!;
+ if (!deepCompareSecrets(initialSecretValue, secret)) {
secretsToBeUpdated.push({
method: 'PATCH',
secret: {
_id: idOverride,
type: 'personal',
tags,
+ secretName: key,
...encryptASecret(randomBytes, key, valueOverride, comment)
}
});
}
}
}
- );
+ });
return secretsToBeCreated.concat(secretsToBeUpdated, secretsToBeDeleted);
};
diff --git a/frontend/src/views/DashboardPage/components/EnvComparisonRow/EnvComparisonRow.tsx b/frontend/src/views/DashboardPage/components/EnvComparisonRow/EnvComparisonRow.tsx
index ec9b1cb8dd..ab25ba4963 100644
--- a/frontend/src/views/DashboardPage/components/EnvComparisonRow/EnvComparisonRow.tsx
+++ b/frontend/src/views/DashboardPage/components/EnvComparisonRow/EnvComparisonRow.tsx
@@ -1,12 +1,8 @@
/* eslint-disable react/jsx-no-useless-fragment */
-import { SyntheticEvent, useRef, useState } from 'react';
-import { useFormContext, useWatch } from 'react-hook-form';
+import { useCallback, useState } from 'react';
import { faCircle, faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
-
-import guidGenerator from '@app/components/utilities/randomId';
-
-import { FormData } from '../../DashboardPage.utils';
+import { twMerge } from 'tailwind-merge';
type Props = {
index: number;
@@ -19,84 +15,97 @@ type Props = {
const REGEX = /([$]{.*?})/g;
-const DashboardInput = ({ isOverridden, isSecretValueHidden, isReadOnly, secret, index }: { isOverridden: boolean, isSecretValueHidden: boolean, isReadOnly?: boolean, secret: any, index: number } ): JSX.Element => {
- const ref = useRef<HTMLDivElement | null>(null);
- const syncScroll = (e: SyntheticEvent<HTMLDivElement>) => {
- if (ref.current === null) return;
-
- ref.current.scrollTop = e.currentTarget.scrollTop;
- ref.current.scrollLeft = e.currentTarget.scrollLeft;
- };
-
- return <td key={`row-${secret?.key || ''}--`} className={`flex cursor-default flex-row w-full justify-center h-10 items-center ${!(secret?.value || secret?.value === '') ? "bg-red-400/10" : "bg-mineshaft-900/30"}`}>
- <div className="group relative whitespace-pre flex flex-col justify-center w-full cursor-default">
- <input
- // {...register(`secrets.${index}.valueOverride`)}
- defaultValue={(isOverridden ? secret.valueOverride : secret?.value || '')}
- onScroll={syncScroll}
- readOnly={isReadOnly}
- className={`${
- isSecretValueHidden
- ? 'text-transparent focus:text-transparent active:text-transparent'
- : ''
- } z-10 peer cursor-default font-mono ph-no-capture bg-transparent caret-transparent text-transparent text-sm px-2 py-2 w-full outline-none duration-200 no-scrollbar no-scrollbar::-webkit-scrollbar`}
- spellCheck="false"
- />
- <div
- ref={ref}
- className={`${
- isSecretValueHidden && !isOverridden && secret?.value
- ? 'text-bunker-800 group-hover:text-gray-400 peer-focus:text-gray-100 peer-active:text-gray-400 duration-200'
- : ''
- } ${!secret?.value && "text-bunker-400 justify-center"}
- absolute cursor-default flex flex-row whitespace-pre font-mono z-0 ${isSecretValueHidden && secret?.value ? 'invisible' : 'visible'} peer-focus:visible mt-0.5 ph-no-capture overflow-x-scroll bg-transparent h-10 text-sm px-2 py-2 w-full min-w-16 outline-none duration-100 no-scrollbar no-scrollbar::-webkit-scrollbar`}
- >
- {(secret?.value || secret?.value === '') && (isOverridden ? secret.valueOverride : secret?.value)?.split('').length === 0 && <span className='text-bunker-400/80 font-sans w-full'>EMPTY</span>}
- {(secret?.value || secret?.value === '') && (isOverridden ? secret.valueOverride : secret?.value)?.split(REGEX).map((word: string) => {
- if (word.match(REGEX) !== null) {
- return (
- <span className="ph-no-capture text-yellow" key={word}>
- {word.slice(0, 2)}
- <span className="ph-no-capture text-yellow-200/80">
- {word.slice(2, word.length - 1)}
- </span>
- {word.slice(word.length - 1, word.length) === '}' ? (
- <span className="ph-no-capture text-yellow">
- {word.slice(word.length - 1, word.length)}
- </span>
- ) : (
- <span className="ph-no-capture text-yellow-400">
- {word.slice(word.length - 1, word.length)}
- </span>
- )}
- </span>
- );
- }
- return (
- <span key={`${word}_${index + 1}`} className="ph-no-capture">
- {word}
+const DashboardInput = ({
+ isOverridden,
+ isSecretValueHidden,
+ secret,
+ isReadOnly = true
+}: {
+ isOverridden: boolean;
+ isSecretValueHidden: boolean;
+ isReadOnly?: boolean;
+ secret?: any;
+}): JSX.Element => {
+ const syntaxHighlight = useCallback((val: string) => {
+ if (!val)
+ return (
+ <span className="cursor-default font-sans text-xs italic text-red-500/80">missing</span>
+ );
+ if (val?.length === 0)
+ return <span className="w-full font-sans text-bunker-400/80">EMPTY</span>;
+ return val?.split(REGEX).map((word, index) =>
+ word.match(REGEX) !== null ? (
+ <span className="ph-no-capture text-yellow" key={`${val}-${index + 1}`}>
+ {word.slice(0, 2)}
+ <span className="ph-no-capture text-yellow-200/80">{word.slice(2, word.length - 1)}</span>
+ {word.slice(word.length - 1, word.length) === '}' ? (
+ <span className="ph-no-capture text-yellow">
+ {word.slice(word.length - 1, word.length)}
</span>
- );
- })}
- {!(secret?.value || secret?.value === '') && <span className='text-red-500/80 cursor-default font-sans text-xs italic'>missing</span>}
- </div>
- {(isSecretValueHidden && secret?.value) && (
- <div className='absolute flex flex-row justify-between items-center z-0 peer pr-2 peer-active:hidden peer-focus:hidden group-hover:bg-white/[0.00] duration-100 h-10 w-full text-bunker-400 text-clip'>
- <div className="px-2 flex flex-row items-center overflow-x-scroll no-scrollbar no-scrollbar::-webkit-scrollbar">
- {(isOverridden ? secret.valueOverride : secret?.value || '')?.split('').map(() => (
- <FontAwesomeIcon
- key={guidGenerator()}
- className="text-xxs mr-0.5"
- icon={faCircle}
- />
- ))}
- {(isOverridden ? secret.valueOverride : secret?.value || '')?.split('').length === 0 && <span className='text-bunker-400/80 text-sm'>EMPTY</span>}
- </div>
+ ) : (
+ <span className="ph-no-capture text-yellow-400">
+ {word.slice(word.length - 1, word.length)}
+ </span>
+ )}
+ </span>
+ ) : (
+ <span key={word} className="ph-no-capture">
+ {word}
+ </span>
+ )
+ );
+ }, []);
+
+ return (
+ <td
+ key={`row-${secret?.key || ''}--`}
+ className={`flex h-10 w-full cursor-default flex-row items-center justify-center ${
+ !(secret?.value || secret?.value === '') ? 'bg-red-400/10' : 'bg-mineshaft-900/30'
+ }`}
+ >
+ <div className="group relative flex w-full cursor-default flex-col justify-center whitespace-pre">
+ <input
+ value={isOverridden ? secret.valueOverride : secret?.value || ''}
+ readOnly={isReadOnly}
+ className={twMerge(
+ 'ph-no-capture no-scrollbar::-webkit-scrollbar duration-50 peer z-10 w-full cursor-default bg-transparent px-2 py-2 font-mono text-sm text-transparent caret-transparent outline-none no-scrollbar',
+ isSecretValueHidden && 'text-transparent focus:text-transparent active:text-transparent'
+ )}
+ spellCheck="false"
+ />
+ <div
+ className={twMerge(
+ 'ph-no-capture min-w-16 no-scrollbar::-webkit-scrollbar duration-50 absolute z-0 mt-0.5 flex h-10 w-full cursor-default flex-row overflow-x-scroll whitespace-pre bg-transparent px-2 py-2 font-mono text-sm outline-none no-scrollbar peer-focus:visible',
+ isSecretValueHidden && secret?.value ? 'invisible' : 'visible',
+ isSecretValueHidden &&
+ secret?.value &&
+ 'duration-50 text-bunker-800 group-hover:text-gray-400 peer-focus:text-gray-100 peer-active:text-gray-400',
+ !secret?.value && 'justify-center text-bunker-400'
+ )}
+ >
+ {syntaxHighlight(secret?.value)}
</div>
- )}
- </div>
- </td>
-}
+ {isSecretValueHidden && secret?.value && (
+ <div className="duration-50 peer absolute z-0 flex h-10 w-full flex-row items-center justify-between text-clip pr-2 text-bunker-400 group-hover:bg-white/[0.00] peer-focus:hidden peer-active:hidden">
+ <div className="no-scrollbar::-webkit-scrollbar flex flex-row items-center overflow-x-scroll px-2 no-scrollbar">
+ {(isOverridden ? secret.valueOverride : secret?.value || '')
+ ?.split('')
+ .map((_a: string, index: number) => (
+ <FontAwesomeIcon
+ key={`${secret?.value}_${index + 1}`}
+ className="mr-0.5 text-xxs"
+ icon={faCircle}
+ />
+ ))}
+ {(isOverridden ? secret.valueOverride : secret?.value || '')?.split('').length ===
+ 0 && <span className="text-sm text-bunker-400/80">EMPTY</span>}
+ </div>
+ </div>
+ )}
+ </div>
+ </td>
+ );
+};
export const EnvComparisonRow = ({
index,
@@ -105,27 +114,39 @@ export const EnvComparisonRow = ({
isReadOnly,
userAvailableEnvs
}: Props): JSX.Element => {
- const {
- // register, setValue,
- control } = useFormContext<FormData>();
-
- // to get details on a secret
- const secret = useWatch({ name: `secrets.${index}`, control });
-
const [areValuesHiddenThisRow, setAreValuesHiddenThisRow] = useState(true);
+ const getSecretByEnv = useCallback(
+ (secEnv: string, secs?: any[]) => secs?.find(({ env }) => env === secEnv),
+ []
+ );
+
return (
- <tr className="group min-w-full flex flex-row items-center hover:bg-bunker-700">
- <td className="w-10 h-10 px-4 flex items-center justify-center border-none"><div className='text-center w-10 text-xs text-bunker-400'>{index + 1}</div></td>
- <td className="flex flex-row justify-between items-center h-full min-w-[200px] lg:min-w-[220px] xl:min-w-[250px]">
- <div className="flex truncate flex-row items-center h-8 cursor-default">{secrets![0].key || ''}</div>
- <button type="button" className='mr-1 ml-2 text-bunker-400 hover:text-bunker-300 invisible group-hover:visible' onClick={() => setAreValuesHiddenThisRow(!areValuesHiddenThisRow)}>
+ <tr className="group flex min-w-full flex-row items-center hover:bg-bunker-700">
+ <td className="flex h-10 w-10 items-center justify-center border-none px-4">
+ <div className="w-10 text-center text-xs text-bunker-400">{index + 1}</div>
+ </td>
+ <td className="flex h-full min-w-[200px] flex-row items-center justify-between lg:min-w-[220px] xl:min-w-[250px]">
+ <div className="flex h-8 cursor-default flex-row items-center truncate">
+ {secrets![0].key || ''}
+ </div>
+ <button
+ type="button"
+ className="invisible mr-1 ml-2 text-bunker-400 hover:text-bunker-300 group-hover:visible"
+ onClick={() => setAreValuesHiddenThisRow(!areValuesHiddenThisRow)}
+ >
<FontAwesomeIcon icon={areValuesHiddenThisRow ? faEye : faEyeSlash} />
</button>
</td>
- {userAvailableEnvs?.map(env => {
- return <DashboardInput key={`row-${secret?.key || ''}-${env.slug}`} isOverridden={false} isSecretValueHidden={areValuesHiddenThisRow && isSecretValueHidden} isReadOnly={isReadOnly} secret={secrets?.filter(sec => sec.env === env.slug)[0]} index={index} />
- })}
+ {userAvailableEnvs?.map(({ slug }) => (
+ <DashboardInput
+ isReadOnly={isReadOnly}
+ key={`row-${secrets![0].key || ''}-${slug}`}
+ isOverridden={false}
+ secret={getSecretByEnv(slug, secrets)}
+ isSecretValueHidden={areValuesHiddenThisRow && isSecretValueHidden}
+ />
+ ))}
</tr>
);
};
diff --git a/frontend/src/views/DashboardPage/components/SecretDetailDrawer/SecretDetailDrawer.tsx b/frontend/src/views/DashboardPage/components/SecretDetailDrawer/SecretDetailDrawer.tsx
index f0d64819f0..c2c98f0015 100644
--- a/frontend/src/views/DashboardPage/components/SecretDetailDrawer/SecretDetailDrawer.tsx
+++ b/frontend/src/views/DashboardPage/components/SecretDetailDrawer/SecretDetailDrawer.tsx
@@ -1,4 +1,4 @@
-import { useFormContext } from 'react-hook-form';
+import { useFormContext, useWatch } from 'react-hook-form';
import { faCircle, faCircleDot, faShuffle } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
@@ -44,14 +44,14 @@ export const SecretDetailDrawer = ({
const [canRevealSecVal, setCanRevealSecVal] = useToggle();
const [canRevealSecOverride, setCanRevealSecOverride] = useToggle();
- const { register, setValue, watch } = useFormContext<FormData>();
- const secret = watch(`secrets.${index}`);
+ const { register, setValue, control, getValues } = useFormContext<FormData>();
+ const overrideAction = useWatch({ control, name: `secrets.${index}.overrideAction` });
const isOverridden =
- secret?.overrideAction === SecretActionType.Created ||
- secret?.overrideAction === SecretActionType.Modified;
+ overrideAction === SecretActionType.Created || overrideAction === SecretActionType.Modified;
const onSecretOverride = () => {
+ const secret = getValues(`secrets.${index}`);
if (isOverridden) {
// when user created a new override but then removes
if (SecretActionType.Created) {
@@ -67,21 +67,17 @@ export const SecretDetailDrawer = ({
}
};
- if (!secret) {
- return <div />;
- }
-
return (
<Drawer onOpenChange={onOpenChange} isOpen={isDrawerOpen}>
<DrawerContent
- className="border-l border-mineshaft-500 bg-bunker dark"
+ className="dark border-l border-mineshaft-500 bg-bunker"
title="Secret"
footerContent={
<div className="flex flex-col space-y-2 pt-4 shadow-md">
<div>
<Button
variant="star"
- onClick={() => onEnvCompare(secret?.key)}
+ onClick={() => onEnvCompare(getValues(`secrets.${index}.key`))}
isFullWidth
isDisabled={isReadOnly}
>
@@ -95,7 +91,10 @@ export const SecretDetailDrawer = ({
<Button
colorSchema="danger"
isDisabled={isReadOnly}
- onClick={() => onSecretDelete(index, secret._id, secret.idOverride)}
+ onClick={() => {
+ const secret = getValues(`secrets.${index}`);
+ onSecretDelete(index, secret._id, secret.idOverride);
+ }}
>
Delete
</Button>
@@ -173,9 +172,9 @@ export const SecretDetailDrawer = ({
</PopoverContent>
</Popover>
</FormControl>
- <div className="mb-4 text-sm text-bunker-300 dark">
+ <div className="dark mb-4 text-sm text-bunker-300">
<div className="mb-2">Version History</div>
- <div className="flex h-48 flex-col space-y-2 border border-mineshaft-600 overflow-y-auto overflow-x-hidden rounded-md bg-bunker-800 p-2 dark:[color-scheme:dark]">
+ <div className="flex h-48 flex-col space-y-2 overflow-y-auto overflow-x-hidden rounded-md border border-mineshaft-600 bg-bunker-800 p-2 dark:[color-scheme:dark]">
{secretVersion?.map(({ createdAt, value, id }, i) => (
<div key={id} className="flex flex-col space-y-1">
<div className="flex items-center space-x-2">
@@ -202,7 +201,12 @@ export const SecretDetailDrawer = ({
</div>
</div>
<FormControl label="Comments & Notes">
- <TextArea className="border border-mineshaft-600 text-sm" isDisabled={isReadOnly} {...register(`secrets.${index}.comment`)} rows={5} />
+ <TextArea
+ className="border border-mineshaft-600 text-sm"
+ isDisabled={isReadOnly}
+ {...register(`secrets.${index}.comment`)}
+ rows={5}
+ />
</FormControl>
</div>
</DrawerContent>
diff --git a/frontend/src/views/DashboardPage/components/SecretInputRow/MaskedInput.tsx b/frontend/src/views/DashboardPage/components/SecretInputRow/MaskedInput.tsx
new file mode 100644
index 0000000000..21ae0264de
--- /dev/null
+++ b/frontend/src/views/DashboardPage/components/SecretInputRow/MaskedInput.tsx
@@ -0,0 +1,107 @@
+import { useCallback } from 'react';
+import { useFormContext, useWatch } from 'react-hook-form';
+import { faCircle } from '@fortawesome/free-solid-svg-icons';
+import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
+import { twMerge } from 'tailwind-merge';
+
+import { FormData } from '../../DashboardPage.utils';
+
+type Props = {
+ isReadOnly?: boolean;
+ isSecretValueHidden?: boolean;
+ isOverridden?: boolean;
+ index: number;
+};
+
+const REGEX = /([$]{.*?})/g;
+
+export const MaskedInput = ({ isReadOnly, isSecretValueHidden, index, isOverridden }: Props) => {
+ const { register, control } = useFormContext<FormData>();
+
+ const secretValue = useWatch({ control, name: `secrets.${index}.value` });
+ const secretValueOverride = useWatch({ control, name: `secrets.${index}.valueOverride` });
+ const value = isOverridden ? secretValueOverride : secretValue;
+
+ const syntaxHighlight = useCallback((val: string) => {
+ if (val?.length === 0) return <span className="font-sans text-bunker-400/80">EMPTY</span>;
+ return val?.split(REGEX).map((word) =>
+ word.match(REGEX) !== null ? (
+ <span className="ph-no-capture text-yellow" key={`${val}-${index + 1}`}>
+ {word.slice(0, 2)}
+ <span className="ph-no-capture text-yellow-200/80">{word.slice(2, word.length - 1)}</span>
+ {word.slice(word.length - 1, word.length) === '}' ? (
+ <span className="ph-no-capture text-yellow">
+ {word.slice(word.length - 1, word.length)}
+ </span>
+ ) : (
+ <span className="ph-no-capture text-yellow-400">
+ {word.slice(word.length - 1, word.length)}
+ </span>
+ )}
+ </span>
+ ) : (
+ <span key={`${word}_${index + 1}`} className="ph-no-capture">
+ {word}
+ </span>
+ )
+ );
+ }, []);
+
+ return (
+ <div className="group relative flex w-full flex-col justify-center whitespace-pre px-1.5">
+ {isOverridden ? (
+ <input
+ {...register(`secrets.${index}.valueOverride`)}
+ readOnly={isReadOnly}
+ className={twMerge(
+ 'ph-no-capture min-w-16 no-scrollbar::-webkit-scrollbar duration-50 peer z-10 w-full bg-transparent px-2 py-2 font-mono text-sm text-transparent caret-white outline-none no-scrollbar',
+ !isSecretValueHidden &&
+ 'text-transparent focus:text-transparent active:text-transparent'
+ )}
+ spellCheck="false"
+ />
+ ) : (
+ <input
+ {...register(`secrets.${index}.value`)}
+ readOnly={isReadOnly}
+ className={twMerge(
+ 'ph-no-capture min-w-16 no-scrollbar::-webkit-scrollbar duration-50 peer z-10 w-full bg-transparent px-2 py-2 font-mono text-sm text-transparent caret-white outline-none no-scrollbar',
+ !isSecretValueHidden &&
+ 'text-transparent focus:text-transparent active:text-transparent'
+ )}
+ spellCheck="false"
+ />
+ )}
+ <div
+ className={twMerge(
+ 'ph-no-capture min-w-16 no-scrollbar::-webkit-scrollbar duration-50 absolute z-0 mt-0.5 flex h-10 w-full flex-row overflow-x-scroll whitespace-pre bg-transparent px-2 py-2 font-mono text-sm outline-none no-scrollbar peer-focus:visible',
+ isSecretValueHidden ? 'invisible' : 'visible',
+ isOverridden
+ ? 'text-primary-300'
+ : 'duration-50 text-gray-400 group-hover:text-gray-400 peer-focus:text-gray-100 peer-active:text-gray-400'
+ )}
+ >
+ {syntaxHighlight(value || '')}
+ </div>
+ <div
+ className={twMerge(
+ 'duration-50 peer absolute z-0 flex h-10 w-full flex-row items-center justify-between text-clip pr-2 text-bunker-400 group-hover:bg-white/[0.00] peer-focus:hidden peer-active:hidden',
+ !isSecretValueHidden ? 'invisible' : 'visible'
+ )}
+ >
+ <div className="no-scrollbar::-webkit-scrollbar flex flex-row items-center overflow-x-scroll px-2 no-scrollbar">
+ {value?.split('').map((val, i) => (
+ <FontAwesomeIcon
+ key={`${value}_${val}_${i + 1}`}
+ className="mr-0.5 text-xxs"
+ icon={faCircle}
+ />
+ ))}
+ {value?.split('').length === 0 && (
+ <span className="text-sm text-bunker-400/80">EMPTY</span>
+ )}
+ </div>
+ </div>
+ </div>
+ );
+};
diff --git a/frontend/src/views/DashboardPage/components/SecretInputRow/SecretInputRow.tsx b/frontend/src/views/DashboardPage/components/SecretInputRow/SecretInputRow.tsx
index f0b2cd092c..64818ff36a 100644
--- a/frontend/src/views/DashboardPage/components/SecretInputRow/SecretInputRow.tsx
+++ b/frontend/src/views/DashboardPage/components/SecretInputRow/SecretInputRow.tsx
@@ -1,8 +1,7 @@
/* eslint-disable react/jsx-no-useless-fragment */
-import { SyntheticEvent, useRef } from 'react';
+import { memo, useRef } from 'react';
import { Controller, useFieldArray, useFormContext, useWatch } from 'react-hook-form';
import {
- faCircle,
faCodeBranch,
faComment,
faEllipsis,
@@ -15,7 +14,6 @@ import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { cx } from 'cva';
import { twMerge } from 'tailwind-merge';
-import guidGenerator from '@app/components/utilities/randomId';
import {
Button,
Checkbox,
@@ -32,10 +30,10 @@ import {
TextArea,
Tooltip
} from '@app/components/v2';
-import { useToggle } from '@app/hooks';
import { WsTag } from '@app/hooks/api/types';
import { FormData, SecretActionType } from '../../DashboardPage.utils';
+import { MaskedInput } from './MaskedInput';
type Props = {
index: number;
@@ -64,361 +62,327 @@ const tagColors = [
{ bg: 'bg-[#C40B13]/40', text: 'text-[#FFDEDE]/70' },
{ bg: 'bg-[#332FD0]/40', text: 'text-[#DFF6FF]/70' }
];
-const REGEX = /([$]{.*?})/g;
-export const SecretInputRow = ({
- index,
- isSecretValueHidden,
- onRowExpand,
- isReadOnly,
- isRollbackMode,
- isAddOnly,
- wsTags,
- onCreateTagOpen,
- onSecretDelete,
- searchTerm
-}: Props): JSX.Element => {
- const ref = useRef<HTMLDivElement | null>(null);
- const syncScroll = (e: SyntheticEvent<HTMLDivElement>) => {
- if (ref.current === null) return;
+export const SecretInputRow = memo(
+ ({
+ index,
+ isSecretValueHidden,
+ onRowExpand,
+ isReadOnly,
+ isRollbackMode,
+ isAddOnly,
+ wsTags,
+ onCreateTagOpen,
+ onSecretDelete,
+ searchTerm
+ }: Props): JSX.Element => {
+ const isKeySubDisabled = useRef<boolean>(false);
+ const { register, setValue, control } = useFormContext<FormData>();
+ // comment management in a row
+ const {
+ fields: secretTags,
+ remove,
+ append
+ } = useFieldArray({ control, name: `secrets.${index}.tags` });
- ref.current.scrollTop = e.currentTarget.scrollTop;
- ref.current.scrollLeft = e.currentTarget.scrollLeft;
- };
- const { register, setValue, control } = useFormContext<FormData>();
- const [canRevealSecret] = useToggle();
- // comment management in a row
- const {
- fields: secretTags,
- remove,
- append
- } = useFieldArray({ control, name: `secrets.${index}.tags` });
+ // to get details on a secret
+ const overrideAction = useWatch({ control, name: `secrets.${index}.overrideAction` });
+ const idOverride = useWatch({ control, name: `secrets.${index}.idOverride` });
+ const secComment = useWatch({ control, name: `secrets.${index}.comment` });
+ const hasComment = Boolean(secComment);
+ const secKey = useWatch({
+ control,
+ name: `secrets.${index}.key`,
+ disabled: isKeySubDisabled.current
+ });
+ const secId = useWatch({ control, name: `secrets.${index}._id` });
- // to get details on a secret
- const secret = useWatch({ name: `secrets.${index}`, control });
- const hasComment = Boolean(secret.comment);
- const tags = secret.tags || [];
- const selectedTagIds = tags.reduce<Record<string, boolean>>(
- (prev, curr) => ({ ...prev, [curr.slug]: true }),
- {}
- );
+ const tags = useWatch({ control, name: `secrets.${index}.tags`, defaultValue: [] }) || [];
+ const selectedTagIds = tags.reduce<Record<string, boolean>>(
+ (prev, curr) => ({ ...prev, [curr.slug]: true }),
+ {}
+ );
- // when secret is override by personal values
- const isOverridden =
- secret.overrideAction === SecretActionType.Created ||
- secret.overrideAction === SecretActionType.Modified;
+ // when secret is override by personal values
+ const isOverridden =
+ overrideAction === SecretActionType.Created || overrideAction === SecretActionType.Modified;
- const onSecretOverride = () => {
- if (isOverridden) {
- // when user created a new override but then removes
- if (secret?.overrideAction === SecretActionType.Created)
+ const onSecretOverride = () => {
+ if (isOverridden) {
+ // when user created a new override but then removes
+ if (overrideAction === SecretActionType.Created)
+ setValue(`secrets.${index}.valueOverride`, '');
+ setValue(`secrets.${index}.overrideAction`, SecretActionType.Deleted, {
+ shouldDirty: true
+ });
+ } else {
setValue(`secrets.${index}.valueOverride`, '');
- setValue(`secrets.${index}.overrideAction`, SecretActionType.Deleted, { shouldDirty: true });
- } else {
- setValue(`secrets.${index}.valueOverride`, '');
- setValue(
- `secrets.${index}.overrideAction`,
- secret?.idOverride ? SecretActionType.Modified : SecretActionType.Created,
- { shouldDirty: true }
- );
- }
- };
+ setValue(
+ `secrets.${index}.overrideAction`,
+ idOverride ? SecretActionType.Modified : SecretActionType.Created,
+ { shouldDirty: true }
+ );
+ }
+ };
- const onSelectTag = (selectedTag: WsTag) => {
- const shouldAppend = !selectedTagIds[selectedTag.slug];
- if (shouldAppend) {
- append(selectedTag);
- } else {
- const pos = tags.findIndex(({ slug }) => selectedTag.slug === slug);
- remove(pos);
- }
- };
+ const onSelectTag = (selectedTag: WsTag) => {
+ const shouldAppend = !selectedTagIds[selectedTag.slug];
+ if (shouldAppend) {
+ append(selectedTag);
+ } else {
+ const pos = tags.findIndex(({ slug }) => selectedTag.slug === slug);
+ remove(pos);
+ }
+ };
- const isCreatedSecret = !secret?._id;
- const shouldBeBlockedInAddOnly = !isCreatedSecret && isAddOnly;
+ const isCreatedSecret = !secId;
+ const shouldBeBlockedInAddOnly = !isCreatedSecret && isAddOnly;
- // Why this instead of filter in parent
- // Because rhf field.map has default values so basically
- // keys are not updated there and index needs to kept so that we can monitor
- // values individually here
- if (
- !(
- secret.key?.toUpperCase().includes(searchTerm?.toUpperCase()) ||
- tags
- ?.map((tag) => tag.name)
- .join(' ')
- ?.toUpperCase()
- .includes(searchTerm?.toUpperCase()) ||
- secret.comment?.toUpperCase().includes(searchTerm?.toUpperCase())
- )
- ) {
- return <></>;
- }
+ // Why this instead of filter in parent
+ // Because rhf field.map has default values so basically
+ // keys are not updated there and index needs to kept so that we can monitor
+ // values individually here
+ if (
+ !(
+ secKey?.toUpperCase().includes(searchTerm?.toUpperCase()) ||
+ tags
+ ?.map((tag) => tag.name)
+ .join(' ')
+ ?.toUpperCase()
+ .includes(searchTerm?.toUpperCase()) ||
+ secComment?.toUpperCase().includes(searchTerm?.toUpperCase())
+ )
+ ) {
+ return <></>;
+ }
- return (
- <tr className="group min-w-full flex flex-row items-center" key={index}>
- <td className="w-10 h-10 px-4 flex items-center justify-center"><div className='text-center w-10 text-xs text-bunker-400'>{index + 1}</div></td>
- <Controller
- control={control}
- defaultValue=""
- name={`secrets.${index}.key`}
- render={({ fieldState: { error }, field }) => (
- <HoverCard openDelay={0} open={error?.message ? undefined : false}>
- <HoverCardTrigger asChild>
- <td className={cx(error?.message ? 'rounded ring ring-red/50' : null)}>
- <div className="min-w-[220px] lg:min-w-[240px] xl:min-w-[280px] relative flex items-center justify-end w-full">
- <Input
- autoComplete="off"
- variant="plain"
- isDisabled={isReadOnly || shouldBeBlockedInAddOnly || isRollbackMode}
- className="w-full focus:text-bunker-100 focus:ring-transparent"
- {...field}
- />
- <div className="w-max flex flex-row items-center justify-end">
- <Tooltip content="Comment">
- <div className={`${hasComment ? "w-5" : "w-0"} overflow-hidden group-hover:w-5 mt-0.5`}>
- <Popover>
- <PopoverTrigger asChild>
- <IconButton
+ return (
+ <tr className="group flex flex-row items-center" key={index}>
+ <td className="flex h-10 w-10 items-center justify-center px-4">
+ <div className="w-10 text-center text-xs text-bunker-400">{index + 1}</div>
+ </td>
+ <Controller
+ control={control}
+ defaultValue=""
+ name={`secrets.${index}.key`}
+ render={({ fieldState: { error }, field }) => (
+ <HoverCard openDelay={0} open={error?.message ? undefined : false}>
+ <HoverCardTrigger asChild>
+ <td className={cx(error?.message ? 'rounded ring ring-red/50' : null)}>
+ <div className="relative flex w-full min-w-[220px] items-center justify-end lg:min-w-[240px] xl:min-w-[280px]">
+ <Input
+ autoComplete="off"
+ onFocus={() => {
+ isKeySubDisabled.current = true;
+ }}
+ variant="plain"
+ isDisabled={isReadOnly || shouldBeBlockedInAddOnly || isRollbackMode}
+ className="w-full focus:text-bunker-100 focus:ring-transparent"
+ {...field}
+ onBlur={() => {
+ isKeySubDisabled.current = false;
+ field.onBlur();
+ }}
+ />
+ <div className="flex w-max flex-row items-center justify-end">
+ <Tooltip content="Comment">
+ <div
+ className={`${
+ hasComment ? 'w-5' : 'w-0'
+ } mt-0.5 overflow-hidden group-hover:w-5`}
+ >
+ <Popover>
+ <PopoverTrigger asChild>
+ <IconButton
+ className={twMerge(
+ 'w-0 overflow-hidden p-0 group-hover:w-5',
+ hasComment && 'w-5 text-primary'
+ )}
+ variant="plain"
+ size="md"
+ ariaLabel="add-tag"
+ >
+ <FontAwesomeIcon icon={faComment} />
+ </IconButton>
+ </PopoverTrigger>
+ <PopoverContent className="w-auto border border-mineshaft-600 bg-mineshaft-800 p-2 drop-shadow-2xl">
+ <FormControl label="Comment" className="mb-0">
+ <TextArea
+ isDisabled={
+ isReadOnly || isRollbackMode || shouldBeBlockedInAddOnly
+ }
+ className="border border-mineshaft-600 text-sm"
+ {...register(`secrets.${index}.comment`)}
+ rows={8}
+ cols={30}
+ />
+ </FormControl>
+ </PopoverContent>
+ </Popover>
+ </div>
+ </Tooltip>
+ {!isAddOnly && (
+ <div>
+ <Tooltip content="Override with a personal value">
+ <IconButton
+ variant="plain"
className={twMerge(
- 'w-0 overflow-hidden p-0 group-hover:w-5',
- hasComment && 'w-5 text-primary'
+ 'mt-0.5 w-0 overflow-hidden p-0 group-hover:ml-1 group-hover:w-6',
+ isOverridden && 'ml-1 w-6 text-primary'
)}
- variant="plain"
- size="md"
- ariaLabel="add-tag"
+ onClick={onSecretOverride}
+ size="md"
+ isDisabled={isRollbackMode || isReadOnly}
+ ariaLabel="info"
>
- <FontAwesomeIcon icon={faComment} />
+ <div className="flex items-center space-x-1">
+ <FontAwesomeIcon icon={faCodeBranch} className="text-base" />
+ </div>
</IconButton>
- </PopoverTrigger>
- <PopoverContent className="w-auto bg-mineshaft-800 border border-mineshaft-600 drop-shadow-2xl p-2">
- <FormControl label="Comment" className="mb-0">
- <TextArea
- isDisabled={isReadOnly || isRollbackMode || shouldBeBlockedInAddOnly}
- className="border border-mineshaft-600 text-sm"
- {...register(`secrets.${index}.comment`)}
- rows={8}
- cols={30}
- />
- </FormControl>
- </PopoverContent>
- </Popover>
- </div>
- </Tooltip>
- {!isAddOnly && (
- <div>
- <Tooltip content="Override with a personal value">
- <IconButton
- variant="plain"
- className={twMerge(
- 'w-0 overflow-hidden p-0 group-hover:w-6 group-hover:ml-1 mt-0.5',
- isOverridden && 'w-6 text-primary ml-1'
- )}
- onClick={onSecretOverride}
- size="md"
- isDisabled={isRollbackMode || isReadOnly}
- ariaLabel="info"
- >
- <div className="flex items-center space-x-1">
- <FontAwesomeIcon icon={faCodeBranch} className="text-base" />
- </div>
- </IconButton>
- </Tooltip>
- </div>
- )}
+ </Tooltip>
+ </div>
+ )}
+ </div>
</div>
- </div>
- </td>
- </HoverCardTrigger>
- <HoverCardContent className="w-auto py-2 pt-2">
- <div className="flex items-center space-x-2">
- <div>
- <FontAwesomeIcon icon={faInfoCircle} className="text-red" />
- </div>
- <div className="text-sm">{error?.message}</div>
- </div>
- </HoverCardContent>
- </HoverCard>
- )}
- />
- <td className="flex flex-row w-full justify-center h-8 items-center">
- <div className="group relative whitespace-pre flex flex-col justify-center w-full px-1.5">
- {isOverridden
- ? <input
- {...register(`secrets.${index}.valueOverride`)}
- onScroll={syncScroll}
- readOnly={isReadOnly || isRollbackMode || (isOverridden ? isAddOnly : shouldBeBlockedInAddOnly)}
- className={`${
- (!canRevealSecret && isSecretValueHidden)
- ? 'text-transparent focus:text-transparent active:text-transparent'
- : ''
- } z-10 peer font-mono ph-no-capture bg-transparent caret-white text-transparent text-sm px-2 py-2 w-full min-w-16 outline-none duration-200 no-scrollbar no-scrollbar::-webkit-scrollbar`}
- spellCheck="false"
- />
- : <input
- {...register(`secrets.${index}.value`)}
- onScroll={syncScroll}
- readOnly={isReadOnly || isRollbackMode || (isOverridden ? isAddOnly : shouldBeBlockedInAddOnly)}
- className={`${
- (!canRevealSecret && isSecretValueHidden)
- ? 'text-transparent focus:text-transparent active:text-transparent'
- : ''
- } z-10 peer font-mono ph-no-capture bg-transparent caret-white text-transparent text-sm px-2 py-2 w-full min-w-16 outline-none duration-200 no-scrollbar no-scrollbar::-webkit-scrollbar`}
- spellCheck="false"
- />}
- <div
- ref={ref}
- className={`${
- (!canRevealSecret && isSecretValueHidden) && !isOverridden
- ? 'text-bunker-800 group-hover:text-gray-400 peer-focus:text-gray-100 peer-active:text-gray-400 duration-200'
- : ''
- } ${isOverridden ? 'text-primary-300' : 'text-gray-400'}
- absolute flex flex-row whitespace-pre font-mono z-0 ${(!canRevealSecret && isSecretValueHidden) ? 'invisible' : 'visible'} peer-focus:visible mt-0.5 ph-no-capture overflow-x-scroll bg-transparent h-10 text-sm px-2 py-2 w-full min-w-16 outline-none duration-100 no-scrollbar no-scrollbar::-webkit-scrollbar`}
- >
- {(isOverridden ? secret.valueOverride : secret.value)?.split('').length === 0 && <span className='text-bunker-400/80 font-sans'>EMPTY</span>}
- {(isOverridden ? secret.valueOverride : secret.value)?.split(REGEX).map((word) => {
- if (word.match(REGEX) !== null) {
- return (
- <span className="ph-no-capture text-yellow" key={guidGenerator()}>
- {word.slice(0, 2)}
- <span className="ph-no-capture text-yellow-200/80">
- {word.slice(2, word.length - 1)}
- </span>
- {word.slice(word.length - 1, word.length) === '}' ? (
- <span className="ph-no-capture text-yellow">
- {word.slice(word.length - 1, word.length)}
- </span>
- ) : (
- <span className="ph-no-capture text-yellow-400">
- {word.slice(word.length - 1, word.length)}
- </span>
- )}
- </span>
- );
- }
- return (
- <span key={`${word}_${index + 1}`} className="ph-no-capture">
- {word}
- </span>
- );
- })}
- </div>
- {(!canRevealSecret && isSecretValueHidden) && (
- <div className='absolute flex flex-row justify-between items-center z-0 peer pr-2 peer-active:hidden peer-focus:hidden group-hover:bg-white/[0.00] duration-100 h-10 w-full text-bunker-400 text-clip'>
- <div className="px-2 flex flex-row items-center overflow-x-scroll no-scrollbar no-scrollbar::-webkit-scrollbar">
- {(isOverridden ? secret.valueOverride : secret.value)?.split('').map(() => (
- <FontAwesomeIcon
- key={guidGenerator()}
- className="text-xxs mr-0.5"
- icon={faCircle}
- />
- ))}
- {(isOverridden ? secret.valueOverride : secret.value)?.split('').length === 0 && <span className='text-bunker-400/80 text-sm'>EMPTY</span>}
- </div>
- </div>
- )}
- </div>
- </td>
- <td className="flex items-center min-w-sm h-10">
- <div className="flex items-center pl-2">
- {secretTags.map(({ id, slug }, i) => (
- <Tag
- className={cx(
- tagColors[i % tagColors.length].bg,
- tagColors[i % tagColors.length].text
- )}
- isDisabled={isReadOnly || isAddOnly || isRollbackMode}
- onClose={() => remove(i)}
- key={id}
- >
- {slug}
- </Tag>
- ))}
- {!(isReadOnly || isAddOnly || isRollbackMode) && (
- <div className="w-0 overflow-hidden group-hover:w-8">
- <Popover>
- <PopoverTrigger asChild>
+ </td>
+ </HoverCardTrigger>
+ <HoverCardContent className="w-auto py-2 pt-2">
+ <div className="flex items-center space-x-2">
<div>
- <Tooltip content="Add tags">
- <IconButton variant="star" size="xs" ariaLabel="add-tag" className="py-[0.42rem]">
- <FontAwesomeIcon icon={faTags} />
- </IconButton>
- </Tooltip>
+ <FontAwesomeIcon icon={faInfoCircle} className="text-red" />
</div>
- </PopoverTrigger>
- <PopoverContent
- side="left"
- className="max-h-96 w-auto min-w-[200px] overflow-y-auto overflow-x-hidden p-2 text-bunker-200 bg-mineshaft-800 border border-mineshaft-600"
- hideCloseBtn
- >
- <div className="mb-2 text-sm font-medium text-center text-bunker-200 px-2">Add tags to {secret.key || "this secret"}</div>
- <div className="flex flex-col space-y-1">
- {wsTags?.map((wsTag) => (
+ <div className="text-sm">{error?.message}</div>
+ </div>
+ </HoverCardContent>
+ </HoverCard>
+ )}
+ />
+ <td className="flex h-8 w-full flex-grow flex-row items-center justify-center">
+ <MaskedInput
+ isReadOnly={
+ isReadOnly || isRollbackMode || (isOverridden ? isAddOnly : shouldBeBlockedInAddOnly)
+ }
+ isOverridden={isOverridden}
+ isSecretValueHidden={isSecretValueHidden}
+ index={index}
+ />
+ </td>
+ <td className="min-w-sm flex h-10 items-center">
+ <div className="flex items-center pl-2">
+ {secretTags.map(({ id, slug }, i) => (
+ <Tag
+ className={cx(
+ tagColors[i % tagColors.length].bg,
+ tagColors[i % tagColors.length].text
+ )}
+ isDisabled={isReadOnly || isAddOnly || isRollbackMode}
+ onClose={() => remove(i)}
+ key={id}
+ >
+ {slug}
+ </Tag>
+ ))}
+ {!(isReadOnly || isAddOnly || isRollbackMode) && (
+ <div className="w-0 overflow-hidden group-hover:w-8">
+ <Popover>
+ <PopoverTrigger asChild>
+ <div>
+ <Tooltip content="Add tags">
+ <IconButton
+ variant="star"
+ size="xs"
+ ariaLabel="add-tag"
+ className="py-[0.42rem]"
+ >
+ <FontAwesomeIcon icon={faTags} />
+ </IconButton>
+ </Tooltip>
+ </div>
+ </PopoverTrigger>
+ <PopoverContent
+ side="left"
+ className="max-h-96 w-auto min-w-[200px] overflow-y-auto overflow-x-hidden border border-mineshaft-600 bg-mineshaft-800 p-2 text-bunker-200"
+ hideCloseBtn
+ >
+ <div className="mb-2 px-2 text-center text-sm font-medium text-bunker-200">
+ Add tags to {secKey || 'this secret'}
+ </div>
+ <div className="flex flex-col space-y-1">
+ {wsTags?.map((wsTag) => (
+ <Button
+ variant="plain"
+ size="sm"
+ className={twMerge(
+ 'justify-start bg-mineshaft-600 text-bunker-100 hover:bg-mineshaft-500',
+ selectedTagIds?.[wsTag.slug] && 'text-primary'
+ )}
+ onClick={() => onSelectTag(wsTag)}
+ leftIcon={
+ <Checkbox
+ className="mr-0 data-[state=checked]:bg-primary"
+ id="autoCapitalization"
+ isChecked={selectedTagIds?.[wsTag.slug]}
+ onCheckedChange={() => {}}
+ >
+ {}
+ </Checkbox>
+ }
+ key={wsTag._id}
+ >
+ {wsTag.slug}
+ </Button>
+ ))}
<Button
- variant="plain"
+ variant="star"
+ color="primary"
size="sm"
- className={twMerge(
- 'justify-start bg-mineshaft-600 text-bunker-100 hover:bg-mineshaft-500',
- selectedTagIds?.[wsTag.slug] && 'text-primary'
- )}
- onClick={() => onSelectTag(wsTag)}
- leftIcon={
- <Checkbox
- className="data-[state=checked]:bg-primary mr-0"
- id="autoCapitalization"
- isChecked={selectedTagIds?.[wsTag.slug]}
- onCheckedChange={() => {}}
- >
- {}
- </Checkbox>
- }
- key={wsTag._id}
+ className="mt-4 h-7 justify-start bg-mineshaft-600 px-1"
+ onClick={onCreateTagOpen}
+ leftIcon={<FontAwesomeIcon icon={faPlus} />}
>
- {wsTag.slug}
+ Add new tag
</Button>
- ))}
- <Button
- variant="star"
- color="primary"
- size="sm"
- className="mt-4 justify-start bg-mineshaft-600 h-7 px-1"
- onClick={onCreateTagOpen}
- leftIcon={<FontAwesomeIcon icon={faPlus} />}
- >
- Add new tag
- </Button>
- </div>
- </PopoverContent>
- </Popover>
- </div>
- )}
- </div>
- <div className="flex w-0 group-hover:w-14 invisible group-hover:visible duration-0 items-center justify-end space-x-2 overflow-hidden transition-all">
- {!isAddOnly && (
+ </div>
+ </PopoverContent>
+ </Popover>
+ </div>
+ )}
+ </div>
+ <div className="duration-0 invisible flex w-0 items-center justify-end space-x-2 overflow-hidden transition-all group-hover:visible group-hover:w-14">
+ {!isAddOnly && (
+ <div>
+ <Tooltip content="Settings">
+ <IconButton
+ size="lg"
+ colorSchema="primary"
+ variant="plain"
+ onClick={onRowExpand}
+ ariaLabel="expand"
+ >
+ <FontAwesomeIcon icon={faEllipsis} />
+ </IconButton>
+ </Tooltip>
+ </div>
+ )}
<div>
- <Tooltip content="Settings">
- <IconButton size="lg" colorSchema="primary" variant="plain" onClick={onRowExpand} ariaLabel="expand">
- <FontAwesomeIcon icon={faEllipsis} />
+ <Tooltip content="Delete">
+ <IconButton
+ size="md"
+ variant="plain"
+ colorSchema="danger"
+ ariaLabel="delete"
+ isDisabled={isReadOnly || isRollbackMode}
+ onClick={() => onSecretDelete(index, secId, idOverride)}
+ >
+ <FontAwesomeIcon icon={faXmark} />
</IconButton>
</Tooltip>
</div>
- )}
- <div>
- <Tooltip content="Delete">
- <IconButton
- size="md"
- variant="plain"
- colorSchema="danger"
- ariaLabel="delete"
- isDisabled={isReadOnly || isRollbackMode}
- onClick={() => onSecretDelete(index, secret._id, secret?.idOverride)}
- >
- <FontAwesomeIcon icon={faXmark} />
- </IconButton>
- </Tooltip>
</div>
- </div>
- </td>
- </tr>
- );
-};
+ </td>
+ </tr>
+ );
+ }
+);
+
+SecretInputRow.displayName = 'SecretInputRow';
diff --git a/frontend/src/views/DashboardPage/components/SecretTableHeader/SecretTableHeader.tsx b/frontend/src/views/DashboardPage/components/SecretTableHeader/SecretTableHeader.tsx
index 2c76312980..e92d578765 100644
--- a/frontend/src/views/DashboardPage/components/SecretTableHeader/SecretTableHeader.tsx
+++ b/frontend/src/views/DashboardPage/components/SecretTableHeader/SecretTableHeader.tsx
@@ -1,4 +1,3 @@
-import { Controller } from 'react-hook-form';
import { faArrowDown, faArrowUp } from '@fortawesome/free-solid-svg-icons';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
@@ -9,36 +8,29 @@ type Props = {
onSort: () => void;
};
-export const SecretTableHeader = ({
- sortDir,
- onSort
-}: Props): JSX.Element => (
+export const SecretTableHeader = ({ sortDir, onSort }: Props): JSX.Element => (
<thead>
- <tr className="absolute flex flex-row sticky top-0">
- <td className="w-10 px-4 flex items-center justify-center">
- <div className='text-center w-10 text-xs text-transparent'>{0}</div>
+ <tr className="sticky top-0 flex flex-row">
+ <td className="flex w-10 items-center justify-center px-4">
+ <div className="w-10 text-center text-xs text-transparent">{0}</div>
</td>
- <Controller
- defaultValue=""
- name="na"
- render={() => (
- <td className='flex items-center'>
- <div className="min-w-[220px] lg:min-w-[240px] xl:min-w-[280px] relative flex items-center justify-start pl-2.5 w-full">
- <div className="inline-flex items-end text-md font-medium">
- Key
- <IconButton variant="plain" className="ml-2" ariaLabel="sort" onClick={onSort}>
- <FontAwesomeIcon icon={sortDir === 'asc' ? faArrowDown : faArrowUp} />
- </IconButton>
- </div>
- <div className="w-max flex flex-row items-center justify-end">
- <div className="w-5 overflow-hidden group-hover:w-5 mt-1"/>
- </div>
- </div>
- </td>
- )}
- />
- <th className="flex flex-row w-full"><div className="text-sm font-medium">Value</div></th>
+ <td className="flex items-center">
+ <div className="relative flex w-full min-w-[220px] items-center justify-start pl-2.5 lg:min-w-[240px] xl:min-w-[280px]">
+ <div className="text-md inline-flex items-end font-medium">
+ Key
+ <IconButton variant="plain" className="ml-2" ariaLabel="sort" onClick={onSort}>
+ <FontAwesomeIcon icon={sortDir === 'asc' ? faArrowDown : faArrowUp} />
+ </IconButton>
+ </div>
+ <div className="flex w-max flex-row items-center justify-end">
+ <div className="mt-1 w-5 overflow-hidden group-hover:w-5" />
+ </div>
+ </div>
+ </td>
+ <th className="flex w-full flex-row">
+ <div className="text-sm font-medium">Value</div>
+ </th>
</tr>
- <tr className='h-0 w-full border border-mineshaft-600'/>
+ <tr className="h-0 w-full border border-mineshaft-600" />
</thead>
);