fix(editor): Disable Ask AI button in deprecated nodes (no-changelog) (#11194)

This commit is contained in:
Ricardo Espinoza 2024-10-11 09:36:27 -04:00 committed by GitHub
parent 6e990175c7
commit 98759701e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 43 additions and 1 deletions

View file

@ -840,6 +840,7 @@ exports[`AskAssistantChat > renders default placeholder chat correctly 1`] = `
For specific tasks, youll see the
<button
class="button"
data-test-id="ask-assistant-button"
style="height: 18px;"
tabindex="-1"
>
@ -1082,6 +1083,7 @@ exports[`AskAssistantChat > renders end of session chat correctly 1`] = `
</span>
<button
class="button"
data-test-id="ask-assistant-button"
style="height: 18px;"
tabindex="-1"
>

View file

@ -50,6 +50,7 @@ const onClick = () => {
:style="{ height: sizes[size].height }"
:disabled="asked"
:tabindex="static ? '-1' : ''"
data-test-id="ask-assistant-button"
@click="onClick"
>
<div>

View file

@ -121,7 +121,8 @@ const isAskAssistantAvailable = computed(() => {
return false;
}
const isCustomNode = node.value.type === undefined || isCommunityPackageName(node.value.type);
return assistantStore.canShowAssistantButtonsOnCanvas && !isCustomNode;
return assistantStore.canShowAssistantButtonsOnCanvas && !isCustomNode && !nodeIsHidden();
});
const assistantAlreadyAsked = computed(() => {
@ -384,6 +385,11 @@ function copySuccess() {
});
}
function nodeIsHidden() {
const nodeType = nodeTypesStore.getNodeType(node?.value.type);
return nodeType?.hidden ?? false;
}
async function onAskAssistantClick() {
const { message, lineNumber, description } = props.error;
const sessionInProgress = !assistantStore.isSessionEnded;

View file

@ -4,6 +4,8 @@ import NodeErrorView from '@/components/Error/NodeErrorView.vue';
import { STORES } from '@/constants';
import { createTestingPinia } from '@pinia/testing';
import { type INode } from 'n8n-workflow';
import { useAssistantStore } from '@/stores/assistant.store';
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
const DEFAULT_SETUP = {
pinia: createTestingPinia({
@ -63,4 +65,35 @@ describe('NodeErrorView.vue', () => {
expect(errorMessage).toHaveTextContent('Unexpected identifier [line 1]');
});
it('should not render AI assistant button when error happens in deprecated function node', async () => {
const aiAssistantStore = useAssistantStore(DEFAULT_SETUP.pinia);
const nodeTypeStore = useNodeTypesStore(DEFAULT_SETUP.pinia);
//@ts-expect-error
nodeTypeStore.getNodeType = vi.fn(() => ({
type: 'n8n-nodes-base.function',
typeVersion: 1,
hidden: true,
}));
//@ts-expect-error
aiAssistantStore.canShowAssistantButtonsOnCanvas = true;
const { queryByTestId } = renderComponent({
props: {
error: {
node: {
...mockNode,
type: 'n8n-nodes-base.function',
typeVersion: 1,
},
},
},
});
const aiAssistantButton = queryByTestId('ask-assistant-button');
expect(aiAssistantButton).toBeNull();
});
});