You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2022/03/30 13:33:35 UTC

[GitHub] [superset] diegomedina248 commented on a change in pull request #19420: fix: sql lab ctrl t behaved differently from clicking

diegomedina248 commented on a change in pull request #19420:
URL: https://github.com/apache/superset/pull/19420#discussion_r838549125



##########
File path: superset-frontend/src/SqlLab/utils/newQueryTabName.ts
##########
@@ -0,0 +1,28 @@
+import { t } from '@superset-ui/core';
+import { QueryEditor } from '../types';
+
+const untitledQueryRegex = /^Untitled Query (\d+)$/; // Literal notation isn't recompiled
+const untitledQuery = 'Untitled Query ';
+
+export const newQueryTabName = (
+  queryEditors: QueryEditor[],
+  initialTitle = `${untitledQuery}1`,
+): string => {
+  if (queryEditors.length > 0) {
+    const mappedUntitled = queryEditors.filter(qe =>
+      qe.title.match(untitledQueryRegex),
+    );
+    const untitledQueryNumbers = mappedUntitled.map(
+      qe => +qe.title.replace(untitledQuery, ''),
+    );
+    if (untitledQueryNumbers.length > 0) {
+      // When there are query tabs open, and at least one is called "Untitled Query #"
+      // Where # is a valid number
+      const largestNumber: number = Math.max(...untitledQueryNumbers);
+      return t(`${untitledQuery}%s`, largestNumber + 1);
+    }
+    return initialTitle;
+  }
+
+  return initialTitle;

Review comment:
       I know this was already present in the original code, but I think it's a bug.
   If we reach this line, it means it's the first editor. In this case, the title is not translated.
   Can you ensure "Untitled Query 1" is translated here as well?

##########
File path: superset-frontend/src/SqlLab/utils/newQueryTabName.ts
##########
@@ -0,0 +1,28 @@
+import { t } from '@superset-ui/core';
+import { QueryEditor } from '../types';
+
+const untitledQueryRegex = /^Untitled Query (\d+)$/; // Literal notation isn't recompiled
+const untitledQuery = 'Untitled Query ';
+
+export const newQueryTabName = (

Review comment:
       add a couple of tests for this file please




-- 
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.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org