From d90c97255be149a57d6155e39b6127b081fc00fb Mon Sep 17 00:00:00 2001 From: Nut He <18328704+hetao92@users.noreply.github.com> Date: Wed, 6 Jul 2022 09:46:50 +0800 Subject: [PATCH] fix: fix bugs (#250) --- app/pages/Import/TaskList/TaskItem/index.tsx | 2 +- app/pages/Import/TaskList/index.tsx | 2 +- app/stores/twoGraph.ts | 68 +++++++++++-------- server/api/studio/internal/service/gateway.go | 36 ++++++---- 4 files changed, 64 insertions(+), 44 deletions(-) diff --git a/app/pages/Import/TaskList/TaskItem/index.tsx b/app/pages/Import/TaskList/TaskItem/index.tsx index 6baadf22..a8d41101 100644 --- a/app/pages/Import/TaskList/TaskItem/index.tsx +++ b/app/pages/Import/TaskList/TaskItem/index.tsx @@ -36,7 +36,7 @@ const COLOR_MAP = { to: '#2F80ED', }, }; -const loadingStatus = [ITaskStatus.StatusPending, ITaskStatus.StatusProcessing] +const loadingStatus = [ITaskStatus.StatusPending, ITaskStatus.StatusProcessing]; const TaskItem = (props: IProps) => { const { data: { diff --git a/app/pages/Import/TaskList/index.tsx b/app/pages/Import/TaskList/index.tsx index 10d1ae39..69572df5 100644 --- a/app/pages/Import/TaskList/index.tsx +++ b/app/pages/Import/TaskList/index.tsx @@ -78,7 +78,7 @@ const TaskList = (props: IProps) => { }; }, []); useEffect(() => { - const loadingStatus = [ITaskStatus.StatusProcessing, ITaskStatus.StatusPending] + const loadingStatus = [ITaskStatus.StatusProcessing, ITaskStatus.StatusPending]; const needRefresh = taskList.filter(item => loadingStatus.includes(item.status)).length > 0; if(logDimension.id !== undefined && loadingStatus.includes(logDimension.status)) { const status = taskList.filter(item => item.id === logDimension.id)[0].status; diff --git a/app/stores/twoGraph.ts b/app/stores/twoGraph.ts index dc5c5fca..504bd491 100644 --- a/app/stores/twoGraph.ts +++ b/app/stores/twoGraph.ts @@ -36,6 +36,40 @@ class TwoGraph { setTransform = (transform: Partial) => Object.keys(transform).forEach((key) => (this.transform[key] = transform[key])); + renderNode = (node, ctx: CanvasRenderingContext2D) => { + const { graph } = this; + const color = graph.filterExclusionIds[node.id] ? '#efefef' : node.color; + const nodeSize = node.nodeArea ? Math.sqrt(node.nodeArea) : NODE_SIZE; + ctx.fillStyle = color; + ctx.strokeStyle = undefined; + ctx.beginPath(); + ctx.arc(node.x!, node.y!, nodeSize, 0, 2 * Math.PI, false); + ctx.fill(); + if (graph.nodesSelected.has(node) || graph.nodeHovering === node) { + ctx.lineWidth = 4; + ctx.strokeStyle = !graph.nodesSelected.has(node) ? '#fbe969' : 'rgba(0, 0, 0, 0.5)'; + ctx.shadowColor = !graph.nodesSelected.has(node) ? '#1890ff' : 'rgba(0, 0, 0, 0.5)'; + ctx.shadowBlur = 10; + ctx.stroke(); + ctx.shadowBlur = 0; + ctx.shadowColor = null; + } + + this.renderNodeLabel(node, ctx, nodeSize); + }; + + renderNodeLabel = (node, ctx: CanvasRenderingContext2D, nodeSize) => { + // renderlabel + const label = node.id; + if (label && this.transform.k > 0.9) { + ctx.strokeStyle = null; + ctx.textAlign = 'center'; + ctx.textBaseline = 'middle'; + ctx.font = `${FONT_SIZE}px Sans-Serif`; + ctx.fillText(label, node.x, node.y + nodeSize + FONT_SIZE); + } + }; + // init ForceGraph instance ,it will be called only once init = () => { const { graph } = this; @@ -44,6 +78,7 @@ class TwoGraph { Graph.d3Force('link')!.distance((d) => { return d.lineLength || LINE_LENGTH; }); + Graph.d3Force('charge')!.strength(-150); Graph.width(1100).height(400); Graph.onZoom((v) => { this.setTransform(v); @@ -52,6 +87,7 @@ class TwoGraph { }); Graph.linkVisibility(() => false); }) + .d3AlphaDecay(0.05) .onZoomEnd(() => Graph.linkVisibility(() => true)) .minZoom(0.1) .nodeVal((node) => { @@ -63,7 +99,7 @@ class TwoGraph { return this.transform.k > 1 ? 6 : 0; }) .linkDirectionalArrowRelPos(1) - .cooldownTicks(120) + .cooldownTicks(90) .onEngineStop(() => { // fix every node's pos graph.nodes.forEach((item) => { @@ -96,35 +132,7 @@ class TwoGraph { // .autoPauseRedraw(false) .nodeCanvasObjectMode(() => 'replace') .nodeCanvasObject((node: any, ctx) => { - const color = graph.filterExclusionIds[node.id] ? '#efefef' : node.color; - const nodeSize = node.nodeArea ? Math.sqrt(node.nodeArea) : NODE_SIZE; - ctx.fillStyle = color; - ctx.strokeStyle = undefined; - ctx.beginPath(); - ctx.arc(node.x!, node.y!, nodeSize, 0, 2 * Math.PI, false); - ctx.fill(); - if (graph.nodesSelected.has(node) || graph.nodeHovering === node) { - ctx.lineWidth = 4; - ctx.strokeStyle = !graph.nodesSelected.has(node) ? '#fbe969' : 'rgba(0, 0, 0, 0.5)'; - ctx.shadowColor = !graph.nodesSelected.has(node) ? '#1890ff' : 'rgba(0, 0, 0, 0.5)'; - ctx.shadowBlur = 10; - ctx.stroke(); - ctx.shadowBlur = 0; - ctx.shadowColor = null; - } - // renderlabel - const label = node.id; - if (label && this.transform.k > 0.9) { - ctx.strokeStyle = null; - ctx.textAlign = 'center'; - ctx.textBaseline = 'middle'; - ctx.font = `${FONT_SIZE}px Sans-Serif`; - const labels = label.split('\r\n'); - labels.forEach((each, index) => { - // calculate label position - ctx.fillText(each, node.x, node.y + nodeSize + FONT_SIZE + index * (FONT_SIZE + 6)); - }); - } + this.renderNode(node, ctx); }) .onNodeClick((node, event) => { graph.setPointer({ diff --git a/server/api/studio/internal/service/gateway.go b/server/api/studio/internal/service/gateway.go index 20355ff4..c1edee8d 100644 --- a/server/api/studio/internal/service/gateway.go +++ b/server/api/studio/internal/service/gateway.go @@ -82,23 +82,31 @@ func (s *gatewayService) DisconnectDB() (*types.AnyResponse, error) { return &types.AnyResponse{Data: response.StandardHandlerDataFieldAny(nil)}, nil } +func isSessionError(err error) bool { + subErrMsgStr := []string{ + "session expired", + "connection refused", + "broken pipe", + "an existing connection was forcibly closed", + "Token is expired", + "Session not existed", + } + for _, subErrMsg := range subErrMsgStr { + if strings.Contains(err.Error(), subErrMsg) { + return true + } + } + return false +} + func (s *gatewayService) ExecNGQL(request *types.ExecNGQLParams) (*types.AnyResponse, error) { authData := s.ctx.Value(auth.CtxKeyUserInfo{}).(*auth.AuthData) execute, _, err := dao.Execute(authData.NSID, request.Gql, request.ParamList) if err != nil { - // TODO: common middleware should handle this - subErrMsgStr := []string{ - "session expired", - "connection refused", - "broken pipe", - "an existing connection was forcibly closed", - "Token is expired", - } - for _, subErrMsg := range subErrMsgStr { - if strings.Contains(err.Error(), subErrMsg) { - return nil, ecode.WithSessionMessage(err) - } + isSErr := isSessionError(err) + if isSErr { + return nil, ecode.WithSessionMessage(err) } return nil, ecode.WithErrorMessage(ecode.ErrInternalServer, err, "execute failed") } @@ -118,6 +126,10 @@ func (s *gatewayService) BatchExecNGQL(request *types.BatchExecNGQLParams) (*typ execute, _, err := dao.Execute(NSID, gql, make([]string, 0)) gqlRes := map[string]interface{}{"gql": gql, "data": execute} if err != nil { + isSErr := isSessionError(err) + if isSErr { + return nil, ecode.WithSessionMessage(err) + } gqlRes["message"] = err.Error() gqlRes["code"] = base.Error } else {