Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(hubble): support highlighting and hints in query statements #384

Merged
merged 11 commits into from
Dec 15, 2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export const keywords =
'g|V|E|has|open|close|inV|inE|out|outV|outE|label|store|next|addVertex|clazz|' +
'limit|traversal|withBulk|values|schema|except|ifNotExist|addEdge|addVertex|property|io|' +
'filter|loops|readGraph|tree|properties|graph|value|bothE|addV|where|hidden|bothV|without' +
'both|is|path|it|get|from|to|select|otherV|within|inside|outside|withSack';

export const buildinFunctions =
'targetLabel|sourceLabel|indexLabel|indexLabels|edgeLabel|vertexLabel|propertyKey|getPropertyKey|' +
'getVertexLabel|getEdgeLabel|getIndexLabel|getPropertyKeys|getVertexLabels|getEdgeLabels|getIndexLabels|' +
'coin|count|coalesce|createIndex|hasLabel|getLabelId|create|build|append|eliminate|remove|rebuildIndex|' +
'constant|isDirected|desc|inject|profile|simplePath|eq|neq|gt|gte|lt|lte|queryType|indexFields|frequency|' +
'links|type|in|on|by|checkDataType|checkValue|validValue|secondary|drop|search|makeEdgeLabel|cyclicPath|' +
'hasKey|match|sack|aggregate|between|baseType|baseValue|indexType|rebuild|choose|aggregate|iterate|lte|dedup|' +
'identity|groupCount|until|barrier|fold|unfold|schemaId|checkName|makeIndexLabel|makeVertexLabel|makePropertyKey|' +
'sideEffect|hasNext|toList|toSet|cap|option|branch|choose|repeat|emit|order|mean|withComputer|subgraph|' +
'getObjectsAtDepth|hasValue|hasNot|hasId|nullableKey|nullableKeys|sortKeys|link|singleTime|multiTimes|' +
'enableLabelIndex|userdata|checkExist|linkWithLabel|directed|idStrategy|primaryKeys|primaryKey';

export const dataTypes =
'int|numeric|decimal|date|varchar|char|bigint|float|double|bit|binary|text|set|timestamp|toString|primitive|' +
'money|real|number|integer|asInt|asText|dataType|cardinality|asText|asInt|asTimestamp|flatMap|valueMap|' +
'asByte|asBlob|asDouble|asDate|asFloat|asLong|valueSingle|asBoolean|valueList|valueSet|asUuid|null|Infinity|NaN|undefined';

export const baseData = [
...keywords.split('|'),
...buildinFunctions.split('|'),
...dataTypes.split('|')
];
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import { Button, Tooltip, Alert, Dropdown } from 'hubble-ui';
import 'codemirror/lib/codemirror.css';
import 'react-popper-tooltip/dist/styles.css';
import 'codemirror/addon/display/placeholder';
import 'codemirror/mode/sql/sql';
import 'codemirror/addon/hint/show-hint.css';
import 'codemirror/addon/hint/show-hint.js';
import 'codemirror/addon/hint/sql-hint.js';

import { Tooltip as CustomTooltip } from '../../common';
import Favorite from './common/Favorite';
Expand All @@ -41,6 +45,7 @@ import PersonalRank from './algorithm/PersonalRank';
import ArrowIcon from '../../../assets/imgs/ic_arrow_16.svg';
import QuestionMarkIcon from '../../../assets/imgs/ic_question_mark.svg';
import { Algorithm } from '../../../stores/factory/dataAnalyzeStore/algorithmStore';
import { baseData } from './GremlinKeyWords';

export const styles = {
primaryButton: {
Expand All @@ -51,7 +56,6 @@ export const styles = {
margin: '16px 0'
}
};

const codeRegexp = /[A-Za-z0-9]+/;

const QueryAndAlgorithmLibrary: React.FC = observer(() => {
Expand Down Expand Up @@ -191,13 +195,36 @@ export const GremlinQuery: React.FC = observer(() => {
isLoading: dataAnalyzeStore.requestStatus.fetchGraphs === 'pending'
});

const handleShowHint = (cm: any) => {
var cursor = cm.getCursor(),
line = cm.getLine(cursor.line);
var start = cursor.ch,
end = cursor.ch;
while (start && /\w/.test(line.charAt(start - 1))) --start;
while (end < line.length && /\w/.test(line.charAt(end))) ++end;
var word = line.slice(start, end).toLowerCase();
const list = baseData.filter(function (el) {
return el.toLowerCase().indexOf(word) > -1;
});
return {
list: list,
from: { ch: start, line: cursor.line },
to: { ch: end, line: cursor.line }
};
};
useEffect(() => {
codeEditor.current = CodeMirror.fromTextArea(
codeContainer.current as HTMLTextAreaElement,
{
lineNumbers: true,
lineWrapping: true,
placeholder: t('addition.operate.input-query-statement')
mode: { name: 'text/x-mysql' },
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like is mysql's hint config. I think that we should set config as gremlin's hint.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems right catch, thanks for ur reminder, would u also like to improve the FE module?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I'm learning the FE module codes

Copy link
Member

@imbajin imbajin Dec 10, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I'm learning the FE module codes

@lionztt any update for this PR? it should consider be merged and improve it later if no better solution now (due to the apache release next week)

extraKeys: { Ctrl: 'autocomplete' },
placeholder: t('addition.operate.input-query-statement'),
hintOptions: {
completeSingle: false,
hint: handleShowHint
}
}
);

Expand Down