etr2460 commented on a change in pull request #18951:
URL: https://github.com/apache/superset/pull/18951#discussion_r816935054



##########
File path: superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx
##########
@@ -260,8 +256,31 @@ class TabbedSqlEditors extends React.PureComponent {
       : t(
           '-- Note: Unless you save your query, these tabs will NOT persist if 
you clear your cookies or change browsers.\n\n',
         );
+
+    let newTitle;
+
+    if (this.props.queryEditors.length > 0) {
+      const untitledQueryNumbers = this.props.queryEditors
+        .filter(x => x.title.includes('Untitled Query '))
+        .map(x => x.title.replace('Untitled Query ', ''))
+        .filter(x => !Number.isNaN(Number(x)));
+      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 = Math.max.apply(null, untitledQueryNumbers);
+        newTitle = t('Untitled Query %s', largestNumber + 1);
+      } else {
+        // When there are query tabs open but none of them are called 
"Untitled Query #"
+        // Where # is a valid number
+        newTitle = 'Untitled Query 1';
+      }
+    } else {
+      // When there are no query tabs currently open
+      newTitle = 'Untitled Query 1';
+    }

Review comment:
       instead of these else cases, why not initialize `newTitle` to `'Untitled 
Query 1'`?

##########
File path: superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.jsx
##########
@@ -260,8 +256,31 @@ class TabbedSqlEditors extends React.PureComponent {
       : t(
           '-- Note: Unless you save your query, these tabs will NOT persist if 
you clear your cookies or change browsers.\n\n',
         );
+
+    let newTitle;
+
+    if (this.props.queryEditors.length > 0) {
+      const untitledQueryNumbers = this.props.queryEditors
+        .filter(x => x.title.includes('Untitled Query '))
+        .map(x => x.title.replace('Untitled Query ', ''))
+        .filter(x => !Number.isNaN(Number(x)));

Review comment:
       maybe let's find all tab titles that match a regex of `^Untitled Query 
(\d+)$`, and then we can pull the number our of the group that matches there. 
Then we also shouldn't need to do the `isNaN` check. 




-- 
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: [email protected]

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