superdesk-ui-framework 5.1.4 → 5.1.6

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.
@@ -337,6 +337,13 @@ export class DatePickerISO extends React.PureComponent<IDatePickerISO> {
337
337
  }
338
338
  }
339
339
 
340
+ function getOptionLabel(options: Array<{id: string; label?: string}>, id: string | null | undefined): string {
341
+ if (id == null) {
342
+ return '';
343
+ }
344
+ return options.find((option) => option.id === id)?.label ?? id;
345
+ }
346
+
340
347
  const MonthNavigator = ({
341
348
  value,
342
349
  options,
@@ -346,7 +353,7 @@ const MonthNavigator = ({
346
353
  kind="synchronous"
347
354
  value={[value]}
348
355
  getOptions={() => options.map((option) => ({value: option.id}))}
349
- getLabel={(option) => options[parseInt(option, 10)].label}
356
+ getLabel={(optionId) => getOptionLabel(options, optionId)}
350
357
  getId={(option) => option}
351
358
  onChange={(selected) => {
352
359
  onChange(selected[0]);
@@ -355,7 +362,7 @@ const MonthNavigator = ({
355
362
  labelHidden
356
363
  valueTemplate={(item) => (
357
364
  <div className="sd-datepicker__navigator-value sd-datepicker__navigator-month">
358
- <div>{options[parseInt(item, 10)].label}</div>
365
+ <div>{getOptionLabel(options, item)}</div>
359
366
  <Icon name="chevron-down-thin" />
360
367
  </div>
361
368
  )}
@@ -374,102 +374,104 @@ export class TreeMenu<T> extends React.Component<IProps<T>, IState<T>> {
374
374
  <div ref={this.treeMenuRef}>
375
375
  <div ref={this.openDropdownRef}>{this.props.children(this.toggle)}</div>
376
376
 
377
- <WithPortal active={this.state.openDropdown} data-test-id="tree-menu-popover">
378
- <div
379
- ref={this.dropdownRef}
380
- className="autocomplete autocomplete--multi-select autocomplete--fixed-width"
381
- style={{
382
- zIndex: this.zIndex,
383
- }}
384
- >
385
- <div className="autocomplete__header">
386
- <div
387
- className="autocomplete__icon"
388
- onClick={() => {
389
- this.backButton();
390
- }}
391
- >
392
- <Icon name="search" className="search"></Icon>
393
- </div>
394
-
395
- <div className="autocomplete__filter">
396
- <input
397
- className="autocomplete__input"
398
- type="text"
399
- placeholder={this.props.searchPlaceholder}
400
- ref={this.inputRef}
401
- value={this.state.searchFieldValue}
402
- onChange={(event) => {
403
- this.setState({searchFieldValue: event.target.value});
404
- this.popperInstance?.update();
405
- }}
406
- />
407
- </div>
408
- </div>
409
-
410
- {this.state.activeTree.length > 0 && this.state.buttonValue != null && (
411
- <div className="autocomplete__category-header">
377
+ {this.state.openDropdown && (
378
+ <WithPortal active={this.state.openDropdown} data-test-id="tree-menu-popover">
379
+ <div
380
+ ref={this.dropdownRef}
381
+ className="autocomplete autocomplete--multi-select autocomplete--fixed-width"
382
+ style={{
383
+ zIndex: this.zIndex,
384
+ }}
385
+ >
386
+ <div className="autocomplete__header">
412
387
  <div
413
388
  className="autocomplete__icon"
414
389
  onClick={() => {
415
390
  this.backButton();
416
391
  }}
417
392
  >
418
- <Icon name="arrow-left" className="arrow-left"></Icon>
393
+ <Icon name="search" className="search"></Icon>
419
394
  </div>
420
395
 
421
396
  <div className="autocomplete__filter">
422
- <button className="autocomplete__category-title">
423
- {this.props.optionTemplate
424
- ? this.props.optionTemplate(this.state.buttonValue.value)
425
- : this.props.getLabel(this.state.buttonValue.value)}
426
- </button>
397
+ <input
398
+ className="autocomplete__input"
399
+ type="text"
400
+ placeholder={this.props.searchPlaceholder}
401
+ ref={this.inputRef}
402
+ value={this.state.searchFieldValue}
403
+ onChange={(event) => {
404
+ this.setState({searchFieldValue: event.target.value});
405
+ this.popperInstance?.update();
406
+ }}
407
+ />
427
408
  </div>
428
409
  </div>
429
- )}
430
-
431
- {this.state.searchFieldValue === '' ? (
432
- this.props.getOptions ? (
433
- <ul
434
- ref={this.ref}
435
- className="suggestion-list suggestion-list--multi-select"
436
- role="tree"
437
- >
438
- {this.state.options.map((option, i: React.Key | undefined) => (
439
- <TreeSelectItem
440
- key={i}
441
- option={option}
442
- handleTree={this.handleTree}
443
- onClick={() => {
444
- onSelect(option);
445
- }}
446
- disabledItem={disabledItem(option)}
447
- getBorderColor={this.props.getBorderColor}
448
- getBackgroundColor={this.props.getBackgroundColor}
449
- getId={this.props.getId}
450
- optionTemplate={this.props.optionTemplate}
451
- getLabel={this.props.getLabel}
452
- onKeyDown={() =>
453
- this.setState({
454
- buttonTarget: [
455
- ...this.state.buttonTarget,
456
- this.props.getId(option.value),
457
- ],
458
- })
459
- }
460
- />
461
- ))}
410
+
411
+ {this.state.activeTree.length > 0 && this.state.buttonValue != null && (
412
+ <div className="autocomplete__category-header">
413
+ <div
414
+ className="autocomplete__icon"
415
+ onClick={() => {
416
+ this.backButton();
417
+ }}
418
+ >
419
+ <Icon name="arrow-left" className="arrow-left"></Icon>
420
+ </div>
421
+
422
+ <div className="autocomplete__filter">
423
+ <button className="autocomplete__category-title">
424
+ {this.props.optionTemplate
425
+ ? this.props.optionTemplate(this.state.buttonValue.value)
426
+ : this.props.getLabel(this.state.buttonValue.value)}
427
+ </button>
428
+ </div>
429
+ </div>
430
+ )}
431
+
432
+ {this.state.searchFieldValue === '' ? (
433
+ this.props.getOptions ? (
434
+ <ul
435
+ ref={this.ref}
436
+ className="suggestion-list suggestion-list--multi-select"
437
+ role="tree"
438
+ >
439
+ {this.state.options.map((option, i: React.Key | undefined) => (
440
+ <TreeSelectItem
441
+ key={i}
442
+ option={option}
443
+ handleTree={this.handleTree}
444
+ onClick={() => {
445
+ onSelect(option);
446
+ }}
447
+ disabledItem={disabledItem(option)}
448
+ getBorderColor={this.props.getBorderColor}
449
+ getBackgroundColor={this.props.getBackgroundColor}
450
+ getId={this.props.getId}
451
+ optionTemplate={this.props.optionTemplate}
452
+ getLabel={this.props.getLabel}
453
+ onKeyDown={() =>
454
+ this.setState({
455
+ buttonTarget: [
456
+ ...this.state.buttonTarget,
457
+ this.props.getId(option.value),
458
+ ],
459
+ })
460
+ }
461
+ />
462
+ ))}
463
+ </ul>
464
+ ) : null
465
+ ) : (
466
+ <ul className="suggestion-list suggestion-list--multi-select" ref={this.ref}>
467
+ {this.filteredItem(
468
+ this.props.singleLevelSearch ? this.state.options : this.state.filterArr,
469
+ )}
462
470
  </ul>
463
- ) : null
464
- ) : (
465
- <ul className="suggestion-list suggestion-list--multi-select" ref={this.ref}>
466
- {this.filteredItem(
467
- this.props.singleLevelSearch ? this.state.options : this.state.filterArr,
468
- )}
469
- </ul>
470
- )}
471
- </div>
472
- </WithPortal>
471
+ )}
472
+ </div>
473
+ </WithPortal>
474
+ )}
473
475
  </div>
474
476
  );
475
477
  }
@@ -147,6 +147,26 @@ export class TreeSelect<T> extends React.Component<IProps<T>, IState<T>> {
147
147
  this.changesFromOutside = false;
148
148
  }
149
149
 
150
+ shouldComponentUpdate(nextProps: Readonly<IProps<T>>, nextState: Readonly<IState<T>>): boolean {
151
+ if (!isEqual(this.state, nextState)) {
152
+ return true;
153
+ }
154
+
155
+ const propKeys = Object.keys(nextProps) as Array<keyof IProps<T>>;
156
+
157
+ for (const key of propKeys) {
158
+ if (typeof this.props[key] === 'function') {
159
+ continue;
160
+ }
161
+
162
+ if (!isEqual(this.props[key], nextProps[key])) {
163
+ return true;
164
+ }
165
+ }
166
+
167
+ return false;
168
+ }
169
+
150
170
  inputFocus = () => {
151
171
  this.inputRef.current?.focus();
152
172
  };
@@ -897,131 +917,134 @@ export class TreeSelect<T> extends React.Component<IProps<T>, IState<T>> {
897
917
  )}
898
918
  </div>
899
919
 
900
- <WithPortal active={this.state.openDropdown} data-test-id="tree-select-popover">
901
- <div
902
- className={
903
- 'autocomplete autocomplete--multi-select' +
904
- (this.props.width === 'medium' ? ' autocomplete--fixed-width' : '')
905
- }
906
- style={{
907
- zIndex: this.zIndex,
908
- width: this.treeSelectRef.current?.offsetWidth,
909
- minWidth: '300px',
910
- }}
911
- ref={this.dropdownRef}
912
- >
913
- <div className="autocomplete__header">
914
- <div className="autocomplete__icon">
915
- <Icon name="search" className="search"></Icon>
916
- </div>
917
-
918
- <div className="autocomplete__filter">
919
- <input
920
- className="autocomplete__input"
921
- type="text"
922
- placeholder={this.props.searchPlaceholder}
923
- ref={this.inputRef}
924
- value={this.state.searchFieldValue}
925
- onChange={(event) => {
926
- if (this.props.kind === 'synchronous') {
927
- this.setState({searchFieldValue: event.target.value});
928
- this.popperInstance?.update();
929
- } else if (this.props.kind === 'asynchronous') {
930
- if (this.ICancelFn) {
931
- this.ICancelFn();
932
- }
933
-
934
- this.setState({
935
- searchFieldValue: event.target.value,
936
- options: [],
937
- loading: true,
938
- });
939
- this.popperInstance?.update();
940
- this.debounceFn();
941
- } else {
942
- return;
943
- }
944
- }}
945
- data-test-id="filter-input"
946
- />
947
- </div>
948
- </div>
949
-
950
- {this.state.activeTree.length > 0 && this.state.buttonValue != null && (
951
- <div className="autocomplete__category-header">
952
- <div
953
- className="autocomplete__icon"
954
- onClick={() => {
955
- this.backButton();
956
- }}
957
- >
958
- <Icon name="arrow-left" className="arrow-left"></Icon>
920
+ {this.state.openDropdown && (
921
+ <WithPortal active={this.state.openDropdown} data-test-id="tree-select-popover">
922
+ <div
923
+ className={
924
+ 'autocomplete autocomplete--multi-select' +
925
+ (this.props.width === 'medium' ? ' autocomplete--fixed-width' : '')
926
+ }
927
+ style={{
928
+ zIndex: this.zIndex,
929
+ width: this.treeSelectRef.current?.offsetWidth,
930
+ minWidth: '300px',
931
+ }}
932
+ ref={this.dropdownRef}
933
+ >
934
+ <div className="autocomplete__header">
935
+ <div className="autocomplete__icon">
936
+ <Icon name="search" className="search"></Icon>
959
937
  </div>
960
938
 
961
939
  <div className="autocomplete__filter">
962
- <button className="autocomplete__category-title">
963
- {this.props.optionTemplate
964
- ? this.props.optionTemplate(this.state.buttonValue.value)
965
- : this.props.getLabel(this.state.buttonValue.value)}
966
- </button>
940
+ <input
941
+ className="autocomplete__input"
942
+ type="text"
943
+ placeholder={this.props.searchPlaceholder}
944
+ ref={this.inputRef}
945
+ value={this.state.searchFieldValue}
946
+ onChange={(event) => {
947
+ if (this.props.kind === 'synchronous') {
948
+ this.setState({searchFieldValue: event.target.value});
949
+ this.popperInstance?.update();
950
+ } else if (this.props.kind === 'asynchronous') {
951
+ if (this.ICancelFn) {
952
+ this.ICancelFn();
953
+ }
967
954
 
968
- {this.props.selectBranchWithChildren && this.branchButton(this.state.buttonValue)}
955
+ this.setState({
956
+ searchFieldValue: event.target.value,
957
+ options: [],
958
+ loading: true,
959
+ });
960
+ this.popperInstance?.update();
961
+ this.debounceFn();
962
+ } else {
963
+ return;
964
+ }
965
+ }}
966
+ data-test-id="filter-input"
967
+ />
969
968
  </div>
970
969
  </div>
971
- )}
972
-
973
- {this.state.loading ? (
974
- <ul className="suggestion-list--loader">
975
- <Loader overlay={true}></Loader>
976
- </ul>
977
- ) : this.state.searchFieldValue === '' ? (
978
- this.props.getOptions ? (
979
- <ul
980
- className="suggestion-list suggestion-list--multi-select"
981
- ref={this.ref}
982
- data-test-id="options"
983
- role="tree"
984
- aria-multiselectable={this.props.allowMultiple}
985
- >
986
- {this.state.options.map((option, i: React.Key | undefined) => {
987
- let selectedItem = this.state.value.some(
988
- (obj) => this.props.getId(obj) === this.props.getId(option.value),
989
- );
990
-
991
- return (
992
- <TreeSelectItem
993
- key={i}
994
- option={option}
995
- handleTree={this.handleTree}
996
- selectedItem={selectedItem}
997
- allowMultiple={this.props.allowMultiple}
998
- getBorderColor={this.props.getBorderColor}
999
- getBackgroundColor={this.props.getBackgroundColor}
1000
- getId={this.props.getId}
1001
- getLabel={this.props.getLabel}
1002
- optionTemplate={this.props.optionTemplate}
1003
- onKeyDown={() =>
1004
- this.setState({
1005
- buttonTarget: [
1006
- ...this.state.buttonTarget,
1007
- this.props.getId(option.value),
1008
- ],
1009
- })
1010
- }
1011
- />
1012
- );
1013
- })}
970
+
971
+ {this.state.activeTree.length > 0 && this.state.buttonValue != null && (
972
+ <div className="autocomplete__category-header">
973
+ <div
974
+ className="autocomplete__icon"
975
+ onClick={() => {
976
+ this.backButton();
977
+ }}
978
+ >
979
+ <Icon name="arrow-left" className="arrow-left"></Icon>
980
+ </div>
981
+
982
+ <div className="autocomplete__filter">
983
+ <button className="autocomplete__category-title">
984
+ {this.props.optionTemplate
985
+ ? this.props.optionTemplate(this.state.buttonValue.value)
986
+ : this.props.getLabel(this.state.buttonValue.value)}
987
+ </button>
988
+
989
+ {this.props.selectBranchWithChildren &&
990
+ this.branchButton(this.state.buttonValue)}
991
+ </div>
992
+ </div>
993
+ )}
994
+
995
+ {this.state.loading ? (
996
+ <ul className="suggestion-list--loader">
997
+ <Loader overlay={true}></Loader>
1014
998
  </ul>
1015
- ) : null
1016
- ) : (
1017
- <ul className="suggestion-list suggestion-list--multi-select" ref={this.ref}>
1018
- {this.filteredItem(
1019
- this.props.singleLevelSearch ? this.state.options : this.state.filterArr,
1020
- )}
1021
- </ul>
1022
- )}
1023
- </div>
1024
- </WithPortal>
999
+ ) : this.state.searchFieldValue === '' ? (
1000
+ this.props.getOptions ? (
1001
+ <ul
1002
+ className="suggestion-list suggestion-list--multi-select"
1003
+ ref={this.ref}
1004
+ data-test-id="options"
1005
+ role="tree"
1006
+ aria-multiselectable={this.props.allowMultiple}
1007
+ >
1008
+ {this.state.options.map((option, i: React.Key | undefined) => {
1009
+ let selectedItem = this.state.value.some(
1010
+ (obj) => this.props.getId(obj) === this.props.getId(option.value),
1011
+ );
1012
+
1013
+ return (
1014
+ <TreeSelectItem
1015
+ key={i}
1016
+ option={option}
1017
+ handleTree={this.handleTree}
1018
+ selectedItem={selectedItem}
1019
+ allowMultiple={this.props.allowMultiple}
1020
+ getBorderColor={this.props.getBorderColor}
1021
+ getBackgroundColor={this.props.getBackgroundColor}
1022
+ getId={this.props.getId}
1023
+ getLabel={this.props.getLabel}
1024
+ optionTemplate={this.props.optionTemplate}
1025
+ onKeyDown={() =>
1026
+ this.setState({
1027
+ buttonTarget: [
1028
+ ...this.state.buttonTarget,
1029
+ this.props.getId(option.value),
1030
+ ],
1031
+ })
1032
+ }
1033
+ />
1034
+ );
1035
+ })}
1036
+ </ul>
1037
+ ) : null
1038
+ ) : (
1039
+ <ul className="suggestion-list suggestion-list--multi-select" ref={this.ref}>
1040
+ {this.filteredItem(
1041
+ this.props.singleLevelSearch ? this.state.options : this.state.filterArr,
1042
+ )}
1043
+ </ul>
1044
+ )}
1045
+ </div>
1046
+ </WithPortal>
1047
+ )}
1025
1048
  </InputWrapper>
1026
1049
  );
1027
1050
  }
@@ -60620,12 +60620,19 @@ var DatePickerISO = /** @class */ (function (_super) {
60620
60620
  return DatePickerISO;
60621
60621
  }(React.PureComponent));
60622
60622
  exports.DatePickerISO = DatePickerISO;
60623
+ function getOptionLabel(options, id) {
60624
+ var _a, _b;
60625
+ if (id == null) {
60626
+ return '';
60627
+ }
60628
+ return (_b = (_a = options.find(function (option) { return option.id === id; })) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : id;
60629
+ }
60623
60630
  var MonthNavigator = function (_a) {
60624
60631
  var value = _a.value, options = _a.options, onChange = _a.onChange;
60625
- return (React.createElement(TreeSelect_1.TreeSelect, { kind: "synchronous", value: [value], getOptions: function () { return options.map(function (option) { return ({ value: option.id }); }); }, getLabel: function (option) { return options[parseInt(option, 10)].label; }, getId: function (option) { return option; }, onChange: function (selected) {
60632
+ return (React.createElement(TreeSelect_1.TreeSelect, { kind: "synchronous", value: [value], getOptions: function () { return options.map(function (option) { return ({ value: option.id }); }); }, getLabel: function (optionId) { return getOptionLabel(options, optionId); }, getId: function (option) { return option; }, onChange: function (selected) {
60626
60633
  onChange(selected[0]);
60627
60634
  }, clearable: false, labelHidden: true, valueTemplate: function (item) { return (React.createElement("div", { className: "sd-datepicker__navigator-value sd-datepicker__navigator-month" },
60628
- React.createElement("div", null, options[parseInt(item, 10)].label),
60635
+ React.createElement("div", null, getOptionLabel(options, item)),
60629
60636
  React.createElement(Icon_1.Icon, { name: "chevron-down-thin" }))); }, inputWrapper: {
60630
60637
  kind: 'custom',
60631
60638
  component: function (_a) {
@@ -62345,6 +62352,22 @@ var TreeSelect = /** @class */ (function (_super) {
62345
62352
  _this.changesFromOutside = false;
62346
62353
  return _this;
62347
62354
  }
62355
+ TreeSelect.prototype.shouldComponentUpdate = function (nextProps, nextState) {
62356
+ if (!(0, lodash_1.isEqual)(this.state, nextState)) {
62357
+ return true;
62358
+ }
62359
+ var propKeys = Object.keys(nextProps);
62360
+ for (var _i = 0, propKeys_1 = propKeys; _i < propKeys_1.length; _i++) {
62361
+ var key = propKeys_1[_i];
62362
+ if (typeof this.props[key] === 'function') {
62363
+ continue;
62364
+ }
62365
+ if (!(0, lodash_1.isEqual)(this.props[key], nextProps[key])) {
62366
+ return true;
62367
+ }
62368
+ }
62369
+ return false;
62370
+ };
62348
62371
  TreeSelect.prototype.componentWillUnmount = function () {
62349
62372
  document.removeEventListener('mousedown', this.onMouseDown);
62350
62373
  document.removeEventListener('keydown', this.onKeyDown);
@@ -62796,7 +62819,7 @@ var TreeSelect = /** @class */ (function (_super) {
62796
62819
  };
62797
62820
  return React.createElement(React.Fragment, { key: i }, _this.renderItemContent(item, Wrapper));
62798
62821
  })))),
62799
- React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-select-popover" },
62822
+ this.state.openDropdown && (React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-select-popover" },
62800
62823
  React.createElement("div", { className: 'autocomplete autocomplete--multi-select' +
62801
62824
  (this.props.width === 'medium' ? ' autocomplete--fixed-width' : ''), style: {
62802
62825
  zIndex: this.zIndex,
@@ -62838,7 +62861,8 @@ var TreeSelect = /** @class */ (function (_super) {
62838
62861
  React.createElement("button", { className: "autocomplete__category-title" }, this.props.optionTemplate
62839
62862
  ? this.props.optionTemplate(this.state.buttonValue.value)
62840
62863
  : this.props.getLabel(this.state.buttonValue.value)),
62841
- this.props.selectBranchWithChildren && this.branchButton(this.state.buttonValue)))),
62864
+ this.props.selectBranchWithChildren &&
62865
+ this.branchButton(this.state.buttonValue)))),
62842
62866
  this.state.loading ? (React.createElement("ul", { className: "suggestion-list--loader" },
62843
62867
  React.createElement(Loader_1.Loader, { overlay: true }))) : this.state.searchFieldValue === '' ? (this.props.getOptions ? (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref, "data-test-id": "options", role: "tree", "aria-multiselectable": this.props.allowMultiple }, this.state.options.map(function (option, i) {
62844
62868
  var selectedItem = _this.state.value.some(function (obj) { return _this.props.getId(obj) === _this.props.getId(option.value); });
@@ -62849,7 +62873,7 @@ var TreeSelect = /** @class */ (function (_super) {
62849
62873
  ], false),
62850
62874
  });
62851
62875
  } }));
62852
- }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr)))))));
62876
+ }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr))))))));
62853
62877
  };
