-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
57 changed files
with
2,589 additions
and
1,543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/background/workflow-engine/blocks-handler/handler-browser-event.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 52 additions & 19 deletions
71
src/background/workflow-engine/blocks-handler/handler-conditions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,74 @@ | ||
import { getBlockConnection } from '../helper'; | ||
import compareBlockValue from '@/utils/compare-block-value'; | ||
import mustacheReplacer from '@/utils/reference-data/mustache-replacer'; | ||
import testConditions from '@/utils/test-conditions'; | ||
import { getBlockConnection } from '../helper'; | ||
|
||
function conditions({ data, outputs }, { prevBlockData, refData }) { | ||
return new Promise((resolve, reject) => { | ||
if (data.conditions.length === 0) { | ||
reject(new Error('conditions-empty')); | ||
return; | ||
} | ||
async function conditions({ data, outputs }, { prevBlockData, refData }) { | ||
if (data.conditions.length === 0) { | ||
throw new Error('conditions-empty'); | ||
} | ||
|
||
let resultData = ''; | ||
let isConditionMatch = false; | ||
let outputIndex = data.conditions.length + 1; | ||
|
||
const replacedValue = {}; | ||
const condition = data.conditions[0]; | ||
const prevData = Array.isArray(prevBlockData) | ||
? prevBlockData[0] | ||
: prevBlockData; | ||
|
||
if (condition && condition.conditions) { | ||
const conditionPayload = { | ||
refData, | ||
activeTab: this.activeTab.id, | ||
sendMessage: (payload) => | ||
this._sendMessageToTab({ ...payload, isBlock: false }), | ||
}; | ||
|
||
for (let index = 0; index < data.conditions.length; index += 1) { | ||
const result = await testConditions( | ||
data.conditions[index].conditions, | ||
conditionPayload | ||
); | ||
|
||
let resultData = ''; | ||
let isConditionMatch = false; | ||
let outputIndex = data.conditions.length + 1; | ||
const prevData = Array.isArray(prevBlockData) | ||
? prevBlockData[0] | ||
: prevBlockData; | ||
Object.assign(replacedValue, result?.replacedValue || {}); | ||
|
||
if (result.isMatch) { | ||
isConditionMatch = true; | ||
outputIndex = index + 1; | ||
|
||
break; | ||
} | ||
} | ||
} else { | ||
data.conditions.forEach(({ type, value, compareValue }, index) => { | ||
if (isConditionMatch) return; | ||
|
||
const firstValue = mustacheReplacer(compareValue ?? prevData, refData); | ||
const secondValue = mustacheReplacer(value, refData); | ||
|
||
const isMatch = compareBlockValue(type, firstValue, secondValue); | ||
Object.assign(replacedValue, firstValue.list, secondValue.list); | ||
|
||
const isMatch = compareBlockValue( | ||
type, | ||
firstValue.value, | ||
secondValue.value | ||
); | ||
|
||
if (isMatch) { | ||
resultData = value; | ||
outputIndex = index + 1; | ||
isConditionMatch = true; | ||
} | ||
}); | ||
} | ||
|
||
resolve({ | ||
data: resultData, | ||
nextBlockId: getBlockConnection({ outputs }, outputIndex), | ||
}); | ||
}); | ||
return { | ||
replacedValue, | ||
data: resultData, | ||
nextBlockId: getBlockConnection({ outputs }, outputIndex), | ||
}; | ||
} | ||
|
||
export default conditions; |
4 changes: 2 additions & 2 deletions
4
src/background/workflow-engine/blocks-handler/handler-execute-workflow.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/background/workflow-engine/blocks-handler/handler-export-data.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/background/workflow-engine/blocks-handler/handler-google-sheets.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 8 additions & 3 deletions
11
src/background/workflow-engine/blocks-handler/handler-insert-data.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/background/workflow-engine/blocks-handler/handler-javascript-code.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { getBlockConnection } from '../helper'; | ||
|
||
export async function javascriptCode({ outputs, data, ...block }, { refData }) { | ||
const nextBlockId = getBlockConnection({ outputs }); | ||
|
||
try { | ||
if (data.everyNewTab) { | ||
const isScriptExist = this.preloadScripts.find( | ||
({ id }) => id === block.id | ||
); | ||
|
||
if (!isScriptExist) { | ||
this.preloadScripts.push({ ...block, data }); | ||
} | ||
} | ||
if (!this.activeTab.id) { | ||
if (!data.everyNewTab) { | ||
throw new Error('no-tab'); | ||
} else { | ||
return { data: '', nextBlockId }; | ||
} | ||
} | ||
|
||
const result = await this._sendMessageToTab({ ...block, data, refData }); | ||
|
||
if (result?.variables) { | ||
Object.keys(result.variables).forEach((varName) => { | ||
this.setVariable(varName, result.variables[varName]); | ||
}); | ||
} | ||
if (result?.columns.insert) { | ||
const params = Array.isArray(result.columns.data) | ||
? result.columns.data | ||
: [result.columns.data]; | ||
|
||
this.addDataToColumn(params); | ||
} | ||
|
||
return { | ||
nextBlockId, | ||
data: result?.columns.data || {}, | ||
}; | ||
} catch (error) { | ||
error.nextBlockId = nextBlockId; | ||
|
||
throw error; | ||
} | ||
} | ||
|
||
export default javascriptCode; |
2 changes: 1 addition & 1 deletion
2
src/background/workflow-engine/blocks-handler/handler-loop-data.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.