-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add canvas edge toolbar hover show/hide support
- Loading branch information
1 parent
817167c
commit 07b0379
Showing
5 changed files
with
149 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
packages/editor-ui/src/components/canvas/elements/edges/CanvasEdge.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { fireEvent } from '@testing-library/vue'; | ||
import CanvasEdge from './CanvasEdge.vue'; | ||
import { createComponentRenderer } from '@/__tests__/render'; | ||
|
||
const renderComponent = createComponentRenderer(CanvasEdge, { | ||
props: { | ||
sourceX: 0, | ||
sourceY: 0, | ||
sourcePosition: 'top', | ||
targetX: 100, | ||
targetY: 100, | ||
targetPosition: 'bottom', | ||
}, | ||
}); | ||
|
||
describe('CanvasEdge', () => { | ||
it('should emit delete event when toolbar delete is clicked', async () => { | ||
const { emitted, getByTestId } = renderComponent(); | ||
const deleteButton = getByTestId('delete-connection-button'); | ||
|
||
await fireEvent.click(deleteButton); | ||
|
||
expect(emitted()).toHaveProperty('delete'); | ||
}); | ||
|
||
it('should compute edgeStyle correctly', () => { | ||
const { container } = renderComponent({ | ||
props: { | ||
style: { | ||
stroke: 'red', | ||
}, | ||
}, | ||
}); | ||
|
||
const edge = container.querySelector('.vue-flow__edge-path'); | ||
|
||
expect(edge).toHaveStyle({ | ||
stroke: 'red', | ||
strokeWidth: 2, | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
packages/editor-ui/src/components/canvas/elements/edges/CanvasEdgeToolbar.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { fireEvent } from '@testing-library/vue'; | ||
import CanvasEdgeToolbar from './CanvasEdgeToolbar.vue'; | ||
import { createComponentRenderer } from '@/__tests__/render'; | ||
|
||
const renderComponent = createComponentRenderer(CanvasEdgeToolbar); | ||
|
||
describe('CanvasEdgeToolbar', () => { | ||
it('should emit delete event when delete button is clicked', async () => { | ||
const { getByTestId, emitted } = renderComponent(); | ||
const deleteButton = getByTestId('delete-connection-button'); | ||
|
||
await fireEvent.click(deleteButton); | ||
|
||
expect(emitted()).toHaveProperty('delete'); | ||
}); | ||
}); |
42 changes: 42 additions & 0 deletions
42
packages/editor-ui/src/components/canvas/elements/edges/CanvasEdgeToolbar.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<script lang="ts" setup> | ||
import { useI18n } from '@/composables/useI18n'; | ||
import { computed, useCssModule } from 'vue'; | ||
const emit = defineEmits<{ | ||
delete: []; | ||
}>(); | ||
const $style = useCssModule(); | ||
const i18n = useI18n(); | ||
const classes = computed(() => ({ | ||
[$style.canvasEdgeToolbar]: true, | ||
})); | ||
function onDelete() { | ||
emit('delete'); | ||
} | ||
</script> | ||
|
||
<template> | ||
<div :class="classes" data-test-id="canvas-edge-toolbar"> | ||
<N8nIconButton | ||
data-test-id="delete-connection-button" | ||
type="tertiary" | ||
size="small" | ||
icon="trash" | ||
:title="i18n.baseText('node.delete')" | ||
@click="onDelete" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<style lang="scss" module> | ||
.canvasEdgeToolbar { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
pointer-events: all; | ||
} | ||
</style> |