Skip to content

Commit

Permalink
feat: add removeChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
sheepluo committed Aug 20, 2023
1 parent dd8e334 commit 59acd3f
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion js/table/tree-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import isUndefined from 'lodash/isUndefined';
/* eslint-disable no-param-reassign */
/* eslint-disable no-use-before-define */
import get from 'lodash/get';
import set from 'lodash/set';
import { isRowSelectedDisabled } from './utils';
import { PrimaryTableCol, TableRowState, TableRowValue, TableRowData } from './types';
import log from '../log';
Expand Down Expand Up @@ -255,11 +256,42 @@ class TableTreeStore<T extends TableRowData = TableRowData> {
type: 'remove',
});
} else {
log.warn('EnhancedTable', 'Do not remove this node, which is not appeared.');
log.warn('EnhancedTable', 'Can not remove this node, which is not appeared.');
}
return dataSource;
}

/**
* 清除子节点
* @param key

Check failure on line 266 in js/table/tree-store.ts

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
* @param dataSource

Check failure on line 267 in js/table/tree-store.ts

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
* @param keys

Check failure on line 268 in js/table/tree-store.ts

View workflow job for this annotation

GitHub Actions / test

Trailing spaces not allowed
*/
removeChildren(key: TableRowValue, dataSource: T[], keys: KeysType): T[] {
const r = this.treeDataMap.get(key);
if (r && r.rowIndex >= 0) {
const removeNumber = (r.expandChildrenLength || 0);
removeNumber && dataSource.splice(r.rowIndex + 1, removeNumber);

Check failure on line 274 in js/table/tree-store.ts

View workflow job for this annotation

GitHub Actions / test

Expected an assignment or function call and instead saw an expression
if (r.parent) {
updateRowExpandLength(this.treeDataMap, r.parent.row, -1 * removeNumber, 'delete', keys);
}
r.expandChildrenLength = 0;
r.expanded = false;
set(r.row, keys.childrenKey, undefined);
this.treeDataMap.set(key, r);
// 更新 rowIndex 之后的下标
removeNumber && updateRowIndex(this.treeDataMap, dataSource, {

Check failure on line 283 in js/table/tree-store.ts

View workflow job for this annotation

GitHub Actions / test

Expected an assignment or function call and instead saw an expression
minRowIndex: r.rowIndex + 1,
rowKey: keys.rowKey,
type: 'remove',
});
} else {
log.warn('EnhancedTable', 'Can not remove this node\'s children, which is not appeared.');
}
console.log('~~~~~', this.treeDataMap);

Check warning on line 291 in js/table/tree-store.ts

View workflow job for this annotation

GitHub Actions / test

Unexpected console statement
return dataSource;
}

/**
* 为当前节点添加子节点,默认添加到最后一个节点。允许添加单个或多个
* @param rowValue 当前节点唯一标识
Expand Down

0 comments on commit 59acd3f

Please sign in to comment.