62854
62878
  return TreeSelect;
62855
62879
  }(React.Component));
@@ -99718,7 +99742,7 @@ var TreeMenu = /** @class */ (function (_super) {
99718
99742
  var _this = this;
99719
99743
  return (React.createElement("div", { ref: this.treeMenuRef },
99720
99744
  React.createElement("div", { ref: this.openDropdownRef }, this.props.children(this.toggle)),
99721
- React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-menu-popover" },
99745
+ this.state.openDropdown && (React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-menu-popover" },
99722
99746
  React.createElement("div", { ref: this.dropdownRef, className: "autocomplete autocomplete--multi-select autocomplete--fixed-width", style: {
99723
99747
  zIndex: this.zIndex,
99724
99748
  } },
@@ -99750,7 +99774,7 @@ var TreeMenu = /** @class */ (function (_super) {
99750
99774
  _this.props.getId(option.value),
99751
99775
  ], false),
99752
99776
  });
99753
- } })); }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr)))))));
99777
+ } })); }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr))))))));
99754
99778
  };
99755
99779
  return TreeMenu;
99756
99780
  }(React.Component));
@@ -196537,7 +196561,7 @@ exports.ThreePaneLayoutPattern = ThreePaneLayoutPattern;
196537
196561
  /* 1055 */
