mirror of
https://github.com/Kingsrook/qqq-frontend-material-dashboard.git
synced 2025-07-17 21:00:45 +00:00
Add tooltips from metaData/helpContent to widget blocks.
This commit is contained in:
@ -21,8 +21,6 @@
|
|||||||
|
|
||||||
import BlockElementWrapper from "qqq/components/widgets/blocks/BlockElementWrapper";
|
import BlockElementWrapper from "qqq/components/widgets/blocks/BlockElementWrapper";
|
||||||
import {StandardBlockComponentProps} from "qqq/components/widgets/blocks/BlockModels";
|
import {StandardBlockComponentProps} from "qqq/components/widgets/blocks/BlockModels";
|
||||||
import UpOrDownNumberBlock from "qqq/components/widgets/blocks/UpOrDownNumberBlock";
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
@ -40,7 +38,7 @@ export default function BigNumberBlock({widgetMetaData, data}: StandardBlockComp
|
|||||||
<div style={{width: data.styles.width ?? "auto"}}>
|
<div style={{width: data.styles.width ?? "auto"}}>
|
||||||
|
|
||||||
<div style={{fontWeight: "700", fontSize: "0.875rem", color: "#3D3D3D", marginBottom: "-0.5rem"}}>
|
<div style={{fontWeight: "700", fontSize: "0.875rem", color: "#3D3D3D", marginBottom: "-0.5rem"}}>
|
||||||
<BlockElementWrapper data={data} slot="heading">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="heading">
|
||||||
<span>{data.values.heading}</span>
|
<span>{data.values.heading}</span>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
</div>
|
</div>
|
||||||
@ -49,14 +47,14 @@ export default function BigNumberBlock({widgetMetaData, data}: StandardBlockComp
|
|||||||
|
|
||||||
<div style={{display: "flex", alignItems: "baseline"}}>
|
<div style={{display: "flex", alignItems: "baseline"}}>
|
||||||
<div style={{fontWeight: "700", fontSize: "2rem", marginRight: "0.25rem"}}>
|
<div style={{fontWeight: "700", fontSize: "2rem", marginRight: "0.25rem"}}>
|
||||||
<BlockElementWrapper data={data} slot="number">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="number">
|
||||||
<span style={{color: data.styles.numberColor}}>{data.values.number}</span>
|
<span style={{color: data.styles.numberColor}}>{data.values.number}</span>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
</div>
|
</div>
|
||||||
{
|
{
|
||||||
data.values.context &&
|
data.values.context &&
|
||||||
<div style={{fontWeight: "500", fontSize: "0.875rem", color: "#7b809a"}}>
|
<div style={{fontWeight: "500", fontSize: "0.875rem", color: "#7b809a"}}>
|
||||||
<BlockElementWrapper data={data} slot="context">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="context">
|
||||||
<span>{data.values.context}</span>
|
<span>{data.values.context}</span>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
</div>
|
</div>
|
||||||
|
@ -20,14 +20,18 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
import {QWidgetMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/QWidgetMetaData";
|
||||||
import {Tooltip} from "@mui/material";
|
import {Tooltip} from "@mui/material";
|
||||||
import React, {ReactElement} from "react";
|
import React, {ReactElement, useContext} from "react";
|
||||||
import {Link} from "react-router-dom";
|
import {Link} from "react-router-dom";
|
||||||
|
import QContext from "QContext";
|
||||||
|
import HelpContent, {hasHelpContent} from "qqq/components/misc/HelpContent";
|
||||||
import {BlockData, BlockLink, BlockTooltip} from "qqq/components/widgets/blocks/BlockModels";
|
import {BlockData, BlockLink, BlockTooltip} from "qqq/components/widgets/blocks/BlockModels";
|
||||||
|
|
||||||
interface BlockElementWrapperProps
|
interface BlockElementWrapperProps
|
||||||
{
|
{
|
||||||
data: BlockData;
|
data: BlockData;
|
||||||
|
metaData: QWidgetMetaData;
|
||||||
slot: string
|
slot: string
|
||||||
linkProps?: any;
|
linkProps?: any;
|
||||||
children: ReactElement;
|
children: ReactElement;
|
||||||
@ -36,8 +40,10 @@ interface BlockElementWrapperProps
|
|||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** For Blocks - wrap their "slot" elements with an optional tooltip and/or link
|
** For Blocks - wrap their "slot" elements with an optional tooltip and/or link
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
export default function BlockElementWrapper({data, slot, linkProps, children}: BlockElementWrapperProps): JSX.Element
|
export default function BlockElementWrapper({data, metaData, slot, linkProps, children}: BlockElementWrapperProps): JSX.Element
|
||||||
{
|
{
|
||||||
|
const {helpHelpActive} = useContext(QContext);
|
||||||
|
|
||||||
let link: BlockLink;
|
let link: BlockLink;
|
||||||
let tooltip: BlockTooltip;
|
let tooltip: BlockTooltip;
|
||||||
|
|
||||||
@ -61,6 +67,26 @@ export default function BlockElementWrapper({data, slot, linkProps, children}: B
|
|||||||
tooltip = data.tooltip;
|
tooltip = data.tooltip;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!tooltip)
|
||||||
|
{
|
||||||
|
const helpRoles = ["ALL_SCREENS"]
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// the full keys in the helpContent table will look like: //
|
||||||
|
// widget:MyCoolWidget;slot=myBlockId,label (if the block has a blockId in data) //
|
||||||
|
// widget:MyCoolWidget;slot=label (no blockId; note, label is slot name here) //
|
||||||
|
// in the widget metaData, the map of helpContent will just have the "slot" portion as a key //
|
||||||
|
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
const key = data.blockId ? `${data.blockId},${slot}` : slot;
|
||||||
|
const showHelp = helpHelpActive || hasHelpContent(metaData?.helpContent?.get(key), helpRoles);
|
||||||
|
|
||||||
|
if(showHelp)
|
||||||
|
{
|
||||||
|
const formattedHelpContent = <HelpContent helpContents={metaData?.helpContent?.get(key)} roles={helpRoles} helpContentKey={`widget:${metaData?.name};slot:${key}`} />;
|
||||||
|
tooltip = {title: formattedHelpContent, placement: "bottom"}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let rs = children;
|
let rs = children;
|
||||||
|
|
||||||
if(link)
|
if(link)
|
||||||
|
@ -24,6 +24,7 @@ import {QWidgetMetaData} from "@kingsrook/qqq-frontend-core/lib/model/metaData/Q
|
|||||||
|
|
||||||
export interface BlockData
|
export interface BlockData
|
||||||
{
|
{
|
||||||
|
blockId?: string;
|
||||||
blockTypeName: string;
|
blockTypeName: string;
|
||||||
|
|
||||||
tooltip?: BlockTooltip;
|
tooltip?: BlockTooltip;
|
||||||
@ -38,7 +39,7 @@ export interface BlockData
|
|||||||
|
|
||||||
export interface BlockTooltip
|
export interface BlockTooltip
|
||||||
{
|
{
|
||||||
title: string;
|
title: string | JSX.Element;
|
||||||
placement: string;
|
placement: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,19 +28,19 @@ import {StandardBlockComponentProps} from "qqq/components/widgets/blocks/BlockMo
|
|||||||
**
|
**
|
||||||
** ${number} ${icon}
|
** ${number} ${icon}
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
export default function NumberIconBadgeBlock({data}: StandardBlockComponentProps): JSX.Element
|
export default function NumberIconBadgeBlock({widgetMetaData, data}: StandardBlockComponentProps): JSX.Element
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
<div style={{display: "inline-block", whiteSpace: "nowrap", color: data.styles.color}}>
|
<div style={{display: "inline-block", whiteSpace: "nowrap", color: data.styles.color}}>
|
||||||
{
|
{
|
||||||
data.values.number &&
|
data.values.number &&
|
||||||
<BlockElementWrapper data={data} slot="number">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="number">
|
||||||
<span style={{color: data.styles.color, fontSize: "0.875rem"}}>{data.values.number}</span>
|
<span style={{color: data.styles.color, fontSize: "0.875rem"}}>{data.values.number}</span>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
data.values.iconName &&
|
data.values.iconName &&
|
||||||
<BlockElementWrapper data={data} slot="icon">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="icon">
|
||||||
<Icon style={{color: data.styles.color, fontSize: "1rem", position: "relative", top: "3px"}}>{data.values.iconName}</Icon>
|
<Icon style={{color: data.styles.color, fontSize: "1rem", position: "relative", top: "3px"}}>{data.values.iconName}</Icon>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
}
|
}
|
||||||
|
@ -35,14 +35,14 @@ import {StandardBlockComponentProps} from "qqq/components/widgets/blocks/BlockMo
|
|||||||
** ${heading}
|
** ${heading}
|
||||||
** ${bar} ${value}
|
** ${bar} ${value}
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
export default function ProgressBarBlock({data}: StandardBlockComponentProps): JSX.Element
|
export default function ProgressBarBlock({widgetMetaData, data}: StandardBlockComponentProps): JSX.Element
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
<Typography component="div" variant="button" color="text" fontWeight="light" sx={{textTransform: "none"}}>
|
<Typography component="div" variant="button" color="text" fontWeight="light" sx={{textTransform: "none"}}>
|
||||||
{
|
{
|
||||||
data.values.heading &&
|
data.values.heading &&
|
||||||
<div style={{marginBottom: "0.25rem", fontWeight: 500, color: "#3D3D3D"}}>
|
<div style={{marginBottom: "0.25rem", fontWeight: 500, color: "#3D3D3D"}}>
|
||||||
<BlockElementWrapper data={data} slot="heading">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="heading">
|
||||||
<span>{data.values.heading}</span>
|
<span>{data.values.heading}</span>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
</div>
|
</div>
|
||||||
@ -50,7 +50,7 @@ export default function ProgressBarBlock({data}: StandardBlockComponentProps): J
|
|||||||
|
|
||||||
<div style={{display: "flex", alignItems: "center", marginBottom: "0.75rem"}}>
|
<div style={{display: "flex", alignItems: "center", marginBottom: "0.75rem"}}>
|
||||||
|
|
||||||
<BlockElementWrapper data={data} slot="bar" linkProps={{style: {width: "100%"}}}>
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="bar" linkProps={{style: {width: "100%"}}}>
|
||||||
<div style={{background: "#E0E0E0", width: "100%", borderRadius: "0.5rem", height: "1rem"}}>
|
<div style={{background: "#E0E0E0", width: "100%", borderRadius: "0.5rem", height: "1rem"}}>
|
||||||
{
|
{
|
||||||
data.values.percent > 0 ? <div style={{background: data.styles.barColor ?? "#0062ff", minWidth: "1rem", width: `${data.values.percent}%`, borderRadius: "0.5rem", height: "1rem"}}></div> : <></>
|
data.values.percent > 0 ? <div style={{background: data.styles.barColor ?? "#0062ff", minWidth: "1rem", width: `${data.values.percent}%`, borderRadius: "0.5rem", height: "1rem"}}></div> : <></>
|
||||||
@ -59,7 +59,7 @@ export default function ProgressBarBlock({data}: StandardBlockComponentProps): J
|
|||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
|
|
||||||
<div style={{width: "60px", textAlign: "right", fontWeight: 600, color: "#3D3D3D"}}>
|
<div style={{width: "60px", textAlign: "right", fontWeight: 600, color: "#3D3D3D"}}>
|
||||||
<BlockElementWrapper data={data} slot="value">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="value">
|
||||||
<span>{data.values.value ?? `${(data.values.percent as number).toFixed(1)}%`}</span>
|
<span>{data.values.value ?? `${(data.values.percent as number).toFixed(1)}%`}</span>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
</div>
|
</div>
|
||||||
|
@ -29,7 +29,7 @@ import {StandardBlockComponentProps} from "qqq/components/widgets/blocks/BlockMo
|
|||||||
**
|
**
|
||||||
** ${label} ${value}
|
** ${label} ${value}
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
export default function TableSubRowDetailRowBlock({data}: StandardBlockComponentProps): JSX.Element
|
export default function TableSubRowDetailRowBlock({widgetMetaData, data}: StandardBlockComponentProps): JSX.Element
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
<div style={{display: "flex", maxWidth: "calc(100% - 24px)", justifyContent: "space-between"}}>
|
<div style={{display: "flex", maxWidth: "calc(100% - 24px)", justifyContent: "space-between"}}>
|
||||||
@ -37,7 +37,7 @@ export default function TableSubRowDetailRowBlock({data}: StandardBlockComponent
|
|||||||
{
|
{
|
||||||
data.values.label &&
|
data.values.label &&
|
||||||
<div style={{overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis"}}>
|
<div style={{overflow: "hidden", whiteSpace: "nowrap", textOverflow: "ellipsis"}}>
|
||||||
<BlockElementWrapper data={data} slot="label">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="label">
|
||||||
<span style={{color: data.styles.labelColor}}>{data.values.label}</span>
|
<span style={{color: data.styles.labelColor}}>{data.values.label}</span>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
</div>
|
</div>
|
||||||
@ -45,7 +45,7 @@ export default function TableSubRowDetailRowBlock({data}: StandardBlockComponent
|
|||||||
|
|
||||||
{
|
{
|
||||||
data.values.value &&
|
data.values.value &&
|
||||||
<BlockElementWrapper data={data} slot="value">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="value">
|
||||||
<span style={{color: data.styles.valueColor}}>{data.values.value}</span>
|
<span style={{color: data.styles.valueColor}}>{data.values.value}</span>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
}
|
}
|
||||||
|
@ -27,10 +27,10 @@ import {StandardBlockComponentProps} from "qqq/components/widgets/blocks/BlockMo
|
|||||||
**
|
**
|
||||||
** ${text}
|
** ${text}
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
export default function TextBlock({data}: StandardBlockComponentProps): JSX.Element
|
export default function TextBlock({widgetMetaData, data}: StandardBlockComponentProps): JSX.Element
|
||||||
{
|
{
|
||||||
return (
|
return (
|
||||||
<BlockElementWrapper data={data} slot="">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="">
|
||||||
<span>{data.values.text}</span>
|
<span>{data.values.text}</span>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
);
|
);
|
||||||
|
@ -35,7 +35,7 @@ import {StandardBlockComponentProps} from "qqq/components/widgets/blocks/BlockMo
|
|||||||
** ${icon} ${number}
|
** ${icon} ${number}
|
||||||
** ${context}
|
** ${context}
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
export default function UpOrDownNumberBlock({data}: StandardBlockComponentProps): JSX.Element
|
export default function UpOrDownNumberBlock({widgetMetaData, data}: StandardBlockComponentProps): JSX.Element
|
||||||
{
|
{
|
||||||
if (!data.styles)
|
if (!data.styles)
|
||||||
{
|
{
|
||||||
@ -61,7 +61,7 @@ export default function UpOrDownNumberBlock({data}: StandardBlockComponentProps)
|
|||||||
<div style={{display: "flex", flexDirection: data.styles.isStacked ? "column" : "row", alignItems: data.styles.isStacked ? "flex-end" : "baseline"}}>
|
<div style={{display: "flex", flexDirection: data.styles.isStacked ? "column" : "row", alignItems: data.styles.isStacked ? "flex-end" : "baseline"}}>
|
||||||
|
|
||||||
<div style={{display: "flex", alignItems: "baseline", fontWeight: 700, fontSize: ".875rem"}}>
|
<div style={{display: "flex", alignItems: "baseline", fontWeight: 700, fontSize: ".875rem"}}>
|
||||||
<BlockElementWrapper data={data} slot="number">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="number">
|
||||||
<>
|
<>
|
||||||
<Icon sx={{color: goodOrBadColor, alignSelf: "flex-end", fontSize: "2.25rem !important", lineHeight: "0.875rem", height: "1rem", width: "2rem",}}>{iconName}</Icon>
|
<Icon sx={{color: goodOrBadColor, alignSelf: "flex-end", fontSize: "2.25rem !important", lineHeight: "0.875rem", height: "1rem", width: "2rem",}}>{iconName}</Icon>
|
||||||
<span style={{color: goodOrBadColor}}>{data.values.number}</span>
|
<span style={{color: goodOrBadColor}}>{data.values.number}</span>
|
||||||
@ -70,7 +70,7 @@ export default function UpOrDownNumberBlock({data}: StandardBlockComponentProps)
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div style={{fontWeight: 500, fontSize: "0.875rem", color: "#7b809a", marginLeft: "0.25rem"}}>
|
<div style={{fontWeight: 500, fontSize: "0.875rem", color: "#7b809a", marginLeft: "0.25rem"}}>
|
||||||
<BlockElementWrapper data={data} slot="context">
|
<BlockElementWrapper metaData={widgetMetaData} data={data} slot="context">
|
||||||
<span>{data.values.context}</span>
|
<span>{data.values.context}</span>
|
||||||
</BlockElementWrapper>
|
</BlockElementWrapper>
|
||||||
</div>
|
</div>
|
||||||
|
Reference in New Issue
Block a user