Skip to content

Commit f6ae6a3

Browse files
authored
Merge pull request #1618 from AutomaApp/dev
Dev
2 parents 5051c3f + 1332572 commit f6ae6a3

File tree

11 files changed

+157
-43
lines changed

11 files changed

+157
-43
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "automa",
3-
"version": "1.28.25",
3+
"version": "1.28.26",
44
"description": "An extension for automating your browser by connecting blocks",
55
"repository": {
66
"type": "git",

src/components/newtab/logs/LogsVariables.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
readonly
3030
/>
3131
<ui-input
32-
:model-value="JSON.stringify(varValue)"
32+
:model-value="
33+
typeof varValue === 'string' ? varValue : JSON.stringify(varValue)
34+
"
3335
label="Value"
3436
class="w-full"
3537
placeholder="EMPTY"

src/components/newtab/storage/StorageEditTable.vue

Lines changed: 47 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
style="height: 600px"
77
>
88
<p class="p-4 font-semibold">
9-
{{ t('storage.table.add') }}
9+
{{ title || t('storage.table.add') }}
1010
</p>
1111
<div class="scroll flex-1 overflow-auto px-4 pb-4">
1212
<ui-input
@@ -27,32 +27,43 @@
2727
>
2828
{{ t('message.noData') }}
2929
</p>
30-
<ul class="mt-4 space-y-2">
31-
<li
32-
v-for="(column, index) in state.columns"
33-
:key="column.id"
34-
class="flex items-center space-x-2"
35-
>
36-
<ui-input
37-
:model-value="column.name"
38-
:placeholder="t('workflow.table.column.name')"
39-
class="flex-1"
40-
@blur="updateColumnName(index, $event.target)"
41-
/>
42-
<ui-select
43-
v-model="column.type"
44-
class="flex-1"
45-
:placeholder="t('workflow.table.column.type')"
46-
>
47-
<option v-for="type in dataTypes" :key="type.id" :value="type.id">
48-
{{ type.name }}
49-
</option>
50-
</ui-select>
51-
<button @click="deleteColumn(index)">
52-
<v-remixicon name="riDeleteBin7Line" />
53-
</button>
54-
</li>
55-
</ul>
30+
<draggable
31+
v-model="state.columns"
32+
tag="ul"
33+
handle=".handle"
34+
item-key="id"
35+
class="mt-4 space-y-2"
36+
>
37+
<template #item="{ element: column, index }">
38+
<li class="flex items-center space-x-2">
39+
<span class="handle cursor-move">
40+
<v-remixicon name="mdiDrag" />
41+
</span>
42+
<ui-input
43+
:model-value="column.name"
44+
:placeholder="t('workflow.table.column.name')"
45+
class="flex-1"
46+
@blur="updateColumnName(index, $event.target)"
47+
/>
48+
<ui-select
49+
v-model="column.type"
50+
class="flex-1"
51+
:placeholder="t('workflow.table.column.type')"
52+
>
53+
<option
54+
v-for="type in dataTypes"
55+
:key="type.id"
56+
:value="type.id"
57+
>
58+
{{ type.name }}
59+
</option>
60+
</ui-select>
61+
<button @click="deleteColumn(index)">
62+
<v-remixicon name="riDeleteBin7Line" />
63+
</button>
64+
</li>
65+
</template>
66+
</draggable>
5667
</div>
5768
<div class="p-4 text-right">
5869
<ui-button class="mr-4" @click="clearTempTables(true)">
@@ -73,6 +84,7 @@
7384
import { reactive, toRaw, watch } from 'vue';
7485
import { useI18n } from 'vue-i18n';
7586
import { nanoid } from 'nanoid';
87+
import draggable from 'vuedraggable';
7688
import cloneDeep from 'lodash.clonedeep';
7789
import { dataTypes } from '@/utils/constants/table';
7890
@@ -85,6 +97,10 @@ const props = defineProps({
8597
type: String,
8698
default: '',
8799
},
100+
title: {
101+
type: String,
102+
default: '',
103+
},
88104
columns: {
89105
type: Array,
90106
default: () => [],
@@ -122,7 +138,10 @@ function updateColumnName(index, target) {
122138
state.columns[index].name = columnName;
123139
}
124140
function saveTable() {
125-
const rawState = toRaw(state);
141+
const rawState = {
142+
...toRaw(state),
143+
columns: state.columns.map(toRaw),
144+
};
126145
127146
emit('save', { ...rawState, changes });
128147
}

src/execute/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Execute</title>
7+
</head>
8+
<body>
9+
</body>
10+
</html>

src/execute/index.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import { parseJSON } from '@/utils/helper';
2+
import { sendMessage } from '@/utils/message';
3+
import Browser from 'webextension-polyfill';
4+
5+
function getWorkflowDetail() {
6+
let hash = window.location.hash.slice(1);
7+
if (!hash.startsWith('/')) hash = `/${hash}`;
8+
9+
const { pathname, searchParams } = new URL(window.location.origin + hash);
10+
11+
const variables = {};
12+
const { 1: workflowId } = pathname.split('/');
13+
14+
searchParams.forEach((key, value) => {
15+
const varValue = parseJSON(decodeURIComponent(value), '##_empty');
16+
if (varValue === '##_empty') return;
17+
18+
variables[key] = varValue;
19+
});
20+
21+
return { workflowId: workflowId ?? '', variables };
22+
}
23+
24+
function writeResult(text) {
25+
document.body.innerText = text;
26+
}
27+
28+
(async () => {
29+
try {
30+
const { workflowId, variables } = getWorkflowDetail();
31+
if (!workflowId) {
32+
writeResult('Invalid path');
33+
return;
34+
}
35+
36+
const { workflows } = await Browser.storage.local.get('workflows');
37+
38+
let workflow = workflows[workflowId];
39+
if (!workflow && Array.isArray(workflows)) {
40+
workflow = workflows.find((item) => item.id === workflowId);
41+
}
42+
43+
if (!workflow) {
44+
writeResult('Workflow not found');
45+
return;
46+
}
47+
48+
const hasVariables = Object.keys(variables).length > 0;
49+
50+
writeResult('Executing workflow');
51+
52+
sendMessage(
53+
'workflow:execute',
54+
{
55+
...workflow,
56+
options: { checkParam: !hasVariables, data: { variables } },
57+
},
58+
'background'
59+
).then(() => {
60+
setTimeout(window.close, 1000);
61+
});
62+
} catch (error) {
63+
console.error(error);
64+
}
65+
})();

src/locales/en/newtab.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"title": "Storage",
4343
"table": {
4444
"add": "Add table",
45+
"edit": "Edit table",
4546
"createdAt": "Created at",
4647
"modifiedAt": "Modified at",
4748
"rowsCount": "Rows count",

src/newtab/pages/settings/SettingsBackup.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ async function backupWorkflows() {
336336
337337
return acc;
338338
}, []);
339+
339340
const payload = {
340341
isProtected: state.encrypt,
341342
workflows: JSON.stringify(workflows),
@@ -409,7 +410,9 @@ async function restoreWorkflows() {
409410
};
410411
411412
if (state.updateIfExists) {
412-
return workflowStore.insertOrUpdate(newWorkflows).then(showMessage);
413+
return workflowStore
414+
.insertOrUpdate(newWorkflows, { duplicateId: true })
415+
.then(showMessage);
413416
}
414417
415418
return workflowStore.insert(newWorkflows).then(showMessage);

src/newtab/pages/storage/Tables.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
</div>
7676
<storage-edit-table
7777
v-model="editState.show"
78+
:title="t('storage.table.edit')"
7879
:name="editState.name"
7980
:columns="editState.columns"
8081
@save="saveEditedTable"

src/stores/workflow.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const defaultWorkflow = (data = null, options = {}) => {
4747
settings: {
4848
publicId: '',
4949
blockDelay: 0,
50-
saveLog: false,
50+
saveLog: true,
5151
debugMode: false,
5252
restartTimes: 3,
5353
notification: true,
@@ -211,11 +211,15 @@ export const useWorkflowStore = defineStore('workflow', {
211211

212212
return updatedWorkflows;
213213
},
214-
async insertOrUpdate(data = [], { checkUpdateDate = false } = {}) {
214+
async insertOrUpdate(
215+
data = [],
216+
{ checkUpdateDate = false, duplicateId = false } = {}
217+
) {
215218
const insertedData = {};
216219

217220
data.forEach((item) => {
218221
const currentWorkflow = this.workflows[item.id];
222+
219223
if (currentWorkflow) {
220224
let insert = true;
221225
if (checkUpdateDate && currentWorkflow.createdAt && item.updatedAt) {
@@ -229,7 +233,7 @@ export const useWorkflowStore = defineStore('workflow', {
229233
insertedData[item.id] = mergedData;
230234
}
231235
} else {
232-
const workflow = defaultWorkflow(item);
236+
const workflow = defaultWorkflow(item, { duplicateId });
233237
this.workflows[workflow.id] = workflow;
234238
insertedData[workflow.id] = workflow;
235239
}

src/workflowEngine/blocksHandler/handlerBlockPackage.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,23 @@ export default async function (
3030
const outputsMap = new Set();
3131

3232
data.inputs.forEach((item) => {
33-
connections[addBlockPrefix(item.id)] = [
34-
{
35-
id: addBlockPrefix(item.blockId),
36-
targetId: `${addBlockPrefix(block.id)}-input-1`,
37-
},
38-
];
33+
connections[addBlockPrefix(item.id)] = new Map([
34+
[
35+
item.id,
36+
{
37+
id: addBlockPrefix(item.blockId),
38+
targetId: `${addBlockPrefix(block.id)}-input-1`,
39+
},
40+
],
41+
]);
3942
});
4043
data.outputs.forEach((output) => {
41-
outputsMap.add(output.handleId);
42-
4344
const connection =
4445
this.engine.connectionsMap[`${id}-output-${output.id}`];
4546
if (!connection) return;
4647

47-
connections[addBlockPrefix(output.handleId)] = [...connection.values()];
48+
connections[addBlockPrefix(output.handleId)] = new Map(connection);
49+
outputsMap.add(output.handleId);
4850
});
4951

5052
data.data.nodes.forEach((node) => {

0 commit comments

Comments
 (0)