forked from redhat-developer/rhdh
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamicRootContext.tsx
164 lines (141 loc) · 3.76 KB
/
DynamicRootContext.tsx
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
import React, { createContext } from 'react';
import { Entity } from '@backstage/catalog-model';
import {
AnyApiFactory,
AppTheme,
BackstagePlugin,
} from '@backstage/core-plugin-api';
import { ScalprumComponentProps } from '@scalprum/react-core';
export type RouteBinding = {
bindTarget: string;
bindMap: {
[target: string]: string;
};
};
export type ResolvedDynamicRouteMenuItem =
| {
text: string;
icon: string;
}
| {
Component: React.ComponentType<any>;
config: {
props?: Record<string, any>;
};
};
export type ResolvedMenuItem = {
name: string;
title: string;
icon?: string;
children?: ResolvedMenuItem[];
to?: string;
priority?: number;
};
export type DynamicModuleEntry = Pick<
ScalprumComponentProps,
'scope' | 'module'
>;
export type ResolvedDynamicRoute = DynamicModuleEntry & {
path: string;
menuItem?: ResolvedDynamicRouteMenuItem;
Component: React.ComponentType<any>;
staticJSXContent?:
| React.ReactNode
| ((dynamicRootConfig: DynamicRootConfig) => React.ReactNode);
config: {
props?: Record<string, any>;
};
};
export type ScalprumMountPointConfigBase = {
layout?: Record<string, string>;
props?: Record<string, any>;
};
export type ScalprumMountPointConfig = ScalprumMountPointConfigBase & {
if: (e: Entity) => boolean;
};
export type ScalprumMountPointConfigRawIf = {
[key in 'allOf' | 'oneOf' | 'anyOf']?: (
| {
[key: string]: string | string[];
}
| Function
)[];
};
export type ScalprumMountPointConfigRaw = ScalprumMountPointConfigBase & {
if?: ScalprumMountPointConfigRawIf;
};
export type ScalprumMountPoint = {
Component: React.ComponentType<React.PropsWithChildren>;
config?: ScalprumMountPointConfig;
staticJSXContent?:
| React.ReactNode
| ((config: DynamicRootConfig) => React.ReactNode);
};
export type RemotePlugins = {
[scope: string]: {
[module: string]: {
[importName: string]:
| React.ComponentType<React.PropsWithChildren>
| ((...args: any[]) => any)
| BackstagePlugin<{}>
| {
element: React.ComponentType<React.PropsWithChildren>;
staticJSXContent:
| React.ReactNode
| ((config: DynamicRootConfig) => React.ReactNode);
}
| AnyApiFactory;
};
};
};
export type EntityTabOverrides = Record<
string,
{ title: string; mountPoint: string; priority?: number }
>;
export type MountPoints = Record<string, ScalprumMountPoint[]>;
export type AppThemeProvider = Partial<AppTheme> & Omit<AppTheme, 'theme'>;
export type ScaffolderFieldExtension = {
scope: string;
module: string;
importName: string;
Component: React.ComponentType<{}>;
};
export type TechdocsAddon = {
scope: string;
module: string;
importName: string;
Component: React.ComponentType<{}>;
config: {
props?: Record<string, any>;
};
};
export type ProviderSetting = {
title: string;
description: string;
provider: string;
};
export type DynamicRootConfig = {
dynamicRoutes: ResolvedDynamicRoute[];
entityTabOverrides: EntityTabOverrides;
mountPoints: MountPoints;
menuItems: ResolvedMenuItem[];
providerSettings: ProviderSetting[];
scaffolderFieldExtensions: ScaffolderFieldExtension[];
techdocsAddons: TechdocsAddon[];
};
export type ComponentRegistry = {
AppProvider: React.ComponentType<React.PropsWithChildren>;
AppRouter: React.ComponentType<React.PropsWithChildren>;
} & DynamicRootConfig;
const DynamicRootContext = createContext<ComponentRegistry>({
AppProvider: () => null,
AppRouter: () => null,
dynamicRoutes: [],
entityTabOverrides: {},
mountPoints: {},
menuItems: [],
providerSettings: [],
scaffolderFieldExtensions: [],
techdocsAddons: [],
});
export default DynamicRootContext;