betodealmeida commented on a change in pull request #12113:
URL: 
https://github.com/apache/incubator-superset/pull/12113#discussion_r545969644



##########
File path: 
superset-frontend/src/components/ErrorMessage/ParameterErrorMessage.tsx
##########
@@ -32,17 +33,76 @@ interface ParameterErrorExtra {
   }[];
 }
 
-const triggerMessage = t('This may be triggered by:');
+const maxDistanceForSuggestion = 2;
+const findMatches = (
+  undefined_parameters: string[],
+  template_keys: string[],
+) => {
+  const matches: { [undefined_parameter: string]: string[] } = {};
+  undefined_parameters.forEach(undefined_parameter => {
+    template_keys.forEach(template_key => {
+      if (
+        levenshtein(undefined_parameter, template_key) <=
+        maxDistanceForSuggestion
+      ) {
+        if (!matches[undefined_parameter]) {
+          matches[undefined_parameter] = [];
+        }
+        matches[undefined_parameter].push(`"${template_key}"`);
+      }
+    });
+  });
+  return matches;
+};
 
 function ParameterErrorMessage({
   error,
   source = 'sqllab',
 }: ErrorMessageComponentProps<ParameterErrorExtra>) {
   const { extra, level, message } = error;
 
+  const triggerMessage = tn(
+    'This was triggered by:',
+    'This may be triggered by:',
+    extra.issue_codes.length,
+  );
+
+  const matches = findMatches(
+    extra.undefined_parameters || [],
+    Object.keys(extra.template_parameters || []),
+  );
+
   const body = (
     <>
       <p>
+        {matches && (
+          <>
+            <p>{t('Did you mean:')}</p>
+            <ul>
+              {Object.entries(matches).map(
+                ([undefined_parameter, template_keys]) => (
+                  <li>
+                    {tn(
+                      '%(suggestion)s instead of "%(undefined)s?"',

Review comment:
       In this case the `tn` function depends on the runtime to determine which 
string to use, so it has to be called here.
   
   I think something like this could work:
   
   ```js
   const s1 = t('foo');
   const s2 = t('bar');
   ...
   function someFunction() => {
     ...
     const message = tn(s1, s2, numberOfItems);
   }
   ```
   
   But then it might make the translation harder, since the strings are 
disassociated? I'm not sure how the translation tooling works on the frontend.
   
   @ktmud any thoughts here?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to