From 32394fb8e251f2cd563818498e8663d08b4d2703 Mon Sep 17 00:00:00 2001 From: Jack Kavanagh Date: Fri, 18 Aug 2023 10:30:57 +0200 Subject: [PATCH] fix array length check (#6320) --- packages/insomnia/src/main/ipc/electron.ts | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/packages/insomnia/src/main/ipc/electron.ts b/packages/insomnia/src/main/ipc/electron.ts index 771434633..56c7245fc 100644 --- a/packages/insomnia/src/main/ipc/electron.ts +++ b/packages/insomnia/src/main/ipc/electron.ts @@ -34,26 +34,27 @@ export function registerElectronHandlers() { .sort((a, b) => fnOrString(a.templateTag.displayName).localeCompare(fnOrString(b.templateTag.displayName))) .map(l => { const actions = l.templateTag.args?.[0]; - const otherArgs = l.templateTag.args?.slice(1); + const additionalArgs = l.templateTag.args?.slice(1); const hasSubmenu = actions?.options?.length; return { label: fnOrString(l.templateTag.displayName), - ...(hasSubmenu ? {} : { - click: () => { - const tag = `{% ${l.templateTag.name} ${l.templateTag.args?.map(getTemplateValue).join(', ')} %}`; - event.sender.send('context-menu-command', { key: options.key, tag }); - }, - }), - ...(hasSubmenu ? { - submenu: actions?.options?.map(action => ({ - label: fnOrString(action.displayName), + ...(!hasSubmenu ? + { click: () => { - const defaultTagArgs = otherArgs ? ', ' + otherArgs.map(getTemplateValue).join(', ') : ''; - const tag = `{% ${l.templateTag.name} '${action.value}'${defaultTagArgs} %}`; + const tag = `{% ${l.templateTag.name} ${l.templateTag.args?.map(getTemplateValue).join(', ')} %}`; event.sender.send('context-menu-command', { key: options.key, tag }); }, - })), - } : {}), + } : + { + submenu: actions?.options?.map(action => ({ + label: fnOrString(action.displayName), + click: () => { + const additionalTagFields = additionalArgs.length ? ', ' + additionalArgs.map(getTemplateValue).join(', ') : ''; + const tag = `{% ${l.templateTag.name} '${action.value}'${additionalTagFields} %}`; + event.sender.send('context-menu-command', { key: options.key, tag }); + }, + })), + }), }; }),