dsh-data-window 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/BRIDGE.md CHANGED
@@ -75,6 +75,12 @@ window.dispatchEvent(new CustomEvent('dsh-data-window:response', {
75
75
  3. 多个候选时按**环境顺序取第一个**,回执里带全部 `candidates`,调用方可提示用户;
76
76
  4. 没有候选 → `table-not-found`。
77
77
 
78
+ `openSql` 不查表,按这条顺序选库:
79
+
80
+ 1. 请求带了 `schema` → 精确匹配该库;
81
+ 2. 否则**只在本工作区发现出来的库**里取第一个(资源树是全机共享的,同一个实例下还挂着别的项目的库;`shared.js` 会给本项目发现的库打 `inWorkspace: true`);
82
+ 3. 本工作区一个库都没发现(比如只有共享/手动连接)→ 退回全量列表的第一个。
83
+
78
84
  ## 只读边界
79
85
 
80
86
  桥只负责打开控制台、粘贴文本、执行生成的只读 `SELECT`。所有真正发往 MySQL 的语句仍然经过 Host 的只读网关(白名单 / 单语句 / 写关键字 / `SET SESSION TRANSACTION READ ONLY`)。`openSql` 从不自动执行外部传入的 SQL。
package/docs/DETAIL.md CHANGED
@@ -67,7 +67,7 @@ bootstrap.yml spring.application.name = demo-order-service
67
67
  |---|---|
68
68
  | 连接 | 清掉子节点与补全缓存,重新跑一次发现(重读工作区配置),新库/改过的地址会进来 |
69
69
  | 库 | 重新拉一次 `tables` 并展开该库;同时清掉该库的补全缓存,编辑器建议随之更新 |
70
- | 表 / 视图 | 重新拉一次 `columns`;如果这张表的建表语句标签页开着,一并刷新 |
70
+ | 表 / 视图 | 重新拉一次 `columns` |
71
71
 
72
72
  刷新只读:只读元数据(`information_schema` / `SHOW`),不执行任何 DDL/DML。
73
73
 
@@ -109,7 +109,7 @@ bootstrap.yml spring.application.name = demo-order-service
109
109
  |---|---|
110
110
  | 点工作区自动加载配置、缓存地址与账号 | 打开面板即解析工作区 → 环境 → 实例 → 库,结果按工作区缓存;`重新读取配置` 强制刷新 |
111
111
  | 看到实例、库、表、字段 | 左侧树逐层展开;实例上的网格按钮打开「选择数据库」勾选面板,表可展开字段(类型、主键、NOT NULL、注释) |
112
- | 快捷键查看建表语句 | 选中表后按 **F4** 或 **⌘/Ctrl + Shift + D**;也可右键「查看建表语句」 |
112
+ | 快捷键查看建表语句 | 选中表后按 **F4** 或 **⌘/Ctrl + Shift + D**;也可右键「查看建表语句」;在弹窗里查看并复制,不打开工作标签。右键**库**(或选中库按 F4)则是「查看全部建表语句」:逐表读取,带 `x/y` 进度,失败的表在末尾用注释标出 |
113
113
  | 每个库一个 SQL 工作台 | 点库名打开该库的工作台,标签页常驻 |
114
114
  | 每张表一个窗口 | 双击表打开/聚焦该表自己的标签,并在末尾追加一条 `SELECT *` 基础查询;重复双击不会新开标签、不覆盖已有内容,且只执行刚追加的那一条 |
115
115
  | 代码工作区联动 | 代码工作区右键实体类(`@TableName`)直接打开该表并执行基础查询;右键 Mapper 方法把 XML/注解里的 SQL 粘贴到数据窗口(不自动执行)。契约见 `docs/BRIDGE.md` |
@@ -141,8 +141,30 @@ SQL 编辑器接管了浏览器右键菜单,保留常用编辑动作并多了
141
141
  - 优化说明的语言跟随系统(`navigator.language`,如 `zh-CN` → 简体中文);
142
142
  - 没配置模型时弹窗直接说明去哪里配置;
143
143
  - Host 侧 `optimizeSql` 只调用模型,**不连数据库、不执行 SQL**;SQL 上限 20,000 字符;
144
+ - 结果以**左右对照 diff** 展示:左边原始 SQL、右边优化后 SQL,改动按 token 标色(左红右绿),
145
+ token 级比较是为了兼容"原 SQL 多行、模型返回一行"的常见情况;两侧滚动同步;
144
146
  - 结果只展示和复制,**不会自动改写编辑器里的语句**——仍然遵守"不覆盖用户 SQL"。
145
147
 
148
+ ## 资源树的点击
149
+
150
+ 行点击只**选中**,不展开;展开/收起只由行首的三角控制。双击是"打开":库打开控制台并展开,表/视图打开数据,环境/实例展开;实例行右侧的网格按钮仍然打开选库面板。
151
+
152
+ ## 标签页右键菜单
153
+
154
+ SQL 标签页(库控制台 / 表控制台)右键出菜单:
155
+
156
+ | 菜单项 | 行为 |
157
+ |---|---|
158
+ | 关闭 | 关闭当前标签,激活右侧邻居(没有就左侧) |
159
+ | 关闭其他标签页 / 关闭所有标签页 | 批量关闭,同样把激活位置落到邻居 |
160
+ | 关闭左侧标签页 / 关闭右侧标签页 | 只关一侧;没有可关的就置灰 |
161
+ | 复制引用 | 复制 `库.表`(表控制台)或 `库`(库控制台) |
162
+ | 复制引用到对话 | 先复制,再尝试把引用插入 DSH 对话输入框(`[data-composer-seat]` 的 contenteditable);输入框没打开时只复制并提示 |
163
+
164
+ 菜单本身沿用 `dsh-ide-window` 的样式:图标 + 文字、27px 行高、分隔线、禁用的左侧/右侧项置灰,并夹在面板矩形内展开。
165
+
166
+ `⌘W` / 中键仍可关闭单个标签;批量关闭会立即保存控制台快照。
167
+
146
168
  ## 结果翻页
147
169
 
148
170
  语句末尾带 `LIMIT` 时,结果栏会出现 `‹ 上一页 · 第 N 页 · 每页 X 行 · 下一页 ›`:
package/locale/en.json CHANGED
@@ -282,5 +282,23 @@
282
282
  "aiModelUnknown": "not configured",
283
283
  "optimizeNotes": "Notes",
284
284
  "optimizeCopy": "Copy SQL",
285
- "log.optimizeCopied": "Optimized SQL copied"
285
+ "log.optimizeCopied": "Optimized SQL copied",
286
+ "tabClose": "Close",
287
+ "tabCloseOthers": "Close other tabs",
288
+ "tabCloseAll": "Close all tabs",
289
+ "tabCloseLeft": "Close tabs to the left",
290
+ "tabCloseRight": "Close tabs to the right",
291
+ "copyReference": "Copy reference",
292
+ "copyReferenceToChat": "Copy reference to chat",
293
+ "log.copiedReference": "Reference copied: {reference}",
294
+ "log.copiedReferenceToChat": "Reference inserted into the chat: {reference}",
295
+ "log.copiedReferenceOnly": "Chat input is closed; reference copied: {reference}",
296
+ "tabMenuLabel": "Tab menu",
297
+ "optimizeOriginal": "Original SQL",
298
+ "optimizeOptimized": "Optimized SQL",
299
+ "menuDdlAll": "Show all create statements",
300
+ "ddlAllEmpty": "This database has no tables",
301
+ "ddlAllPartial": "{count} table(s) could not be read; noted at the end of the script",
302
+ "log.ddlAll": "Read all create statements of {database}: {count} tables · {ms}",
303
+ "log.copiedDdlAll": "Copied all create statements of {database} ({count} tables)"
286
304
  }
package/locale/zh.json CHANGED
@@ -282,5 +282,23 @@
282
282
  "aiModelUnknown": "未配置",
283
283
  "optimizeNotes": "优化说明",
284
284
  "optimizeCopy": "复制 SQL",
285
- "log.optimizeCopied": "优化后的 SQL 已复制"
285
+ "log.optimizeCopied": "优化后的 SQL 已复制",
286
+ "tabClose": "关闭",
287
+ "tabCloseOthers": "关闭其他标签页",
288
+ "tabCloseAll": "关闭所有标签页",
289
+ "tabCloseLeft": "关闭左侧标签页",
290
+ "tabCloseRight": "关闭右侧标签页",
291
+ "copyReference": "复制引用",
292
+ "copyReferenceToChat": "复制引用到对话",
293
+ "log.copiedReference": "已复制引用:{reference}",
294
+ "log.copiedReferenceToChat": "已把引用插入对话:{reference}",
295
+ "log.copiedReferenceOnly": "对话输入框未打开,已复制引用:{reference}",
296
+ "tabMenuLabel": "标签页菜单",
297
+ "optimizeOriginal": "原始 SQL",
298
+ "optimizeOptimized": "优化后 SQL",
299
+ "menuDdlAll": "查看全部建表语句",
300
+ "ddlAllEmpty": "这个库还没有表",
301
+ "ddlAllPartial": "{count} 张表读取失败,已在脚本末尾用注释标出",
302
+ "log.ddlAll": "读取 {database} 的全部建表语句:{count} 张表 · {ms}",
303
+ "log.copiedDdlAll": "已复制 {database} 的全部建表语句({count} 张表)"
286
304
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-data-window",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "DataGrip-style database window for DeepSeek Harness: reads the workspace's own config to find the environment hosts, then browses instances, databases, tables and columns and runs read-only SQL in one workbench per database.",
5
5
  "type": "module",
6
6
  "icon": "icon.svg",
@@ -631,6 +631,63 @@ const DW_CSS = `
631
631
  background: var(--dsw-alias-bg-overlay, #23262d);
632
632
  box-shadow: 0 10px 26px rgba(0,0,0,.42);
633
633
  }
634
+ .dw-tabmenu-backdrop {
635
+ position: fixed;
636
+ inset: 0;
637
+ z-index: 70;
638
+ background: transparent;
639
+ }
640
+ /* The tab menu mirrors the code workspace's menu (icons + labels, IDEA-like). */
641
+ .dw-tabmenu {
642
+ position: fixed;
643
+ overflow-y: auto;
644
+ overscroll-behavior: contain;
645
+ min-width: 232px;
646
+ padding: 5px;
647
+ border: 0.5px solid var(--dsw-alias-border-l2, rgba(255, 255, 255, .1));
648
+ border-radius: var(--dsw-radius-md, 10px);
649
+ background: var(--dsw-specific-menu, var(--dsw-alias-bg-layer-2, #23262b));
650
+ backdrop-filter: var(--dsw-menu-backdrop-filter, none);
651
+ box-shadow: var(--dsw-elevation-prominent, 0 12px 32px rgba(0, 0, 0, .35));
652
+ color: var(--dsw-alias-label-primary, inherit);
653
+ }
654
+ .dw-tabmenu-item {
655
+ display: flex;
656
+ align-items: center;
657
+ gap: 9px;
658
+ width: 100%;
659
+ height: 27px;
660
+ padding: 0 9px;
661
+ border: 0;
662
+ border-radius: var(--dsw-radius-sm, 6px);
663
+ background: transparent;
664
+ color: inherit;
665
+ font: inherit;
666
+ font-size: 12.5px;
667
+ line-height: 27px;
668
+ text-align: left;
669
+ cursor: default;
670
+ }
671
+ .dw-tabmenu-item:hover:not(:disabled) { background: var(--dsw-alias-interactive-bg-hover, rgba(255, 255, 255, .08)); }
672
+ .dw-tabmenu-item:disabled { opacity: .45; }
673
+ .dw-tabmenu-item:focus-visible {
674
+ outline: none;
675
+ box-shadow: inset 0 0 0 2px var(--dsw-focus-ring-color, var(--dsw-alias-state-business-primary, #4a7dff));
676
+ }
677
+ .dw-tabmenu-icon {
678
+ display: inline-flex;
679
+ flex: none;
680
+ align-items: center;
681
+ justify-content: center;
682
+ width: 14px;
683
+ color: var(--dsw-alias-label-secondary, inherit);
684
+ }
685
+ .dw-tabmenu-label { flex: 1 1 auto; }
686
+ .dw-tabmenu-sep {
687
+ height: 0.5px;
688
+ margin: 5px 8px;
689
+ background: var(--dsw-alias-border-l1, rgba(255, 255, 255, .08));
690
+ }
634
691
  .dw-menu-note {
635
692
  padding: 4px 8px 5px;
636
693
  color: var(--dsw-alias-label-secondary, #8b919d);
@@ -908,7 +965,67 @@ const DW_CSS = `
908
965
  word-break: break-all;
909
966
  }
910
967
  .dw-cell-dialog { width: min(720px, 100%); }
911
- .dw-optimize-dialog { width: min(760px, 100%); }
968
+ .dw-optimize-dialog { width: min(1100px, 100%); }
969
+ .dw-ddl-dialog { width: min(900px, 100%); }
970
+ /*
971
+ * The DDL is the only scroll container in this dialog: one scrollbar pair, at the
972
+ * code box, instead of the modal body plus the pre each growing their own.
973
+ */
974
+ .dw-ddl-dialog .dw-modal-body {
975
+ display: flex;
976
+ flex-direction: column;
977
+ min-height: 0;
978
+ overflow: hidden;
979
+ }
980
+ .dw-ddl-result {
981
+ display: flex;
982
+ flex: 1 1 auto;
983
+ flex-direction: column;
984
+ min-height: 0;
985
+ }
986
+ .dw-ddl-result .dw-log-warn { margin-bottom: 6px; }
987
+ .dw-ddl-code {
988
+ flex: 1 1 auto;
989
+ min-height: 0;
990
+ max-height: none;
991
+ overflow: auto;
992
+ /* Keep the server's line breaks: long COMMENTs scroll sideways, never wrap. */
993
+ white-space: pre;
994
+ word-break: normal;
995
+ }
996
+ .dw-diff { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
997
+ .dw-diff-col { display: flex; flex-direction: column; min-width: 0; }
998
+ .dw-diff-head {
999
+ padding-bottom: 5px;
1000
+ color: var(--dsw-alias-label-secondary, #8b919d);
1001
+ font-size: 11px;
1002
+ }
1003
+ .dw-diff-pane {
1004
+ margin: 0;
1005
+ padding: 10px 12px;
1006
+ max-height: 320px;
1007
+ overflow: auto;
1008
+ border: 1px solid var(--dsw-alias-border-l1, #31353d);
1009
+ border-radius: 8px;
1010
+ background: var(--dsw-alias-bg-layer-2, #262930);
1011
+ color: var(--dsw-alias-label-primary, #e6e8ec);
1012
+ font-family: var(--dsw-font-mono, ui-monospace, SFMono-Regular, Menlo, monospace);
1013
+ font-size: 12px;
1014
+ line-height: 1.55;
1015
+ white-space: pre-wrap;
1016
+ word-break: break-word;
1017
+ }
1018
+ .dw-diff-del {
1019
+ border-radius: 2px;
1020
+ background: color-mix(in srgb, var(--dsw-alias-state-error-primary, #e5534b) 26%, transparent);
1021
+ }
1022
+ .dw-diff-add {
1023
+ border-radius: 2px;
1024
+ background: color-mix(in srgb, var(--dsw-alias-state-success-primary, #3fb950) 26%, transparent);
1025
+ }
1026
+ @media (max-width: 720px) {
1027
+ .dw-diff { grid-template-columns: 1fr; }
1028
+ }
912
1029
  .dw-optimize-model { padding-bottom: 8px; color: var(--dsw-alias-label-secondary, #8b919d); font-size: 11px; }
913
1030
  .dw-optimize-notes {
914
1031
  max-height: 120px;
@@ -65,6 +65,25 @@ function DwIcon({ name, size = 14, className }) {
65
65
  return h('svg', { ...common, fill: 'currentColor', stroke: 'none' }, [h('path', { d: 'M4.6 2.9l8 5.1-8 5.1z' })])
66
66
  case 'stop':
67
67
  return h('svg', { ...common, fill: 'currentColor', stroke: 'none' }, [h('rect', { x: 4, y: 4, width: 8, height: 8, rx: 1.4 })])
68
+ case 'layers':
69
+ return h('svg', common, [
70
+ h('rect', { key: 'a', x: 2.4, y: 2.4, width: 7, height: 7, rx: 1.4 }),
71
+ h('rect', { key: 'b', x: 6.6, y: 6.6, width: 7, height: 7, rx: 1.4 }),
72
+ ])
73
+ case 'stack':
74
+ return h('svg', common, [
75
+ h('path', { key: 'a', d: 'M2 6 8 3.2 14 6 8 8.8Z' }),
76
+ h('path', { key: 'b', d: 'M2 10.4 8 13.2 14 10.4' }),
77
+ ])
78
+ case 'arrow-left':
79
+ return h('svg', common, [h('path', { key: 'a', d: 'M12.5 8H3.5M7 4.5 3.5 8 7 11.5' })])
80
+ case 'arrow-right':
81
+ return h('svg', common, [h('path', { key: 'a', d: 'M3.5 8h9M9 4.5 12.5 8 9 11.5' })])
82
+ case 'at':
83
+ return h('svg', common, [
84
+ h('circle', { key: 'a', cx: 8, cy: 8, r: 2.4 }),
85
+ h('path', { key: 'b', d: 'M10.4 8v1.4a2.1 2.1 0 0 0 4.2 0V8A6.4 6.4 0 1 0 8 14.4c1.2 0 2.2-.2 3-.7' }),
86
+ ])
68
87
  case 'close':
69
88
  return h('svg', common, [h('path', { d: 'M4.2 4.2l7.6 7.6M11.8 4.2l-7.6 7.6' })])
70
89
  case 'download':
@@ -43,6 +43,9 @@ function dwBridgeDatabases(state) {
43
43
  env: environment.env,
44
44
  envLabel: environment.label ?? environment.env,
45
45
  instanceLabel: instance.label ?? '',
46
+ // 资源树是全机共享的,同一个实例下会挂着别的项目的库;只有本项目发现出来的
47
+ // 库才带这个标记,`openSql` 靠它选库。
48
+ inWorkspace: database.inWorkspace === true,
46
49
  })
47
50
  }
48
51
  }
@@ -154,7 +157,13 @@ async function dwBridgeHandle(detail, deps) {
154
157
  return
155
158
  }
156
159
  const schema = typeof detail.schema === 'string' ? detail.schema.trim() : ''
157
- const target = databases.find((entry) => schema !== '' && entry.database === schema) ?? databases[0]
160
+ // 库的定位:显式 schema 优先;没有就只在本项目发现出来的库里挑。
161
+ // 以前直接取 databases[0],共享资源树里第一个常常是别的项目的库
162
+ // (bluewhale-order-service 的 Mapper 被打开在 tiangong_tk_order 下)。
163
+ const own = databases.filter((entry) => entry.inWorkspace === true)
164
+ const pool = own.length > 0 ? own : databases
165
+ const target = (schema === '' ? null : databases.find((entry) => entry.database === schema))
166
+ ?? pool[0]
158
167
  layout()?.selectPanel?.(DW_PANEL_ID)
159
168
  // Paste only: Mapper SQL usually carries #{...} parameters and dynamic
160
169
  // fragments, so running it automatically would just produce an error.
@@ -822,10 +822,6 @@ function dwCreateStore(translate) {
822
822
  void store.loadSchema(node.dbId)
823
823
  await store.ensureChildren(node)
824
824
  if (state.loadState.get(node.key) === 'error') return
825
- if (node.kind === 'table' || node.kind === 'view') {
826
- const tab = state.tabs.find((entry) => entry.kind === 'ddl' && entry.dbId === node.dbId && entry.table === node.table)
827
- if (tab !== undefined) await store.refreshDdl(tab.id)
828
- }
829
825
  pushLog('info', t('log.refreshedStructure', { name: node.label }))
830
826
  },
831
827
 
@@ -1060,73 +1056,45 @@ function dwCreateStore(translate) {
1060
1056
  return tab
1061
1057
  },
1062
1058
 
1063
- /**
1064
- * Open the DDL of one table.
1065
- *
1066
- * Requirement: the create statement is one keystroke away. The tab is keyed by
1067
- * table, so asking twice focuses the same document instead of stacking copies.
1068
- */
1069
- async openDdl(node) {
1070
- if (node === null || node === undefined || node.table === undefined) return
1071
- const id = `ddl:${node.dbId}:${node.table}`
1072
- const existing = state.tabs.find((tab) => tab.id === id)
1073
- if (existing !== undefined) {
1074
- patch({ activeTab: id })
1075
- if (existing.loading !== true && existing.ddl !== '') return
1076
- await store.refreshDdl(id)
1077
- return
1078
- }
1079
- const tab = {
1080
- id,
1081
- kind: 'ddl',
1082
- title: node.table,
1083
- env: node.env ?? '',
1084
- subtitle: [node.env, node.database].filter((part) => typeof part === 'string' && part !== '').join(' · '),
1085
- dbId: node.dbId,
1086
- database: node.database,
1087
- instanceLabel: node.instanceLabel ?? '',
1088
- table: node.table,
1089
- ddl: '',
1090
- columns: [],
1091
- loading: true,
1092
- error: '',
1059
+ /** Close one or more tabs and keep the active selection on a neighbour. */
1060
+ closeTabs(ids) {
1061
+ const removing = new Set(Array.isArray(ids) ? ids : [])
1062
+ if (removing.size === 0) return
1063
+ const tabs = state.tabs.filter((tab) => !removing.has(tab.id))
1064
+ let activeTab = state.activeTab
1065
+ if (removing.has(activeTab)) {
1066
+ const index = state.tabs.findIndex((tab) => tab.id === activeTab)
1067
+ const neighbour = state.tabs.slice(index + 1).find((tab) => !removing.has(tab.id))
1068
+ ?? state.tabs.slice(0, index).reverse().find((tab) => !removing.has(tab.id))
1069
+ activeTab = neighbour?.id ?? ''
1093
1070
  }
1094
- patch({ tabs: [...state.tabs, tab], activeTab: id })
1095
- await store.refreshDdl(id)
1071
+ patch({ tabs, activeTab })
1072
+ // Closing a console is deliberate: drop it from storage now, not later.
1073
+ flushConsoles()
1096
1074
  },
1097
1075
 
1098
- /** Re-read one DDL tab (a schema change is exactly why the tab exists). */
1099
- async refreshDdl(id) {
1100
- const tab = state.tabs.find((entry) => entry.id === id)
1101
- if (tab === undefined || tab.kind !== 'ddl') return
1102
- patch({ tabs: state.tabs.map((entry) => (entry.id === id ? { ...entry, loading: true, error: '' } : entry)) })
1103
- try {
1104
- const value = await call('ddl', { id: tab.dbId, table: tab.table })
1105
- patch({
1106
- tabs: state.tabs.map((entry) => (entry.id === id
1107
- ? { ...entry, ddl: value.ddl ?? '', columns: value.columns ?? [], loading: false, error: '' }
1108
- : entry)),
1109
- })
1110
- pushLog('info', t('log.ddl', { table: tab.table, ms: dwDuration(value.statementTime) }))
1111
- } catch (error) {
1112
- patch({ tabs: state.tabs.map((entry) => (entry.id === id ? { ...entry, loading: false, error: dwExplainFailure(t, error) } : entry)) })
1113
- pushLog('error', t('log.loadFailed', { name: tab.table, message: dwExplainFailure(t, error) }))
1114
- }
1076
+ closeTab(id) {
1077
+ store.closeTabs([id])
1115
1078
  },
1116
1079
 
1117
- /** Close one tab and pick a neighbour. */
1118
- closeTab(id) {
1080
+ closeOtherTabs(id) {
1081
+ store.closeTabs(state.tabs.filter((tab) => tab.id !== id).map((tab) => tab.id))
1082
+ },
1083
+
1084
+ closeAllTabs() {
1085
+ store.closeTabs(state.tabs.map((tab) => tab.id))
1086
+ },
1087
+
1088
+ closeTabsToLeft(id) {
1089
+ const index = state.tabs.findIndex((tab) => tab.id === id)
1090
+ if (index <= 0) return
1091
+ store.closeTabs(state.tabs.slice(0, index).map((tab) => tab.id))
1092
+ },
1093
+
1094
+ closeTabsToRight(id) {
1119
1095
  const index = state.tabs.findIndex((tab) => tab.id === id)
1120
1096
  if (index < 0) return
1121
- const tabs = state.tabs.filter((tab) => tab.id !== id)
1122
- let activeTab = state.activeTab
1123
- if (activeTab === id) {
1124
- const neighbour = tabs[index] ?? tabs[index - 1]
1125
- activeTab = neighbour?.id ?? ''
1126
- }
1127
- patch({ tabs, activeTab })
1128
- // Closing a console is deliberate: drop it from storage now, not later.
1129
- flushConsoles()
1097
+ store.closeTabs(state.tabs.slice(index + 1).map((tab) => tab.id))
1130
1098
  },
1131
1099
 
1132
1100
  setActiveTab(id) {
@@ -155,6 +155,8 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
155
155
  [state.environments, state.expanded, state.children, state.loadState, state.filter],
156
156
  )
157
157
 
158
+ // A row click only selects: expanding belongs to the twisty (and to double-click
159
+ // for the kinds whose whole purpose is to be opened).
158
160
  const activate = (row) => {
159
161
  const node = row.node
160
162
  if (node.kind === 'retry') {
@@ -162,13 +164,24 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
162
164
  return
163
165
  }
164
166
  store.select(node)
167
+ }
168
+
169
+ const openRow = (row) => {
170
+ const node = row.node
171
+ if (node.kind === 'retry') {
172
+ store.retryNode(node.retryOf)
173
+ return
174
+ }
175
+ store.select(node)
165
176
  if (node.kind === 'database') {
166
177
  store.openDatabase(node)
167
- // Opening the workbench also reveals its tables: that is the list the user
168
- // came for, and one click is better than two.
169
178
  if (row.open !== true) void store.toggleNode(node)
170
179
  return
171
180
  }
181
+ if (node.kind === 'table' || node.kind === 'view') {
182
+ openTableData(row)
183
+ return
184
+ }
172
185
  if (node.kind === 'instance' && (node.databases ?? []).length === 0) {
173
186
  onChooseDatabases(node)
174
187
  return
@@ -214,10 +227,9 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
214
227
  className: 'dw-node-twisty',
215
228
  style: { transform: row.open === true ? 'rotate(90deg)' : 'none', transition: 'transform 110ms ease', cursor: 'pointer' },
216
229
  onClick: (event) => {
217
- // The twisty is the only control that collapses a node: clicking the row
218
- // of a database opens its workbench and never closes the list.
230
+ // The twisty is the only control that expands or collapses a node;
231
+ // clicking the row never changes the expansion.
219
232
  event.stopPropagation()
220
- store.select(node)
221
233
  void store.toggleNode(node)
222
234
  },
223
235
  }, row.loading === true ? h(DwIcon, { name: 'spinner', size: 11 }) : h(DwIcon, { name: 'chevron', size: 11 }))
@@ -244,7 +256,7 @@ function DwTree({ store, state, tr, onContextMenu, onChooseDatabases }) {
244
256
  ].filter((part) => part !== '').join(' · ')
245
257
  : `${node.title ?? `${node.label}${node.detail ? ` ${node.detail}` : ''}`}`,
246
258
  onClick: () => activate(row),
247
- onDoubleClick: () => (node.kind === 'table' || node.kind === 'view' ? openTableData(row) : undefined),
259
+ onDoubleClick: () => openRow(row),
248
260
  onContextMenu: (event) => {
249
261
  event.preventDefault()
250
262
  store.select(node)