Skip to content

Commit

Permalink
fix(editor): Fix sticky color picker getting covered by nodes on new …
Browse files Browse the repository at this point in the history
…canvas (#12263)
  • Loading branch information
alexgrozav authored Dec 17, 2024
1 parent 9d50dad commit 27bd3c8
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,6 @@ onBeforeUnmount(() => {

<CanvasNodeToolbar
v-if="nodeTypeDescription"
data-test-id="canvas-node-toolbar"
:read-only="readOnly"
:class="$style.canvasNodeToolbar"
@delete="onDelete"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fireEvent } from '@testing-library/vue';
import { fireEvent, waitFor } from '@testing-library/vue';
import CanvasNodeToolbar from '@/components/canvas/elements/nodes/CanvasNodeToolbar.vue';
import { createComponentRenderer } from '@/__tests__/render';
import { createCanvasNodeProvide, createCanvasProvide } from '@/__tests__/data';
Expand Down Expand Up @@ -137,4 +137,45 @@ describe('CanvasNodeToolbar', () => {

expect(emitted('update')[0]).toEqual([{ color: 1 }]);
});

it('should have "forceVisible" class when hovered', async () => {
const { getByTestId } = renderComponent({
global: {
provide: {
...createCanvasNodeProvide(),
...createCanvasProvide(),
},
},
});

const toolbar = getByTestId('canvas-node-toolbar');

await fireEvent.mouseEnter(toolbar);

expect(toolbar).toHaveClass('forceVisible');
});

it('should have "forceVisible" class when sticky color picker is visible', async () => {
const { getByTestId } = renderComponent({
global: {
provide: {
...createCanvasNodeProvide({
data: {
render: {
type: CanvasNodeRenderType.StickyNote,
options: { color: 3 },
},
},
}),
...createCanvasProvide(),
},
},
});

const toolbar = getByTestId('canvas-node-toolbar');

await fireEvent.click(getByTestId('change-sticky-color'));

await waitFor(() => expect(toolbar).toHaveClass('forceVisible'));
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, useCssModule } from 'vue';
import { computed, ref, useCssModule } from 'vue';
import { useI18n } from '@/composables/useI18n';
import { useCanvasNode } from '@/composables/useCanvasNode';
import { CanvasNodeRenderType } from '@/types';
Expand Down Expand Up @@ -27,9 +27,13 @@ const nodeDisabledTitle = computed(() => {
return isDisabled.value ? i18n.baseText('node.disable') : i18n.baseText('node.enable');
});
const isStickyColorSelectorOpen = ref(false);
const isHovered = ref(false);
const classes = computed(() => ({
[$style.canvasNodeToolbar]: true,
[$style.readOnly]: props.readOnly,
[$style.forceVisible]: isHovered.value || isStickyColorSelectorOpen.value,
}));
const isExecuteNodeVisible = computed(() => {
Expand Down Expand Up @@ -72,10 +76,23 @@ function onChangeStickyColor(color: number) {
function onOpenContextMenu(event: MouseEvent) {
emit('open:contextmenu', event);
}
function onMouseEnter() {
isHovered.value = true;
}
function onMouseLeave() {
isHovered.value = false;
}
</script>

<template>
<div :class="classes">
<div
data-test-id="canvas-node-toolbar"
:class="classes"
@mouseenter="onMouseEnter"
@mouseleave="onMouseLeave"
>
<div :class="$style.canvasNodeToolbarItems">
<N8nIconButton
v-if="isExecuteNodeVisible"
Expand Down Expand Up @@ -110,6 +127,7 @@ function onOpenContextMenu(event: MouseEvent) {
/>
<CanvasNodeStickyColorSelector
v-if="isStickyNoteChangeColorVisible"
v-model:visible="isStickyColorSelectorOpen"
@update="onChangeStickyColor"
/>
<N8nIconButton
Expand Down Expand Up @@ -143,4 +161,8 @@ function onOpenContextMenu(event: MouseEvent) {
--button-font-color: var(--color-text-light);
}
}
.forceVisible {
opacity: 1 !important;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ const { render, eventBus } = useCanvasNode();
const renderOptions = computed(() => render.value.options as CanvasNodeStickyNoteRender['options']);
const autoHideTimeout = ref<NodeJS.Timeout | null>(null);
const isPopoverVisible = ref(false);
const colors = computed(() => Array.from({ length: 7 }).map((_, index) => index + 1));
function togglePopover() {
isPopoverVisible.value = !isPopoverVisible.value;
}
const isPopoverVisible = defineModel<boolean>('visible');
function hidePopover() {
isPopoverVisible.value = false;
Expand Down Expand Up @@ -59,22 +56,21 @@ onBeforeUnmount(() => {

<template>
<N8nPopover
v-model:visible="isPopoverVisible"
effect="dark"
trigger="click"
placement="top"
:popper-class="$style.popover"
:popper-style="{ width: '208px' }"
:visible="isPopoverVisible"
:teleported="false"
@mouseenter="onMouseEnter"
@mouseleave="onMouseLeave"
:teleported="true"
@before-enter="onMouseEnter"
@after-leave="onMouseLeave"
>
<template #reference>
<div
:class="$style.option"
data-test-id="change-sticky-color"
:title="i18n.baseText('node.changeColor')"
@click.stop="togglePopover"
>
<FontAwesomeIcon icon="palette" />
</div>
Expand Down

0 comments on commit 27bd3c8

Please sign in to comment.