@seafile/sdoc-editor 0.3.26-1 → 0.3.26-2

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.
Files changed (44) hide show
  1. package/dist/basic-sdk/constants/index.js +2 -1
  2. package/dist/basic-sdk/editor/sdoc-editor.js +1 -1
  3. package/dist/basic-sdk/extension/plugins/chart/chart-components/chart-type-setting/index.css +1 -1
  4. package/dist/basic-sdk/extension/plugins/chart/chart-components/common-settings/column-setting.js +1 -1
  5. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/common-add-tool.js +23 -0
  6. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/common-hooks.js +15 -0
  7. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/constants.js +10 -0
  8. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/custom-select/index.js +98 -0
  9. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/custom-select/option-group.js +236 -0
  10. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/custom-select/option.js +40 -0
  11. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/custom-select/select.css +135 -0
  12. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/date-translate.js +54 -0
  13. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/department-editor/department-multiple-select.js +146 -0
  14. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/department-editor/department-single-select.js +272 -0
  15. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/department-editor/index.css +209 -0
  16. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/department-editor/index.js +98 -0
  17. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/department-editor/selected-departments.js +85 -0
  18. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/dtable-search-input.js +127 -0
  19. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/collaborator-filter.js +106 -0
  20. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/department-multiple-select-filter.js +86 -0
  21. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/department-single-select-filter.js +85 -0
  22. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/filter-calendar.js +166 -0
  23. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/filter-item-utils.js +144 -0
  24. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/filter-item.js +679 -0
  25. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/filters-list.css +320 -0
  26. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/filters-list.js +121 -0
  27. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover-widgets/rate-item.js +72 -0
  28. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filter-popover.js +208 -0
  29. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/filters-popover.css +30 -0
  30. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/index.css +18 -0
  31. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/index.js +79 -0
  32. package/dist/basic-sdk/extension/plugins/chart/chart-components/data-filter-setting/utils.js +531 -0
  33. package/dist/basic-sdk/extension/plugins/chart/chart-edit-dialog/index.js +76 -15
  34. package/dist/basic-sdk/extension/plugins/chart/chart-setting/index.js +5 -0
  35. package/dist/basic-sdk/extension/plugins/chart/chart-utils/common-utils/base-utils.js +84 -3
  36. package/dist/basic-sdk/extension/plugins/chart/chart-utils/common-utils/dtable-utils.js +2 -5
  37. package/dist/basic-sdk/extension/plugins/chart/chart-utils/histogram-bar-utils.js +2 -3
  38. package/dist/basic-sdk/extension/plugins/chart/constants/special-column-types.js +7 -7
  39. package/dist/basic-sdk/extension/plugins/chart/helpers.js +17 -1
  40. package/dist/basic-sdk/extension/plugins/chart/hover-menu/index.js +0 -1
  41. package/dist/basic-sdk/extension/plugins/chart/model.js +1 -0
  42. package/dist/basic-sdk/extension/plugins/chart/render-elem.js +18 -73
  43. package/dist/context.js +4 -0
  44. package/package.json +4 -2
