@instructure/ui-tree-browser 7.10.0 → 7.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/es/TreeBrowser/index.js +12 -4
- package/lib/TreeBrowser/index.js +12 -4
- package/package.json +11 -11
- package/src/TreeBrowser/README.md +77 -0
- package/src/TreeBrowser/index.js +26 -15
- package/types/index.d.ts +4 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,24 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [7.14.0](https://github.com/instructure/instructure-ui/compare/v7.13.0...v7.14.0) (2021-12-01)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **ui-tree-browser:** add `sortOrder` property to TreeBrowser component ([9c5d32d](https://github.com/instructure/instructure-ui/commit/9c5d32d))
|
|
11
|
+
|
|
12
|
+
# [7.13.0](https://github.com/instructure/instructure-ui/compare/v7.12.0...v7.13.0) (2021-11-18)
|
|
13
|
+
|
|
14
|
+
**Note:** Version bump only for package @instructure/ui-tree-browser
|
|
15
|
+
|
|
16
|
+
# [7.12.0](https://github.com/instructure/instructure-ui/compare/v7.11.0...v7.12.0) (2021-10-15)
|
|
17
|
+
|
|
18
|
+
**Note:** Version bump only for package @instructure/ui-tree-browser
|
|
19
|
+
|
|
20
|
+
# [7.11.0](https://github.com/instructure/instructure-ui/compare/v7.10.0...v7.11.0) (2021-09-17)
|
|
21
|
+
|
|
22
|
+
**Note:** Version bump only for package @instructure/ui-tree-browser
|
|
23
|
+
|
|
6
24
|
# [7.10.0](https://github.com/instructure/instructure-ui/compare/v7.9.0...v7.10.0) (2021-08-27)
|
|
7
25
|
|
|
8
26
|
**Note:** Version bump only for package @instructure/ui-tree-browser
|
package/es/TreeBrowser/index.js
CHANGED
|
@@ -276,7 +276,7 @@ var TreeBrowser = (_dec = testable(), _dec2 = themeable(theme, styles), _dec(_cl
|
|
|
276
276
|
return _this3.getCollectionProps(_this3.props.collections[id]);
|
|
277
277
|
}).filter(function (collection) {
|
|
278
278
|
return collection != null;
|
|
279
|
-
});
|
|
279
|
+
}).sort(this.props.sortOrder);
|
|
280
280
|
}
|
|
281
281
|
}, {
|
|
282
282
|
key: "getItems",
|
|
@@ -289,7 +289,7 @@ var TreeBrowser = (_dec = testable(), _dec2 = themeable(theme, styles), _dec(_cl
|
|
|
289
289
|
return _objectSpread({}, _this4.props.items[id]);
|
|
290
290
|
}).filter(function (item) {
|
|
291
291
|
return item != null;
|
|
292
|
-
});
|
|
292
|
+
}).sort(this.props.sortOrder);
|
|
293
293
|
} else {
|
|
294
294
|
return [];
|
|
295
295
|
}
|
|
@@ -322,7 +322,7 @@ var TreeBrowser = (_dec = testable(), _dec2 = themeable(theme, styles), _dec(_cl
|
|
|
322
322
|
value: function renderRoot() {
|
|
323
323
|
var _this5 = this;
|
|
324
324
|
|
|
325
|
-
return this.collections.map(function (collection, i) {
|
|
325
|
+
return this.collections.sort(this.props.sortOrder).map(function (collection, i) {
|
|
326
326
|
return /*#__PURE__*/React.createElement(TreeCollection, Object.assign({
|
|
327
327
|
key: i
|
|
328
328
|
}, pickProps(_this5.props, TreeCollection.propTypes), _this5.getCollectionProps(collection), {
|
|
@@ -439,7 +439,12 @@ var TreeBrowser = (_dec = testable(), _dec2 = themeable(theme, styles), _dec(_cl
|
|
|
439
439
|
/**
|
|
440
440
|
* An optional label to assist visually impaired users
|
|
441
441
|
*/
|
|
442
|
-
treeLabel: PropTypes.string
|
|
442
|
+
treeLabel: PropTypes.string,
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* An optional compare function to specify order of the collections and the items
|
|
446
|
+
*/
|
|
447
|
+
sortOrder: PropTypes.func
|
|
443
448
|
}, _class2.defaultProps = {
|
|
444
449
|
size: 'medium',
|
|
445
450
|
variant: 'folderTree',
|
|
@@ -455,6 +460,9 @@ var TreeBrowser = (_dec = testable(), _dec2 = themeable(theme, styles), _dec(_cl
|
|
|
455
460
|
onItemClick: function onItemClick(item) {},
|
|
456
461
|
onCollectionClick: function onCollectionClick(id, collection) {},
|
|
457
462
|
onCollectionToggle: function onCollectionToggle(collection) {},
|
|
463
|
+
sortOrder: function sortOrder(obj1, obj2) {
|
|
464
|
+
return 0;
|
|
465
|
+
},
|
|
458
466
|
rootId: void 0,
|
|
459
467
|
expanded: void 0,
|
|
460
468
|
treeLabel: void 0
|
package/lib/TreeBrowser/index.js
CHANGED
|
@@ -280,7 +280,7 @@ var TreeBrowser = (_dec = (0, _testable.testable)(), _dec2 = (0, _themeable.them
|
|
|
280
280
|
return _this3.getCollectionProps(_this3.props.collections[id]);
|
|
281
281
|
}).filter(function (collection) {
|
|
282
282
|
return collection != null;
|
|
283
|
-
});
|
|
283
|
+
}).sort(this.props.sortOrder);
|
|
284
284
|
}
|
|
285
285
|
}, {
|
|
286
286
|
key: "getItems",
|
|
@@ -293,7 +293,7 @@ var TreeBrowser = (_dec = (0, _testable.testable)(), _dec2 = (0, _themeable.them
|
|
|
293
293
|
return (0, _objectSpread2.default)({}, _this4.props.items[id]);
|
|
294
294
|
}).filter(function (item) {
|
|
295
295
|
return item != null;
|
|
296
|
-
});
|
|
296
|
+
}).sort(this.props.sortOrder);
|
|
297
297
|
} else {
|
|
298
298
|
return [];
|
|
299
299
|
}
|
|
@@ -326,7 +326,7 @@ var TreeBrowser = (_dec = (0, _testable.testable)(), _dec2 = (0, _themeable.them
|
|
|
326
326
|
value: function renderRoot() {
|
|
327
327
|
var _this5 = this;
|
|
328
328
|
|
|
329
|
-
return this.collections.map(function (collection, i) {
|
|
329
|
+
return this.collections.sort(this.props.sortOrder).map(function (collection, i) {
|
|
330
330
|
return /*#__PURE__*/_react.default.createElement(_index.TreeCollection, Object.assign({
|
|
331
331
|
key: i
|
|
332
332
|
}, (0, _pickProps.pickProps)(_this5.props, _index.TreeCollection.propTypes), _this5.getCollectionProps(collection), {
|
|
@@ -442,7 +442,12 @@ var TreeBrowser = (_dec = (0, _testable.testable)(), _dec2 = (0, _themeable.them
|
|
|
442
442
|
/**
|
|
443
443
|
* An optional label to assist visually impaired users
|
|
444
444
|
*/
|
|
445
|
-
treeLabel: _propTypes.default.string
|
|
445
|
+
treeLabel: _propTypes.default.string,
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* An optional compare function to specify order of the collections and the items
|
|
449
|
+
*/
|
|
450
|
+
sortOrder: _propTypes.default.func
|
|
446
451
|
}, _class2.defaultProps = {
|
|
447
452
|
size: 'medium',
|
|
448
453
|
variant: 'folderTree',
|
|
@@ -458,6 +463,9 @@ var TreeBrowser = (_dec = (0, _testable.testable)(), _dec2 = (0, _themeable.them
|
|
|
458
463
|
onItemClick: function onItemClick(item) {},
|
|
459
464
|
onCollectionClick: function onCollectionClick(id, collection) {},
|
|
460
465
|
onCollectionToggle: function onCollectionToggle(collection) {},
|
|
466
|
+
sortOrder: function sortOrder(obj1, obj2) {
|
|
467
|
+
return 0;
|
|
468
|
+
},
|
|
461
469
|
rootId: void 0,
|
|
462
470
|
expanded: void 0,
|
|
463
471
|
treeLabel: void 0
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@instructure/ui-tree-browser",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.14.0",
|
|
4
4
|
"description": "A component for displaying a hierarchical view of information",
|
|
5
5
|
"author": "Instructure, Inc. Engineering and Product Design",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -23,19 +23,19 @@
|
|
|
23
23
|
},
|
|
24
24
|
"license": "MIT",
|
|
25
25
|
"devDependencies": {
|
|
26
|
-
"@instructure/ui-babel-preset": "^7.
|
|
27
|
-
"@instructure/ui-test-locator": "^7.
|
|
28
|
-
"@instructure/ui-test-utils": "^7.
|
|
26
|
+
"@instructure/ui-babel-preset": "^7.14.0",
|
|
27
|
+
"@instructure/ui-test-locator": "^7.14.0",
|
|
28
|
+
"@instructure/ui-test-utils": "^7.14.0"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@babel/runtime": "^7.9.2",
|
|
32
|
-
"@instructure/ui-icons": "^7.
|
|
33
|
-
"@instructure/ui-img": "^7.
|
|
34
|
-
"@instructure/ui-prop-types": "^7.
|
|
35
|
-
"@instructure/ui-react-utils": "^7.
|
|
36
|
-
"@instructure/ui-testable": "^7.
|
|
37
|
-
"@instructure/ui-themeable": "^7.
|
|
38
|
-
"@instructure/ui-utils": "^7.
|
|
32
|
+
"@instructure/ui-icons": "^7.14.0",
|
|
33
|
+
"@instructure/ui-img": "^7.14.0",
|
|
34
|
+
"@instructure/ui-prop-types": "^7.14.0",
|
|
35
|
+
"@instructure/ui-react-utils": "^7.14.0",
|
|
36
|
+
"@instructure/ui-testable": "^7.14.0",
|
|
37
|
+
"@instructure/ui-themeable": "^7.14.0",
|
|
38
|
+
"@instructure/ui-utils": "^7.14.0",
|
|
39
39
|
"classnames": "^2",
|
|
40
40
|
"keycode": "^2",
|
|
41
41
|
"prop-types": "^15"
|
|
@@ -338,6 +338,83 @@ class Example extends React.Component {
|
|
|
338
338
|
render(<Example/>)
|
|
339
339
|
```
|
|
340
340
|
|
|
341
|
+
### Change the order of appearance of items and collection
|
|
342
|
+
|
|
343
|
+
By default, the order of collections and items depend on the order of `collections` and `items` array. We can override it by providing a `sortOrder` comparison function.
|
|
344
|
+
|
|
345
|
+
---
|
|
346
|
+
|
|
347
|
+
**NOTE**
|
|
348
|
+
|
|
349
|
+
This works with all collections and items of the TreeBrowser.
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
353
|
+
```js
|
|
354
|
+
---
|
|
355
|
+
example: true
|
|
356
|
+
render: false
|
|
357
|
+
---
|
|
358
|
+
class Example extends React.Component {
|
|
359
|
+
constructor (props) {
|
|
360
|
+
super(props)
|
|
361
|
+
|
|
362
|
+
this.state = {
|
|
363
|
+
sorted: false
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
toogleSort = (event) => { this.setState({ sorted: !this.state.sorted }) }
|
|
368
|
+
|
|
369
|
+
render () {
|
|
370
|
+
return (
|
|
371
|
+
<>
|
|
372
|
+
<View display="block" margin="none none medium">
|
|
373
|
+
<FormFieldGroup description="Turn of/off sorting">
|
|
374
|
+
<Checkbox
|
|
375
|
+
checked={this.state.sorted}
|
|
376
|
+
label="Sort"
|
|
377
|
+
onChange={this.toogleSort}
|
|
378
|
+
/>
|
|
379
|
+
</FormFieldGroup>
|
|
380
|
+
</View>
|
|
381
|
+
<TreeBrowser
|
|
382
|
+
size="medium"
|
|
383
|
+
collections={{
|
|
384
|
+
1: {
|
|
385
|
+
id: 1,
|
|
386
|
+
name: "Assignments",
|
|
387
|
+
collections: [3,2],
|
|
388
|
+
items: [3],
|
|
389
|
+
descriptor: "Class Assignments"
|
|
390
|
+
},
|
|
391
|
+
2: { id: 2, name: "English Assignments", collections: [4], items: [] },
|
|
392
|
+
3: { id: 3, name: "Math Assignments", collections: [5], items: [2,1] },
|
|
393
|
+
4: { id: 4, name: "Reading Assignments", collections: [], items: [4] },
|
|
394
|
+
5: { id: 5, name: "Advanced Math Assignments", items: [5]}
|
|
395
|
+
}}
|
|
396
|
+
items={{
|
|
397
|
+
1: { id: 1, name: "Addition Worksheet" },
|
|
398
|
+
2: { id: 2, name: "Subtraction Worksheet" },
|
|
399
|
+
3: { id: 3, name: "General Questions" },
|
|
400
|
+
4: { id: 4, name: "Vogon Poetry" },
|
|
401
|
+
5: { id: 5, name: "Bistromath", descriptor: "Explain the Bistromathic Drive" }
|
|
402
|
+
}}
|
|
403
|
+
defaultExpanded={[1, 3]}
|
|
404
|
+
rootId={1}
|
|
405
|
+
sortOrder={
|
|
406
|
+
this.state.sorted
|
|
407
|
+
? (a,b)=>{ return (a.name).localeCompare(b.name) }
|
|
408
|
+
: (a,b) => { return 0 }
|
|
409
|
+
}
|
|
410
|
+
/>
|
|
411
|
+
</>
|
|
412
|
+
)
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
render(<Example/>)
|
|
416
|
+
```
|
|
417
|
+
|
|
341
418
|
### showRootCollection
|
|
342
419
|
|
|
343
420
|
The `showRootCollection` prop sets whether the root collection (specified in `rootId` prop) is displayed or to begin with its immediate sub-collections and items instead. It defaults to `true`.
|
package/src/TreeBrowser/index.js
CHANGED
|
@@ -111,7 +111,11 @@ class TreeBrowser extends Component {
|
|
|
111
111
|
/**
|
|
112
112
|
* An optional label to assist visually impaired users
|
|
113
113
|
*/
|
|
114
|
-
treeLabel: PropTypes.string
|
|
114
|
+
treeLabel: PropTypes.string,
|
|
115
|
+
/**
|
|
116
|
+
* An optional compare function to specify order of the collections and the items
|
|
117
|
+
*/
|
|
118
|
+
sortOrder: PropTypes.func
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
static defaultProps = {
|
|
@@ -127,6 +131,9 @@ class TreeBrowser extends Component {
|
|
|
127
131
|
onItemClick: function (item) {},
|
|
128
132
|
onCollectionClick: function (id, collection) {},
|
|
129
133
|
onCollectionToggle: function (collection) {},
|
|
134
|
+
sortOrder: function (obj1, obj2) {
|
|
135
|
+
return 0
|
|
136
|
+
},
|
|
130
137
|
rootId: undefined,
|
|
131
138
|
expanded: undefined,
|
|
132
139
|
treeLabel: undefined
|
|
@@ -326,6 +333,7 @@ class TreeBrowser extends Component {
|
|
|
326
333
|
return collections
|
|
327
334
|
.map((id) => this.getCollectionProps(this.props.collections[id]))
|
|
328
335
|
.filter((collection) => collection != null)
|
|
336
|
+
.sort(this.props.sortOrder)
|
|
329
337
|
}
|
|
330
338
|
|
|
331
339
|
getItems(collection) {
|
|
@@ -337,6 +345,7 @@ class TreeBrowser extends Component {
|
|
|
337
345
|
return { ...this.props.items[id] }
|
|
338
346
|
})
|
|
339
347
|
.filter((item) => item != null)
|
|
348
|
+
.sort(this.props.sortOrder)
|
|
340
349
|
} else {
|
|
341
350
|
return []
|
|
342
351
|
}
|
|
@@ -371,20 +380,22 @@ class TreeBrowser extends Component {
|
|
|
371
380
|
}
|
|
372
381
|
|
|
373
382
|
renderRoot() {
|
|
374
|
-
return this.collections
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
383
|
+
return this.collections
|
|
384
|
+
.sort(this.props.sortOrder)
|
|
385
|
+
.map((collection, i) => (
|
|
386
|
+
<TreeCollection
|
|
387
|
+
key={i}
|
|
388
|
+
{...pickProps(this.props, TreeCollection.propTypes)}
|
|
389
|
+
{...this.getCollectionProps(collection)}
|
|
390
|
+
selection={this.state.selection}
|
|
391
|
+
onItemClick={this.handleItemClick}
|
|
392
|
+
onCollectionClick={this.handleCollectionClick}
|
|
393
|
+
onKeyDown={this.handleKeyDown}
|
|
394
|
+
numChildren={this.collections.length}
|
|
395
|
+
level={1}
|
|
396
|
+
position={1}
|
|
397
|
+
/>
|
|
398
|
+
))
|
|
388
399
|
}
|
|
389
400
|
|
|
390
401
|
render() {
|
package/types/index.d.ts
CHANGED
|
@@ -69,6 +69,10 @@ export interface TreeBrowserProps {
|
|
|
69
69
|
* An optional label to assist visually impaired users
|
|
70
70
|
*/
|
|
71
71
|
treeLabel?: string;
|
|
72
|
+
/**
|
|
73
|
+
* An optional compare function to specify order of the collections and the items
|
|
74
|
+
*/
|
|
75
|
+
sortOrder?: (...args: any[])=>any;
|
|
72
76
|
}
|
|
73
77
|
|
|
74
78
|
export class TreeBrowser extends React.Component<TreeBrowserProps, any> {
|