Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface PPLSuggestion {
input: string;
suggestion: string;
item: string;
currCommand: string;
}

interface CreatePPLSuggestionsPluginProps {
Expand Down Expand Up @@ -75,6 +76,7 @@ const fillSuggestions = (str: string, word: string, items: any) => {
input: str,
suggestion: filteredList[i].label.substring(word.length),
itemName: filteredList[i].label,
currCommand: str.substring(str.lastIndexOf("|")),
});
}
return suggestionList;
Expand Down Expand Up @@ -115,7 +117,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
splittedModel[splittedModel.length - 2] === 'source' ||
splittedModel[splittedModel.length - 2] === 'index'
) {
return [{ label: str + '=', input: str, suggestion: '=' }].filter(
return [{ label: str + '=', input: str, suggestion: '=', currCommand: str.substring(str.lastIndexOf("|")) }].filter(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if "currCommand" is same throughout the "getSuggestions" function. Can we make it a const at the beginning of the function and remove the repeated str.substring(str.lastIndexOf("|"))

({ label }) => label.startsWith(prefix) && prefix !== label
);
} else if (
Expand All @@ -126,7 +128,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
} else if (indexList.includes(splittedModel[splittedModel.length - 2])) {
currIndex = splittedModel[splittedModel.length - 2];
getFields(dslService);
return [{ label: str + '|', input: str, suggestion: '|' }].filter(
return [{ label: str + '|', input: str, suggestion: '|', currCommand: str.substring(str.lastIndexOf("|")) }].filter(
({ label }) => label.startsWith(prefix) && prefix !== label
);
} else if (splittedModel[splittedModel.length - 2] === 'search') {
Expand All @@ -146,13 +148,14 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
input: str.substring(0, str.length - 1),
suggestion: numberFields[i].label.substring(prefix.length) + ')',
itemName: numberFields[i].label,
currCommand: str.substring(str.lastIndexOf("|")),
});
}
nextStats = nextStats - 1;
return fullSuggestions;
}
} else if (nextStats === splittedModel.length - 2) {
return [{ label: str + 'by', input: str, suggestion: 'by' }].filter(
return [{ label: str + 'by', input: str, suggestion: 'by', currCommand: str.substring(str.lastIndexOf("|")) }].filter(
({ label }) => label.startsWith(prefix) && prefix !== label
);
} else if (nextStats === splittedModel.length - 3) {
Expand All @@ -172,6 +175,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
input: str,
suggestion: '=',
item: '=',
currCommand: str.substring(str.lastIndexOf("|")),
});
currField = splittedModel[splittedModel.length - 2];
currFieldType = fieldsFromBackend.find((field) => field.label === currField)?.type;
Expand All @@ -183,7 +187,7 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
await getDataValues(currIndex, currField, currFieldType, dslService)
);
} else if (nextWhere === splittedModel.length - 3 || nextStats === splittedModel.length - 4) {
return [{ label: str + '|', input: str, suggestion: '|' }].filter(
return [{ label: str + '|', input: str, suggestion: '|', currCommand: str.substring(str.lastIndexOf("|")) }].filter(
({ label }) => label.startsWith(prefix) && prefix !== label
);
} else if (inFieldsCommaLoop) {
Expand All @@ -193,8 +197,9 @@ const getSuggestions = async (str: string, dslService: DSLService) => {
input: str.substring(0, str.length - 1),
suggestion: ',',
item: ',',
currCommand: str.substring(str.lastIndexOf("|")),
},
{ label: str + '|', input: str, suggestion: '|', item: ',' },
{ label: str + '|', input: str, suggestion: '|', item: ',', currCommand: str.substring(str.lastIndexOf("|")) },
].filter(({ label }) => label.startsWith(prefix) && prefix !== label);
}
return [];
Expand Down Expand Up @@ -270,6 +275,8 @@ export function createPPLSuggestionsPlugin(
onStateChange: ({ state }) => {
if (options.query !== state.query) {
options.handleQueryChange(state.query, currIndex);
} else {
console.log("Doesn't handle query change")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Minor: Do we need logging here?

@mengweieric mengweieric Oct 25, 2021

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nvm, I saw you've removed it.

}
},
onSubmit: () => {
Expand All @@ -296,7 +303,7 @@ export function createPPLSuggestionsPlugin(
return createElement('div', {
dangerouslySetInnerHTML: {
__html: `<div>
${item.input}<span class=styling>${item.suggestion}</span>
${item.currCommand}<span class=styling>${item.suggestion}</span>
</div>`,
},
});
Expand Down