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.
- package/lib/CollaboratorEditor/index.js +26 -4
- package/lib/CollaboratorEditor/pc-collaborator-editor-popover/index.js +2 -1
- package/lib/DTableCommonAddTool/index.css +25 -0
- package/lib/DTableCommonAddTool/index.js +24 -0
- package/lib/DTableFiltersPopover/constants/index.js +65 -0
- package/lib/DTableFiltersPopover/index.css +39 -0
- package/lib/DTableFiltersPopover/index.js +216 -0
- package/lib/DTableFiltersPopover/utils/filter-item-utils.js +145 -0
- package/lib/DTableFiltersPopover/utils/index.js +452 -0
- package/lib/DTableFiltersPopover/widgets/collaborator-filter/index.css +0 -0
- package/lib/DTableFiltersPopover/widgets/collaborator-filter/index.js +106 -0
- package/lib/DTableFiltersPopover/widgets/department-select-filter/department-multiple-select-filter.js +89 -0
- package/lib/DTableFiltersPopover/widgets/department-select-filter/department-single-select-filter.js +89 -0
- package/lib/DTableFiltersPopover/widgets/filter-calendar.js +167 -0
- package/lib/DTableFiltersPopover/widgets/filter-item.js +677 -0
- package/lib/DTableFiltersPopover/widgets/filter-list/index.css +321 -0
- package/lib/DTableFiltersPopover/widgets/filter-list/index.js +125 -0
- package/lib/DTableFiltersPopover/widgets/rate-item.js +72 -0
- package/lib/DTablePopover/index.js +1 -1
- package/lib/Department-editor/constants.js +10 -0
- package/lib/Department-editor/department-multiple-select/index.css +67 -0
- package/lib/Department-editor/department-multiple-select/index.js +143 -0
- package/lib/Department-editor/department-single-select.js +263 -0
- package/lib/Department-editor/index.css +117 -0
- package/lib/Department-editor/index.js +99 -0
- package/lib/Department-editor/selected-departments/index.css +26 -0
- package/lib/Department-editor/selected-departments/index.js +81 -0
- package/lib/Department-editor/utils.js +29 -0
- package/lib/constants/index.js +4 -1
- package/lib/hooks/common-hooks.js +21 -0
- package/lib/index.js +4 -1
- package/lib/lang/index.js +67 -3
- package/lib/locals/en.js +69 -1
- package/lib/locals/zh-CN.js +68 -1
- package/lib/select-editor/mb-select-editor-popover/index.css +1 -1
- package/lib/select-editor/mb-select-editor-popover/index.js +1 -1
- package/lib/utils/dayjs.js +4 -0
- package/lib/utils/event-bus.js +28 -0
- package/lib/utils/utils.js +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,452 @@
|
|
|
1
|
+
import { FILTER_PREDICATE_TYPE, FILTER_COLUMN_OPTIONS, filterTermModifierNotWithin, filterTermModifierIsWithin, CellType, isDateColumn, isNumericColumn, FORMULA_RESULT_TYPE, COLLABORATOR_COLUMN_TYPES, DATE_COLUMN_OPTIONS, FORMULA_COLUMN_TYPES_MAP, DEFAULT_DATE_FORMAT } from 'dtable-utils';
|
|
2
|
+
import FilterItemUtils from './filter-item-utils';
|
|
3
|
+
import { FORMULA_COLUMN_TYPES, SPECIAL_TERM_TYPE, ARRAY_PREDICATE, STRING_PREDICATE, DATE_EMPTY_LABEL_MAP, MULTIPLE_SELECTOR_COLUMNS } from '../constants';
|
|
4
|
+
const isArrayFilterTermByArrayType = array_type => {
|
|
5
|
+
return COLLABORATOR_COLUMN_TYPES.includes(array_type) || array_type === CellType.SINGLE_SELECT || array_type === CellType.MULTIPLE_SELECT;
|
|
6
|
+
};
|
|
7
|
+
export const isFilterTermArray = (column, filterPredicate) => {
|
|
8
|
+
const {
|
|
9
|
+
type,
|
|
10
|
+
data
|
|
11
|
+
} = column;
|
|
12
|
+
if (MULTIPLE_SELECTOR_COLUMNS.includes(type)) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
if (type === CellType.SINGLE_SELECT && [FILTER_PREDICATE_TYPE.IS_ANY_OF, FILTER_PREDICATE_TYPE.IS_NONE_OF].includes(filterPredicate)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
if (FORMULA_COLUMN_TYPES.includes(type)) {
|
|
19
|
+
const {
|
|
20
|
+
result_type,
|
|
21
|
+
array_type
|
|
22
|
+
} = data || {};
|
|
23
|
+
if (result_type !== FORMULA_RESULT_TYPE.ARRAY) return false;
|
|
24
|
+
return isArrayFilterTermByArrayType(array_type);
|
|
25
|
+
}
|
|
26
|
+
if (type === CellType.LINK) {
|
|
27
|
+
const {
|
|
28
|
+
array_type
|
|
29
|
+
} = data || {};
|
|
30
|
+
return isArrayFilterTermByArrayType(array_type);
|
|
31
|
+
}
|
|
32
|
+
return false;
|
|
33
|
+
};
|
|
34
|
+
export const getUpdatedFilterByCreator = (filter, collaborator) => {
|
|
35
|
+
const multipleSelectType = [FILTER_PREDICATE_TYPE.CONTAINS, FILTER_PREDICATE_TYPE.NOT_CONTAIN];
|
|
36
|
+
let {
|
|
37
|
+
filter_predicate,
|
|
38
|
+
filter_term: filterTerm
|
|
39
|
+
} = filter;
|
|
40
|
+
if (multipleSelectType.includes(filter_predicate)) {
|
|
41
|
+
filterTerm = filterTerm ? filter.filter_term.slice(0) : [];
|
|
42
|
+
let selectedEmail = collaborator.email;
|
|
43
|
+
let collaborator_index = filterTerm.indexOf(selectedEmail);
|
|
44
|
+
if (collaborator_index > -1) {
|
|
45
|
+
filterTerm.splice(collaborator_index, 1);
|
|
46
|
+
} else {
|
|
47
|
+
filterTerm.push(selectedEmail);
|
|
48
|
+
}
|
|
49
|
+
} else {
|
|
50
|
+
if (filterTerm[0] === collaborator.email) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
filterTerm = [collaborator.email];
|
|
54
|
+
}
|
|
55
|
+
return Object.assign({}, filter, {
|
|
56
|
+
filter_term: filterTerm
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
export const getUpdatedFilterBySelectSingle = (filter, columnOption) => {
|
|
60
|
+
let new_filter_term;
|
|
61
|
+
// if predicate is any of / is none of, filter_term is array; else filter_term is string
|
|
62
|
+
if (filter.filter_predicate === FILTER_PREDICATE_TYPE.IS_ANY_OF || filter.filter_predicate === FILTER_PREDICATE_TYPE.IS_NONE_OF) {
|
|
63
|
+
new_filter_term = Array.isArray(filter.filter_term) ? [...filter.filter_term] : [];
|
|
64
|
+
const index = new_filter_term.indexOf(columnOption.id);
|
|
65
|
+
if (index === -1) {
|
|
66
|
+
new_filter_term.push(columnOption.id);
|
|
67
|
+
} else {
|
|
68
|
+
new_filter_term.splice(index, 1);
|
|
69
|
+
}
|
|
70
|
+
} else {
|
|
71
|
+
new_filter_term = columnOption.id;
|
|
72
|
+
}
|
|
73
|
+
return Object.assign({}, filter, {
|
|
74
|
+
filter_term: new_filter_term
|
|
75
|
+
});
|
|
76
|
+
};
|
|
77
|
+
export const getUpdatedFilterBySelectMultiple = (filter, columnOption) => {
|
|
78
|
+
let filterTerm = filter.filter_term ? filter.filter_term : [];
|
|
79
|
+
let index = filterTerm.indexOf(columnOption.id);
|
|
80
|
+
if (index > -1) {
|
|
81
|
+
filterTerm.splice(index, 1);
|
|
82
|
+
} else {
|
|
83
|
+
filterTerm.push(columnOption.id);
|
|
84
|
+
}
|
|
85
|
+
return Object.assign({}, filter, {
|
|
86
|
+
filter_term: filterTerm
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
export const getUpdatedFilterByCollaborator = (filter, collaborator) => {
|
|
90
|
+
let filterTerm = filter.filter_term ? filter.filter_term.slice(0) : [];
|
|
91
|
+
let selectedEmail = collaborator.email;
|
|
92
|
+
let collaborator_index = filterTerm.indexOf(selectedEmail);
|
|
93
|
+
if (collaborator_index > -1) {
|
|
94
|
+
filterTerm.splice(collaborator_index, 1);
|
|
95
|
+
} else {
|
|
96
|
+
filterTerm.push(selectedEmail);
|
|
97
|
+
}
|
|
98
|
+
return Object.assign({}, filter, {
|
|
99
|
+
filter_term: filterTerm
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
export const getUpdatedFilterByRate = (filter, value) => {
|
|
103
|
+
if (filter.filter_term === value) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
return Object.assign({}, filter, {
|
|
107
|
+
filter_term: value
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
export const getColumnOptions = column => {
|
|
111
|
+
const {
|
|
112
|
+
type,
|
|
113
|
+
data
|
|
114
|
+
} = column;
|
|
115
|
+
if (FORMULA_COLUMN_TYPES.includes(type)) {
|
|
116
|
+
return getFormulaColumnFilterOptions(column);
|
|
117
|
+
}
|
|
118
|
+
if (type === CellType.LINK) {
|
|
119
|
+
const {
|
|
120
|
+
array_type
|
|
121
|
+
} = data || {};
|
|
122
|
+
if (array_type === FORMULA_RESULT_TYPE.BOOL) {
|
|
123
|
+
return FILTER_COLUMN_OPTIONS[CellType.CHECKBOX];
|
|
124
|
+
}
|
|
125
|
+
if (array_type === FORMULA_RESULT_TYPE.STRING) {
|
|
126
|
+
return FILTER_COLUMN_OPTIONS[CellType.TEXT];
|
|
127
|
+
}
|
|
128
|
+
return getFilterOptionsByArrayType(array_type);
|
|
129
|
+
}
|
|
130
|
+
return FILTER_COLUMN_OPTIONS[type] || {};
|
|
131
|
+
};
|
|
132
|
+
const getFormulaColumnFilterOptions = column => {
|
|
133
|
+
const {
|
|
134
|
+
data
|
|
135
|
+
} = column;
|
|
136
|
+
const {
|
|
137
|
+
result_type,
|
|
138
|
+
array_type
|
|
139
|
+
} = data || {};
|
|
140
|
+
if (result_type === FORMULA_RESULT_TYPE.BOOL) {
|
|
141
|
+
return FILTER_COLUMN_OPTIONS[CellType.CHECKBOX];
|
|
142
|
+
}
|
|
143
|
+
if (result_type === FORMULA_RESULT_TYPE.STRING) {
|
|
144
|
+
return FILTER_COLUMN_OPTIONS[CellType.TEXT];
|
|
145
|
+
}
|
|
146
|
+
if ([FORMULA_RESULT_TYPE.NUMBER, FORMULA_RESULT_TYPE.DATE].includes(result_type)) {
|
|
147
|
+
return FILTER_COLUMN_OPTIONS[result_type];
|
|
148
|
+
}
|
|
149
|
+
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
150
|
+
return getFilterOptionsByArrayType(array_type);
|
|
151
|
+
}
|
|
152
|
+
return FILTER_COLUMN_OPTIONS[CellType.TEXT];
|
|
153
|
+
};
|
|
154
|
+
const getFilterOptionsByArrayType = array_type => {
|
|
155
|
+
if (!array_type) {
|
|
156
|
+
return {};
|
|
157
|
+
}
|
|
158
|
+
let checkType = array_type;
|
|
159
|
+
if (COLLABORATOR_COLUMN_TYPES.includes(array_type)) {
|
|
160
|
+
checkType = CellType.COLLABORATOR;
|
|
161
|
+
} else if (array_type === CellType.SINGLE_SELECT) {
|
|
162
|
+
checkType = CellType.MULTIPLE_SELECT;
|
|
163
|
+
} else if (DATE_COLUMN_OPTIONS.includes(array_type)) {
|
|
164
|
+
checkType = CellType.DATE;
|
|
165
|
+
} else if (isNumericColumn({
|
|
166
|
+
type: array_type
|
|
167
|
+
})) {
|
|
168
|
+
checkType = CellType.NUMBER;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// only support: is
|
|
172
|
+
if (checkType === CellType.CHECKBOX || checkType === CellType.BOOL) {
|
|
173
|
+
return FILTER_COLUMN_OPTIONS[CellType.CHECKBOX];
|
|
174
|
+
}
|
|
175
|
+
let filterOptions = FILTER_COLUMN_OPTIONS[checkType] || FILTER_COLUMN_OPTIONS[CellType.TEXT];
|
|
176
|
+
let {
|
|
177
|
+
filterPredicateList
|
|
178
|
+
} = filterOptions;
|
|
179
|
+
if (filterPredicateList && !filterPredicateList.includes(FILTER_PREDICATE_TYPE.EMPTY)) {
|
|
180
|
+
filterPredicateList.push(FILTER_PREDICATE_TYPE.EMPTY);
|
|
181
|
+
}
|
|
182
|
+
if (filterPredicateList && !filterPredicateList.includes(FILTER_PREDICATE_TYPE.NOT_EMPTY)) {
|
|
183
|
+
filterPredicateList.push(FILTER_PREDICATE_TYPE.NOT_EMPTY);
|
|
184
|
+
}
|
|
185
|
+
return filterOptions;
|
|
186
|
+
};
|
|
187
|
+
export const getFilterByColumn = function (column, value) {
|
|
188
|
+
let {
|
|
189
|
+
textDefaultPredicate
|
|
190
|
+
} = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
191
|
+
let filter = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
192
|
+
let {
|
|
193
|
+
type: columnType,
|
|
194
|
+
data: columnData
|
|
195
|
+
} = column;
|
|
196
|
+
let {
|
|
197
|
+
filterPredicateList
|
|
198
|
+
} = getColumnOptions(column, value);
|
|
199
|
+
if (!filterPredicateList) return;
|
|
200
|
+
let filterPredicate = filterPredicateList[0];
|
|
201
|
+
if (textDefaultPredicate && columnType === CellType.TEXT && filterPredicateList.includes(textDefaultPredicate)) {
|
|
202
|
+
filterPredicate = textDefaultPredicate;
|
|
203
|
+
}
|
|
204
|
+
let updatedFilter = Object.assign({}, filter, {
|
|
205
|
+
column_key: column.key,
|
|
206
|
+
filter_predicate: filterPredicate
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// text | number | long-text | url | email
|
|
210
|
+
// auto-number | geolocation | duration
|
|
211
|
+
updatedFilter.filter_term = '';
|
|
212
|
+
|
|
213
|
+
// checkbox
|
|
214
|
+
if (columnType === CellType.CHECKBOX) {
|
|
215
|
+
updatedFilter.filter_term = false;
|
|
216
|
+
return updatedFilter;
|
|
217
|
+
}
|
|
218
|
+
// rate
|
|
219
|
+
if (columnType === CellType.RATE) {
|
|
220
|
+
const {
|
|
221
|
+
rate_max_number
|
|
222
|
+
} = columnData;
|
|
223
|
+
updatedFilter.filter_term = rate_max_number;
|
|
224
|
+
return updatedFilter;
|
|
225
|
+
}
|
|
226
|
+
// single-select | multiple-select | collaborators | creator | last-modifier
|
|
227
|
+
if (isFilterTermArray(column, filterPredicate)) {
|
|
228
|
+
updatedFilter.filter_term = [];
|
|
229
|
+
return updatedFilter;
|
|
230
|
+
}
|
|
231
|
+
// date | ctime | mtime
|
|
232
|
+
if (isDateColumn(column)) {
|
|
233
|
+
let filterTermModifier = filterPredicate === FILTER_PREDICATE_TYPE.IS_WITHIN ? filterTermModifierIsWithin[0] : filterTermModifierNotWithin[0];
|
|
234
|
+
updatedFilter.filter_term_modifier = filterTermModifier;
|
|
235
|
+
updatedFilter.filter_term = '';
|
|
236
|
+
return updatedFilter;
|
|
237
|
+
}
|
|
238
|
+
// formula | link-formula
|
|
239
|
+
if (FORMULA_COLUMN_TYPES.includes(columnType)) {
|
|
240
|
+
const newUpdatedFilter = getFormulaColumnFilter(column, value, filter);
|
|
241
|
+
if (newUpdatedFilter) {
|
|
242
|
+
updatedFilter.filter_term = newUpdatedFilter.filter_term;
|
|
243
|
+
}
|
|
244
|
+
return updatedFilter;
|
|
245
|
+
}
|
|
246
|
+
// link
|
|
247
|
+
if (columnType === CellType.LINK) {
|
|
248
|
+
let {
|
|
249
|
+
array_type,
|
|
250
|
+
array_data
|
|
251
|
+
} = columnData || {};
|
|
252
|
+
if (array_type) {
|
|
253
|
+
if (array_type === FORMULA_RESULT_TYPE.BOOL) {
|
|
254
|
+
array_type = CellType.CHECKBOX;
|
|
255
|
+
}
|
|
256
|
+
if (array_type === FORMULA_RESULT_TYPE.STRING) {
|
|
257
|
+
array_type = CellType.TEXT;
|
|
258
|
+
}
|
|
259
|
+
const linkedColumn = {
|
|
260
|
+
key: column.key,
|
|
261
|
+
type: array_type,
|
|
262
|
+
data: array_data
|
|
263
|
+
};
|
|
264
|
+
const newUpdatedFilter = getFilterByColumn(linkedColumn, value, filter) || {};
|
|
265
|
+
if (newUpdatedFilter) {
|
|
266
|
+
updatedFilter.filter_term = newUpdatedFilter.filter_term;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
return updatedFilter;
|
|
270
|
+
}
|
|
271
|
+
return updatedFilter;
|
|
272
|
+
};
|
|
273
|
+
export const getFormulaColumnFilter = (column, value, filter) => {
|
|
274
|
+
const {
|
|
275
|
+
data
|
|
276
|
+
} = column;
|
|
277
|
+
let {
|
|
278
|
+
result_type,
|
|
279
|
+
array_type,
|
|
280
|
+
array_data
|
|
281
|
+
} = data || {};
|
|
282
|
+
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
283
|
+
const linkedColumn = {
|
|
284
|
+
key: column.key,
|
|
285
|
+
type: array_type,
|
|
286
|
+
data: array_data
|
|
287
|
+
};
|
|
288
|
+
return getFilterByColumn(linkedColumn, value, filter);
|
|
289
|
+
}
|
|
290
|
+
// result_type: string | number | bool | date
|
|
291
|
+
if (result_type === FORMULA_RESULT_TYPE.BOOL) {
|
|
292
|
+
array_type = CellType.CHECKBOX;
|
|
293
|
+
}
|
|
294
|
+
if (result_type === FORMULA_RESULT_TYPE.STRING) {
|
|
295
|
+
array_type = CellType.TEXT;
|
|
296
|
+
}
|
|
297
|
+
const linkedColumn = {
|
|
298
|
+
key: column.key,
|
|
299
|
+
type: array_type,
|
|
300
|
+
data: array_data
|
|
301
|
+
};
|
|
302
|
+
return getFilterByColumn(linkedColumn, value, filter);
|
|
303
|
+
};
|
|
304
|
+
|
|
305
|
+
// file, image : not support
|
|
306
|
+
// text, long-text, number, single-select, date, ctime, mtime, formula, link, geolocation : string
|
|
307
|
+
// checkbox : boolean
|
|
308
|
+
// multiple-select, collaborator, creator, last modifier : array
|
|
309
|
+
|
|
310
|
+
export const getUpdatedFilterByColumn = (filters, value, filterIndex, column) => {
|
|
311
|
+
const filter = filters[filterIndex];
|
|
312
|
+
if (filter.column_key === column.key) {
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
return getFilterByColumn(column, value, filter);
|
|
316
|
+
};
|
|
317
|
+
export const getUpdatedFilterByPredicate = (filter, column, filterPredicate) => {
|
|
318
|
+
let updatedFilter = Object.assign({}, filter, {
|
|
319
|
+
filter_predicate: filterPredicate
|
|
320
|
+
});
|
|
321
|
+
let {
|
|
322
|
+
type: columnType
|
|
323
|
+
} = column;
|
|
324
|
+
if (columnType === CellType.CHECKBOX) {
|
|
325
|
+
updatedFilter.filter_term = false;
|
|
326
|
+
return updatedFilter;
|
|
327
|
+
}
|
|
328
|
+
if ([CellType.SINGLE_SELECT, CellType.DEPARTMENT_SINGLE_SELECT].includes(columnType)) {
|
|
329
|
+
if (ARRAY_PREDICATE[filterPredicate]) {
|
|
330
|
+
if (ARRAY_PREDICATE[filter.filter_predicate] !== ARRAY_PREDICATE[filterPredicate]) {
|
|
331
|
+
updatedFilter.filter_term = [];
|
|
332
|
+
}
|
|
333
|
+
} else if (STRING_PREDICATE[filterPredicate]) {
|
|
334
|
+
if (STRING_PREDICATE[filter.filter_predicate] !== STRING_PREDICATE[filterPredicate]) {
|
|
335
|
+
updatedFilter.filter_term = '';
|
|
336
|
+
}
|
|
337
|
+
} else {
|
|
338
|
+
updatedFilter.filter_term = '';
|
|
339
|
+
}
|
|
340
|
+
return updatedFilter;
|
|
341
|
+
}
|
|
342
|
+
if ([CellType.CREATOR, CellType.LAST_MODIFIER].includes(columnType)) {
|
|
343
|
+
if (STRING_PREDICATE[filter.filter_predicate] !== STRING_PREDICATE[filterPredicate] || filterPredicate === FILTER_PREDICATE_TYPE.INCLUDE_ME) {
|
|
344
|
+
updatedFilter.filter_term = [];
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
if (isFilterTermArray(column, filterPredicate)) {
|
|
348
|
+
if (DATE_EMPTY_LABEL_MAP[filterPredicate] || filterPredicate === FILTER_PREDICATE_TYPE.INCLUDE_ME) {
|
|
349
|
+
updatedFilter.filter_term = [];
|
|
350
|
+
}
|
|
351
|
+
return updatedFilter;
|
|
352
|
+
}
|
|
353
|
+
if (isDateColumn(column)) {
|
|
354
|
+
let filterTermModifier = filterPredicate === FILTER_PREDICATE_TYPE.IS_WITHIN ? filterTermModifierIsWithin[0] : filterTermModifierNotWithin[0];
|
|
355
|
+
updatedFilter.filter_term_modifier = filterTermModifier;
|
|
356
|
+
return updatedFilter;
|
|
357
|
+
}
|
|
358
|
+
return updatedFilter;
|
|
359
|
+
};
|
|
360
|
+
export const getUpdatedFilterByTermModifier = (filters, filterIndex, filterTermModifier) => {
|
|
361
|
+
const filter = filters[filterIndex];
|
|
362
|
+
if (filter.filter_term_modifier === filterTermModifier) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
return Object.assign({}, filter, {
|
|
366
|
+
filter_term_modifier: filterTermModifier
|
|
367
|
+
});
|
|
368
|
+
};
|
|
369
|
+
export const getUpdatedFilterByNormalTerm = (filters, column, filterIndex, event) => {
|
|
370
|
+
const filter = filters[filterIndex];
|
|
371
|
+
let filterTerm;
|
|
372
|
+
if (column.type === CellType.CHECKBOX) {
|
|
373
|
+
filterTerm = event.target.checked;
|
|
374
|
+
} else {
|
|
375
|
+
filterTerm = event.target.value;
|
|
376
|
+
}
|
|
377
|
+
if (filter.filter_term === filterTerm) {
|
|
378
|
+
return;
|
|
379
|
+
}
|
|
380
|
+
return Object.assign({}, filter, {
|
|
381
|
+
filter_term: filterTerm
|
|
382
|
+
});
|
|
383
|
+
};
|
|
384
|
+
export const getUpdatedFilterBySpecialTerm = (filters, filterIndex, type, value) => {
|
|
385
|
+
const filter = filters[filterIndex];
|
|
386
|
+
switch (type) {
|
|
387
|
+
case SPECIAL_TERM_TYPE.CREATOR:
|
|
388
|
+
{
|
|
389
|
+
return getUpdatedFilterByCreator(filter, value);
|
|
390
|
+
}
|
|
391
|
+
case SPECIAL_TERM_TYPE.SINGLE_SELECT:
|
|
392
|
+
{
|
|
393
|
+
return getUpdatedFilterBySelectSingle(filter, value);
|
|
394
|
+
}
|
|
395
|
+
case SPECIAL_TERM_TYPE.MULTIPLE_SELECT:
|
|
396
|
+
{
|
|
397
|
+
return getUpdatedFilterBySelectMultiple(filter, value);
|
|
398
|
+
}
|
|
399
|
+
case SPECIAL_TERM_TYPE.COLLABORATOR:
|
|
400
|
+
{
|
|
401
|
+
return getUpdatedFilterByCollaborator(filter, value);
|
|
402
|
+
}
|
|
403
|
+
case SPECIAL_TERM_TYPE.RATE:
|
|
404
|
+
{
|
|
405
|
+
return getUpdatedFilterByRate(filter, value);
|
|
406
|
+
}
|
|
407
|
+
default:
|
|
408
|
+
{
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
export const getColumnByKey = (columns, columnKey) => {
|
|
414
|
+
if (!Array.isArray(columns) || !columnKey) return null;
|
|
415
|
+
return columns.find(column => column.key === columnKey);
|
|
416
|
+
};
|
|
417
|
+
export const isCheckboxColumn = column => {
|
|
418
|
+
let {
|
|
419
|
+
type,
|
|
420
|
+
data
|
|
421
|
+
} = column;
|
|
422
|
+
if (FORMULA_COLUMN_TYPES_MAP[type]) {
|
|
423
|
+
const {
|
|
424
|
+
result_type,
|
|
425
|
+
array_type
|
|
426
|
+
} = data || {};
|
|
427
|
+
if (result_type === FORMULA_RESULT_TYPE.ARRAY) {
|
|
428
|
+
return array_type === CellType.CHECKBOX;
|
|
429
|
+
}
|
|
430
|
+
return false;
|
|
431
|
+
}
|
|
432
|
+
return type === CellType.CHECKBOX;
|
|
433
|
+
};
|
|
434
|
+
export const getDateColumnFormat = column => {
|
|
435
|
+
const format = column && column.data && column.data.format ? column.data.format : DEFAULT_DATE_FORMAT;
|
|
436
|
+
// Old Europe format is D/M/YYYY new format is DD/MM/YYYY
|
|
437
|
+
return format;
|
|
438
|
+
};
|
|
439
|
+
const getMediaUrl = () => {
|
|
440
|
+
var _window, _window$dtable, _window2, _window2$dtablePlugin;
|
|
441
|
+
return ((_window = window) === null || _window === void 0 ? void 0 : (_window$dtable = _window.dtable) === null || _window$dtable === void 0 ? void 0 : _window$dtable.mediaUrl) || ((_window2 = window) === null || _window2 === void 0 ? void 0 : (_window2$dtablePlugin = _window2.dtablePluginConfig) === null || _window2$dtablePlugin === void 0 ? void 0 : _window2$dtablePlugin.mediaUrl) || '/media/';
|
|
442
|
+
};
|
|
443
|
+
export const generateDefaultUser = name => {
|
|
444
|
+
const mediaUrl = getMediaUrl();
|
|
445
|
+
const defaultAvatarUrl = "".concat(mediaUrl, "avatars/default.png");
|
|
446
|
+
return {
|
|
447
|
+
name,
|
|
448
|
+
email: name,
|
|
449
|
+
avatar_url: defaultAvatarUrl
|
|
450
|
+
};
|
|
451
|
+
};
|
|
452
|
+
export { FilterItemUtils };
|
|
File without changes
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React, { Component, Fragment } from 'react';
|
|
2
|
+
import { FILTER_PREDICATE_TYPE } from 'dtable-utils';
|
|
3
|
+
import DTableCustomizeSelect from '../../../DTableCustomizeSelect';
|
|
4
|
+
import { getLocale } from '../../../lang';
|
|
5
|
+
import './index.css';
|
|
6
|
+
class CollaboratorFilter extends Component {
|
|
7
|
+
constructor(props) {
|
|
8
|
+
super(props);
|
|
9
|
+
this.createCollaboratorOptions = (filterIndex, collaborators, filterTerm) => {
|
|
10
|
+
return collaborators.map(collaborator => {
|
|
11
|
+
let isSelected = filterTerm.findIndex(item => item === collaborator.email) > -1;
|
|
12
|
+
return {
|
|
13
|
+
value: {
|
|
14
|
+
filterIndex,
|
|
15
|
+
columnOption: collaborator
|
|
16
|
+
},
|
|
17
|
+
label: /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
18
|
+
className: "select-option-name option-collaborator"
|
|
19
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
20
|
+
className: "collaborator-container"
|
|
21
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
22
|
+
className: "collaborator"
|
|
23
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
24
|
+
className: "collaborator-avatar-container"
|
|
25
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
26
|
+
className: "collaborator-avatar",
|
|
27
|
+
alt: collaborator.name,
|
|
28
|
+
src: collaborator.avatar_url
|
|
29
|
+
})), /*#__PURE__*/React.createElement("span", {
|
|
30
|
+
className: "collaborator-name text-truncate",
|
|
31
|
+
style: {
|
|
32
|
+
maxWidth: '200px'
|
|
33
|
+
},
|
|
34
|
+
title: collaborator.name,
|
|
35
|
+
"aria-label": collaborator.name
|
|
36
|
+
}, collaborator.name))), /*#__PURE__*/React.createElement("div", {
|
|
37
|
+
className: "collaborator-check-icon"
|
|
38
|
+
}, isSelected && /*#__PURE__*/React.createElement("i", {
|
|
39
|
+
className: "option-edit dtable-font dtable-icon-check-mark"
|
|
40
|
+
}))))
|
|
41
|
+
};
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
this.onClick = (e, collaborator) => {
|
|
45
|
+
e.stopPropagation();
|
|
46
|
+
this.props.onSelectCollaborator({
|
|
47
|
+
columnOption: collaborator
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
this.supportMultipleSelectOptions = [FILTER_PREDICATE_TYPE.HAS_ANY_OF, FILTER_PREDICATE_TYPE.HAS_ALL_OF, FILTER_PREDICATE_TYPE.HAS_NONE_OF, FILTER_PREDICATE_TYPE.IS_EXACTLY];
|
|
51
|
+
}
|
|
52
|
+
render() {
|
|
53
|
+
let {
|
|
54
|
+
filterIndex,
|
|
55
|
+
filterTerm,
|
|
56
|
+
collaborators,
|
|
57
|
+
placeholder,
|
|
58
|
+
filter_predicate
|
|
59
|
+
} = this.props;
|
|
60
|
+
let isSupportMultipleSelect = this.supportMultipleSelectOptions.indexOf(filter_predicate) > -1 ? true : false;
|
|
61
|
+
let selectedCollaborators = Array.isArray(filterTerm) && filterTerm.length > 0 && filterTerm.map(item => {
|
|
62
|
+
let collaborator = collaborators.find(c => c.email === item);
|
|
63
|
+
if (!collaborator) return null;
|
|
64
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
65
|
+
key: item,
|
|
66
|
+
className: "collaborator"
|
|
67
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
68
|
+
className: "collaborator-avatar-container"
|
|
69
|
+
}, /*#__PURE__*/React.createElement("img", {
|
|
70
|
+
className: "collaborator-avatar",
|
|
71
|
+
alt: collaborator.name,
|
|
72
|
+
src: collaborator.avatar_url
|
|
73
|
+
})), /*#__PURE__*/React.createElement("span", {
|
|
74
|
+
className: "collaborator-name text-truncate",
|
|
75
|
+
title: collaborator.name,
|
|
76
|
+
"aria-label": collaborator.name
|
|
77
|
+
}, collaborator.name), /*#__PURE__*/React.createElement("span", {
|
|
78
|
+
className: "remove-container"
|
|
79
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
80
|
+
className: "remove-icon",
|
|
81
|
+
onClick: e => {
|
|
82
|
+
this.onClick(e, collaborator);
|
|
83
|
+
}
|
|
84
|
+
}, /*#__PURE__*/React.createElement("i", {
|
|
85
|
+
className: "dtable-font dtable-icon-fork-number"
|
|
86
|
+
}))));
|
|
87
|
+
});
|
|
88
|
+
let value = selectedCollaborators ? {
|
|
89
|
+
label: /*#__PURE__*/React.createElement(React.Fragment, null, selectedCollaborators)
|
|
90
|
+
} : {};
|
|
91
|
+
let options = Array.isArray(filterTerm) ? this.createCollaboratorOptions(filterIndex, collaborators, filterTerm) : [];
|
|
92
|
+
return /*#__PURE__*/React.createElement(DTableCustomizeSelect, {
|
|
93
|
+
className: "selector-collaborator",
|
|
94
|
+
value: value,
|
|
95
|
+
onSelectOption: this.props.onSelectCollaborator,
|
|
96
|
+
options: options,
|
|
97
|
+
placeholder: placeholder,
|
|
98
|
+
isLocked: this.props.isLocked,
|
|
99
|
+
supportMultipleSelect: isSupportMultipleSelect,
|
|
100
|
+
searchable: true,
|
|
101
|
+
searchPlaceholder: getLocale('Find_a_collaborator'),
|
|
102
|
+
isShowSelected: false
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
export default CollaboratorFilter;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import React, { useState, useRef } from 'react';
|
|
2
|
+
import classnames from 'classnames';
|
|
3
|
+
import SelectedDepartments from '../../../Department-editor/selected-departments';
|
|
4
|
+
import DepartmentMultipleSelect from '../../../Department-editor/department-multiple-select';
|
|
5
|
+
import { DEPARTMENT_SELECT_RANGE_OPTIONS } from '../../../Department-editor/constants';
|
|
6
|
+
import { useClickOutside } from '../../../hooks/common-hooks';
|
|
7
|
+
import { getLocale } from '../../../lang';
|
|
8
|
+
function DepartmentMultipleSelectFilter(props) {
|
|
9
|
+
const {
|
|
10
|
+
value,
|
|
11
|
+
departments
|
|
12
|
+
} = props;
|
|
13
|
+
const [isShowSelector, setIsShowSelector] = useState(false);
|
|
14
|
+
const [selectedDepartments, setSelectedDepartments] = useState(value || []);
|
|
15
|
+
const selectorRef = useRef(null);
|
|
16
|
+
useClickOutside({
|
|
17
|
+
currDOM: selectorRef.current,
|
|
18
|
+
onClickOutside: () => setIsShowSelector(false)
|
|
19
|
+
}, [selectedDepartments]);
|
|
20
|
+
function renderUserDepartmentOptions() {
|
|
21
|
+
return DEPARTMENT_SELECT_RANGE_OPTIONS.slice(0, 2).map((option, index) => {
|
|
22
|
+
const {
|
|
23
|
+
type,
|
|
24
|
+
name
|
|
25
|
+
} = option;
|
|
26
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
27
|
+
className: "dropdown-item d-flex align-items-center",
|
|
28
|
+
key: index,
|
|
29
|
+
onClick: event => selectDepartment(event, type)
|
|
30
|
+
}, /*#__PURE__*/React.createElement("input", {
|
|
31
|
+
type: "checkbox",
|
|
32
|
+
className: "vam department-select-input",
|
|
33
|
+
checked: selectedDepartments.includes(type),
|
|
34
|
+
onChange: event => selectDepartment(event, type)
|
|
35
|
+
}), /*#__PURE__*/React.createElement("span", {
|
|
36
|
+
className: "text-truncate department-name"
|
|
37
|
+
}, getLocale(name)));
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
function onSelectToggle(event) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
setIsShowSelector(!isShowSelector);
|
|
43
|
+
}
|
|
44
|
+
function selectDepartment(event, value) {
|
|
45
|
+
event.stopPropagation();
|
|
46
|
+
event.nativeEvent.stopImmediatePropagation();
|
|
47
|
+
let newSelectedDepartment = selectedDepartments.slice(0);
|
|
48
|
+
const index = newSelectedDepartment.findIndex(item => item === value);
|
|
49
|
+
if (index !== -1) {
|
|
50
|
+
newSelectedDepartment.splice(index, 1);
|
|
51
|
+
} else {
|
|
52
|
+
newSelectedDepartment.push(value);
|
|
53
|
+
}
|
|
54
|
+
setSelectedDepartments(newSelectedDepartment);
|
|
55
|
+
const columnOption = {
|
|
56
|
+
id: value
|
|
57
|
+
};
|
|
58
|
+
props.onCommit({
|
|
59
|
+
columnOption
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
63
|
+
ref: selectorRef,
|
|
64
|
+
className: classnames('dtable-select custom-select', {
|
|
65
|
+
'focus': isShowSelector
|
|
66
|
+
}),
|
|
67
|
+
onClick: onSelectToggle,
|
|
68
|
+
id: "filter-department-editor"
|
|
69
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
70
|
+
className: "selected-option"
|
|
71
|
+
}, selectedDepartments.length > 0 ? /*#__PURE__*/React.createElement("span", {
|
|
72
|
+
className: "selected-option-show"
|
|
73
|
+
}, /*#__PURE__*/React.createElement(SelectedDepartments, {
|
|
74
|
+
value: selectedDepartments,
|
|
75
|
+
departments: departments
|
|
76
|
+
})) : /*#__PURE__*/React.createElement("span", {
|
|
77
|
+
className: "select-placeholder"
|
|
78
|
+
}, getLocale('Select_department')), /*#__PURE__*/React.createElement("span", {
|
|
79
|
+
className: "dtable-font dtable-icon-drop-down"
|
|
80
|
+
})), isShowSelector && /*#__PURE__*/React.createElement(DepartmentMultipleSelect, {
|
|
81
|
+
isShowSelectedDepartments: false,
|
|
82
|
+
classNamePrefix: "filter",
|
|
83
|
+
value: selectedDepartments,
|
|
84
|
+
onCommit: selectDepartment,
|
|
85
|
+
renderUserDepartmentOptions: renderUserDepartmentOptions,
|
|
86
|
+
departments: departments
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
export default DepartmentMultipleSelectFilter;
|