Skip to content

Commit

Permalink
fix: [Tree] fix onChange value error in treeDataSimpleJson mode
Browse files Browse the repository at this point in the history
  • Loading branch information
YyumeiZhang committed Dec 2, 2024
1 parent 782c2fb commit acda2e4
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/semi-foundation/tree/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const cssClasses = {

const strings = {
EXPAND_ACTION: [false, 'click', 'doubleClick'],
JSON_KEY_SPLIT: '_SEMI_TREE_SPLIT_',
};

const numbers = {};
Expand Down
3 changes: 2 additions & 1 deletion packages/semi-foundation/tree/foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
} from './treeUtil';

import type { KeyMapProps } from './treeUtil';
import { strings } from './constants';
export type { KeyMapProps };

export interface BasicTreeNodeProps {
Expand Down Expand Up @@ -415,7 +416,7 @@ export default class TreeFoundation extends BaseFoundation<TreeAdapter, BasicTre

notifyJsonChange(key: string[] | string, e: any) {
const data = this.getProp('treeDataSimpleJson');
const selectedPath = normalizedArr(key).map(i => i.replace('-', '.'));
const selectedPath = normalizedArr(key).map(i => i.replaceAll(strings.JSON_KEY_SPLIT, '.'));
const value = pick(data, selectedPath);
this._adapter.notifyChange(value as BasicValue);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/semi-foundation/tree/treeUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { difference, uniq, max, isObject, isNull, isUndefined, isEmpty, pick, get, omit } from 'lodash';
import { strings } from './constants';

export interface KeyEntities {
[x: string]: any
Expand Down Expand Up @@ -98,7 +99,7 @@ export function convertJsonToData(treeJson: TreeDataSimpleJson) {
const treeData: any[] = [];
const traverseNode = (key: string, children: any, path: any, res: any[]) => {
const currPath = [...path, key];
const itemKey = currPath.join('-');
const itemKey = currPath.join(strings.JSON_KEY_SPLIT);

const newNode: NodeData = {
key: itemKey,
Expand Down
11 changes: 8 additions & 3 deletions packages/semi-ui/tree/_story/tree.stories.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,13 @@ const treeDataWithNode = [

const treeJson = {
Node1: {
Child1: '0-0-1',
Child2: '0-0-2',
Child1: {
child11: '0-0-1',
child12: '0-0-2'
},
Child2: {
child21: '0-1-1',
},
},
Node2: '0-1',
};
Expand Down Expand Up @@ -2937,7 +2942,7 @@ export const KeyMaps = () => {
}, []);

const normalExpanded = useCallback((expandedKeys, { expanded, node }) => {
console.log('onExpanded', expandedKeys, expanded, cloneDeep(node));
console.log('onExpanded', expandedKeys, expanded, copy(node));

}, []);

Expand Down

0 comments on commit acda2e4

Please sign in to comment.