feat: Rewrite Front End cloud and posthog hooks using TypeScript (no-changelog) (#5491)
This commit is contained in:
@@ -184,6 +184,7 @@ export const usePostHog = defineStore('posthog', () => {
|
||||
isVariantEnabled,
|
||||
getVariant,
|
||||
reset,
|
||||
identify,
|
||||
capture,
|
||||
setMetadata,
|
||||
};
|
||||
|
||||
@@ -7,10 +7,12 @@ import {
|
||||
WEBHOOK_NODE_TYPE,
|
||||
} from '@/constants';
|
||||
import { defineStore } from 'pinia';
|
||||
|
||||
import { useSettingsStore } from '@/stores/settings.store';
|
||||
import type { INodeTypeDescription, IRun, ITelemetryTrackProperties } from 'n8n-workflow';
|
||||
import { useWorkflowsStore } from '@/stores/workflows.store';
|
||||
import { useNodeTypesStore } from '@/stores/nodeTypes.store';
|
||||
import { useUsersStore } from '@/stores/users.store';
|
||||
|
||||
const EVENTS = {
|
||||
ADDED_MANUAL_TRIGGER: 'User added manual trigger',
|
||||
@@ -27,6 +29,7 @@ export const useSegment = defineStore('segment', () => {
|
||||
const nodeTypesStore = useNodeTypesStore();
|
||||
const workflowsStore = useWorkflowsStore();
|
||||
const settingsStore = useSettingsStore();
|
||||
const usersStore = useUsersStore();
|
||||
|
||||
const track = (eventName: string, properties?: ITelemetryTrackProperties) => {
|
||||
if (settingsStore.telemetry.enabled) {
|
||||
@@ -34,6 +37,20 @@ export const useSegment = defineStore('segment', () => {
|
||||
}
|
||||
};
|
||||
|
||||
const page = (category: string, name: string, properties?: ITelemetryTrackProperties) => {
|
||||
if (settingsStore.telemetry.enabled) {
|
||||
window.analytics?.page(category, name, properties);
|
||||
}
|
||||
};
|
||||
|
||||
const identify = () => {
|
||||
const userId = usersStore.currentUserId;
|
||||
|
||||
if (settingsStore.telemetry.enabled && userId) {
|
||||
window.analytics?.identify(userId);
|
||||
}
|
||||
};
|
||||
|
||||
const trackAddedTrigger = (nodeTypeName: string) => {
|
||||
if (!nodeTypesStore.isTriggerNode(nodeTypeName)) {
|
||||
return;
|
||||
@@ -119,6 +136,8 @@ export const useSegment = defineStore('segment', () => {
|
||||
track,
|
||||
trackAddedTrigger,
|
||||
trackSuccessfulWorkflowExecution,
|
||||
identify,
|
||||
page,
|
||||
EVENTS,
|
||||
};
|
||||
});
|
||||
|
||||
@@ -115,10 +115,7 @@ export const useSettingsStore = defineStore(STORES.SETTINGS, {
|
||||
return this.settings.deployment?.type.startsWith('desktop_');
|
||||
},
|
||||
isCloudDeployment(): boolean {
|
||||
if (!this.settings.deployment) {
|
||||
return false;
|
||||
}
|
||||
return this.settings.deployment.type === 'cloud';
|
||||
return this.settings.deployment?.type === 'cloud';
|
||||
},
|
||||
isSmtpSetup(): boolean {
|
||||
return this.userManagement.smtpSetup;
|
||||
|
||||
@@ -1,69 +1,19 @@
|
||||
import { STORES } from '@/constants';
|
||||
import type { IFakeDoor, INodeUi, IRootState, NestedRecord } from '@/Interface';
|
||||
import type { IMenuItem } from 'n8n-design-system';
|
||||
import type { IWorkflowSettings } from 'n8n-workflow';
|
||||
import { defineStore } from 'pinia';
|
||||
import { useRootStore } from './n8nRoot.store';
|
||||
import { useNDVStore } from './ndv.store';
|
||||
import { useUIStore } from './ui.store';
|
||||
import { useUsersStore } from './users.store';
|
||||
import { useWorkflowsStore } from './workflows.store';
|
||||
import { useSettingsStore } from './settings.store';
|
||||
|
||||
export const useWebhooksStore = defineStore(STORES.WEBHOOKS, {
|
||||
getters: {
|
||||
globalRoleName(): string {
|
||||
return useUsersStore().globalRoleName;
|
||||
},
|
||||
getContextBasedTranslationKeys() {
|
||||
return useUIStore().contextBasedTranslationKeys;
|
||||
},
|
||||
getFakeDoorFeatures() {
|
||||
return useUIStore().fakeDoorFeatures;
|
||||
},
|
||||
getFakeDoorItems(): IFakeDoor[] {
|
||||
return useUIStore().fakeDoorFeatures;
|
||||
},
|
||||
n8nMetadata(): IRootState['n8nMetadata'] {
|
||||
return useRootStore().n8nMetadata;
|
||||
},
|
||||
instanceId(): string {
|
||||
return useRootStore().instanceId;
|
||||
},
|
||||
workflowId(): string {
|
||||
return useWorkflowsStore().workflowId;
|
||||
},
|
||||
workflowName(): string {
|
||||
return useWorkflowsStore().workflowName;
|
||||
},
|
||||
activeNode(): INodeUi | null {
|
||||
return useNDVStore().activeNode;
|
||||
},
|
||||
workflowSettings(): IWorkflowSettings {
|
||||
return useWorkflowsStore().workflowSettings;
|
||||
},
|
||||
activeExecutionId(): string {
|
||||
return useWorkflowsStore().activeExecutionId || '';
|
||||
},
|
||||
nodeByName:
|
||||
(state: IRootState) =>
|
||||
(nodeName: string): INodeUi | null => {
|
||||
return useWorkflowsStore().getNodeByName(nodeName);
|
||||
},
|
||||
allNodes(): INodeUi[] {
|
||||
return useWorkflowsStore().allNodes;
|
||||
},
|
||||
},
|
||||
actions: {
|
||||
addSidebarMenuItems(menuItems: IMenuItem[]) {
|
||||
const uiStore = useUIStore();
|
||||
const updated = uiStore.sidebarMenuItems.concat(menuItems);
|
||||
uiStore.sidebarMenuItems = updated;
|
||||
},
|
||||
setFakeDoorFeatures(fakeDoors: IFakeDoor[]): void {
|
||||
useUIStore().fakeDoorFeatures = fakeDoors;
|
||||
},
|
||||
setContextBasedTranslationKeys(translations: NestedRecord<string>): void {
|
||||
useUIStore().contextBasedTranslationKeys = translations;
|
||||
},
|
||||
},
|
||||
export const useWebhooksStore = defineStore(STORES.WEBHOOKS, () => {
|
||||
return {
|
||||
...useRootStore(),
|
||||
...useWorkflowsStore(),
|
||||
...useUIStore(),
|
||||
...useUsersStore(),
|
||||
...useNDVStore(),
|
||||
...useSettingsStore(),
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user