@gingkoo/pandora-metabase 1.0.0-alpha.4 → 1.0.0-alpha.5

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.
@@ -1,10 +1,13 @@
1
1
  import * as React from 'react';
2
2
  export declare function generateTrigger(PortalComponent: any): {
3
3
  new (props: PropsType): {
4
+ resizeObserver: ResizeObserver | null;
4
5
  resetId: number;
5
6
  ref: any;
6
7
  componentDidMount(): void;
8
+ componentDidUpdate(prevProps: PropsType): void;
7
9
  componentWillUnmount(): void;
10
+ initResizeObserver: () => void;
8
11
  bindEvent: () => void;
9
12
  closePopup: () => void;
10
13
  attachParent: (popupContainer: HTMLSpanElement) => void;
@@ -29,7 +32,6 @@ export declare function generateTrigger(PortalComponent: any): {
29
32
  shouldComponentUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<{}>, nextContext: any): boolean;
30
33
  componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
31
34
  getSnapshotBeforeUpdate?(prevProps: Readonly<PropsType>, prevState: Readonly<{}>): any;
32
- componentDidUpdate?(prevProps: Readonly<PropsType>, prevState: Readonly<{}>, snapshot?: any): void;
33
35
  componentWillMount?(): void;
34
36
  UNSAFE_componentWillMount?(): void;
35
37
  componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
@@ -45,10 +47,13 @@ export declare function generateTrigger(PortalComponent: any): {
45
47
  };
46
48
  declare const _default: {
47
49
  new (props: PropsType): {
50
+ resizeObserver: ResizeObserver | null;
48
51
  resetId: number;
49
52
  ref: any;
50
53
  componentDidMount(): void;
54
+ componentDidUpdate(prevProps: PropsType): void;
51
55
  componentWillUnmount(): void;
56
+ initResizeObserver: () => void;
52
57
  bindEvent: () => void;
53
58
  closePopup: () => void;
54
59
  attachParent: (popupContainer: HTMLSpanElement) => void;
@@ -73,7 +78,6 @@ declare const _default: {
73
78
  shouldComponentUpdate?(nextProps: Readonly<PropsType>, nextState: Readonly<{}>, nextContext: any): boolean;
74
79
  componentDidCatch?(error: Error, errorInfo: React.ErrorInfo): void;
75
80
  getSnapshotBeforeUpdate?(prevProps: Readonly<PropsType>, prevState: Readonly<{}>): any;
76
- componentDidUpdate?(prevProps: Readonly<PropsType>, prevState: Readonly<{}>, snapshot?: any): void;
77
81
  componentWillMount?(): void;
78
82
  UNSAFE_componentWillMount?(): void;
79
83
  componentWillReceiveProps?(nextProps: Readonly<PropsType>, nextContext: any): void;
package/lib/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @gingkoo/pandora-metabase v1.0.0-alpha.4
2
+ * @gingkoo/pandora-metabase v1.0.0-alpha.5
3
3
  */
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import * as React from 'react';
@@ -278,7 +278,6 @@ const summarizeToSql = (arr, record) => {
278
278
  condition,
279
279
  alias,
280
280
  name,
281
- fieldAlias,
282
281
  realName = ''
283
282
  } = record;
284
283
  let index = arr.indexOf(record);
@@ -339,7 +338,7 @@ const summarizeToSql = (arr, record) => {
339
338
  count++;
340
339
  }
341
340
  });
342
- as = fieldAlias || as + (count ? '_' + (count + 1) : '');
341
+ as = as + (count ? '_' + (count + 1) : '');
343
342
  return {
344
343
  sql: sql + ' AS ' + as,
345
344
  fieldAlias: as
@@ -1001,6 +1000,8 @@ const useStore = () => {
1001
1000
  }); //弹窗
1002
1001
  const [popupClosable, setClosable] = useState(true); //是否可关闭 如果弹框里面再弹框 则不可关闭
1003
1002
  const [popupClosable2, setClosable2] = useState(true); //是否可关闭 如果弹框里面再弹框 则不可关闭
1003
+ // 外层ref
1004
+ const popupContainer = useRef();
1004
1005
  // const [fetchDatasetFn, setFetchDatasetFn] = useState<(id: string) => Promise<any>>(
1005
1006
  // async () => {},
1006
1007
  // ); //fn
@@ -1411,7 +1412,8 @@ const useStore = () => {
1411
1412
  _setShowSubquery,
1412
1413
  constantList,
1413
1414
  setConstantList,
1414
- changeAlias
1415
+ changeAlias,
1416
+ popupContainer
1415
1417
  };
1416
1418
  };
1417
1419
 
@@ -3426,6 +3428,7 @@ function returnDocument(element) {
3426
3428
  const outSpacing = 10;
3427
3429
  function generateTrigger(PortalComponent) {
3428
3430
  class Trigger extends React.Component {
3431
+ resizeObserver = null; // 显式声明 resizeObserver 属性
3429
3432
  resetId = -1; // 监听窗口改变事件id 用于组件销毁的时候清除事件
3430
3433
  static defaultProps = {
3431
3434
  visible: false,
@@ -3440,11 +3443,39 @@ function generateTrigger(PortalComponent) {
3440
3443
  this.resetId = winResetEvent.addEvent(this.didUpdate, this, 300);
3441
3444
  this.props.container && this.props.container.addEventListener('scroll', this.didUpdate);
3442
3445
  this.bindEvent();
3446
+ // 延迟绑定 ResizeObserver 到 ensure the element is ready
3447
+ this.initResizeObserver();
3448
+ }
3449
+ componentDidUpdate(prevProps) {
3450
+ // 如果 children 发生变化,重新初始化观察器
3451
+ if (prevProps.children !== this.props.children) {
3452
+ this.initResizeObserver();
3453
+ }
3443
3454
  }
3444
3455
  componentWillUnmount() {
3445
3456
  winResetEvent.removeEvent(this.resetId);
3446
3457
  this.props.container && this.props.container.removeEventListener('scroll', this.didUpdate);
3458
+ if (this.resizeObserver) {
3459
+ this.resizeObserver.disconnect();
3460
+ this.resizeObserver = null;
3461
+ }
3447
3462
  }
3463
+ // children高度变化后,从新计算高度
3464
+ initResizeObserver = () => {
3465
+ const targetNode = this.ref.current;
3466
+ if (!targetNode) return;
3467
+ // 如果已经存在 ResizeObserver,先断开连接
3468
+ if (this.resizeObserver) {
3469
+ this.resizeObserver.disconnect();
3470
+ }
3471
+ // 初始化 ResizeObserver 并开始观察目标节点
3472
+ this.resizeObserver = new ResizeObserver(entries => {
3473
+ entries.forEach(entry => {
3474
+ this.didUpdate();
3475
+ });
3476
+ });
3477
+ this.resizeObserver.observe(targetNode);
3478
+ };
3448
3479
  bindEvent = () => {
3449
3480
  let that = this;
3450
3481
  returnDocument().body.addEventListener('click', function (e) {
@@ -6003,10 +6034,11 @@ const JoinData = props => {
6003
6034
  let oldList = cloneDeep(newMeta[index].subquery);
6004
6035
  let _toolbar = subToolbar || toolbar;
6005
6036
  _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
6037
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
6006
6038
  let o = Modal2.openModal({
6007
6039
  title: __('SqlQueryBuilder.subquery'),
6008
6040
  transparentMask: true,
6009
- zIndex: 200,
6041
+ zIndex: Number(zIndex),
6010
6042
  content: jsx(Fragment, {
6011
6043
  children: jsx(SqlVisionBuilder, {
6012
6044
  ...other,
@@ -7046,10 +7078,11 @@ const CustomColumn = props => {
7046
7078
  const showSubQuery = (e, i) => {
7047
7079
  let newMeta = store.metaList[groupIndex].list.slice();
7048
7080
  const _value = newMeta[index].customColumn[i] || [];
7081
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : 0;
7049
7082
  let o = Modal2.openModal({
7050
7083
  title: __('SqlQueryBuilder.customExpression'),
7051
7084
  transparentMask: true,
7052
- zIndex: 200,
7085
+ zIndex: Number(zIndex),
7053
7086
  content: jsx(Fragment, {
7054
7087
  children: jsx(Provider, {
7055
7088
  value: store,
@@ -7421,10 +7454,11 @@ const Filter = props => {
7421
7454
  let oldList = position ? [] : cloneDeep(newMeta[index].filter[i]?.subquery || []);
7422
7455
  let _toolbar = subToolbar || toolbar;
7423
7456
  _toolbar = _toolbar.filter(v => v !== 'group'); // 子查询不需要分组
7457
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : null;
7424
7458
  let o = Modal2.openModal({
7425
7459
  title: 'NOT EXISTS',
7426
7460
  transparentMask: true,
7427
- zIndex: 200,
7461
+ zIndex: Number(zIndex),
7428
7462
  content: jsx(Fragment, {
7429
7463
  children: jsx(SqlVisionBuilder, {
7430
7464
  ...other,
@@ -7760,7 +7794,7 @@ const GroupBy = props => {
7760
7794
  newMeta[index].by.splice(i, 1, data);
7761
7795
  // @ts-ignore
7762
7796
  newMeta[index].by = newMeta[index].by.map(v => {
7763
- const fieldAlias = v.fieldAlias || `${v.alias}__${v.name}`;
7797
+ const fieldAlias = `${v.alias}__${v.name}`;
7764
7798
  return {
7765
7799
  ...v,
7766
7800
  sql: `${v.alias}.${v.realName || v.name} AS ${fieldAlias}`,
@@ -7812,7 +7846,7 @@ const GroupBy = props => {
7812
7846
  newMeta[index].by.push(data);
7813
7847
  // @ts-ignore
7814
7848
  newMeta[index].by = newMeta[index].by.map(v => {
7815
- const fieldAlias = v.fieldAlias || `${v.alias}__${v.name}`;
7849
+ const fieldAlias = `${v.alias}__${v.name}`;
7816
7850
  return {
7817
7851
  ...v,
7818
7852
  sql: `${v.alias}.${v.realName || v.name} AS ${fieldAlias}`,
@@ -8627,7 +8661,8 @@ const Metabase = props => {
8627
8661
  } = props;
8628
8662
  const store = useStore$1();
8629
8663
  const [saveLoading, setSaveLoading] = useState(false);
8630
- const popupContainer = useRef();
8664
+ // const popupContainer = useRef();
8665
+ // store.setPopupContainer(popupContainer);
8631
8666
  const popupContent = useMemo(() => {
8632
8667
  let {
8633
8668
  visible,
@@ -8658,11 +8693,11 @@ const Metabase = props => {
8658
8693
  await onOk?.(_metaList);
8659
8694
  setSaveLoading(false);
8660
8695
  };
8661
- let zIndex = popupContainer.current ? getMaxZIndexInParents(popupContainer.current) : null;
8696
+ let zIndex = store.popupContainer.current ? getMaxZIndexInParents(store.popupContainer.current) : null;
8662
8697
  return (
8663
8698
  // @ts-ignore
8664
8699
  jsx(VisualBox, {
8665
- ref: popupContainer,
8700
+ ref: store.popupContainer,
8666
8701
  children: jsxs("div", {
8667
8702
  className: 'Sqb',
8668
8703
  children: [store.metaList.map((v, index) => {
@@ -8699,8 +8734,8 @@ const Metabase = props => {
8699
8734
  disabled: saveLoading,
8700
8735
  onClick: onSave,
8701
8736
  children: btnText || __('SqlQueryBuilder.visualize')
8702
- }) : null, popupContainer.current && jsx(Popup, {
8703
- container: popupContainer.current,
8737
+ }) : null, store.popupContainer.current && jsx(Popup, {
8738
+ container: store.popupContainer.current,
8704
8739
  visible: store.popupData.visible,
8705
8740
  node: store.popupData.node,
8706
8741
  closable: store.popupClosable,
@@ -8711,8 +8746,8 @@ const Metabase = props => {
8711
8746
  });
8712
8747
  },
8713
8748
  children: popupContent
8714
- }), popupContainer.current && jsx(Popup, {
8715
- container: popupContainer.current,
8749
+ }), store.popupContainer.current && jsx(Popup, {
8750
+ container: store.popupContainer.current,
8716
8751
  visible: store.popupData2.visible,
8717
8752
  node: store.popupData2.node,
8718
8753
  closable: store.popupClosable2,