feat(core): Fix populating of node custom api call options (#5303)

* feat(core): Fix populating of node custom api call options

* lint fixes

* Adress PR comments

* Add e2e test and only inject custom API options for latest version

* Make sure to injectCustomApiCallOption for the latest version of node
This commit is contained in:
OlegIvaniv
2023-02-02 14:53:08 +01:00
committed by GitHub
parent 6cba652ff9
commit e58bc41d24
8 changed files with 78 additions and 85 deletions

View File

@@ -233,7 +233,7 @@ const telemetry = instance?.proxy.$telemetry;
const { categorizedItems: allNodes, isTriggerNode } = useNodeTypesStore();
const containsAPIAction = computed(
() =>
state.latestNodeData?.properties.some((p) =>
activeNodeActions.value?.properties.some((p) =>
p.options?.find((o) => o.name === CUSTOM_API_CALL_NAME),
) === true,
);
@@ -338,27 +338,10 @@ function getCustomAPICallHintLocale(key: string) {
interpolate: { nodeNameTitle },
});
}
// The nodes.json doesn't contain API CALL option so we need to fetch the node detail
// to determine if need to render the API CALL hint
async function fetchNodeDetails() {
if (!state.activeNodeActions) return;
const { getNodesInformation } = useNodeTypesStore();
const { version, name } = state.activeNodeActions;
const payload = {
name,
version: Array.isArray(version) ? version?.slice(-1)[0] : version,
} as INodeTypeNameVersion;
const nodesInfo = await getNodesInformation([payload], false);
state.latestNodeData = nodesInfo[0];
}
function setActiveActionsNodeType(nodeType: INodeTypeDescription | null) {
state.activeNodeActions = nodeType;
setShowTabs(false);
fetchNodeDetails();
if (nodeType) trackActionsView();
}

View File

@@ -116,7 +116,11 @@
</n8n-text>
</div>
<div v-if="isCustomApiCallSelected(nodeValues)" class="parameter-item parameter-notice">
<div
v-if="isCustomApiCallSelected(nodeValues)"
class="parameter-item parameter-notice"
data-test-id="node-parameters-http-notice"
>
<n8n-notice
:content="
$locale.baseText('nodeSettings.useTheHttpRequestNode', {

View File

@@ -56,9 +56,12 @@ const customNodeActionsParsers: {
},
};
function filterSinglePlaceholderAction(actions: INodeActionTypeDescription[]) {
function filterActions(actions: INodeActionTypeDescription[]) {
return actions.filter(
(action: INodeActionTypeDescription, _: number, arr: INodeActionTypeDescription[]) => {
const isApiCall = action.actionKey === CUSTOM_API_CALL_KEY;
if (isApiCall) return false;
const isPlaceholderTriggerAction = action.actionKey === PLACEHOLDER_RECOMMENDED_ACTION_KEY;
return !isPlaceholderTriggerAction || (isPlaceholderTriggerAction && arr.length > 1);
},
@@ -339,7 +342,7 @@ export const useNodeCreatorStore = defineStore(STORES.NODE_CREATOR, {
const filteredNodes = Object.values(mergedNodes).map((node) => ({
...node,
actions: filterSinglePlaceholderAction(node.actions || []),
actions: filterActions(node.actions || []),
}));
return filteredNodes;