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): Fix Admin panel icon in the sidebar for cloud deployments (no-changelog) #7738

Merged
merged 5 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 16 additions & 0 deletions cypress/e2e/27-opt-in-trial-banner.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,20 @@ describe('BannerStack', { disableAutoLogin: true }, () => {

mainSidebar.actions.signout();
});

it('Should show admin button', () => {
cy.intercept('GET', '/rest/settings', (req) => {
req.on('response', (res) => {
res.send({
data: { ...res.body.data, deployment: { type: 'cloud' }, n8nMetadata: { userId: 1 } },
});
});
}).as('loadSettings');

cy.signin({ email: INSTANCE_OWNER.email, password: INSTANCE_OWNER.password });

cy.visit(workflowPage.url);

mainSidebar.getters.adminPanel().should('be.visible');
});
});
1 change: 1 addition & 0 deletions cypress/pages/sidebar/main-sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class MainSidebar extends BasePage {
workflows: () => this.getters.menuItem('Workflows'),
credentials: () => this.getters.menuItem('Credentials'),
executions: () => this.getters.menuItem('Executions'),
adminPanel: () => this.getters.menuItem('Admin Panel'),
userMenu: () => cy.get('div[class="action-dropdown-container"]'),
logo: () => cy.getByTestId('n8n-logo'),
};
Expand Down
18 changes: 4 additions & 14 deletions packages/editor-ui/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ import {
} from '@/stores';
import { useHistoryHelper } from '@/composables/useHistoryHelper';
import { useRoute } from 'vue-router';
import type { ExternalHooks } from '@/types';
import type { PartialDeep } from 'type-fest';
import { runExternalHook } from '@/utils';

export default defineComponent({
Expand Down Expand Up @@ -136,19 +134,10 @@ export default defineComponent({
}
},
async initializeHooks(): Promise<void> {
const hooksImports = [];

if (this.settingsStore.isCloudDeployment) {
hooksImports.push(
import('./hooks/cloud').then(
({ n8nCloudHooks }: { n8nCloudHooks: PartialDeep<ExternalHooks> }) => {
extendExternalHooks(n8nCloudHooks);
},
),
);
const { n8nCloudHooks } = await import('@/hooks/cloud');
extendExternalHooks(n8nCloudHooks);
}

await Promise.allSettled(hooksImports);
},
async onAfterAuthenticate() {
if (this.onAfterAuthenticateInitialized) {
Expand All @@ -160,7 +149,6 @@ export default defineComponent({
}

await Promise.all([
this.initializeCloudData(),
this.initializeSourceControl(),
this.initializeTemplates(),
this.initializeNodeTranslationHeaders(),
Expand All @@ -172,7 +160,9 @@ export default defineComponent({
async mounted() {
this.logHiringBanner();

await this.settingsStore.initialize();
await this.initializeHooks();
await this.initializeCloudData();

void this.checkForNewVersions();
void this.onAfterAuthenticate();
Expand Down
12 changes: 12 additions & 0 deletions packages/editor-ui/src/components/MainSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,14 @@ export default defineComponent({
this.settingsStore.isQueueModeEnabled && this.settingsStore.isWorkerViewAvailable,
activateOnRouteNames: [VIEWS.WORKER_VIEW],
},
{
id: 'cloud-admin',
type: 'link',
position: 'bottom',
label: 'Admin Panel',
icon: 'home',
available: this.settingsStore.isCloudDeployment && this.usersStore.isInstanceOwner,
},
{
id: 'settings',
icon: 'cog',
Expand Down Expand Up @@ -461,6 +469,10 @@ export default defineComponent({
this.uiStore.openModal(ABOUT_MODAL_KEY);
break;
}
case 'cloud-admin': {
this.cloudPlanStore.redirectToDashboard();
break;
}
case 'quickstart':
case 'docs':
case 'forum':
Expand Down
8 changes: 1 addition & 7 deletions packages/editor-ui/src/hooks/cloud.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { hooksAddAdminIcon, hooksAddFakeDoorFeatures } from '@/hooks/utils';
import { hooksAddFakeDoorFeatures } from '@/hooks/utils';
import {
getAuthenticationModalEventData,
getExpressionEditorEventsData,
Expand Down Expand Up @@ -29,9 +29,6 @@ import type { ExternalHooks } from '@/types';
export const n8nCloudHooks: PartialDeep<ExternalHooks> = {
app: {
mount: [
() => {
hooksAddAdminIcon();
},
() => {
hooksAddFakeDoorFeatures();
},
Expand All @@ -43,9 +40,6 @@ export const n8nCloudHooks: PartialDeep<ExternalHooks> = {
const segmentStore = useSegment();
segmentStore.identify();
},
() => {
hooksAddAdminIcon();
},
],
createNodeActiveChanged: [
(_, meta) => {
Expand Down
38 changes: 0 additions & 38 deletions packages/editor-ui/src/hooks/utils/hooksAddAdminIcon.ts

This file was deleted.

This file was deleted.

2 changes: 0 additions & 2 deletions packages/editor-ui/src/hooks/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
export * from './hooksAddAdminIcon';
export * from './hooksAddAutoLoginToAdminPanelButton';
export * from './hooksAddFakeDoorFeatures';
export * from './hooksNodesPanel';
1 change: 0 additions & 1 deletion packages/editor-ui/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,6 @@ router.beforeEach(async (to, from, next) => {

const settingsStore = useSettingsStore();
const usersStore = useUsersStore();
await settingsStore.initialize();
await usersStore.initialize();

/**
Expand Down
7 changes: 7 additions & 0 deletions packages/editor-ui/src/stores/cloudPlan.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => {
} catch {}
};

const redirectToDashboard = async () => {
const adminPanelHost = new URL(window.location.href).host.split('.').slice(1).join('.');
const { code } = await getAutoLoginCode();
window.location.href = `https://${adminPanelHost}/login?code=${code}`;
};

return {
state,
getOwnerCurrentPlan,
Expand All @@ -166,5 +172,6 @@ export const useCloudPlanStore = defineStore(STORES.CLOUD_PLAN, () => {
checkForCloudPlanData,
fetchUserCloudAccount,
getAutoLoginCode,
redirectToDashboard,
};
});
Loading