@infinilabs/ui-web-cli 0.0.19 → 0.0.20

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/README-zh_CN.md CHANGED
@@ -8,59 +8,478 @@
8
8
 
9
9
  ## 安装
10
10
 
11
- ```
12
- npm i @infinilabs/ui-web-cli
11
+ ```bash
12
+ npm i @infinilabs/ui-web-cli
13
13
 
14
14
  # or
15
15
  cnpm i @infinilabs/ui-web-cli
16
16
 
17
17
  # or
18
- yarn add @infinilabs/ui-web-cli
18
+ yarn add @infinilabs/ui-web-cli
19
19
 
20
20
  # or
21
- pnpm add @infinilabs/ui-web-cli
21
+ pnpm add @infinilabs/ui-web-cli
22
22
  ```
23
23
 
24
- ## 使用示例
24
+ ## 组件概述
25
+
26
+ `ConsoleUI` 是一个功能强大的 Web 控制台组件,专为 Elasticsearch 等搜索引擎设计。它提供了完整的查询界面、多标签页管理、拖拽功能、数据源切换等特性,支持高度自定义和灵活配置。
27
+
28
+ ### 主要特性
29
+
30
+ - 🎯 **多标签页管理** - 支持动态添加、删除、重命名标签页
31
+ - 🔄 **拖拽功能** - 标签页拖拽排序,窗口大小调整
32
+ - 🎨 **高度自定义** - 支持自定义图标、样式、数据源组件
33
+ - 📱 **响应式设计** - 适配不同屏幕尺寸
34
+ - 🔧 **灵活配置** - 丰富的配置选项满足不同使用场景
35
+ - 🚀 **性能优化** - 虚拟滚动、懒加载等性能优化
36
+
37
+ ## 基础使用
25
38
 
26
39
  ```jsx
27
- // ...
28
- import ConsoleUI from "@infinilabs/ui-web-cli";
29
- //...
40
+ import React, { useState } from 'react';
41
+ import ConsoleUI from '@infinilabs/ui-web-cli';
42
+
43
+ function App() {
44
+ const [consoleOpen, setConsoleOpen] = useState(true);
45
+
46
+ // 集群列表数据
47
+ const clusterList = [
48
+ {
49
+ id: 'cluster1',
50
+ name: 'Production Cluster',
51
+ endpoint: 'https://es-prod.example.com:9200',
52
+ status: 'green'
53
+ },
54
+ {
55
+ id: 'cluster2',
56
+ name: 'Development Cluster',
57
+ endpoint: 'https://es-dev.example.com:9200',
58
+ status: 'yellow'
59
+ }
60
+ ];
61
+
62
+ // 发送请求到 ES
63
+ const sendRequestToES = async (query, cluster) => {
64
+ try {
65
+ const response = await fetch(`${cluster.endpoint}/_search`, {
66
+ method: 'POST',
67
+ headers: {
68
+ 'Content-Type': 'application/json',
69
+ },
70
+ body: JSON.stringify(query)
71
+ });
72
+ return await response.json();
73
+ } catch (error) {
74
+ console.error('Request failed:', error);
75
+ throw error;
76
+ }
77
+ };
78
+
79
+ // 获取数据源
80
+ const fetchDataSource = async (clusterId) => {
81
+ // 返回指定集群的索引列表
82
+ return [
83
+ { name: 'logs-2024', type: 'index' },
84
+ { name: 'metrics-*', type: 'pattern' }
85
+ ];
86
+ };
87
+
88
+ return (
89
+ <ConsoleUI
90
+ clusterList={clusterList}
91
+ visible={consoleOpen}
92
+ minimize={true}
93
+ resizeable={true}
94
+ height="60vh"
95
+ onMinimizeClick={() => setConsoleOpen(false)}
96
+ sendRequestToES={sendRequestToES}
97
+ fetchDataSource={fetchDataSource}
98
+ />
99
+ );
100
+ }
101
+
102
+ export default App;
103
+ ```
104
+
105
+ ## API 参数
106
+
107
+ ### 基础参数
108
+
109
+ | 参数 | 说明 | 类型 | 默认值 | 版本 |
110
+ |------|------|------|--------|---------|
111
+ | visible | 组件是否可见 | boolean | true | 1.0.0 |
112
+ | minimize | 是否显示最小化按钮 | boolean | false | 1.0.0 |
113
+ | resizeable | 是否可以调整大小 | boolean | false | 1.0.0 |
114
+ | height | 组件高度 | string | "50vh" | 1.0.0 |
115
+ | width | 组件宽度 | string | "100%" | 1.0.0 |
116
+ | className | 自定义样式类名 | string | - | 1.0.0 |
117
+ | style | 自定义内联样式 | object | - | 1.0.0 |
118
+
119
+ ### 数据源参数
120
+
121
+ | 参数 | 说明 | 类型 | 默认值 | 版本 |
122
+ |------|------|------|--------|---------|
123
+ | clusterList | 集群列表数据 | array | [] | 1.0.0 |
124
+ | clusterStatus | 集群状态信息 | object | {} | 1.0.0 |
125
+ | tabData | 标签页数据 | object | {activeKey: "", panes: []} | 1.0.0 |
126
+ | DataSourceSelector | 自定义数据源选择器组件 | ReactNode | - | 1.0.0 |
127
+ | fetchDataSource | 获取数据源的方法 | function | - | 1.0.0 |
128
+
129
+ ### 拖拽配置参数
130
+
131
+ | 参数 | 说明 | 类型 | 默认值 | 版本 |
132
+ |------|------|------|--------|---------|
133
+ | dragConfig | 拖拽功能配置 | object | {enabled: true, tabDraggable: true} | 1.2.0 |
134
+ | dragConfig.enabled | 是否启用拖拽功能 | boolean | true | 1.2.0 |
135
+ | dragConfig.tabDraggable | 标签页是否可拖拽 | boolean | true | 1.2.0 |
136
+
137
+ ### 回调函数
138
+
139
+ | 参数 | 说明 | 类型 | 默认值 | 版本 |
140
+ |------|------|------|--------|---------|
141
+ | onMinimizeClick | 最小化按钮点击事件 | function | - | 1.0.0 |
142
+ | newTabClick | 新增标签页按钮点击事件 | function | - | 1.0.0 |
143
+ | addTab | 添加标签页的方法 | function | - | 1.0.0 |
144
+ | updateTabData | 更新标签页数据的方法 | function | - | 1.0.0 |
145
+ | sendRequestToES | 发送请求到搜索引擎的方法 | function | - | 1.0.0 |
146
+ | onTabChange | 标签页切换事件 | function | - | 1.0.0 |
147
+ | onTabClose | 标签页关闭事件 | function | - | 1.0.0 |
148
+
149
+ ### 自定义组件
150
+
151
+ | 参数 | 说明 | 类型 | 默认值 | 版本 |
152
+ |------|------|------|--------|---------|
153
+ | renderTabBarItemIcon | 标签页图标渲染函数 | function | - | 1.0.0 |
154
+ | SearchEngineIcon | 搜索引擎图标组件 | ReactNode | - | 1.0.0 |
155
+ | LogoImg | Logo 图片组件 | ReactNode | - | 1.0.0 |
156
+ | CustomToolbar | 自定义工具栏组件 | ReactNode | - | 1.0.0 |
30
157
 
31
- //...
32
- return (
158
+ ## 详细使用案例
159
+
160
+ ### 1. 基础配置
161
+
162
+ ```jsx
163
+ <ConsoleUI
164
+ clusterList={[
165
+ {
166
+ id: 'es-prod',
167
+ name: '生产环境',
168
+ endpoint: 'https://es-prod.company.com:9200',
169
+ status: 'green',
170
+ version: '8.5.0'
171
+ }
172
+ ]}
173
+ visible={true}
174
+ minimize={true}
175
+ resizeable={true}
176
+ height="70vh"
177
+ sendRequestToES={handleESRequest}
178
+ fetchDataSource={fetchIndices}
179
+ />
180
+ ```
181
+
182
+ ### 2. 禁用拖拽功能
183
+
184
+ ```jsx
185
+ <ConsoleUI
186
+ clusterList={clusterList}
187
+ dragConfig={{
188
+ enabled: false, // 完全禁用拖拽
189
+ tabDraggable: false // 禁用标签页拖拽
190
+ }}
191
+ resizeable={false} // 禁用窗口大小调整
192
+ sendRequestToES={sendRequest}
193
+ fetchDataSource={fetchData}
194
+ />
195
+ ```
196
+
197
+ ### 3. 自定义数据源和图标
198
+
199
+ ```jsx
200
+ import { DatabaseIcon, ServerIcon } from './icons';
201
+
202
+ <ConsoleUI
203
+ clusterList={clusterList}
204
+ SearchEngineIcon={<DatabaseIcon />}
205
+ LogoImg={<img src="/logo.png" alt="Company Logo" />}
206
+ renderTabBarItemIcon={(tab) => {
207
+ return tab.type === 'query' ? <ServerIcon /> : <DatabaseIcon />;
208
+ }}
209
+ DataSourceSelector={<CustomDataSourceSelector />}
210
+ sendRequestToES={sendRequest}
211
+ fetchDataSource={fetchData}
212
+ />
213
+ ```
214
+
215
+ ### 4. 嵌入式模式
216
+
217
+ ```jsx
218
+ // 适用于嵌入到现有应用中
219
+ <div style={{ border: '1px solid #d9d9d9', borderRadius: '6px' }}>
33
220
  <ConsoleUI
