Skip to content

Commit fd0de93

Browse files
ellingemrchief
authored andcommitted
fix: Updated onAction to bubble up custom props (#230)
BREAKING CHANGE: Action Changes - The option to pass a local `onAction` handler on a node is now removed. Use the **global** `onAction` event instead. ```jsx <DropdownTreeSelect onAction={onAction} ... /> ``` - `onAction` signature is now consistent with signature for other event handlers such `onChange` and `onNodeToggle` ```js // before onAction = ({ action, id }) => { console.log(action, id) } // after onAction = (node, action) => { console.log(action, node.id) } ``` - Any custom props passed to `node` or `action` is accessible in the event properties. This will make it easier to add generic custom logic based on your custom data/properties which can be used instead of separate handlers. For example: ```js // node with action and custom props { id: 'mynode', propA: 'hello', propB: true, actions: [ { id: 'myaction', propX: {...}, propY: 12 } ] } onAction = (node, action) => { console.log(node.propA, node.propB, action.propX, action.propY) // prints hello true {...} 12 } ```
1 parent 071e7f5 commit fd0de93

File tree

16 files changed

+70
-30
lines changed

16 files changed

+70
-30
lines changed

.github/prlint.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"title": [
33
{
4-
"pattern": "^(feat|fix|docs|style|refactor|perf|test|chore|BREAKING CHANGE):\\s",
4+
"pattern": "^(feat|fix|docs|style|refactor|perf|test|chore):\\s",
55
"flags": ["i"],
66
"message": "PR title doesn't match conventional commit message specs. See https://conventionalcommits.org/"
77
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ const data = {
158158
const onChange = (currentNode, selectedNodes) => {
159159
console.log('onChange::', currentNode, selectedNodes)
160160
}
161-
const onAction = ({ action, id }) => {
162-
console.log(`onAction:: [${action}]`, id)
161+
const onAction = (node, action) => {
162+
console.log('onAction::', action, node)
163163
}
164164
const onNodeToggle = currentNode => {
165165
console.log('onNodeToggle::', currentNode)
@@ -228,8 +228,8 @@ Type: `function`
228228
Fires when a action is triggered. Example:
229229

230230
```jsx
231-
function onAction({ action, id }) {
232-
console.log(`onAction:: [${action}]`, id)
231+
function onAction(node, action) {
232+
console.log('onAction::', action, node)
233233
}
234234

235235
return <DropdownTreeSelect data={data} onAction={onAction} />

__snapshots__/src/index.test.js.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ Generated by [AVA](https://ava.li).
4343
],
4444
_depth: 0,
4545
_id: 'rdts-0',
46+
actions: [
47+
{
48+
className: 'fa fa-ban',
49+
id: 'NOT',
50+
title: 'NOT',
51+
},
52+
],
4653
children: undefined,
4754
label: 'item1',
4855
value: 'value1',
@@ -193,6 +200,13 @@ Generated by [AVA](https://ava.li).
193200
data={
194201
[
195202
{
203+
actions: [
204+
{
205+
className: 'fa fa-ban',
206+
id: 'NOT',
207+
title: 'NOT',
208+
},
209+
],
196210
children: [
197211
{
198212
children: [
@@ -322,6 +336,13 @@ Generated by [AVA](https://ava.li).
322336
data={
323337
[
324338
{
339+
actions: [
340+
{
341+
className: 'fa fa-ban',
342+
id: 'NOT',
343+
title: 'NOT',
344+
},
345+
],
325346
children: [
326347
{
327348
children: [
@@ -479,6 +500,13 @@ Generated by [AVA](https://ava.li).
479500
],
480501
_depth: 0,
481502
_id: 'rdts-0',
503+
actions: [
504+
{
505+
className: 'fa fa-ban',
506+
id: 'NOT',
507+
title: 'NOT',
508+
},
509+
],
482510
children: undefined,
483511
label: 'item1',
484512
value: 'value1',
157 Bytes
Binary file not shown.

__snapshots__/src/tree-node/actions.test.js.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,14 @@ Generated by [AVA](https://ava.li).
1111
<Action
1212
actionData={
1313
{
14-
action: 'action-0',
15-
id: 'snapshot',
14+
action: {
15+
className: 'cn0-0-0',
16+
id: 'action-0',
17+
junk: '1',
18+
text: 'hello',
19+
title: 'action',
20+
},
21+
nodeId: 'snapshot',
1622
}
1723
}
1824
className="cn0-0-0"
46 Bytes
Binary file not shown.

docs/src/stories/BigData/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import bigData from './big-data.json'
88
const onChange = (curNode, selectedNodes) => {
99
console.log('onChange::', curNode, selectedNodes)
1010
}
11-
const onAction = ({ action, id }) => {
12-
console.log(`onAction:: [${action}]`, id)
11+
const onAction = (node, action) => {
12+
console.log('onAction::', action, node)
1313
}
1414
const onNodeToggle = curNode => {
1515
console.log('onNodeToggle::', curNode)

docs/src/stories/DefaultValues/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import data from './data.json'
99
const onChange = (curNode, selectedNodes) => {
1010
console.log('onChange::', curNode, selectedNodes)
1111
}
12-
const onAction = ({ action, id }) => {
13-
console.log(`onAction:: [${action}]`, id)
12+
const onAction = (node, action) => {
13+
console.log('onAction::', action, node)
1414
}
1515
const onNodeToggle = curNode => {
1616
console.log('onNodeToggle::', curNode)

docs/src/stories/Options/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class WithOptions extends PureComponent {
2626
onChange = (curNode, selectedNodes) => {
2727
console.log('onChange::', curNode, selectedNodes)
2828
}
29-
onAction = ({ action, id }) => {
30-
console.log(`onAction:: [${action}]`, id)
29+
onAction = (node, action) => {
30+
console.log('onAction::', action, node)
3131
}
3232
onNodeToggle = curNode => {
3333
console.log('onNodeToggle::', curNode)

docs/src/stories/Simple/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import data from './data.json'
88
const onChange = (curNode, selectedNodes) => {
99
console.log('onChange::', curNode, selectedNodes)
1010
}
11-
const onAction = ({ action, id }) => {
12-
console.log(`onAction:: [${action}]`, id)
11+
const onAction = (node, action) => {
12+
console.log('onAction::', action, node)
1313
}
1414
const onNodeToggle = curNode => {
1515
console.log('onNodeToggle::', curNode)

0 commit comments

Comments
 (0)