n8n/packages/editor-ui/src/components/Modal.vue
Mutasem Aldmour 49bf786e5b
Improve workflow activation (#2692)
* feat: activator disabled based on thiggers

* feat: tooltip over inactive switch

* feat: message for trigger types

* feat: deactivate on save if trigger is removed

* chore: refactor executions modal

* feat: calculate service name if possible

* feat: alert on activation

* chore: fix linting

* feat: always enable activator when active

* fix: adjust the alert

* feat: take disabled state into account

* feat: automatically save on activation

* feat: rely on nodes name and edit messages

* feat: isolate state for each activator instance

* feat: create activation modal component

* feat: activationModal checkbox and trigger message

* feat: add activation messages to node config

* chore: style activation modal

* chore: style fixes

* feat: refactor disabled state

* chore: refactor modal

* chore: refactor modal

* chore: tidy the node config

* chore: refactor and styling tweaks

* chore: minor fixes

* fix: check webhooks from ui nodes

* chore: remove saving prompt

* chore: explicit current workflow evaluation

* feat: add settings link to activation modal

* fix: immediately load executions on render

* feat: exclude error trigger from trigger nodes

* chore: add i18n keys

* fix: check localstorage more strictly

* fix: handle refresh in execution list

* remove unnessary event

* remove comment

* fix closing executions modal bugs

* update closing

* update translation key

* fix translation keys

* fix modal closing

* fix closing

* fix drawer closing

* close all modals when opening executions

* update key

* close all modals when opening workflow or new page

* delete unnessary comment

* clean up import

* clean up unnessary initial data

* clean up activator impl

* rewrite

* fix open modal bug

* simply remove error

* refactor activation logic

* fix i18n and such

* remove changes

* revert saving changes

* Revert "revert saving changes"

25c29d1055

* add translation

* fix new workflows saving

* clean up modal impl

* clean up impl

* refactor common code out

* remove active changes from saving

* refactor differently

* revert unnessary change

* set dirty false

* fix i18n bug

* avoid opening two modals

* fix tooltips

* add comment

* address other comments

* address comments

Co-authored-by: saintsebastian <tilitidam@gmail.com>
2022-01-21 18:00:00 +01:00

259 lines
4.9 KiB
Vue

<template>
<el-dialog
:visible="visible"
:before-close="closeDialog"
:class="{'dialog-wrapper': true, [$style.center]: center, scrollable: scrollable}"
:width="width"
:show-close="showClose"
:custom-class="getCustomClass()"
:close-on-click-modal="closeOnClickModal"
:close-on-press-escape="closeOnPressEscape"
:style="styles"
append-to-body
>
<template v-slot:title v-if="$scopedSlots.header">
<slot name="header" v-if="!loading" />
</template>
<template v-slot:title v-else-if="title">
<div :class="centerTitle ? $style.centerTitle : ''">
<div v-if="title">
<n8n-heading tag="h1" size="xlarge">{{title}}</n8n-heading>
</div>
<div v-if="subtitle" :class="$style.subtitle">
<n8n-heading tag="h3" size="small" color="text-light">{{subtitle}}</n8n-heading>
</div>
</div>
</template>
<div class="modal-content" @keydown.stop @keydown.enter="handleEnter" @keydown.esc="closeDialog">
<slot v-if="!loading" name="content"/>
<div :class="$style.loader" v-else>
<n8n-spinner />
</div>
</div>
<div v-if="!loading && $scopedSlots.footer" :class="$style.footer">
<slot name="footer" :close="closeDialog" />
</div>
</el-dialog>
</template>
<script lang="ts">
import Vue from "vue";
export default Vue.extend({
name: "Modal",
props: {
name: {
type: String,
},
title: {
type: String,
},
subtitle: {
type: String,
},
eventBus: {
type: Vue,
},
showClose: {
type: Boolean,
default: true,
},
loading: {
type: Boolean,
},
classic: {
type: Boolean,
},
beforeClose: {
type: Function,
},
customClass: {
type: String,
},
center: {
type: Boolean,
},
width: {
type: String,
default: '50%',
},
minWidth: {
type: String,
},
maxWidth: {
type: String,
},
height: {
type: String,
},
minHeight: {
type: String,
},
maxHeight: {
type: String,
},
scrollable: {
type: Boolean,
default: false,
},
centerTitle: {
type: Boolean,
default: false,
},
closeOnClickModal: {
type: Boolean,
default: true,
},
closeOnPressEscape: {
type: Boolean,
default: true,
},
},
mounted() {
window.addEventListener('keydown', this.onWindowKeydown);
if (this.$props.eventBus) {
this.$props.eventBus.$on('close', () => {
this.closeDialog();
});
this.$props.eventBus.$on('closeAll', () => {
this.closeAllDialogs();
});
}
const activeElement = document.activeElement as HTMLElement;
if (activeElement) {
activeElement.blur();
}
},
beforeDestroy() {
window.removeEventListener('keydown', this.onWindowKeydown);
},
methods: {
onWindowKeydown(event: KeyboardEvent) {
if (!this.isActive) {
return;
}
if (event && event.keyCode === 13) {
this.handleEnter();
}
},
handleEnter() {
if (this.isActive) {
this.$emit('enter');
}
},
closeAllDialogs() {
this.$store.commit('ui/closeAllModals');
},
async closeDialog() {
if (this.beforeClose) {
const shouldClose = await this.beforeClose();
if (shouldClose === false) { // must be strictly false to stop modal from closing
return;
}
}
this.$store.commit('ui/closeModal', this.$props.name);
},
getCustomClass() {
let classes = this.$props.customClass || '';
if (this.$props.classic) {
classes = `${classes} classic`;
}
return classes;
},
},
computed: {
isActive(): boolean {
return this.$store.getters['ui/isModalActive'](this.$props.name);
},
visible(): boolean {
return this.$store.getters['ui/isModalOpen'](this.$props.name);
},
styles() {
const styles: {[prop: string]: string} = {};
if (this.height) {
styles['--dialog-height'] = this.height;
}
if (this.minHeight) {
styles['--dialog-min-height'] = this.minHeight;
}
if (this.maxHeight) {
styles['--dialog-max-height'] = this.maxHeight;
}
if (this.maxWidth) {
styles['--dialog-max-width'] = this.maxWidth;
}
if (this.minWidth) {
styles['--dialog-min-width'] = this.minWidth;
}
return styles;
},
},
});
</script>
<style lang="scss">
.dialog-wrapper {
.el-dialog {
display: flex;
flex-direction: column;
max-width: var(--dialog-max-width, 80%);
min-width: var(--dialog-min-width, 420px);
height: var(--dialog-height);
min-height: var(--dialog-min-height);
max-height: var(--dialog-max-height);
}
.el-dialog__body {
overflow: hidden;
display: flex;
flex-direction: column;
flex-grow: 1;
}
.modal-content {
overflow: hidden;
flex-grow: 1;
}
&.scrollable .modal-content {
overflow-y: auto;
}
}
</style>
<style lang="scss" module>
.center {
display: flex;
align-items: center;
justify-content: center;
}
.loader {
display: flex;
align-items: center;
justify-content: center;
color: var(--color-primary-tint-1);
font-size: 30px;
height: 80%;
}
.centerTitle {
text-align: center;
}
.subtitle {
margin-top: var(--spacing-2xs);
}
.footer {
margin-top: var(--spacing-l);
}
</style>