196538
196562
  /***/ (function(module, exports) {
196539
196563
 
196540
- module.exports = {"name":"superdesk-ui-framework","version":"5.1.4","license":"AGPL-3.0","repository":{"type":"git","url":"https://github.com/superdesk/superdesk-ui-framework.git"},"main":"dist/superdesk-ui.bundle.js","types":"react/index.d.ts","contributors":["Nemanja Pavlovic","Vladimir Stefanovic","Darko Tomic","Aleksandar Jelicic","Tomas Kikutis","Dragana Zivkovic","Konstantin Markov","Helmy Giacoman"],"scripts":{"start":"webpack-dev-server --config tasks/webpack.dev.js","server":"webpack --watch --config tasks/webpack.prod.js && tsc-watch","build":"tsc -p tsconfig.json --noEmit && webpack --config tasks/webpack.prod.js && tsc","build-ui":"webpack && tsc && npm run lint","playground-lint":"tsc -p examples/pages/playgrounds/react-playgrounds --noEmit","format-code":"npx prettier . --write","lint":"tsc -p tsconfig.json --noEmit && npx prettier . --check && eslint --parser=@typescript-eslint/parser app && tslint -c tslint.json 'app-typescript/**/*.{ts,tsx}' && npm run playground-lint && npm run unit-test","lint-fix":"tsc -p tsconfig.json --noEmit && tslint --fix -c tslint.json 'app-typescript/**/*.{ts,tsx}'","prepublishOnly":"npm run build","unit-test":"mocha","debug-unit-tests":"mocha --inspect-brk"},"devDependencies":{"@types/assert":"^1.5.6","@types/chart.js":"^2.9.24","@types/classnames":"^2.2.9","@types/enzyme":"^3.10.12","@types/enzyme-adapter-react-16":"^1.0.6","@types/lodash":"^4.14.161","@types/mocha":"^9.1.1","@types/react":"16.8.23","@types/react-beautiful-dnd":"^13.1.2","@types/react-dom":"16.8.0","@types/react-router-dom":"^5.1.2","@types/react-scrollspy":"^3.3.5","@typescript-eslint/parser":"^5.58.0","angular":"^1.7.9","angular-animate":"^1.7.9","angular-route":"^1.7.9","classnames":"^2.2.5","clean-webpack-plugin":"^1.0.0","code-prettify":"^0.1.0","copy-webpack-plugin":"^4.6.0","css-loader":"^2.1.1","enzyme":"^3.11.0","enzyme-adapter-react-16":"^1.15.7","eslint":"^4.6.1","eslint-loader":"^1.9.0","eslint-plugin-angular":"^3.1.1","eslint-plugin-react":"^7.3.0","extract-text-webpack-plugin":"^3.0.2","file-loader":"^0.11.2","html-loader":"^0.5.1","html-webpack-plugin":"^2.30.1","jquery":"^3.1.1","jquery-ui":"^1.12.1","jsdom":"20.0.3","jsdom-global":"3.0.2","lodash":"4.17.21","mocha":"^8.4.0","moment":"^2.29.3","node-sass":"6.0","prettier":"3.5.3","prismjs":"^1.28.0","prop-types":"^15.6.0","react":"16.8.6","react-dom":"16.8.6","react-redux":"^5.0.6","react-router-dom":"^5.1.2","redux":"^3.7.2","redux-form":"^7.0.4","sass-loader":"^6.0.6","style-loader":"^0.18.2","superdesk-code-style":"^1.1.2","ts-loader":"^6.0.2","ts-node":"^10.9.1","tslint":"^5.18.0","typescript":"^5.8.3","url-loader":"^1.1.2","webpack":"^3.5.5","webpack-cli":"3.3.10","webpack-dev-server":"2.11.1","webpack-merge":"^4.2.1"},"dependencies":{"@popperjs/core":"^2.4.0","@sourcefabric/common":"0.0.66","@superdesk/primereact":"^5.0.2-16","@superdesk/react-resizable-panels":"0.0.39","chart.js":"^2.9.3","date-fns":"^4.1.0","popper-max-size-modifier":"^0.2.0","popper.js":"1.14.4","primeicons":"2.0.0","react-beautiful-dnd":"^13.0.0","react-id-generator":"^3.0.0","react-scrollspy":"^3.4.3","weekstart":"^2.0.0"},"peerDependencies":{"moment":"*"},"volta":{"node":"14.21.3"}}
196564
+ module.exports = {"name":"superdesk-ui-framework","version":"5.1.6","license":"AGPL-3.0","repository":{"type":"git","url":"https://github.com/superdesk/superdesk-ui-framework.git"},"main":"dist/superdesk-ui.bundle.js","types":"react/index.d.ts","contributors":["Nemanja Pavlovic","Vladimir Stefanovic","Darko Tomic","Aleksandar Jelicic","Tomas Kikutis","Dragana Zivkovic","Konstantin Markov","Helmy Giacoman"],"scripts":{"start":"webpack-dev-server --config tasks/webpack.dev.js","server":"webpack --watch --config tasks/webpack.prod.js && tsc-watch","build":"tsc -p tsconfig.json --noEmit && webpack --config tasks/webpack.prod.js && tsc","build-ui":"webpack && tsc && npm run lint","playground-lint":"tsc -p examples/pages/playgrounds/react-playgrounds --noEmit","format-code":"npx prettier . --write","lint":"tsc -p tsconfig.json --noEmit && npx prettier . --check && eslint --parser=@typescript-eslint/parser app && tslint -c tslint.json 'app-typescript/**/*.{ts,tsx}' && npm run playground-lint && npm run unit-test","lint-fix":"tsc -p tsconfig.json --noEmit && tslint --fix -c tslint.json 'app-typescript/**/*.{ts,tsx}'","prepublishOnly":"npm run build","unit-test":"mocha","debug-unit-tests":"mocha --inspect-brk"},"devDependencies":{"@types/assert":"^1.5.6","@types/chart.js":"^2.9.24","@types/classnames":"^2.2.9","@types/enzyme":"^3.10.12","@types/enzyme-adapter-react-16":"^1.0.6","@types/lodash":"^4.14.161","@types/mocha":"^9.1.1","@types/react":"16.8.23","@types/react-beautiful-dnd":"^13.1.2","@types/react-dom":"16.8.0","@types/react-router-dom":"^5.1.2","@types/react-scrollspy":"^3.3.5","@typescript-eslint/parser":"^5.58.0","angular":"^1.7.9","angular-animate":"^1.7.9","angular-route":"^1.7.9","classnames":"^2.2.5","clean-webpack-plugin":"^1.0.0","code-prettify":"^0.1.0","copy-webpack-plugin":"^4.6.0","css-loader":"^2.1.1","enzyme":"^3.11.0","enzyme-adapter-react-16":"^1.15.7","eslint":"^4.6.1","eslint-loader":"^1.9.0","eslint-plugin-angular":"^3.1.1","eslint-plugin-react":"^7.3.0","extract-text-webpack-plugin":"^3.0.2","file-loader":"^0.11.2","html-loader":"^0.5.1","html-webpack-plugin":"^2.30.1","jquery":"^3.1.1","jquery-ui":"^1.12.1","jsdom":"20.0.3","jsdom-global":"3.0.2","lodash":"4.17.21","mocha":"^8.4.0","moment":"^2.29.3","node-sass":"6.0","prettier":"3.5.3","prismjs":"^1.28.0","prop-types":"^15.6.0","react":"16.8.6","react-dom":"16.8.6","react-redux":"^5.0.6","react-router-dom":"^5.1.2","redux":"^3.7.2","redux-form":"^7.0.4","sass-loader":"^6.0.6","style-loader":"^0.18.2","superdesk-code-style":"^1.1.2","ts-loader":"^6.0.2","ts-node":"^10.9.1","tslint":"^5.18.0","typescript":"^5.8.3","url-loader":"^1.1.2","webpack":"^3.5.5","webpack-cli":"3.3.10","webpack-dev-server":"2.11.1","webpack-merge":"^4.2.1"},"dependencies":{"@popperjs/core":"^2.4.0","@sourcefabric/common":"0.0.66","@superdesk/primereact":"^5.0.2-16","@superdesk/react-resizable-panels":"0.0.39","chart.js":"^2.9.3","date-fns":"^4.1.0","popper-max-size-modifier":"^0.2.0","popper.js":"1.14.4","primeicons":"2.0.0","react-beautiful-dnd":"^13.0.0","react-id-generator":"^3.0.0","react-scrollspy":"^3.4.3","weekstart":"^2.0.0"},"peerDependencies":{"moment":"*"},"volta":{"node":"14.21.3"}}
196541
196565
 
196542
196566
  /***/ }),
