feat(editor): AI assistant UX improvements (no-changelog) (#10568)

This commit is contained in:
Milorad FIlipović
2024-09-03 10:43:24 +02:00
committed by GitHub
parent 5eba534319
commit d92374b5c6
20 changed files with 511 additions and 53 deletions

View File

@@ -0,0 +1,28 @@
import AssistantLoadingMessage from './AssistantLoadingMessage.vue';
import type { StoryFn } from '@storybook/vue3';
export default {
title: 'Assistant/AskAssistantLoadingMessage',
component: AssistantLoadingMessage,
argTypes: {},
};
const Template: StoryFn = (args, { argTypes }) => ({
setup: () => ({ args }),
props: Object.keys(argTypes),
components: {
AssistantLoadingMessage,
},
template: `<div class="p-xs" style="width: ${args.templateWidth || 'auto'}"><AssistantLoadingMessage v-bind="args" /></div>`,
});
export const Default = Template.bind({});
Default.args = {
message: 'Searching n8n documentation for the best possible answer...',
};
export const NarrowContainer = Template.bind({});
NarrowContainer.args = {
...Default.args,
templateWidth: '200px',
};

View File

@@ -0,0 +1,122 @@
<script setup lang="ts">
import { defineProps, withDefaults } from 'vue';
import AssistantAvatar from '../AskAssistantAvatar/AssistantAvatar.vue';
withDefaults(
defineProps<{
message: string;
animationType?: 'slide-vertical' | 'slide-horizontal' | 'fade';
}>(),
{
animationType: 'slide-vertical',
},
);
</script>
<template>
<div :class="$style.container">
<div :class="$style.avatar">
<AssistantAvatar size="mini" />
</div>
<div :class="$style['message-container']">
<transition :name="animationType" mode="out-in">
<span v-if="message" :key="message" :class="$style.message">{{ message }}</span>
</transition>
</div>
</div>
</template>
<style module lang="scss">
.container {
display: flex;
gap: var(--spacing-3xs);
align-items: flex-start;
user-select: none;
}
.avatar {
animation: pulse 1.5s infinite;
position: relative;
}
.message-container {
display: inline-flex;
position: relative;
overflow: hidden;
line-height: 1.4rem;
}
.message {
margin: 0;
padding: 0;
font-weight: var(--font-weight-bold);
font-size: var(--font-size-2xs);
text-align: left;
}
@keyframes pulse {
0% {
transform: scale(1);
opacity: 0.7;
}
50% {
transform: scale(1.2);
opacity: 1;
}
100% {
transform: scale(1);
opacity: 0.7;
}
}
</style>
<style lang="scss" scoped>
// Vertical Slide transition
.slide-vertical-enter-active,
.slide-vertical-leave-active {
transition:
transform 0.5s ease,
opacity 0.5s ease;
}
.slide-vertical-enter {
transform: translateY(100%);
opacity: 0;
}
.slide-vertical-leave-to {
transform: translateY(-100%);
opacity: 0;
}
// Horizontal Slide transition
.slide-horizontal-enter-active,
.slide-horizontal-leave-active {
transition:
transform 0.5s ease,
opacity 0.5s ease;
}
.slide-horizontal-enter {
transform: translateX(100%);
opacity: 0;
}
.slide-horizontal-leave-to {
transform: translateX(-100%);
opacity: 0;
}
// Fade transition
.fade-enter-active,
.fade-leave-active {
transition: opacity 0.5s ease;
}
.fade-enter {
opacity: 0;
}
.fade-leave-to /* .fade-leave-active in <2.1.8 */ {
opacity: 0;
}
</style>

View File

@@ -0,0 +1,30 @@
import DemoComponent from './DemoComponent.vue';
import type { StoryFn } from '@storybook/vue3';
export default {
title: 'Assistant/AskAssistantLoadingMessageTransitions',
component: DemoComponent,
argTypes: {},
};
const Template: StoryFn = (args, { argTypes }) => ({
setup: () => ({ args }),
props: Object.keys(argTypes),
components: {
DemoComponent,
},
template: '<DemoComponent v-bind="args" />',
});
export const Default = Template.bind({});
Default.args = {};
export const Horizontal = Template.bind({});
Horizontal.args = {
animationType: 'slide-horizontal',
};
export const Fade = Template.bind({});
Fade.args = {
animationType: 'fade',
};

View File

@@ -0,0 +1,55 @@
<script setup lang="ts">
import { ref, computed, onMounted } from 'vue';
import AssistantLoadingMessage from './AssistantLoadingMessage.vue';
import Notice from '../N8nNotice/Notice.vue';
/**
* This is a demo component to show how the transitions work in the AssistantLoadingMessage component.
* It should be only used in the storybook.
*/
withDefaults(
defineProps<{
animationType?: 'slide-vertical' | 'slide-horizontal' | 'fade';
}>(),
{
animationType: 'slide-vertical',
},
);
const messages = [
'Analyzing the error...',
'Searching the n8n documentation...',
'Checking the n8n community for answers..',
];
const currentIndex = ref(0);
const currentMessage = computed(() => {
return messages[currentIndex.value];
});
const startMessageRotation = () => {
setInterval(() => {
currentIndex.value = (currentIndex.value + 1) % messages.length;
}, 2000);
};
onMounted(() => {
startMessageRotation();
});
</script>
<template>
<div>
<Notice type="warning" content="This component is for demo purposes only" />
<div :class="$style['loading-message']">
<AssistantLoadingMessage :message="currentMessage" :animation-type="animationType" />
</div>
</div>
</template>
<style module lang="scss">
.loading-message {
padding: var(--spacing-3xs);
}
</style>

View File

@@ -0,0 +1,13 @@
import { render } from '@testing-library/vue';
import AssistantLoadingMessage from '../AssistantLoadingMessage.vue';
describe('AssistantLoadingMessage', () => {
it('renders loading message correctly', () => {
const { container } = render(AssistantLoadingMessage, {
props: {
loadingMessage: 'Thinking...',
},
});
expect(container).toMatchSnapshot();
});
});

View File

@@ -0,0 +1,71 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
exports[`AssistantLoadingMessage > renders loading message correctly 1`] = `
<div>
<div
class="container"
data-v-4e90e01e=""
loadingmessage="Thinking..."
>
<div
class="avatar"
data-v-4e90e01e=""
>
<div
class="container mini"
data-v-4e90e01e=""
>
<svg
fill="none"
height="8"
viewBox="0 0 24 24"
width="8"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M19.9658 14.0171C19.9679 14.3549 19.8654 14.6851 19.6722 14.9622C19.479 15.2393 19.2046 15.4497 18.8869 15.5645L13.5109 17.5451L11.5303 22.9211C11.4137 23.2376 11.2028 23.5107 10.9261 23.7037C10.6494 23.8966 10.3202 24 9.9829 24C9.64559 24 9.3164 23.8966 9.0397 23.7037C8.76301 23.5107 8.55212 23.2376 8.43549 22.9211L6.45487 17.5451L1.07888 15.5645C0.762384 15.4479 0.489262 15.237 0.296347 14.9603C0.103431 14.6836 0 14.3544 0 14.0171C0 13.6798 0.103431 13.3506 0.296347 13.0739C0.489262 12.7972 0.762384 12.5863 1.07888 12.4697L6.45487 10.4891L8.43549 5.11309C8.55212 4.79659 8.76301 4.52347 9.0397 4.33055C9.3164 4.13764 9.64559 4.0342 9.9829 4.0342C10.3202 4.0342 10.6494 4.13764 10.9261 4.33055C11.2028 4.52347 11.4137 4.79659 11.5303 5.11309L13.5109 10.4891L18.8869 12.4697C19.2046 12.5845 19.479 12.7949 19.6722 13.072C19.8654 13.3491 19.9679 13.6793 19.9658 14.0171ZM14.1056 4.12268H15.7546V5.77175C15.7546 5.99043 15.8415 6.20015 15.9961 6.35478C16.1508 6.50941 16.3605 6.59628 16.5792 6.59628C16.7979 6.59628 17.0076 6.50941 17.1622 6.35478C17.3168 6.20015 17.4037 5.99043 17.4037 5.77175V4.12268H19.0528C19.2715 4.12268 19.4812 4.03581 19.6358 3.88118C19.7905 3.72655 19.8773 3.51682 19.8773 3.29814C19.8773 3.07946 19.7905 2.86974 19.6358 2.71511C19.4812 2.56048 19.2715 2.47361 19.0528 2.47361H17.4037V0.824535C17.4037 0.605855 17.3168 0.396131 17.1622 0.241501C17.0076 0.0868704 16.7979 0 16.5792 0C16.3605 0 16.1508 0.0868704 15.9961 0.241501C15.8415 0.396131 15.7546 0.605855 15.7546 0.824535V2.47361H14.1056C13.8869 2.47361 13.6772 2.56048 13.5225 2.71511C13.3679 2.86974 13.281 3.07946 13.281 3.29814C13.281 3.51682 13.3679 3.72655 13.5225 3.88118C13.6772 4.03581 13.8869 4.12268 14.1056 4.12268ZM23.1755 7.42082H22.3509V6.59628C22.3509 6.3776 22.2641 6.16788 22.1094 6.01325C21.9548 5.85862 21.7451 5.77175 21.5264 5.77175C21.3077 5.77175 21.098 5.85862 20.9434 6.01325C20.7887 6.16788 20.7019 6.3776 20.7019 6.59628V7.42082H19.8773C19.6586 7.42082 19.4489 7.50769 19.2943 7.66232C19.1397 7.81695 19.0528 8.02667 19.0528 8.24535C19.0528 8.46404 19.1397 8.67376 19.2943 8.82839C19.4489 8.98302 19.6586 9.06989 19.8773 9.06989H20.7019V9.89443C20.7019 10.1131 20.7887 10.3228 20.9434 10.4775C21.098 10.6321 21.3077 10.719 21.5264 10.719C21.7451 10.719 21.9548 10.6321 22.1094 10.4775C22.2641 10.3228 22.3509 10.1131 22.3509 9.89443V9.06989H23.1755C23.3941 9.06989 23.6039 8.98302 23.7585 8.82839C23.9131 8.67376 24 8.46404 24 8.24535C24 8.02667 23.9131 7.81695 23.7585 7.66232C23.6039 7.50769 23.3941 7.42082 23.1755 7.42082Z"
fill="white"
/>
<defs>
<lineargradient
gradientUnits="userSpaceOnUse"
id="paint0_linear_173_12825"
x1="-3.67094e-07"
x2="28.8315"
y1="-0.000120994"
y2="9.82667"
>
<stop
stop-color="var(--color-assistant-highlight-1)"
/>
<stop
offset="0.495"
stop-color="var(--color-assistant-highlight-2)"
/>
<stop
offset="1"
stop-color="var(--color-assistant-highlight-3)"
/>
</lineargradient>
</defs>
</svg>
</div>
</div>
<div
class="message-container"
data-v-4e90e01e=""
>
<transition-stub
appear="false"
css="true"
data-v-4e90e01e=""
mode="out-in"
name="slide-vertical"
persisted="false"
>
<!--v-if-->
</transition-stub>
</div>
</div>
</div>
`;