Skip to content

Commit

Permalink
fix: fix bugs (#250)
Browse files Browse the repository at this point in the history
  • Loading branch information
hetao92 authored Jul 6, 2022
1 parent 787466c commit d90c972
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 44 deletions.
2 changes: 1 addition & 1 deletion app/pages/Import/TaskList/TaskItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
2 changes: 1 addition & 1 deletion app/pages/Import/TaskList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
68 changes: 38 additions & 30 deletions app/stores/twoGraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@ class TwoGraph {
setTransform = (transform: Partial<ITransform>) =>
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;
Expand All @@ -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);
Expand All @@ -52,6 +87,7 @@ class TwoGraph {
});
Graph.linkVisibility(() => false);
})
.d3AlphaDecay(0.05)
.onZoomEnd(() => Graph.linkVisibility(() => true))
.minZoom(0.1)
.nodeVal((node) => {
Expand All @@ -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) => {
Expand Down Expand Up @@ -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({
Expand Down
36 changes: 24 additions & 12 deletions server/api/studio/internal/service/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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 {
Expand Down

0 comments on commit d90c972

Please sign in to comment.