sea-chart 1.1.115 → 1.1.117

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,6 +1,5 @@
1
1
  import dayjs from 'dayjs';
2
2
  import { CellType, COLLABORATOR_COLUMN_TYPES, FORMULA_RESULT_TYPE, getCollaboratorsName, getFormulaDisplayString, FORMULA_COLUMN_TYPES_MAP, getCellValueDisplayString } from 'dtable-utils';
3
- import ObjectUtils from './object-utils';
4
3
  export const getClientFormulaDisplayString = function (value, columnData) {
5
4
  let {
6
5
  collaborators = []
@@ -30,12 +29,15 @@ export const getClientLinkDisplayString = (links, columnData, _ref) => {
30
29
  if (!columnData || !Array.isArray(links) || links.length === 0) {
31
30
  return null;
32
31
  }
33
-
34
- // eslint-disable-next-line
35
- const formulaData = ObjectUtils.hasOwnProperty(columnData, 'result_type') ? columnData : {
36
- ...columnData,
37
- result_type: FORMULA_RESULT_TYPE.ARRAY
38
- };
32
+ let formulaData = columnData;
33
+ const hasResultType = Object.prototype.hasOwnProperty.call(columnData, 'result_type');
34
+ if (!hasResultType) {
35
+ formulaData = {
36
+ ...columnData,
37
+ result_type: FORMULA_RESULT_TYPE.ARRAY,
38
+ array_type: 'text'
39
+ };
40
+ }
39
41
  const displayValue = links.map(link => link.display_value);
40
42
  return getClientFormulaDisplayString(displayValue, formulaData, {
41
43
  collaborators
@@ -762,6 +762,43 @@ BaseUtils.updateTableViewListItemNameAndColor = async (result, column, nameKey,
762
762
  };
763
763
  // for linked formula, need to call recursively, using it's result as the result of the promise
764
764
  resultPromise = _BaseUtils.updateTableViewListItemNameAndColor(result, linkedColumn, nameKey, colorKey, isScatterChart);
765
+ } else if (columnType === CellType.FORMULA) {
766
+ const {
767
+ result_type: resultType,
768
+ array_type: arrayType,
769
+ array_data: arrayData
770
+ } = columnData || {};
771
+ if (resultType === FORMULA_RESULT_TYPE.NUMBER) {
772
+ const valueNumber = parseFloat(name);
773
+ result[nameKey] = isNumber(valueNumber) ? getNumberDisplayString(valueNumber, columnData) : name;
774
+ isNameField && (result.original_name = name);
775
+ } else if (resultType === FORMULA_RESULT_TYPE.DATE || resultType === CellType.CTIME || resultType === CellType.MTIME) {
776
+ result[nameKey] = getFormulaDisplayString(name, columnData);
777
+ isNameField && (result.original_name = name);
778
+ } else if (arrayType && arrayData) {
779
+ const formulaArrayColumn = {
780
+ ...column,
781
+ type: arrayType,
782
+ data: arrayData
783
+ };
784
+ resultPromise = _BaseUtils.updateTableViewListItemNameAndColor(result, formulaArrayColumn, nameKey, colorKey, isScatterChart, isNameField);
785
+ } else if (Array.isArray(name)) {
786
+ result[nameKey] = name.map(item => {
787
+ if (isValidCollaboratorEmail(item)) {
788
+ const collaborator = getKnownCollaboratorByEmail(item);
789
+ return collaborator ? collaborator.name : item;
790
+ }
791
+ return item;
792
+ }).join(', ');
793
+ isNameField && (result.original_name = name.join(', '));
794
+ } else if (typeof name === 'string' && isValidCollaboratorEmail(name)) {
795
+ const collaborator = getKnownCollaboratorByEmail(name);
796
+ result[nameKey] = collaborator ? collaborator.name : name;
797
+ isNameField && (result.original_name = name);
798
+ } else {
799
+ result[nameKey] = getFormulaDisplayString(name, columnData);
800
+ isNameField && (result.original_name = name);
801
+ }
765
802
  }
766
803
  resolve(resultPromise);
767
804
  });
@@ -1,7 +1,7 @@
1
1
  import _ButtonFormatter from "dtable-ui-component/lib/ButtonFormatter";
2
2
  import _RateFormatter from "dtable-ui-component/lib/RateFormatter";
3
3
  import React from 'react';
4
- import { CellType, FORMULA_RESULT_TYPE, getNumberDisplayString, getDateDisplayString, getCellValueStringResult, isNumber, isDateColumn, isValidLink, getColumnOptions } from 'dtable-utils';
4
+ import { CellType, FORMULA_RESULT_TYPE, COLLABORATOR_COLUMN_TYPES, getNumberDisplayString, getDateDisplayString, getCellValueStringResult, isNumber, isValidLink, getColumnOptions } from 'dtable-utils';
5
5
  import dayjs from 'dayjs';
6
6
  import { isEqual } from 'lodash-es';
7
7
  import cellFormatterFactory from '../components/cell-factory/cell-formatter-factory';
@@ -517,11 +517,21 @@ const getFilterByColumnTypeForPivot = (columnKey, columns, value, rows) => {
517
517
  }
518
518
  let type = column.type;
519
519
  const columnType = column.type;
520
- if (columnType === CellType.FORMULA) {
521
- type = column.data.result_type;
520
+ const {
521
+ result_type,
522
+ array_type
523
+ } = column.data || {};
524
+
525
+ // get the actual type for formula columns
526
+ if (type === CellType.FORMULA) {
527
+ if (result_type === FORMULA_RESULT_TYPE.ARRAY && array_type) {
528
+ type = array_type;
529
+ } else {
530
+ type = result_type;
531
+ }
522
532
  }
523
- if (columnType === CellType.LINK_FORMULA) {
524
- type = column.data.array_type;
533
+ if (type === CellType.LINK_FORMULA) {
534
+ type = array_type;
525
535
  // extract display_value from link formula column value
526
536
  if (Array.isArray(value) && value.length > 0) {
527
537
  value = value[0];
@@ -531,9 +541,9 @@ const getFilterByColumnTypeForPivot = (columnKey, columns, value, rows) => {
531
541
  // handle link column based on array_type
532
542
  if (columnType === CellType.LINK) {
533
543
  var _column$data, _value$;
534
- const arrayType = (_column$data = column.data) === null || _column$data === void 0 ? void 0 : _column$data.array_type;
535
- if (arrayType) {
536
- type = arrayType;
544
+ const linkArrayType = (_column$data = column.data) === null || _column$data === void 0 ? void 0 : _column$data.array_type;
545
+ if (linkArrayType) {
546
+ type = linkArrayType;
537
547
  }
538
548
  // extract display_value from link column value
539
549
  if (Array.isArray(value) && value.length > 0 && ((_value$ = value[0]) === null || _value$ === void 0 ? void 0 : _value$.display_value) !== undefined) {
@@ -547,19 +557,24 @@ const getFilterByColumnTypeForPivot = (columnKey, columns, value, rows) => {
547
557
  if (typeof value === 'string') {
548
558
  value = value.trim();
549
559
  }
560
+
561
+ // handle collaborator type for formula/link_formula columns
562
+ const isFormulaCollaborator = (columnType === CellType.FORMULA || columnType === CellType.LINK_FORMULA) && result_type === FORMULA_RESULT_TYPE.ARRAY && COLLABORATOR_COLUMN_TYPES.includes(array_type);
550
563
  if (USE_OPTION_ID_CELL_TYPES.includes(column.type)) {
551
564
  const options = getColumnOptions(column);
552
565
  // name may contains spaces
553
566
  // value maybe id or name, find option by name or id
554
567
  const selectedOption = options.find(o => o.name.trim() === value || o.id === value);
555
568
  filter['filter_term'] = selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.id;
569
+ } else if (isFormulaCollaborator) {
570
+ filter['filter_term'] = Array.isArray(value) ? value : [value];
556
571
  } else {
557
572
  // value may contains spaces
558
573
  filter['filter_term'] = value;
559
574
  }
560
-
561
- // link_formula and link use is
562
- if ([CellType.LINK_FORMULA, CellType.LINK].includes(columnType)) {
575
+ if (isFormulaCollaborator) {
576
+ filter['filter_predicate'] = filterPredicateMap[CellType.COLLABORATOR];
577
+ } else if ([CellType.LINK_FORMULA, CellType.LINK].includes(columnType)) {
563
578
  filter['filter_predicate'] = filterPredicateMap[columnType];
564
579
  } else {
565
580
  filter['filter_predicate'] = filterPredicateMap[type];
@@ -582,13 +597,23 @@ const getFilterByColumnType = (columnKey, columns, rows, sqlColumnKey) => {
582
597
  let value;
583
598
  let type = column.type;
584
599
  let columnType = column.type;
600
+ const {
601
+ result_type,
602
+ array_type
603
+ } = column.data || {};
585
604
  const correctRow = rows.find(r => sqlColumnKey in r);
586
605
  value = correctRow && correctRow[sqlColumnKey];
587
- if (columnType === CellType.FORMULA) {
588
- type = column.data.result_type;
606
+
607
+ // get the actual type for formula columns
608
+ if (type === CellType.FORMULA) {
609
+ if (result_type === FORMULA_RESULT_TYPE.ARRAY && array_type) {
610
+ type = array_type;
611
+ } else {
612
+ type = result_type;
613
+ }
589
614
  }
590
- if (columnType === CellType.LINK_FORMULA) {
591
- type = column.data.array_type;
615
+ if (type === CellType.LINK_FORMULA) {
616
+ type = array_type;
592
617
  // extract display_value from link formula column value
593
618
  if (Array.isArray(value) && value.length > 0) {
594
619
  value = value[0];
@@ -598,9 +623,9 @@ const getFilterByColumnType = (columnKey, columns, rows, sqlColumnKey) => {
598
623
  // handle link column based on array_type
599
624
  if (columnType === CellType.LINK) {
600
625
  var _column$data2, _value$2;
601
- const arrayType = (_column$data2 = column.data) === null || _column$data2 === void 0 ? void 0 : _column$data2.array_type;
602
- if (arrayType) {
603
- type = arrayType;
626
+ const linkArrayType = (_column$data2 = column.data) === null || _column$data2 === void 0 ? void 0 : _column$data2.array_type;
627
+ if (linkArrayType) {
628
+ type = linkArrayType;
604
629
  }
605
630
  // extract display_value from link column value
606
631
  if (Array.isArray(value) && value.length > 0 && ((_value$2 = value[0]) === null || _value$2 === void 0 ? void 0 : _value$2.display_value) !== undefined) {
@@ -614,14 +639,21 @@ const getFilterByColumnType = (columnKey, columns, rows, sqlColumnKey) => {
614
639
  return filter;
615
640
  }
616
641
 
642
+ // handle collaborator type for formula/link_formula columns
643
+ const isFormulaCollaborator = (columnType === CellType.FORMULA || columnType === CellType.LINK_FORMULA) && result_type === FORMULA_RESULT_TYPE.ARRAY && COLLABORATOR_COLUMN_TYPES.includes(array_type);
644
+
617
645
  // value may contains spaces
618
646
  if (typeof value === 'string') {
619
647
  value = value.trim();
620
648
  }
621
- filter['filter_term'] = value;
622
-
623
- // link_formula and link use is
624
- if ([CellType.LINK_FORMULA, CellType.LINK].includes(columnType)) {
649
+ if (isFormulaCollaborator) {
650
+ filter['filter_term'] = Array.isArray(value) ? value : [value];
651
+ } else {
652
+ filter['filter_term'] = value;
653
+ }
654
+ if (isFormulaCollaborator) {
655
+ filter['filter_predicate'] = filterPredicateMap[CellType.COLLABORATOR];
656
+ } else if ([CellType.LINK_FORMULA, CellType.LINK].includes(columnType)) {
625
657
  filter['filter_predicate'] = filterPredicateMap[columnType];
626
658
  } else {
627
659
  filter['filter_predicate'] = filterPredicateMap[type];
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "sea-chart",
3
- "version": "1.1.115",
3
+ "version": "1.1.117",
4
4
  "main": "./dist/index.js",
5
5
  "dependencies": {
6
6
  "@antv/data-set": "0.11.8",
7
7
  "@antv/g2": "4.1.46",
8
+ "@antv/util": "^3.3.2",
8
9
  "@dnd-kit/core": "^6.3.1",
9
10
  "@dnd-kit/modifiers": "^9.0.0",
10
11
  "@dnd-kit/sortable": "^10.0.0",