1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-21 11:27:18 +00:00

fix: single select column cascade edit (#5563)

* fix: single select column cascade edit

* feat: update code
This commit is contained in:
杨国璇
2023-07-27 17:03:49 +08:00
committed by GitHub
parent 5eadcb2d45
commit f8e2f72ac2
3 changed files with 41 additions and 20 deletions

View File

@@ -41,6 +41,12 @@
} }
/* editor */ /* editor */
.single-select-editor-popover .popover,
.single-select-editor-popover .popover-inner {
width: fit-content;
max-width: fit-content;
}
.single-select-editor-container { .single-select-editor-container {
min-height: 160px; min-height: 160px;
width: 320px; width: 320px;

View File

@@ -21,7 +21,7 @@ class SingleSelect extends Component {
} }
updateState = () => { updateState = () => {
// this.setState({ isShowSingleSelect: !this.state.isShowSingleSelect }); this.setState({ isShowSingleSelect: !this.state.isShowSingleSelect });
} }
onCommit = (value, column) => { onCommit = (value, column) => {

View File

@@ -9,22 +9,41 @@ class SingleSelectEditor extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
const options = this.getSelectColumnOptions(); const options = this.getSelectColumnOptions(props);
this.state = { this.state = {
value: props.row[props.column.key], value: props.row[props.column.key],
searchVal: '', searchVal: '',
highlightIndex: -1, highlightIndex: -1,
maxItemNum: 0, maxItemNum: 0,
itemHeight: 0 itemHeight: 0,
filteredOptions: options,
}; };
this.options = options; this.options = options;
this.filteredOptions = options;
this.timer = null; this.timer = null;
this.editorKey = `single-select-editor-${props.column.key}`; this.editorKey = `single-select-editor-${props.column.key}`;
} }
getSelectColumnOptions = () => { UNSAFE_componentWillReceiveProps(nextProps) {
const { column, row, columns } = this.props; const currentCascadeColumnValue = this.getCascadeColumnValue(this.props);
const nextCascadeColumnValue = this.getCascadeColumnValue(nextProps);
if (currentCascadeColumnValue !== nextCascadeColumnValue) {
this.options = this.getSelectColumnOptions(nextProps);
this.setState({ filteredOptions: this.options });
}
}
getCascadeColumnValue = (props) => {
const { column, row, columns } = props;
const { data } = column;
const { cascade_column_key } = data || {};
if (!cascade_column_key) return '';
const cascadeColumn = columns.find(item => item.key === cascade_column_key);
if (!cascadeColumn) return '';
return row[cascade_column_key];
}
getSelectColumnOptions = (props) => {
const { column, row, columns } = props;
let options = getSelectColumnOptions(column); let options = getSelectColumnOptions(column);
const { data } = column; const { data } = column;
const { cascade_column_key, cascade_settings } = data || {}; const { cascade_column_key, cascade_settings } = data || {};
@@ -41,35 +60,30 @@ class SingleSelectEditor extends Component {
return options; return options;
} }
setRef = (ref) => { toggle = () => {
this.ref = ref; this.ref.toggle();
if (!this.ref) return;
const { toggle } = this.ref;
this.ref.toggle = () => {
toggle && toggle();
this.props.onUpdateState(); this.props.onUpdateState();
};
} }
onChangeSearch = (searchVal) => { onChangeSearch = (searchVal) => {
const { searchVal: oldSearchVal } = this.state; const { searchVal: oldSearchVal } = this.state;
if (oldSearchVal === searchVal) return; if (oldSearchVal === searchVal) return;
const val = searchVal.toLowerCase(); const val = searchVal.toLowerCase();
this.filteredOptions = val ? const filteredOptions = val ?
this.options.filter((item) => item.name && item.name.toLowerCase().indexOf(val) > -1) : this.options; this.options.filter((item) => item.name && item.name.toLowerCase().indexOf(val) > -1) : this.options;
this.setState({ searchVal }); this.setState({ searchVal, filteredOptions });
} }
onSelectOption = (optionID) => { onSelectOption = (optionID) => {
const { column } = this.props; const { column } = this.props;
this.setState({ value: optionID }, () => { this.setState({ value: optionID }, () => {
this.props.onCommit({ [column.key]: optionID }, column); this.props.onCommit({ [column.key]: optionID }, column);
this.ref.toggle(); this.toggle();
}); });
} }
render() { render() {
const { value } = this.state; const { value, filteredOptions } = this.state;
const { column } = this.props; const { column } = this.props;
return ( return (
@@ -79,7 +93,8 @@ class SingleSelectEditor extends Component {
trigger="legacy" trigger="legacy"
placement="bottom-start" placement="bottom-start"
hideArrow={true} hideArrow={true}
ref={this.setRef} toggle={this.toggle}
ref={ref => this.ref = ref}
> >
<div className="single-select-editor-container"> <div className="single-select-editor-container">
<div className="search-single-selects"> <div className="search-single-selects">
@@ -91,7 +106,7 @@ class SingleSelectEditor extends Component {
/> />
</div> </div>
<div className="single-select-editor-content"> <div className="single-select-editor-content">
{this.filteredOptions.map(option => { {filteredOptions.map(option => {
const isSelected = value === option.id; const isSelected = value === option.id;
const style = { const style = {
backgroundColor: option.color, backgroundColor: option.color,