Move checkBlockCounts into BaseSequenceBlock as a general blockCountChanged callback

The call to checkBlockCounts from duplicateBlock can be removed outright, as it already gets called via the call to insert.
pull/7345/head
Matt Westcott 2021-07-09 18:37:07 +01:00
rodzic 8c97c254a7
commit d22cc560f1
2 zmienionych plików z 12 dodań i 19 usunięć

Wyświetl plik

@ -332,6 +332,8 @@ export class BaseSequenceBlock {
}
)
];
this.blockCountChanged();
}
_onRequestInsert(index, opts) {
@ -342,6 +344,10 @@ export class BaseSequenceBlock {
newChild.focus({ soft: true });
}
blockCountChanged() {
/* Called whenever the block count has changed; subclasses can override this to apply
checks on max block count and disable insert / duplicate controls accordingly */
}
_insert(childBlockDef, initialState, id, index, opts) {
const prefix = this.prefix + '-' + this.blockCounter;
@ -408,6 +414,8 @@ export class BaseSequenceBlock {
}
}
this.blockCountChanged();
return child;
}
@ -435,6 +443,8 @@ export class BaseSequenceBlock {
/* we have removed the last child; the new last child cannot be moved down */
this.children[this.children.length - 1].disableMoveDown();
}
this.blockCountChanged();
}
moveBlock(oldIndex, newIndex) {

Wyświetl plik

@ -221,7 +221,8 @@ export class StreamBlock extends BaseSequenceBlock {
*
* Updates the state of add / duplicate block buttons to prevent too many blocks being inserted.
*/
checkBlockCounts() {
blockCountChanged() {
super.blockCountChanged();
this.canAddBlock = true;
if (typeof this.blockDef.meta.maxNum === 'number' && this.children.length >= this.blockDef.meta.maxNum) {
@ -276,12 +277,6 @@ export class StreamBlock extends BaseSequenceBlock {
return this._insert(childBlockDef, value, id, index, opts);
}
_insert(childBlockDef, value, id, index, opts) {
const result = super._insert(childBlockDef, value, id, index, opts);
this.checkBlockCounts();
return result;
}
_getChildDataForInsertion({ type }) {
/* Called when an 'insert new block' action is triggered: given a dict of data from the insertion control,
return the block definition and initial state to be used for the new block.
@ -292,11 +287,6 @@ export class StreamBlock extends BaseSequenceBlock {
return [blockDef, initialState, uuidv4()];
}
clear() {
super.clear();
this.checkBlockCounts();
}
duplicateBlock(index, opts) {
const child = this.children[index];
const childState = child.getState();
@ -305,13 +295,6 @@ export class StreamBlock extends BaseSequenceBlock {
this.insert(childState, index + 1, { animate, collapsed: child.collapsed });
// focus the newly added field if we can do so without obtrusive UI behaviour
this.children[index + 1].focus({ soft: true });
this.checkBlockCounts();
}
deleteBlock(index, opts) {
super.deleteBlock(index, opts);
this.checkBlockCounts();
}
setState(values) {