196543
196567
  /* 1056 */
@@ -60350,12 +60350,19 @@ var DatePickerISO = /** @class */ (function (_super) {
60350
60350
  return DatePickerISO;
60351
60351
  }(React.PureComponent));
60352
60352
  exports.DatePickerISO = DatePickerISO;
60353
+ function getOptionLabel(options, id) {
60354
+ var _a, _b;
60355
+ if (id == null) {
60356
+ return '';
60357
+ }
60358
+ return (_b = (_a = options.find(function (option) { return option.id === id; })) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : id;
60359
+ }
60353
60360
  var MonthNavigator = function (_a) {
60354
60361
  var value = _a.value, options = _a.options, onChange = _a.onChange;
60355
- return (React.createElement(TreeSelect_1.TreeSelect, { kind: "synchronous", value: [value], getOptions: function () { return options.map(function (option) { return ({ value: option.id }); }); }, getLabel: function (option) { return options[parseInt(option, 10)].label; }, getId: function (option) { return option; }, onChange: function (selected) {
60362
+ return (React.createElement(TreeSelect_1.TreeSelect, { kind: "synchronous", value: [value], getOptions: function () { return options.map(function (option) { return ({ value: option.id }); }); }, getLabel: function (optionId) { return getOptionLabel(options, optionId); }, getId: function (option) { return option; }, onChange: function (selected) {
60356
60363
  onChange(selected[0]);
60357
60364
  }, clearable: false, labelHidden: true, valueTemplate: function (item) { return (React.createElement("div", { className: "sd-datepicker__navigator-value sd-datepicker__navigator-month" },
60358
- React.createElement("div", null, options[parseInt(item, 10)].label),
60365
+ React.createElement("div", null, getOptionLabel(options, item)),
60359
60366
  React.createElement(Icon_1.Icon, { name: "chevron-down-thin" }))); }, inputWrapper: {
60360
60367
  kind: 'custom',
60361
60368
  component: function (_a) {
@@ -62075,6 +62082,22 @@ var TreeSelect = /** @class */ (function (_super) {
62075
62082
  _this.changesFromOutside = false;
62076
62083
  return _this;
62077
62084
  }
62085
+ TreeSelect.prototype.shouldComponentUpdate = function (nextProps, nextState) {
62086
+ if (!(0, lodash_1.isEqual)(this.state, nextState)) {
62087
+ return true;
62088
+ }
62089
+ var propKeys = Object.keys(nextProps);
62090
+ for (var _i = 0, propKeys_1 = propKeys; _i < propKeys_1.length; _i++) {
62091
+ var key = propKeys_1[_i];
62092
+ if (typeof this.props[key] === 'function') {
62093
+ continue;
62094
+ }
62095
+ if (!(0, lodash_1.isEqual)(this.props[key], nextProps[key])) {
62096
+ return true;
62097
+ }
62098
+ }
62099
+ return false;
62100
+ };
62078
62101
  TreeSelect.prototype.componentWillUnmount = function () {
62079
62102
  document.removeEventListener('mousedown', this.onMouseDown);
62080
62103
  document.removeEventListener('keydown', this.onKeyDown);
@@ -62526,7 +62549,7 @@ var TreeSelect = /** @class */ (function (_super) {
62526
62549
  };
62527
62550
  return React.createElement(React.Fragment, { key: i }, _this.renderItemContent(item, Wrapper));
62528
62551
  })))),
62529
- React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-select-popover" },
62552
+ this.state.openDropdown && (React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-select-popover" },
62530
62553
  React.createElement("div", { className: 'autocomplete autocomplete--multi-select' +
62531
62554
  (this.props.width === 'medium' ? ' autocomplete--fixed-width' : ''), style: {
62532
62555
  zIndex: this.zIndex,
@@ -62568,7 +62591,8 @@ var TreeSelect = /** @class */ (function (_super) {
62568
62591
  React.createElement("button", { className: "autocomplete__category-title" }, this.props.optionTemplate
62569
62592
  ? this.props.optionTemplate(this.state.buttonValue.value)
62570
62593
  : this.props.getLabel(this.state.buttonValue.value)),
62571
- this.props.selectBranchWithChildren && this.branchButton(this.state.buttonValue)))),
62594
+ this.props.selectBranchWithChildren &&
62595
+ this.branchButton(this.state.buttonValue)))),
62572
62596
  this.state.loading ? (React.createElement("ul", { className: "suggestion-list--loader" },
62573
62597
  React.createElement(Loader_1.Loader, { overlay: true }))) : this.state.searchFieldValue === '' ? (this.props.getOptions ? (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref, "data-test-id": "options", role: "tree", "aria-multiselectable": this.props.allowMultiple }, this.state.options.map(function (option, i) {
62574
62598
  var selectedItem = _this.state.value.some(function (obj) { return _this.props.getId(obj) === _this.props.getId(option.value); });
@@ -62579,7 +62603,7 @@ var TreeSelect = /** @class */ (function (_super) {
62579
62603
  ], false),
62580
62604
  });
62581
62605
  } }));
62582
- }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr)))))));
62606
+ }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr))))))));
62583
62607
  };
