index.ts
3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import { BasicConnectionModalEnum } from '../enum';
import { FetchNodeComFlagTypeENum } from '../enum/node';
import type { NodeItemConfigType } from '../types/node';
import { ActionCategoryConfig, ActionComponents } from './Action';
import { EnrichmentCategoryConfig, EnrichmentComponents } from './Enrichment';
import { ExternalCategoryConfig, ExternalComponents } from './External';
import { FilterCategoryConfig, FilterComponents } from './Filter';
import { FlowCategoryConfig, FlowComponents } from './Flow';
import { TransformationCategoryConfig, TransformationComponents } from './Transformation';
import { CategoryItemType, RuleNodeTypeEnum } from './index.type';
const createModules = import.meta.glob('../packages/**/create.vue');
const connectionModules = import.meta.glob('../packages/**/connection.vue');
const nodeExtraContentModules = import.meta.glob('../packages/**/node.vue');
const BasicConnectionComponent = {
[BasicConnectionModalEnum.BASIC]: () =>
import('../src/components/CreateEdgeModal/BasicRelations.vue'),
[BasicConnectionModalEnum.CUSTOM]: () =>
import('../src/components/CreateEdgeModal/CustomRelations.vue'),
};
export const fetchNodeComponent = (config: NodeItemConfigType, flag: FetchNodeComFlagTypeENum) => {
const { key, categoryType } = config;
const modules =
flag === FetchNodeComFlagTypeENum.CONNECTION_MODAL ? connectionModules : createModules;
const modulesName = Object.keys(modules);
const path = modulesName.find((item) => {
const temp = item.split('/');
const categoryName = temp[temp.length - 3];
const fileName = temp[temp.length - 2];
return fileName === key && categoryType.toUpperCase() === categoryName.toUpperCase();
});
return path ? modules[path] : null;
};
export const fetchConnectionComponent = async (config: NodeItemConfigType) => {
const { configurationDescriptor } = config;
const { nodeDefinition } = configurationDescriptor;
const { customRelations } = nodeDefinition;
return customRelations
? BasicConnectionComponent[BasicConnectionModalEnum.CUSTOM]
: BasicConnectionComponent[BasicConnectionModalEnum.BASIC];
};
export const fetchCreateComponent = async (config: NodeItemConfigType) => {
return fetchNodeComponent(config, FetchNodeComFlagTypeENum.CREATE_MODAL);
};
export const fetchNodeExtraContent = async (config: NodeItemConfigType) => {
const { key, categoryType } = config || {};
const modulesName = Object.keys(nodeExtraContentModules);
const path = modulesName.find((item) => {
const temp = item.split('/');
const categoryName = temp[temp.length - 3];
const fileName = temp[temp.length - 2];
return fileName === key && categoryType.toUpperCase() === categoryName.toUpperCase();
});
return path ? nodeExtraContentModules[path] : null;
};
export const allComponents: Record<
Exclude<RuleNodeTypeEnum, RuleNodeTypeEnum.ENTRY>,
CategoryItemType
> = {
[RuleNodeTypeEnum.FILTER]: {
category: FilterCategoryConfig,
components: FilterComponents,
},
[RuleNodeTypeEnum.ENRICHMENT]: {
category: EnrichmentCategoryConfig,
components: EnrichmentComponents,
},
[RuleNodeTypeEnum.TRANSFORMATION]: {
category: TransformationCategoryConfig,
components: TransformationComponents,
},
[RuleNodeTypeEnum.ACTION]: {
category: ActionCategoryConfig,
components: ActionComponents,
},
[RuleNodeTypeEnum.EXTERNAL]: {
category: ExternalCategoryConfig,
components: ExternalComponents,
},
[RuleNodeTypeEnum.FLOW]: {
category: FlowCategoryConfig,
components: FlowComponents,
},
};