@remvst/configurable-react 1.2.2 → 1.3.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.
@@ -39,8 +39,11 @@ class EnumConfigurableComponent extends react_1.default.Component {
39
39
  valueKey = key;
40
40
  }
41
41
  }
42
- return (react_1.default.createElement("select", { value: valueKey, onChange: (e) => this.onChange(e) }, Array.from(configurable.categories).map((category) => {
43
- return (react_1.default.createElement("optgroup", { label: category.label || '', key: category.label }, category.items.map((item) => {
42
+ const categories = Array.from(configurable.categories)
43
+ .sort((a, b) => (a.label || '') < (b.label || '') ? -1 : 1);
44
+ return (react_1.default.createElement("select", { value: valueKey, onChange: (e) => this.onChange(e) }, categories.map((category) => {
45
+ const items = category.items.sort((a, b) => a.key < b.key ? -1 : 1);
46
+ return (react_1.default.createElement("optgroup", { label: category.label || '', key: category.label }, items.map((item) => {
44
47
  return (react_1.default.createElement("option", { key: item.key, value: item.key }, item.key));
45
48
  })));
46
49
  })));
@@ -7,6 +7,7 @@ interface Props {
7
7
  }
8
8
  interface State {
9
9
  readonly configurable: Configurable;
10
+ readonly refreshCount: number;
10
11
  }
11
12
  export default class InvalidatableComponent extends React.Component<Props, State> {
12
13
  constructor(props: Props);
@@ -9,11 +9,12 @@ class InvalidatableComponent extends react_1.default.Component {
9
9
  super(props);
10
10
  this.state = {
11
11
  'configurable': this.prepareConfigurable(),
12
+ 'refreshCount': 0,
12
13
  };
13
14
  }
14
15
  renew() {
15
16
  const configurable = this.prepareConfigurable();
16
- this.setState({ configurable });
17
+ this.setState({ configurable, 'refreshCount': this.state.refreshCount + 1 });
17
18
  }
18
19
  prepareConfigurable() {
19
20
  const configurable = this.props.configurable();
@@ -21,7 +22,7 @@ class InvalidatableComponent extends react_1.default.Component {
21
22
  return configurable;
22
23
  }
23
24
  render() {
24
- return (react_1.default.createElement("div", null, this.props.mapper(this.state.configurable, this.props.mapper)));
25
+ return (react_1.default.createElement("div", { key: this.state.refreshCount }, this.props.mapper(this.state.configurable, this.props.mapper)));
25
26
  }
26
27
  }
27
28
  exports.default = InvalidatableComponent;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remvst/configurable-react",
3
- "version": "1.2.2",
3
+ "version": "1.3.0",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "exports": {
@@ -13,7 +13,7 @@
13
13
  "author": "",
14
14
  "license": "ISC",
15
15
  "dependencies": {
16
- "@remvst/configurable": "file:../configurable-api",
16
+ "@remvst/configurable": "^1.4.0",
17
17
  "react": "^18.2.0",
18
18
  "react-dom": "^18.2.0",
19
19
  "@types/react-dom": "^18.0.6",
@@ -49,11 +49,16 @@ export default class EnumConfigurableComponent extends React.Component<Component
49
49
  }
50
50
  }
51
51
 
52
+ const categories = Array.from(configurable.categories)
53
+ .sort((a, b) => (a.label || '') < (b.label || '') ? -1 : 1)
54
+
52
55
  return (
53
56
  <select value={valueKey} onChange={(e) => this.onChange(e)}>
54
- {Array.from(configurable.categories).map((category) => {
57
+ {categories.map((category) => {
58
+ const items = category.items.sort((a, b) => a.key < b.key ? -1 : 1);
59
+
55
60
  return (<optgroup label={category.label || ''} key={category.label}>
56
- {category.items.map((item) => {
61
+ {items.map((item) => {
57
62
  return (
58
63
  <option key={item.key} value={item.key}>{item.key}</option>
59
64
  );
@@ -11,6 +11,7 @@ interface Props {
11
11
 
12
12
  interface State {
13
13
  readonly configurable: Configurable;
14
+ readonly refreshCount: number;
14
15
  }
15
16
 
16
17
  export default class InvalidatableComponent extends React.Component<Props, State> {
@@ -19,12 +20,13 @@ export default class InvalidatableComponent extends React.Component<Props, State
19
20
  super(props);
20
21
  this.state = {
21
22
  'configurable': this.prepareConfigurable(),
23
+ 'refreshCount': 0,
22
24
  };
23
25
  }
24
26
 
25
27
  private renew() {
26
28
  const configurable = this.prepareConfigurable();
27
- this.setState({ configurable });
29
+ this.setState({ configurable, 'refreshCount': this.state.refreshCount + 1 });
28
30
  }
29
31
 
30
32
  private prepareConfigurable(): Configurable {
@@ -34,6 +36,6 @@ export default class InvalidatableComponent extends React.Component<Props, State
34
36
  }
35
37
 
36
38
  render(): React.ReactNode {
37
- return (<div>{this.props.mapper(this.state.configurable, this.props.mapper)}</div>);
39
+ return (<div key={this.state.refreshCount}>{this.props.mapper(this.state.configurable, this.props.mapper)}</div>);
38
40
  }
39
41
  }