diff --git a/app/assets/modules/Import/index.less b/app/assets/modules/Import/index.less index c0ce1e85..bf590c49 100644 --- a/app/assets/modules/Import/index.less +++ b/app/assets/modules/Import/index.less @@ -55,7 +55,7 @@ .import-log { height: 100%; overflow: auto; - padding: 10px 20px 20px; + padding: 10px 20px 120px; font-size: 18px; text-align: left; background: #333; diff --git a/app/assets/store/models/explore.ts b/app/assets/store/models/explore.ts index 18e5bfb7..0e66202c 100644 --- a/app/assets/store/models/explore.ts +++ b/app/assets/store/models/explore.ts @@ -26,17 +26,16 @@ import { parsePathToGraph, setLink } from '#assets/utils/parseData'; function getBidrectVertexIds(data) { const { tables } = data; - // go from nqgl return [{*._dst: id}] - const ids = _.uniq( - tables - .map(row => { - return Object.values(row); - }) - .flat(), - ) - .filter(id => id !== 0) - .map(id => String(id)); - return ids; + // go from yield edge nqgl return [{_edgesParsedList: srcID: xx, dstID: xx}] + const vertexIds: string[] = []; + tables.forEach(item => { + item._edgesParsedList.forEach(edge => { + const { dstID, srcID } = edge; + vertexIds.push(String(dstID)); + vertexIds.push(String(srcID)); + }); + }); + return _.uniq(vertexIds); } interface IExportEdge { @@ -95,7 +94,7 @@ function getGroup(tags) { return 't-' + tags.sort().join('-'); } -function getTagData(nodes, expand) { +function getTagData(nodes, expand?) { const data = nodes.map(node => { const { vid, tags, properties } = node; const group = getGroup(tags); @@ -352,9 +351,21 @@ export const explore = createModel({ quantityLimit: number | null; }) { const { code, data, message } = await fetchVertexPropsWithIndex(payload); - if (code === 0 && data.tables.length !== 0) { - const ids = data.tables && data.tables.map(i => i.VertexID || i._vid); - this.asyncImportNodes({ ids }); + if (code === 0) { + if (data.tables.length === 0) { + message.info(intl.get('common.noData')); + } else { + const vertexList = data.tables.map(i => i._verticesParsedList).flat(); + const vertexes = vertexList.map(({ vid, tags, properties }) => ({ + vid: vid || '', + tags: tags || [], + properties: properties || {}, + })); + this.addNodesAndEdges({ + vertexes: getTagData(vertexes), + edges: [], + }); + } } else { throw new Error(message); } @@ -437,19 +448,9 @@ export const explore = createModel({ const { nebula: { spaceVidType }, } = rootState; - // If these ids have hanging edges, get the src/dst id of these input ids on the hanging edges - let bidirectRes = await fetchBidirectVertexes({ ids, spaceVidType }); - let _ids = - bidirectRes.code === 0 ? getBidrectVertexIds(bidirectRes.data) : []; - if (_ids.length > 0) { - // Batch query cannot accurately know which input ids have hanging edges - // So use the result ids to query the corresponding ids on all edges - // these ids must include vertex id of the haning edge - bidirectRes = await fetchBidirectVertexes({ ids: _ids, spaceVidType }); - _ids = - bidirectRes.code === 0 ? getBidrectVertexIds(bidirectRes.data) : []; - } - return _ids; + const res = await fetchBidirectVertexes({ ids, spaceVidType }); + const vertexIds = res.code === 0 ? getBidrectVertexIds(res.data) : []; + return vertexIds.filter(id => ids.includes(id)); }, async asyncGetExploreEdge(edgeList: IExportEdge[], rootState) { diff --git a/app/assets/utils/fetch.ts b/app/assets/utils/fetch.ts index ce5b16a3..7b789c51 100644 --- a/app/assets/utils/fetch.ts +++ b/app/assets/utils/fetch.ts @@ -23,6 +23,8 @@ export async function fetchEdgeProps(payload: { gql += `,${edgeType}.${edgeField}`; } }); + } else { + gql += ' YIELD edge as `_edge`'; } const { data } = (await service.execNGQL({ @@ -73,7 +75,7 @@ export async function fetchBidirectVertexes(payload: { }) { const { ids, spaceVidType } = payload; const _ids = ids.map(id => handleVidStringName(id, spaceVidType)).join(', '); - const gql = `GO FROM ${_ids} OVER * BIDIRECT`; + const gql = `GO FROM ${_ids} OVER * BIDIRECT yield edge as \`_edge\``; const { code, data, message } = (await service.execNGQL({ gql, })) as any; diff --git a/app/assets/utils/gql.ts b/app/assets/utils/gql.ts index 30fcdcc1..c664fcfa 100644 --- a/app/assets/utils/gql.ts +++ b/app/assets/utils/gql.ts @@ -94,7 +94,10 @@ export const getExploreGQLWithIndex = (params: { const gql = `LOOKUP ON ${handleKeyword(tag)} ${wheres ? `\nWHERE ${wheres}` : ''} - ` + `| LIMIT ${quantityLimit ? quantityLimit : 100}`; + ` + + ` yield vertex as \`_vertex\` | LIMIT ${ + quantityLimit ? quantityLimit : 100 + }`; return gql; }; @@ -283,6 +286,7 @@ export const getPathGQL = (params: { `FIND ${type} PATH FROM ${_srcIds} TO ${_dstIds} over ${_relation}` + `${direction ? ` ${direction}` : ''}` + `${stepLimit ? ' UPTO ' + stepLimit + ' STEPS' : ''}` + + ' yield path as `_path`' + `${quantityLimit ? ' | LIMIT ' + quantityLimit : ''}`; return gql;