|
@@ -1,44 +1,78 @@
|
|
|
-function loopBreakpoint(block, { prevBlockData }) {
|
|
|
- const currentLoop = this.loopList[block.data.loopId];
|
|
|
+import { waitTabLoaded } from '../helper';
|
|
|
|
|
|
- return new Promise((resolve) => {
|
|
|
- let validLoopData = false;
|
|
|
+async function loopBreakpoint(block, { prevBlockData }) {
|
|
|
+ const currentLoop = this.loopList[block.data.loopId];
|
|
|
|
|
|
- if (currentLoop) {
|
|
|
- validLoopData =
|
|
|
- currentLoop.type === 'numbers'
|
|
|
- ? true
|
|
|
- : currentLoop.index <= currentLoop.data.length - 1;
|
|
|
- }
|
|
|
+ let validLoopData = false;
|
|
|
|
|
|
- const continueLoop =
|
|
|
- currentLoop &&
|
|
|
- currentLoop.index < currentLoop.maxLoop - 1 &&
|
|
|
- validLoopData;
|
|
|
+ if (currentLoop) {
|
|
|
+ validLoopData =
|
|
|
+ currentLoop.type === 'numbers'
|
|
|
+ ? true
|
|
|
+ : currentLoop.index < currentLoop.data.length - 1;
|
|
|
+ }
|
|
|
|
|
|
- if (!block.data.clearLoop && continueLoop) {
|
|
|
- resolve({
|
|
|
- data: '',
|
|
|
- nextBlockId: [{ id: currentLoop.blockId }],
|
|
|
+ const notReachMaxLoop =
|
|
|
+ currentLoop && currentLoop.maxLoop > 0
|
|
|
+ ? currentLoop.index < currentLoop.maxLoop - 1
|
|
|
+ : true;
|
|
|
+ if (!block.data.clearLoop && validLoopData && notReachMaxLoop) {
|
|
|
+ return {
|
|
|
+ data: '',
|
|
|
+ nextBlockId: [{ id: currentLoop.blockId }],
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (currentLoop.type === 'elements') {
|
|
|
+ if (currentLoop.loadMoreAction && notReachMaxLoop) {
|
|
|
+ const isClickLink = currentLoop.loadMoreAction.type === 'click-link';
|
|
|
+ let result = await this._sendMessageToTab({
|
|
|
+ id: currentLoop.blockId,
|
|
|
+ label: 'loop-elements',
|
|
|
+ data: {
|
|
|
+ ...currentLoop.loadMoreAction,
|
|
|
+ index: currentLoop.index,
|
|
|
+ onlyClickLink: isClickLink,
|
|
|
+ },
|
|
|
});
|
|
|
- } else {
|
|
|
- if (currentLoop.type === 'elements') {
|
|
|
- const loopElsIndex = this.loopEls.findIndex(
|
|
|
- ({ blockId }) => blockId === currentLoop.blockId
|
|
|
- );
|
|
|
|
|
|
- if (loopElsIndex !== -1) this.loopEls.splice(loopElsIndex, 1);
|
|
|
+ if (!result.continue && isClickLink) {
|
|
|
+ await waitTabLoaded({
|
|
|
+ tabId: this.activeTab.id,
|
|
|
+ ms: currentLoop.loadMoreAction.actionPageMaxWaitTime * 1000,
|
|
|
+ });
|
|
|
+ result = await this._sendMessageToTab({
|
|
|
+ id: currentLoop.blockId,
|
|
|
+ label: 'loop-elements',
|
|
|
+ data: {
|
|
|
+ ...currentLoop.loadMoreAction,
|
|
|
+ index: currentLoop.index,
|
|
|
+ },
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
- delete this.loopList[block.data.loopId];
|
|
|
- delete this.engine.referenceData.loopData[block.data.loopId];
|
|
|
-
|
|
|
- resolve({
|
|
|
- data: prevBlockData,
|
|
|
- nextBlockId: this.getBlockConnections(block.id),
|
|
|
- });
|
|
|
+ if (!result.continue && result.length > 0) {
|
|
|
+ this.loopList[block.data.loopId].data.push(...result);
|
|
|
+ return {
|
|
|
+ data: '',
|
|
|
+ nextBlockId: [{ id: currentLoop.blockId }],
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
- });
|
|
|
+
|
|
|
+ const loopElsIndex = this.loopEls.findIndex(
|
|
|
+ ({ blockId }) => blockId === currentLoop.blockId
|
|
|
+ );
|
|
|
+
|
|
|
+ if (loopElsIndex !== -1) this.loopEls.splice(loopElsIndex, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ delete this.loopList[block.data.loopId];
|
|
|
+ delete this.engine.referenceData.loopData[block.data.loopId];
|
|
|
+
|
|
|
+ return {
|
|
|
+ data: prevBlockData,
|
|
|
+ nextBlockId: this.getBlockConnections(block.id),
|
|
|
+ };
|
|
|
}
|
|
|
|
|
|
export default loopBreakpoint;
|