From 115fbfd23668d69d222feb39562bbb95a7994911 Mon Sep 17 00:00:00 2001 From: Remko Date: Mon, 19 Feb 2024 16:24:14 +0100 Subject: [PATCH] Added horizontaloverflowwrapper --- .../HorizontalOverflowWrapper.module.css | 52 +++ .../HorizontalOverflowWrapper.tsx | 84 ++++ .../logsTable/LogsTableTemplate.module.css | 4 - .../logsTable/LogsTableTemplate.tsx | 377 +++++++++--------- 4 files changed, 327 insertions(+), 190 deletions(-) create mode 100644 pwa/src/components/horizontalOverflowWrapper/HorizontalOverflowWrapper.module.css create mode 100644 pwa/src/components/horizontalOverflowWrapper/HorizontalOverflowWrapper.tsx diff --git a/pwa/src/components/horizontalOverflowWrapper/HorizontalOverflowWrapper.module.css b/pwa/src/components/horizontalOverflowWrapper/HorizontalOverflowWrapper.module.css new file mode 100644 index 00000000..8b32a3d9 --- /dev/null +++ b/pwa/src/components/horizontalOverflowWrapper/HorizontalOverflowWrapper.module.css @@ -0,0 +1,52 @@ +:root { + --conduction-horizontal-overflow-wrapper-background-color: unset; + --conduction-horizontal-overflow-wrapper-buttons-top: 12px; + + --conduction-horizontal-overflow-wrapper-margin-inline-start: 8px; + --conduction-horizontal-overflow-wrapper-margin-inline-end: 8px; + --conduction-horizontal-overflow-wrapper-margin-block-start: 8px; + --conduction-horizontal-overflow-wrapper-margin-block-end: 8px; +} + +.container { + position: relative; + background-color: var( + --conduction-horizontal-overflow-wrapper-background-color + ); +} + +.wrapper { + overflow-x: scroll; +} + +.scrollButton { + position: sticky; + top: var(--conduction-horizontal-overflow-wrapper-buttons-top); + + margin-inline-start: var( + --conduction-horizontal-overflow-wrapper-margin-inline-start + ); + margin-inline-end: var( + --conduction-horizontal-overflow-wrapper-margin-inline-end + ); + margin-block-start: var( + --conduction-horizontal-overflow-wrapper-margin-block-start + ); + margin-block-end: var( + --conduction-horizontal-overflow-wrapper-margin-block-end + ); + z-index: 10000; +} + +.scrollButton.right { + left: 100%; +} + +/* Hide scrollbar */ +.wrapper::-webkit-scrollbar { + display: none; +} +.wrapper { + -ms-overflow-style: none; + scrollbar-width: none; +} diff --git a/pwa/src/components/horizontalOverflowWrapper/HorizontalOverflowWrapper.tsx b/pwa/src/components/horizontalOverflowWrapper/HorizontalOverflowWrapper.tsx new file mode 100644 index 00000000..c6385d7d --- /dev/null +++ b/pwa/src/components/horizontalOverflowWrapper/HorizontalOverflowWrapper.tsx @@ -0,0 +1,84 @@ +/** + * IMPORTANT: This is a temporary component that will be removed if the @conduction/components package can be updated. + */ + +import * as React from "react"; +import * as styles from "./HorizontalOverflowWrapper.module.css"; +import clsx from "clsx"; +import { Button } from "@utrecht/component-library-react/dist/css-module"; +import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; +import { faChevronLeft, faChevronRight } from "@fortawesome/free-solid-svg-icons"; + +interface HorizontalOverflowWrapperProps { + children: React.ReactNode; + ariaLabels: { + scrollRightButton: string; + scrollLeftButton: string; + }; +} + +export const HorizontalOverflowWrapper: React.FC = ({ children, ariaLabels }) => { + const [canScrollRight, setCanScrollRight] = React.useState(false); + const [canScrollLeft, setCanScrollLeft] = React.useState(false); + + const wrapperRef = React.useRef(null); + + const scrollRight = (): void => { + wrapperRef.current?.scrollTo({ + left: wrapperRef.current.scrollLeft + wrapperRef.current.clientWidth * 0.9, + behavior: "smooth", + }); + }; + + const scrollLeft = (): void => { + wrapperRef.current?.scrollTo({ + left: wrapperRef.current.scrollLeft - wrapperRef.current.clientWidth * 0.9, + behavior: "smooth", + }); + }; + + React.useEffect(() => { + checkScrollDirections(); // initiate available scroll directions + + window.addEventListener("resize", checkScrollDirections); + + return () => window.removeEventListener("resize", checkScrollDirections); + }, []); + + const checkScrollDirections = (): void => { + if (!wrapperRef.current) return; + + setCanScrollRight(wrapperRef.current.scrollLeft + wrapperRef.current.clientWidth < wrapperRef.current.scrollWidth); + setCanScrollLeft(wrapperRef.current.scrollLeft > 0); + }; + + return ( +
+ {canScrollLeft && ( + + )} + + {canScrollRight && ( + + )} + +
+ {children} +
+
+ ); +}; diff --git a/pwa/src/templates/templateParts/logsTable/LogsTableTemplate.module.css b/pwa/src/templates/templateParts/logsTable/LogsTableTemplate.module.css index 2d46eeac..bc2070f9 100644 --- a/pwa/src/templates/templateParts/logsTable/LogsTableTemplate.module.css +++ b/pwa/src/templates/templateParts/logsTable/LogsTableTemplate.module.css @@ -17,10 +17,6 @@ justify-content: space-between; } -.tableContainer { - max-width: 100%; - overflow-x: scroll; -} .button > span > svg { margin-inline-end: var(--gateway-ui-size-xs); diff --git a/pwa/src/templates/templateParts/logsTable/LogsTableTemplate.tsx b/pwa/src/templates/templateParts/logsTable/LogsTableTemplate.tsx index 5beb5569..7a8b1691 100644 --- a/pwa/src/templates/templateParts/logsTable/LogsTableTemplate.tsx +++ b/pwa/src/templates/templateParts/logsTable/LogsTableTemplate.tsx @@ -16,6 +16,7 @@ import { Link } from "@gemeente-denhaag/components-react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { usePagination } from "../../../hooks/usePagination"; import clsx from "clsx"; +import { HorizontalOverflowWrapper } from "../../../components/horizontalOverflowWrapper/HorizontalOverflowWrapper"; interface LogsTableTemplateProps { logs: any[]; @@ -69,206 +70,210 @@ export const LogsTableTemplate: React.FC = ({ logs, pagi -
- - - - {logColumns.level && {t("Level")}} - {logColumns.message && {t("Message")}} - {logColumns.created && {t("Created")}} - {logColumns.endpoint && {t("Endpoint")}} - {logColumns.schema && {t("Schema")}} - {logColumns.source && {t("Source")}} - {logColumns.cronjob && {t("Cronjob")}} - {logColumns.action && {t("Action")}} - {logColumns.user && {t("User")}} - {logColumns.organization && {t("Organization")}} - {logColumns.application && {t("Application")}} - {logColumns.object && {t("Object")}} - {logColumns.mapping && {t("Mapping")}} - - - - - {logs.map((log: any) => ( - - {logColumns.level && ( - - - - )} + +
+
+ + + {logColumns.level && {t("Level")}} + {logColumns.message && {t("Message")}} + {logColumns.created && {t("Created")}} + {logColumns.endpoint && {t("Endpoint")}} + {logColumns.schema && {t("Schema")}} + {logColumns.source && {t("Source")}} + {logColumns.cronjob && {t("Cronjob")}} + {logColumns.action && {t("Action")}} + {logColumns.user && {t("User")}} + {logColumns.organization && {t("Organization")}} + {logColumns.application && {t("Application")}} + {logColumns.object && {t("Object")}} + {logColumns.mapping && {t("Mapping")}} + + + + + {logs.map((log: any) => ( + + {logColumns.level && ( + + + + )} - {logColumns.message && ( - - -
{log.message}
-
-
- )} + {logColumns.message && ( + + +
{log.message}
+
+
+ )} - {logColumns.created && ( - - -
- {formatUnixDateTime(t(i18n.language), log.datetime.$date.$numberLong)} -
-
-
- )} + {logColumns.created && ( + + +
+ {formatUnixDateTime(t(i18n.language), log.datetime.$date.$numberLong)} +
+
+
+ )} - {logColumns.endpoint && ( - -
-
+ {!logs.length && ( + + {Object.values(logColumns) + .filter((value) => value) + .map((_, idx) => ( + {idx === 0 && <>No logs found} + ))} + + )} + + + +