-
Notifications
You must be signed in to change notification settings - Fork 14.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: sql lab ctrl t behaved differently from clicking #19420
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this was already present in the original code, but I think it's a bug. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! |
||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a couple of tests for this file please