jomarko commented on code in PR #3985:
URL:
https://github.com/apache/incubator-kie-tools/pull/3985#discussion_r3880834043
##########
packages/dmn-editor/src/diagram/Palette.tsx:
##########
@@ -107,6 +135,130 @@ export function Palette({ pulse }: { pulse: boolean }) {
const { maxHeight } = useInViewSelect(dmnEditorRootElementRef,
nodesPalletePopoverRef);
+ const panelRef = useRef<HTMLDivElement>(null);
+ const paletteRef = useRef<HTMLDivElement>(null);
+ const submenuRef = useRef<HTMLDivElement>(null);
+ const iconMeasureRef = useRef<HTMLDivElement>(null);
+ const ellipsisButtonRef = useRef<HTMLButtonElement>(null);
+
+ const primaryIcons = useMemo(
+ () => [
+ { nodeType: NODE_TYPES.inputData as NodeType, title:
i18n.nodes.inputData, className: "input-data" },
+ { nodeType: NODE_TYPES.decision as NodeType, title: i18n.nodes.decision,
className: "decision" },
+ { nodeType: NODE_TYPES.bkm as NodeType, title:
i18n.nodes.businessKnowledgeModel, className: "bkm" },
+ {
+ nodeType: NODE_TYPES.knowledgeSource as NodeType,
+ title: i18n.nodes.knowledgeSource,
+ className: "knowledge-source",
+ },
+ {
+ nodeType: NODE_TYPES.decisionService as NodeType,
+ title: i18n.nodes.decisionService,
+ className: "decision-service",
+ },
+ ],
+ [i18n]
+ );
+
+ const totalIcons = primaryIcons.length;
+ const [visibleIconCount, setVisibleIconCount] = useState<number>(totalIcons);
+ const [submenuOpen, setSubmenuOpen] = useState(false);
+
+ const showEllipsis = visibleIconCount < totalIcons;
+
+ const iconHeightRef = useRef(48);
+ const ellipsisHeightRef = useRef(40);
+
+ useEffect(() => {
+ if (iconMeasureRef.current) {
+ const rect = iconMeasureRef.current.getBoundingClientRect();
+ if (rect.height) {
+ iconHeightRef.current = rect.height;
+ }
+ }
+ if (ellipsisButtonRef.current) {
+ const rect = ellipsisButtonRef.current.getBoundingClientRect();
+ if (rect.height) {
+ ellipsisHeightRef.current = rect.height;
+ }
+ }
+ }, [visibleIconCount]);
+
+ useEffect(() => {
+ let animationFrameId: number | null = null;
+ let lastCount = totalIcons;
+
+ const updateVisibleIcons = () => {
+ if (animationFrameId !== null) cancelAnimationFrame(animationFrameId);
+
+ animationFrameId = requestAnimationFrame(() => {
+ if (!panelRef.current || !paletteRef.current) {
+ if (lastCount !== totalIcons) {
+ setVisibleIconCount(totalIcons);
+ lastCount = totalIcons;
+ }
+ return;
+ }
+
+ const newCount = calculateVisibleIconCount(
+ panelRef.current.getBoundingClientRect(),
+ paletteRef.current.getBoundingClientRect(),
+ window.innerHeight,
+ iconHeightRef.current,
+ ellipsisHeightRef.current,
+ totalIcons
+ );
+
+ if (newCount !== lastCount) {
+ setVisibleIconCount(newCount);
+ lastCount = newCount;
+ }
+ });
+ };
+
+ updateVisibleIcons();
+ window.addEventListener("resize", updateVisibleIcons);
+
+ return () => {
+ window.removeEventListener("resize", updateVisibleIcons);
+ if (animationFrameId !== null) cancelAnimationFrame(animationFrameId);
+ };
+ }, [totalIcons]);
+
+ const renderPaletteIcon = useCallback(
Review Comment:
Why do not need we here `TextAnnotation`, `Group`, `Drg Nodes`, `External
Nodes` ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]