@instructure/ui-tree-browser 8.12.1-snapshot.7 → 8.13.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 CHANGED
@@ -3,6 +3,12 @@
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
+ # [8.13.0](https://github.com/instructure/instructure-ui/compare/v8.12.0...v8.13.0) (2021-12-01)
7
+
8
+ ### Features
9
+
10
+ - add 'sortOrder' property to TreeBrowser component ([e669e54](https://github.com/instructure/instructure-ui/pull/776/commits/e669e5405864b26c6f98b378e11cef6603fcca58))
11
+
6
12
  # [8.12.0](https://github.com/instructure/instructure-ui/compare/v8.11.1...v8.12.0) (2021-11-17)
7
13
 
8
14
  **Note:** Version bump only for package @instructure/ui-tree-browser
@@ -26,10 +26,10 @@ import { TreeBrowser } from './index'; // TODO: if we make a TreeBrowserItem com
26
26
 
27
27
  const TreeBrowserItemLocator = locator('[role="treeitem"]');
28
28
  export const TreeBrowserLocator = locator(TreeBrowser.selector, {
29
- findAllItems: (...args) => {
30
- return TreeBrowserItemLocator.findAll(...args);
29
+ findAllItems: function () {
30
+ return TreeBrowserItemLocator.findAll(...arguments);
31
31
  },
32
- findItem: (...args) => {
33
- return TreeBrowserItemLocator.find(...args);
32
+ findItem: function () {
33
+ return TreeBrowserItemLocator.find(...arguments);
34
34
  }
35
35
  });
@@ -42,8 +42,8 @@ id: TreeBrowser.Button
42
42
  // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
43
43
 
44
44
  let TreeButton = (_dec = withStyle(generateStyles, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeButton extends Component {
45
- constructor(...args) {
46
- super(...args);
45
+ constructor() {
46
+ super(...arguments);
47
47
  this.ref = null;
48
48
 
49
49
  this.handleRef = el => {
@@ -45,8 +45,8 @@ in the TreeBrowser.
45
45
  // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
46
46
 
47
47
  let TreeNode = (_dec = withStyle(generateStyles, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeNode extends Component {
48
- constructor(...args) {
49
- super(...args);
48
+ constructor() {
49
+ super(...arguments);
50
50
  this.ref = null;
51
51
 
52
52
  this.handleRef = el => {
@@ -45,16 +45,20 @@ category: components
45
45
 
46
46
  let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _dec2 = testable(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeBrowser extends Component {
47
47
  constructor(props) {
48
+ var _this;
49
+
48
50
  super(props);
51
+ _this = this;
49
52
  this.ref = null;
50
53
 
51
- this.handleCollectionClick = (e, collection, expand = true) => {
54
+ this.handleCollectionClick = function (e, collection) {
55
+ let expand = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
52
56
  e.stopPropagation();
53
- const onCollectionClick = this.props.onCollectionClick;
54
- if (expand) this.expandOrCollapseNode(collection);
57
+ const onCollectionClick = _this.props.onCollectionClick;
58
+ if (expand) _this.expandOrCollapseNode(collection);
55
59
  onCollectionClick(collection.id, collection); // TODO: this should pass the event as the first arg
56
60
 
57
- this.handleSelection(collection.id, 'collection');
61
+ _this.handleSelection(collection.id, 'collection');
58
62
  };
59
63
 
60
64
  this.handleItemClick = (e, item) => {
@@ -259,7 +263,7 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
259
263
 
260
264
  getSubCollections(collection) {
261
265
  const collections = [].concat(collection.collections || []);
262
- return collections.map(id => this.getCollectionProps(this.props.collections[id])).filter(collection => collection != null);
266
+ return collections.map(id => this.getCollectionProps(this.props.collections[id])).filter(collection => collection != null).sort(this.props.sortOrder);
263
267
  }
264
268
 
265
269
  getItems(collection) {
@@ -268,7 +272,7 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
268
272
  return items.map(id => {
269
273
  return { ...this.props.items[id]
270
274
  };
271
- }).filter(item => item != null);
275
+ }).filter(item => item != null).sort(this.props.sortOrder);
272
276
  } else {
273
277
  return [];
274
278
  }
@@ -294,7 +298,7 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
294
298
  }
295
299
 
296
300
  renderRoot() {
297
- return this.collections.map((collection, i) => jsx(TreeCollection, Object.assign({
301
+ return this.collections.sort(this.props.sortOrder).map((collection, i) => jsx(TreeCollection, Object.assign({
298
302
  key: i
299
303
  }, pickProps(omitProps(this.props), TreeCollection.allowedProps), this.getCollectionProps(collection), {
300
304
  selection: this.state.selection,
@@ -335,7 +339,10 @@ let TreeBrowser = (_dec = withStyle(generateStyles, generateComponentTheme), _de
335
339
  selectionType: 'none',
336
340
  onItemClick: function (item) {},
337
341
  onCollectionClick: function (id, collection) {},
338
- onCollectionToggle: function (collection) {}
342
+ onCollectionToggle: function (collection) {},
343
+ sortOrder: function (obj1, obj2) {
344
+ return 0;
345
+ }
339
346
  }, _class2.Node = TreeNode, _class2.Collection = TreeCollection, _class2.Button = TreeButton, _temp)) || _class) || _class);
340
347
  export default TreeBrowser;
341
348
  export { TreeBrowser };
@@ -93,7 +93,12 @@ const propTypes = {
93
93
  * An optional label to assist visually impaired users
94
94
  */
95
95
  treeLabel: PropTypes.string,
96
- renderContent: PropTypes.func
96
+ renderContent: PropTypes.func,
97
+
98
+ /**
99
+ * An optional compare function to specify order of the collections and the items
100
+ */
101
+ sortOrder: PropTypes.func
97
102
  };
98
- const allowedProps = ['collections', 'items', 'rootId', 'expanded', 'defaultExpanded', 'selectionType', 'size', 'variant', 'collectionIcon', 'collectionIconExpanded', 'itemIcon', 'getItemProps', 'getCollectionProps', 'showRootCollection', 'onCollectionClick', 'onCollectionToggle', 'onItemClick', 'treeLabel', 'renderContent'];
103
+ const allowedProps = ['collections', 'items', 'rootId', 'expanded', 'defaultExpanded', 'selectionType', 'size', 'variant', 'collectionIcon', 'collectionIconExpanded', 'itemIcon', 'getItemProps', 'getCollectionProps', 'showRootCollection', 'onCollectionClick', 'onCollectionToggle', 'onItemClick', 'treeLabel', 'renderContent', 'sortOrder'];
99
104
  export { propTypes, allowedProps };
@@ -35,11 +35,11 @@ var _index = require("./index");
35
35
  // TODO: if we make a TreeBrowserItem component + locator we could use it here.
36
36
  const TreeBrowserItemLocator = (0, _locator.locator)('[role="treeitem"]');
37
37
  const TreeBrowserLocator = (0, _locator.locator)(_index.TreeBrowser.selector, {
38
- findAllItems: (...args) => {
39
- return TreeBrowserItemLocator.findAll(...args);
38
+ findAllItems: function () {
39
+ return TreeBrowserItemLocator.findAll(...arguments);
40
40
  },
41
- findItem: (...args) => {
42
- return TreeBrowserItemLocator.find(...args);
41
+ findItem: function () {
42
+ return TreeBrowserItemLocator.find(...arguments);
43
43
  }
44
44
  });
45
45
  exports.TreeBrowserLocator = TreeBrowserLocator;
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.TreeButton = exports.default = void 0;
8
+ exports.default = exports.TreeButton = void 0;
9
9
 
10
10
  var _react = require("react");
11
11
 
@@ -33,8 +33,8 @@ id: TreeBrowser.Button
33
33
  **/
34
34
  // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
35
35
  let TreeButton = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeButton extends _react.Component {
36
- constructor(...args) {
37
- super(...args);
36
+ constructor() {
37
+ super(...arguments);
38
38
  this.ref = null;
39
39
 
40
40
  this.handleRef = el => {
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.allowedProps = exports.propTypes = void 0;
8
+ exports.propTypes = exports.allowedProps = void 0;
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
@@ -7,7 +7,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports.TreeCollection = exports.default = void 0;
10
+ exports.default = exports.TreeCollection = void 0;
11
11
 
12
12
  var _react = _interopRequireWildcard(require("react"));
13
13
 
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.allowedProps = exports.propTypes = void 0;
8
+ exports.propTypes = exports.allowedProps = void 0;
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.TreeNode = exports.default = void 0;
8
+ exports.default = exports.TreeNode = void 0;
9
9
 
10
10
  var _react = require("react");
11
11
 
@@ -35,8 +35,8 @@ in the TreeBrowser.
35
35
  **/
36
36
  // Todo: merge TreeButton and TreeNode: TreeButton should be a special type of TreeNode
37
37
  let TreeNode = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeNode extends _react.Component {
38
- constructor(...args) {
39
- super(...args);
38
+ constructor() {
39
+ super(...arguments);
40
40
  this.ref = null;
41
41
 
42
42
  this.handleRef = el => {
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.allowedProps = exports.propTypes = void 0;
8
+ exports.propTypes = exports.allowedProps = void 0;
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.TreeBrowser = exports.default = void 0;
8
+ exports.default = exports.TreeBrowser = void 0;
9
9
 
10
10
  var _react = require("react");
11
11
 
@@ -44,16 +44,20 @@ category: components
44
44
  **/
45
45
  let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.default), _dec2 = (0, _testable.testable)(), _dec(_class = _dec2(_class = (_temp = _class2 = class TreeBrowser extends _react.Component {
46
46
  constructor(props) {
47
+ var _this;
48
+
47
49
  super(props);
50
+ _this = this;
48
51
  this.ref = null;
49
52
 
50
- this.handleCollectionClick = (e, collection, expand = true) => {
53
+ this.handleCollectionClick = function (e, collection) {
54
+ let expand = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true;
51
55
  e.stopPropagation();
52
- const onCollectionClick = this.props.onCollectionClick;
53
- if (expand) this.expandOrCollapseNode(collection);
56
+ const onCollectionClick = _this.props.onCollectionClick;
57
+ if (expand) _this.expandOrCollapseNode(collection);
54
58
  onCollectionClick(collection.id, collection); // TODO: this should pass the event as the first arg
55
59
 
56
- this.handleSelection(collection.id, 'collection');
60
+ _this.handleSelection(collection.id, 'collection');
57
61
  };
58
62
 
59
63
  this.handleItemClick = (e, item) => {
@@ -258,7 +262,7 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
258
262
 
259
263
  getSubCollections(collection) {
260
264
  const collections = [].concat(collection.collections || []);
261
- return collections.map(id => this.getCollectionProps(this.props.collections[id])).filter(collection => collection != null);
265
+ return collections.map(id => this.getCollectionProps(this.props.collections[id])).filter(collection => collection != null).sort(this.props.sortOrder);
262
266
  }
263
267
 
264
268
  getItems(collection) {
@@ -267,7 +271,7 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
267
271
  return items.map(id => {
268
272
  return { ...this.props.items[id]
269
273
  };
270
- }).filter(item => item != null);
274
+ }).filter(item => item != null).sort(this.props.sortOrder);
271
275
  } else {
272
276
  return [];
273
277
  }
@@ -293,7 +297,7 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
293
297
  }
294
298
 
295
299
  renderRoot() {
296
- return this.collections.map((collection, i) => (0, _emotion.jsx)(_TreeCollection.TreeCollection, Object.assign({
300
+ return this.collections.sort(this.props.sortOrder).map((collection, i) => (0, _emotion.jsx)(_TreeCollection.TreeCollection, Object.assign({
297
301
  key: i
298
302
  }, (0, _pickProps.pickProps)((0, _omitProps.omitProps)(this.props), _TreeCollection.TreeCollection.allowedProps), this.getCollectionProps(collection), {
299
303
  selection: this.state.selection,
@@ -334,7 +338,10 @@ let TreeBrowser = (_dec = (0, _emotion.withStyle)(_styles.default, _theme.defaul
334
338
  selectionType: 'none',
335
339
  onItemClick: function (item) {},
336
340
  onCollectionClick: function (id, collection) {},
337
- onCollectionToggle: function (collection) {}
341
+ onCollectionToggle: function (collection) {},
342
+ sortOrder: function (obj1, obj2) {
343
+ return 0;
344
+ }
338
345
  }, _class2.Node = _TreeNode.TreeNode, _class2.Collection = _TreeCollection.TreeCollection, _class2.Button = _TreeButton.TreeButton, _temp)) || _class) || _class);
339
346
  exports.TreeBrowser = TreeBrowser;
340
347
  var _default = TreeBrowser;
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.allowedProps = exports.propTypes = void 0;
8
+ exports.propTypes = exports.allowedProps = void 0;
9
9
 
10
10
  var _propTypes = _interopRequireDefault(require("prop-types"));
11
11
 
@@ -104,8 +104,13 @@ const propTypes = {
104
104
  * An optional label to assist visually impaired users
105
105
  */
106
106
  treeLabel: _propTypes.default.string,
107
- renderContent: _propTypes.default.func
107
+ renderContent: _propTypes.default.func,
108
+
109
+ /**
110
+ * An optional compare function to specify order of the collections and the items
111
+ */
112
+ sortOrder: _propTypes.default.func
108
113
  };
109
114
  exports.propTypes = propTypes;
110
- const allowedProps = ['collections', 'items', 'rootId', 'expanded', 'defaultExpanded', 'selectionType', 'size', 'variant', 'collectionIcon', 'collectionIconExpanded', 'itemIcon', 'getItemProps', 'getCollectionProps', 'showRootCollection', 'onCollectionClick', 'onCollectionToggle', 'onItemClick', 'treeLabel', 'renderContent'];
115
+ const allowedProps = ['collections', 'items', 'rootId', 'expanded', 'defaultExpanded', 'selectionType', 'size', 'variant', 'collectionIcon', 'collectionIconExpanded', 'itemIcon', 'getItemProps', 'getCollectionProps', 'showRootCollection', 'onCollectionClick', 'onCollectionToggle', 'onItemClick', 'treeLabel', 'renderContent', 'sortOrder'];
111
116
  exports.allowedProps = allowedProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-tree-browser",
3
- "version": "8.12.1-snapshot.7+1e7ac8219",
3
+ "version": "8.13.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",
@@ -24,22 +24,22 @@
24
24
  },
25
25
  "license": "MIT",
26
26
  "devDependencies": {
27
- "@instructure/ui-babel-preset": "8.12.1-snapshot.7+1e7ac8219",
28
- "@instructure/ui-color-utils": "8.12.1-snapshot.7+1e7ac8219",
29
- "@instructure/ui-test-locator": "8.12.1-snapshot.7+1e7ac8219",
30
- "@instructure/ui-test-utils": "8.12.1-snapshot.7+1e7ac8219",
31
- "@instructure/ui-themes": "8.12.1-snapshot.7+1e7ac8219"
27
+ "@instructure/ui-babel-preset": "8.13.0",
28
+ "@instructure/ui-color-utils": "8.13.0",
29
+ "@instructure/ui-test-locator": "8.13.0",
30
+ "@instructure/ui-test-utils": "8.13.0",
31
+ "@instructure/ui-themes": "8.13.0"
32
32
  },
33
33
  "dependencies": {
34
34
  "@babel/runtime": "^7.13.10",
35
- "@instructure/emotion": "8.12.1-snapshot.7+1e7ac8219",
36
- "@instructure/shared-types": "8.12.1-snapshot.7+1e7ac8219",
37
- "@instructure/ui-icons": "8.12.1-snapshot.7+1e7ac8219",
38
- "@instructure/ui-img": "8.12.1-snapshot.7+1e7ac8219",
39
- "@instructure/ui-prop-types": "8.12.1-snapshot.7+1e7ac8219",
40
- "@instructure/ui-react-utils": "8.12.1-snapshot.7+1e7ac8219",
41
- "@instructure/ui-testable": "8.12.1-snapshot.7+1e7ac8219",
42
- "@instructure/ui-utils": "8.12.1-snapshot.7+1e7ac8219",
35
+ "@instructure/emotion": "8.13.0",
36
+ "@instructure/shared-types": "8.13.0",
37
+ "@instructure/ui-icons": "8.13.0",
38
+ "@instructure/ui-img": "8.13.0",
39
+ "@instructure/ui-prop-types": "8.13.0",
40
+ "@instructure/ui-react-utils": "8.13.0",
41
+ "@instructure/ui-testable": "8.13.0",
42
+ "@instructure/ui-utils": "8.13.0",
43
43
  "keycode": "^2",
44
44
  "prop-types": "^15"
45
45
  },
@@ -49,6 +49,5 @@
49
49
  "publishConfig": {
50
50
  "access": "public"
51
51
  },
52
- "sideEffects": false,
53
- "gitHead": "1e7ac821932a91fe9ef761c96f747c7ea1f3925a"
52
+ "sideEffects": false
54
53
  }
@@ -381,6 +381,80 @@ class Example extends React.Component {
381
381
  render(<Example/>)
382
382
  ```
383
383
 
384
+ ### Change the order of appearance of items and collection
385
+
386
+ 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.
387
+
388
+ ---
389
+
390
+ **NOTE**
391
+
392
+ This works with all collections and items of the TreeBrowser.
393
+
394
+ ---
395
+
396
+ ```js
397
+ ---
398
+ example: true
399
+ render: false
400
+ ---
401
+ class Example extends React.Component {
402
+ constructor (props) {
403
+ super(props)
404
+ this.state = {
405
+ size: 'medium',
406
+ sorted: false
407
+ }
408
+ }
409
+ toogleSort = (event)=>{ this.setState({sorted:!this.state.sorted}) }
410
+ render () {
411
+ return (
412
+ <>
413
+ <View display="block" margin="none none medium">
414
+ <FormFieldGroup description="Turn of/off sorting">
415
+ <Checkbox
416
+ checked={this.state.sorted}
417
+ label="Sort"
418
+ onChange={this.toogleSort}
419
+ />
420
+ </FormFieldGroup>
421
+ </View>
422
+
423
+ <TreeBrowser
424
+ size={this.state.size}
425
+ collections={{
426
+ 1: {
427
+ id: 1,
428
+ name: "Assignments",
429
+ collections: [3,2],
430
+ items: [3],
431
+ descriptor: "Class Assignments"
432
+ },
433
+ 2: { id: 2, name: "English Assignments", collections: [4], items: [] },
434
+ 3: { id: 3, name: "Math Assignments", collections: [5], items: [2,1] },
435
+ 4: { id: 4, name: "Reading Assignments", collections: [], items: [4] },
436
+ 5: { id: 5, name: "Advanced Math Assignments", items: [5]}
437
+ }}
438
+ items={{
439
+ 1: { id: 1, name: "Addition Worksheet" },
440
+ 2: { id: 2, name: "Subtraction Worksheet" },
441
+ 3: { id: 3, name: "General Questions" },
442
+ 4: { id: 4, name: "Vogon Poetry" },
443
+ 5: { id: 5, name: "Bistromath", descriptor: "Explain the Bistromathic Drive" }
444
+ }}
445
+ defaultExpanded={[1, 3]}
446
+ rootId={1}
447
+ sortOrder={this.state.sorted? (a,b)=>{return(a.name).localeCompare(b.name)}: (a,b)=>{return 0} }
448
+ />
449
+ </>
450
+ )
451
+ }
452
+ }
453
+
454
+ render(<Example/>)
455
+
456
+ ```
457
+
384
458
  ### showRootCollection
385
459
 
386
460
  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`.
@@ -73,7 +73,11 @@ class TreeBrowser extends Component<TreeBrowserProps> {
73
73
  // @ts-expect-error ts-migrate(6133) FIXME: 'id' is declared but its value is never read.
74
74
  onCollectionClick: function (id, collection) {},
75
75
  // @ts-expect-error ts-migrate(6133) FIXME: 'collection' is declared but its value is never re... Remove this comment to see the full error message
76
- onCollectionToggle: function (collection) {}
76
+ onCollectionToggle: function (collection) {},
77
+ // @ts-expect-error ts-migrate(6133) FIXME: 'foo' and 'bar' are declared but their values are never read.
78
+ sortOrder: function (obj1, obj2) {
79
+ return 0
80
+ }
77
81
  }
78
82
 
79
83
  static Node = TreeNode
@@ -309,6 +313,7 @@ class TreeBrowser extends Component<TreeBrowserProps> {
309
313
  return collections
310
314
  .map((id) => this.getCollectionProps(this.props.collections[id]))
311
315
  .filter((collection) => collection != null)
316
+ .sort(this.props.sortOrder)
312
317
  }
313
318
 
314
319
  // @ts-expect-error ts-migrate(7006) FIXME: Parameter 'collection' implicitly has an 'any' typ... Remove this comment to see the full error message
@@ -321,6 +326,7 @@ class TreeBrowser extends Component<TreeBrowserProps> {
321
326
  return { ...this.props.items[id] }
322
327
  })
323
328
  .filter((item) => item != null)
329
+ .sort(this.props.sortOrder)
324
330
  } else {
325
331
  return []
326
332
  }
@@ -359,7 +365,7 @@ class TreeBrowser extends Component<TreeBrowserProps> {
359
365
  }
360
366
 
361
367
  renderRoot() {
362
- return this.collections.map((collection, i) => (
368
+ return this.collections.sort(this.props.sortOrder).map((collection, i) => (
363
369
  <TreeCollection
364
370
  key={i}
365
371
  // @ts-expect-error ts-migrate(2554) FIXME: Expected 3 arguments, but got 2.
@@ -52,6 +52,7 @@ type TreeBrowserOwnProps = {
52
52
  onItemClick?: (...args: any[]) => any
53
53
  treeLabel?: string
54
54
  renderContent?: (...args: any[]) => any
55
+ sortOrder?: (obj1: any, obj2: any) => number
55
56
  }
56
57
 
57
58
  type PropKeys = keyof TreeBrowserOwnProps
@@ -134,7 +135,11 @@ const propTypes: PropValidators<PropKeys> = {
134
135
  * An optional label to assist visually impaired users
135
136
  */
136
137
  treeLabel: PropTypes.string,
137
- renderContent: PropTypes.func
138
+ renderContent: PropTypes.func,
139
+ /**
140
+ * An optional compare function to specify order of the collections and the items
141
+ */
142
+ sortOrder: PropTypes.func
138
143
  }
139
144
 
140
145
  const allowedProps: AllowedPropKeys = [
@@ -156,7 +161,8 @@ const allowedProps: AllowedPropKeys = [
156
161
  'onCollectionToggle',
157
162
  'onItemClick',
158
163
  'treeLabel',
159
- 'renderContent'
164
+ 'renderContent',
165
+ 'sortOrder'
160
166
  ]
161
167
 
162
168
  export type { TreeBrowserProps, TreeBrowserStyle }
@@ -33,6 +33,7 @@ declare class TreeBrowser extends Component<TreeBrowserProps> {
33
33
  onItemClick?: ((...args: any[]) => any) | undefined;
34
34
  treeLabel?: string | undefined;
35
35
  renderContent?: ((...args: any[]) => any) | undefined;
36
+ sortOrder?: ((obj1: any, obj2: any) => number) | undefined;
36
37
  })[];
37
38
  static propTypes: import("@instructure/shared-types/types/UtilityTypes").PropValidators<keyof {
38
39
  collections: any;
@@ -54,6 +55,7 @@ declare class TreeBrowser extends Component<TreeBrowserProps> {
54
55
  onItemClick?: ((...args: any[]) => any) | undefined;
55
56
  treeLabel?: string | undefined;
56
57
  renderContent?: ((...args: any[]) => any) | undefined;
58
+ sortOrder?: ((obj1: any, obj2: any) => number) | undefined;
57
59
  }>;
58
60
  static defaultProps: {
59
61
  size: string;
@@ -69,6 +71,7 @@ declare class TreeBrowser extends Component<TreeBrowserProps> {
69
71
  onItemClick: (item: any) => void;
70
72
  onCollectionClick: (id: any, collection: any) => void;
71
73
  onCollectionToggle: (collection: any) => void;
74
+ sortOrder: (obj1: any, obj2: any) => number;
72
75
  };
73
76
  static Node: typeof TreeNode;
74
77
  static Collection: typeof TreeCollection;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/TreeBrowser/index.tsx"],"names":[],"mappings":"AAwBA,eAAe;AAEf,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGjC,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AAIxE,OAAO,EAAa,GAAG,EAAE,MAAM,sBAAsB,CAAA;AAErD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAIrC,OAAO,KAAK,EAAE,g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AA;IAcxB,iBAAiB;IAKjB,SAAS,CAAC,KAAK,KAAA;IAoBf,SAAS,CAAC,OAAO,KAAA;IAUjB,sBAAsB,CAAC,OAAO,KAAA,EAAE,IAAI,KAAA;IAgBpC,gBAAgB,CAAC,IAAI,KAAA;IAarB,qBAAqB,CAAC,IAAI,KAAA;IAS1B,gBAAgB,CAAC,KAAK,KAAA,EAAE,IAAI,KAAA;IAc5B,iBAAiB,CAAC,UAAU,KAAA;IAU5B,QAAQ,CAAC,UAAU,KAAA;IAgBnB,cAAc,+BAOb;IAGD,kBAAkB,CAAC,UAAU,KAAA;IAgB7B,gBAAgB,CAAC,QAAQ,KAAA,EAAE,EAAE,KAAA;IAK7B,UAAU;IAoBV,MAAM;CAmBP;AAED,eAAe,WAAW,CAAA;AAC1B,OAAO,EAAE,WAAW,EAAE,CAAA"}
@@ -21,6 +21,7 @@ declare type TreeBrowserOwnProps = {
21
21
  onItemClick?: (...args: any[]) => any;
22
22
  treeLabel?: string;
23
23
  renderContent?: (...args: any[]) => any;
24
+ sortOrder?: (obj1: any, obj2: any) => number;
24
25
  };
25
26
  declare type PropKeys = keyof TreeBrowserOwnProps;
26
27
  declare type AllowedPropKeys = Readonly<Array<PropKeys>>;
@@ -1 +1 @@
1
- {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/TreeBrowser/props.ts"],"names":[],"mappings":";AA4BA,OAAO,KAAK,EACV,cAAc,EACd,gBAAgB,EACjB,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AAE1E,aAAK,mBAAmB,GAAG;IACzB,WAAW,EAAE,GAAG,CAAA;IAChB,KAAK,EAAE,GAAG,CAAA;IACV,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,GAAG,CAAA;IACd,eAAe,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACrC,a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MIT)
3
- category: Getting Started
4
- order: 9
5
- ---
6
-
7
- # The MIT License (MIT)
8
-
9
- Copyright (c) 2015 Instructure, Inc.
10
-
11
- **Permission is hereby granted, free of charge, to any person obtaining a copy
12
- of this software and associated documentation files (the "Software"), to deal
13
- in the Software without restriction, including without limitation the rights
14
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
- copies of the Software, and to permit persons to whom the Software is
16
- furnished to do so, subject to the following conditions.**
17
-
18
- The above copyright notice and this permission notice shall be included in all
19
- copies or substantial portions of the Software.
20
-
21
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
- SOFTWARE.