Skip to content

Commit e65970b

Browse files
Merge pull request #296 from seatable/fix-row-expand-editor
fix: row expand editor
2 parents 29df91c + 50369c2 commit e65970b

File tree

8 files changed

+70
-32
lines changed

8 files changed

+70
-32
lines changed

src/RowExpandDialog/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ const RowExpandDialog = forwardRef(({
6969
if (readonly || !column || !column.editable || NOT_SUPPORT_EDIT_COLUMN_TYPE_MAP[column.type]) return false;
7070
if (column.type === CellType.IMAGE || column.type === CellType.FILE) return Boolean(uploadFile);
7171
return true;
72-
}, [isSaving, uploadFile]);
72+
}, [readonly, isSaving, uploadFile]);
7373

7474
const initRowData = useCallback(() => {
7575
setLoading(true);
@@ -82,7 +82,7 @@ const RowExpandDialog = forwardRef(({
8282
isChangedRef.current = isInsertingRow && Object.keys(defaultRow).length > 0;
8383
setColumns(validColumns);
8484
setLoading(false);
85-
}, [isInsertingRow, checkEditable]);
85+
}, [isInsertingRow, defaultColumns, defaultRow, checkEditable]);
8686

8787
const toggle = useCallback(() => {
8888
if (isSaving) return;

src/RowExpandEditor/RowExpandCollaboratorEditor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class RowExpandCollaboratorEditor extends React.Component {
9292
};
9393

9494
hideSelect = (event) => {
95-
if (!this.state.showCollaboratorSelect || !event.target || event.target.tagName.toUpperCase() === 'INPUT') {
95+
if (!this.state.showCollaboratorSelect || !event.target) {
9696
return;
9797
}
9898
const editor = document.querySelector('.dtable-ui-collaborator-editor-container');

src/RowExpandEditor/RowExpandDepartmentEditor/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ import classnames from 'classnames';
44
import { useClickOutside } from '../../hooks';
55
import DepartmentSingleSelectFormatter from '../../DepartmentSingleSelectFormatter';
66
import { KeyCodes } from '../../constants';
7-
import { getLocale } from '../../lang';
87
import DepartmentSingleSelect from '../../Department-editor/department-single-select';
9-
import { DEPARTMENT_SELECT_RANGE_OPTIONS } from '../../Department-editor/constants';
108

119
function RowExpandDepartmentEditor(props) {
1210
const { row, column, valueKey, departments, userDepartmentIdsMap, isEditorFocus, columnIndex } = props;
@@ -35,7 +33,7 @@ function RowExpandDepartmentEditor(props) {
3533
}, [row]);
3634

3735
function hideDropDownMenu(event) {
38-
if (!event.target || event.target.tagName.toUpperCase() === 'INPUT') return;
36+
if (!event.target) return;
3937
toggleDepartmentSelect(false);
4038
}
4139

src/RowExpandEditor/RowExpandGeolocationEditor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class RowExpandGeolocationEditor extends React.Component {
6161
hideEditor = (event) => {
6262
if (
6363
!this.state.isShowEditor
64-
|| !event.target || event.target.tagName.toUpperCase() === 'INPUT'
64+
|| !event.target
6565
|| this.editorContainer.contains(event.target)
6666
) return;
6767
if (this.state.isShowEditor && this.geoEditor.getLargeEditorState()) return;

src/RowExpandEditor/RowExpandMultipleSelectEditor/index.js

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23
import { getColumnOptions } from 'dtable-utils';
34
import classnames from 'classnames';
45
import { KeyCodes, DELETED_OPTION_BACKGROUND_COLOR, DELETED_OPTION_TIPS } from '../../constants';
56
import MultipleSelectEditor from '../../MultipleSelectEditor';
67
import { getLocale } from '../../lang';
8+
import ObjectUtils from '../../utils/object-utils';
79

810
import './index.css';
911

@@ -26,8 +28,8 @@ class RowExpandMultipleSelectEditor extends React.Component {
2628
}
2729

2830
UNSAFE_componentWillReceiveProps(nextProps) {
29-
const { value } = nextProps;
30-
if (value !== this.props.value) {
31+
const { value, column } = nextProps;
32+
if (value !== this.props.value || !ObjectUtils.isSameObject(column, this.props.column)) {
3133
this.options = this.getOptions(nextProps);
3234
this.setState({ value });
3335
}
@@ -69,7 +71,7 @@ class RowExpandMultipleSelectEditor extends React.Component {
6971
};
7072

7173
hideDropDownMenu = (event) => {
72-
if (!event.target || event.target.tagName.toUpperCase() === 'INPUT') return;
74+
if (!event.target) return;
7375
if (!this.ref.contains(event.target) && this.state.showSelectPopover) {
7476
const singleSelectEditor = document.getElementsByClassName('dtable-ui-select-editor-container')[0];
7577
if (singleSelectEditor && singleSelectEditor.contains(event.target)) return;
@@ -80,7 +82,8 @@ class RowExpandMultipleSelectEditor extends React.Component {
8082
onToggleSelect = (e) => {
8183
e.preventDefault();
8284
e.stopPropagation();
83-
this.props.updateTabIndex(this.props.columnIndex);
85+
const { updateTabIndex, columnIndex } = this.props;
86+
updateTabIndex && updateTabIndex(columnIndex);
8487
this.toggleSingleSelect(true);
8588
};
8689

@@ -89,7 +92,8 @@ class RowExpandMultipleSelectEditor extends React.Component {
8992
};
9093

9194
onFocus = () => {
92-
this.props.updateTabIndex(this.props.columnIndex);
95+
const { updateTabIndex, columnIndex } = this.props;
96+
updateTabIndex && updateTabIndex(columnIndex);
9397
};
9498

9599
onChange = (option) => {
@@ -148,7 +152,7 @@ class RowExpandMultipleSelectEditor extends React.Component {
148152
};
149153

150154
renderOptions = () => {
151-
const { isEditorFocus } = this.props;
155+
const { isEditorFocus, classNamePrefix, placeholder } = this.props;
152156
const options = this.getMultipleSelectList();
153157

154158
return (
@@ -157,15 +161,16 @@ class RowExpandMultipleSelectEditor extends React.Component {
157161
onFocus={this.onFocus}
158162
onClick={this.onToggleSelect}
159163
ref={ref => this.multipleSelectOptionsRef = ref}
160-
className={classnames('dtable-ui dtable-ui-row-expand-select-editor custom-select', { 'focus': isEditorFocus })}
164+
className={classnames('dtable-ui dtable-ui-row-expand-select-editor custom-select', { 'focus': isEditorFocus, [`${classNamePrefix}-select-editor`]: classNamePrefix })}
161165
>
162-
<div className="dtable-ui-row-expand-select-editor-inner">
163-
<div>
166+
<div className={classnames('dtable-ui-row-expand-select-editor-inner', { [`${classNamePrefix}-select-editor-inner`]: classNamePrefix })}>
167+
<div className={classnames('', { [`${classNamePrefix}-select-editor-inner-container`]: classNamePrefix })}>
164168
{options.length > 0 &&
165-
<div className="dtable-ui-row-expand-select-options">
169+
<div className={classnames('dtable-ui-row-expand-select-options', { [`${classNamePrefix}-select-editor-options`]: classNamePrefix })}>
166170
{options}
167171
</div>
168172
}
173+
{options.length === 0 && placeholder && (<>{placeholder}</>)}
169174
</div>
170175
<i aria-hidden="true" className="dtable-font dtable-icon-down3"></i>
171176
</div>
@@ -174,7 +179,7 @@ class RowExpandMultipleSelectEditor extends React.Component {
174179
};
175180

176181
render() {
177-
const { column, isSupportNewOption, onAddNewOption } = this.props;
182+
const { column, isSupportNewOption, onAddNewOption, classNamePrefix } = this.props;
178183
const { showSelectPopover, value } = this.state;
179184
return (
180185
<div className="position-relative w-100" ref={ref => this.ref = ref}>
@@ -188,6 +193,7 @@ class RowExpandMultipleSelectEditor extends React.Component {
188193
value={value}
189194
valueKey={this.key}
190195
target={this.targetRef}
196+
classNamePrefix={classNamePrefix}
191197
onCommit={this.onChange}
192198
isSupportNewOption={isSupportNewOption}
193199
onAddNewOption={onAddNewOption}
@@ -200,4 +206,19 @@ class RowExpandMultipleSelectEditor extends React.Component {
200206

201207
}
202208

209+
RowExpandMultipleSelectEditor.propTypes = {
210+
column: PropTypes.object,
211+
value: PropTypes.array,
212+
valueKey: PropTypes.string,
213+
isSupportNewOption: PropTypes.bool,
214+
onAddNewOption: PropTypes.func,
215+
isEditorFocus: PropTypes.bool,
216+
classNamePrefix: PropTypes.string,
217+
placeholder: PropTypes.any,
218+
columnIndex: PropTypes.number,
219+
updateTabIndex: PropTypes.func,
220+
onEditorOpen: PropTypes.func,
221+
onEditorClose: PropTypes.func,
222+
};
223+
203224
export default RowExpandMultipleSelectEditor;

src/RowExpandEditor/RowExpandSingleSelectorEditor/index.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import React from 'react';
2+
import PropTypes from 'prop-types';
23
import { getColumnOptions } from 'dtable-utils';
34
import { KeyCodes, DELETED_OPTION_BACKGROUND_COLOR, DELETED_OPTION_TIPS } from '../../constants';
45
import classnames from 'classnames';
56
import SingleSelectEditor from '../../SingleSelectEditor';
67
import { getLocale } from '../../lang';
8+
import ObjectUtils from '../../utils/object-utils';
79

810
import './index.css';
911

@@ -27,8 +29,8 @@ class RowExpandSingleSelectEditor extends React.Component {
2729
}
2830

2931
UNSAFE_componentWillReceiveProps(nextProps) {
30-
const { value } = nextProps;
31-
if (value !== this.props.value) {
32+
const { value, column } = nextProps;
33+
if (value !== this.props.value || !ObjectUtils.isSameObject(column, this.props.column)) {
3234
this.options = this.getOptions(nextProps);
3335
this.setState({ value, showSelectPopover: false });
3436
}
@@ -87,8 +89,8 @@ class RowExpandSingleSelectEditor extends React.Component {
8789
};
8890

8991
hideDropDownMenu = (event) => {
90-
if (!event.target || event.target.tagName.toUpperCase() === 'INPUT') return;
91-
if (!this.singleSelectContainer.contains(event.target) && this.state.showSelectPopover) {
92+
if (!event.target) return;
93+
if (!this.ref.contains(event.target) && this.state.showSelectPopover) {
9294
const singleSelectEditor = document.getElementsByClassName('dtable-ui-select-editor-container')[0];
9395
if (singleSelectEditor && singleSelectEditor.contains(event.target)) return;
9496
this.toggleSingleSelect(false);
@@ -116,7 +118,7 @@ class RowExpandSingleSelectEditor extends React.Component {
116118
};
117119

118120
renderOption = () => {
119-
const { isEditorFocus } = this.props;
121+
const { isEditorFocus, classNamePrefix, placeholder } = this.props;
120122
const { value } = this.state;
121123
const option = this.options.find(o => o[this.key] === value);
122124
const optionStyle = option ?
@@ -130,15 +132,16 @@ class RowExpandSingleSelectEditor extends React.Component {
130132
onFocus={this.onFocus}
131133
onClick={this.onToggleSelect}
132134
ref={ref => this.selectRef = ref}
133-
className={classnames('dtable-ui dtable-ui-row-expand-select-editor custom-select', { 'focus': isEditorFocus })}
135+
className={classnames('dtable-ui dtable-ui-row-expand-select-editor custom-select', { 'focus': isEditorFocus, [`${classNamePrefix}-select-editor`]: classNamePrefix })}
134136
>
135-
<div className="dtable-ui-row-expand-select-editor-inner">
136-
<div>
137+
<div className={classnames('dtable-ui-row-expand-select-editor-inner', { [`${classNamePrefix}-select-editor-inner`]: classNamePrefix })}>
138+
<div className={classnames('', { [`${classNamePrefix}-select-editor-inner-container`]: classNamePrefix })}>
137139
{value && (
138140
<div className="dtable-ui-select-option" style={optionStyle} title={optionName}>
139141
{optionName}
140142
</div>
141143
)}
144+
{!value && placeholder && (<>{placeholder}</>)}
142145
</div>
143146
<i aria-hidden="true" className="dtable-font dtable-icon-down3"></i>
144147
</div>
@@ -147,10 +150,10 @@ class RowExpandSingleSelectEditor extends React.Component {
147150
};
148151

149152
render() {
150-
const { isSupportNewOption, onAddNewOption, column } = this.props;
153+
const { isSupportNewOption, onAddNewOption, column, classNamePrefix } = this.props;
151154
const { showSelectPopover, value } = this.state;
152155
return (
153-
<div className="position-relative w-100" ref={ref => this.singleSelectContainer = ref}>
156+
<div className="position-relative w-100" ref={ref => this.ref = ref}>
154157
{this.renderOption()}
155158
<span ref={ref => this.targetRef = ref}></span>
156159
{showSelectPopover && (
@@ -161,6 +164,7 @@ class RowExpandSingleSelectEditor extends React.Component {
161164
value={value}
162165
valueKey={this.key}
163166
target={this.targetRef}
167+
classNamePrefix={classNamePrefix}
164168
onCommit={this.onChange}
165169
isSupportNewOption={isSupportNewOption}
166170
onAddNewOption={onAddNewOption}
@@ -173,4 +177,19 @@ class RowExpandSingleSelectEditor extends React.Component {
173177

174178
}
175179

180+
RowExpandSingleSelectEditor.propTypes = {
181+
column: PropTypes.object,
182+
value: PropTypes.array,
183+
valueKey: PropTypes.string,
184+
isSupportNewOption: PropTypes.bool,
185+
onAddNewOption: PropTypes.func,
186+
isEditorFocus: PropTypes.bool,
187+
classNamePrefix: PropTypes.string,
188+
placeholder: PropTypes.any,
189+
columnIndex: PropTypes.number,
190+
updateTabIndex: PropTypes.func,
191+
onEditorOpen: PropTypes.func,
192+
onEditorClose: PropTypes.func,
193+
};
194+
176195
export default RowExpandSingleSelectEditor;

src/RowExpandEditor/RowExpandUrlEditor/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RowExpandUrlEditor extends React.Component {
1212
constructor(props) {
1313
super(props);
1414
this.state = {
15-
value: props.value,
15+
value: props.value || '',
1616
};
1717
this.inputRef = React.createRef();
1818
}

src/select-editor/pc-select-editor/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class PCSelectEditor extends React.Component {
204204
};
205205

206206
render() {
207-
const { isInModal, className, value, column, valueKey, isSupportNewOption, target } = this.props;
207+
const { isInModal, className, value, column, valueKey, isSupportNewOption, target, classNamePrefix } = this.props;
208208
const { searchValue, highlightIndex } = this.state;
209209

210210
// maxWidth = single-selects-container's width - single-selects-container's padding-left and padding-right - single-select-container's padding-left - single-select-check-icon's width - The gap between the single-select-check-icon and single-select-name or scroll's width
@@ -213,7 +213,7 @@ class PCSelectEditor extends React.Component {
213213
let maxWidth = isInModal ? 250 : column?.width > 200 ? column.width - 62 : 138;
214214

215215
const dom = (
216-
<div className={classnames('dtable-ui-editor-container dtable-ui-select-editor-container', className)} ref={ref => this.ref = ref}>
216+
<div className={classnames('dtable-ui-editor-container dtable-ui-select-editor-container', className, { [`${classNamePrefix}-select-editor-container`]: classNamePrefix })} ref={ref => this.ref = ref}>
217217
<div className="select-options-search">
218218
<DtableSearchInput
219219
placeholder={getLocale('Search_option')}
@@ -264,7 +264,7 @@ class PCSelectEditor extends React.Component {
264264
target={target}
265265
hideArrow={true}
266266
fade={false}
267-
className="dtable-ui dtable-ui-row-expand-select-editor-popover"
267+
className={classnames('dtable-ui dtable-ui-row-expand-select-editor-popover', { [`${classNamePrefix}-select-editor-popover`]: classNamePrefix })}
268268
>
269269
{dom}
270270
</Popover>

0 commit comments

Comments
 (0)