feat(editor): Implement loading and error states for dynamically loaded components in node parameter list (#8477)

This commit is contained in:
Milorad FIlipović
2024-01-30 14:27:42 +01:00
committed by GitHub
parent 121a55b691
commit e643a126f4
5 changed files with 65 additions and 32 deletions

View File

@@ -65,26 +65,38 @@
:underline="true"
color="text-dark"
/>
<Suspense>
<CollectionParameter
v-if="parameter.type === 'collection'"
:parameter="parameter"
:values="nodeHelpers.getParameterValue(nodeValues, parameter.name, path)"
:node-values="nodeValues"
:path="getPath(parameter.name)"
:is-read-only="isReadOnly"
@valueChanged="valueChanged"
/>
<FixedCollectionParameter
v-else-if="parameter.type === 'fixedCollection'"
:parameter="parameter"
:values="nodeHelpers.getParameterValue(nodeValues, parameter.name, path)"
:node-values="nodeValues"
:path="getPath(parameter.name)"
:is-read-only="isReadOnly"
@valueChanged="valueChanged"
/>
<Suspense v-if="!asyncLoadingError">
<template #default>
<CollectionParameter
v-if="parameter.type === 'collection'"
:parameter="parameter"
:values="nodeHelpers.getParameterValue(nodeValues, parameter.name, path)"
:node-values="nodeValues"
:path="getPath(parameter.name)"
:is-read-only="isReadOnly"
@valueChanged="valueChanged"
/>
<FixedCollectionParameter
v-else-if="parameter.type === 'fixedCollection'"
:parameter="parameter"
:values="nodeHelpers.getParameterValue(nodeValues, parameter.name, path)"
:node-values="nodeValues"
:path="getPath(parameter.name)"
:is-read-only="isReadOnly"
@valueChanged="valueChanged"
/>
</template>
<template #fallback>
<n8n-text size="small" class="async-notice">
<n8n-icon icon="sync-alt" size="xsmall" :spin="true" />
{{ $locale.baseText('parameterInputList.loadingFields') }}
</n8n-text>
</template>
</Suspense>
<n8n-text v-else size="small" color="danger" class="async-notice">
<n8n-icon icon="exclamation-triangle" size="xsmall" />
{{ $locale.baseText('parameterInputList.loadingError') }}
</n8n-text>
</div>
<ResourceMapper
v-else-if="parameter.type === 'resourceMapper'"
@@ -150,7 +162,7 @@ import type {
import { deepCopy } from 'n8n-workflow';
import { mapStores } from 'pinia';
import type { PropType } from 'vue';
import { defineAsyncComponent, defineComponent } from 'vue';
import { defineAsyncComponent, defineComponent, onErrorCaptured, ref } from 'vue';
import type { INodeUi, IUpdateInformation } from '@/Interface';
@@ -226,9 +238,31 @@ export default defineComponent({
},
setup() {
const nodeHelpers = useNodeHelpers();
const asyncLoadingError = ref(false);
// This will catch errors in async components
onErrorCaptured((e, component) => {
if (
!['FixedCollectionParameter', 'CollectionParameter'].includes(
component?.$options.name as string,
)
) {
return;
}
asyncLoadingError.value = true;
console.error(e);
window?.Sentry?.captureException(e, {
tags: {
asyncLoadingError: true,
},
});
// Don't propagate the error further
return false;
});
return {
nodeHelpers,
asyncLoadingError,
};
},
computed: {
@@ -572,5 +606,10 @@ export default defineComponent({
font-weight: var(--font-weight-bold);
}
}
.async-notice {
display: block;
padding: var(--spacing-3xs) 0;
}
}
</style>