Skip to content
Snippets Groups Projects
Commit d4e3faa4 authored by Marcos Pieras's avatar Marcos Pieras
Browse files

feat: correct position tooltip and text alignment

parent f84a3994
No related branches found
No related tags found
1 merge request!163feat: redesign tooltips for schema and nodelink
Pipeline #137531 passed
import React from 'react'; import React from 'react';
import { Icon } from '@graphpolaris/shared/lib/components/icon'; import { Icon } from '@graphpolaris/shared/lib/components/icon';
import { Numbers } from '@mui/icons-material'; import { Numbers, Close } from '@mui/icons-material';
import styles from './cardtooltipvis.module.scss'; import styles from './cardtooltipvis.module.scss';
import { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from '@graphpolaris/shared/lib/components/tooltip'; import { Tooltip, TooltipTrigger, TooltipContent, TooltipProvider } from '@graphpolaris/shared/lib/components/tooltip';
import { import {
...@@ -11,6 +11,8 @@ import { ...@@ -11,6 +11,8 @@ import {
CarbonUndefined, CarbonUndefined,
} from '@graphpolaris/shared/lib/assets/carbonIcons/carbonIcons'; } from '@graphpolaris/shared/lib/assets/carbonIcons/carbonIcons';
import { Button } from '@graphpolaris/shared/lib/components/buttons';
export type CardToolTipVisProps = { export type CardToolTipVisProps = {
type: string; type: string;
name: string; name: string;
...@@ -39,12 +41,26 @@ export const CardToolTipVis: React.FC<CardToolTipVisProps> = ({ ...@@ -39,12 +41,26 @@ export const CardToolTipVis: React.FC<CardToolTipVisProps> = ({
numberOfElements, numberOfElements,
}) => { }) => {
const itemsToShow = Object.entries(data).slice(0, maxVisibleItems); const itemsToShow = Object.entries(data).slice(0, maxVisibleItems);
// shadow-md
return ( return (
<div className="border-1 border-sec-200 bg-white w-[12rem] -mx-2 -my-1"> <div className="border-1 border-sec-200 bg-white w-[12rem] -mx-2 -my-1">
<div className="flex m-0 items-center border-b border-sec-200"> <div className="flex m-0 items-center border-b border-sec-200">
<div className="h-9 w-2" style={{ backgroundColor: colorHeader }}></div> <div className="h-9 w-2" style={{ backgroundColor: colorHeader }}></div>
<span className="text-xl ml-2 font-semibold">{name}</span> <div className="flex-1 min-w-0">
<Tooltip>
<TooltipTrigger>
<span className="text-xl ml-2 font-semibold truncate">{name}</span>
</TooltipTrigger>
<TooltipContent side={'top'}>
<span>{name}</span>
</TooltipContent>
</Tooltip>
</div>
{/*
<div className="flex-shrink-0 ml-2">
<Button variantType="secondary" variant="ghost" size="xs" rounded={true} iconComponent={<Close />} onClick={() => {}} />
</div>
*/}
</div> </div>
{type === 'schema' && numberOfElements && ( {type === 'schema' && numberOfElements && (
...@@ -81,7 +97,7 @@ export const CardToolTipVis: React.FC<CardToolTipVisProps> = ({ ...@@ -81,7 +97,7 @@ export const CardToolTipVis: React.FC<CardToolTipVisProps> = ({
<div className="flex flex-row gap-3 items-center"> <div className="flex flex-row gap-3 items-center">
<span className={`font-semibold truncate ${type === 'schema' ? 'w-[90%]' : 'w-[40%]'}`}>{k}</span> <span className={`font-semibold truncate ${type === 'schema' ? 'w-[90%]' : 'w-[40%]'}`}>{k}</span>
<TooltipTrigger asChild> <TooltipTrigger asChild>
<span className="ml-auto text-right truncate w-[60%] min-h-[24px]"> <span className="ml-auto text-right truncate w-[60%] min-h-[24px] flex items-center">
{type === 'schema' ? ( {type === 'schema' ? (
<Icon <Icon
className="ml-auto text-right flex-shrink-0" className="ml-auto text-right flex-shrink-0"
...@@ -113,8 +129,10 @@ export const CardToolTipVis: React.FC<CardToolTipVisProps> = ({ ...@@ -113,8 +129,10 @@ export const CardToolTipVis: React.FC<CardToolTipVisProps> = ({
</span> </span>
</TooltipTrigger> </TooltipTrigger>
<TooltipContent side="right"> <TooltipContent side="right">
<div> <div className="max-w-[12rem]">
<span>{v !== undefined && (typeof v !== 'object' || Array.isArray(v)) && v != '' ? v : 'noData'}</span> <span className="truncate">
{v !== undefined && (typeof v !== 'object' || Array.isArray(v)) && v != '' ? v : 'noData'}
</span>
</div> </div>
</TooltipContent> </TooltipContent>
</div> </div>
......
...@@ -96,7 +96,6 @@ export const Schema = (props: Props) => { ...@@ -96,7 +96,6 @@ export const Schema = (props: Props) => {
const xy = bounds ? { x1: 50, x2: bounds.width - 50, y1: 50, y2: bounds.height - 200 } : { x1: 0, x2: 500, y1: 0, y2: 1000 }; const xy = bounds ? { x1: 50, x2: bounds.width - 50, y1: 50, y2: bounds.height - 200 } : { x1: 0, x2: 500, y1: 0, y2: 1000 };
await layout.current?.layout(expandedSchema, xy); await layout.current?.layout(expandedSchema, xy);
const schemaFlow = schemaGraphology2Reactflow(expandedSchema, settings.connectionType, settings.animatedEdges); const schemaFlow = schemaGraphology2Reactflow(expandedSchema, settings.connectionType, settings.animatedEdges);
console.log('SCHEMA ', schemaFlow.nodes);
const nodesWithRef = schemaFlow.nodes.map((node) => ({ const nodesWithRef = schemaFlow.nodes.map((node) => ({
...node, ...node,
......
import React, { useState, useRef } from 'react'; import React, { useState, useRef, useEffect } from 'react';
import { Handle, Position, NodeProps } from 'reactflow'; import { Handle, Position, NodeProps } from 'reactflow';
import { SchemaReactflowNodeWithFunctions } from '../../../model/reactflow'; import { SchemaReactflowNodeWithFunctions } from '../../../model/reactflow';
import { QueryElementTypes } from '@graphpolaris/shared/lib/querybuilder'; import { QueryElementTypes } from '@graphpolaris/shared/lib/querybuilder';
...@@ -8,8 +8,6 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@graphpolaris/shared/li ...@@ -8,8 +8,6 @@ import { Tooltip, TooltipContent, TooltipTrigger } from '@graphpolaris/shared/li
import { CardToolTipVis, CardToolTipVisProps } from '@graphpolaris/shared/lib/components/CardToolTipVis'; import { CardToolTipVis, CardToolTipVisProps } from '@graphpolaris/shared/lib/components/CardToolTipVis';
export const SchemaEntityPill = React.memo(({ id, selected, data }: NodeProps<SchemaReactflowNodeWithFunctions>) => { export const SchemaEntityPill = React.memo(({ id, selected, data }: NodeProps<SchemaReactflowNodeWithFunctions>) => {
console.log('SchemaEntityPI ', data.reactFlowRef);
const [openPopup, setOpenPopup] = useState(false); const [openPopup, setOpenPopup] = useState(false);
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
/** /**
...@@ -42,31 +40,6 @@ export const SchemaEntityPill = React.memo(({ id, selected, data }: NodeProps<Sc ...@@ -42,31 +40,6 @@ export const SchemaEntityPill = React.memo(({ id, selected, data }: NodeProps<Sc
return ( return (
<> <>
{openPopup && (
<Tooltip key={data.name} open={true} boundaryElement={data.reactFlowRef} showArrow={true}>
<TooltipTrigger x={data.x} y={data.y} />
<TooltipContent side="top">
<div>
<CardToolTipVis
type="schema"
typeOfSchema="node"
name={data.name}
colorHeader="#fb7b04"
numberOfElements={1000}
data={data.attributes.reduce(
(acc, attr) => {
if (attr.name && attr.type) {
acc[attr.name] = attr.type;
}
return acc;
},
{} as Record<string, string>,
)}
/>
</div>
</TooltipContent>
</Tooltip>
)}
<div <div
className="w-fit h-fit" className="w-fit h-fit"
onDragStart={(event) => onDragStart(event)} onDragStart={(event) => onDragStart(event)}
...@@ -78,7 +51,34 @@ export const SchemaEntityPill = React.memo(({ id, selected, data }: NodeProps<Sc ...@@ -78,7 +51,34 @@ export const SchemaEntityPill = React.memo(({ id, selected, data }: NodeProps<Sc
setOpenPopup(!openPopup); setOpenPopup(!openPopup);
}} }}
draggable draggable
ref={ref}
> >
{openPopup && (
<Tooltip key={data.name} open={true} boundaryElement={data.reactFlowRef} showArrow={true}>
<TooltipTrigger />
<TooltipContent side="right">
<div>
<CardToolTipVis
type="schema"
typeOfSchema="node"
name={data.name}
colorHeader="#fb7b04"
numberOfElements={1000}
data={data.attributes.reduce(
(acc, attr) => {
if (attr.name && attr.type) {
acc[attr.name] = attr.type;
}
return acc;
},
{} as Record<string, string>,
)}
/>
</div>
</TooltipContent>
</Tooltip>
)}
<EntityPill <EntityPill
draggable draggable
title={id} title={id}
......
...@@ -49,46 +49,6 @@ export const SchemaRelationPill = React.memo(({ id, selected, data, ...props }: ...@@ -49,46 +49,6 @@ export const SchemaRelationPill = React.memo(({ id, selected, data, ...props }:
}; };
return ( return (
<> <>
{/*
{openPopup && (
<Popup open={openPopup} hAnchor="left" className="-top-8" offset="-20rem">
<SchemaRelationshipPopup data={data} onClose={() => setOpenPopup(false)} />
</Popup>
)}
*/}
{openPopup && (
<Tooltip key={data.name} open={true} boundaryElement={ref} showArrow={true}>
<TooltipTrigger x={data.x} y={data.y} />
<TooltipContent side="top">
<div>
<CardToolTipVis
type="schema"
typeOfSchema="relationship"
name={data.collection}
colorHeader="#0676C1"
numberOfElements={1000}
connectedFrom={data.from}
connectedTo={data.to}
data={
data.attributes.length > 0
? data.attributes.reduce(
(acc, attr) => {
if (attr.name && attr.type) {
acc[attr.name] = attr.type;
}
return acc;
},
{} as Record<string, string>,
)
: {}
}
/>
</div>
</TooltipContent>
</Tooltip>
)}
<div <div
className="w-fit h-fit" className="w-fit h-fit"
onDragStart={(event) => onDragStart(event)} onDragStart={(event) => onDragStart(event)}
...@@ -101,6 +61,37 @@ export const SchemaRelationPill = React.memo(({ id, selected, data, ...props }: ...@@ -101,6 +61,37 @@ export const SchemaRelationPill = React.memo(({ id, selected, data, ...props }:
}} }}
draggable draggable
> >
{openPopup && (
<Tooltip key={data.name} open={true} boundaryElement={ref} showArrow={true}>
<TooltipTrigger />
<TooltipContent side="top">
<div>
<CardToolTipVis
type="schema"
typeOfSchema="relationship"
name={data.collection}
colorHeader="#0676C1"
numberOfElements={1000}
connectedFrom={data.from}
connectedTo={data.to}
data={
data.attributes.length > 0
? data.attributes.reduce(
(acc, attr) => {
if (attr.name && attr.type) {
acc[attr.name] = attr.type;
}
return acc;
},
{} as Record<string, string>,
)
: {}
}
/>
</div>
</TooltipContent>
</Tooltip>
)}
<RelationPill <RelationPill
draggable draggable
title={data.collection} title={data.collection}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment