@gingkoo/pandora-metabase 1.0.54 → 1.0.55

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.
@@ -192,7 +192,7 @@ var SelectColumn = function SelectColumn(_ref) {
192
192
  children: (0, _jsxRuntime.jsx)(_icons.SelectIcon, {})
193
193
  }) : (0, _jsxRuntime.jsx)("div", {
194
194
  className: 'no-select mr-2'
195
- }), v.name, v.name_zh ? " \uFF08".concat(v.name_zh, "\uFF09") : '', v.fieldAlias ? " as ".concat(v.fieldAlias) : '', (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
195
+ }), v.name, v.name_zh ? " \uFF08".concat(v.name_zh, "\uFF09") : '', v.fieldAlias ? " as ".concat(v.fieldAlias) : '', store.fieldEnableAlias && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
196
196
  title: (0, _locale.__)('SqlQueryBuilder.alias'),
197
197
  children: (0, _jsxRuntime.jsx)(_pandora.Button, {
198
198
  className: ':Sqb-TableName-as',
@@ -1118,7 +1118,11 @@ var JoinData = function JoinData(props) {
1118
1118
  return oldCol.name === newCol.name;
1119
1119
  });
1120
1120
  // 如果存在,返回旧列;否则返回新列
1121
- return existingCol ? existingCol : newCol;
1121
+ // return existingCol ? existingCol : newCol;
1122
+ var _column = existingCol ? existingCol : newCol;
1123
+ _column.select = store.isSelectFields || _column.select;
1124
+ // 如果存在,返回旧列;否则返回新列
1125
+ return _column;
1122
1126
  });
1123
1127
  // (newMeta[index] as MetaJoin).columns = newColumns;
1124
1128
  initExpressions();
@@ -1466,61 +1470,149 @@ var JoinData = function JoinData(props) {
1466
1470
  onClick: function onClick() {
1467
1471
  showSubQuery(meta.subquery);
1468
1472
  },
1469
- children: [subQuerySelected && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
1470
- title: (0, _locale.__)(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
1471
- children: (0, _jsxRuntime.jsx)(_pandora.Button, {
1472
- danger: tableIsError(),
1473
- className: (0, _classnames["default"])(':Sqb-TableName-as', {
1474
- isError: tableIsError()
1475
- }),
1476
- shape: 'circle',
1477
- style: isDel ? {
1478
- fontSize: 18,
1479
- backgroundColor: '#fff',
1480
- width: 'auto',
1481
- height: 'auto'
1482
- } : {},
1483
- iconOnly: true,
1484
- primary: !isDel,
1485
- icon: isDel ? (0, _jsxRuntime.jsx)(_pandoraIcons.ExclamationCircleFill, {}) : 'As',
1486
- size: 'small',
1487
- onClick: function onClick(e) {
1488
- var _meta$table4;
1489
- e.stopPropagation();
1490
- onChangeTableAlias(((_meta$table4 = meta.table2) === null || _meta$table4 === void 0 ? void 0 : _meta$table4.alias) || '');
1491
- }
1492
- })
1493
- }), subQuerySelected ? "".concat(((_meta$subquery2 = meta.subquery) === null || _meta$subquery2 === void 0 ? void 0 : _meta$subquery2[0]).table.datasourceName, ".").concat(((_meta$subquery3 = meta.subquery) === null || _meta$subquery3 === void 0 ? void 0 : _meta$subquery3[0]).table.name, " ").concat((_meta$table5 = meta.table2) !== null && _meta$table5 !== void 0 && _meta$table5.alias ? "as ".concat((_meta$table6 = meta.table2) === null || _meta$table6 === void 0 ? void 0 : _meta$table6.alias) : '', " ") : (0, _locale.__)('SqlQueryBuilder.setSubQuery')]
1473
+ children: [subQuerySelected && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
1474
+ children: function () {
1475
+ var showButton = store.tableEnableAlias || tableIsError() && isDel;
1476
+ var icon = isDel ? (0, _jsxRuntime.jsx)(_pandoraIcons.ExclamationCircleFill, {}) : store.tableEnableAlias ? 'As' : '';
1477
+ return showButton ? (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
1478
+ title: (0, _locale.__)(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
1479
+ children: (0, _jsxRuntime.jsx)(_pandora.Button, {
1480
+ danger: tableIsError(),
1481
+ className: (0, _classnames["default"])(':Sqb-TableName-as', {
1482
+ isError: tableIsError()
1483
+ }),
1484
+ shape: 'circle',
1485
+ style: isDel ? {
1486
+ fontSize: 18,
1487
+ backgroundColor: '#fff',
1488
+ width: 'auto',
1489
+ height: 'auto'
1490
+ } : {},
1491
+ iconOnly: true,
1492
+ primary: !isDel,
1493
+ icon: icon,
1494
+ size: 'small',
1495
+ onClick: function onClick(e) {
1496
+ if (store.tableEnableAlias) {
1497
+ var _meta$table4;
1498
+ e.stopPropagation();
1499
+ onChangeTableAlias(((_meta$table4 = meta.table2) === null || _meta$table4 === void 0 ? void 0 : _meta$table4.alias) || '');
1500
+ }
1501
+ }
1502
+ })
1503
+ }) : null;
1504
+ }()
1505
+ })
1506
+ // <Tooltip
1507
+ // title={__(
1508
+ // tableIsError()
1509
+ // ? isDel
1510
+ // ? 'metabase.verify'
1511
+ // : 'SqlQueryBuilder.repeatAlias'
1512
+ // : 'SqlQueryBuilder.alias',
1513
+ // )}
1514
+ // >
1515
+ // <Button
1516
+ // danger={tableIsError()}
1517
+ // className={cx(':Sqb-TableName-as', {
1518
+ // isError: tableIsError(),
1519
+ // })}
1520
+ // shape='circle'
1521
+ // style={
1522
+ // isDel
1523
+ // ? {
1524
+ // fontSize: 18,
1525
+ // backgroundColor: '#fff',
1526
+ // width: 'auto',
1527
+ // height: 'auto',
1528
+ // }
1529
+ // : {}
1530
+ // }
1531
+ // iconOnly
1532
+ // primary={!isDel}
1533
+ // icon={isDel ? <ExclamationCircleFill /> : 'As'}
1534
+ // size='small'
1535
+ // onClick={(e) => {
1536
+ // e.stopPropagation();
1537
+ // onChangeTableAlias(meta.table2?.alias || '');
1538
+ // }}
1539
+ // ></Button>
1540
+ // </Tooltip>
1541
+ , subQuerySelected ? "".concat(((_meta$subquery2 = meta.subquery) === null || _meta$subquery2 === void 0 ? void 0 : _meta$subquery2[0]).table.datasourceName, ".").concat(((_meta$subquery3 = meta.subquery) === null || _meta$subquery3 === void 0 ? void 0 : _meta$subquery3[0]).table.name, " ").concat((_meta$table5 = meta.table2) !== null && _meta$table5 !== void 0 && _meta$table5.alias ? "as ".concat((_meta$table6 = meta.table2) === null || _meta$table6 === void 0 ? void 0 : _meta$table6.alias) : '', " ") : (0, _locale.__)('SqlQueryBuilder.setSubQuery')]
1494
1542
  }) : (0, _jsxRuntime.jsxs)("div", {
1495
1543
  className: (0, _classnames["default"])("Sqb-TableName", {
1496
1544
  notSelected: !table2Selected
1497
1545
  }),
1498
1546
  onClick: selectTable,
1499
- children: [table2Selected && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
1500
- title: (0, _locale.__)(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
1501
- children: (0, _jsxRuntime.jsx)(_pandora.Button, {
1502
- danger: tableIsError(),
1503
- className: (0, _classnames["default"])(':Sqb-TableName-as', {
1504
- isError: tableIsError()
1505
- }),
1506
- shape: 'circle',
1507
- style: isDel ? {
1508
- fontSize: 18,
1509
- backgroundColor: '#fff',
1510
- width: 'auto',
1511
- height: 'auto'
1512
- } : {},
1513
- iconOnly: true,
1514
- primary: !isDel,
1515
- icon: isDel ? (0, _jsxRuntime.jsx)(_pandoraIcons.ExclamationCircleFill, {}) : 'As',
1516
- size: 'small',
1517
- onClick: function onClick(e) {
1518
- var _meta$table7;
1519
- e.stopPropagation();
1520
- onChangeTableAlias(((_meta$table7 = meta.table2) === null || _meta$table7 === void 0 ? void 0 : _meta$table7.alias) || '');
1521
- }
1522
- })
1523
- }), table2Selected ? "".concat(meta.table2.datasourceName, ".").concat(meta.table2.name, " ").concat((_meta$table8 = meta.table2) !== null && _meta$table8 !== void 0 && _meta$table8.alias ? "as ".concat((_meta$table9 = meta.table2) === null || _meta$table9 === void 0 ? void 0 : _meta$table9.alias) : '') : (0, _locale.__)('SqlQueryBuilder.pickTable')]
1547
+ children: [table2Selected && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
1548
+ children: function () {
1549
+ var showButton = store.tableEnableAlias || tableIsError() && isDel;
1550
+ var icon = isDel ? (0, _jsxRuntime.jsx)(_pandoraIcons.ExclamationCircleFill, {}) : store.tableEnableAlias ? 'As' : '';
1551
+ return showButton ? (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
1552
+ title: (0, _locale.__)(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
1553
+ children: (0, _jsxRuntime.jsx)(_pandora.Button, {
1554
+ danger: tableIsError(),
1555
+ className: (0, _classnames["default"])(':Sqb-TableName-as', {
1556
+ isError: tableIsError()
1557
+ }),
1558
+ shape: 'circle',
1559
+ style: isDel ? {
1560
+ fontSize: 18,
1561
+ backgroundColor: '#fff',
1562
+ width: 'auto',
1563
+ height: 'auto'
1564
+ } : {},
1565
+ iconOnly: true,
1566
+ primary: !isDel,
1567
+ icon: icon,
1568
+ size: 'small',
1569
+ onClick: function onClick(e) {
1570
+ if (store.tableEnableAlias) {
1571
+ var _meta$table7;
1572
+ e.stopPropagation();
1573
+ onChangeTableAlias(((_meta$table7 = meta.table2) === null || _meta$table7 === void 0 ? void 0 : _meta$table7.alias) || '');
1574
+ }
1575
+ }
1576
+ })
1577
+ }) : null;
1578
+ }()
1579
+ })
1580
+ // <Tooltip
1581
+ // title={__(
1582
+ // tableIsError()
1583
+ // ? isDel
1584
+ // ? 'metabase.verify'
1585
+ // : 'SqlQueryBuilder.repeatAlias'
1586
+ // : 'SqlQueryBuilder.alias',
1587
+ // )}
1588
+ // >
1589
+ // <Button
1590
+ // danger={tableIsError()}
1591
+ // className={cx(':Sqb-TableName-as', {
1592
+ // isError: tableIsError(),
1593
+ // })}
1594
+ // shape='circle'
1595
+ // style={
1596
+ // isDel
1597
+ // ? {
1598
+ // fontSize: 18,
1599
+ // backgroundColor: '#fff',
1600
+ // width: 'auto',
1601
+ // height: 'auto',
1602
+ // }
1603
+ // : {}
1604
+ // }
1605
+ // iconOnly
1606
+ // primary={!isDel}
1607
+ // icon={isDel ? <ExclamationCircleFill /> : 'As'}
1608
+ // size='small'
1609
+ // onClick={(e) => {
1610
+ // e.stopPropagation();
1611
+ // onChangeTableAlias(meta.table2?.alias || '');
1612
+ // }}
1613
+ // ></Button>
1614
+ // </Tooltip>
1615
+ , table2Selected ? "".concat(meta.table2.datasourceName, ".").concat(meta.table2.name, " ").concat((_meta$table8 = meta.table2) !== null && _meta$table8 !== void 0 && _meta$table8.alias ? "as ".concat((_meta$table9 = meta.table2) === null || _meta$table9 === void 0 ? void 0 : _meta$table9.alias) : '') : (0, _locale.__)('SqlQueryBuilder.pickTable')]
1524
1616
  }), store.showSubquery && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
1525
1617
  title: (0, _locale.__)('SqlQueryBuilder.switchSubQuery'),
1526
1618
  children: (0, _jsxRuntime.jsx)(_pandora.Button, {
@@ -328,19 +328,21 @@ var GroupBy = function GroupBy(props) {
328
328
  onClick: function onClick(e) {
329
329
  return handleUpdate(e, i);
330
330
  },
331
- children: [v.quotes && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
332
- title: (0, _locale.__)('SqlQueryBuilder.alias'),
333
- children: (0, _jsxRuntime.jsx)(_pandora.Button, {
334
- className: ':Sqb-TableName-as :Sqb-TableName green-name',
335
- shape: 'circle',
336
- iconOnly: true,
337
- primary: true,
338
- icon: 'As',
339
- size: 'small',
340
- onClick: function onClick(e) {
341
- e.stopPropagation();
342
- onChangeFieldAlias((v === null || v === void 0 ? void 0 : v.fieldAlias) || '', i);
343
- }
331
+ children: [v.quotes && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
332
+ children: store.fieldEnableAlias && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
333
+ title: (0, _locale.__)('SqlQueryBuilder.alias'),
334
+ children: (0, _jsxRuntime.jsx)(_pandora.Button, {
335
+ className: ':Sqb-TableName-as :Sqb-TableName green-name',
336
+ shape: 'circle',
337
+ iconOnly: true,
338
+ primary: true,
339
+ icon: 'As',
340
+ size: 'small',
341
+ onClick: function onClick(e) {
342
+ e.stopPropagation();
343
+ onChangeFieldAlias((v === null || v === void 0 ? void 0 : v.fieldAlias) || '', i);
344
+ }
345
+ })
344
346
  })
345
347
  }), "".concat(v.quotes, " ").concat(v.fieldAlias ? "as ".concat(v.fieldAlias) : ''), (0, _jsxRuntime.jsx)("span", {
346
348
  style: {
@@ -329,19 +329,21 @@ var SelectIndex = function SelectIndex(props) {
329
329
  onClick: function onClick(e) {
330
330
  return handleUpdate(e, i);
331
331
  },
332
- children: [v.quotes && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
333
- title: (0, _locale.__)('SqlQueryBuilder.alias'),
334
- children: (0, _jsxRuntime.jsx)(_pandora.Button, {
335
- className: ':Sqb-TableName-as :Sqb-TableName green-name',
336
- shape: 'circle',
337
- iconOnly: true,
338
- primary: true,
339
- icon: 'As',
340
- size: 'small',
341
- onClick: function onClick(e) {
342
- e.stopPropagation();
343
- onChangeFieldAlias((v === null || v === void 0 ? void 0 : v.fieldAlias) || '', i);
344
- }
332
+ children: [v.quotes && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
333
+ children: store.fieldEnableAlias && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
334
+ title: (0, _locale.__)('SqlQueryBuilder.alias'),
335
+ children: (0, _jsxRuntime.jsx)(_pandora.Button, {
336
+ className: ':Sqb-TableName-as :Sqb-TableName green-name',
337
+ shape: 'circle',
338
+ iconOnly: true,
339
+ primary: true,
340
+ icon: 'As',
341
+ size: 'small',
342
+ onClick: function onClick(e) {
343
+ e.stopPropagation();
344
+ onChangeFieldAlias((v === null || v === void 0 ? void 0 : v.fieldAlias) || '', i);
345
+ }
346
+ })
345
347
  })
346
348
  }), "".concat(v.quotes, " ").concat(v.fieldAlias ? "as ".concat(v.fieldAlias) : ''), (0, _jsxRuntime.jsx)("span", {
347
349
  style: {
@@ -221,8 +221,10 @@ var TableData = function TableData(props) {
221
221
  var existingCol = newMetaList.columns.find(function (oldCol) {
222
222
  return oldCol.name === newCol.name;
223
223
  });
224
+ var _column = existingCol ? existingCol : newCol;
225
+ _column.select = store.isSelectFields || _column.select;
224
226
  // 如果存在,返回旧列;否则返回新列
225
- return existingCol ? existingCol : newCol;
227
+ return _column;
226
228
  });
227
229
  // (newMeta[index] as MetaJoin).expressions = [];
228
230
  var newMetas = store.metaList[groupIndex].list.slice();
@@ -290,61 +292,113 @@ var TableData = function TableData(props) {
290
292
  onClick: function onClick() {
291
293
  showSubQuery(meta.subquery);
292
294
  },
293
- children: [subQuerySelected && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
294
- title: (0, _locale.__)(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
295
- children: (0, _jsxRuntime.jsx)(_pandora.Button, {
296
- danger: tableIsError(),
297
- className: (0, _classnames["default"])(':Sqb-TableName-as', {
298
- isError: tableIsError()
299
- }),
300
- shape: 'circle',
301
- style: isDel ? {
302
- fontSize: 18,
303
- backgroundColor: '#fff',
304
- width: 'auto',
305
- height: 'auto'
306
- } : {},
307
- iconOnly: true,
308
- primary: !isDel,
309
- icon: isDel ? (0, _jsxRuntime.jsx)(_pandoraIcons.ExclamationCircleFill, {}) : 'As',
310
- size: 'small',
311
- onClick: function onClick(e) {
312
- var _meta$table4;
313
- e.stopPropagation();
314
- onChangeTableAlias(((_meta$table4 = meta.table) === null || _meta$table4 === void 0 ? void 0 : _meta$table4.alias) || '');
315
- }
316
- })
295
+ children: [subQuerySelected && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
296
+ children: function () {
297
+ var showButton = store.tableEnableAlias || tableIsError() && isDel;
298
+ var icon = isDel ? (0, _jsxRuntime.jsx)(_pandoraIcons.ExclamationCircleFill, {}) : store.tableEnableAlias ? 'As' : '';
299
+ return showButton ? (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
300
+ title: (0, _locale.__)(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
301
+ children: (0, _jsxRuntime.jsx)(_pandora.Button, {
302
+ danger: tableIsError(),
303
+ className: (0, _classnames["default"])(':Sqb-TableName-as', {
304
+ isError: tableIsError()
305
+ }),
306
+ shape: 'circle',
307
+ style: isDel ? {
308
+ fontSize: 18,
309
+ backgroundColor: '#fff',
310
+ width: 'auto',
311
+ height: 'auto'
312
+ } : {},
313
+ iconOnly: true,
314
+ primary: !isDel,
315
+ icon: icon,
316
+ size: 'small',
317
+ onClick: function onClick(e) {
318
+ if (store.tableEnableAlias) {
319
+ var _meta$table4;
320
+ e.stopPropagation();
321
+ onChangeTableAlias(((_meta$table4 = meta.table) === null || _meta$table4 === void 0 ? void 0 : _meta$table4.alias) || '');
322
+ }
323
+ }
324
+ })
325
+ }) : null;
326
+ }()
317
327
  }), subQuerySelected ? "".concat(((_meta$subquery2 = meta.subquery) === null || _meta$subquery2 === void 0 ? void 0 : _meta$subquery2[0]).table.datasourceName, ".").concat(((_meta$subquery3 = meta.subquery) === null || _meta$subquery3 === void 0 ? void 0 : _meta$subquery3[0]).table.name, " ").concat((_meta$table5 = meta.table) !== null && _meta$table5 !== void 0 && _meta$table5.alias ? "as ".concat((_meta$table6 = meta.table) === null || _meta$table6 === void 0 ? void 0 : _meta$table6.alias) : '', " ") : (0, _locale.__)('SqlQueryBuilder.setSubQuery')]
318
328
  }) : (0, _jsxRuntime.jsxs)("div", {
319
329
  className: (0, _classnames["default"])("Sqb-TableName", {
320
330
  notSelected: !selected
321
331
  }),
322
332
  onClick: selectTable,
323
- children: [selected && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
324
- title: (0, _locale.__)(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
325
- children: (0, _jsxRuntime.jsx)(_pandora.Button, {
326
- danger: tableIsError(),
327
- className: (0, _classnames["default"])(':Sqb-TableName-as', {
328
- isError: tableIsError()
329
- }),
330
- shape: 'circle',
331
- style: isDel ? {
332
- fontSize: 18,
333
- backgroundColor: '#fff',
334
- width: 'auto',
335
- height: 'auto'
336
- } : {},
337
- iconOnly: true,
338
- primary: !isDel,
339
- icon: isDel ? (0, _jsxRuntime.jsx)(_pandoraIcons.ExclamationCircleFill, {}) : 'As',
340
- size: 'small',
341
- onClick: function onClick(e) {
342
- var _meta$table7;
343
- e.stopPropagation();
344
- onChangeTableAlias(((_meta$table7 = meta.table) === null || _meta$table7 === void 0 ? void 0 : _meta$table7.alias) || '');
345
- }
346
- })
347
- }), selected ? "".concat(meta.table.datasourceName, ".").concat(meta.table.name, " ").concat((_meta$table8 = meta.table) !== null && _meta$table8 !== void 0 && _meta$table8.alias ? "as ".concat((_meta$table9 = meta.table) === null || _meta$table9 === void 0 ? void 0 : _meta$table9.alias) : '') : (0, _locale.__)('SqlQueryBuilder.pickTable')]
333
+ children: [selected && (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
334
+ children: function () {
335
+ var showButton = store.tableEnableAlias || tableIsError() && isDel;
336
+ var icon = isDel ? (0, _jsxRuntime.jsx)(_pandoraIcons.ExclamationCircleFill, {}) : store.tableEnableAlias ? 'As' : '';
337
+ return showButton ? (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
338
+ title: (0, _locale.__)(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
339
+ children: (0, _jsxRuntime.jsx)(_pandora.Button, {
340
+ danger: tableIsError(),
341
+ className: (0, _classnames["default"])(':Sqb-TableName-as', {
342
+ isError: tableIsError()
343
+ }),
344
+ shape: 'circle',
345
+ style: isDel ? {
346
+ fontSize: 18,
347
+ backgroundColor: '#fff',
348
+ width: 'auto',
349
+ height: 'auto'
350
+ } : {},
351
+ iconOnly: true,
352
+ primary: !isDel,
353
+ icon: icon,
354
+ size: 'small',
355
+ onClick: function onClick(e) {
356
+ if (store.tableEnableAlias) {
357
+ var _meta$table7;
358
+ e.stopPropagation();
359
+ onChangeTableAlias(((_meta$table7 = meta.table) === null || _meta$table7 === void 0 ? void 0 : _meta$table7.alias) || '');
360
+ }
361
+ }
362
+ })
363
+ }) : null;
364
+ }()
365
+ })
366
+ // <Tooltip
367
+ // title={__(
368
+ // tableIsError()
369
+ // ? isDel
370
+ // ? 'metabase.verify'
371
+ // : 'SqlQueryBuilder.repeatAlias'
372
+ // : 'SqlQueryBuilder.alias',
373
+ // )}
374
+ // >
375
+ // <Button
376
+ // danger={tableIsError()}
377
+ // className={cx(':Sqb-TableName-as', {
378
+ // isError: tableIsError(),
379
+ // })}
380
+ // shape='circle'
381
+ // style={
382
+ // isDel
383
+ // ? {
384
+ // fontSize: 18,
385
+ // backgroundColor: '#fff',
386
+ // width: 'auto',
387
+ // height: 'auto',
388
+ // }
389
+ // : {}
390
+ // }
391
+ // iconOnly
392
+ // primary={!isDel}
393
+ // icon={isDel ? <ExclamationCircleFill /> : 'As'}
394
+ // size='small'
395
+ // onClick={(e) => {
396
+ // e.stopPropagation();
397
+ // onChangeTableAlias(meta.table?.alias || '');
398
+ // }}
399
+ // ></Button>
400
+ // </Tooltip>
401
+ , selected ? "".concat(meta.table.datasourceName, ".").concat(meta.table.name, " ").concat((_meta$table8 = meta.table) !== null && _meta$table8 !== void 0 && _meta$table8.alias ? "as ".concat((_meta$table9 = meta.table) === null || _meta$table9 === void 0 ? void 0 : _meta$table9.alias) : '') : (0, _locale.__)('SqlQueryBuilder.pickTable')]
348
402
  }), store.showSubquery && (0, _jsxRuntime.jsx)(_pandora.Tooltip, {
349
403
  title: (0, _locale.__)('SqlQueryBuilder.switchSubQuery'),
350
404
  children: (0, _jsxRuntime.jsx)(_pandora.Button, {
@@ -133,6 +133,18 @@ var useStore = function useStore() {
133
133
  _useState38 = (0, _slicedToArray2["default"])(_useState37, 2),
134
134
  isExit = _useState38[0],
135
135
  setIsExit = _useState38[1]; // 是否是notExit
136
+ var _useState39 = (0, _react.useState)(true),
137
+ _useState40 = (0, _slicedToArray2["default"])(_useState39, 2),
138
+ tableEnableAlias = _useState40[0],
139
+ setTableEnableAlias = _useState40[1]; // 表名是否开启别名
140
+ var _useState41 = (0, _react.useState)(true),
141
+ _useState42 = (0, _slicedToArray2["default"])(_useState41, 2),
142
+ fieldEnableAlias = _useState42[0],
143
+ setFieldEnableAlias = _useState42[1]; // 字段名是否开启别名
144
+ var _useState43 = (0, _react.useState)(true),
145
+ _useState44 = (0, _slicedToArray2["default"])(_useState43, 2),
146
+ isSelectFields = _useState44[0],
147
+ setIsSelectFields = _useState44[1]; // 是否默认勾选字段
136
148
  // 外层ref
137
149
  var popupContainer = (0, _react.useRef)();
138
150
  // const [fetchDatasetFn, setFetchDatasetFn] = useState<(id: string) => Promise<any>>(
@@ -271,7 +283,7 @@ var useStore = function useStore() {
271
283
  var obj = {};
272
284
  obj = oldObj[v.id] || {};
273
285
  return (0, _objectSpread2["default"])((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, obj), v), {}, {
274
- select: select,
286
+ select: isSelectFields || select,
275
287
  fieldUuid: obj.fieldUuid || v.fieldUuid || (0, _helper.uuidv4)('field')
276
288
  });
277
289
  });
@@ -609,7 +621,13 @@ var useStore = function useStore() {
609
621
  formulaTemplates: formulaTemplates,
610
622
  setFormulaTemplates: setFormulaTemplates,
611
623
  isExit: isExit,
612
- setIsExit: setIsExit
624
+ setIsExit: setIsExit,
625
+ tableEnableAlias: tableEnableAlias,
626
+ setTableEnableAlias: setTableEnableAlias,
627
+ fieldEnableAlias: fieldEnableAlias,
628
+ setFieldEnableAlias: setFieldEnableAlias,
629
+ isSelectFields: isSelectFields,
630
+ setIsSelectFields: setIsSelectFields
613
631
  };
614
632
  };
615
633
  var _default = exports["default"] = useStore;
package/lib/cjs/index.js CHANGED
@@ -43,6 +43,8 @@ var SqlVisionBuilder = _react["default"].forwardRef(function (props, ref) {
43
43
  value = _props$value === void 0 ? [] : _props$value,
44
44
  _props$sourceList = props.sourceList,
45
45
  sourceList = _props$sourceList === void 0 ? [] : _props$sourceList,
46
+ _props$exitSourceList = props.exitSourceList,
47
+ exitSourceList = _props$exitSourceList === void 0 ? [] : _props$exitSourceList,
46
48
  _props$showSubquery = props.showSubquery,
47
49
  showSubquery = _props$showSubquery === void 0 ? true : _props$showSubquery,
48
50
  _props$subShowSubquer = props.subShowSubquery,
@@ -54,7 +56,13 @@ var SqlVisionBuilder = _react["default"].forwardRef(function (props, ref) {
54
56
  _props$filterCustomTy = props.filterCustomType,
55
57
  filterCustomType = _props$filterCustomTy === void 0 ? false : _props$filterCustomTy,
56
58
  _props$isExit = props.isExit,
57
- isExit = _props$isExit === void 0 ? false : _props$isExit;
59
+ isExit = _props$isExit === void 0 ? false : _props$isExit,
60
+ _props$tableEnableAli = props.tableEnableAlias,
61
+ tableEnableAlias = _props$tableEnableAli === void 0 ? true : _props$tableEnableAli,
62
+ _props$fieldEnableAli = props.fieldEnableAlias,
63
+ fieldEnableAlias = _props$fieldEnableAli === void 0 ? true : _props$fieldEnableAli,
64
+ _props$isSelectFields = props.isSelectFields,
65
+ isSelectFields = _props$isSelectFields === void 0 ? true : _props$isSelectFields;
58
66
  var store = (0, _useState["default"])();
59
67
  (0, _react.useEffect)(function () {
60
68
  getTables && store.setFetchDatasetFn(getTables);
@@ -68,8 +76,8 @@ var SqlVisionBuilder = _react["default"].forwardRef(function (props, ref) {
68
76
  store.setPreData(_value);
69
77
  }, [value]);
70
78
  (0, _react.useEffect)(function () {
71
- store.setSourceList(sourceList);
72
- }, [sourceList]);
79
+ store.setSourceList(isExit && exitSourceList && Array.from(exitSourceList).length > 0 ? exitSourceList || sourceList : sourceList);
80
+ }, [sourceList, exitSourceList, isExit]);
73
81
  (0, _react.useEffect)(function () {
74
82
  store.setShowFields(showFields);
75
83
  store.setFieldNameTpl(fieldNameTpl || '${name}');
@@ -82,7 +90,10 @@ var SqlVisionBuilder = _react["default"].forwardRef(function (props, ref) {
82
90
  store.setIgnoreGroupByType(ignoreGroupByType);
83
91
  store.setfilterCustomType(filterCustomType);
84
92
  store.setIsExit(isExit);
85
- }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, formulaTemplates, ignoreGroupByType, filterCustomType, isExit]);
93
+ store.setTableEnableAlias(tableEnableAlias);
94
+ store.setFieldEnableAlias(fieldEnableAlias);
95
+ store.setIsSelectFields(isSelectFields);
96
+ }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, formulaTemplates, ignoreGroupByType, filterCustomType, isExit, tableEnableAlias, fieldEnableAlias, isSelectFields]);
86
97
  _react["default"].useImperativeHandle(ref, function () {
87
98
  return {
88
99
  // setDatasource: (list) => {
@@ -25,6 +25,7 @@ export interface MetabaseProps {
25
25
  onOk?: (params: any) => void;
26
26
  value?: MetaListType[];
27
27
  sourceList?: DatasourceType[];
28
+ exitSourceList?: DatasourceType[];
28
29
  showSubquery?: boolean;
29
30
  subShowSubquery?: boolean;
30
31
  constantList?: OptionItem[];
@@ -34,6 +35,9 @@ export interface MetabaseProps {
34
35
  notExistsColumns?: DataType[];
35
36
  formulaTemplates?: FormulaTemplatesItem[];
36
37
  isExit?: boolean;
38
+ tableEnableAlias?: boolean;
39
+ fieldEnableAlias?: boolean;
40
+ isSelectFields?: boolean;
37
41
  }
38
42
  export interface OptionItem {
39
43
  value?: string;
@@ -185,7 +185,7 @@ var SelectColumn = function SelectColumn(_ref) {
185
185
  children: _jsx(SelectIcon, {})
186
186
  }) : _jsx("div", {
187
187
  className: 'no-select mr-2'
188
- }), v.name, v.name_zh ? " \uFF08".concat(v.name_zh, "\uFF09") : '', v.fieldAlias ? " as ".concat(v.fieldAlias) : '', _jsx(Tooltip, {
188
+ }), v.name, v.name_zh ? " \uFF08".concat(v.name_zh, "\uFF09") : '', v.fieldAlias ? " as ".concat(v.fieldAlias) : '', store.fieldEnableAlias && _jsx(Tooltip, {
189
189
  title: __('SqlQueryBuilder.alias'),
190
190
  children: _jsx(Button, {
191
191
  className: ':Sqb-TableName-as',
@@ -1113,7 +1113,11 @@ var JoinData = function JoinData(props) {
1113
1113
  return oldCol.name === newCol.name;
1114
1114
  });
1115
1115
  // 如果存在,返回旧列;否则返回新列
1116
- return existingCol ? existingCol : newCol;
1116
+ // return existingCol ? existingCol : newCol;
1117
+ var _column = existingCol ? existingCol : newCol;
1118
+ _column.select = store.isSelectFields || _column.select;
1119
+ // 如果存在,返回旧列;否则返回新列
1120
+ return _column;
1117
1121
  });
1118
1122
  // (newMeta[index] as MetaJoin).columns = newColumns;
1119
1123
  initExpressions();
@@ -1461,61 +1465,149 @@ var JoinData = function JoinData(props) {
1461
1465
  onClick: function onClick() {
1462
1466
  showSubQuery(meta.subquery);
1463
1467
  },
1464
- children: [subQuerySelected && _jsx(Tooltip, {
1465
- title: __(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
1466
- children: _jsx(Button, {
1467
- danger: tableIsError(),
1468
- className: cx(':Sqb-TableName-as', {
1469
- isError: tableIsError()
1470
- }),
1471
- shape: 'circle',
1472
- style: isDel ? {
1473
- fontSize: 18,
1474
- backgroundColor: '#fff',
1475
- width: 'auto',
1476
- height: 'auto'
1477
- } : {},
1478
- iconOnly: true,
1479
- primary: !isDel,
1480
- icon: isDel ? _jsx(ExclamationCircleFill, {}) : 'As',
1481
- size: 'small',
1482
- onClick: function onClick(e) {
1483
- var _meta$table4;
1484
- e.stopPropagation();
1485
- onChangeTableAlias(((_meta$table4 = meta.table2) === null || _meta$table4 === void 0 ? void 0 : _meta$table4.alias) || '');
1486
- }
1487
- })
1488
- }), subQuerySelected ? "".concat(((_meta$subquery2 = meta.subquery) === null || _meta$subquery2 === void 0 ? void 0 : _meta$subquery2[0]).table.datasourceName, ".").concat(((_meta$subquery3 = meta.subquery) === null || _meta$subquery3 === void 0 ? void 0 : _meta$subquery3[0]).table.name, " ").concat((_meta$table5 = meta.table2) !== null && _meta$table5 !== void 0 && _meta$table5.alias ? "as ".concat((_meta$table6 = meta.table2) === null || _meta$table6 === void 0 ? void 0 : _meta$table6.alias) : '', " ") : __('SqlQueryBuilder.setSubQuery')]
1468
+ children: [subQuerySelected && _jsx(_Fragment, {
1469
+ children: function () {
1470
+ var showButton = store.tableEnableAlias || tableIsError() && isDel;
1471
+ var icon = isDel ? _jsx(ExclamationCircleFill, {}) : store.tableEnableAlias ? 'As' : '';
1472
+ return showButton ? _jsx(Tooltip, {
1473
+ title: __(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
1474
+ children: _jsx(Button, {
1475
+ danger: tableIsError(),
1476
+ className: cx(':Sqb-TableName-as', {
1477
+ isError: tableIsError()
1478
+ }),
1479
+ shape: 'circle',
1480
+ style: isDel ? {
1481
+ fontSize: 18,
1482
+ backgroundColor: '#fff',
1483
+ width: 'auto',
1484
+ height: 'auto'
1485
+ } : {},
1486
+ iconOnly: true,
1487
+ primary: !isDel,
1488
+ icon: icon,
1489
+ size: 'small',
1490
+ onClick: function onClick(e) {
1491
+ if (store.tableEnableAlias) {
1492
+ var _meta$table4;
1493
+ e.stopPropagation();
1494
+ onChangeTableAlias(((_meta$table4 = meta.table2) === null || _meta$table4 === void 0 ? void 0 : _meta$table4.alias) || '');
1495
+ }
1496
+ }
1497
+ })
1498
+ }) : null;
1499
+ }()
1500
+ })
1501
+ // <Tooltip
1502
+ // title={__(
1503
+ // tableIsError()
1504
+ // ? isDel
1505
+ // ? 'metabase.verify'
1506
+ // : 'SqlQueryBuilder.repeatAlias'
1507
+ // : 'SqlQueryBuilder.alias',
1508
+ // )}
1509
+ // >
1510
+ // <Button
1511
+ // danger={tableIsError()}
1512
+ // className={cx(':Sqb-TableName-as', {
1513
+ // isError: tableIsError(),
1514
+ // })}
1515
+ // shape='circle'
1516
+ // style={
1517
+ // isDel
1518
+ // ? {
1519
+ // fontSize: 18,
1520
+ // backgroundColor: '#fff',
1521
+ // width: 'auto',
1522
+ // height: 'auto',
1523
+ // }
1524
+ // : {}
1525
+ // }
1526
+ // iconOnly
1527
+ // primary={!isDel}
1528
+ // icon={isDel ? <ExclamationCircleFill /> : 'As'}
1529
+ // size='small'
1530
+ // onClick={(e) => {
1531
+ // e.stopPropagation();
1532
+ // onChangeTableAlias(meta.table2?.alias || '');
1533
+ // }}
1534
+ // ></Button>
1535
+ // </Tooltip>
1536
+ , subQuerySelected ? "".concat(((_meta$subquery2 = meta.subquery) === null || _meta$subquery2 === void 0 ? void 0 : _meta$subquery2[0]).table.datasourceName, ".").concat(((_meta$subquery3 = meta.subquery) === null || _meta$subquery3 === void 0 ? void 0 : _meta$subquery3[0]).table.name, " ").concat((_meta$table5 = meta.table2) !== null && _meta$table5 !== void 0 && _meta$table5.alias ? "as ".concat((_meta$table6 = meta.table2) === null || _meta$table6 === void 0 ? void 0 : _meta$table6.alias) : '', " ") : __('SqlQueryBuilder.setSubQuery')]
1489
1537
  }) : _jsxs("div", {
1490
1538
  className: cx("Sqb-TableName", {
1491
1539
  notSelected: !table2Selected
1492
1540
  }),
1493
1541
  onClick: selectTable,
1494
- children: [table2Selected && _jsx(Tooltip, {
1495
- title: __(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
1496
- children: _jsx(Button, {
1497
- danger: tableIsError(),
1498
- className: cx(':Sqb-TableName-as', {
1499
- isError: tableIsError()
1500
- }),
1501
- shape: 'circle',
1502
- style: isDel ? {
1503
- fontSize: 18,
1504
- backgroundColor: '#fff',
1505
- width: 'auto',
1506
- height: 'auto'
1507
- } : {},
1508
- iconOnly: true,
1509
- primary: !isDel,
1510
- icon: isDel ? _jsx(ExclamationCircleFill, {}) : 'As',
1511
- size: 'small',
1512
- onClick: function onClick(e) {
1513
- var _meta$table7;
1514
- e.stopPropagation();
1515
- onChangeTableAlias(((_meta$table7 = meta.table2) === null || _meta$table7 === void 0 ? void 0 : _meta$table7.alias) || '');
1516
- }
1517
- })
1518
- }), table2Selected ? "".concat(meta.table2.datasourceName, ".").concat(meta.table2.name, " ").concat((_meta$table8 = meta.table2) !== null && _meta$table8 !== void 0 && _meta$table8.alias ? "as ".concat((_meta$table9 = meta.table2) === null || _meta$table9 === void 0 ? void 0 : _meta$table9.alias) : '') : __('SqlQueryBuilder.pickTable')]
1542
+ children: [table2Selected && _jsx(_Fragment, {
1543
+ children: function () {
1544
+ var showButton = store.tableEnableAlias || tableIsError() && isDel;
1545
+ var icon = isDel ? _jsx(ExclamationCircleFill, {}) : store.tableEnableAlias ? 'As' : '';
1546
+ return showButton ? _jsx(Tooltip, {
1547
+ title: __(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
1548
+ children: _jsx(Button, {
1549
+ danger: tableIsError(),
1550
+ className: cx(':Sqb-TableName-as', {
1551
+ isError: tableIsError()
1552
+ }),
1553
+ shape: 'circle',
1554
+ style: isDel ? {
1555
+ fontSize: 18,
1556
+ backgroundColor: '#fff',
1557
+ width: 'auto',
1558
+ height: 'auto'
1559
+ } : {},
1560
+ iconOnly: true,
1561
+ primary: !isDel,
1562
+ icon: icon,
1563
+ size: 'small',
1564
+ onClick: function onClick(e) {
1565
+ if (store.tableEnableAlias) {
1566
+ var _meta$table7;
1567
+ e.stopPropagation();
1568
+ onChangeTableAlias(((_meta$table7 = meta.table2) === null || _meta$table7 === void 0 ? void 0 : _meta$table7.alias) || '');
1569
+ }
1570
+ }
1571
+ })
1572
+ }) : null;
1573
+ }()
1574
+ })
1575
+ // <Tooltip
1576
+ // title={__(
1577
+ // tableIsError()
1578
+ // ? isDel
1579
+ // ? 'metabase.verify'
1580
+ // : 'SqlQueryBuilder.repeatAlias'
1581
+ // : 'SqlQueryBuilder.alias',
1582
+ // )}
1583
+ // >
1584
+ // <Button
1585
+ // danger={tableIsError()}
1586
+ // className={cx(':Sqb-TableName-as', {
1587
+ // isError: tableIsError(),
1588
+ // })}
1589
+ // shape='circle'
1590
+ // style={
1591
+ // isDel
1592
+ // ? {
1593
+ // fontSize: 18,
1594
+ // backgroundColor: '#fff',
1595
+ // width: 'auto',
1596
+ // height: 'auto',
1597
+ // }
1598
+ // : {}
1599
+ // }
1600
+ // iconOnly
1601
+ // primary={!isDel}
1602
+ // icon={isDel ? <ExclamationCircleFill /> : 'As'}
1603
+ // size='small'
1604
+ // onClick={(e) => {
1605
+ // e.stopPropagation();
1606
+ // onChangeTableAlias(meta.table2?.alias || '');
1607
+ // }}
1608
+ // ></Button>
1609
+ // </Tooltip>
1610
+ , table2Selected ? "".concat(meta.table2.datasourceName, ".").concat(meta.table2.name, " ").concat((_meta$table8 = meta.table2) !== null && _meta$table8 !== void 0 && _meta$table8.alias ? "as ".concat((_meta$table9 = meta.table2) === null || _meta$table9 === void 0 ? void 0 : _meta$table9.alias) : '') : __('SqlQueryBuilder.pickTable')]
1519
1611
  }), store.showSubquery && _jsx(Tooltip, {
1520
1612
  title: __('SqlQueryBuilder.switchSubQuery'),
1521
1613
  children: _jsx(Button, {
@@ -1,7 +1,7 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
4
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  import cx from 'classnames';
6
6
  import { __ } from '../../../locale';
7
7
  import { findIndex, getHelper } from '../../../utils';
@@ -322,19 +322,21 @@ var GroupBy = function GroupBy(props) {
322
322
  onClick: function onClick(e) {
323
323
  return handleUpdate(e, i);
324
324
  },
325
- children: [v.quotes && _jsx(Tooltip, {
326
- title: __('SqlQueryBuilder.alias'),
327
- children: _jsx(Button, {
328
- className: ':Sqb-TableName-as :Sqb-TableName green-name',
329
- shape: 'circle',
330
- iconOnly: true,
331
- primary: true,
332
- icon: 'As',
333
- size: 'small',
334
- onClick: function onClick(e) {
335
- e.stopPropagation();
336
- onChangeFieldAlias((v === null || v === void 0 ? void 0 : v.fieldAlias) || '', i);
337
- }
325
+ children: [v.quotes && _jsx(_Fragment, {
326
+ children: store.fieldEnableAlias && _jsx(Tooltip, {
327
+ title: __('SqlQueryBuilder.alias'),
328
+ children: _jsx(Button, {
329
+ className: ':Sqb-TableName-as :Sqb-TableName green-name',
330
+ shape: 'circle',
331
+ iconOnly: true,
332
+ primary: true,
333
+ icon: 'As',
334
+ size: 'small',
335
+ onClick: function onClick(e) {
336
+ e.stopPropagation();
337
+ onChangeFieldAlias((v === null || v === void 0 ? void 0 : v.fieldAlias) || '', i);
338
+ }
339
+ })
338
340
  })
339
341
  }), "".concat(v.quotes, " ").concat(v.fieldAlias ? "as ".concat(v.fieldAlias) : ''), _jsx("span", {
340
342
  style: {
@@ -1,7 +1,7 @@
1
1
  import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
2
2
  import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
3
3
  import _regeneratorRuntime from "@babel/runtime/regenerator";
4
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
4
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
5
5
  import cx from 'classnames';
6
6
  import { __ } from '../../../locale';
7
7
  import { findIndex, getHelper } from '../../../utils';
@@ -323,19 +323,21 @@ var SelectIndex = function SelectIndex(props) {
323
323
  onClick: function onClick(e) {
324
324
  return handleUpdate(e, i);
325
325
  },
326
- children: [v.quotes && _jsx(Tooltip, {
327
- title: __('SqlQueryBuilder.alias'),
328
- children: _jsx(Button, {
329
- className: ':Sqb-TableName-as :Sqb-TableName green-name',
330
- shape: 'circle',
331
- iconOnly: true,
332
- primary: true,
333
- icon: 'As',
334
- size: 'small',
335
- onClick: function onClick(e) {
336
- e.stopPropagation();
337
- onChangeFieldAlias((v === null || v === void 0 ? void 0 : v.fieldAlias) || '', i);
338
- }
326
+ children: [v.quotes && _jsx(_Fragment, {
327
+ children: store.fieldEnableAlias && _jsx(Tooltip, {
328
+ title: __('SqlQueryBuilder.alias'),
329
+ children: _jsx(Button, {
330
+ className: ':Sqb-TableName-as :Sqb-TableName green-name',
331
+ shape: 'circle',
332
+ iconOnly: true,
333
+ primary: true,
334
+ icon: 'As',
335
+ size: 'small',
336
+ onClick: function onClick(e) {
337
+ e.stopPropagation();
338
+ onChangeFieldAlias((v === null || v === void 0 ? void 0 : v.fieldAlias) || '', i);
339
+ }
340
+ })
339
341
  })
340
342
  }), "".concat(v.quotes, " ").concat(v.fieldAlias ? "as ".concat(v.fieldAlias) : ''), _jsx("span", {
341
343
  style: {
@@ -215,8 +215,10 @@ var TableData = function TableData(props) {
215
215
  var existingCol = newMetaList.columns.find(function (oldCol) {
216
216
  return oldCol.name === newCol.name;
217
217
  });
218
+ var _column = existingCol ? existingCol : newCol;
219
+ _column.select = store.isSelectFields || _column.select;
218
220
  // 如果存在,返回旧列;否则返回新列
219
- return existingCol ? existingCol : newCol;
221
+ return _column;
220
222
  });
221
223
  // (newMeta[index] as MetaJoin).expressions = [];
222
224
  var newMetas = store.metaList[groupIndex].list.slice();
@@ -284,61 +286,113 @@ var TableData = function TableData(props) {
284
286
  onClick: function onClick() {
285
287
  showSubQuery(meta.subquery);
286
288
  },
287
- children: [subQuerySelected && _jsx(Tooltip, {
288
- title: __(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
289
- children: _jsx(Button, {
290
- danger: tableIsError(),
291
- className: cx(':Sqb-TableName-as', {
292
- isError: tableIsError()
293
- }),
294
- shape: 'circle',
295
- style: isDel ? {
296
- fontSize: 18,
297
- backgroundColor: '#fff',
298
- width: 'auto',
299
- height: 'auto'
300
- } : {},
301
- iconOnly: true,
302
- primary: !isDel,
303
- icon: isDel ? _jsx(ExclamationCircleFill, {}) : 'As',
304
- size: 'small',
305
- onClick: function onClick(e) {
306
- var _meta$table4;
307
- e.stopPropagation();
308
- onChangeTableAlias(((_meta$table4 = meta.table) === null || _meta$table4 === void 0 ? void 0 : _meta$table4.alias) || '');
309
- }
310
- })
289
+ children: [subQuerySelected && _jsx(_Fragment, {
290
+ children: function () {
291
+ var showButton = store.tableEnableAlias || tableIsError() && isDel;
292
+ var icon = isDel ? _jsx(ExclamationCircleFill, {}) : store.tableEnableAlias ? 'As' : '';
293
+ return showButton ? _jsx(Tooltip, {
294
+ title: __(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
295
+ children: _jsx(Button, {
296
+ danger: tableIsError(),
297
+ className: cx(':Sqb-TableName-as', {
298
+ isError: tableIsError()
299
+ }),
300
+ shape: 'circle',
301
+ style: isDel ? {
302
+ fontSize: 18,
303
+ backgroundColor: '#fff',
304
+ width: 'auto',
305
+ height: 'auto'
306
+ } : {},
307
+ iconOnly: true,
308
+ primary: !isDel,
309
+ icon: icon,
310
+ size: 'small',
311
+ onClick: function onClick(e) {
312
+ if (store.tableEnableAlias) {
313
+ var _meta$table4;
314
+ e.stopPropagation();
315
+ onChangeTableAlias(((_meta$table4 = meta.table) === null || _meta$table4 === void 0 ? void 0 : _meta$table4.alias) || '');
316
+ }
317
+ }
318
+ })
319
+ }) : null;
320
+ }()
311
321
  }), subQuerySelected ? "".concat(((_meta$subquery2 = meta.subquery) === null || _meta$subquery2 === void 0 ? void 0 : _meta$subquery2[0]).table.datasourceName, ".").concat(((_meta$subquery3 = meta.subquery) === null || _meta$subquery3 === void 0 ? void 0 : _meta$subquery3[0]).table.name, " ").concat((_meta$table5 = meta.table) !== null && _meta$table5 !== void 0 && _meta$table5.alias ? "as ".concat((_meta$table6 = meta.table) === null || _meta$table6 === void 0 ? void 0 : _meta$table6.alias) : '', " ") : __('SqlQueryBuilder.setSubQuery')]
312
322
  }) : _jsxs("div", {
313
323
  className: cx("Sqb-TableName", {
314
324
  notSelected: !selected
315
325
  }),
316
326
  onClick: selectTable,
317
- children: [selected && _jsx(Tooltip, {
318
- title: __(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
319
- children: _jsx(Button, {
320
- danger: tableIsError(),
321
- className: cx(':Sqb-TableName-as', {
322
- isError: tableIsError()
323
- }),
324
- shape: 'circle',
325
- style: isDel ? {
326
- fontSize: 18,
327
- backgroundColor: '#fff',
328
- width: 'auto',
329
- height: 'auto'
330
- } : {},
331
- iconOnly: true,
332
- primary: !isDel,
333
- icon: isDel ? _jsx(ExclamationCircleFill, {}) : 'As',
334
- size: 'small',
335
- onClick: function onClick(e) {
336
- var _meta$table7;
337
- e.stopPropagation();
338
- onChangeTableAlias(((_meta$table7 = meta.table) === null || _meta$table7 === void 0 ? void 0 : _meta$table7.alias) || '');
339
- }
340
- })
341
- }), selected ? "".concat(meta.table.datasourceName, ".").concat(meta.table.name, " ").concat((_meta$table8 = meta.table) !== null && _meta$table8 !== void 0 && _meta$table8.alias ? "as ".concat((_meta$table9 = meta.table) === null || _meta$table9 === void 0 ? void 0 : _meta$table9.alias) : '') : __('SqlQueryBuilder.pickTable')]
327
+ children: [selected && _jsx(_Fragment, {
328
+ children: function () {
329
+ var showButton = store.tableEnableAlias || tableIsError() && isDel;
330
+ var icon = isDel ? _jsx(ExclamationCircleFill, {}) : store.tableEnableAlias ? 'As' : '';
331
+ return showButton ? _jsx(Tooltip, {
332
+ title: __(tableIsError() ? isDel ? 'metabase.verify' : 'SqlQueryBuilder.repeatAlias' : 'SqlQueryBuilder.alias'),
333
+ children: _jsx(Button, {
334
+ danger: tableIsError(),
335
+ className: cx(':Sqb-TableName-as', {
336
+ isError: tableIsError()
337
+ }),
338
+ shape: 'circle',
339
+ style: isDel ? {
340
+ fontSize: 18,
341
+ backgroundColor: '#fff',
342
+ width: 'auto',
343
+ height: 'auto'
344
+ } : {},
345
+ iconOnly: true,
346
+ primary: !isDel,
347
+ icon: icon,
348
+ size: 'small',
349
+ onClick: function onClick(e) {
350
+ if (store.tableEnableAlias) {
351
+ var _meta$table7;
352
+ e.stopPropagation();
353
+ onChangeTableAlias(((_meta$table7 = meta.table) === null || _meta$table7 === void 0 ? void 0 : _meta$table7.alias) || '');
354
+ }
355
+ }
356
+ })
357
+ }) : null;
358
+ }()
359
+ })
360
+ // <Tooltip
361
+ // title={__(
362
+ // tableIsError()
363
+ // ? isDel
364
+ // ? 'metabase.verify'
365
+ // : 'SqlQueryBuilder.repeatAlias'
366
+ // : 'SqlQueryBuilder.alias',
367
+ // )}
368
+ // >
369
+ // <Button
370
+ // danger={tableIsError()}
371
+ // className={cx(':Sqb-TableName-as', {
372
+ // isError: tableIsError(),
373
+ // })}
374
+ // shape='circle'
375
+ // style={
376
+ // isDel
377
+ // ? {
378
+ // fontSize: 18,
379
+ // backgroundColor: '#fff',
380
+ // width: 'auto',
381
+ // height: 'auto',
382
+ // }
383
+ // : {}
384
+ // }
385
+ // iconOnly
386
+ // primary={!isDel}
387
+ // icon={isDel ? <ExclamationCircleFill /> : 'As'}
388
+ // size='small'
389
+ // onClick={(e) => {
390
+ // e.stopPropagation();
391
+ // onChangeTableAlias(meta.table?.alias || '');
392
+ // }}
393
+ // ></Button>
394
+ // </Tooltip>
395
+ , selected ? "".concat(meta.table.datasourceName, ".").concat(meta.table.name, " ").concat((_meta$table8 = meta.table) !== null && _meta$table8 !== void 0 && _meta$table8.alias ? "as ".concat((_meta$table9 = meta.table) === null || _meta$table9 === void 0 ? void 0 : _meta$table9.alias) : '') : __('SqlQueryBuilder.pickTable')]
342
396
  }), store.showSubquery && _jsx(Tooltip, {
343
397
  title: __('SqlQueryBuilder.switchSubQuery'),
344
398
  children: _jsx(Button, {
@@ -126,6 +126,18 @@ var useStore = function useStore() {
126
126
  _useState38 = _slicedToArray(_useState37, 2),
127
127
  isExit = _useState38[0],
128
128
  setIsExit = _useState38[1]; // 是否是notExit
129
+ var _useState39 = useState(true),
130
+ _useState40 = _slicedToArray(_useState39, 2),
131
+ tableEnableAlias = _useState40[0],
132
+ setTableEnableAlias = _useState40[1]; // 表名是否开启别名
133
+ var _useState41 = useState(true),
134
+ _useState42 = _slicedToArray(_useState41, 2),
135
+ fieldEnableAlias = _useState42[0],
136
+ setFieldEnableAlias = _useState42[1]; // 字段名是否开启别名
137
+ var _useState43 = useState(true),
138
+ _useState44 = _slicedToArray(_useState43, 2),
139
+ isSelectFields = _useState44[0],
140
+ setIsSelectFields = _useState44[1]; // 是否默认勾选字段
129
141
  // 外层ref
130
142
  var popupContainer = useRef();
131
143
  // const [fetchDatasetFn, setFetchDatasetFn] = useState<(id: string) => Promise<any>>(
@@ -264,7 +276,7 @@ var useStore = function useStore() {
264
276
  var obj = {};
265
277
  obj = oldObj[v.id] || {};
266
278
  return _objectSpread(_objectSpread(_objectSpread({}, obj), v), {}, {
267
- select: select,
279
+ select: isSelectFields || select,
268
280
  fieldUuid: obj.fieldUuid || v.fieldUuid || uuidv4('field')
269
281
  });
270
282
  });
@@ -602,7 +614,13 @@ var useStore = function useStore() {
602
614
  formulaTemplates: formulaTemplates,
603
615
  setFormulaTemplates: setFormulaTemplates,
604
616
  isExit: isExit,
605
- setIsExit: setIsExit
617
+ setIsExit: setIsExit,
618
+ tableEnableAlias: tableEnableAlias,
619
+ setTableEnableAlias: setTableEnableAlias,
620
+ fieldEnableAlias: fieldEnableAlias,
621
+ setFieldEnableAlias: setFieldEnableAlias,
622
+ isSelectFields: isSelectFields,
623
+ setIsSelectFields: setIsSelectFields
606
624
  };
607
625
  };
608
626
  export default useStore;
package/lib/es/index.js CHANGED
@@ -33,6 +33,8 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
33
33
  value = _props$value === void 0 ? [] : _props$value,
34
34
  _props$sourceList = props.sourceList,
35
35
  sourceList = _props$sourceList === void 0 ? [] : _props$sourceList,
36
+ _props$exitSourceList = props.exitSourceList,
37
+ exitSourceList = _props$exitSourceList === void 0 ? [] : _props$exitSourceList,
36
38
  _props$showSubquery = props.showSubquery,
37
39
  showSubquery = _props$showSubquery === void 0 ? true : _props$showSubquery,
38
40
  _props$subShowSubquer = props.subShowSubquery,
@@ -44,7 +46,13 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
44
46
  _props$filterCustomTy = props.filterCustomType,
45
47
  filterCustomType = _props$filterCustomTy === void 0 ? false : _props$filterCustomTy,
46
48
  _props$isExit = props.isExit,
47
- isExit = _props$isExit === void 0 ? false : _props$isExit;
49
+ isExit = _props$isExit === void 0 ? false : _props$isExit,
50
+ _props$tableEnableAli = props.tableEnableAlias,
51
+ tableEnableAlias = _props$tableEnableAli === void 0 ? true : _props$tableEnableAli,
52
+ _props$fieldEnableAli = props.fieldEnableAlias,
53
+ fieldEnableAlias = _props$fieldEnableAli === void 0 ? true : _props$fieldEnableAli,
54
+ _props$isSelectFields = props.isSelectFields,
55
+ isSelectFields = _props$isSelectFields === void 0 ? true : _props$isSelectFields;
48
56
  var store = useData();
49
57
  useEffect(function () {
50
58
  getTables && store.setFetchDatasetFn(getTables);
@@ -58,8 +66,8 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
58
66
  store.setPreData(_value);
59
67
  }, [value]);
60
68
  useEffect(function () {
61
- store.setSourceList(sourceList);
62
- }, [sourceList]);
69
+ store.setSourceList(isExit && exitSourceList && Array.from(exitSourceList).length > 0 ? exitSourceList || sourceList : sourceList);
70
+ }, [sourceList, exitSourceList, isExit]);
63
71
  useEffect(function () {
64
72
  store.setShowFields(showFields);
65
73
  store.setFieldNameTpl(fieldNameTpl || '${name}');
@@ -72,7 +80,10 @@ var SqlVisionBuilder = React.forwardRef(function (props, ref) {
72
80
  store.setIgnoreGroupByType(ignoreGroupByType);
73
81
  store.setfilterCustomType(filterCustomType);
74
82
  store.setIsExit(isExit);
75
- }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, formulaTemplates, ignoreGroupByType, filterCustomType, isExit]);
83
+ store.setTableEnableAlias(tableEnableAlias);
84
+ store.setFieldEnableAlias(fieldEnableAlias);
85
+ store.setIsSelectFields(isSelectFields);
86
+ }, [showFields, fieldNameTpl, tableNameTpl, toolbar, showSubquery, subShowSubquery, constantList, formulaTemplates, ignoreGroupByType, filterCustomType, isExit, tableEnableAlias, fieldEnableAlias, isSelectFields]);
76
87
  React.useImperativeHandle(ref, function () {
77
88
  return {
78
89
  // setDatasource: (list) => {
package/lib/es/types.d.ts CHANGED
@@ -25,6 +25,7 @@ export interface MetabaseProps {
25
25
  onOk?: (params: any) => void;
26
26
  value?: MetaListType[];
27
27
  sourceList?: DatasourceType[];
28
+ exitSourceList?: DatasourceType[];
28
29
  showSubquery?: boolean;
29
30
  subShowSubquery?: boolean;
30
31
  constantList?: OptionItem[];
@@ -34,6 +35,9 @@ export interface MetabaseProps {
34
35
  notExistsColumns?: DataType[];
35
36
  formulaTemplates?: FormulaTemplatesItem[];
36
37
  isExit?: boolean;
38
+ tableEnableAlias?: boolean;
39
+ fieldEnableAlias?: boolean;
40
+ isSelectFields?: boolean;
37
41
  }
38
42
  export interface OptionItem {
39
43
  value?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gingkoo/pandora-metabase",
3
- "version": "1.0.54",
3
+ "version": "1.0.55",
4
4
  "description": "",
5
5
  "main": "lib/es/index.js",
6
6
  "module": "lib/es/index.js",