mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat: refactor disabled state
This commit is contained in:
parent
1fef8e764c
commit
530f601a9c
|
@ -68,14 +68,6 @@ export default mixins(
|
|||
nodes: [] as INodeUi[],
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
if (this.workflowId && this.$store.state.workflow.id !== this.workflowId) {
|
||||
this.restApi().getWorkflow(this.workflowId)
|
||||
.then((data: IWorkflowDb) => {
|
||||
this.nodes = data.nodes;
|
||||
});
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapGetters({
|
||||
dirtyState: "getStateIsDirty",
|
||||
|
@ -97,19 +89,18 @@ export default mixins(
|
|||
return '#13ce66';
|
||||
},
|
||||
disabled(): boolean {
|
||||
return this.workflowActive ? !this.containsTrigger : false;
|
||||
if (this.isCurrentWorkflow) {
|
||||
// Switch should be enabled if workflow is currently active
|
||||
return !this.workflowActive && !this.containsTrigger;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
isCurrentWorkflow() {
|
||||
return this.workflowId && this.$store.state.workflow.id == this.workflowId;
|
||||
},
|
||||
containsTrigger(): boolean {
|
||||
let nodes: INodeUi[];
|
||||
if (this.nodes.length > 0) {
|
||||
nodes = this.nodes;
|
||||
} else {
|
||||
nodes = this.$store.getters.allNodes;
|
||||
}
|
||||
const foundNodes = nodes
|
||||
.filter(({ disabled }: INodeUi) => !disabled)
|
||||
.map(({ type }: INodeUi) => this.$store.getters.nodeType(type));
|
||||
return foundNodes.filter(((node: INodeTypeDescription) => node.group.includes('trigger'))).length > 0;
|
||||
const foundTriggers = this.$store.getters.worklfowEnabledTriggerNodes;
|
||||
return foundTriggers.length > 0;
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
@ -186,7 +177,7 @@ export default mixins(
|
|||
this.$store.commit('setWorkflowActive', this.workflowId);
|
||||
|
||||
// Show activation dialog only for current workflow and if user hasn't deactivated it
|
||||
if (this.nodes.length === 0 && !window.localStorage.getItem(LOCAL_STORAGE_ACTIVATION_FLAG)) {
|
||||
if (this.isCurrentWorkflow && !window.localStorage.getItem(LOCAL_STORAGE_ACTIVATION_FLAG)) {
|
||||
this.$store.dispatch('ui/openModal', WORKFLOW_ACTIVE_MODAL_KEY);
|
||||
}
|
||||
} else {
|
||||
|
|
2
packages/editor-ui/src/components/activationModal.vue
Normal file
2
packages/editor-ui/src/components/activationModal.vue
Normal file
|
@ -0,0 +1,2 @@
|
|||
const foundTriggers = this.$store.getters.worklfowEnabledTriggerNodes
|
||||
.map(({ type }: INodeUi) => this.$store.getters.nodeType(type));
|
|
@ -460,9 +460,7 @@ export const workflowHelpers = mixins(
|
|||
// Check if trigger was removed from active workflow
|
||||
let triggerIsRemoved = false;
|
||||
if (this.$store.getters.isActive) {
|
||||
const triggers = this.$store.getters.allNodes
|
||||
.map(({ type }: INodeUi) => this.$store.getters.nodeType(type))
|
||||
.filter(((type: INodeTypeDescription) => type.group.includes('trigger')));
|
||||
const triggers = this.$store.getters.worklfowEnabledTriggerNodes;
|
||||
triggerIsRemoved = triggers.length === 0;
|
||||
|
||||
if (triggerIsRemoved) {
|
||||
|
|
|
@ -762,6 +762,13 @@ export const store = new Vuex.Store({
|
|||
return getters.nodeType(node.type).group.includes('trigger');
|
||||
});
|
||||
},
|
||||
|
||||
worklfowEnabledTriggerNodes: (state, getters) => {
|
||||
return getters.workflowTriggerNodes.filter(node => {
|
||||
return !node.disabled;
|
||||
});
|
||||
},
|
||||
|
||||
// Node-Index
|
||||
getNodeIndex: (state) => (nodeName: string): number => {
|
||||
return state.nodeIndex.indexOf(nodeName);
|
||||
|
|
Loading…
Reference in a new issue