62584
62608
  return TreeSelect;
62585
62609
  }(React.Component));
@@ -99065,7 +99089,7 @@ var TreeMenu = /** @class */ (function (_super) {
99065
99089
  var _this = this;
99066
99090
  return (React.createElement("div", { ref: this.treeMenuRef },
99067
99091
  React.createElement("div", { ref: this.openDropdownRef }, this.props.children(this.toggle)),
99068
- React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-menu-popover" },
99092
+ this.state.openDropdown && (React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-menu-popover" },
99069
99093
  React.createElement("div", { ref: this.dropdownRef, className: "autocomplete autocomplete--multi-select autocomplete--fixed-width", style: {
99070
99094
  zIndex: this.zIndex,
99071
99095
  } },
@@ -99097,7 +99121,7 @@ var TreeMenu = /** @class */ (function (_super) {
99097
99121
  _this.props.getId(option.value),
99098
99122
  ], false),
99099
99123
  });
99100
- } })); }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr)))))));
99124
+ } })); }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr))))))));
99101
99125
  };
99102
99126
  return TreeMenu;
99103
99127
  }(React.Component));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "superdesk-ui-framework",
3
- "version": "5.1.4",
3
+ "version": "5.1.6",
4
4
  "license": "AGPL-3.0",
5
5
  "repository": {
6
6
  "type": "git",
@@ -264,12 +264,19 @@ var DatePickerISO = /** @class */ (function (_super) {
264
264
  return DatePickerISO;
265
265
  }(React.PureComponent));
266
266
  exports.DatePickerISO = DatePickerISO;
267
+ function getOptionLabel(options, id) {
268
+ var _a, _b;
269
+ if (id == null) {
270
+ return '';
271
+ }
272
+ return (_b = (_a = options.find(function (option) { return option.id === id; })) === null || _a === void 0 ? void 0 : _a.label) !== null && _b !== void 0 ? _b : id;
273
+ }
267
274
  var MonthNavigator = function (_a) {
268
275
  var value = _a.value, options = _a.options, onChange = _a.onChange;
269
- return (React.createElement(TreeSelect_1.TreeSelect, { kind: "synchronous", value: [value], getOptions: function () { return options.map(function (option) { return ({ value: option.id }); }); }, getLabel: function (option) { return options[parseInt(option, 10)].label; }, getId: function (option) { return option; }, onChange: function (selected) {
276
+ return (React.createElement(TreeSelect_1.TreeSelect, { kind: "synchronous", value: [value], getOptions: function () { return options.map(function (option) { return ({ value: option.id }); }); }, getLabel: function (optionId) { return getOptionLabel(options, optionId); }, getId: function (option) { return option; }, onChange: function (selected) {
270
277
  onChange(selected[0]);
271
278
  }, clearable: false, labelHidden: true, valueTemplate: function (item) { return (React.createElement("div", { className: "sd-datepicker__navigator-value sd-datepicker__navigator-month" },
272
- React.createElement("div", null, options[parseInt(item, 10)].label),
279
+ React.createElement("div", null, getOptionLabel(options, item)),
273
280
  React.createElement(Icon_1.Icon, { name: "chevron-down-thin" }))); }, inputWrapper: {
274
281
  kind: 'custom',
275
282
  component: function (_a) {
@@ -344,7 +344,7 @@ var TreeMenu = /** @class */ (function (_super) {
344
344
  var _this = this;
345
345
  return (React.createElement("div", { ref: this.treeMenuRef },
346
346
  React.createElement("div", { ref: this.openDropdownRef }, this.props.children(this.toggle)),
347
- React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-menu-popover" },
347
+ this.state.openDropdown && (React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-menu-popover" },
348
348
  React.createElement("div", { ref: this.dropdownRef, className: "autocomplete autocomplete--multi-select autocomplete--fixed-width", style: {
349
349
  zIndex: this.zIndex,
350
350
  } },
@@ -376,7 +376,7 @@ var TreeMenu = /** @class */ (function (_super) {
376
376
  _this.props.getId(option.value),
377
377
  ], false),
378
378
  });
379
- } })); }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr)))))));
379
+ } })); }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr))))))));
380
380
  };
