Skip to content

Commit 106e114

Browse files
杨国璇杨国璇
杨国璇
authored and
杨国璇
committed
feat: optimzie code
1 parent 8706ff9 commit 106e114

File tree

284 files changed

+1540
-1493
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

284 files changed

+1540
-1493
lines changed

src/CheckboxEditor/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
import React, { forwardRef } from 'react';
22
import PropTypes from 'prop-types';
33
import MediaQuery from 'react-responsive';
4-
import Large from './lg';
5-
import Small from './sm';
4+
import PCCheckboxEditor from './pc-editor';
5+
import MBCheckboxEditor from './mb-editor';
66

77
import './index.css';
88

9-
const CheckboxEditor = forwardRef(({ size, ...props }, ref) => {
10-
if (size === 'lg') return (<Large { ...props } />);
11-
if (size === 'sm') return (<Small { ...props } />);
9+
const CheckboxEditor = forwardRef(({ isMobile, ...props }, ref) => {
10+
if (isMobile === false) return (<PCCheckboxEditor { ...props } ref={ref} />);
11+
if (isMobile === true) return (<MBCheckboxEditor { ...props } ref={ref} />);
1212

1313
return (
1414
<>
1515
<MediaQuery query="(min-width: 768px)">
16-
<Large { ...props } ref={ref} />
16+
<PCCheckboxEditor { ...props } ref={ref} />
1717
</MediaQuery>
1818
<MediaQuery query="(max-width: 768px)">
19-
<Small { ...props } ref={ref} />
19+
<MBCheckboxEditor { ...props } ref={ref} />
2020
</MediaQuery>
2121
</>
2222
);
2323
});
2424

2525
CheckboxEditor.propTypes = {
26-
size: PropTypes.oneOf(['lg', 'sm']),
26+
isMobile: PropTypes.bool,
2727
};
2828

2929
export default CheckboxEditor;

src/CheckboxEditor/sm.js renamed to src/CheckboxEditor/mb-editor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import classnames from 'classnames';
44
import SvgIcon from '../SvgIcon';
55
import { DEFAULT_CHECKBOX_MARK_STYLE } from '../constants';
66

7-
class Small extends Component {
7+
class MBCheckboxEditor extends Component {
88

99
constructor(props) {
1010
super(props);
@@ -74,7 +74,7 @@ class Small extends Component {
7474
}
7575
}
7676

77-
Small.propTypes = {
77+
MBCheckboxEditor.propTypes = {
7878
isEditorShow: PropTypes.bool,
7979
className: PropTypes.string,
8080
style: PropTypes.object,
@@ -83,4 +83,4 @@ Small.propTypes = {
8383
onCommit: PropTypes.func,
8484
};
8585

86-
export default Small;
86+
export default MBCheckboxEditor;

src/CheckboxEditor/lg.js renamed to src/CheckboxEditor/pc-editor.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import classnames from 'classnames';
44
import SvgIcon from '../SvgIcon';
55
import { KeyCodes, DEFAULT_CHECKBOX_MARK_STYLE } from '../constants';
66

7-
class Large extends Component {
7+
class PCCheckboxEditor extends Component {
88

99
constructor(props) {
1010
super(props);
@@ -89,7 +89,7 @@ class Large extends Component {
8989
}
9090
}
9191

92-
Large.propTypes = {
92+
PCCheckboxEditor.propTypes = {
9393
isEditorShow: PropTypes.bool,
9494
className: PropTypes.string,
9595
style: PropTypes.object,
@@ -98,4 +98,4 @@ Large.propTypes = {
9898
onCommit: PropTypes.func,
9999
};
100100

101-
export default Large;
101+
export default PCCheckboxEditor;

src/CollaboratorEditor/index.js

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,31 @@
11
import React, { forwardRef } from 'react';
22
import PropTypes from 'prop-types';
33
import MediaQuery from 'react-responsive';
4-
import Large from './lg';
5-
import Small from './sm';
4+
import PCCollaboratorEditor from './pc-editor';
5+
import MBCollaboratorEditor from './mb-editor';
66

77
import './index.css';
88

9-
const CollaboratorEditor = forwardRef(({ value: oldValue, size, ...props }, ref) => {
9+
const CollaboratorEditor = forwardRef(({ isMobile, value: oldValue, ...props }, ref) => {
1010
const value = Array.isArray(oldValue) ? oldValue : [];
11-
12-
if (size === 'lg') return (<Large { ...props } value={value} />);
13-
if (size === 'sm') return (<Small { ...props } value={value} />);
11+
if (isMobile === false) return (<PCCollaboratorEditor { ...props } value={value} ref={ref} />);
12+
if (isMobile === true) return (<MBCollaboratorEditor { ...props } value={value} ref={ref} />);
1413

1514
return (
1615
<>
17-
<MediaQuery query={'(min-width: 768px)'}>
18-
<Large { ...props} value={value} ref={ref} />
16+
<MediaQuery query="(min-width: 768px)">
17+
<PCCollaboratorEditor { ...props } value={value} ref={ref} />
1918
</MediaQuery>
20-
<MediaQuery query={'(max-width: 767.8px)'}>
21-
<Small { ...props} value={value} ref={ref} />
19+
<MediaQuery query="(max-width: 768px)">
20+
<MBCollaboratorEditor { ...props } value={value} ref={ref} />
2221
</MediaQuery>
2322
</>
2423
);
2524
});
2625

2726
CollaboratorEditor.propTypes = {
27+
isMobile: PropTypes.bool,
2828
value: PropTypes.oneOfType([PropTypes.string, PropTypes.array]),
29-
size: PropTypes.oneOf(['lg', 'sm']),
3029
};
3130

3231
export default CollaboratorEditor;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
@import url('../../css/mb-cell-editor.css');
2+
3+
.dtable-ui-mobile-collaborator-editor .dtable-ui-mobile-selector-option .dtable-ui-mobile-selector-option-name {
4+
height: 36px !important;
5+
line-height: 36px !important;
6+
margin-top: 0px !important;
7+
}
8+
9+
.dtable-ui-mobile-selector.dtable-ui-mobile-collaborator-editor .dtable-ui-mobile-selector-option {
10+
font-size: 16px;
11+
}
12+
13+
.dtable-ui-mobile-collaborator-editor .dtable-ui-mobile-selector-option .dtable-ui.collaborator-item {
14+
background-color: inherit;
15+
border-radius: 0;
16+
height: 100%;
17+
width: 100%;
18+
}
19+
20+
.dtable-ui-mobile-collaborator-editor .dtable-ui-mobile-selector-option .dtable-ui.collaborator-item .collaborator-avatar {
21+
height: 2rem;
22+
margin: 2px 0;
23+
vertical-align: middle;
24+
width: 2rem;
25+
}
26+
27+
.dtable-ui-mobile-collaborator-editor .dtable-ui-mobile-selector-option .dtable-ui.collaborator-item .collaborator-avatar-icon {
28+
border-radius: 50%;
29+
height: 2rem;
30+
width: 2rem;
31+
}
32+
33+
.dtable-ui-mobile-collaborator-editor .dtable-ui-mobile-selector-option .dtable-ui.collaborator-item .collaborator-name {
34+
height: 100%;
35+
font-size: 16px;
36+
line-height: 36px;
37+
width: 100%;
38+
overflow: hidden;
39+
text-overflow: ellipsis;
40+
white-space: nowrap;
41+
}

src/CollaboratorEditor/sm/index.js renamed to src/CollaboratorEditor/mb-editor/index.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { searchCollaborators } from 'dtable-utils';
4-
import MobileSelectorEditor from '../../MobileSelectorEditor';
4+
import MobileSelector from '../../MobileSelector';
55
import { getLocale } from '../../lang';
66
import CollaboratorItem from '../../CollaboratorItem';
77

88
import './index.css';
99

10-
const { Search, Option, Options, Empty } = MobileSelectorEditor;
10+
const { Search, Option, Options, Empty } = MobileSelector;
1111

12-
class Small extends React.Component {
12+
class MBCollaboratorEditor extends React.Component {
1313

1414
static defaultProps = {
1515
value: [],
@@ -65,25 +65,25 @@ class Small extends React.Component {
6565
const displayCollaborators = searchVal ? searchCollaborators(collaborators, searchVal) : collaborators;
6666

6767
return (
68-
<MobileSelectorEditor onClose={this.props.onClose} title={column.name} className="mobile-dtable-ui-collaborator-editor">
68+
<MobileSelector onClose={this.props.onClose} title={column.name} className="dtable-ui-mobile-collaborator-editor">
6969
{collaborators.length > 10 && (
7070
<Search value={searchVal} placeholder={getLocale('Search_collaborator')} onChange={this.onChangeSearch} />
7171
)}
7272
<Options>
7373
{displayCollaborators.length === 0 && (<Empty>{getLocale('No_collaborators_available')}</Empty>)}
7474
{displayCollaborators.length > 0 && this.renderCollaborators(displayCollaborators)}
7575
</Options>
76-
</MobileSelectorEditor>
76+
</MobileSelector>
7777
);
7878
}
7979
}
8080

81-
Small.propTypes = {
81+
MBCollaboratorEditor.propTypes = {
8282
value: PropTypes.array.isRequired,
8383
column: PropTypes.object.isRequired,
8484
collaborators: PropTypes.array.isRequired,
8585
onCommit: PropTypes.func.isRequired,
8686
onClose: PropTypes.func,
8787
};
8888

89-
export default Small;
89+
export default MBCollaboratorEditor;

src/CollaboratorEditor/lg/index.js renamed to src/CollaboratorEditor/pc-editor/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import ObjectUtils from '../../utils/object-utils';
1111

1212
import './index.css';
1313

14-
class Large extends React.Component {
14+
class PCCollaboratorEditor extends React.Component {
1515

1616
constructor(props) {
1717
super(props);
@@ -230,7 +230,7 @@ class Large extends React.Component {
230230
}
231231
}
232232

233-
Large.propTypes = {
233+
PCCollaboratorEditor.propTypes = {
234234
isInModal: PropTypes.bool,
235235
value: PropTypes.array,
236236
collaborators: PropTypes.array.isRequired,
@@ -241,4 +241,4 @@ Large.propTypes = {
241241
onPressTab: PropTypes.func,
242242
};
243243

244-
export default Large;
244+
export default PCCollaboratorEditor;

src/CollaboratorEditor/sm/index.css

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/DTableFiltersPopover/widgets/department-select-filter/department-multiple-select-filter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { useState, useRef } from 'react';
22
import PropTypes from 'prop-types';
33
import classnames from 'classnames';
4-
import SelectedDepartments from '../../../DepartmentEditor/selected-departments';
5-
import DepartmentMultipleSelect from '../../../DepartmentEditor/department-multiple-select';
6-
import { DEPARTMENT_SELECT_RANGE_OPTIONS } from '../../../DepartmentEditor/constants';
4+
import SelectedDepartments from '../../../SelectedDepartments';
5+
import DepartmentMultipleSelectEditor from '../../../DepartmentMultipleSelectEditor';
6+
import { DEPARTMENT_SELECT_RANGE_OPTIONS } from '../../../constants/departments';
77
import { useClickOutside } from '../../../hooks/common-hooks';
88
import { getLocale } from '../../../lang';
99

@@ -85,7 +85,7 @@ function DepartmentMultipleSelectFilter(props) {
8585
<span className="dtable-font dtable-icon-down3"></span>
8686
</div>
8787
{isShowSelector &&
88-
<DepartmentMultipleSelect
88+
<DepartmentMultipleSelectEditor
8989
isShowSelectedDepartments={false}
9090
classNamePrefix="filter"
9191
value={selectedDepartments}

src/DTableFiltersPopover/widgets/department-select-filter/department-single-select-filter.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, { useState, useRef } from 'react';
22
import PropTypes from 'prop-types';
33
import classnames from 'classnames';
4-
import SelectedDepartments from '../../../DepartmentEditor/selected-departments';
5-
import DepartmentEditor from '../../../DepartmentEditor';
6-
import { DEPARTMENT_SELECT_RANGE_OPTIONS } from '../../../DepartmentEditor/constants';
4+
import SelectedDepartments from '../../../SelectedDepartments';
5+
import DepartmentSingleSelectEditor from '../../../DepartmentSingleSelectEditor';
6+
import { DEPARTMENT_SELECT_RANGE_OPTIONS } from '../../../constants/departments';
77
import { useClickOutside } from '../../../hooks/common-hooks';
88
import { getLocale } from '../../../lang';
99

@@ -83,7 +83,7 @@ function DepartmentSingleSelectFilter(props) {
8383
<span className="dtable-font dtable-icon-down3"></span>
8484
</div>
8585
{isShowSelector &&
86-
<DepartmentEditor
86+
<DepartmentSingleSelectEditor
8787
enableSelectRange={false}
8888
column={column}
8989
value={value}

src/DateEditor/index.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,15 @@ import PropTypes from 'prop-types';
33
import MediaQuery from 'react-responsive';
44
import { DEFAULT_DATE_FORMAT } from 'dtable-utils';
55
import dayjs from '../utils/dayjs';
6-
import Large from './lg';
7-
import Small from './sm';
6+
import PCDateEditor from './pc-editor';
7+
import MBDateEditor from './mb-editor';
88

99
import 'dayjs/locale/zh-cn';
1010
import 'dayjs/locale/en-gb';
1111

1212
import './index.css';
1313

14-
const propTypes = {
15-
isReadOnly: PropTypes.bool,
16-
isInModal: PropTypes.bool,
17-
value: PropTypes.string,
18-
lang: PropTypes.string,
19-
className: PropTypes.string,
20-
column: PropTypes.object.isRequired,
21-
onCommit: PropTypes.func.isRequired,
22-
onClose: PropTypes.func,
23-
firstDayOfWeek: PropTypes.string,
24-
};
25-
26-
const DateEditor = forwardRef(({ lang, isReadOnly, column, className, isInModal, firstDayOfWeek, size, value: oldValue, hideCalendar, onCommit }, ref) => {
14+
const DateEditor = forwardRef(({ isMobile, lang, isReadOnly, column, className, isInModal, firstDayOfWeek, size, value: oldValue, hideCalendar, onCommit }, ref) => {
2715
const [isDateInit, setDateInit] = useState(false);
2816
const [value, setValue] = useState(oldValue || '');
2917

@@ -58,21 +46,32 @@ const DateEditor = forwardRef(({ lang, isReadOnly, column, className, isInModal,
5846
onClose: hideCalendar,
5947
};
6048

61-
if (size === 'lg') return (<Large { ...props } isInModal={isInModal} ref={ref} />);
62-
if (size === 'sm') return (<Small { ...props } isReadOnly={isReadOnly} column={column} ref={ref} />);
49+
if (isMobile === false) return (<PCDateEditor { ...props } isInModal={isInModal} ref={ref} />);
50+
if (isMobile === true) return (<MBDateEditor { ...props } isReadOnly={isReadOnly} column={column} ref={ref} />);
6351

6452
return (
6553
<>
6654
<MediaQuery query={'(min-width: 768px)'}>
67-
<Large { ...props } isInModal={isInModal} ref={ref} />
55+
<PCDateEditor { ...props } isInModal={isInModal} ref={ref} />
6856
</MediaQuery>
69-
<MediaQuery query={'(max-width: 767.8px)'}>
70-
<Small { ...props } isReadOnly={isReadOnly} column={column} ref={ref} />
57+
<MediaQuery query={'(max-width: 768px)'}>
58+
<MBDateEditor { ...props } isReadOnly={isReadOnly} column={column} ref={ref} />
7159
</MediaQuery>
7260
</>
7361
);
7462
});
7563

76-
DateEditor.propTypes = propTypes;
64+
DateEditor.propTypes = {
65+
isMobile: PropTypes.bool,
66+
isReadOnly: PropTypes.bool,
67+
isInModal: PropTypes.bool,
68+
value: PropTypes.string,
69+
lang: PropTypes.string,
70+
className: PropTypes.string,
71+
column: PropTypes.object.isRequired,
72+
onCommit: PropTypes.func.isRequired,
73+
onClose: PropTypes.func,
74+
firstDayOfWeek: PropTypes.string,
75+
};
7776

7877
export default DateEditor;

0 commit comments

Comments
 (0)