@@ -0,0 +1,679 @@
1
+ import React, { Fragment } from 'react';
2
+ import classnames from 'classnames';
3
+ import { withTranslation } from 'react-i18next';
4
+ import { UncontrolledTooltip } from 'reactstrap';
5
+ import { CellType, COLLABORATOR_COLUMN_TYPES, DATE_COLUMN_OPTIONS, FORMULA_RESULT_TYPE, FILTER_PREDICATE_TYPE, FILTER_TERM_MODIFIER_TYPE, filterTermModifierIsWithin, isDateColumn } from 'dtable-utils';
6
+ import Select from '../custom-select';
7
+ import DtableSearchInput from '../dtable-search-input';
8
+ import CollaboratorFilter from './collaborator-filter';
9
+ import DepartmentSingleSelectFilter from './department-single-select-filter';
10
+ import DepartmentMultipleSelectFilter from './department-multiple-select-filter';
11
+ import RateItem from './rate-item';
12
+ import FilterCalendar from './filter-calendar';
13
+ import FilterItemUtils from './filter-item-utils';
14
+ import { getFilterByColumn, getUpdatedFilterBySelectSingle, getUpdatedFilterBySelectMultiple, isCheckboxColumn, generateDefaultUser, getUpdatedFilterByCreator, getUpdatedFilterByCollaborator, getColumnOptions, getUpdatedFilterByPredicate } from '../utils';
15
+ const EMPTY_PREDICATE = [FILTER_PREDICATE_TYPE.EMPTY, FILTER_PREDICATE_TYPE.NOT_EMPTY];
16
+ class FilterItem extends React.Component {
17
+ constructor(_props) {
18
+ var _this;
19
+ super(_props);
20
+ _this = this;
21
+ this.initSelectOptions = props => {
22
+ const {
23
+ filter,
24
+ filterColumn,
25
+ value,
26
+ isPre,
27
+ t
28
+ } = props;
29
+ let {
30
+ filterPredicateList,
31
+ filterTermModifierList
32
+ } = getColumnOptions(filterColumn, value);
33
+ // The value of the calculation formula column does not exist in the shared view
34
+ this.filterPredicateOptions = filterPredicateList ? filterPredicateList.map(predicate => {
35
+ return FilterItemUtils.generatorPredicateOption(predicate, isPre, t);
36
+ }).filter(item => item) : [];
37
+ const {
38
+ filter_predicate
39
+ } = filter;
40
+ if (isDateColumn(filterColumn)) {
41
+ if (filter_predicate === FILTER_PREDICATE_TYPE.IS_WITHIN) {
42
+ filterTermModifierList = filterTermModifierIsWithin;
43
+ }
44
+ this.filterTermModifierOptions = filterTermModifierList.map(termModifier => {
45
+ return FilterItemUtils.generatorTermModifierOption(termModifier, t);
46
+ });
47
+ }
48
+ };
49
+ this.onDeleteFilter = event => {
50
+ event.nativeEvent.stopImmediatePropagation();
51
+ const {
52
+ index
53
+ } = this.props;
54
+ this.props.deleteFilter(index);
55
+ };
56
+ this.resetState = filter => {
57
+ this.setState({
58
+ filterTerm: filter.filter_term
59
+ });
60
+ };
61
+ this.onSelectConjunction = value => {
62
+ const {
63
+ filterConjunction
64
+ } = this.props;
65
+ if (filterConjunction === value.filterConjunction) {
66
+ return;
67
+ }
68
+ this.props.updateConjunction(value.filterConjunction);
69
+ };
70
+ this.onSelectColumn = value => {
71
+ const {
72
+ index,
73
+ filter
74
+ } = this.props;
75
+ const {
76
+ column
77
+ } = value;
78
+ if (column.key === filter.column_key) return;
79
+ let newFilter = getFilterByColumn(column, filter);
80
+ if (!newFilter) return;
81
+ this.resetState(newFilter);
82
+ this.props.updateFilter(index, newFilter);
83
+ };
84
+ this.onSelectPredicate = value => {
85
+ const {
86
+ index,
87
+ filter,
88
+ filterColumn
89
+ } = this.props;
90
+ const {
91
+ filterPredicate
92
+ } = value;
93
+ if (filter.filter_predicate === filterPredicate) {
94
+ return;
95
+ }
96
+ let newFilter = getUpdatedFilterByPredicate(filter, filterColumn, filterPredicate);
97
+ this.resetState(newFilter);
98
+ this.props.updateFilter(index, newFilter);
99
+ };
100
+ this.onSelectTermModifier = value => {
101
+ const {
102
+ index,
103
+ filter
104
+ } = this.props;
105
+ const {
106
+ filterTermModifier
107
+ } = value;
108
+ const inputRangeLabel = [FILTER_TERM_MODIFIER_TYPE.EXACT_DATE, FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_AGO, FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_FROM_NOW, FILTER_TERM_MODIFIER_TYPE.THE_NEXT_NUMBERS_OF_DAYS, FILTER_TERM_MODIFIER_TYPE.THE_PAST_NUMBERS_OF_DAYS];
109
+ if (filter.filter_term_modifier === filterTermModifier) {
110
+ return;
111
+ }
112
+ let filter_term = filter.filter_term;
113
+ if (inputRangeLabel.indexOf(filter.filter_term_modifier) > -1) {
114
+ filter_term = '';
115
+ }
116
+ let newFilter = Object.assign({}, filter, {
117
+ filter_term_modifier: filterTermModifier,
118
+ filter_term
119
+ });
120
+ this.resetState(newFilter);
121
+ this.props.updateFilter(index, newFilter);
122
+ };
123
+ this.onSelectSingle = value => {
124
+ const {
125
+ index,
126
+ filter
127
+ } = this.props;
128
+ const {
129
+ columnOption: option
130
+ } = value;
131
+ if (filter.filter_term === option.id) {
132
+ return;
133
+ }
134
+ let newFilter = getUpdatedFilterBySelectSingle(filter, option);
135
+ this.resetState(newFilter);
136
+ this.props.updateFilter(index, newFilter);
137
+ };
138
+ this.onSelectMultiple = value => {
139
+ const {
140
+ index,
141
+ filter
142
+ } = this.props;
143
+ const {
144
+ columnOption: option
145
+ } = value;
146
+ let newFilter = getUpdatedFilterBySelectMultiple(filter, option);
147
+ this.resetState(newFilter);
148
+ this.props.updateFilter(index, newFilter);
149
+ };
150
+ this.onSelectCollaborator = value => {
151
+ const {
152
+ index,
153
+ filter
154
+ } = this.props;
155
+ const {
156
+ columnOption: collaborator
157
+ } = value;
158
+ let newFilter = getUpdatedFilterByCollaborator(filter, collaborator);
159
+ this.resetState(newFilter);
160
+ this.props.updateFilter(index, newFilter);
161
+ };
162
+ this.onSelectCreator = value => {
163
+ const {
164
+ index,
165
+ filter
166
+ } = this.props;
167
+ const {
168
+ columnOption: collaborator
169
+ } = value;
170
+ let newFilter = getUpdatedFilterByCreator(filter, collaborator);
171
+ // the predicate is 'is' or 'is not'
172
+ if (!newFilter) {
173
+ return;
174
+ }
175
+ this.resetState(newFilter);
176
+ this.props.updateFilter(index, newFilter);
177
+ };
178
+ this.onFilterTermCheckboxChanged = e => {
179
+ this.onFilterTermChanged(e.target.checked);
180
+ };
181
+ this.onFilterTermTextChanged = value => {
182
+ this.onFilterTermChanged(value);
183
+ };
184
+ this.onFilterTermChanged = newFilterTerm => {
185
+ const {
186
+ index,
187
+ filter
188
+ } = this.props;
189
+ const {
190
+ filterTerm
191
+ } = this.state;
192
+ if (newFilterTerm !== filterTerm) {
193
+ this.setState({
194
+ filterTerm: newFilterTerm
195
+ });
196
+ let newFilter = Object.assign({}, filter, {
197
+ filter_term: newFilterTerm
198
+ });
199
+ this.props.updateFilter(index, newFilter);
200
+ }
201
+ };
202
+ this.onMouseEnterRateItem = index => {
203
+ this.setState({
204
+ enterRateItemIndex: index
205
+ });
206
+ };
207
+ this.onMouseLeaveRateItem = () => {
208
+ this.setState({
209
+ enterRateItemIndex: 0
210
+ });
211
+ };
212
+ this.onChangeRateNumber = index => {
213
+ this.onFilterTermChanged(index);
214
+ };
215
+ this.getInputComponent = type => {
216
+ const {
217
+ filterTerm
218
+ } = this.state;
219
+ if (type === 'text') {
220
+ return /*#__PURE__*/React.createElement(DtableSearchInput, {
221
+ value: filterTerm,
222
+ onChange: this.onFilterTermTextChanged,
223
+ autoFocus: false,
224
+ className: classnames('text-truncate')
225
+ });
226
+ } else if (type === 'checkbox') {
227
+ return /*#__PURE__*/React.createElement("input", {
228
+ type: "checkbox",
229
+ checked: filterTerm,
230
+ onChange: this.onFilterTermCheckboxChanged
231
+ });
232
+ }
233
+ };
234
+ this.renderConjunction = () => {
235
+ const {
236
+ index,
237
+ filterConjunction,
238
+ conjunctionOptions,
239
+ t
240
+ } = this.props;
241
+ switch (index) {
242
+ case 0:
243
+ {
244
+ return null;
245
+ }
246
+ case 1:
247
+ {
248
+ const activeConjunction = FilterItemUtils.getActiveConjunctionOption(filterConjunction, t);
249
+ return /*#__PURE__*/React.createElement(Select, {
250
+ value: activeConjunction,
251
+ options: conjunctionOptions,
252
+ onSelectOption: this.onSelectConjunction
253
+ });
254
+ }
255
+ default:
256
+ {
257
+ return /*#__PURE__*/React.createElement("span", {
258
+ className: "selected-conjunction-show"
259
+ }, t(filterConjunction));
260
+ }
261
+ }
262
+ };
263
+ this.renderMultipleSelectOption = function () {
264
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
265
+ let filterTerm = arguments.length > 1 ? arguments[1] : undefined;
266
+ const {
267
+ filter,
268
+ t
269
+ } = _this.props;
270
+ const {
271
+ filter_predicate
272
+ } = filter;
273
+ let isSupportMultipleSelect = false;
274
+ // The first two options are used for single selection, and the last four options are used for multiple selection
275
+ const supportMultipleSelectOptions = [FILTER_PREDICATE_TYPE.IS_ANY_OF, FILTER_PREDICATE_TYPE.IS_NONE_OF, FILTER_PREDICATE_TYPE.HAS_ANY_OF, FILTER_PREDICATE_TYPE.HAS_ALL_OF, FILTER_PREDICATE_TYPE.HAS_NONE_OF, FILTER_PREDICATE_TYPE.IS_EXACTLY];
276
+ if (supportMultipleSelectOptions.includes(filter_predicate)) {
277
+ isSupportMultipleSelect = true;
278
+ }
279
+ const className = 'select-option-name multiple-select-option';
280
+ let labelArray = [];
281
+ if (Array.isArray(options) && Array.isArray(filterTerm)) {
282
+ filterTerm.forEach(item => {
283
+ let inOption = options.find(option => option.id === item);
284
+ if (inOption) {
285
+ let optionStyle = {
286
+ margin: '0 10px 0 0',
287
+ background: inOption.color,
288
+ color: inOption.textColor || null
289
+ };
290
+ labelArray.push( /*#__PURE__*/React.createElement("span", {
291
+ className: className,
292
+ style: optionStyle,
293
+ key: 'option_' + item,
294
+ title: inOption.name,
295
+ "aria-label": inOption.name
296
+ }, inOption.name));
297
+ }
298
+ });
299
+ }
300
+ const selectedOptionNames = labelArray.length > 0 ? {
301
+ label: /*#__PURE__*/React.createElement(Fragment, null, labelArray)
302
+ } : {};
303
+ const dataOptions = options.map(option => {
304
+ return FilterItemUtils.generatorMultipleSelectOption(option, filterTerm);
305
+ });
306
+ return /*#__PURE__*/React.createElement(Select, {
307
+ className: "selector-multiple-select",
308
+ value: selectedOptionNames,
309
+ options: dataOptions,
310
+ onSelectOption: _this.onSelectMultiple,
311
+ placeholder: t('Select_option(s)'),
312
+ searchable: true,
313
+ searchPlaceholder: t('Find_an_option'),
314
+ noOptionsPlaceholder: t('No_options_available'),
315
+ supportMultipleSelect: isSupportMultipleSelect
316
+ });
317
+ };
318
+ this.renderFilterTerm = filterColumn => {
319
+ const {
320
+ index,
321
+ filter,
322
+ collaborators,
323
+ t
324
+ } = this.props;
325
+ const {
326
+ type
327
+ } = filterColumn;
328
+ const {
329
+ filter_term,
330
+ filter_predicate,
331
+ filter_term_modifier
332
+ } = filter;
333
+ // predicate is empty or not empty
334
+ if (EMPTY_PREDICATE.includes(filter_predicate)) {
335
+ return null;
336
+ }
337
+
338
+ // the cell value will be date
339
+ // 1. DATE
340
+ // 2. CTIME: create-time
341
+ // 3. MTIME: modify-time
342
+ // 4. FORMULA: result_type is date
343
+ if (isDateColumn(filterColumn)) {
344
+ const inputRangeLabel = [FILTER_TERM_MODIFIER_TYPE.EXACT_DATE, FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_AGO, FILTER_TERM_MODIFIER_TYPE.NUMBER_OF_DAYS_FROM_NOW, FILTER_TERM_MODIFIER_TYPE.THE_NEXT_NUMBERS_OF_DAYS, FILTER_TERM_MODIFIER_TYPE.THE_PAST_NUMBERS_OF_DAYS];
345
+ if (inputRangeLabel.indexOf(filter_term_modifier) > -1) {
346
+ if (filter_term_modifier === 'exact_date') {
347
+ return /*#__PURE__*/React.createElement(FilterCalendar, {
348
+ onChange: this.onFilterTermTextChanged,
349
+ value: this.state.filterTerm,
350
+ filterColumn: filterColumn
351
+ });
352
+ }
353
+ return this.getInputComponent('text');
354
+ }
355
+ return null;
356
+ }
357
+ switch (type) {
358
+ case CellType.TEXT:
359
+ case CellType.LONG_TEXT:
360
+ case CellType.GEOLOCATION:
361
+ case CellType.NUMBER:
362
+ case CellType.AUTO_NUMBER:
363
+ case CellType.DURATION:
364
+ case CellType.EMAIL:
365
+ case CellType.URL:
366
+ {
367
+ // The data in the formula column is a date type that has been excluded
368
+ if (filter_predicate === FILTER_PREDICATE_TYPE.IS_CURRENT_USER_ID) {
369
+ return null;
370
+ }
371
+ return this.getInputComponent('text');
372
+ }
373
+ case CellType.CHECKBOX:
374
+ {
375
+ return this.getInputComponent('checkbox');
376
+ }
377
+ case CellType.SINGLE_SELECT:
378
+ {
379
+ // get options
380
+ let {
381
+ options = []
382
+ } = filterColumn.data || {};
383
+ if ([FILTER_PREDICATE_TYPE.IS_ANY_OF, FILTER_PREDICATE_TYPE.IS_NONE_OF].includes(filter_predicate)) {
384
+ return this.renderMultipleSelectOption(options, filter_term);
385
+ }
386
+ let selectedOption = options.find(option => option.id === filter_term);
387
+ let selectedOptionName = {};
388
+ if (selectedOption) {
389
+ const className = 'select-option-name single-select-option';
390
+ const style = {
391
+ background: selectedOption.color,
392
+ color: selectedOption.textColor || null
393
+ };
394
+ selectedOptionName = {
395
+ label: /*#__PURE__*/React.createElement("span", {
396
+ className: className,
397
+ style: style,
398
+ title: selectedOption.name,
399
+ "aria-label": selectedOption.name
400
+ }, selectedOption.name)
401
+ };
402
+ }
403
+ let dataOptions = options.map(option => {
404
+ return FilterItemUtils.generatorSingleSelectOption(option);
405
+ });
406
+ return /*#__PURE__*/React.createElement(Select, {
407
+ className: "selector-single-select",
408
+ value: selectedOptionName,
409
+ options: dataOptions,
410
+ onSelectOption: this.onSelectSingle,
411
+ placeholder: t('Select_an_option'),
412
+ searchable: true,
413
+ searchPlaceholder: t('Find_an_option'),
414
+ noOptionsPlaceholder: t('No_options_available')
415
+ });
416
+ }
417
+ case CellType.MULTIPLE_SELECT:
418
+ {
419
+ let {
420
+ options = []
421
+ } = filterColumn.data || {};
422
+ return this.renderMultipleSelectOption(options, filter_term);
423
+ }
424
+ case CellType.DEPARTMENT_SINGLE_SELECT:
425
+ {
426
+ if ([FILTER_PREDICATE_TYPE.IS_ANY_OF, FILTER_PREDICATE_TYPE.IS_NONE_OF].includes(filter_predicate)) {
427
+ return /*#__PURE__*/React.createElement(DepartmentMultipleSelectFilter, {
428
+ column: filterColumn,
429
+ value: filter_term || [],
430
+ onCommit: this.onSelectMultiple
431
+ });
432
+ }
433
+ return /*#__PURE__*/React.createElement(DepartmentSingleSelectFilter, {
434
+ column: filterColumn,
435
+ value: filter_term || '',
436
+ onCommit: this.onSelectSingle
437
+ });
438
+ }
439
+ case CellType.COLLABORATOR:
440
+ {
441
+ if (filter_predicate === FILTER_PREDICATE_TYPE.INCLUDE_ME) {
442
+ return null;
443
+ }
444
+ return /*#__PURE__*/React.createElement(CollaboratorFilter, {
445
+ filterIndex: index,
446
+ filterTerm: filter_term || [],
447
+ filter_predicate: filter_predicate,
448
+ collaborators: collaborators,
449
+ onSelectCollaborator: this.onSelectCollaborator,
450
+ placeholder: t('Add_collaborator')
451
+ });
452
+ }
453
+ case CellType.CREATOR:
454
+ case CellType.LAST_MODIFIER:
455
+ {
456
+ if (filter_predicate === FILTER_PREDICATE_TYPE.INCLUDE_ME) {
457
+ return null;
458
+ }
459
+ const creators = collaborators.concat([generateDefaultUser('anonymous')]);
460
+ return /*#__PURE__*/React.createElement(CollaboratorFilter, {
461
+ filterIndex: index,
462
+ filterTerm: filter_term || [],
463
+ collaborators: creators,
464
+ onSelectCollaborator: this.onSelectCreator,
465
+ placeholder: type === CellType.CREATOR ? t('Add_a_creator') : t('Add_a_last_modifier')
466
+ });
467
+ }
468
+ case CellType.RATE:
469
+ {
470
+ let {
471
+ rate_max_number
472
+ } = filterColumn.data || {};
473
+ let rateList = [];
474
+ for (let i = 0; i < rate_max_number; i++) {
475
+ let rateItem = /*#__PURE__*/React.createElement(RateItem, {
476
+ key: i,
477
+ enterRateItemIndex: this.state.enterRateItemIndex,
478
+ rateItemIndex: i + 1,
479
+ onMouseEnterRateItem: this.onMouseEnterRateItem,
480
+ onMouseLeaveRateItem: this.onMouseLeaveRateItem,
481
+ value: Number(filter_term) || rate_max_number,
482
+ column: filterColumn,
483
+ isShowRateItem: true,
484
+ onChangeRateNumber: this.onChangeRateNumber,
485
+ editable: true
486
+ });
487
+ rateList.push(rateItem);
488
+ }
489
+ return /*#__PURE__*/React.createElement("div", {
490
+ className: "filter-rate-list"
491
+ }, rateList);
492
+ }
493
+ case CellType.FORMULA:
494
+ case CellType.LINK_FORMULA:
495
+ {
496
+ return this.renderFormulaFilterTerm(filter_predicate, filter_term, index, filterColumn);
497
+ }
498
+ case CellType.LINK:
499
+ {
500
+ return this.renderLinkFilterTerm(filter_predicate, filter_term, index, filterColumn);
501
+ }
502
+ default:
503
+ {
504
+ return null;
505
+ }
506
+ }
507
+ };
508
+ this.renderFormulaFilterTerm = (filterPredicate, filterTerm, index, filterColumn) => {
509
+ const {
510
+ data
511
+ } = filterColumn || {};
512
+ const {
513
+ result_type
514
+ } = data || {};
515
+ if (filterPredicate === FILTER_PREDICATE_TYPE.IS_CURRENT_USER_ID) {
516
+ return null;
517
+ }
518
+ if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
519
+ return this.renderFilterTermByArrayType(filterPredicate, filterTerm, index, filterColumn);
520
+ }
521
+ return this.getInputComponent('text');
522
+ };
523
+ this.renderLinkFilterTerm = (filterPredicate, filterTerm, index, filterColumn) => {
524
+ if (filterPredicate === FILTER_PREDICATE_TYPE.IS_CURRENT_USER_ID) {
525
+ return null;
526
+ }
527
+ return this.renderFilterTermByArrayType(filterPredicate, filterTerm, index, filterColumn);
528
+ };
529
+ this.renderFilterTermByArrayType = (filterPredicate, filterTerm, index, filterColumn) => {
530
+ const {
531
+ collaborators,
532
+ t
533
+ } = this.props;
534
+ const {
535
+ data
536
+ } = filterColumn || {};
537
+ const {
538
+ array_type,
539
+ array_data
540
+ } = data || {};
541
+ if (!array_type) {
542
+ return null;
543
+ }
544
+ const linkedColumn = {
545
+ type: array_type,
546
+ data: array_data
547
+ };
548
+ if (array_type === CellType.SINGLE_SELECT || array_type === CellType.MULTIPLE_SELECT) {
549
+ let {
550
+ options = []
551
+ } = array_data || {};
552
+ return this.renderMultipleSelectOption(options, filterTerm);
553
+ }
554
+ if (DATE_COLUMN_OPTIONS.includes(array_type) || array_type === CellType.RATE || array_type === CellType.CHECKBOX) {
555
+ return this.renderFilterTerm(linkedColumn);
556
+ }
557
+ if (COLLABORATOR_COLUMN_TYPES.includes(array_type)) {
558
+ if (filterPredicate === FILTER_PREDICATE_TYPE.INCLUDE_ME) {
559
+ return null;
560
+ }
561
+ return /*#__PURE__*/React.createElement(CollaboratorFilter, {
562
+ filterIndex: index,
563
+ filterTerm: filterTerm || [],
564
+ collaborators: collaborators,
565
+ onSelectCollaborator: this.onSelectCollaborator,
566
+ placeholder: t('Add_collaborator')
567
+ });
568
+ }
569
+ return this.getInputComponent('text');
570
+ };
571
+ this.renderErrorMessage = () => {
572
+ const {
573
+ t
574
+ } = this.props;
575
+ return /*#__PURE__*/React.createElement("div", {
576
+ className: "ml-2"
577
+ }, /*#__PURE__*/React.createElement("span", {
578
+ ref: this.invalidFilterTip,
579
+ className: "dtable-font dtable-icon-exclamation-triangle invalid-filter"
580
+ }), /*#__PURE__*/React.createElement(UncontrolledTooltip, {
581
+ target: this.invalidFilterTip,
582
+ placement: "bottom",
583
+ fade: false
584
+ }, t('Invalid_filter')));
585
+ };
586
+ this.state = {
587
+ filterTerm: _props.filter.filter_term,
588
+ enterRateItemIndex: 0
589
+ };
590
+ this.filterPredicateOptions = null;
591
+ this.filterTermModifierOptions = null;
592
+ this.invalidFilterTip = React.createRef();
593
+ this.initSelectOptions(_props);
594
+ }
595
+ UNSAFE_componentWillReceiveProps(nextProps) {
596
+ const {
597
+ filter
598
+ } = this.props;
599
+ if (nextProps.filter !== filter) {
600
+ this.initSelectOptions(nextProps);
601
+ this.setState({
602
+ filterTerm: nextProps.filter.filter_term
603
+ });
604
+ }
605
+ }
606
+ shouldComponentUpdate(nextProps) {
607
+ const currentProps = this.props;
608
+ const shouldUpdated = nextProps.index !== currentProps.index || nextProps.filter !== currentProps.filter || nextProps.filterColumn !== currentProps.filterColumn || nextProps.filterConjunction !== currentProps.filterConjunction || nextProps.conjunctionOptions !== currentProps.conjunctionOptions || nextProps.filterColumnOptions !== currentProps.filterColumnOptions;
609
+ return shouldUpdated;
610
+ }
611
+ render() {
612
+ const {
613
+ filterPredicateOptions,
614
+ filterTermModifierOptions,
615
+ t
616
+ } = this;
617
+ const {
618
+ filter,
619
+ filterColumn,
620
+ filterColumnOptions,
621
+ isPre,
622
+ errMsg
623
+ } = this.props;
624
+ const {
625
+ filter_predicate,
626
+ filter_term_modifier
627
+ } = filter;
628
+ const activeColumn = FilterItemUtils.generatorColumnOption(filterColumn);
629
+ const activePredicate = FilterItemUtils.generatorPredicateOption(filter_predicate, isPre);
630
+ let activeTermModifier = null;
631
+ let _isCheckboxColumn = false;
632
+ if (isDateColumn(filterColumn)) {
633
+ activeTermModifier = FilterItemUtils.generatorTermModifierOption(filter_term_modifier);
634
+ } else if (isCheckboxColumn(filterColumn)) {
635
+ _isCheckboxColumn = true;
636
+ }
637
+
638
+ // current predicate is not empty
639
+ const isNeedShowTermModifier = !EMPTY_PREDICATE.includes(filter_predicate);
640
+ return /*#__PURE__*/React.createElement("div", {
641
+ className: "filter-item"
642
+ }, /*#__PURE__*/React.createElement("div", {
643
+ className: "delete-filter",
644
+ onClick: this.onDeleteFilter
645
+ }, /*#__PURE__*/React.createElement("i", {
646
+ className: "dtable-font dtable-icon-fork-number"
647
+ })), /*#__PURE__*/React.createElement("div", {
648
+ className: "condition"
649
+ }, /*#__PURE__*/React.createElement("div", {
650
+ className: "filter-conjunction"
651
+ }, this.renderConjunction()), /*#__PURE__*/React.createElement("div", {
652
+ className: "filter-container"
653
+ }, /*#__PURE__*/React.createElement("div", {
654
+ className: "filter-column"
655
+ }, /*#__PURE__*/React.createElement(Select, {
656
+ value: activeColumn,
657
+ options: filterColumnOptions,
658
+ onSelectOption: this.onSelectColumn,
659
+ searchable: true,
660
+ searchPlaceholder: t('Find_column'),
661
+ noOptionsPlaceholder: t('No_results')
662
+ })), /*#__PURE__*/React.createElement("div", {
663
+ className: "filter-predicate ml-2 ".concat(_isCheckboxColumn ? 'filter-checkbox-predicate' : '')
664
+ }, /*#__PURE__*/React.createElement(Select, {
665
+ value: activePredicate,
666
+ options: filterPredicateOptions,
667
+ onSelectOption: this.onSelectPredicate
668
+ })), isDateColumn(filterColumn) && isNeedShowTermModifier && /*#__PURE__*/React.createElement("div", {
669
+ className: "filter-term-modifier ml-2"
670
+ }, /*#__PURE__*/React.createElement(Select, {
671
+ value: activeTermModifier,
672
+ options: filterTermModifierOptions,
673
+ onSelectOption: this.onSelectTermModifier
674
+ })), /*#__PURE__*/React.createElement("div", {
675
+ className: "filter-term ml-2"
676
+ }, this.renderFilterTerm(filterColumn)), errMsg && this.renderErrorMessage())));
677
+ }
678
+ }
679
+ export default withTranslation('sdoc-editor')(FilterItem);