Skip to content
This repository was archived by the owner on Apr 18, 2024. It is now read-only.

Commit 1028ba8

Browse files
committed
Hotfix for maxUsages - consider non-label states
1 parent 6ce62c2 commit 1028ba8

File tree

5 files changed

+28
-41
lines changed

5 files changed

+28
-41
lines changed

src/tags/object/AudioPlus.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,15 +176,8 @@ const Model = types
176176
return find_r;
177177
}
178178

179-
const exceeded = self.states().reduce((list, s) => list.concat(s.checkMaxUsages()), []);
180-
const allStates = self.activeStates();
181-
179+
const allStates = self.getAvailableStates();
182180
if (allStates.length === 0) {
183-
if (exceeded.length) {
184-
const label = exceeded[0];
185-
InfoModal.warning(`You can't use ${label.value} more than ${label.maxUsages} time(s)`);
186-
}
187-
self.completion.regionStore.unselectAll(true);
188181
ws_region.remove && ws_region.remove();
189182
return;
190183
}

src/tags/object/Base.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { types } from "mobx-state-tree";
22
import lodash from "../../utils/lodash";
33
import { guidGenerator, restoreNewsnapshot } from "../../core/Helpers";
4+
import InfoModal from "../../components/Infomodal/Infomodal";
45

56
const ObjectBase = types
67
.model({
@@ -38,9 +39,29 @@ const ObjectBase = types
3839
return props;
3940
}
4041

42+
// @todo maybe not a best place for this method?
43+
// check that maxUsages was not exceeded for labels
44+
// and if it was - don't allow to create new region and unselect all regions
45+
// unselect labels which was exceeded maxUsages
46+
// return all states left untouched - available labels and others
47+
function getAvailableStates() {
48+
const checkAndCollect = (list, s) => (s.checkMaxUsages ? list.concat(s.checkMaxUsages()) : list);
49+
const exceeded = self.states().reduce(checkAndCollect, []);
50+
const states = self.activeStates();
51+
if (states.length === 0) {
52+
if (exceeded.length) {
53+
const label = exceeded[0];
54+
InfoModal.warning(`You can't use ${label.value} more than ${label.maxUsages} time(s)`);
55+
}
56+
self.completion.regionStore.unselectAll(true);
57+
}
58+
return states;
59+
}
60+
4161
return {
4262
addProp,
4363
getProps,
64+
getAvailableStates,
4465
};
4566
});
4667

src/tags/object/HyperText.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,8 @@ const Model = types
8989
},
9090

9191
addRegion(range) {
92-
const exceeded = self.states().reduce((list, s) => list.concat(s.checkMaxUsages()), []);
93-
const states = self.activeStates();
94-
if (states.length === 0) {
95-
if (exceeded.length) {
96-
const label = exceeded[0];
97-
InfoModal.warning(`You can't use ${label.value} more than ${label.maxUsages} time(s)`);
98-
}
99-
self.completion.regionStore.unselectAll(true);
100-
return;
101-
}
92+
const states = self.getAvailableStates();
93+
if (states.length === 0) return;
10294

10395
const clonedStates = states.map(s => cloneNode(s));
10496

src/tags/object/Image.js

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -331,20 +331,9 @@ const Model = types
331331
});
332332
},
333333

334-
// check that maxUsages was not exceeded
335-
// and if it was - don't allow to create new region and unselect all regions
336334
checkLabels() {
337-
const exceeded = self.states().reduce((list, s) => (s.checkMaxUsages ? list.concat(s.checkMaxUsages()) : []), []);
338-
const states = self.activeStates();
339-
if (states.length === 0) {
340-
if (exceeded.length) {
341-
const label = exceeded[0];
342-
InfoModal.warning(`You can't use ${label.value} more than ${label.maxUsages} time(s)`);
343-
}
344-
self.completion().regionStore.unselectAll(true);
345-
return false;
346-
}
347-
return true;
335+
const states = self.getAvailableStates();
336+
return states.length !== 0;
348337
},
349338

350339
addShape(shape) {

src/tags/object/Text.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,8 @@ const Model = types
154154
},
155155

156156
addRegion(range) {
157-
const exceeded = self.states().reduce((list, s) => list.concat(s.checkMaxUsages()), []);
158-
const states = self.activeStates();
159-
if (states.length === 0) {
160-
if (exceeded.length) {
161-
const label = exceeded[0];
162-
InfoModal.warning(`You can't use ${label.value} more than ${label.maxUsages} time(s)`);
163-
}
164-
self.completion.regionStore.unselectAll(true);
165-
return;
166-
}
157+
const states = self.getAvailableStates();
158+
if (states.length === 0) return;
167159

168160
const clonedStates = states.map(s => cloneNode(s));
169161

0 commit comments

Comments
 (0)