sea-chart 1.1.15 → 1.1.16
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.
|
@@ -48,9 +48,12 @@ class StatisticRecordDialog extends React.Component {
|
|
|
48
48
|
var _context$api, _context$api2;
|
|
49
49
|
if ((_context$api = context.api) === null || _context$api === void 0 ? void 0 : _context$api.customQueryRows) {
|
|
50
50
|
const detailFilterConditions = {
|
|
51
|
-
filters: getFilterConditions(statisticRecord, chart, this.table
|
|
51
|
+
filters: getFilterConditions(statisticRecord, chart, this.table)
|
|
52
52
|
};
|
|
53
|
-
|
|
53
|
+
|
|
54
|
+
// if more then 2 filters, use 'Or' conjunction to get them all
|
|
55
|
+
// if the statistic record is '_Others', use 'Or' conjunction to get them all
|
|
56
|
+
if ((detailFilterConditions === null || detailFilterConditions === void 0 ? void 0 : detailFilterConditions.filters.length) > 2 || statisticRecord.name === '_Others') {
|
|
54
57
|
detailFilterConditions.filter_conjunction = 'Or';
|
|
55
58
|
}
|
|
56
59
|
context.api.customQueryRows(currentElementId, detailFilterConditions).then(res => {
|
|
@@ -12,7 +12,8 @@ import Highlighter from '../components/highlighter/highlighter';
|
|
|
12
12
|
import DigitalSignUtils from '../utils/digital-sign-utils';
|
|
13
13
|
import { getColumnByKey } from '../utils/column-utils';
|
|
14
14
|
import context from '../context';
|
|
15
|
-
import { xAxisMap, groupAxisMap
|
|
15
|
+
import { xAxisMap, groupAxisMap } from '../constants';
|
|
16
|
+
import { chartColumn2SqlColumn } from './sql';
|
|
16
17
|
export const UNSHOW_COLUMN_TYPE = [CellType.LINK, CellType.LONG_TEXT, CellType.FORMULA, CellType.LINK_FORMULA];
|
|
17
18
|
export const getCellRecordWidth = column => {
|
|
18
19
|
let {
|
|
@@ -499,10 +500,11 @@ const filterPredicateMap = {
|
|
|
499
500
|
[CellType.EMAIL]: 'is',
|
|
500
501
|
[CellType.URL]: 'is',
|
|
501
502
|
[CellType.STRING]: 'is',
|
|
502
|
-
[CellType.BOOL]: 'is'
|
|
503
|
+
[CellType.BOOL]: 'is',
|
|
504
|
+
[CellType.LINK_FORMULA]: 'has_any_of'
|
|
503
505
|
};
|
|
504
506
|
const USE_OPTION_ID_CELL_TYPES = [CellType.SINGLE_SELECT, CellType.MULTIPLE_SELECT];
|
|
505
|
-
const
|
|
507
|
+
const getFilterByColumnTypeForPivot = (columnKey, columns, value, rows) => {
|
|
506
508
|
if (!rows) rows = [];
|
|
507
509
|
const filter = {
|
|
508
510
|
column_key: columnKey || ''
|
|
@@ -512,24 +514,14 @@ const getFilterByColumnType = (columnKey, columns, value, rows) => {
|
|
|
512
514
|
return filter;
|
|
513
515
|
}
|
|
514
516
|
let type = column.type;
|
|
515
|
-
if (type === CellType.LINK_FORMULA) {
|
|
516
|
-
type = column.data.array_type;
|
|
517
|
-
const correctRow = rows.find(r => columnKey in r);
|
|
518
|
-
value = correctRow && correctRow[columnKey];
|
|
519
|
-
Array.isArray(value) && (value = value[0]);
|
|
520
|
-
}
|
|
521
517
|
if (type === CellType.FORMULA) {
|
|
522
518
|
type = column.data.result_type;
|
|
523
|
-
const correctRow = rows.find(r => columnKey in r);
|
|
524
|
-
value = correctRow && correctRow[columnKey];
|
|
525
519
|
}
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
const correctRow = rows.find(r => columnKey in r);
|
|
530
|
-
value = correctRow && correctRow[columnKey];
|
|
520
|
+
if (type === CellType.LINK_FORMULA) {
|
|
521
|
+
type = column.data.array_type;
|
|
522
|
+
Array.isArray(value) && (value = value[0]);
|
|
531
523
|
}
|
|
532
|
-
if (column && [CellType.GEOLOCATION, CellType.DATE].includes(type)) {
|
|
524
|
+
if (column && [CellType.GEOLOCATION, CellType.DATE, CellType.MTIME, CellType.CTIME].includes(type)) {
|
|
533
525
|
filter['value'] = value;
|
|
534
526
|
return filter;
|
|
535
527
|
}
|
|
@@ -549,13 +541,55 @@ const getFilterByColumnType = (columnKey, columns, value, rows) => {
|
|
|
549
541
|
filter['filter_predicate'] = filterPredicateMap[type];
|
|
550
542
|
return filter;
|
|
551
543
|
};
|
|
552
|
-
|
|
553
|
-
|
|
544
|
+
const getFilterByColumnType = (columnKey, columns, rows, sqlColumnKey) => {
|
|
545
|
+
if (!rows) rows = [];
|
|
546
|
+
const filter = {
|
|
547
|
+
column_key: columnKey || ''
|
|
548
|
+
};
|
|
549
|
+
|
|
550
|
+
// need column to get type
|
|
551
|
+
const column = getColumnByKey(columnKey, columns);
|
|
552
|
+
if (!column) {
|
|
553
|
+
return filter;
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
// normal case
|
|
557
|
+
let value;
|
|
558
|
+
let type = column.type;
|
|
559
|
+
let columnType = column.type;
|
|
560
|
+
const correctRow = rows.find(r => sqlColumnKey in r);
|
|
561
|
+
value = correctRow && correctRow[sqlColumnKey];
|
|
562
|
+
if (type === CellType.FORMULA) {
|
|
563
|
+
type = column.data.result_type;
|
|
564
|
+
}
|
|
565
|
+
if (type === CellType.LINK_FORMULA) {
|
|
566
|
+
type = column.data.array_type;
|
|
567
|
+
}
|
|
568
|
+
if (column && [CellType.GEOLOCATION, CellType.DATE, CellType.MTIME, CellType.CTIME].includes(type)) {
|
|
569
|
+
// link_formula result is an array, but can't pass the value directly as an array here
|
|
570
|
+
if (Array.isArray(value)) value = value[0];
|
|
571
|
+
filter['value'] = value;
|
|
572
|
+
return filter;
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// value may contains spaces
|
|
576
|
+
if (typeof value === 'string') {
|
|
577
|
+
value = value.trim();
|
|
578
|
+
}
|
|
579
|
+
filter['filter_term'] = value;
|
|
580
|
+
|
|
581
|
+
// link_formula use has_any_of
|
|
582
|
+
if (columnType === CellType.LINK_FORMULA) {
|
|
583
|
+
filter['filter_predicate'] = filterPredicateMap[columnType];
|
|
584
|
+
} else {
|
|
585
|
+
filter['filter_predicate'] = filterPredicateMap[type];
|
|
586
|
+
}
|
|
587
|
+
return filter;
|
|
588
|
+
};
|
|
589
|
+
export const getFilterConditions = (statisticRecord, chart, table) => {
|
|
590
|
+
const columns = table.columns || [];
|
|
554
591
|
const {
|
|
555
|
-
original_name = '',
|
|
556
592
|
name = '',
|
|
557
|
-
group_name = '',
|
|
558
|
-
groupby = '',
|
|
559
593
|
rows,
|
|
560
594
|
isPivot
|
|
561
595
|
} = statisticRecord || {};
|
|
@@ -568,12 +602,17 @@ export const getFilterConditions = function (statisticRecord, chart) {
|
|
|
568
602
|
const filters = [];
|
|
569
603
|
const columnKey = xAxisMap[type];
|
|
570
604
|
const groupColumnKey = groupAxisMap[type];
|
|
605
|
+
const chartSQLMap = chartColumn2SqlColumn(chart, table);
|
|
606
|
+
const {
|
|
607
|
+
sqlColumnGroupbyColumnKey,
|
|
608
|
+
sqlGroupbyColumnKey
|
|
609
|
+
} = chartSQLMap;
|
|
571
610
|
if (isPivot && rows.length) {
|
|
572
611
|
const xValueList = [];
|
|
573
612
|
const yValueList = [];
|
|
574
613
|
rows.forEach(r => {
|
|
575
|
-
const xValue = r[
|
|
576
|
-
const yValue = r[
|
|
614
|
+
const xValue = r[sqlGroupbyColumnKey];
|
|
615
|
+
const yValue = r[sqlColumnGroupbyColumnKey];
|
|
577
616
|
if (!xValueList.some(v => isEqual(v, xValue))) {
|
|
578
617
|
xValueList.push(xValue);
|
|
579
618
|
}
|
|
@@ -581,29 +620,24 @@ export const getFilterConditions = function (statisticRecord, chart) {
|
|
|
581
620
|
yValueList.push(yValue);
|
|
582
621
|
}
|
|
583
622
|
});
|
|
584
|
-
|
|
585
|
-
const columnFilter =
|
|
623
|
+
xValueList.forEach(xValue => {
|
|
624
|
+
const columnFilter = getFilterByColumnTypeForPivot(config[columnKey], columns, xValue, rows);
|
|
586
625
|
filters.push(columnFilter);
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
const columnFilter =
|
|
626
|
+
});
|
|
627
|
+
yValueList.forEach(yValue => {
|
|
628
|
+
const columnFilter = getFilterByColumnTypeForPivot(config[groupColumnKey], columns, yValue, rows);
|
|
590
629
|
filters.push(columnFilter);
|
|
591
|
-
}
|
|
630
|
+
});
|
|
592
631
|
} else {
|
|
593
|
-
// pie and ring chart
|
|
594
632
|
if (name === '_Others') {
|
|
595
|
-
const columnFilters = rows.map(
|
|
633
|
+
const columnFilters = rows.map(row => getFilterByColumnType(config[columnKey], columns, [row], sqlGroupbyColumnKey));
|
|
596
634
|
filters.push(...columnFilters);
|
|
597
635
|
} else {
|
|
598
|
-
const columnFilter = getFilterByColumnType(config[columnKey], columns,
|
|
636
|
+
const columnFilter = getFilterByColumnType(config[columnKey], columns, rows, sqlGroupbyColumnKey);
|
|
599
637
|
filters.push(columnFilter);
|
|
600
638
|
}
|
|
601
|
-
if (
|
|
602
|
-
|
|
603
|
-
if (COMPLTETELESS_CHART_TYPES.includes(type)) {
|
|
604
|
-
groupNameFiled = groupby;
|
|
605
|
-
}
|
|
606
|
-
const groupColumnFilter = getFilterByColumnType(config[groupColumnKey], columns, groupNameFiled);
|
|
639
|
+
if (sqlColumnGroupbyColumnKey) {
|
|
640
|
+
const groupColumnFilter = getFilterByColumnType(config[groupColumnKey], columns, rows, sqlColumnGroupbyColumnKey);
|
|
607
641
|
filters.push(groupColumnFilter);
|
|
608
642
|
}
|
|
609
643
|
}
|