381
381
  return TreeMenu;
382
382
  }(React.Component));
@@ -73,6 +73,7 @@ export declare class TreeSelect<T> extends React.Component<IProps<T>, IState<T>>
73
73
  private zIndex;
74
74
  private changesFromOutside;
75
75
  constructor(props: IProps<T>);
76
+ shouldComponentUpdate(nextProps: Readonly<IProps<T>>, nextState: Readonly<IState<T>>): boolean;
76
77
  inputFocus: () => void;
77
78
  listNavigation: () => void;
78
79
  buttonFocus: () => void;
@@ -188,6 +188,22 @@ var TreeSelect = /** @class */ (function (_super) {
188
188
  _this.changesFromOutside = false;
189
189
  return _this;
190
190
  }
191
+ TreeSelect.prototype.shouldComponentUpdate = function (nextProps, nextState) {
192
+ if (!(0, lodash_1.isEqual)(this.state, nextState)) {
193
+ return true;
194
+ }
195
+ var propKeys = Object.keys(nextProps);
196
+ for (var _i = 0, propKeys_1 = propKeys; _i < propKeys_1.length; _i++) {
197
+ var key = propKeys_1[_i];
198
+ if (typeof this.props[key] === 'function') {
199
+ continue;
200
+ }
201
+ if (!(0, lodash_1.isEqual)(this.props[key], nextProps[key])) {
202
+ return true;
203
+ }
204
+ }
205
+ return false;
206
+ };
191
207
  TreeSelect.prototype.componentWillUnmount = function () {
192
208
  document.removeEventListener('mousedown', this.onMouseDown);
193
209
  document.removeEventListener('keydown', this.onKeyDown);
@@ -639,7 +655,7 @@ var TreeSelect = /** @class */ (function (_super) {
639
655
  };
640
656
  return React.createElement(React.Fragment, { key: i }, _this.renderItemContent(item, Wrapper));
641
657
  })))),
642
- React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-select-popover" },
658
+ this.state.openDropdown && (React.createElement(WithPortal_1.WithPortal, { active: this.state.openDropdown, "data-test-id": "tree-select-popover" },
643
659
  React.createElement("div", { className: 'autocomplete autocomplete--multi-select' +
644
660
  (this.props.width === 'medium' ? ' autocomplete--fixed-width' : ''), style: {
645
661
  zIndex: this.zIndex,
@@ -681,7 +697,8 @@ var TreeSelect = /** @class */ (function (_super) {
681
697
  React.createElement("button", { className: "autocomplete__category-title" }, this.props.optionTemplate
682
698
  ? this.props.optionTemplate(this.state.buttonValue.value)
683
699
  : this.props.getLabel(this.state.buttonValue.value)),
684
- this.props.selectBranchWithChildren && this.branchButton(this.state.buttonValue)))),
700
+ this.props.selectBranchWithChildren &&
701
+ this.branchButton(this.state.buttonValue)))),
685
702
  this.state.loading ? (React.createElement("ul", { className: "suggestion-list--loader" },
686
703
  React.createElement(Loader_1.Loader, { overlay: true }))) : this.state.searchFieldValue === '' ? (this.props.getOptions ? (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref, "data-test-id": "options", role: "tree", "aria-multiselectable": this.props.allowMultiple }, this.state.options.map(function (option, i) {
687
704
  var selectedItem = _this.state.value.some(function (obj) { return _this.props.getId(obj) === _this.props.getId(option.value); });
@@ -692,7 +709,7 @@ var TreeSelect = /** @class */ (function (_super) {
692
709
  ], false),
693
710
  });
694
711
  } }));
695
- }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr)))))));
712
+ }))) : null) : (React.createElement("ul", { className: "suggestion-list suggestion-list--multi-select", ref: this.ref }, this.filteredItem(this.props.singleLevelSearch ? this.state.options : this.state.filterArr))))))));
696
713
  };
697
714
  return TreeSelect;
698
715
  }(React.Component));