Skip to content

Commit

Permalink
popupdialog associated with an id (query selector)
Browse files Browse the repository at this point in the history
resolves #2293
- also fix a possible bug in chart
  • Loading branch information
Fred Lefévère-Laoide authored and Fred Lefévère-Laoide committed Dec 16, 2024
1 parent 31a6b96 commit 35f9b38
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
4 changes: 2 additions & 2 deletions frontend/taipy-gui/src/components/Taipy/Chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ const updateArrays = (sel: number[][], val: number[], idx: number) => {
return sel;
};

const getDataKey = (columns: Record<string, ColumnDesc>, decimators?: string[]): [string[], string] => {
const backCols = Object.values(columns).map((col) => col.dfid);
const getDataKey = (columns?: Record<string, ColumnDesc>, decimators?: string[]): [string[], string] => {
const backCols = columns ? Object.values(columns).map((col) => col.dfid) : [];
return [backCols, backCols.join("-") + (decimators ? `--${decimators.join("")}` : "")];
};

Expand Down
47 changes: 42 additions & 5 deletions frontend/taipy-gui/src/components/Taipy/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import DialogTitle from "@mui/material/DialogTitle";
import MuiDialog from "@mui/material/Dialog";
import DialogActions from "@mui/material/DialogActions";
import DialogContent from "@mui/material/DialogContent";
import Tooltip from "@mui/material/Tooltip";
import IconButton from "@mui/material/IconButton";
import CloseIcon from "@mui/icons-material/Close";
import Popover, { PopoverOrigin } from "@mui/material/Popover";
import Tooltip from "@mui/material/Tooltip";
import { SxProps, Theme } from "@mui/system";
import CloseIcon from "@mui/icons-material/Close";

import { createSendActionNameAction } from "../../context/taipyReducers";
import TaipyRendered from "../pages/TaipyRendered";
Expand All @@ -41,6 +42,9 @@ interface DialogProps extends TaipyActiveProps {
height?: string | number;
width?: string | number;
localAction?: (idx: number) => void;
refId?: string;
defaultRefId?: string;
popup?: boolean;
}

const closeSx: SxProps<Theme> = {
Expand All @@ -51,6 +55,22 @@ const closeSx: SxProps<Theme> = {
};
const titleSx = { m: 0, p: 2, display: "flex", paddingRight: "0.1em" };

const virtualElt = {
nodeType: 1,
getBoundingClientRect: () =>
new DOMRect(
document.body.offsetWidth - document.body.offsetLeft,
document.body.offsetHeight - document.body.offsetTop,
0,
0
),
} as Element;

const popoverAnchor: PopoverOrigin = {
vertical: 'center',
horizontal: 'center',
};

const Dialog = (props: DialogProps) => {
const {
id,
Expand All @@ -64,13 +84,15 @@ const Dialog = (props: DialogProps) => {
partial,
width,
height,
popup = false,
} = props;
const dispatch = useDispatch();
const module = useModule();

const className = useClassNames(props.libClassName, props.dynamicClassName, props.className);
const active = useDynamicProperty(props.active, props.defaultActive, true);
const hover = useDynamicProperty(props.hoverText, props.defaultHoverText, undefined);
const refId = useDynamicProperty(props.refId, props.defaultRefId, undefined);

const handleAction = useCallback(
(evt: MouseEvent<HTMLElement>) => {
Expand Down Expand Up @@ -110,7 +132,22 @@ const Dialog = (props: DialogProps) => {
return {};
}, [width, height]);

return (
const getAnchorEl = useCallback(() => (refId && document.querySelector(refId)) || virtualElt, [refId]);

return popup ? (
<Popover
id={id}
onClose={handleAction}
open={open === undefined ? defaultOpen === "true" || defaultOpen === true : !!open}
className={`${className} ${getComponentClassName(props.children)}`}
sx={paperProps.sx}
anchorEl={getAnchorEl}
anchorOrigin={popoverAnchor}
>
{page ? <TaipyRendered path={"/" + page} partial={partial} fromBlock={true} /> : null}
{props.children}
</Popover>
) : (
<MuiDialog
id={id}
onClose={handleAction}
Expand All @@ -133,9 +170,9 @@ const Dialog = (props: DialogProps) => {
</DialogContent>
{labels.length ? (
<DialogActions>
{labels.map((l, i) => (
{labels.map((label, i) => (
<Button onClick={handleAction} disabled={!active} key={"label" + i} data-idx={i}>
{l}
{label}
</Button>
))}
</DialogActions>
Expand Down
2 changes: 2 additions & 0 deletions taipy/gui/_renderers/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ class _Factory:
("width", PropertyType.string_or_number),
("height", PropertyType.string_or_number),
("hover_text", PropertyType.dynamic_string),
("ref_id", PropertyType.dynamic_string),
("popup", PropertyType.boolean),
]
)
._set_propagate(),
Expand Down
3 changes: 2 additions & 1 deletion taipy/gui/viselements.json
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,8 @@
"name": "height",
"type": "Union[str,int,float]",
"doc": "The height of the dialog, in CSS units."
}
},
{"name": "ref_id", "type": "dynamic(str)", "doc": "TODO an id or a query selector that allows to identify an HTML component that would be tha anchor for the dialog."}

Check failure on line 2017 in taipy/gui/viselements.json

View workflow job for this annotation

GitHub Actions / Check for spelling errors

tha ==> than, that, the
]
}
],
Expand Down

0 comments on commit 35f9b38

Please sign in to comment.