rusackas commented on code in PR #41285:
URL: https://github.com/apache/superset/pull/41285#discussion_r3525756749
##########
superset-frontend/src/core/sqlLab/sqlLab.test.ts:
##########
@@ -561,10 +561,29 @@ test('createTab dispatches ADD_QUERY_EDITOR and returns
the new tab', async () =
expect(tab).toBeDefined();
expect(tab.title).toBe('Custom Tab');
+ // A freshly created tab has no backend identifier until it syncs.
+ expect(tab.backendId).toBeUndefined();
const tabs = sqlLab.getTabs();
expect(tabs.length).toBeGreaterThanOrEqual(2);
});
+test('getTabs leaves backendId undefined when the editor has no tabViewId', ()
=> {
+ // The preloaded editor has no tabViewId, so its backendId stays undefined.
+ const [tab] = sqlLab.getTabs();
+ expect(tab.id).toBe(EDITOR_ID);
+ expect(tab.backendId).toBeUndefined();
+});
+
+test('getTabs surfaces the editor tabViewId as the tab backendId', () => {
+ // Stamp a backend id onto the editor and confirm it flows through to the
tab.
+ (mockStore.getState().sqlLab.queryEditors[0] as QueryEditor).tabViewId =
+ 'backend-42';
+
+ const tab = sqlLab.getCurrentTab();
Review Comment:
Good catch — switched it to actually call `getTabs()`.
##########
superset-frontend/src/SqlLab/components/SqlEditor/index.tsx:
##########
@@ -1046,6 +1120,29 @@ const SqlEditor: FC<Props> = ({
'Choose one of the available databases from the panel on the
left.',
)}
Review Comment:
Right — moved the northPane check ahead of the empty-state branch so
extension tabs render without a db selected.
##########
superset-frontend/src/SqlLab/components/TabbedSqlEditors/index.tsx:
##########
@@ -94,6 +97,114 @@ const TabTitle = styled.span`
// Get the user's OS
const userOS = detectOS();
+const newTabTooltip =
+ userOS === 'Windows' ? t('New tab (Ctrl + q)') : t('New tab (Ctrl + t)');
+
+const PlusIcon = (
+ <Icons.PlusOutlined
+ iconSize="l"
+ css={css`
+ vertical-align: middle;
+ `}
+ data-test="add-tab-icon"
+ />
+);
+
+function NewTabButton({ onAddSqlEditor }: { onAddSqlEditor: () => void }) {
+ const [open, setOpen] = useState(false);
+
+ const dropdownItems = useMemo<MenuItemType[]>(() => {
+ if (!open) return [];
+ const primaryItems =
+ menus.getMenu(ViewLocations.sqllab.newTab)?.primary ?? [];
+ return [
+ {
+ key: 'sql-editor',
+ label: t('SQL Editor'),
+ icon: <Icons.TableOutlined iconSize="m" />,
+ onClick: () => {
+ setOpen(false);
+ onAddSqlEditor();
+ },
+ },
+ ...primaryItems.flatMap(item => {
+ const command = commands.getCommand(item.command);
+ if (!command) {
+ // An extension contributed this menu item but its command isn't
+ // registered (load is still pending or failed). Skip it so clicking
+ // can't throw "Command not found" and break the add-tab flow.
+ return [];
+ }
+ const Icon = command.icon
+ ? ((Icons as Record<string, typeof Icons.FileOutlined>)[
+ command.icon
+ ] ?? Icons.FileOutlined)
+ : Icons.FileOutlined;
+ return [
+ {
+ key: command.id,
+ label: command.title ?? item.command,
+ icon: <Icon iconSize="m" />,
+ onClick: () => {
+ setOpen(false);
+ commands.executeCommand(item.command);
Review Comment:
Added a `.catch` so a rejected command logs instead of going unhandled.
--
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]