Skip to content
Snippets Groups Projects
Unverified Commit e4eb3f99 authored by Ariya Hidayat's avatar Ariya Hidayat Committed by GitHub
Browse files

Custom expression editor: don't suggest a unique matching function (#20485)

parent db531274
No related merge requests found
......@@ -151,11 +151,22 @@ export function suggest({
suggestions = suggestions.filter(suggestion => suggestion.range);
// deduplicate suggestions and sort by type then name
return {
suggestions: _.chain(suggestions)
.uniq(suggestion => suggestion.text)
.sortBy("text")
.sortBy("order")
.value(),
};
suggestions = _.chain(suggestions)
.uniq(suggestion => suggestion.text)
.sortBy("text")
.sortBy("order")
.value();
// the only suggested function equals the prefix match?
if (suggestions.length === 1 && matchPrefix) {
const { icon } = suggestions[0];
if (icon === "function") {
const helpText = getHelpText(getMBQLName(matchPrefix));
if (helpText) {
return { helpText };
}
}
}
return { suggestions };
}
......@@ -161,6 +161,16 @@ describe("metabase/lib/expression/suggest", () => {
expect(args).toHaveLength(3);
});
it("should provide help text for the unique match", () => {
const { structure, args } = helpText({
source: "lower", // doesn't need to be "lower(" since it's a unique match
query: ORDERS.query(),
startRule: "expression",
});
expect(structure).toEqual("lower(text)");
expect(args).toHaveLength(1);
});
it("should provide help text after first argument if there's only one argument", () => {
expect(
helpText({
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment