@gingkoo/pandora-metabase 1.0.158-alpha.13 → 1.0.158-alpha.14

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.
@@ -2778,6 +2778,7 @@ var FormulaList = (0, _react.forwardRef)(function (props, ref) {
2778
2778
  notExistsColumns: exitData,
2779
2779
  fieldEnableAlias: false,
2780
2780
  toolbar: _toolbar,
2781
+ subToolbar: subToolbar,
2781
2782
  btnText: (0, _locale.__)('SqlQueryBuilder.confirm'),
2782
2783
  value: (0, _cloneDeep["default"])(_value),
2783
2784
  onOk: function onOk(newList) {
@@ -126,64 +126,63 @@ var Metabase = function Metabase(props) {
126
126
  return;
127
127
  }
128
128
  }
129
- var doms = store.popupContainer.current.querySelectorAll('.isError');
130
- var isSqlError = store.popupContainer.current.querySelectorAll('.isSqlError');
131
- var checkDomIssues = function checkDomIssues() {
132
- if (doms.length) {
133
- _pandora.Modal.confirm({
134
- title: (0, _locale.__)('metabase.prompt'),
135
- content: (0, _locale.__)('metabase.validationFailed'),
136
- onOk: function () {
137
- var _onOk = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee() {
138
- return _regenerator["default"].wrap(function (_context) {
139
- while (1) switch (_context.prev = _context.next) {
140
- case 0:
141
- _context.next = 1;
142
- return onSave();
143
- case 1:
144
- case "end":
145
- return _context.stop();
146
- }
147
- }, _callee);
148
- }));
149
- function onOk() {
150
- return _onOk.apply(this, arguments);
151
- }
152
- return onOk;
153
- }()
154
- });
155
- return;
156
- }
157
- onSave();
158
- };
159
- var checkFormulaIssues = function checkFormulaIssues() {
160
- if (isSqlError.length) {
161
- _pandora.Modal.confirm({
162
- title: (0, _locale.__)('metabase.prompt'),
163
- content: (0, _locale.__)('metabase.validationFormulaSave'),
164
- onOk: checkDomIssues
165
- });
166
- return;
167
- }
168
- checkDomIssues();
169
- };
170
- if (sqlValidationEnabled) {
171
- var sqlMetaList = (0, _utils.normalizeLegacySummarizeForSave)((0, _utils.splitByUnion)(store.metaList));
172
- var sqlValidation = (0, _transformSql.validateMetabaseConfig)(sqlMetaList, sqlDialect, {
173
- queryKind: sqlValidationQueryKind
129
+ var container = store.popupContainer.current;
130
+ var doms = container ? container.querySelectorAll('.isError') : [];
131
+ var isSqlError = container ? container.querySelectorAll('.isSqlError') : [];
132
+ var extraMessages = [];
133
+ if (isSqlError.length) extraMessages.push((0, _locale.__)('metabase.sqlErrorFormula'));
134
+ if (doms.length) extraMessages.push((0, _locale.__)('metabase.sqlErrorUi'));
135
+ var sqlIssues = sqlValidationEnabled ? (0, _transformSql.validateMetabaseConfig)((0, _utils.normalizeLegacySummarizeForSave)((0, _utils.splitByUnion)(store.metaList)), sqlDialect, {
136
+ queryKind: sqlValidationQueryKind
137
+ }).issues : [];
138
+ var confirmSave = function () {
139
+ var _ref = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee() {
140
+ return _regenerator["default"].wrap(function (_context) {
141
+ while (1) switch (_context.prev = _context.next) {
142
+ case 0:
143
+ _context.next = 1;
144
+ return onSave();
145
+ case 1:
146
+ case "end":
147
+ return _context.stop();
148
+ }
149
+ }, _callee);
150
+ }));
151
+ return function confirmSave() {
152
+ return _ref.apply(this, arguments);
153
+ };
154
+ }();
155
+ if (sqlIssues.length) {
156
+ var hasConfigIssue = sqlIssues.some(function (issue) {
157
+ return issue.severity === 'error';
174
158
  });
175
- if (sqlValidation.issues.length) {
176
- var hasConfigIssue = sqlValidation.issues.some(function (issue) {
177
- return issue.severity === 'error';
178
- });
179
- (0, _sqlSyntaxConfirm.confirmSyntaxIssues)(sqlValidation.issues, checkFormulaIssues, hasConfigIssue ? 'metabase.validationConfigSave' : 'metabase.validationSqlSave');
180
- return;
181
- }
159
+ (0, _sqlSyntaxConfirm.confirmSyntaxIssues)(sqlIssues, confirmSave, hasConfigIssue ? 'metabase.validationConfigSave' : 'metabase.validationSqlSave', extraMessages);
160
+ return;
161
+ }
162
+ if (extraMessages.length > 1) {
163
+ (0, _sqlSyntaxConfirm.confirmSyntaxIssues)([], confirmSave, 'metabase.validationConfigSave', extraMessages);
164
+ return;
165
+ }
166
+ if (isSqlError.length) {
167
+ _pandora.Modal.confirm({
168
+ title: (0, _locale.__)('metabase.prompt'),
169
+ content: (0, _locale.__)('metabase.validationFormulaSave'),
170
+ onOk: confirmSave
171
+ });
172
+ return;
173
+ }
174
+ if (doms.length) {
175
+ _pandora.Modal.confirm({
176
+ title: (0, _locale.__)('metabase.prompt'),
177
+ content: (0, _locale.__)('metabase.validationFailed'),
178
+ onOk: confirmSave
179
+ });
180
+ return;
182
181
  }
183
- checkFormulaIssues();
182
+ confirmSave();
184
183
  };
185
184
  var onSave = function () {
186
- var _ref = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2() {
185
+ var _ref2 = (0, _asyncToGenerator2["default"])(_regenerator["default"].mark(function _callee2() {
187
186
  var intercept, _metaList;
188
187
  return _regenerator["default"].wrap(function (_context2) {
189
188
  while (1) switch (_context2.prev = _context2.next) {
@@ -224,7 +223,7 @@ var Metabase = function Metabase(props) {
224
223
  }, _callee2);
225
224
  }));
226
225
  return function onSave() {
227
- return _ref.apply(this, arguments);
226
+ return _ref2.apply(this, arguments);
228
227
  };
229
228
  }();
230
229
  (0, _react.useEffect)(function () {
@@ -1038,6 +1038,8 @@ var JoinData = function JoinData(props) {
1038
1038
  isExit: isExit,
1039
1039
  isSubquery: true,
1040
1040
  toolbar: _toolbar,
1041
+ subToolbar: subToolbar,
1042
+ sqlValidationQueryKind: 'query',
1041
1043
  btnText: (0, _locale.__)('SqlQueryBuilder.confirm'),
1042
1044
  value: (0, _cloneDeep["default"])(val),
1043
1045
  onOk: function onOk(newList) {
@@ -226,6 +226,8 @@ var TableData = function TableData(props) {
226
226
  isExit: isExit,
227
227
  isSubquery: true,
228
228
  toolbar: _toolbar,
229
+ subToolbar: subToolbar,
230
+ sqlValidationQueryKind: 'query',
229
231
  btnText: (0, _locale.__)('SqlQueryBuilder.confirm'),
230
232
  value: (0, _cloneDeep["default"])(val),
231
233
  onOk: function onOk(newList) {
@@ -1,5 +1,5 @@
1
1
  import { SqlValidationIssue } from '../utils/transformSql';
2
- export declare const confirmSyntaxIssues: (issues: SqlValidationIssue[] | undefined, onOk: () => void | Promise<void>, descriptionKey?: string) => void | Promise<void>;
2
+ export declare const confirmSyntaxIssues: (issues: SqlValidationIssue[] | undefined, onOk: () => void | Promise<void>, descriptionKey?: string, extraMessages?: string[]) => void | Promise<void>;
3
3
  export declare const toSyntaxIssues: (result?: {
4
4
  isError?: boolean;
5
5
  issues?: SqlValidationIssue[];
@@ -32,15 +32,16 @@ var getIssuePath = function getIssuePath(issue) {
32
32
  }).join(' > ');
33
33
  };
34
34
  var renderIssues = function renderIssues(issues, descriptionKey) {
35
+ var extraMessages = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
35
36
  return (0, _jsxRuntime.jsxs)("div", {
36
37
  children: [(0, _jsxRuntime.jsx)("div", {
37
38
  children: (0, _locale.__)(descriptionKey)
38
- }), (0, _jsxRuntime.jsx)("ul", {
39
+ }), issues.length || extraMessages.length ? (0, _jsxRuntime.jsxs)("ul", {
39
40
  style: {
40
41
  margin: '8px 0 0',
41
42
  paddingLeft: 20
42
43
  },
43
- children: issues.map(function (issue) {
44
+ children: [issues.map(function (issue) {
44
45
  var issuePath = getIssuePath(issue);
45
46
  var key = "".concat(issue.code, "-").concat((issue.path || []).map(function (item) {
46
47
  var _item$metaKey, _item$index;
@@ -49,20 +50,25 @@ var renderIssues = function renderIssues(issues, descriptionKey) {
49
50
  return (0, _jsxRuntime.jsxs)("li", {
50
51
  children: [issuePath ? "".concat(issuePath, "\uFF1A") : '', getIssueMessage(issue.code)]
51
52
  }, key);
52
- })
53
- })]
53
+ }), extraMessages.map(function (message, index) {
54
+ return (0, _jsxRuntime.jsx)("li", {
55
+ children: message
56
+ }, "extra-".concat(index));
57
+ })]
58
+ }) : null]
54
59
  });
55
60
  };
56
61
  var confirmSyntaxIssues = exports.confirmSyntaxIssues = function confirmSyntaxIssues() {
57
62
  var issues = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
58
63
  var onOk = arguments.length > 1 ? arguments[1] : undefined;
59
64
  var descriptionKey = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'metabase.validationSqlSave';
60
- if (!issues.length) {
65
+ var extraMessages = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : [];
66
+ if (!issues.length && !extraMessages.length) {
61
67
  return onOk();
62
68
  }
63
69
  _pandora.Modal.confirm({
64
70
  title: (0, _locale.__)('metabase.prompt'),
65
- content: renderIssues(issues, descriptionKey),
71
+ content: renderIssues(issues, descriptionKey, extraMessages),
66
72
  onOk: onOk
67
73
  });
68
74
  };
@@ -506,15 +506,21 @@ var useStore = function useStore() {
506
506
  }
507
507
  return _context7.abrupt("return", tables);
508
508
  case 1:
509
- _context7.next = 2;
509
+ if (!(typeof fetchDatasetFn.current !== 'function')) {
510
+ _context7.next = 2;
511
+ break;
512
+ }
513
+ return _context7.abrupt("return", []);
514
+ case 2:
515
+ _context7.next = 3;
510
516
  return fetchDatasetFn.current(datasourceId, {
511
517
  isExit: isExit
512
518
  });
513
- case 2:
519
+ case 3:
514
520
  _tables = _context7.sent;
515
521
  setDataset(datasourceId, _tables);
516
522
  return _context7.abrupt("return", _tables);
517
- case 3:
523
+ case 4:
518
524
  case "end":
519
525
  return _context7.stop();
520
526
  }
@@ -550,19 +556,26 @@ var useStore = function useStore() {
550
556
  _isExit = _args8.length > 5 && _args8[5] !== undefined ? _args8[5] : isExit;
551
557
  _table$alias = table.alias, alias = _table$alias === void 0 ? '' : _table$alias, datasourceName = table.datasourceName, did = table.datasourceId, column = table.column, extra = (0, _objectWithoutProperties2["default"])(table, _excluded);
552
558
  tableName = table.name;
553
- columns = getColumns(tableName);
559
+ columns = getColumns(tableName, datasourceId, _isExit);
554
560
  if (columns.length) {
555
- _context8.next = 2;
561
+ _context8.next = 3;
556
562
  break;
557
563
  }
558
- _context8.next = 1;
564
+ if (!(typeof fetchColumnsFn.current !== 'function')) {
565
+ _context8.next = 1;
566
+ break;
567
+ }
568
+ typeof callback === 'function' && callback(oldColumns);
569
+ return _context8.abrupt("return", oldColumns);
570
+ case 1:
571
+ _context8.next = 2;
559
572
  return fetchColumnsFn.current(extra, datasourceId, {
560
573
  isExit: _isExit
561
574
  });
562
- case 1:
563
- columns = _context8.sent;
564
- setColumns(tableName, columns);
565
575
  case 2:
576
+ columns = _context8.sent;
577
+ setColumns(tableName, columns, datasourceId, _isExit);
578
+ case 3:
566
579
  _columns = (_columns2 = columns) === null || _columns2 === void 0 ? void 0 : _columns2.map(function (v) {
567
580
  var _ref9, _obj$fieldAlias;
568
581
  var obj = oldColumns.find(function (oldColumn) {
@@ -576,7 +589,7 @@ var useStore = function useStore() {
576
589
  });
577
590
  });
578
591
  typeof callback === 'function' && callback(_columns);
579
- case 3:
592
+ case 4:
580
593
  case "end":
581
594
  return _context8.stop();
582
595
  }
@@ -597,7 +610,8 @@ var useStore = function useStore() {
597
610
  oldData,
598
611
  newData,
599
612
  isChange,
600
- _args9 = arguments;
613
+ _args9 = arguments,
614
+ _t;
601
615
  return _regenerator["default"].wrap(function (_context9) {
602
616
  while (1) switch (_context9.prev = _context9.next) {
603
617
  case 0:
@@ -628,25 +642,35 @@ var useStore = function useStore() {
628
642
  case 2:
629
643
  oldData = (0, _utils.splitByUnion)(prevMeta);
630
644
  newData = (0, _utils.splitByUnion)(newMeta);
645
+ if (!(typeof fetchChangeFn.current === 'function')) {
646
+ _context9.next = 4;
647
+ break;
648
+ }
631
649
  _context9.next = 3;
632
650
  return fetchChangeFn.current(oldData, changeObj, {
633
651
  isExit: isExit
634
652
  }, newData);
635
653
  case 3:
636
- isChange = _context9.sent;
654
+ _t = _context9.sent;
655
+ _context9.next = 5;
656
+ break;
657
+ case 4:
658
+ _t = true;
659
+ case 5:
660
+ isChange = _t;
637
661
  if (!(isChange === false)) {
638
- _context9.next = 4;
662
+ _context9.next = 6;
639
663
  break;
640
664
  }
641
665
  if (requestId === metaRequestRef.current && metaRevisionRef.current === prevRevision) {
642
666
  _setMeta(prevMeta);
643
667
  }
644
668
  return _context9.abrupt("return");
645
- case 4:
669
+ case 6:
646
670
  if (requestId === metaRequestRef.current && metaRevisionRef.current === prevRevision) {
647
671
  _setMeta(newMeta);
648
672
  }
649
- case 5:
673
+ case 7:
650
674
  case "end":
651
675
  return _context9.stop();
652
676
  }
@@ -978,18 +1002,27 @@ var useStore = function useStore() {
978
1002
  });
979
1003
  setMeta(_metaList, groupIndex);
980
1004
  };
1005
+ var getColumnsCacheKey = function getColumnsCacheKey(tableId) {
1006
+ var datasourceId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
1007
+ var exitMode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1008
+ return "".concat(datasourceId || '', "::").concat(tableId || '', "::").concat(exitMode ? 'exit' : 'main');
1009
+ };
981
1010
  var setColumns = function setColumns(tableId, columns) {
1011
+ var datasourceId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
1012
+ var exitMode = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
982
1013
  var _columns = columns === null || columns === void 0 ? void 0 : columns.map(function (v) {
983
1014
  return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, v), {}, {
984
1015
  fieldUuid: v.fieldUuid || (0, _helper.uuidv4)('field')
985
1016
  });
986
1017
  });
987
1018
  var map = (0, _objectSpread2["default"])({}, _cacheColumnsMap);
988
- map[tableId] = _columns;
1019
+ map[getColumnsCacheKey(tableId, datasourceId, exitMode)] = _columns;
989
1020
  set_cacheColumnsMap(map);
990
1021
  };
991
1022
  var getColumns = function getColumns(tableId) {
992
- return _cacheColumnsMap[tableId] || [];
1023
+ var datasourceId = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
1024
+ var exitMode = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
1025
+ return _cacheColumnsMap[getColumnsCacheKey(tableId, datasourceId, exitMode)] || [];
993
1026
  };
994
1027
  var setDataset = function setDataset(datasourceId, tables) {
995
1028
  var map = (0, _objectSpread2["default"])({}, _cacheSource2TableMap);
package/lib/cjs/index.js CHANGED
@@ -112,9 +112,7 @@ var SqlVisionBuilder = _react["default"].forwardRef(function (props, ref) {
112
112
  getColumns && store.setFetchColumnsFn(getColumns);
113
113
  onChange && store.setFetchChangeFn(onChange);
114
114
  getModuleDiffCode && store.setFetchDiffFn(getModuleDiffCode);
115
- store.setFetchFormulaSqlFn(getFormulaSqlCode);
116
- store.setFetchFormulaDiffFn(getFormulaDiffCode);
117
- }, []);
115
+ }, [getTables, getColumns, onChange, getModuleDiffCode]);
118
116
  (0, _react.useEffect)(function () {
119
117
  store.setFetchFormulaSqlFn(getFormulaSqlCode);
120
118
  store.setFetchFormulaDiffFn(getFormulaDiffCode);
@@ -232,6 +232,8 @@ var _default = exports["default"] = (0, _index.register)('en', {
232
232
  'metabase.sqlErrorDuplicateLogicalOperator': 'Duplicate logical operator (for example AND AND or OR OR)',
233
233
  'metabase.sqlErrorAndOr': 'Incomplete AND / OR group (missing operator or condition)',
234
234
  'metabase.sqlErrorUnterminatedQuote': 'Unterminated string or identifier quote',
235
+ 'metabase.sqlErrorFormula': 'The formula configuration is incorrect',
236
+ 'metabase.sqlErrorUi': 'A field or module failed validation',
235
237
  'metabase.prompt': 'Prompt',
236
238
  'metabase.copy': 'Copy',
237
239
  'metabase.copySuccess': 'Copy success',
@@ -232,6 +232,8 @@ var _default = exports["default"] = (0, _index.register)('zh', {
232
232
  'metabase.sqlErrorDuplicateLogicalOperator': '逻辑操作符重复(例如 AND AND 或 OR OR)',
233
233
  'metabase.sqlErrorAndOr': 'AND / OR 结构不完整(缺少连接符或条件)',
234
234
  'metabase.sqlErrorUnterminatedQuote': '字符串或标识符引号未闭合',
235
+ 'metabase.sqlErrorFormula': '公式配置有误',
236
+ 'metabase.sqlErrorUi': '字段或模块配置校验未通过',
235
237
  'metabase.prompt': '提示',
236
238
  'metabase.copy': '复制',
237
239
  'metabase.copySuccess': '复制成功',
@@ -24,12 +24,14 @@ export interface SqlValidationResult {
24
24
  }
25
25
  export declare const validateSqlSyntax: (sql: string, options?: {
26
26
  completeQuery?: boolean;
27
+ dialect?: SqlDialect;
27
28
  }) => {
28
29
  isError: boolean;
29
30
  issues: SqlValidationIssue[];
30
31
  };
31
32
  export declare const validateSql: (sql: string, options?: {
32
33
  completeQuery?: boolean;
34
+ dialect?: SqlDialect;
33
35
  }) => {
34
36
  isError: boolean;
35
37
  issues: SqlValidationIssue[];
@@ -606,7 +606,8 @@ var _handleJoinData = function _handleJoinData(joinData) {
606
606
  var db = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : procEnum.mysql;
607
607
  var constants = [];
608
608
  var joinList = joinData.filter(function (v) {
609
- return v.table2.name;
609
+ var _v$table;
610
+ return v === null || v === void 0 || (_v$table = v.table2) === null || _v$table === void 0 ? void 0 : _v$table.name;
610
611
  }).map(function (v) {
611
612
  var expressions = v.expressions,
612
613
  isSubquery = v.isSubquery,
@@ -619,7 +620,7 @@ var _handleJoinData = function _handleJoinData(joinData) {
619
620
  sql = _handleBaseType2Sql0.sql,
620
621
  joinConstants = _handleBaseType2Sql0.constants;
621
622
  var joinCondition = "on ".concat(sql);
622
- constants = joinConstants;
623
+ constants.push.apply(constants, (0, _toConsumableArray2["default"])(joinConstants || []));
623
624
  return {
624
625
  alias: v.table2.alias,
625
626
  tableName: v.table2.name,
@@ -1106,7 +1107,9 @@ var tokenizeSql = function tokenizeSql(sql) {
1106
1107
  var validateSqlSyntax = exports.validateSqlSyntax = function validateSqlSyntax(sql) {
1107
1108
  var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1108
1109
  var _options$completeQuer = options.completeQuery,
1109
- completeQuery = _options$completeQuer === void 0 ? true : _options$completeQuer;
1110
+ completeQuery = _options$completeQuer === void 0 ? true : _options$completeQuer,
1111
+ _options$dialect = options.dialect,
1112
+ dialect = _options$dialect === void 0 ? procEnum.mysql : _options$dialect;
1110
1113
  var tokens = tokenizeSql(String(sql || ''));
1111
1114
  var issues = [];
1112
1115
  var seenCodes = new Set();
@@ -1246,14 +1249,19 @@ var validateSqlSyntax = exports.validateSqlSyntax = function validateSqlSyntax(s
1246
1249
  }
1247
1250
  return -1;
1248
1251
  };
1249
- var validateExpressionSegment = function validateExpressionSegment(start, end) {
1252
+ var isEmptyExpressionSegment = function isEmptyExpressionSegment(start, end) {
1250
1253
  var segment = tokens.slice(start, end).filter(function (token) {
1251
1254
  return token.value !== ';';
1252
1255
  });
1253
- var hasExpression = segment.some(function (token) {
1256
+ return !segment.some(function (token) {
1254
1257
  return !['(', ')', ',', '.', 'ASC', 'DESC', 'NULLS', 'FIRST', 'LAST'].includes(token.value);
1255
1258
  });
1256
- if (!segment.length || !hasExpression) {
1259
+ };
1260
+ var validateExpressionSegment = function validateExpressionSegment(start, end) {
1261
+ var segment = tokens.slice(start, end).filter(function (token) {
1262
+ return token.value !== ';';
1263
+ });
1264
+ if (!segment.length || isEmptyExpressionSegment(start, end)) {
1257
1265
  addIssue('clause');
1258
1266
  return;
1259
1267
  }
@@ -1271,11 +1279,9 @@ var validateSqlSyntax = exports.validateSqlSyntax = function validateSqlSyntax(s
1271
1279
  if (token === 'SELECT') {
1272
1280
  var queryEnd = findBoundary(index + 1, depth, queryBoundaryWords);
1273
1281
  var fromIndex = findToken(index + 1, queryEnd, depth, 'FROM');
1274
- if (fromIndex < 0) {
1275
- addIssue('from');
1276
- return;
1277
- }
1278
- var selectList = tokens.slice(index + 1, fromIndex).filter(function (item) {
1282
+ if (fromIndex < 0 && dialect === procEnum.oracle) addIssue('from');
1283
+ var selectEnd = fromIndex < 0 ? queryEnd : fromIndex;
1284
+ var selectList = tokens.slice(index + 1, selectEnd).filter(function (item) {
1279
1285
  return item.value !== ';';
1280
1286
  });
1281
1287
  if (!selectList.length || selectList[0].value === ',' || selectList[selectList.length - 1].value === ',' || selectList.some(function (item, itemIndex) {
@@ -1285,9 +1291,9 @@ var validateSqlSyntax = exports.validateSqlSyntax = function validateSqlSyntax(s
1285
1291
  addIssue('select-list');
1286
1292
  }
1287
1293
  var fieldStart = index + 1;
1288
- for (var _cursor3 = index + 1; _cursor3 <= fromIndex; _cursor3 += 1) {
1294
+ for (var _cursor3 = index + 1; _cursor3 <= selectEnd; _cursor3 += 1) {
1289
1295
  var _expression;
1290
- var atFieldEnd = _cursor3 === fromIndex || tokenDepths[_cursor3] === depth && tokens[_cursor3].value === ',';
1296
+ var atFieldEnd = _cursor3 === selectEnd || tokenDepths[_cursor3] === depth && tokens[_cursor3].value === ',';
1291
1297
  if (!atFieldEnd) continue;
1292
1298
  var asIndex = findToken(fieldStart, _cursor3, depth, 'AS');
1293
1299
  var expressionEnd = asIndex >= 0 ? asIndex : _cursor3;
@@ -1301,7 +1307,7 @@ var validateSqlSyntax = exports.validateSqlSyntax = function validateSqlSyntax(s
1301
1307
  if (token === 'FROM') {
1302
1308
  var _tokens5;
1303
1309
  var _next = (_tokens5 = tokens[index + 1]) === null || _tokens5 === void 0 ? void 0 : _tokens5.value;
1304
- if (!_next || ['AS', 'JOIN', 'WHERE', 'GROUP', 'ORDER', 'LIMIT', 'UNION', ')'].includes(_next)) {
1310
+ if (!_next || ['AS', 'JOIN', 'WHERE', 'GROUP', 'HAVING', 'ORDER', 'LIMIT', 'UNION', ')'].includes(_next)) {
1305
1311
  addIssue('from');
1306
1312
  }
1307
1313
  }
@@ -1309,10 +1315,18 @@ var validateSqlSyntax = exports.validateSqlSyntax = function validateSqlSyntax(s
1309
1315
  var _tokens6;
1310
1316
  var joinEnd = findBoundary(index + 1, depth, clauseBoundaryWords);
1311
1317
  var onIndex = findToken(index + 1, joinEnd, depth, 'ON');
1312
- if (onIndex < 0 || onIndex === index + 1 || ((_tokens6 = tokens[index + 1]) === null || _tokens6 === void 0 ? void 0 : _tokens6.value) === 'AS') {
1318
+ var joinTarget = (_tokens6 = tokens[index + 1]) === null || _tokens6 === void 0 ? void 0 : _tokens6.value;
1319
+ var missingJoinTarget = !joinTarget || ['AS', 'ON', 'JOIN', 'WHERE', 'GROUP', 'HAVING', 'ORDER', 'LIMIT', 'UNION', ')'].includes(joinTarget);
1320
+ if (onIndex < 0 || missingJoinTarget || isEmptyExpressionSegment(onIndex + 1, joinEnd)) {
1313
1321
  addIssue('join');
1314
1322
  } else {
1315
- validateExpressionSegment(onIndex + 1, joinEnd);
1323
+ var _onSegment$, _onSegment;
1324
+ var onSegment = tokens.slice(onIndex + 1, joinEnd).filter(function (token) {
1325
+ return token.value !== ';';
1326
+ });
1327
+ if (invalidExpressionStart.has((_onSegment$ = onSegment[0]) === null || _onSegment$ === void 0 ? void 0 : _onSegment$.value) || invalidExpressionEnd.has((_onSegment = onSegment[onSegment.length - 1]) === null || _onSegment === void 0 ? void 0 : _onSegment.value)) {
1328
+ addIssue('join');
1329
+ }
1316
1330
  }
1317
1331
  }
1318
1332
  if (token === 'WHERE' || token === 'HAVING') {
@@ -1404,6 +1418,13 @@ var createIssueCollector = function createIssueCollector() {
1404
1418
  });
1405
1419
  },
1406
1420
  result: function result() {
1421
+ var getPathKey = function getPathKey() {
1422
+ var path = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
1423
+ return path.map(function (item) {
1424
+ var _item$metaKey2, _item$index2;
1425
+ return "".concat(item.type, ":").concat((_item$metaKey2 = item.metaKey) !== null && _item$metaKey2 !== void 0 ? _item$metaKey2 : '', ":").concat((_item$index2 = item.index) !== null && _item$index2 !== void 0 ? _item$index2 : '');
1426
+ }).join('/');
1427
+ };
1407
1428
  var scopedCodes = new Set(issues.filter(function (issue) {
1408
1429
  var _issue$path2;
1409
1430
  return (_issue$path2 = issue.path) === null || _issue$path2 === void 0 ? void 0 : _issue$path2.length;
@@ -1414,9 +1435,21 @@ var createIssueCollector = function createIssueCollector() {
1414
1435
  var _issue$path3;
1415
1436
  return ((_issue$path3 = issue.path) === null || _issue$path3 === void 0 ? void 0 : _issue$path3.length) || !scopedCodes.has(issue.code);
1416
1437
  });
1438
+ var joinPaths = new Set(locatedIssues.filter(function (issue) {
1439
+ var _issue$path4;
1440
+ return issue.code === 'join' && ((_issue$path4 = issue.path) === null || _issue$path4 === void 0 ? void 0 : _issue$path4.length);
1441
+ }).map(function (issue) {
1442
+ return getPathKey(issue.path);
1443
+ }));
1444
+ var deduped = locatedIssues.filter(function (issue) {
1445
+ var _issue$path5;
1446
+ if (!((_issue$path5 = issue.path) !== null && _issue$path5 !== void 0 && _issue$path5.length)) return true;
1447
+ if (issue.code !== 'dangling-operator' && issue.code !== 'clause') return true;
1448
+ return !joinPaths.has(getPathKey(issue.path));
1449
+ });
1417
1450
  return {
1418
- isError: locatedIssues.length > 0,
1419
- issues: locatedIssues
1451
+ isError: deduped.length > 0,
1452
+ issues: deduped
1420
1453
  };
1421
1454
  }
1422
1455
  };
@@ -1454,7 +1487,9 @@ var validateNestedMetasForSyntax = function validateNestedMetasForSyntax(metas,
1454
1487
  try {
1455
1488
  var sqlResult = handleSqlUnion(metas, db, noFields);
1456
1489
  if (noFields && !hasCompleteQuerySource(metas)) return;
1457
- ctx.merge(validateSqlSyntax(sqlResult.sql), path);
1490
+ ctx.merge(validateSqlSyntax(sqlResult.sql, {
1491
+ dialect: db
1492
+ }), path);
1458
1493
  if (!noFields) {
1459
1494
  var fieldCounts = (sqlResult.union_fields || []).map(function (fields) {
1460
1495
  return (fields === null || fields === void 0 ? void 0 : fields.length) || 0;
@@ -1518,7 +1553,9 @@ var _walkMetasForSyntax = function walkMetasForSyntax(metas, ctx, db) {
1518
1553
  }
1519
1554
  if (item.type === MetabaseTypeEnum.joinData) {
1520
1555
  var _item$table2, _item$expressions;
1521
- if (!((_item$table2 = item.table2) !== null && _item$table2 !== void 0 && _item$table2.name) || !((_item$expressions = item.expressions) !== null && _item$expressions !== void 0 && _item$expressions.length)) {
1556
+ var joinSql = String(_handleBaseType2Sql9(item.expressions || [], db).sql || '').trim();
1557
+ var blankJoinCondition = !joinSql || /^(AND|OR|NOT|=|!=|<>|<=|>=|<|>)+$/i.test(joinSql.replace(/\s+/g, ''));
1558
+ if (!((_item$table2 = item.table2) !== null && _item$table2 !== void 0 && _item$table2.name) || !((_item$expressions = item.expressions) !== null && _item$expressions !== void 0 && _item$expressions.length) || blankJoinCondition) {
1522
1559
  ctx.addIssue('join', 'error', itemPath);
1523
1560
  }
1524
1561
  walkAtomListForSyntax(item.expressions, ctx, db, itemPath);
@@ -1706,7 +1743,9 @@ var validateMetabaseConfig = exports.validateMetabaseConfig = function validateM
1706
1743
  var sqlResult = transformSql(metas, db, queryKind === 'exists');
1707
1744
  sql = sqlResult.sql;
1708
1745
  if (!isFragmentQuery) {
1709
- var syntaxResult = validateSqlSyntax(sql);
1746
+ var syntaxResult = validateSqlSyntax(sql, {
1747
+ dialect: db
1748
+ });
1710
1749
  if (queryKind === 'scalar') {
1711
1750
  syntaxResult.issues = syntaxResult.issues.filter(function (issue) {
1712
1751
  return issue.code !== 'select-list';
@@ -2769,6 +2769,7 @@ var FormulaList = forwardRef(function (props, ref) {
2769
2769
  notExistsColumns: exitData,
2770
2770
  fieldEnableAlias: false,
2771
2771
  toolbar: _toolbar,
2772
+ subToolbar: subToolbar,
2772
2773
  btnText: __('SqlQueryBuilder.confirm'),
2773
2774
  value: cloneDeep(_value),
2774
2775
  onOk: function onOk(newList) {