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