mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
fix: refactor more
This commit is contained in:
parent
ad990236eb
commit
785b30e675
|
@ -202,17 +202,13 @@ export interface IStartRunData {
|
|||
runData?: IRunData;
|
||||
}
|
||||
|
||||
export interface SubworkflowExecutionInfo {
|
||||
executionId: string;
|
||||
workflowId?: string;
|
||||
}
|
||||
export interface ITableData {
|
||||
columns: string[];
|
||||
data: GenericValue[][];
|
||||
hasJson: { [key: string]: boolean };
|
||||
metadata: {
|
||||
hasExecutionIds: boolean;
|
||||
data: Array<SubworkflowExecutionInfo | undefined>;
|
||||
data: Array<INodeExecutionData['metadata'] | undefined>;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -182,7 +182,7 @@ const nodeHelpers = useNodeHelpers();
|
|||
const externalHooks = useExternalHooks();
|
||||
const telemetry = useTelemetry();
|
||||
const i18n = useI18n();
|
||||
const { openExecutionInNewTab } = useExecutionHelpers();
|
||||
const { openRelatedExecution } = useExecutionHelpers();
|
||||
|
||||
const node = toRef(props, 'node');
|
||||
|
||||
|
@ -514,7 +514,6 @@ const subWorkflowData = computed((): ITaskMetadata | null => {
|
|||
return null;
|
||||
}
|
||||
const metadata = get(workflowRunData.value, [node.value.name, props.runIndex, 'metadata'], null);
|
||||
console.log('yo', metadata);
|
||||
if (!metadata?.parentExecution && !metadata?.subExecution) {
|
||||
return null;
|
||||
}
|
||||
|
@ -1210,22 +1209,6 @@ function onSearchClear() {
|
|||
document.dispatchEvent(new KeyboardEvent('keyup', { key: '/' }));
|
||||
}
|
||||
|
||||
function onOpenRelatedExecution({ parentExecution, subExecution }: ITaskMetadata) {
|
||||
const info = parentExecution || subExecution;
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
|
||||
openExecutionInNewTab(info.executionId, info.workflowId);
|
||||
|
||||
telemetry.track(
|
||||
parentExecution ? 'User clicked parent execution button' : 'User clicked inspect sub-workflow',
|
||||
{
|
||||
view: displayMode.value,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
defineExpose({ enterEditMode });
|
||||
</script>
|
||||
|
||||
|
@ -1454,7 +1437,7 @@ defineExpose({ enterEditMode });
|
|||
v-if="subWorkflowData && !(paneType === 'input' && hasInputOverwrite)"
|
||||
:class="$style.parentExecutionInfo"
|
||||
>
|
||||
<a @click.stop="onOpenRelatedExecution(subWorkflowData)">
|
||||
<a @click.stop="openRelatedExecution(subWorkflowData, displayMode)">
|
||||
<N8nIcon icon="external-link-alt" size="xsmall" />
|
||||
{{
|
||||
subWorkflowData.parentExecution
|
||||
|
|
|
@ -12,7 +12,6 @@ import { computed } from 'vue';
|
|||
import NodeIcon from '@/components/NodeIcon.vue';
|
||||
import AiRunContentBlock from './AiRunContentBlock.vue';
|
||||
import { useExecutionHelpers } from '@/composables/useExecutionHelpers';
|
||||
import { useTelemetry } from '@/composables/useTelemetry';
|
||||
|
||||
interface RunMeta {
|
||||
startTimeMs: number;
|
||||
|
@ -33,9 +32,7 @@ const props = defineProps<{
|
|||
const nodeTypesStore = useNodeTypesStore();
|
||||
const workflowsStore = useWorkflowsStore();
|
||||
|
||||
const telemetry = useTelemetry();
|
||||
|
||||
const { openExecutionInNewTab } = useExecutionHelpers();
|
||||
const { openRelatedExecution } = useExecutionHelpers();
|
||||
|
||||
type TokenUsageData = {
|
||||
completionTokens: number;
|
||||
|
@ -111,15 +108,6 @@ const outputError = computed(() => {
|
|||
| NodeError
|
||||
| undefined;
|
||||
});
|
||||
|
||||
// todo unify function across components
|
||||
function openExecution({ executionId, workflowId }: { workflowId: string; executionId: string }) {
|
||||
openExecutionInNewTab(executionId, workflowId);
|
||||
|
||||
telemetry.track('User clicked inspect sub-workflow', {
|
||||
view: 'ai',
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
|
@ -152,7 +140,7 @@ function openExecution({ executionId, workflowId }: { workflowId: string; execut
|
|||
</n8n-tooltip>
|
||||
</li>
|
||||
<li v-if="runMeta?.subExecution">
|
||||
<a @click.stop="openExecution(runMeta.subExecution)">
|
||||
<a @click.stop="openRelatedExecution(runMeta, 'ai')">
|
||||
<N8nIcon icon="external-link-alt" size="xsmall" />
|
||||
{{ $locale.baseText('runData.openSubExecution') }}
|
||||
</a>
|
||||
|
|
|
@ -1,11 +1,6 @@
|
|||
<script setup lang="ts">
|
||||
import { useExternalHooks } from '@/composables/useExternalHooks';
|
||||
import type {
|
||||
INodeUi,
|
||||
IRunDataDisplayMode,
|
||||
ITableData,
|
||||
SubworkflowExecutionInfo,
|
||||
} from '@/Interface';
|
||||
import type { INodeUi, IRunDataDisplayMode, ITableData } from '@/Interface';
|
||||
import { useNDVStore } from '@/stores/ndv.store';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { getMappedExpression } from '@/utils/mappingUtils';
|
||||
|
@ -69,7 +64,7 @@ const workflowsStore = useWorkflowsStore();
|
|||
|
||||
const i18n = useI18n();
|
||||
const telemetry = useTelemetry();
|
||||
const { openExecutionInNewTab } = useExecutionHelpers();
|
||||
const { openRelatedExecution } = useExecutionHelpers();
|
||||
|
||||
const {
|
||||
hoveringItem,
|
||||
|
@ -346,11 +341,8 @@ function convertToTable(inputData: INodeExecutionData[]): ITableData {
|
|||
leftEntryColumns = entryColumns;
|
||||
}
|
||||
|
||||
if (data.metadata?.executionId) {
|
||||
metadata.data.push({
|
||||
executionId: data.metadata.executionId,
|
||||
workflowId: data.metadata?.workflowId,
|
||||
});
|
||||
if (data.metadata?.subExecution) {
|
||||
metadata.data.push(data.metadata);
|
||||
metadata.hasExecutionIds = true;
|
||||
} else {
|
||||
metadata.data.push(undefined);
|
||||
|
@ -410,14 +402,6 @@ function switchToJsonView() {
|
|||
emit('displayModeChange', 'json');
|
||||
}
|
||||
|
||||
function openExecution({ executionId, workflowId }: SubworkflowExecutionInfo) {
|
||||
openExecutionInNewTab(executionId, workflowId);
|
||||
|
||||
telemetry.track('User clicked inspect sub-workflow', {
|
||||
view: 'table',
|
||||
});
|
||||
}
|
||||
|
||||
watch(focusedMappableInput, (curr) => {
|
||||
setTimeout(
|
||||
() => {
|
||||
|
@ -562,7 +546,7 @@ watch(focusedMappableInput, (curr) => {
|
|||
icon="external-link-alt"
|
||||
data-test-id="debug-sub-execution"
|
||||
size="mini"
|
||||
@click="openExecution(tableData.metadata.data[index1])"
|
||||
@click="openRelatedExecution(tableData.metadata.data[index1], 'table')"
|
||||
/>
|
||||
</td>
|
||||
<td
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import type { ExecutionSummary } from 'n8n-workflow';
|
||||
import type { ExecutionSummary, RelatedExecution } from 'n8n-workflow';
|
||||
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';
|
||||
import { useTelemetry } from './useTelemetry';
|
||||
import type { IRunDataDisplayMode } from '@/Interface';
|
||||
|
||||
export interface IExecutionUIData {
|
||||
name: string;
|
||||
|
@ -19,8 +19,7 @@ export interface IExecutionUIData {
|
|||
export function useExecutionHelpers() {
|
||||
const i18n = useI18n();
|
||||
const router = useRouter();
|
||||
const executionsStore = useExecutionsStore();
|
||||
const toast = useToast();
|
||||
const telemetry = useTelemetry();
|
||||
|
||||
function getUIDetails(execution: ExecutionSummary): IExecutionUIData {
|
||||
const status = {
|
||||
|
@ -76,35 +75,34 @@ export function useExecutionHelpers() {
|
|||
return ['crashed', 'error'].includes(execution.status) && !execution.retrySuccessId;
|
||||
}
|
||||
|
||||
function openInNewTab(executionId: string, workflowId: string) {
|
||||
function openExecutionInNewTab(executionId: string, workflowId: string): void {
|
||||
const route = router.resolve({
|
||||
name: VIEWS.EXECUTION_PREVIEW,
|
||||
params: { name: workflowId, executionId },
|
||||
});
|
||||
|
||||
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);
|
||||
function openRelatedExecution(
|
||||
metadata: { parentExecution?: RelatedExecution; subExecution?: RelatedExecution },
|
||||
view: IRunDataDisplayMode,
|
||||
) {
|
||||
const info = metadata.parentExecution || metadata.subExecution;
|
||||
if (!info) {
|
||||
return;
|
||||
}
|
||||
|
||||
openInNewTab(executionId, workflowId);
|
||||
openExecutionInNewTab(info.executionId, info.workflowId);
|
||||
|
||||
telemetry.track(
|
||||
metadata.parentExecution
|
||||
? 'User clicked parent execution button'
|
||||
: 'User clicked inspect sub-workflow',
|
||||
{
|
||||
view,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
|
@ -112,5 +110,6 @@ export function useExecutionHelpers() {
|
|||
formatDate,
|
||||
isExecutionRetriable,
|
||||
openExecutionInNewTab,
|
||||
openRelatedExecution,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -211,6 +211,7 @@ export class ExecuteWorkflow implements INodeType {
|
|||
const items = this.getInputData();
|
||||
|
||||
const workflowProxy = this.getWorkflowDataProxy(0);
|
||||
const currentWorkflowId = workflowProxy.$workflow.id as string;
|
||||
|
||||
if (mode === 'each') {
|
||||
const returnData: INodeExecutionData[][] = [];
|
||||
|
@ -244,8 +245,10 @@ export class ExecuteWorkflow implements INodeType {
|
|||
for (const item of outputData) {
|
||||
item.pairedItem = { item: i };
|
||||
item.metadata = {
|
||||
executionId: executionResult.executionId,
|
||||
workflowId: workflowInfo.id,
|
||||
subExecution: {
|
||||
executionId: executionResult.executionId,
|
||||
workflowId: workflowInfo.id ?? currentWorkflowId,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -278,7 +281,10 @@ export class ExecuteWorkflow implements INodeType {
|
|||
returnData[0].push({
|
||||
...items[i],
|
||||
metadata: {
|
||||
executionId: executionResult.executionId,
|
||||
subExecution: {
|
||||
workflowId: workflowInfo.id ?? currentWorkflowId,
|
||||
executionId: executionResult.executionId,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1215,8 +1215,7 @@ export interface INodeExecutionData {
|
|||
error?: NodeApiError | NodeOperationError;
|
||||
pairedItem?: IPairedItemData | IPairedItemData[] | number;
|
||||
metadata?: {
|
||||
executionId?: string;
|
||||
workflowId?: string;
|
||||
subExecution: RelatedExecution;
|
||||
};
|
||||
index?: number;
|
||||
}
|
||||
|
@ -2142,16 +2141,15 @@ export interface ITaskSubRunMetadata {
|
|||
runIndex: number;
|
||||
}
|
||||
|
||||
export interface RelatedExecution {
|
||||
executionId: string;
|
||||
workflowId: string;
|
||||
}
|
||||
|
||||
export interface ITaskMetadata {
|
||||
parentExecution?: {
|
||||
executionId: string;
|
||||
workflowId: string;
|
||||
};
|
||||
subExecution?: {
|
||||
executionId: string;
|
||||
workflowId: string;
|
||||
};
|
||||
subRun?: ITaskSubRunMetadata[];
|
||||
parentExecution?: RelatedExecution;
|
||||
subExecution?: RelatedExecution;
|
||||
}
|
||||
|
||||
// The data that gets returned when a node runs
|
||||
|
|
Loading…
Reference in a new issue