Merge pull request #2621 from scott-ray-wilson/improve-overview-table-overflow

Improvement: Cap Expanded Secret View Width when Overview Table Overflows
This commit is contained in:
Maidul Islam
2024-10-18 19:14:42 -04:00
committed by GitHub
3 changed files with 21 additions and 32 deletions

View File

@@ -1,4 +1,4 @@
import { HTMLAttributes, ReactNode, TdHTMLAttributes } from "react"; import { DetailedHTMLProps, HTMLAttributes, ReactNode, TdHTMLAttributes } from "react";
import { twMerge } from "tailwind-merge"; import { twMerge } from "tailwind-merge";
import { Skeleton } from "../Skeleton"; import { Skeleton } from "../Skeleton";
@@ -7,12 +7,13 @@ export type TableContainerProps = {
children: ReactNode; children: ReactNode;
isRounded?: boolean; isRounded?: boolean;
className?: string; className?: string;
}; } & DetailedHTMLProps<HTMLAttributes<HTMLDivElement>, HTMLDivElement>;
export const TableContainer = ({ export const TableContainer = ({
children, children,
className, className,
isRounded = true isRounded = true,
...props
}: TableContainerProps): JSX.Element => ( }: TableContainerProps): JSX.Element => (
<div <div
className={twMerge( className={twMerge(
@@ -20,6 +21,7 @@ export const TableContainer = ({
isRounded && "rounded-lg", isRounded && "rounded-lg",
className className
)} )}
{...props}
> >
{children} {children}
</div> </div>

View File

@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { useCallback, useEffect, useMemo, useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import Link from "next/link"; import Link from "next/link";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
@@ -107,18 +107,10 @@ export const SecretOverviewPage = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const router = useRouter(); const router = useRouter();
// this is to set expandable table width const [scrollOffset, setScrollOffset] = useState(0);
// coz when overflow the table goes to the right const [debouncedScrollOffset] = useDebounce(scrollOffset);
const parentTableRef = useRef<HTMLTableElement>(null);
const [expandableTableWidth, setExpandableTableWidth] = useState(0);
const { permission } = useProjectPermission(); const { permission } = useProjectPermission();
useEffect(() => {
if (parentTableRef.current) {
setExpandableTableWidth(parentTableRef.current.clientWidth);
}
}, [parentTableRef.current]);
const { currentWorkspace, isLoading: isWorkspaceLoading } = useWorkspace(); const { currentWorkspace, isLoading: isWorkspaceLoading } = useWorkspace();
const isProjectV3 = currentWorkspace?.version === ProjectVersion.V3; const isProjectV3 = currentWorkspace?.version === ProjectVersion.V3;
const { currentOrg } = useOrganization(); const { currentOrg } = useOrganization();
@@ -162,19 +154,13 @@ export const SecretOverviewPage = () => {
}, []); }, []);
useEffect(() => { useEffect(() => {
const handleParentTableWidthResize = () => {
setExpandableTableWidth(parentTableRef.current?.clientWidth || 0);
};
const onRouteChangeStart = () => { const onRouteChangeStart = () => {
resetSelectedEntries(); resetSelectedEntries();
}; };
router.events.on("routeChangeStart", onRouteChangeStart); router.events.on("routeChangeStart", onRouteChangeStart);
window.addEventListener("resize", handleParentTableWidthResize);
return () => { return () => {
window.removeEventListener("resize", handleParentTableWidthResize);
router.events.off("routeChangeStart", onRouteChangeStart); router.events.off("routeChangeStart", onRouteChangeStart);
}; };
}, []); }, []);
@@ -864,8 +850,11 @@ export const SecretOverviewPage = () => {
selectedEntries={selectedEntries} selectedEntries={selectedEntries}
resetSelectedEntries={resetSelectedEntries} resetSelectedEntries={resetSelectedEntries}
/> />
<div className="thin-scrollbar mt-4" ref={parentTableRef}> <div className="thin-scrollbar mt-4">
<TableContainer className="rounded-b-none"> <TableContainer
onScroll={(e) => setScrollOffset(e.currentTarget.scrollLeft)}
className="thin-scrollbar"
>
<Table> <Table>
<THead> <THead>
<Tr className="sticky top-0 z-20 border-0"> <Tr className="sticky top-0 z-20 border-0">
@@ -1052,7 +1041,7 @@ export const SecretOverviewPage = () => {
environments={visibleEnvs} environments={visibleEnvs}
secretKey={key} secretKey={key}
getSecretByKey={getSecretByKey} getSecretByKey={getSecretByKey}
expandableColWidth={expandableTableWidth} scrollOffset={debouncedScrollOffset}
/> />
))} ))}
</> </>

View File

@@ -23,7 +23,6 @@ type Props = {
secretKey: string; secretKey: string;
secretPath: string; secretPath: string;
environments: { name: string; slug: string }[]; environments: { name: string; slug: string }[];
expandableColWidth: number;
isSelected: boolean; isSelected: boolean;
onToggleSecretSelect: (key: string) => void; onToggleSecretSelect: (key: string) => void;
getSecretByKey: (slug: string, key: string) => SecretV3RawSanitized | undefined; getSecretByKey: (slug: string, key: string) => SecretV3RawSanitized | undefined;
@@ -41,6 +40,7 @@ type Props = {
env: string, env: string,
secretName: string secretName: string
) => { secret?: SecretV3RawSanitized; environmentInfo?: WorkspaceEnv } | undefined; ) => { secret?: SecretV3RawSanitized; environmentInfo?: WorkspaceEnv } | undefined;
scrollOffset: number;
}; };
export const SecretOverviewTableRow = ({ export const SecretOverviewTableRow = ({
@@ -53,9 +53,7 @@ export const SecretOverviewTableRow = ({
onSecretDelete, onSecretDelete,
isImportedSecretPresentInEnv, isImportedSecretPresentInEnv,
getImportedSecretByKey, getImportedSecretByKey,
// temporary until below todo is resolved scrollOffset,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
expandableColWidth,
onToggleSecretSelect, onToggleSecretSelect,
isSelected isSelected
}: Props) => { }: Props) => {
@@ -152,11 +150,11 @@ export const SecretOverviewTableRow = ({
}`} }`}
> >
<div <div
className="ml-2 w-[99%] p-2" className="ml-2 p-2"
// TODO: scott expandableColWidth sometimes 0 due to parent ref not mounting, opting for relative width until resolved style={{
// style={{ marginLeft: scrollOffset,
// width: `calc(${expandableColWidth} - 1rem)` width: "calc(100vw - 290px)" // 290px accounts for sidebar and margin
// }} }}
> >
<SecretRenameRow <SecretRenameRow
secretKey={secretKey} secretKey={secretKey}