talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 1 | import React from 'react'; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 2 | import { storiesOf } from '@kadira/storybook'; |
| 3 | import { withKnobs } from '@kadira/storybook-addon-knobs'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 4 | import Tree from './Tree.jsx'; |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 5 | |
| 6 | const stories = storiesOf('Version Tree', module); |
| 7 | stories.addDecorator(withKnobs); |
| 8 | |
| 9 | const response = { |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 10 | listCount: 6, |
| 11 | results: [ |
| 12 | { |
| 13 | id: '123', |
| 14 | name: '1.0', |
| 15 | description: 'string', |
| 16 | baseId: '', |
| 17 | status: 'Draft', |
| 18 | creationTime: '2017-06-08T08:55:37.831Z', |
| 19 | modificationTime: '2017-06-08T08:55:37.831Z' |
| 20 | }, |
| 21 | { |
| 22 | id: '1234', |
| 23 | name: '1.1', |
| 24 | description: 'string', |
| 25 | baseId: '123', |
| 26 | status: 'Draft', |
| 27 | creationTime: '2017-06-08T08:55:37.831Z', |
| 28 | modificationTime: '2017-06-08T08:55:37.831Z' |
| 29 | }, |
| 30 | { |
| 31 | id: '12345', |
| 32 | name: '2.0', |
| 33 | description: 'string', |
| 34 | baseId: '123', |
| 35 | status: 'Draft', |
| 36 | creationTime: '2017-06-08T08:55:37.831Z', |
| 37 | modificationTime: '2017-06-08T08:55:37.831Z' |
| 38 | }, |
| 39 | { |
| 40 | id: '123456', |
| 41 | name: '3.0', |
| 42 | description: 'string', |
| 43 | baseId: '12345', |
| 44 | status: 'Draft', |
| 45 | creationTime: '2017-06-08T08:55:37.831Z', |
| 46 | modificationTime: '2017-06-08T08:55:37.831Z' |
| 47 | }, |
| 48 | { |
| 49 | id: '1234567', |
| 50 | name: '1.2', |
| 51 | description: 'string', |
| 52 | baseId: '1234', |
| 53 | status: 'Draft', |
| 54 | creationTime: '2017-06-08T08:55:37.831Z', |
| 55 | modificationTime: '2017-06-08T08:55:37.831Z' |
| 56 | }, |
| 57 | { |
| 58 | id: '12345678', |
| 59 | name: '2.1', |
| 60 | description: 'string', |
| 61 | baseId: '12345', |
| 62 | status: 'Draft', |
| 63 | creationTime: '2017-06-08T08:55:37.831Z', |
| 64 | modificationTime: '2017-06-08T08:55:37.831Z' |
| 65 | }, |
| 66 | { |
| 67 | id: '123456789', |
| 68 | name: '4.0', |
| 69 | description: 'string', |
| 70 | baseId: '123456', |
| 71 | status: 'Draft', |
| 72 | creationTime: '2017-06-08T08:55:37.831Z', |
| 73 | modificationTime: '2017-06-08T08:55:37.831Z' |
| 74 | }, |
| 75 | { |
| 76 | id: '12345678910', |
| 77 | name: '3.1', |
| 78 | description: 'string', |
| 79 | baseId: '123456', |
| 80 | status: 'Draft', |
| 81 | creationTime: '2017-06-08T08:55:37.831Z', |
| 82 | modificationTime: '2017-06-08T08:55:37.831Z' |
| 83 | } |
| 84 | ] |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 85 | }; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 86 | const divStyle = { |
| 87 | width: '200px', |
| 88 | borderStyle: 'solid', |
| 89 | borderColor: 'black', |
| 90 | border: '1px solid black' |
talig | 8e9c065 | 2017-12-20 14:30:43 +0200 | [diff] [blame] | 91 | }; |
Einav Weiss Keidar | 7fdf733 | 2018-03-20 14:45:40 +0200 | [diff] [blame] | 92 | const tree = response.results.map(item => ({ |
| 93 | id: item.id, |
| 94 | name: item.name, |
| 95 | parent: item.baseId |
| 96 | })); |
| 97 | const nodeClickHandler = function(node) { |
| 98 | window.alert(node.name); |
| 99 | }; |
| 100 | stories |
| 101 | .add('Classic Version Tree', () => ( |
| 102 | <div> |
| 103 | <Tree |
| 104 | nodes={tree} |
| 105 | onNodeClick={nodeClickHandler} |
| 106 | selectedNodeId={'1234'} |
| 107 | /> |
| 108 | </div> |
| 109 | )) |
| 110 | .add('Single Version Tree', () => ( |
| 111 | <div> |
| 112 | <Tree nodes={[tree[0]]} onNodeClick={nodeClickHandler} /> |
| 113 | </div> |
| 114 | )) |
| 115 | .add('Single Path Version Tree', () => ( |
| 116 | <div> |
| 117 | <Tree nodes={[tree[0], tree[1]]} onNodeClick={nodeClickHandler} /> |
| 118 | </div> |
| 119 | )) |
| 120 | .add('Empty Tree', () => ( |
| 121 | <div> |
| 122 | <Tree nodes={[]} /> |
| 123 | </div> |
| 124 | )) |
| 125 | .add('Add Tree in Version Page Frame', () => ( |
| 126 | <div style={divStyle}> |
| 127 | Tree wider than frame<br /> |
| 128 | <br /> |
| 129 | <br /> |
| 130 | <Tree |
| 131 | name={'versions-tree'} |
| 132 | width={200} |
| 133 | nodes={tree} |
| 134 | onRenderedBeyondWidth={() => { |
| 135 | console.log('rendered beyond width'); |
| 136 | }} |
| 137 | allowScaleWidth={false} |
| 138 | onNodeClick={nodeClickHandler} |
| 139 | /> |
| 140 | </div> |
| 141 | )); |