fix(editor): Fix workflow back button navigation (#4546)

* 🐛 Fix back button navigation from recetly saved workflow

* 🐛 Fix coming-soon routes
This commit is contained in:
OlegIvaniv 2022-11-09 09:31:23 +01:00 committed by GitHub
parent 740df0c1e5
commit 825637f02a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 368 additions and 355 deletions

View file

@ -34,7 +34,6 @@ import { HIRING_BANNER, LOCAL_STORAGE_THEME, VIEWS } from './constants';
import mixins from 'vue-typed-mixins'; import mixins from 'vue-typed-mixins';
import { showMessage } from './components/mixins/showMessage'; import { showMessage } from './components/mixins/showMessage';
import { IUser } from './Interface';
import { userHelpers } from './components/mixins/userHelpers'; import { userHelpers } from './components/mixins/userHelpers';
import { loadLanguage } from './plugins/i18n'; import { loadLanguage } from './plugins/i18n';
import { restApi } from '@/components/mixins/restApi'; import { restApi } from '@/components/mixins/restApi';

View file

@ -2,7 +2,7 @@
<div :class="$style.container"> <div :class="$style.container">
<n8n-menu :items="sidebarMenuItems" @select="handleSelect"> <n8n-menu :items="sidebarMenuItems" @select="handleSelect">
<template #header> <template #header>
<div :class="$style.returnButton" @click="onReturn"> <div :class="$style.returnButton" @click="$emit('return')">
<i class="mr-xs"> <i class="mr-xs">
<font-awesome-icon icon="arrow-left" /> <font-awesome-icon icon="arrow-left" />
</i> </i>
@ -22,7 +22,6 @@
<script lang="ts"> <script lang="ts">
import mixins from 'vue-typed-mixins'; import mixins from 'vue-typed-mixins';
import { mapGetters } from 'vuex';
import { ABOUT_MODAL_KEY, VERSIONS_MODAL_KEY, VIEWS } from '@/constants'; import { ABOUT_MODAL_KEY, VERSIONS_MODAL_KEY, VIEWS } from '@/constants';
import { userHelpers } from './mixins/userHelpers'; import { userHelpers } from './mixins/userHelpers';
import { pushConnection } from "@/components/mixins/pushConnection"; import { pushConnection } from "@/components/mixins/pushConnection";
@ -123,9 +122,6 @@ export default mixins(
onVersionClick() { onVersionClick() {
this.uiStore.openModal(ABOUT_MODAL_KEY); this.uiStore.openModal(ABOUT_MODAL_KEY);
}, },
onReturn() {
this.$router.push({name: VIEWS.HOMEPAGE});
},
openUpdatesPanel() { openUpdatesPanel() {
this.uiStore.openModal(VERSIONS_MODAL_KEY); this.uiStore.openModal(VERSIONS_MODAL_KEY);
}, },

View file

@ -831,7 +831,7 @@ export const workflowHelpers = mixins(
} }
if (redirect) { if (redirect) {
this.$router.push({ this.$router.replace({
name: VIEWS.WORKFLOW, name: VIEWS.WORKFLOW,
params: { name: workflowData.id as string, action: 'workflowSave' }, params: { name: workflowData.id as string, action: 'workflowSave' },
}); });

View file

@ -9,6 +9,7 @@ import NodeView from '@/views/NodeView.vue';
import ExecutionsView from '@/components/ExecutionsView/ExecutionsView.vue'; import ExecutionsView from '@/components/ExecutionsView/ExecutionsView.vue';
import ExecutionsLandingPage from '@/components/ExecutionsView/ExecutionsLandingPage.vue'; import ExecutionsLandingPage from '@/components/ExecutionsView/ExecutionsLandingPage.vue';
import ExecutionPreview from '@/components/ExecutionsView/ExecutionPreview.vue'; import ExecutionPreview from '@/components/ExecutionsView/ExecutionPreview.vue';
import SettingsView from './views/SettingsView.vue';
import SettingsPersonalView from './views/SettingsPersonalView.vue'; import SettingsPersonalView from './views/SettingsPersonalView.vue';
import SettingsUsersView from './views/SettingsUsersView.vue'; import SettingsUsersView from './views/SettingsUsersView.vue';
import SettingsCommunityNodesView from './views/SettingsCommunityNodesView.vue'; import SettingsCommunityNodesView from './views/SettingsCommunityNodesView.vue';
@ -424,13 +425,39 @@ const router = new Router({
}, },
{ {
path: '/settings', path: '/settings',
redirect: '/settings/personal', component: SettingsView,
props: true,
children: [
{
path: 'personal',
name: VIEWS.PERSONAL_SETTINGS,
components: {
settingsView: SettingsPersonalView,
},
meta: {
telemetry: {
pageCategory: 'settings',
getProperties(route: Route) {
return {
feature: 'personal',
};
},
},
permissions: {
allow: {
loginStatus: [LOGIN_STATUS.LoggedIn],
},
deny: {
role: [ROLE.Default],
},
},
},
}, },
{ {
path: '/settings/users', path: 'users',
name: VIEWS.USERS_SETTINGS, name: VIEWS.USERS_SETTINGS,
components: { components: {
default: SettingsUsersView, settingsView: SettingsUsersView,
}, },
meta: { meta: {
telemetry: { telemetry: {
@ -455,35 +482,10 @@ const router = new Router({
}, },
}, },
{ {
path: '/settings/personal', path: 'api',
name: VIEWS.PERSONAL_SETTINGS,
components: {
default: SettingsPersonalView,
},
meta: {
telemetry: {
pageCategory: 'settings',
getProperties(route: Route) {
return {
feature: 'personal',
};
},
},
permissions: {
allow: {
loginStatus: [LOGIN_STATUS.LoggedIn],
},
deny: {
role: [ROLE.Default],
},
},
},
},
{
path: '/settings/api',
name: VIEWS.API_SETTINGS, name: VIEWS.API_SETTINGS,
components: { components: {
default: SettingsApiView, settingsView: SettingsApiView,
}, },
meta: { meta: {
telemetry: { telemetry: {
@ -508,10 +510,10 @@ const router = new Router({
}, },
}, },
{ {
path: '/settings/community-nodes', path: 'community-nodes',
name: VIEWS.COMMUNITY_NODES, name: VIEWS.COMMUNITY_NODES,
components: { components: {
default: SettingsCommunityNodesView, settingsView: SettingsCommunityNodesView,
}, },
meta: { meta: {
telemetry: { telemetry: {
@ -531,10 +533,11 @@ const router = new Router({
}, },
}, },
{ {
path: '/settings/coming-soon/:featureId', path: 'coming-soon/:featureId',
name: VIEWS.FAKE_DOOR, name: VIEWS.FAKE_DOOR,
component: SettingsFakeDoorView, components: {
props: true, settingsView: SettingsFakeDoorView,
},
meta: { meta: {
telemetry: { telemetry: {
pageCategory: 'settings', pageCategory: 'settings',
@ -551,6 +554,8 @@ const router = new Router({
}, },
}, },
}, },
],
},
{ {
path: '*', path: '*',
name: VIEWS.NOT_FOUND, name: VIEWS.NOT_FOUND,

View file

@ -220,7 +220,7 @@ import { useUIStore } from '@/stores/ui';
import { useSettingsStore } from '@/stores/settings'; import { useSettingsStore } from '@/stores/settings';
import { useUsersStore } from '@/stores/users'; import { useUsersStore } from '@/stores/users';
import { getNodeViewTab } from '@/components/helpers'; import { getNodeViewTab } from '@/components/helpers';
import { Route } from 'vue-router'; import { Route, RawLocation } from 'vue-router';
import { useWorkflowsStore } from '@/stores/workflows'; import { useWorkflowsStore } from '@/stores/workflows';
import { useRootStore } from '@/stores/n8nRootStore'; import { useRootStore } from '@/stores/n8nRootStore';
import { useNDVStore } from '@/stores/ndv'; import { useNDVStore } from '@/stores/ndv';
@ -347,11 +347,25 @@ export default mixins(
if (confirmModal === MODAL_CONFIRMED) { if (confirmModal === MODAL_CONFIRMED) {
const saved = await this.saveCurrentWorkflow({}, false); const saved = await this.saveCurrentWorkflow({}, false);
if (saved) this.settingsStore.fetchPromptsData(); if (saved) await this.settingsStore.fetchPromptsData();
this.uiStore.stateIsDirty = false; this.uiStore.stateIsDirty = false;
if(from.name === VIEWS.NEW_WORKFLOW) {
// Replace the current route with the new workflow route
// before navigating to the new route when saving new workflow.
this.$router.replace({ name: VIEWS.WORKFLOW, params: { name: this.currentWorkflow } }, () => {
// We can't use next() here since vue-router
// would prevent the navigation with an error
this.$router.push(to as RawLocation);
});
} else {
next(); next();
}
} else if (confirmModal === MODAL_CANCEL) { } else if (confirmModal === MODAL_CANCEL) {
await this.resetWorkspace();
this.uiStore.stateIsDirty = false; this.uiStore.stateIsDirty = false;
next(); next();
} else if (confirmModal === MODAL_CLOSE) { } else if (confirmModal === MODAL_CLOSE) {
next(false); next(false);

View file

@ -1,5 +1,4 @@
<template> <template>
<SettingsView>
<div :class="$style.container"> <div :class="$style.container">
<div :class="$style.header"> <div :class="$style.header">
<n8n-heading size="2xlarge"> <n8n-heading size="2xlarge">
@ -63,7 +62,6 @@
@click="createApiKey" @click="createApiKey"
/> />
</div> </div>
</SettingsView>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -71,8 +69,7 @@ import { showMessage } from '@/components/mixins/showMessage';
import { IUser } from '@/Interface'; import { IUser } from '@/Interface';
import mixins from 'vue-typed-mixins'; import mixins from 'vue-typed-mixins';
import SettingsView from './SettingsView.vue'; import CopyInput from '@/components/CopyInput.vue';
import CopyInput from '../components/CopyInput.vue';
import { mapStores } from 'pinia'; import { mapStores } from 'pinia';
import { useSettingsStore } from '@/stores/settings'; import { useSettingsStore } from '@/stores/settings';
import { useRootStore } from '@/stores/n8nRootStore'; import { useRootStore } from '@/stores/n8nRootStore';
@ -83,7 +80,6 @@ export default mixins(
).extend({ ).extend({
name: 'SettingsPersonalView', name: 'SettingsPersonalView',
components: { components: {
SettingsView,
CopyInput, CopyInput,
}, },
data() { data() {

View file

@ -1,5 +1,4 @@
<template> <template>
<SettingsView>
<div :class="$style.container"> <div :class="$style.container">
<div :class="$style.headingContainer"> <div :class="$style.headingContainer">
<n8n-heading size="2xlarge">{{ $locale.baseText('settings.communityNodes') }}</n8n-heading> <n8n-heading size="2xlarge">{{ $locale.baseText('settings.communityNodes') }}</n8n-heading>
@ -56,7 +55,6 @@
></community-package-card> ></community-package-card>
</div> </div>
</div> </div>
</SettingsView>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -64,10 +62,8 @@ import {
COMMUNITY_PACKAGE_INSTALL_MODAL_KEY, COMMUNITY_PACKAGE_INSTALL_MODAL_KEY,
COMMUNITY_NODES_INSTALLATION_DOCS_URL, COMMUNITY_NODES_INSTALLATION_DOCS_URL,
COMMUNITY_NODES_NPM_INSTALLATION_URL, COMMUNITY_NODES_NPM_INSTALLATION_URL,
} from '../constants'; } from '@/constants';
import { mapGetters } from 'vuex'; import CommunityPackageCard from '@/components/CommunityPackageCard.vue';
import SettingsView from './SettingsView.vue';
import CommunityPackageCard from '../components/CommunityPackageCard.vue';
import { showMessage } from '@/components/mixins/showMessage'; import { showMessage } from '@/components/mixins/showMessage';
import mixins from 'vue-typed-mixins'; import mixins from 'vue-typed-mixins';
import { PublicInstalledPackage } from 'n8n-workflow'; import { PublicInstalledPackage } from 'n8n-workflow';
@ -84,7 +80,6 @@ export default mixins(
).extend({ ).extend({
name: 'SettingsCommunityNodesView', name: 'SettingsCommunityNodesView',
components: { components: {
SettingsView,
CommunityPackageCard, CommunityPackageCard,
}, },
data () { data () {

View file

@ -1,21 +1,17 @@
<template> <template>
<SettingsView> <feature-coming-soon :featureId="featureId" showTitle />
<FeatureComingSoon :featureId="featureId" showTitle />
</SettingsView>
</template> </template>
<script lang="ts"> <script lang="ts">
import { IFakeDoor } from '@/Interface'; import { IFakeDoor } from '@/Interface';
import Vue from 'vue'; import Vue from 'vue';
import SettingsView from './SettingsView.vue'; import FeatureComingSoon from '@/components/FeatureComingSoon.vue';
import FeatureComingSoon from '../components/FeatureComingSoon.vue';
import { mapStores } from 'pinia'; import { mapStores } from 'pinia';
import { useUIStore } from '@/stores/ui'; import { useUIStore } from '@/stores/ui';
export default Vue.extend({ export default Vue.extend({
name: 'SettingsFakeDoorView', name: 'SettingsFakeDoorView',
components: { components: {
SettingsView,
FeatureComingSoon, FeatureComingSoon,
}, },
props: { props: {

View file

@ -1,5 +1,4 @@
<template> <template>
<SettingsView>
<div :class="$style.container"> <div :class="$style.container">
<div :class="$style.header"> <div :class="$style.header">
<n8n-heading size="2xlarge">{{ $locale.baseText('settings.personal.personalSettings') }}</n8n-heading> <n8n-heading size="2xlarge">{{ $locale.baseText('settings.personal.personalSettings') }}</n8n-heading>
@ -39,7 +38,7 @@
<n8n-button float="right" :label="$locale.baseText('settings.personal.save')" size="large" :disabled="!hasAnyChanges || !readyToSubmit" @click="onSaveClick" /> <n8n-button float="right" :label="$locale.baseText('settings.personal.save')" size="large" :disabled="!hasAnyChanges || !readyToSubmit" @click="onSaveClick" />
</div> </div>
</div> </div>
</SettingsView>
</template> </template>
<script lang="ts"> <script lang="ts">
@ -52,15 +51,10 @@ import { mapStores } from 'pinia';
import Vue from 'vue'; import Vue from 'vue';
import mixins from 'vue-typed-mixins'; import mixins from 'vue-typed-mixins';
import SettingsView from './SettingsView.vue';
export default mixins( export default mixins(
showMessage, showMessage,
).extend({ ).extend({
name: 'SettingsPersonalView', name: 'SettingsPersonalView',
components: {
SettingsView,
},
data() { data() {
return { return {
hasAnyChanges: false, hasAnyChanges: false,

View file

@ -1,5 +1,4 @@
<template> <template>
<SettingsView>
<div :class="$style.container"> <div :class="$style.container">
<div> <div>
<n8n-heading size="2xlarge">{{ $locale.baseText('settings.users') }}</n8n-heading> <n8n-heading size="2xlarge">{{ $locale.baseText('settings.users') }}</n8n-heading>
@ -37,13 +36,11 @@
<n8n-users-list :users="usersStore.allUsers" :currentUserId="usersStore.currentUserId" @delete="onDelete" @reinvite="onReinvite" /> <n8n-users-list :users="usersStore.allUsers" :currentUserId="usersStore.currentUserId" @delete="onDelete" @reinvite="onReinvite" />
</div> </div>
</div> </div>
</SettingsView>
</template> </template>
<script lang="ts"> <script lang="ts">
import { INVITE_USER_MODAL_KEY, VIEWS } from '@/constants'; import { INVITE_USER_MODAL_KEY, VIEWS } from '@/constants';
import SettingsView from './SettingsView.vue';
import PageAlert from '../components/PageAlert.vue'; import PageAlert from '../components/PageAlert.vue';
import { IUser } from '@/Interface'; import { IUser } from '@/Interface';
import mixins from 'vue-typed-mixins'; import mixins from 'vue-typed-mixins';
@ -56,7 +53,6 @@ import { useUsersStore } from '@/stores/users';
export default mixins(showMessage).extend({ export default mixins(showMessage).extend({
name: 'SettingsUsersView', name: 'SettingsUsersView',
components: { components: {
SettingsView,
PageAlert, PageAlert,
}, },
async mounted() { async mounted() {

View file

@ -1,26 +1,48 @@
<template> <template>
<div :class="$style.container"> <div :class="$style.container">
<SettingsSidebar /> <SettingsSidebar @return="onReturn" />
<div :class="$style.contentContainer"> <div :class="$style.contentContainer">
<div :class="$style.content"> <div :class="$style.content">
<slot> <!--
</slot> Because we're using nested routes the props are going to be bind to the top level route
so we need to pass them down to the child component
-->
<router-view name="settingsView" v-bind="$attrs" />
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts">
import Vue from 'vue'; import { defineComponent } from 'vue';
import { Route } from 'vue-router';
import SettingsSidebar from '../components/SettingsSidebar.vue'; import { VIEWS } from '@/constants';
import SettingsSidebar from '@/components/SettingsSidebar.vue';
export default Vue.extend({ const SettingsView = defineComponent({
name: 'SettingsView', name: 'SettingsView',
components: { components: {
SettingsSidebar, SettingsSidebar,
}, },
beforeRouteEnter(to, from, next) {
next(vm => {
(vm as unknown as InstanceType<typeof SettingsView>).previousRoute = from;
});
},
data() {
return {
previousRoute: null as Route | null,
};
},
methods: {
onReturn() {
this.$router.push(this.previousRoute ? this.previousRoute.path : { name: VIEWS.HOMEPAGE });
},
},
}); });
export default SettingsView;
</script> </script>
<style lang="scss" module> <style lang="scss" module>