Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(editor): Tweak hover area of workflow / cred cards #7108

Merged
merged 3 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions packages/design-system/src/components/N8nCard/Card.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<slot name="footer" />
</div>
</div>
<div v-if="$slots.append">
<div v-if="$slots.append" :class="$style.append">
<slot name="append" />
</div>
</div>
Expand Down Expand Up @@ -82,7 +82,6 @@ export default defineComponent({

.icon {
width: 24px;
height: 24px;
display: inline-flex;
justify-content: center;
align-items: center;
Expand All @@ -101,4 +100,10 @@ export default defineComponent({
border-color: var(--color-primary);
}
}

.append {
display: flex;
align-items: center;
cursor: default;
}
</style>
54 changes: 38 additions & 16 deletions packages/editor-ui/src/components/CredentialCard.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
<template>
<n8n-card :class="$style['card-link']" @click="onClick">
<n8n-card :class="$style.cardLink" @click="onClick">
<template #prepend>
<credential-icon :credential-type-name="credentialType ? credentialType.name : ''" />
</template>
<template #header>
<n8n-heading tag="h2" bold :class="$style['card-heading']">
<n8n-heading tag="h2" bold :class="$style.cardHeading">
{{ data.name }}
</n8n-heading>
</template>
<n8n-text color="text-light" size="small">
<span v-if="credentialType">{{ credentialType.displayName }} | </span>
<span v-show="data"
>{{ $locale.baseText('credentials.item.updated') }} <time-ago :date="data.updatedAt" /> |
</span>
<span v-show="data"
>{{ $locale.baseText('credentials.item.created') }} {{ formattedCreatedAtDate }}
</span>
</n8n-text>
<div :class="$style.cardDescription">
<n8n-text color="text-light" size="small">
<span v-if="credentialType">{{ credentialType.displayName }} | </span>
<span v-show="data"
>{{ $locale.baseText('credentials.item.updated') }} <time-ago :date="data.updatedAt" /> |
</span>
<span v-show="data"
>{{ $locale.baseText('credentials.item.created') }} {{ formattedCreatedAtDate }}
</span>
</n8n-text>
</div>
<template #append>
<div :class="$style['card-actions']">
<div :class="$style.cardActions" ref="cardActions">
<enterprise-edition :features="[EnterpriseEditionFeature.Sharing]">
<n8n-badge v-if="credentialPermissions.isOwner" class="mr-xs" theme="tertiary" bold>
{{ $locale.baseText('credentials.item.owner') }}
Expand Down Expand Up @@ -128,7 +130,15 @@ export default defineComponent({
},
},
methods: {
async onClick() {
async onClick(event: Event) {
if (
this.$refs.cardActions === event.target ||
this.$refs.cardActions?.contains(event.target) ||
event.target?.contains(this.$refs.cardActions)
) {
return;
}

this.uiStore.openExistingCredential(this.data.id);
},
async onAction(action: string) {
Expand Down Expand Up @@ -162,23 +172,35 @@ export default defineComponent({
</script>

<style lang="scss" module>
.card-link {
.cardLink {
transition: box-shadow 0.3s ease;
cursor: pointer;
padding: 0 0 0 var(--spacing-s);
align-items: stretch;

&:hover {
box-shadow: 0 2px 8px rgba(#441c17, 0.1);
}
}

.card-heading {
.cardHeading {
font-size: var(--font-size-s);
padding: var(--spacing-s) 0 0;
}

.cardDescription {
min-height: 19px;
display: flex;
align-items: center;
padding: 0 0 var(--spacing-s);
}

.card-actions {
.cardActions {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 0 var(--spacing-s) 0 0;
cursor: default;
}
</style>
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</div>
</template>
<template #append>
<div :class="$style.cardActions">
<div :class="$style.cardActions" ref="cardActions">
<div :class="$style.activeStatusText" data-test-id="destination-activator-status">
<n8n-text v-if="nodeParameters.enabled" :color="'success'" size="small" bold>
{{ $locale.baseText('workflowActivator.active') }}
Expand Down Expand Up @@ -83,9 +83,7 @@ export default defineComponent({
destination: {
type: Object,
required: true,
default: deepCopy(
defaultMessageEventBusDestinationOptions,
) as MessageEventBusDestinationOptions,
default: deepCopy(defaultMessageEventBusDestinationOptions),
},
isInstanceOwner: Boolean,
},
Expand Down Expand Up @@ -130,17 +128,16 @@ export default defineComponent({
);
}
},
async onClick(event?: PointerEvent) {
async onClick(event: Event) {
if (
event &&
event.target &&
'className' in event.target &&
event.target['className'] === 'el-switch__core'
this.$refs.cardActions === event.target ||
this.$refs.cardActions?.contains(event.target) ||
event.target?.contains(this.$refs.cardActions)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This condition could run into a situation where the click event is cancelled even when the event is triggered by clicking the card itself (the wrapper does contain the card actions).

To avoid this, you could add height: 100% to the cardActions class and then align child items to the center.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And actually with that in place we can also remove event.target?.contains(this.$refs.cardActions) because the outer most target can only be cardActions which is already checked by this.$refs.cardActions === event.target

) {
event.stopPropagation();
} else {
this.$emit('edit', this.destination.id);
return;
}

this.$emit('edit', this.destination.id);
},
onEnabledSwitched(state: boolean, destinationId: string) {
this.nodeParameters.enabled = state;
Expand Down Expand Up @@ -184,6 +181,8 @@ export default defineComponent({
.cardLink {
transition: box-shadow 0.3s ease;
cursor: pointer;
padding: 0 0 0 var(--spacing-s);
align-items: stretch;

&:hover {
box-shadow: 0 2px 8px rgba(#441c17, 0.1);
Expand All @@ -201,18 +200,22 @@ export default defineComponent({
.cardHeading {
font-size: var(--font-size-s);
word-break: break-word;
padding: var(--spacing-s) 0 0 var(--spacing-s);
}

.cardDescription {
min-height: 19px;
display: flex;
align-items: center;
padding: 0 0 var(--spacing-s) var(--spacing-s);
}

.cardActions {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 0 var(--spacing-s) 0 0;
cursor: default;
}
</style>
39 changes: 22 additions & 17 deletions packages/editor-ui/src/components/WorkflowCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</n8n-text>
</div>
<template #append>
<div :class="$style.cardActions">
<div :class="$style.cardActions" ref="cardActions">
<enterprise-edition :features="[EnterpriseEditionFeature.Sharing]">
<n8n-badge v-if="workflowPermissions.isOwner" class="mr-xs" theme="tertiary" bold>
{{ $locale.baseText('workflows.item.owner') }}
Expand All @@ -40,7 +40,6 @@
class="mr-s"
:workflow-active="data.active"
:workflow-id="data.id"
ref="activator"
data-test-id="workflow-card-activator"
/>

Expand Down Expand Up @@ -78,8 +77,6 @@ import { useUsersStore } from '@/stores/users.store';
import { useWorkflowsStore } from '@/stores/workflows.store';
import TimeAgo from '@/components/TimeAgo.vue';

type ActivatorRef = InstanceType<typeof WorkflowActivator>;

export const WORKFLOW_LIST_ITEM_ACTIONS = {
OPEN: 'open',
SHARE: 'share',
Expand Down Expand Up @@ -171,21 +168,23 @@ export default defineComponent({
},
},
methods: {
async onClick(event?: PointerEvent) {
if (event) {
if ((this.$refs.activator as ActivatorRef)?.$el.contains(event.target as HTMLElement)) {
return;
}
async onClick(event: Event) {
if (
this.$refs.cardActions === event.target ||
this.$refs.cardActions?.contains(event.target) ||
event.target?.contains(this.$refs.cardActions)
) {
return;
}

if (event.metaKey || event.ctrlKey) {
const route = this.$router.resolve({
name: VIEWS.WORKFLOW,
params: { name: this.data.id },
});
window.open(route.href, '_blank');
if (event.metaKey || event.ctrlKey) {
const route = this.$router.resolve({
name: VIEWS.WORKFLOW,
params: { name: this.data.id },
});
window.open(route.href, '_blank');

return;
}
return;
}

await this.$router.push({
Expand Down Expand Up @@ -267,6 +266,8 @@ export default defineComponent({
.cardLink {
transition: box-shadow 0.3s ease;
cursor: pointer;
padding: 0;
align-items: stretch;

&:hover {
box-shadow: 0 2px 8px rgba(#441c17, 0.1);
Expand All @@ -276,18 +277,22 @@ export default defineComponent({
.cardHeading {
font-size: var(--font-size-s);
word-break: break-word;
padding: var(--spacing-s) 0 0 var(--spacing-s);
}

.cardDescription {
min-height: 19px;
display: flex;
align-items: center;
padding: 0 0 var(--spacing-s) var(--spacing-s);
}

.cardActions {
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
padding: 0 var(--spacing-s) 0 0;
cursor: default;
}
</style>
Loading