Skip to content

fix: two bugs when workflow start #2007

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 49 additions & 3 deletions src/components/newtab/workflow/WorkflowEditBlock.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<template>
<div id="workflow-edit-block" class="scroll h-full overflow-auto px-4 pb-1">
<div id="workflow-edit-block" class="scroll h-full overflow-auto px-4 py-1">
<div
class="sticky top-0 z-20 mb-2 flex items-center space-x-2 bg-white pb-4 dark:bg-gray-800"
>
<button @click="$emit('close')">
<button @click="handleClose">
<v-remixicon name="riArrowLeftLine" />
</button>
<p class="inline-block font-semibold capitalize">
Expand Down Expand Up @@ -35,9 +35,10 @@
</div>
</template>
<script setup>
import customEditComponents from '@business/blocks/editComponents';
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';
import customEditComponents from '@business/blocks/editComponents';
import { useToast } from 'vue-toastification';

const editComponents = require.context(
'./edit',
Expand Down Expand Up @@ -78,6 +79,7 @@ const props = defineProps({
const emit = defineEmits(['close', 'update', 'update:autocomplete']);

const { t, te } = useI18n();
const toast = useToast();

const blockData = computed({
get() {
Expand All @@ -88,6 +90,50 @@ const blockData = computed({
},
});

function isGoogleSheetsBlock() {
return ['google-sheets'].includes(props.data.id);
}

function validateBeforeClose() {
// 检查是否为Google Sheets相关区块
if (isGoogleSheetsBlock()) {
// 检查spreadsheetId是否为空,且不是create或add-sheet操作
const { spreadsheetId, type, range } = blockData.value;
const isNotCreateAction = !['create', 'add-sheet'].includes(type);

if (isNotCreateAction) {
const errors = [];

if (!spreadsheetId) {
errors.push(
t(
'workflow.blocks.google-sheets.spreadsheetId.required',
'Spreadsheet ID is required'
)
);
}

if (!range) {
errors.push(
t('workflow.blocks.google-sheets.range.required', 'Range is required')
);
}

if (errors.length > 0) {
errors.forEach((error) => toast.error(error));
return false;
}
}
}
return true;
}

function handleClose() {
if (validateBeforeClose()) {
emit('close');
}
}

function getEditComponent() {
const editComp = props.data.editComponent;
if (typeof editComp === 'object') return editComp;
Expand Down
50 changes: 45 additions & 5 deletions src/components/newtab/workflow/edit/EditGoogleSheets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@
:model-value="data.range"
class="mt-1 w-full"
placeholder="Sheet1!A1:B2"
:class="{
'border-red-500':
!data.range && !['create', 'add-sheet'].includes(data.type),
}"
@change="updateData({ range: $event })"
>
<template #label>
Expand All @@ -69,6 +73,17 @@
<v-remixicon name="riInformationLine" size="18" class="inline" />
</a>
</template>
<template
v-if="!data.range && !['create', 'add-sheet'].includes(data.type)"
#footer
>
<span class="text-red-500 text-sm">{{
t(
'workflow.blocks.google-sheets.range.required',
'Range is required'
)
}}</span>
</template>
</ui-input>
</edit-autocomplete>
<template v-if="data.type === 'get'">
Expand Down Expand Up @@ -215,12 +230,12 @@
</div>
</template>
<script setup>
import { shallowReactive, defineAsyncComponent } from 'vue';
import { useI18n } from 'vue-i18n';
import { useToast } from 'vue-toastification';
import { fetchApi } from '@/utils/api';
import { convert2DArrayToArrayObj, debounce } from '@/utils/helper';
import googleSheetsApi from '@/utils/googleSheetsApi';
import { convert2DArrayToArrayObj, debounce } from '@/utils/helper';
import { defineAsyncComponent, shallowReactive } from 'vue';
import { useI18n } from 'vue-i18n';
import { useToast } from 'vue-toastification';
import EditAutocomplete from './EditAutocomplete.vue';
import InsertWorkflowData from './InsertWorkflowData.vue';

Expand Down Expand Up @@ -272,6 +287,21 @@ const state = shallowReactive({

const checkPermission = debounce(async (value) => {
try {
if (!value.trim()) {
toast.error('Spreadsheet id is empty');
return;
}

if (
value.includes('://') ||
value.startsWith('http') ||
value.startsWith('www.') ||
value.includes('docs.google.com')
) {
toast.error('Spreadsheet id is invalid');
return;
}

if (state.lastSheetId === value) return;

const response = await fetchApi(
Expand All @@ -298,7 +328,7 @@ async function previewData() {
spreadsheetId: props.data.spreadsheetId,
};

if (!props.data.spreadsheetId) {
if (!props.data.spreadsheetId.trim()) {
toast.error(
props.googleDrive
? 'No spreadsheet is selected'
Expand All @@ -307,6 +337,16 @@ async function previewData() {
previewDataState.status = 'idle';
return;
}

if (
props.data.spreadsheetId.includes('http') ||
props.data.spreadsheetId.includes('spreadsheets')
) {
toast.error('Spreadsheet Id is invalid, please check it');
previewDataState.status = 'idle';
return;
}

if (!props.data.range) {
toast.error('Spreadsheet range is empty');
previewDataState.status = 'idle';
Expand Down
14 changes: 8 additions & 6 deletions src/components/newtab/workflow/edit/EditPressKey.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@
</div>
</template>
<script setup>
import { ref, onBeforeUnmount } from 'vue';
import { useI18n } from 'vue-i18n';
import SharedElSelectorActions from '@/components/newtab/shared/SharedElSelectorActions.vue';
import { keyDefinitions } from '@/utils/USKeyboardLayout';
import { recordPressedKey } from '@/utils/recordKeys';
import SharedElSelectorActions from '@/components/newtab/shared/SharedElSelectorActions.vue';
import { onBeforeUnmount, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import EditAutocomplete from './EditAutocomplete.vue';

const props = defineProps({
Expand All @@ -100,10 +100,12 @@ const props = defineProps({
});
const emit = defineEmits(['update:data']);

const spaceKeys = ['\r', '\n', ' ', '\u0000'];

const includedKeys = ['Enter', 'Control', 'Meta', 'Shift', 'Alt', 'Space'];
const filteredDefinitions = Object.keys(keyDefinitions).filter(
(key) => key.trim().length <= 1 || key.startsWith('Arrow')
);
const filteredDefinitions = Object.keys(keyDefinitions)
.filter((key) => key.trim().length <= 1 || key.startsWith('Arrow'))
.filter((key) => !spaceKeys.includes(key));
const keysList = filteredDefinitions.concat(includedKeys);

const { t } = useI18n();
Expand Down
4 changes: 3 additions & 1 deletion src/components/newtab/workflow/editor/EditorLocalActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,9 @@ async function setAsHostWorkflow(isHost) {

try {
let url = '/me/workflows';
let payload = {};
let payload = {
auth: true,
};

if (isHost) {
const workflowPaylod = convertWorkflow(props.workflow, ['id']);
Expand Down
38 changes: 27 additions & 11 deletions src/components/newtab/workflows/WorkflowsShared.vue
Original file line number Diff line number Diff line change
@@ -1,19 +1,35 @@
<template>
<shared-card
v-for="workflow in workflows"
:key="workflow.id"
:data="workflow"
:show-details="false"
@execute="RendererWorkflowService.executeWorkflow(workflow)"
@click="$router.push(`/workflows/${$event.id}/shared`)"
/>
<div
v-if="workflows.length === 0"
class="md:flex items-center md:text-left text-center py-12"
>
<img src="@/assets/svg/alien.svg" class="w-96" />
<div class="ml-4">
<h1 class="mb-6 max-w-md text-2xl font-semibold">
{{ t('message.empty') }}
</h1>
</div>
</div>
<div v-else class="workflows-container">
<shared-card
v-for="workflow in workflows"
:key="workflow.id"
:data="workflow"
:show-details="false"
@execute="RendererWorkflowService.executeWorkflow(workflow)"
@click="$router.push(`/workflows/${$event.id}/shared`)"
/>
</div>
</template>
<script setup>
import { computed } from 'vue';
import { useSharedWorkflowStore } from '@/stores/sharedWorkflow';
import { arraySorter } from '@/utils/helper';
import SharedCard from '@/components/newtab/shared/SharedCard.vue';
import RendererWorkflowService from '@/service/renderer/RendererWorkflowService';
import { useSharedWorkflowStore } from '@/stores/sharedWorkflow';
import { arraySorter } from '@/utils/helper';
import { computed } from 'vue';
import { useI18n } from 'vue-i18n';

const { t } = useI18n();

const props = defineProps({
search: {
Expand Down
11 changes: 7 additions & 4 deletions src/content/blocksHandler/handlerForms.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import handleFormElement from '@/utils/handleFormElement';
import { sendMessage } from '@/utils/message';
import renderString from '@/workflowEngine/templating/renderString';
import handleSelector, { markElement } from '../handleSelector';
import synchronizedLock from '../synchronizedLock';

Expand Down Expand Up @@ -45,10 +46,12 @@ async function forms(block) {
);
}

const commands = data.value.split('').map((char) => ({
type: 'keyDown',
text: char === '\n' ? '\r' : char,
}));
const commands = renderString(data.value)
.split('')
.map((char) => ({
type: 'keyDown',
text: char === '\n' ? '\r' : char,
}));
const typeDelay = +block.data.delay;
await sendMessage(
'debugger:type',
Expand Down
6 changes: 4 additions & 2 deletions src/locales/en/blocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -438,11 +438,13 @@
},
"spreadsheetId": {
"label": "Spreadsheet Id",
"link": "See how to get spreadsheet Id"
"link": "See how to get spreadsheet Id",
"required": "Spreadsheet ID is required"
},
"range": {
"label": "Range",
"link": "Click to see more examples"
"link": "Click to see more examples",
"required": "Range is required"
},
"select": {
"get": "Get spreadsheet cell values",
Expand Down
6 changes: 4 additions & 2 deletions src/locales/en/newtab.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@
},
"messages": {
"hostExist": "You have already added this host",
"notFound": "Can't find a hosted workflow with the ID \"{id}\""
"notFound": "Can't find a hosted workflow with the ID \"{id}\"",
"successAdded": "Successfully added hosted workflow with the ID \"{id}\""
}
},
"type": {
Expand All @@ -298,7 +299,8 @@
"edit": "Edit description",
"fetchLocal": "Fetch local workflow",
"update": "Update",
"unpublish": "Unpublish"
"unpublish": "Unpublish",
"linkCopied": "Link copied to clipboard"
},
"variables": {
"title": "Variable | Variables",
Expand Down
6 changes: 4 additions & 2 deletions src/locales/es/newtab.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@
},
"messages": {
"hostExist": "Ya ha añadido este host",
"notFound": "No se puede encontrar un flujo de trabajo alojado con el ID \"{id}\""
"notFound": "No se puede encontrar un flujo de trabajo alojado con el ID \"{id}\"",
"successAdded": "Flujo de trabajo anfitrión añadido con éxito con el ID \"{id}\""
}
},
"type": {
Expand All @@ -298,7 +299,8 @@
"edit": "Editar descripción",
"fetchLocal": "Obtener flujo de trabajo local",
"update": "Actualización",
"unpublish": "Anule la publicación"
"unpublish": "Anule la publicación",
"linkCopied": "Enlace copiado al portapapeles"
},
"variables": {
"title": "Variable | Variables",
Expand Down
6 changes: 4 additions & 2 deletions src/locales/fr/newtab.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@
},
"messages": {
"hostExist": "Vous avez déjà ajouté cet hôte",
"notFound": "Impossible de trouver le workflow hébergé avec l'identifiant \"{id}\""
"notFound": "Impossible de trouver le workflow hébergé avec l'identifiant \"{id}\"",
"successAdded": "Workflow hébergé ajouté avec succès avec l'identifiant \"{id}\""
}
},
"type": {
Expand All @@ -112,7 +113,8 @@
"edit": "Éditer la description",
"fetchLocal": "Récupérer le workflow local",
"update": "Mettre à jour",
"unpublish": "Annuler la publication"
"unpublish": "Annuler la publication",
"linkCopied": "Lien copié dans le presse-papiers"
},
"variables": {
"title": "Variable | Variables",
Expand Down
6 changes: 4 additions & 2 deletions src/locales/it/newtab.json
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@
},
"messages": {
"hostExist": "Hai già aggiunto questo host",
"notFound": "Impossibile trovare un workflow ospitato con l'ID \"{id}\""
"notFound": "Impossibile trovare un workflow ospitato con l'ID \"{id}\"",
"successAdded": "Workflow ospitato aggiunto con successo con l'ID \"{id}\""
}
},
"type": {
Expand All @@ -260,7 +261,8 @@
"edit": "Modifica descrizione",
"fetchLocal": "Recupera workflow locale",
"update": "Aggiorna",
"unpublish": "Annulla pubblicazione"
"unpublish": "Annulla pubblicazione",
"linkCopied": "Link copiato negli appunti"
},
"variables": {
"title": "Variabile | Variabili",
Expand Down
Loading