Skip to content

Commit

Permalink
refactor(ui): optimize some experience issues again (#444)
Browse files Browse the repository at this point in the history
## What type of PR is this?

/kind refactor

## What this PR does / why we need it:

optimize some experience issues again

Co-authored-by: hai-tian <[email protected]>
  • Loading branch information
elliotxx and hai-tian authored May 20, 2024
1 parent f019731 commit cda4664
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 20 deletions.
2 changes: 1 addition & 1 deletion ui/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Karpor</title>
<title>Karpor - A Modern Kubernetes Explorer</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
10 changes: 10 additions & 0 deletions ui/src/components/layout/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
QuestionCircleOutlined,
SearchOutlined,
CaretDownOutlined,
GithubOutlined,
} from '@ant-design/icons'
import type { MenuProps } from 'antd'
import { Outlet, useLocation, useNavigate } from 'react-router-dom'
Expand Down Expand Up @@ -194,6 +195,15 @@ const LayoutPage = () => {
target="_blank"
href="https://github.com/KusionStack/karpor"
rel="noreferrer"
>
<GithubOutlined style={{ color: '#646566' }} />
</a>
</div>
<div className={styles.help}>
<a
target="_blank"
href="https://kusionstack.io/karpor"
rel="noreferrer"
>
<QuestionCircleOutlined style={{ color: '#646566' }} />
</a>
Expand Down
36 changes: 19 additions & 17 deletions ui/src/pages/insightDetail/components/topologyMap/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { memo, useLayoutEffect, useRef, useState } from 'react'
import { Select } from 'antd'
import ReactDOM from 'react-dom'
import G6 from '@antv/g6'
import type { IAbstractGraph, IG6GraphEvent } from '@antv/g6'
import type { Point } from '@antv/g-base/lib/types'
Expand All @@ -12,7 +11,7 @@ import {
createNodeFromReact,
appenAutoShapeListener,
Image,
Text,
// Text,
} from '@antv/g6-react-node'
import Loading from '@/components/loading'
import transferPng from '@/assets/transfer.png'
Expand Down Expand Up @@ -62,8 +61,8 @@ const OverviewTooltip = memo((props: propsType) => {
background: '#fff',
border: '1px solid #f5f5f5',
position: 'absolute',
top: props?.hiddenButtonInfo?.y - 20 || -500,
left: props?.hiddenButtonInfo?.x + (props?.itemWidth || 100) / 2 || -500,
top: props?.hiddenButtonInfo?.y - 60 || -500,
left: props?.hiddenButtonInfo?.x || -500,
zIndex: 5,
padding: 10,
borderRadius: 8,
Expand Down Expand Up @@ -163,6 +162,7 @@ const TopologyMap = ({
}

function handleClickNode(cfg) {
setTooltipopen(false)
onTopologyNodeClick(cfg)
}

Expand Down Expand Up @@ -214,7 +214,11 @@ const TopologyMap = ({
onClick={() => handleClickNode(cfg)}
onMouseOver={evt => handleMouseEnter(evt)}
onMouseLeave={evt => handleMouseLeave(evt)}
width={getTextSize(getName(cfg), 190, 16)}
width={getTextSize(
getName(cfg),
type !== 'cluster' ? 240 : 190,
16,
)}
customStyle={{
fill: '#000',
fontSize: 16,
Expand All @@ -224,16 +228,16 @@ const TopologyMap = ({
{displayName}
</NodeLabel>
{typeof cfg?.data?.count === 'number' && (
<Text
<NodeLabel
onClick={event => handleMouseEnter(event)}
style={{
customStyle={{
fill: '#000',
fontSize: '16px',
margin: [10, 0],
fontSize: 16,
margin: [5, 0],
}}
>
{`${cfg?.data?.count}`}
</Text>
</NodeLabel>
)}
</Rect>
{type === 'cluster' && (
Expand Down Expand Up @@ -309,20 +313,19 @@ const TopologyMap = ({
)

useLayoutEffect(() => {
setTooltipopen(false)
if (topologyData) {
;(async () => {
const container = document.getElementById('overviewContainer')
const width = container?.scrollWidth || 800
const height = container?.scrollHeight || 400
const toolbar = new G6.ToolBar()
if (!graph) {
if (!graph && container) {
// eslint-disable-next-line
graphRef.current = graph = new G6.Graph({
// eslint-disable-next-line react/no-find-dom-node
container: ReactDOM.findDOMNode(ref.current) as HTMLElement,
container,
width,
height,
renderer: 'svg',
fitCenter: true,
fitView: true,
fitViewPadding: 20,
Expand All @@ -340,9 +343,8 @@ const TopologyMap = ({
},
defaultNode: {
type: 'card-node',
size: [250, 50],
size: [240, 45],
},

defaultEdge: {
type: 'polyline',
sourceAnchor: 1,
Expand Down Expand Up @@ -417,7 +419,7 @@ const TopologyMap = ({
!container.scrollHeight
)
return
graph.changeSize(container.scrollWidth, container.scrollHeight)
graph.changeSize(container?.scrollWidth, container?.scrollHeight)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Text } from '@antv/g6-react-node'
import React from 'react'

const NodeLabel = (NodeLabelProps: {
width: number
width?: number
color?: string
children?: string
onClick?: (evt) => void
Expand All @@ -29,7 +29,6 @@ const NodeLabel = (NodeLabelProps: {
width,
fill: color,
cursor: disabled ? 'not-allowed' : 'pointer',
fontSize: '16px',
...customStyle,
}}
onClick={onClick}
Expand Down

0 comments on commit cda4664

Please sign in to comment.