fix: handle better case when workflow id is missing

This commit is contained in:
Mutasem Aldmour 2024-11-11 10:57:10 +01:00
parent 2db0b140bd
commit 9d6f0c5dec
No known key found for this signature in database
GPG key ID: 3DFA8122BB7FD6B8
3 changed files with 33 additions and 4 deletions

View file

@ -3,6 +3,8 @@ import { convertToDisplayDate } from '@/utils/formatters/dateFormatter';
import { useI18n } from '@/composables/useI18n';
import { useRouter } from 'vue-router';
import { VIEWS } from '@/constants';
import { useExecutionsStore } from '@/stores/executions.store';
import { useToast } from './useToast';
export interface IExecutionUIData {
name: string;
@ -17,6 +19,8 @@ export interface IExecutionUIData {
export function useExecutionHelpers() {
const i18n = useI18n();
const router = useRouter();
const executionsStore = useExecutionsStore();
const toast = useToast();
function getUIDetails(execution: ExecutionSummary): IExecutionUIData {
const status = {
@ -72,8 +76,7 @@ export function useExecutionHelpers() {
return ['crashed', 'error'].includes(execution.status) && !execution.retrySuccessId;
}
function openExecutionInNewTab(executionId: string, workflowId?: string) {
// todo this does not work when workflowId is not set
function openInNewTab(executionId: string, workflowId: string) {
const route = router.resolve({
name: VIEWS.EXECUTION_PREVIEW,
params: { name: workflowId, executionId },
@ -81,6 +84,29 @@ export function useExecutionHelpers() {
window.open(route.href, '_blank');
}
async function openExecutionById(executionId: string): Promise<void> {
try {
const execution = (await executionsStore.fetchExecution(executionId)) as ExecutionSummary;
openInNewTab(executionId, execution.workflowId);
} catch (e) {
toast.showMessage({
type: 'error',
message: i18n.baseText('nodeView.showError.openExecution.title'),
});
}
}
function openExecutionInNewTab(executionId: string, workflowId?: string): void {
// todo this does not work when workflowId is not set
if (!workflowId) {
void openExecutionById(executionId);
return;
}
openInNewTab(executionId, workflowId);
}
return {
getUIDetails,
formatDate,

View file

@ -2614,7 +2614,7 @@
"executionUsage.button.upgrade": "Upgrade plan",
"executionUsage.expired.text": "Your trial is over. Upgrade now to keep your data.",
"executionUsage.ranOutOfExecutions.text": "Youre out of executions. Upgrade your plan to keep automating.",
"executionsView.missingExeuctionId": "Could not find execution. Make sure workflow saving is turned on.",
"openExecution.missingExeuctionId": "Could not find execution. Make sure workflow saving is turned on.",
"type.string": "String",
"type.number": "Number",
"type.dateTime": "Date & Time",

View file

@ -25,6 +25,7 @@ const route = useRoute();
const router = useRouter();
const toast = useToast();
const { callDebounced } = useDebounce();
const workflowHelpers = useWorkflowHelpers({ router });
const nodeHelpers = useNodeHelpers();
@ -104,8 +105,10 @@ async function fetchExecution() {
if (!currentExecution.value) {
toast.showMessage({
type: 'error',
message: i18n.baseText('executionsView.missingExeuctionId'),
message: i18n.baseText('openExecution.missingExeuctionId'),
});
return;
}
}