mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-05 06:26:27 +00:00
improvement: allow users to expand collapsed environment view header
This commit is contained in:
@@ -0,0 +1,28 @@
|
|||||||
|
import { MouseEventHandler } from "react";
|
||||||
|
|
||||||
|
export const HeaderResizer = ({
|
||||||
|
onMouseDown,
|
||||||
|
isActive
|
||||||
|
}: {
|
||||||
|
onMouseDown: MouseEventHandler<HTMLDivElement>;
|
||||||
|
isActive: boolean;
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
tabIndex={-1}
|
||||||
|
role="button"
|
||||||
|
className={`absolute bottom-[0.02rem] left-0 z-40 h-0.5 w-full cursor-ns-resize hover:bg-blue-400/20 ${
|
||||||
|
isActive ? "bg-blue-400/75" : "bg-transparent"
|
||||||
|
}`}
|
||||||
|
onMouseDown={onMouseDown}
|
||||||
|
style={{
|
||||||
|
transform: "translateY(50%)"
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
<div className="pointer-events-none absolute -bottom-[0.1rem] left-1/2 z-30 -translate-x-1/2">
|
||||||
|
<div className="h-1 w-8 rounded bg-gray-400 opacity-50" />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -45,10 +45,14 @@ export const Table = ({ children, className }: TableProps): JSX.Element => (
|
|||||||
export type THeadProps = {
|
export type THeadProps = {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
style?: React.CSSProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const THead = ({ children, className }: THeadProps): JSX.Element => (
|
export const THead = ({ children, className, style }: THeadProps): JSX.Element => (
|
||||||
<thead className={twMerge("bg-mineshaft-800 text-xs uppercase text-bunker-300", className)}>
|
<thead
|
||||||
|
className={twMerge("bg-mineshaft-800 text-xs uppercase text-bunker-300", className)}
|
||||||
|
style={style}
|
||||||
|
>
|
||||||
{children}
|
{children}
|
||||||
</thead>
|
</thead>
|
||||||
);
|
);
|
||||||
@@ -96,14 +100,16 @@ export const Tr = ({
|
|||||||
export type ThProps = {
|
export type ThProps = {
|
||||||
children?: ReactNode;
|
children?: ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
style?: React.CSSProperties;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const Th = ({ children, className }: ThProps): JSX.Element => (
|
export const Th = ({ children, className, style }: ThProps): JSX.Element => (
|
||||||
<th
|
<th
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
"border-b-2 border-mineshaft-600 bg-mineshaft-800 px-5 pb-3.5 pt-4 font-semibold",
|
"border-b-2 border-mineshaft-600 bg-mineshaft-800 px-5 pb-3.5 pt-4 font-semibold",
|
||||||
className
|
className
|
||||||
)}
|
)}
|
||||||
|
style={style}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
</th>
|
</th>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ export { usePagination } from "./usePagination";
|
|||||||
export { usePersistentState } from "./usePersistentState";
|
export { usePersistentState } from "./usePersistentState";
|
||||||
export { usePopUp } from "./usePopUp";
|
export { usePopUp } from "./usePopUp";
|
||||||
export { useResetPageHelper } from "./useResetPageHelper";
|
export { useResetPageHelper } from "./useResetPageHelper";
|
||||||
|
export * from "./useResizableHeaderHeight";
|
||||||
export { useSyntaxHighlight } from "./useSyntaxHighlight";
|
export { useSyntaxHighlight } from "./useSyntaxHighlight";
|
||||||
export { useTimedReset } from "./useTimedReset";
|
export { useTimedReset } from "./useTimedReset";
|
||||||
export { useToggle } from "./useToggle";
|
export { useToggle } from "./useToggle";
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
import { MouseEvent, useCallback, useEffect, useRef, useState } from "react";
|
||||||
|
|
||||||
|
type Params = {
|
||||||
|
minHeight: number;
|
||||||
|
maxHeight: number;
|
||||||
|
initialHeight: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const useResizableHeaderHeight = ({ minHeight, maxHeight, initialHeight }: Params) => {
|
||||||
|
const [headerHeight, setHeaderHeight] = useState(initialHeight);
|
||||||
|
const [isResizing, setIsResizing] = useState(false);
|
||||||
|
const startY = useRef(0);
|
||||||
|
const startHeight = useRef(0);
|
||||||
|
|
||||||
|
const handleMouseDown = useCallback(
|
||||||
|
(e: MouseEvent<HTMLDivElement>) => {
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
setIsResizing(true);
|
||||||
|
startY.current = e.clientY;
|
||||||
|
startHeight.current = headerHeight;
|
||||||
|
},
|
||||||
|
[headerHeight]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleMouseMove = useCallback(
|
||||||
|
(e: MouseEvent) => {
|
||||||
|
if (!isResizing) return;
|
||||||
|
|
||||||
|
const deltaY = e.clientY - startY.current;
|
||||||
|
const newHeight = Math.max(minHeight, Math.min(maxHeight, startHeight.current + deltaY));
|
||||||
|
|
||||||
|
setHeaderHeight(newHeight);
|
||||||
|
},
|
||||||
|
[isResizing]
|
||||||
|
);
|
||||||
|
|
||||||
|
const handleMouseUp = useCallback(() => {
|
||||||
|
setIsResizing(false);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isResizing) {
|
||||||
|
document.addEventListener(
|
||||||
|
"mousemove",
|
||||||
|
// @ts-expect-error native discrepancy
|
||||||
|
handleMouseMove
|
||||||
|
);
|
||||||
|
document.addEventListener("mouseup", handleMouseUp);
|
||||||
|
document.body.style.cursor = "ns-resize";
|
||||||
|
document.body.style.userSelect = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
document.removeEventListener(
|
||||||
|
"mousemove",
|
||||||
|
// @ts-expect-error native discrepancy
|
||||||
|
handleMouseMove
|
||||||
|
);
|
||||||
|
document.removeEventListener("mouseup", handleMouseUp);
|
||||||
|
document.body.style.cursor = "";
|
||||||
|
document.body.style.userSelect = "";
|
||||||
|
};
|
||||||
|
}, [isResizing, handleMouseMove, handleMouseUp]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
headerHeight,
|
||||||
|
handleMouseDown,
|
||||||
|
isResizing
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -57,6 +57,7 @@ import {
|
|||||||
Tooltip,
|
Tooltip,
|
||||||
Tr
|
Tr
|
||||||
} from "@app/components/v2";
|
} from "@app/components/v2";
|
||||||
|
import { HeaderResizer } from "@app/components/v2/HeaderResizer/HeaderResizer";
|
||||||
import { ROUTE_PATHS } from "@app/const/routes";
|
import { ROUTE_PATHS } from "@app/const/routes";
|
||||||
import {
|
import {
|
||||||
ProjectPermissionActions,
|
ProjectPermissionActions,
|
||||||
@@ -72,7 +73,14 @@ import {
|
|||||||
PreferenceKey,
|
PreferenceKey,
|
||||||
setUserTablePreference
|
setUserTablePreference
|
||||||
} from "@app/helpers/userTablePreferences";
|
} from "@app/helpers/userTablePreferences";
|
||||||
import { useDebounce, usePagination, usePopUp, useResetPageHelper, useToggle } from "@app/hooks";
|
import {
|
||||||
|
useDebounce,
|
||||||
|
usePagination,
|
||||||
|
usePopUp,
|
||||||
|
useResetPageHelper,
|
||||||
|
useResizableHeaderHeight,
|
||||||
|
useToggle
|
||||||
|
} from "@app/hooks";
|
||||||
import {
|
import {
|
||||||
useCreateFolder,
|
useCreateFolder,
|
||||||
useCreateSecretV3,
|
useCreateSecretV3,
|
||||||
@@ -860,6 +868,19 @@ export const OverviewPage = () => {
|
|||||||
);
|
);
|
||||||
}, [importedByEnvs, selectedEntries, selectedKeysCount]);
|
}, [importedByEnvs, selectedEntries, selectedKeysCount]);
|
||||||
|
|
||||||
|
const storedHeight = Number.parseInt(localStorage.getItem("overview-header-height") ?? "96");
|
||||||
|
const { headerHeight, handleMouseDown, isResizing } = useResizableHeaderHeight({
|
||||||
|
initialHeight: Number.isNaN(storedHeight) ? 96 : storedHeight,
|
||||||
|
minHeight: 96,
|
||||||
|
maxHeight: 192
|
||||||
|
});
|
||||||
|
|
||||||
|
const debouncedHeaderHeight = useDebounce(headerHeight);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
localStorage.setItem("overview-header-height", debouncedHeaderHeight.toString());
|
||||||
|
}, [debouncedHeaderHeight]);
|
||||||
|
|
||||||
if (isProjectV3 && visibleEnvs.length > 0 && isOverviewLoading) {
|
if (isProjectV3 && visibleEnvs.length > 0 && isOverviewLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="container mx-auto flex h-screen w-full items-center justify-center px-8 text-mineshaft-50 dark:[color-scheme:dark]">
|
<div className="container mx-auto flex h-screen w-full items-center justify-center px-8 text-mineshaft-50 dark:[color-scheme:dark]">
|
||||||
@@ -1188,15 +1209,17 @@ export const OverviewPage = () => {
|
|||||||
className="thin-scrollbar rounded-b-none"
|
className="thin-scrollbar rounded-b-none"
|
||||||
>
|
>
|
||||||
<Table>
|
<Table>
|
||||||
<THead className={collapseEnvironments ? "h-24" : ""}>
|
<THead
|
||||||
|
className="relative"
|
||||||
|
style={{ height: collapseEnvironments ? headerHeight : undefined }}
|
||||||
|
>
|
||||||
<Tr
|
<Tr
|
||||||
className={twMerge("sticky top-0 z-20 border-0", collapseEnvironments && "h-24")}
|
className="sticky top-0 z-20 border-0"
|
||||||
|
style={{ height: collapseEnvironments ? headerHeight : undefined }}
|
||||||
>
|
>
|
||||||
<Th
|
<Th
|
||||||
className={twMerge(
|
className="sticky left-0 z-20 min-w-[20rem] border-b-0 p-0"
|
||||||
"sticky left-0 z-20 min-w-[20rem] border-b-0 p-0",
|
style={{ height: collapseEnvironments ? headerHeight : undefined }}
|
||||||
collapseEnvironments && "h-24"
|
|
||||||
)}
|
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
@@ -1270,13 +1293,21 @@ export const OverviewPage = () => {
|
|||||||
const importedSecKeyCount = getEnvImportedSecretKeyCount(slug);
|
const importedSecKeyCount = getEnvImportedSecretKeyCount(slug);
|
||||||
const missingKeyCount = secKeys.length - envSecKeyCount - importedSecKeyCount;
|
const missingKeyCount = secKeys.length - envSecKeyCount - importedSecKeyCount;
|
||||||
|
|
||||||
|
const isLast = index === visibleEnvs.length - 1;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Th
|
<Th
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
"min-table-row border-b-0 p-0 text-xs",
|
"min-table-row border-b-0 p-0 text-xs",
|
||||||
collapseEnvironments && index === visibleEnvs.length - 1 && "mr-8",
|
collapseEnvironments && index === visibleEnvs.length - 1 && "mr-8",
|
||||||
collapseEnvironments ? "h-24 w-[1rem]" : "min-w-[11rem] text-center"
|
// eslint-disable-next-line no-nested-ternary
|
||||||
|
collapseEnvironments
|
||||||
|
? isLast
|
||||||
|
? "!w-[3.8rem]"
|
||||||
|
: "w-[1rem]"
|
||||||
|
: "min-w-[11rem] text-center"
|
||||||
)}
|
)}
|
||||||
|
style={{ height: collapseEnvironments ? headerHeight : undefined }}
|
||||||
key={`secret-overview-${name}-${index + 1}`}
|
key={`secret-overview-${name}-${index + 1}`}
|
||||||
>
|
>
|
||||||
<Tooltip
|
<Tooltip
|
||||||
@@ -1299,33 +1330,48 @@ export const OverviewPage = () => {
|
|||||||
className={twMerge(
|
className={twMerge(
|
||||||
"border-b border-mineshaft-600",
|
"border-b border-mineshaft-600",
|
||||||
collapseEnvironments
|
collapseEnvironments
|
||||||
? "relative h-24 w-[2.9rem]"
|
? "relative min-w-[2.9rem]"
|
||||||
: "flex items-center justify-center px-5 pb-[0.82rem] pt-3.5",
|
: "flex items-center justify-center px-5 pb-[0.82rem] pt-3.5",
|
||||||
collapseEnvironments &&
|
collapseEnvironments && isLast && "overflow-clip"
|
||||||
index === visibleEnvs.length - 1 &&
|
|
||||||
"overflow-clip"
|
|
||||||
)}
|
)}
|
||||||
|
style={{ height: collapseEnvironments ? headerHeight : undefined }}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
"border-mineshaft-600",
|
"border-mineshaft-600",
|
||||||
collapseEnvironments
|
collapseEnvironments
|
||||||
? "ml-[0.85rem] h-24 -skew-x-[16rad] transform border-l text-xs"
|
? "-skew-x-[16rad] transform border-l text-xs"
|
||||||
: "flex items-center justify-center"
|
: "flex items-center justify-center"
|
||||||
)}
|
)}
|
||||||
|
style={{
|
||||||
|
height: collapseEnvironments ? headerHeight : undefined,
|
||||||
|
marginLeft: collapseEnvironments ? headerHeight * 0.145 : undefined
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
className={twMerge(
|
className={twMerge(
|
||||||
"duration-100 hover:text-mineshaft-100",
|
"duration-100 hover:text-mineshaft-100",
|
||||||
collapseEnvironments &&
|
|
||||||
(index === visibleEnvs.length - 1
|
|
||||||
? "bottom-[1.75rem] w-14"
|
|
||||||
: "bottom-10 w-20"),
|
|
||||||
collapseEnvironments
|
collapseEnvironments
|
||||||
? "absolute -rotate-[72.25deg] text-left !text-[12px] font-normal"
|
? "absolute -rotate-[72.25deg] text-left !text-[12px] font-normal"
|
||||||
: "flex items-center text-center text-sm font-medium"
|
: "flex items-center text-center text-sm font-medium"
|
||||||
)}
|
)}
|
||||||
|
style={
|
||||||
|
// eslint-disable-next-line no-nested-ternary
|
||||||
|
collapseEnvironments
|
||||||
|
? isLast
|
||||||
|
? {
|
||||||
|
bottom: 42,
|
||||||
|
left: 0,
|
||||||
|
width: 86
|
||||||
|
}
|
||||||
|
: {
|
||||||
|
width: headerHeight * 0.9,
|
||||||
|
bottom: headerHeight * 0.45,
|
||||||
|
left: 24 - (headerHeight * 0.9) / 3.05
|
||||||
|
}
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
onClick={() => handleExploreEnvClick(slug)}
|
onClick={() => handleExploreEnvClick(slug)}
|
||||||
>
|
>
|
||||||
<p className="truncate font-medium">{name}</p>
|
<p className="truncate font-medium">{name}</p>
|
||||||
@@ -1346,6 +1392,9 @@ export const OverviewPage = () => {
|
|||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</Tr>
|
</Tr>
|
||||||
|
{collapseEnvironments && (
|
||||||
|
<HeaderResizer onMouseDown={handleMouseDown} isActive={isResizing} />
|
||||||
|
)}
|
||||||
</THead>
|
</THead>
|
||||||
<TBody>
|
<TBody>
|
||||||
{canViewOverviewPage && isOverviewLoading && (
|
{canViewOverviewPage && isOverviewLoading && (
|
||||||
|
|||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
import { subject } from "@casl/ability";
|
import { subject } from "@casl/ability";
|
||||||
|
import { faCircle } from "@fortawesome/free-regular-svg-icons";
|
||||||
import {
|
import {
|
||||||
faAngleDown,
|
faAngleDown,
|
||||||
faCheck,
|
faCheck,
|
||||||
faCircle,
|
|
||||||
faCodeBranch,
|
faCodeBranch,
|
||||||
faEye,
|
faEye,
|
||||||
faEyeSlash,
|
faEyeSlash,
|
||||||
@@ -148,7 +148,7 @@ export const SecretOverviewTableRow = ({
|
|||||||
"border-r border-mineshaft-600 px-0 py-3 group-hover:bg-mineshaft-700",
|
"border-r border-mineshaft-600 px-0 py-3 group-hover:bg-mineshaft-700",
|
||||||
isFormExpanded && "border-t-2 border-mineshaft-500",
|
isFormExpanded && "border-t-2 border-mineshaft-500",
|
||||||
(isSecretPresent && !isSecretEmpty) || isSecretImported ? "text-green-600" : "",
|
(isSecretPresent && !isSecretEmpty) || isSecretImported ? "text-green-600" : "",
|
||||||
isSecretPresent && isSecretEmpty && !isSecretImported ? "text-yellow" : "",
|
isSecretPresent && isSecretEmpty && !isSecretImported ? "text-mineshaft-400" : "",
|
||||||
!isSecretPresent && !isSecretEmpty && !isSecretImported ? "text-red-600" : ""
|
!isSecretPresent && !isSecretEmpty && !isSecretImported ? "text-red-600" : ""
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
@@ -174,7 +174,7 @@ export const SecretOverviewTableRow = ({
|
|||||||
)}
|
)}
|
||||||
{isSecretEmpty && (
|
{isSecretEmpty && (
|
||||||
<Tooltip content="Empty value">
|
<Tooltip content="Empty value">
|
||||||
<FontAwesomeIcon icon={faCircle} />
|
<FontAwesomeIcon size="sm" icon={faCircle} />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user