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,89 @@
1
+ import React, { useState, useRef } from 'react';
2
+ import classnames from 'classnames';
3
+ import SelectedDepartments from '../../../Department-editor/selected-departments';
4
+ import DepartmentSingleSelect from '../../../Department-editor/department-single-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 DepartmentSingleSelectFilter(props) {
9
+ const {
10
+ value,
11
+ column,
12
+ roleId,
13
+ departments,
14
+ userDepartmentIdsMap
15
+ } = props;
16
+ const [isShowSelector, setIsShowSelector] = useState(false);
17
+ const [selectedDepartment, setSelectedDepartment] = useState(value || '');
18
+ const selectorRef = useRef(null);
19
+ let selectedDepartmentIds = [];
20
+ selectedDepartmentIds.push(value);
21
+ useClickOutside({
22
+ currDOM: selectorRef.current,
23
+ onClickOutside: () => setIsShowSelector(false)
24
+ }, [selectedDepartment]);
25
+ function renderUserDepartmentOptions(onSelect) {
26
+ if (!roleId) return [];
27
+ return DEPARTMENT_SELECT_RANGE_OPTIONS.slice(0, 2).map((option, index) => {
28
+ const {
29
+ type,
30
+ name
31
+ } = option;
32
+ return /*#__PURE__*/React.createElement("div", {
33
+ className: "dropdown-item department-item d-flex align-items-center",
34
+ key: index,
35
+ onClick: event => onSelect(event, type)
36
+ }, /*#__PURE__*/React.createElement("div", {
37
+ className: "department-item-left-content d-flex align-items-center"
38
+ }, /*#__PURE__*/React.createElement("span", {
39
+ className: "text-truncate department-name"
40
+ }, getLocale(name)), selectedDepartment === type && /*#__PURE__*/React.createElement("span", {
41
+ className: "department-check-icon"
42
+ }, /*#__PURE__*/React.createElement("i", {
43
+ className: "dtable-font dtable-icon-check-mark"
44
+ }))));
45
+ });
46
+ }
47
+ function onSelectToggle(event) {
48
+ event.preventDefault();
49
+ setIsShowSelector(!isShowSelector);
50
+ }
51
+ function onCommit(value) {
52
+ setSelectedDepartment(value);
53
+ setIsShowSelector(false);
54
+ const columnOption = {
55
+ id: value
56
+ };
57
+ props.onCommit({
58
+ columnOption
59
+ });
60
+ }
61
+ return /*#__PURE__*/React.createElement("div", {
62
+ ref: selectorRef,
63
+ className: classnames('dtable-select custom-select', {
64
+ 'focus': isShowSelector
65
+ }),
66
+ onClick: onSelectToggle,
67
+ id: "filter-department-editor"
68
+ }, /*#__PURE__*/React.createElement("div", {
69
+ className: "selected-option"
70
+ }, value ? /*#__PURE__*/React.createElement("span", {
71
+ className: "selected-option-show"
72
+ }, /*#__PURE__*/React.createElement(SelectedDepartments, {
73
+ value: selectedDepartmentIds,
74
+ departments: departments
75
+ })) : /*#__PURE__*/React.createElement("span", {
76
+ className: "select-placeholder"
77
+ }, getLocale('Select_department')), /*#__PURE__*/React.createElement("span", {
78
+ className: "dtable-font dtable-icon-drop-down"
79
+ })), isShowSelector && /*#__PURE__*/React.createElement(DepartmentSingleSelect, {
80
+ enableSelectRange: false,
81
+ column: column,
82
+ value: value,
83
+ onCommit: onCommit,
84
+ userDepartmentIdsMap: userDepartmentIdsMap,
85
+ departments: departments,
86
+ renderUserDepartmentOptions: renderUserDepartmentOptions
87
+ }));
88
+ }
89
+ export default DepartmentSingleSelectFilter;
@@ -0,0 +1,167 @@
1
+ import React, { Component } from 'react';
2
+ import dayjs from '../../utils/dayjs';
3
+ import 'dayjs/locale/zh-cn';
4
+ import 'dayjs/locale/en-gb';
5
+ import Calendar from '@seafile/seafile-calendar';
6
+ import DatePicker from '@seafile/seafile-calendar/lib/Picker';
7
+ import { translateCalendar } from '../../lang';
8
+ import { getDateColumnFormat } from '../utils';
9
+ import '@seafile/seafile-calendar/assets/index.css';
10
+ let now = dayjs();
11
+ class FilterCalendar extends Component {
12
+ constructor(props) {
13
+ super(props);
14
+ this.handleMouseDown = e => {
15
+ e.preventDefault();
16
+ };
17
+ this.onChange = value => {
18
+ const {
19
+ onChange
20
+ } = this.props;
21
+ const searchFormat = 'YYYY-MM-DD';
22
+ this.setState({
23
+ value
24
+ }, () => {
25
+ if (this.state.value) {
26
+ onChange(this.state.value.format(searchFormat));
27
+ }
28
+ });
29
+ };
30
+ this.onClear = () => {
31
+ this.setState({
32
+ value: null
33
+ }, () => {
34
+ this.setState({
35
+ open: true
36
+ });
37
+ });
38
+ };
39
+ this.onOpenChange = open => {
40
+ this.setState({
41
+ open
42
+ });
43
+ };
44
+ this.onReadOnlyFocus = () => {
45
+ if (!this.state.open && this.state.isMouseDown) {
46
+ this.setState({
47
+ isMouseDown: false
48
+ });
49
+ } else {
50
+ this.setState({
51
+ open: true
52
+ });
53
+ }
54
+ };
55
+ this.getCalendarContainer = () => {
56
+ return this.calendarContainerRef.current;
57
+ };
58
+ this.getCalendarFormat = () => {
59
+ let calendarFormat = [];
60
+ if (this.columnDataFormat.indexOf('YYYY-MM-DD') > -1) {
61
+ let newColumnDataFormat = this.columnDataFormat.replace('YYYY-MM-DD', 'YYYY-M-D');
62
+ calendarFormat = [this.columnDataFormat, newColumnDataFormat];
63
+ } else if (this.columnDataFormat.indexOf('DD/MM/YYYY') > -1) {
64
+ let newColumnDataFormat = this.columnDataFormat.replace('DD/MM/YYYY', 'D/M/YYYY');
65
+ calendarFormat = [this.columnDataFormat, newColumnDataFormat];
66
+ } else {
67
+ calendarFormat = [this.columnDataFormat];
68
+ }
69
+ return calendarFormat;
70
+ };
71
+ this.state = {
72
+ open: false,
73
+ value: null
74
+ };
75
+ const DataFormat = getDateColumnFormat(props.filterColumn).trim();
76
+ //Minutes and seconds are not supported at present
77
+ this.columnDataFormat = DataFormat.split(' ')[0];
78
+ this.calendarContainerRef = React.createRef();
79
+ this.defaultCalendarValue = null;
80
+ }
81
+ componentDidMount() {
82
+ const {
83
+ value,
84
+ lang
85
+ } = this.props;
86
+ const iszhcn = lang === 'zh-cn';
87
+ if (iszhcn) {
88
+ now = now.locale('zh-cn');
89
+ } else {
90
+ now = now.locale('en-gb');
91
+ }
92
+ this.defaultCalendarValue = now.clone();
93
+ if (value && dayjs(value).isValid()) {
94
+ let validValue = dayjs(value).isValid() ? dayjs(value) : dayjs(this.defaultCalendarValue);
95
+ this.setState({
96
+ value: iszhcn ? dayjs(validValue).locale('zh-cn') : dayjs(validValue).locale('en-gb')
97
+ });
98
+ }
99
+ }
100
+ render() {
101
+ const {
102
+ isReadOnly
103
+ } = this.props;
104
+ const state = this.state;
105
+ if (isReadOnly) return /*#__PURE__*/React.createElement("input", {
106
+ className: "ant-calendar-picker-input ant-input form-control",
107
+ value: state.value ? state.value.format(this.columnDataFormat) : '',
108
+ disabled: true
109
+ });
110
+ const calendarFormat = this.getCalendarFormat();
111
+ const clearStyle = {
112
+ position: 'absolute',
113
+ top: '15px',
114
+ left: '225px',
115
+ color: 'gray',
116
+ fontSize: '12px'
117
+ };
118
+ const clearIcon = React.createElement('i', {
119
+ className: 'item-icon dtable-font dtable-icon-x',
120
+ style: clearStyle
121
+ });
122
+ const calendar = /*#__PURE__*/React.createElement(Calendar, {
123
+ className: "dtable-rc-calendar",
124
+ locale: translateCalendar(),
125
+ style: {
126
+ zIndex: 1001
127
+ },
128
+ dateInputPlaceholder: 'please enter date',
129
+ format: calendarFormat,
130
+ defaultValue: this.defaultCalendarValue,
131
+ showDateInput: true,
132
+ focusablePanel: false,
133
+ onClear: this.onClear,
134
+ clearIcon: clearIcon
135
+ });
136
+ return /*#__PURE__*/React.createElement("div", {
137
+ className: "date-picker-container"
138
+ }, /*#__PURE__*/React.createElement(DatePicker, {
139
+ calendar: calendar,
140
+ value: state.value,
141
+ onChange: this.onChange,
142
+ getCalendarContainer: this.getCalendarContainer,
143
+ onOpenChange: this.onOpenChange,
144
+ open: state.open,
145
+ style: {
146
+ zIndex: 1001
147
+ }
148
+ }, _ref => {
149
+ let {
150
+ value
151
+ } = _ref;
152
+ return /*#__PURE__*/React.createElement("span", {
153
+ tabIndex: "0",
154
+ onFocus: this.onReadOnlyFocus
155
+ }, /*#__PURE__*/React.createElement("input", {
156
+ tabIndex: "-1",
157
+ readOnly: true,
158
+ className: "ant-calendar-picker-input ant-input form-control",
159
+ value: value ? value.format(this.columnDataFormat) : '',
160
+ onMouseDown: this.handleMouseDown
161
+ }), /*#__PURE__*/React.createElement("div", {
162
+ ref: this.calendarContainerRef
163
+ }));
164
+ }));
165
+ }
166
+ }
167
+ export default FilterCalendar;