From f0a3ddbf2e3b9d14812f8265172cf4632862bc08 Mon Sep 17 00:00:00 2001 From: Simon Larsen Date: Mon, 14 Oct 2024 20:23:20 +0100 Subject: [PATCH] make UI for table filters nicer --- .../Components/ModelTable/BaseModelTable.tsx | 4 +- Common/UI/Components/ModelTable/TableView.tsx | 127 +++++++++++------- Common/UI/Components/MoreMenu/MoreMenu.tsx | 43 ++++-- .../UI/Components/MoreMenu/MoreMenuItem.tsx | 8 +- .../Components/MoreMenu/MoreMenuSection.tsx | 4 +- Common/UI/Types/FunctionTypes.ts | 2 + .../src/Components/Monitor/MonitorTable.tsx | 2 +- 7 files changed, 127 insertions(+), 63 deletions(-) diff --git a/Common/UI/Components/ModelTable/BaseModelTable.tsx b/Common/UI/Components/ModelTable/BaseModelTable.tsx index e5e4a20bf7..117aa429f5 100644 --- a/Common/UI/Components/ModelTable/BaseModelTable.tsx +++ b/Common/UI/Components/ModelTable/BaseModelTable.tsx @@ -906,9 +906,7 @@ const BaseModelTable: ( headerbuttons.push({ title: "", buttonStyle: ButtonStyleType.ICON, - className: props.showRefreshButton - ? "p-1 px-1 pr-0 pl-0 py-0 mt-1" - : "py-0 pr-0 pl-1 mt-1", + className: "py-0 pr-0 pl-1 mt-1", onClick: () => { setQuery({}); setShowFilterModal(true); diff --git a/Common/UI/Components/ModelTable/TableView.tsx b/Common/UI/Components/ModelTable/TableView.tsx index 3660b15d0f..26c00cb132 100644 --- a/Common/UI/Components/ModelTable/TableView.tsx +++ b/Common/UI/Components/ModelTable/TableView.tsx @@ -14,7 +14,7 @@ import { LIMIT_PER_PROJECT } from "../../../Types/Database/LimitMax"; import SortOrder from "../../../Types/BaseDatabase/SortOrder"; import API from "../../../Utils/API"; import MoreMenuSection from "../MoreMenu/MoreMenuSection"; -import Button, { ButtonStyleType } from "../Button/Button"; +import { ButtonStyleType } from "../Button/Button"; import IconProp from "../../../Types/Icon/IconProp"; import { BarLoader } from "react-spinners"; import ConfirmModal from "../Modal/ConfirmModal"; @@ -22,9 +22,10 @@ import ModelFormModal from "../ModelFormModal/ModelFormModal"; import { FormType } from "../Forms/ModelForm"; import FormFieldSchemaType from "../Forms/Types/FormFieldSchemaType"; import { PromiseVoidFunction } from "../../../Types/FunctionTypes"; -import { GetReactElementFunction } from "../../Types/FunctionTypes"; +import { GetReactElementArrayFunction } from "../../Types/FunctionTypes"; import ProjectUtil from "../../Utils/Project"; import User from "../../Utils/User"; +import Icon, { SizeProp, ThickProp } from "../Icon/Icon"; export interface ComponentProps { tableId: string; @@ -122,21 +123,28 @@ const TableViewElement: FunctionComponent = ( (item: TableView): ReactElement => { return (
-
); }; @@ -150,6 +158,8 @@ const TableViewElement: FunctionComponent = ( key={index} rightElement={getRightElementForTableViewMenuItem(item)} text={item.name || ""} + className="text-gray-600 hover:text-gray-800" + icon={IconProp.Window} onClick={() => { props.onViewChange && props.onViewChange(item); setCurrentlySelectedView(item); @@ -159,42 +169,36 @@ const TableViewElement: FunctionComponent = ( }); }; - const getMenuContents: GetReactElementFunction = (): ReactElement => { - if (isLoading) { - return ; - } + const getMenuContents: GetReactElementArrayFunction = + (): Array => { + if (isLoading) { + return []; + } - return ( - <> - {allTableViews.length > 0 ? ( + const elements: Array = []; + + if (allTableViews.length > 0) { + elements.push( {getViewItems()} - - ) : ( - <> - )} - - {currentlySelectedView ? ( - { - setCurrentlySelectedView(null); - props.onViewChange && props.onViewChange(null); - }} - > - ) : ( - <> - )} + , + ); + } + elements.push( { setShowCreateNewViewModel(true); }} - > - - ); - }; + >, + ); + + return elements; + }; if (error) { return ( @@ -311,7 +315,38 @@ const TableViewElement: FunctionComponent = ( ); } - return {getMenuContents()}; + type GetElementToBeShownInsteadOfButtonFunction = () => ReactElement | undefined; + + const getElementToBeShownInsteadOfButton: GetElementToBeShownInsteadOfButtonFunction = (): ReactElement | undefined => { + if (!currentlySelectedView) { + return undefined; + } + + return ( +
+ {currentlySelectedView.name} +
+ { + setCurrentlySelectedView(null); + props.onViewChange && props.onViewChange(null); + }} + /> +
+
+ ); + }; + + return ( + + {getMenuContents()} + + ); }; export default TableViewElement; diff --git a/Common/UI/Components/MoreMenu/MoreMenu.tsx b/Common/UI/Components/MoreMenu/MoreMenu.tsx index 5d56b1d4bf..94a94ac3c5 100644 --- a/Common/UI/Components/MoreMenu/MoreMenu.tsx +++ b/Common/UI/Components/MoreMenu/MoreMenu.tsx @@ -9,7 +9,8 @@ import IconProp from "../../../Types/Icon/IconProp"; import useComponentOutsideClick from "../../Types/UseComponentOutsideClick"; export interface ComponentProps { - children: Array | ReactElement; + children: Array; + elementToBeShownInsteadOfButton?: ReactElement | undefined; } const MoreMenu: FunctionComponent = ( @@ -26,15 +27,27 @@ const MoreMenu: FunctionComponent = ( return (
-
-
+ )} + + {props.elementToBeShownInsteadOfButton && ( +
{ setIsComponentVisible(!isDropdownVisible); }} - /> -
+ > + {props.elementToBeShownInsteadOfButton} +
+ )} {isComponentVisible && (
= ( aria-orientation="vertical" aria-labelledby="menu-button" > - {props.children} + {props.children.map((child: ReactElement, index: number) => { + return ( +
{ + if (isComponentVisible) { + setIsComponentVisible(false); + } + }} + > + {child} +
+ ); + })}
)} diff --git a/Common/UI/Components/MoreMenu/MoreMenuItem.tsx b/Common/UI/Components/MoreMenu/MoreMenuItem.tsx index fea7172a60..0c6c6f5266 100644 --- a/Common/UI/Components/MoreMenu/MoreMenuItem.tsx +++ b/Common/UI/Components/MoreMenu/MoreMenuItem.tsx @@ -7,6 +7,8 @@ export interface ComponentProps { text: string; onClick: () => void; rightElement?: Array | ReactElement | undefined; + className?: string | undefined; + iconClassName?: string | undefined; } const MoreMenuItem: FunctionComponent = ( @@ -14,7 +16,7 @@ const MoreMenuItem: FunctionComponent = ( ): ReactElement => { return ( { props.onClick(); @@ -23,10 +25,10 @@ const MoreMenuItem: FunctionComponent = ( {props.icon && ( )} -
+
{props.text}
{props.rightElement}
diff --git a/Common/UI/Components/MoreMenu/MoreMenuSection.tsx b/Common/UI/Components/MoreMenu/MoreMenuSection.tsx index 4f0d4612a8..fc64c1b271 100644 --- a/Common/UI/Components/MoreMenu/MoreMenuSection.tsx +++ b/Common/UI/Components/MoreMenu/MoreMenuSection.tsx @@ -10,8 +10,8 @@ const MoreMenuSection: FunctionComponent = ( ): ReactElement => { return (
-
- {props.title.toLocaleUpperCase()} +
+ {props.title.toUpperCase()}
{props.children} diff --git a/Common/UI/Types/FunctionTypes.ts b/Common/UI/Types/FunctionTypes.ts index 9f97bbd041..e9cb1585a8 100644 --- a/Common/UI/Types/FunctionTypes.ts +++ b/Common/UI/Types/FunctionTypes.ts @@ -2,4 +2,6 @@ import { ReactElement } from "react"; export type GetReactElementFunction = () => ReactElement; +export type GetReactElementArrayFunction = () => Array; + export type GetReactElementOrStringFunction = () => ReactElement | string; diff --git a/Dashboard/src/Components/Monitor/MonitorTable.tsx b/Dashboard/src/Components/Monitor/MonitorTable.tsx index 5166e4aedc..e3395f4bd9 100644 --- a/Dashboard/src/Components/Monitor/MonitorTable.tsx +++ b/Dashboard/src/Components/Monitor/MonitorTable.tsx @@ -60,7 +60,7 @@ const MonitorsTable: FunctionComponent = ( modelType={Monitor} name="Monitors" id="Monitors-table" - // saveFilterProps={props.saveFilterProps} + saveFilterProps={props.saveFilterProps} bulkActions={{ buttons: [ {