Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into cat-11-restructure-…
Browse files Browse the repository at this point in the history
…front-end-unit-tests-files
  • Loading branch information
alexgrozav committed Nov 1, 2024
2 parents 7e58fc4 + 02b7736 commit d5c7084
Show file tree
Hide file tree
Showing 18 changed files with 52 additions and 364 deletions.
43 changes: 43 additions & 0 deletions packages/cli/src/services/__tests__/url.service.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import type { GlobalConfig } from '@n8n/config';
import { mock } from 'jest-mock-extended';

import config from '@/config';

import { UrlService } from '../url.service';

describe('UrlService', () => {
beforeEach(() => {
process.env.WEBHOOK_URL = undefined;
config.load(config.default);
});

describe('getInstanceBaseUrl', () => {
it('should set URL from N8N_EDITOR_BASE_URL', () => {
config.set('editorBaseUrl', 'https://example.com/');
process.env.WEBHOOK_URL = undefined;
const urlService = new UrlService(mock<GlobalConfig>());
expect(urlService.getInstanceBaseUrl()).toBe('https://example.com');
});

it('should set URL from WEBHOOK_URL', () => {
config.set('editorBaseUrl', '');
process.env.WEBHOOK_URL = 'https://example.com/';
const urlService = new UrlService(mock<GlobalConfig>());
expect(urlService.getInstanceBaseUrl()).toBe('https://example.com');
});

it('should trim quotes when setting URL from N8N_EDITOR_BASE_URL', () => {
config.set('editorBaseUrl', '"https://example.com"');
process.env.WEBHOOK_URL = undefined;
const urlService = new UrlService(mock<GlobalConfig>());
expect(urlService.getInstanceBaseUrl()).toBe('https://example.com');
});

it('should trim quotes when setting URL from WEBHOOK_URL', () => {
config.set('editorBaseUrl', '');
process.env.WEBHOOK_URL = '"https://example.com/"';
const urlService = new UrlService(mock<GlobalConfig>());
expect(urlService.getInstanceBaseUrl()).toBe('https://example.com');
});
});
});
9 changes: 7 additions & 2 deletions packages/cli/src/services/url.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class UrlService {

/** Returns the base URL of the webhooks */
getWebhookBaseUrl() {
let urlBaseWebhook = process.env.WEBHOOK_URL ?? this.baseUrl;
let urlBaseWebhook = this.trimQuotes(process.env.WEBHOOK_URL) || this.baseUrl;
if (!urlBaseWebhook.endsWith('/')) {
urlBaseWebhook += '/';
}
Expand All @@ -23,7 +23,7 @@ export class UrlService {

/** Return the n8n instance base URL without trailing slash */
getInstanceBaseUrl(): string {
const n8nBaseUrl = config.getEnv('editorBaseUrl') || this.getWebhookBaseUrl();
const n8nBaseUrl = this.trimQuotes(config.getEnv('editorBaseUrl')) || this.getWebhookBaseUrl();

return n8nBaseUrl.endsWith('/') ? n8nBaseUrl.slice(0, n8nBaseUrl.length - 1) : n8nBaseUrl;
}
Expand All @@ -36,4 +36,9 @@ export class UrlService {
}
return `${protocol}://${host}:${port}${path}`;
}

/** Remove leading and trailing double quotes from a URL. */
private trimQuotes(url?: string) {
return url?.replace(/^["]+|["]+$/g, '') ?? '';
}
}
20 changes: 0 additions & 20 deletions packages/editor-ui/src/Interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import type {
AI_NODE_CREATOR_VIEW,
CREDENTIAL_EDIT_MODAL_KEY,
SignInType,
FAKE_DOOR_FEATURES,
TRIGGER_NODE_CREATOR_VIEW,
REGULAR_NODE_CREATOR_VIEW,
AI_OTHERS_NODE_CREATOR_VIEW,
Expand All @@ -62,7 +61,6 @@ import type { BulkCommand, Undoable } from '@/models/history';
import type { PartialBy, TupleToUnion } from '@/utils/typeHelpers';

import type { ProjectSharingData } from '@/types/projects.types';
import type { BaseTextKey } from './plugins/i18n';

export * from 'n8n-design-system/types';

Expand Down Expand Up @@ -1036,24 +1034,6 @@ export interface NotificationOptions extends Partial<ElementNotificationOptions>
message: string | ElementNotificationOptions['message'];
}

export type IFakeDoor = {
id: FAKE_DOOR_FEATURES;
featureName: BaseTextKey;
icon?: string;
infoText?: BaseTextKey;
actionBoxTitle: BaseTextKey;
actionBoxDescription: BaseTextKey;
actionBoxButtonLabel?: BaseTextKey;
linkURL: string;
uiLocations: IFakeDoorLocation[];
};

export type IFakeDoorLocation =
| 'settings'
| 'settings/users'
| 'credentialsModal'
| 'workflowShareModal';

export type NodeFilterType =
| typeof REGULAR_NODE_CREATOR_VIEW
| typeof TRIGGER_NODE_CREATOR_VIEW
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { NodeHelpers } from 'n8n-workflow';
import CredentialConfig from '@/components/CredentialEdit/CredentialConfig.vue';
import CredentialInfo from '@/components/CredentialEdit/CredentialInfo.vue';
import CredentialSharing from '@/components/CredentialEdit/CredentialSharing.ee.vue';
import FeatureComingSoon from '@/components/FeatureComingSoon.vue';
import InlineNameEdit from '@/components/InlineNameEdit.vue';
import Modal from '@/components/Modal.vue';
import SaveButton from '@/components/SaveButton.vue';
Expand Down Expand Up @@ -518,14 +517,13 @@ async function loadCurrentCredential() {
function onTabSelect(tab: string) {
activeTab.value = tab;
const tabName: string = tab.replaceAll('coming-soon/', '');
const credType: string = credentialType.value ? credentialType.value.name : '';
const activeNode: INode | null = ndvStore.activeNode;
telemetry.track('User viewed credential tab', {
credential_type: credType,
node_type: activeNode ? activeNode.type : null,
tab: tabName,
tab,
workflow_id: workflowsStore.workflowId,
credential_id: credentialId.value,
sharing_enabled: EnterpriseEditionFeature.Sharing,
Expand Down Expand Up @@ -1130,9 +1128,6 @@ function resetCredentialData(): void {
<div v-else-if="activeTab === 'details' && credentialType" :class="$style.mainContent">
<CredentialInfo :current-credential="currentCredential" />
</div>
<div v-else-if="activeTab.startsWith('coming-soon')" :class="$style.mainContent">
<FeatureComingSoon :feature-id="activeTab.split('/')[1]"></FeatureComingSoon>
</div>
</div>
</template>
</Modal>
Expand Down
82 changes: 0 additions & 82 deletions packages/editor-ui/src/components/FeatureComingSoon.vue

This file was deleted.

34 changes: 1 addition & 33 deletions packages/editor-ui/src/components/SettingsSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
import { computed } from 'vue';
import { ABOUT_MODAL_KEY, VIEWS } from '@/constants';
import { useUserHelpers } from '@/composables/useUserHelpers';
import type { IFakeDoor } from '@/Interface';
import type { IMenuItem } from 'n8n-design-system';
import type { BaseTextKey } from '@/plugins/i18n';
import { useUIStore } from '@/stores/ui.store';
import { useSettingsStore } from '@/stores/settings.store';
import { useRootStore } from '@/stores/root.store';
Expand All @@ -26,23 +24,6 @@ const rootStore = useRootStore();
const settingsStore = useSettingsStore();
const uiStore = useUIStore();
const settingsFakeDoorFeatures = computed<IFakeDoor[]>(() =>
Object.keys(uiStore.fakeDoorsByLocation)
.filter((location: string) => location.includes('settings'))
.map((location) => uiStore.fakeDoorsByLocation[location]),
);
const handleSelect = (key: string) => {
switch (key) {
case 'users': // Fakedoor feature added via hooks when user management is disabled on cloud
case 'logging':
router.push({ name: VIEWS.FAKE_DOOR, params: { featureId: key } }).catch(() => {});
break;
default:
break;
}
};
const sidebarMenuItems = computed<IMenuItem[]>(() => {
const menuItems: IMenuItem[] = [
{
Expand Down Expand Up @@ -122,19 +103,6 @@ const sidebarMenuItems = computed<IMenuItem[]>(() => {
},
];
for (const item of settingsFakeDoorFeatures.value) {
if (item.uiLocations.includes('settings')) {
menuItems.push({
id: item.id,
icon: item.icon ?? 'question',
label: i18n.baseText(item.featureName as BaseTextKey),
position: 'top',
available: true,
activateOnRoutePaths: [`/settings/coming-soon/${item.id}`],
});
}
}
menuItems.push({
id: 'settings-log-streaming',
icon: 'sign-in-alt',
Expand All @@ -159,7 +127,7 @@ const sidebarMenuItems = computed<IMenuItem[]>(() => {

<template>
<div :class="$style.container">
<n8n-menu :items="sidebarMenuItems" @select="handleSelect">
<n8n-menu :items="sidebarMenuItems">
<template #header>
<div :class="$style.returnButton" data-test-id="settings-back" @click="emit('return')">
<i class="mr-xs">
Expand Down
7 changes: 0 additions & 7 deletions packages/editor-ui/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,6 @@ export const enum VIEWS {
PERSONAL_SETTINGS = 'PersonalSettings',
API_SETTINGS = 'APISettings',
NOT_FOUND = 'NotFoundView',
FAKE_DOOR = 'ComingSoon',
COMMUNITY_NODES = 'CommunityNodes',
WORKFLOWS = 'WorkflowsView',
WORKFLOW_EXECUTIONS = 'WorkflowExecutions',
Expand All @@ -500,12 +499,6 @@ export const enum VIEWS {

export const EDITABLE_CANVAS_VIEWS = [VIEWS.WORKFLOW, VIEWS.NEW_WORKFLOW, VIEWS.EXECUTION_DEBUG];

export const enum FAKE_DOOR_FEATURES {
ENVIRONMENTS = 'environments',
LOGGING = 'logging',
SSO = 'sso',
}

export const TEST_PIN_DATA = [
{
name: 'First item',
Expand Down
13 changes: 0 additions & 13 deletions packages/editor-ui/src/hooks/cloud.ts

This file was deleted.

40 changes: 0 additions & 40 deletions packages/editor-ui/src/hooks/register.ts

This file was deleted.

6 changes: 0 additions & 6 deletions packages/editor-ui/src/hooks/types.ts

This file was deleted.

Loading

0 comments on commit d5c7084

Please sign in to comment.