34
221
  clusterList={clusterList}
35
- visible={false}
36
- minimize={true}
37
- onMinimizeClick={() => {
38
- setConsoleOpen(false);
39
- window.parent.postMessage(false, "*");
40
- }}
41
- clusterStatus={clusterStatus}
42
- resizeable={true}
43
- sendRequestToES={sendRequestPlay}
44
- fetchDataSource={fetchDataSource}
45
- SearchEngineIcon={SearchEngineIcon}
46
- LogoImg={PizzaImg}
222
+ visible={true}
223
+ minimize={false} // 隐藏最小化按钮
224
+ resizeable={false} // 禁用大小调整
225
+ height="400px" // 固定高度
226
+ className="embedded-console"
227
+ sendRequestToES={sendRequest}
228
+ fetchDataSource={fetchData}
47
229
  />
48
- );
49
- //...
230
+ </div>
231
+ ```
232
+
233
+ ## 高级配置
234
+
235
+ ### 集群对象结构
236
+
237
+ ```javascript
238
+ const cluster = {
239
+ id: 'unique-cluster-id', // 必需:唯一标识符
240
+ name: 'Display Name', // 必需:显示名称
241
+ endpoint: 'https://es.example.com:9200', // 必需:连接端点
242
+ status: 'green|yellow|red', // 可选:集群状态
243
+ version: '8.5.0', // 可选:版本信息
244
+ username: 'elastic', // 可选:认证用户名
245
+ password: 'password', // 可选:认证密码
246
+ headers: { // 可选:自定义请求头
247
+ 'Authorization': 'Bearer token'
248
+ },
249
+ metadata: { // 可选:额外元数据
250
+ environment: 'production',
251
+ region: 'us-east-1'
252
+ }
253
+ };
254
+ ```
255
+
256
+ ### 拖拽配置详解
257
+
258
+ ```javascript
259
+ const dragConfig = {
260
+ enabled: true, // 总开关:是否启用所有拖拽功能
261
+ tabDraggable: true, // 标签页是否可以拖拽排序
262
+
263
+ // 高级配置(可选)
264
+ dragDelay: 100, // 拖拽延迟(毫秒)
265
+ dragThreshold: 5, // 拖拽阈值(像素)
266
+ animationDuration: 200, // 动画持续时间(毫秒)
267
+
268
+ // 拖拽限制
269
+ maxTabs: 10, // 最大标签页数量
270
+ allowCrossWindow: false // 是否允许跨窗口拖拽
271
+ };
272
+ ```
273
+
274
+ ### 请求处理函数
275
+
276
+ ```javascript
277
+ const sendRequestToES = async (requestData) => {
278
+ const { query, cluster, options = {} } = requestData;
279
+
280
+ try {
281
+ // 构建请求配置
282
+ const config = {
283
+ method: options.method || 'POST',
284
+ headers: {
285
+ 'Content-Type': 'application/json',
286
+ ...cluster.headers
287
+ },
288
+ body: JSON.stringify(query)
289
+ };
290
+
291
+ // 添加认证
292
+ if (cluster.username && cluster.password) {
293
+ config.headers['Authorization'] =
294
+ `Basic ${btoa(`${cluster.username}:${cluster.password}`)}`;
295
+ }
296
+
297
+ // 发送请求
298
+ const response = await fetch(
299
+ `${cluster.endpoint}${options.path || '/_search'}`,
300
+ config
301
+ );
302
+
303
+ if (!response.ok) {
304
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
305
+ }
306
+
307
+ const result = await response.json();
308
+
309
+ // 返回标准化结果
310
+ return {
311
+ success: true,
312
+ data: result,
313
+ took: result.took,
314
+ total: result.hits?.total?.value || 0,
315
+ timestamp: Date.now()
316
+ };
317
+
318
+ } catch (error) {
319
+ console.error('ES Request failed:', error);
320
+ return {
321
+ success: false,
322
+ error: error.message,
323
+ timestamp: Date.now()
324
+ };
325
+ }
326
+ };
327
+ ```
328
+
329
+ ## 样式自定义
330
+
331
+ ### CSS 变量
332
+
333
+ ```css
334
+ .console-ui {
335
+ /* 主题色彩 */
336
+ --console-primary-color: #1890ff;
337
+ --console-success-color: #52c41a;
338
+ --console-warning-color: #faad14;
339
+ --console-error-color: #ff4d4f;
340
+
341
+ /* 背景色 */
342
+ --console-bg-color: #ffffff;
343
+ --console-header-bg: #fafafa;
344
+ --console-tab-bg: #f5f5f5;
345
+
346
+ /* 文字色彩 */
347
+ --console-text-color: #333333;
348
+ --console-text-secondary: #666666;
349
+ --console-text-disabled: #999999;
350
+
351
+ /* 边框和阴影 */
352
+ --console-border-color: #d9d9d9;
353
+ --console-border-radius: 6px;
354
+ --console-box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
355
+ }
356
+ ```
357
+
358
+ ### 自定义样式类
359
+
360
+ ```css
361
+ /* 自定义标签页样式 */
362
+ .custom-console .console-tabs .ant-tabs-tab {
363
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
364
+ color: white;
365
+ border: none;
366
+ }
367
+
368
+ /* 自定义编辑器样式 */
369
+ .custom-console .console-editor {
370
+ font-family: 'Monaco', 'Menlo', monospace;
371
+ font-size: 14px;
372
+ line-height: 1.5;
373
+ }
374
+
375
+ /* 自定义结果面板 */
376
+ .custom-console .console-result {
377
+ background: #f8f9fa;
378
+ border-left: 4px solid #28a745;
379
+ }
50
380
  ```
51
381
 
52
- ## 参数
53
-
54
- | Property | Description | Type | Default | Version |
55
- | --------------------- | -------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------- | --------------------- | ------- |
56
- | minimize | 组件是否可以缩小 | boolean | false | 1.0.0 |
57
- | resizeable | 组件是否可以调整大小 | boolean | false | 1.0.0 |
58
- | height | 组件高度 | string | "50vh" | 1.0.0 |
59
- | DataSourceSelector | 数据源组件 | DOM | - | 1.0.0 |
60
- | tabData | 数据 | object | {activeKey: "", panes: []} | 1.0.0 |
61
- | renderTabBarItemIcon | 标题组件的 Icon | DOM | - | 1.0.0 |
62
- | addTab | 增加 tab 数据的方法 | function | - | 1.0.0 |
63
- | onMinimizeClick | 组件缩小按钮点击事件 | function | - | 1.0.0 |
64
- | newTabClick | 组件新增数据源按钮点击事件 | function | - | 1.0.0 |
65
- | updateTabData | 组件更新 tabData 数据方法 | function | - | 1.0.0 |
66
- | sendRequestToES | 组件点击执行按钮的事件 | function | - | 1.0.0 |
382
+ ## 常见问题
383
+
384
+ ### Q: 如何完全禁用拖拽功能?
385
+
386
+ A: 设置 `dragConfig={{ enabled: false, tabDraggable: false }}` 并将 `resizeable` 设为 `false`:
387
+
388
+ ```jsx
389
+ <ConsoleUI
390
+ dragConfig={{ enabled: false, tabDraggable: false }}
391
+ resizeable={false}
392
+ // ... 其他属性
393
+ />
394
+ ```
395
+
396
+ ### Q: 如何自定义请求超时时间?
397
+
398
+ A: 在 `sendRequestToES` 函数中使用 `AbortController`:
399
+
400
+ ```javascript
401
+ const sendRequestToES = async (requestData) => {
402
+ const controller = new AbortController();
403
+ const timeoutId = setTimeout(() => controller.abort(), 30000); // 30秒超时
404
+
405
+ try {
406
+ const response = await fetch(url, {
407
+ ...config,
408
+ signal: controller.signal
409
+ });
410
+ clearTimeout(timeoutId);
411
+ return await response.json();
412
+ } catch (error) {
413
+ clearTimeout(timeoutId);
414
+ throw error;
415
+ }
416
+ };
417
+ ```
418
+
419
+ ### Q: 如何处理大量数据的性能问题?
420
+
421
+ A: 组件内置了虚拟滚动和分页功能,可以通过以下方式优化:
422
+
423
+ ```jsx
424
+ <ConsoleUI
425
+ // 启用虚拟滚动
426
+ virtualScroll={true}
427
+ // 设置每页显示数量
428
+ pageSize={100}
429
+ // 启用懒加载
430
+ lazyLoad={true}
431
+ // ... 其他属性
432
+ />
433
+ ```
434
+
435
+ ### Q: 如何集成到现有的认证系统?
436
+
437
+ A: 通过 `clusterList` 传入认证信息,或在 `sendRequestToES` 中处理:
438
+
439
+ ```javascript
440
+ const clusterWithAuth = {
441
+ id: 'secure-cluster',
442
+ name: 'Secure Cluster',
443
+ endpoint: 'https://es.example.com:9200',
444
+ headers: {
445
+ 'Authorization': `Bearer ${getAuthToken()}`,
446
+ 'X-Custom-Header': 'custom-value'
447
+ }
448
+ };
449
+ ```
450
+
451
+ ## 更新日志
452
+
453
+ ### v1.2.0
454
+ - ✨ 新增拖拽功能配置选项 (`dragConfig`)
455
+ - 🐛 修复顶部拖拽区域在禁用时仍显示的问题
456
+ - 🎨 优化标签页拖拽体验
457
+ - 📝 完善文档和使用示例
458
+
459
+ ### v1.1.0
460
+ - ✨ 新增自定义工具栏支持
461
+ - 🚀 性能优化:虚拟滚动和懒加载
462
+ - 🎨 UI 样式优化
463
+ - 🐛 修复多个已知问题
464
+
465
+ ### v1.0.0
466
+ - 🎉 首次发布
467
+ - ✨ 基础功能:多标签页、拖拽、数据源切换
468
+ - 📱 响应式设计
469
+ - 🎨 主题定制支持
470
+
471
+ ## 许可证
472
+
473
+ MIT License
474
+
475
+ ## 贡献
476
+
477
+ 欢迎提交 Issue 和 Pull Request!
478
+
479
+ ## 支持
480
+
481
+ 如果您在使用过程中遇到问题,请通过以下方式获取帮助:
482
+
483
+ - 📧 邮箱:support@infinilabs.com
484
+ - 🐛 Issue:[GitHub Issues](https://github.com/infinilabs/ui-web-cli/issues)
485
+ - 📖 文档:[在线文档](https://docs.infinilabs.com/ui-web-cli)
package/README.md CHANGED
@@ -68,4 +68,6 @@ Here’s the English translation of the table:
68
68
  | onMinimizeClick | Event handler for minimize button click | function | - | 1.0.0 |
69
69
  | newTabClick | Event handler for adding a new data source | function | - | 1.0.0 |
70
70
  | updateTabData | Method to update the `tabData` | function | - | 1.0.0 |
71
- | sendRequestToES | Event handler for the execute button click | function | - | 1.0.0 |
71
+ | sendRequestToES | Event handler for the execute button click | function | - | 1.0.0 |
72
+
73
+