@fluxo-dev/shell 0.0.8 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (119) hide show
  1. package/index.esm.css +115 -0
  2. package/index.esm.d.ts +1 -0
  3. package/index.esm.js +68195 -0
  4. package/package.json +13 -2
  5. package/src/index.d.ts +1 -0
  6. package/src/lib/app.d.ts +16 -0
  7. package/src/lib/components/error-page/404.d.ts +1 -0
  8. package/src/lib/components/routes/main-routes.d.ts +6 -0
  9. package/src/lib/layouts/blank/blank-layout.d.ts +2 -0
  10. package/src/lib/layouts/main/app-bar.d.ts +9 -0
  11. package/src/lib/layouts/main/app-layout.d.ts +5 -0
  12. package/src/lib/layouts/main/content.d.ts +2 -0
  13. package/src/lib/layouts/main/footer-bar.d.ts +5 -0
  14. package/src/lib/layouts/main/navbar-item.d.ts +12 -0
  15. package/src/lib/layouts/main/navbar.d.ts +1 -0
  16. package/src/lib/layouts/main/search-bar.d.ts +5 -0
  17. package/src/lib/layouts/main/shell-spotlight.d.ts +2 -0
  18. package/src/lib/models/app-jit.d.ts +5 -0
  19. package/src/lib/pages/general/fluxo-plugin-loader.d.ts +7 -0
  20. package/src/lib/pages/login/account-confirmation.d.ts +2 -0
  21. package/src/lib/pages/login/change-password.d.ts +2 -0
  22. package/src/lib/pages/login/forgot-password.d.ts +2 -0
  23. package/src/lib/pages/login/login-page.d.ts +2 -0
  24. package/src/lib/pages/login/reset-password.d.ts +2 -0
  25. package/src/lib/pages/settings/apps/add-jit-app.d.ts +5 -0
  26. package/src/lib/pages/settings/apps/app-item.d.ts +10 -0
  27. package/src/lib/pages/settings/apps/app-jit-item.d.ts +8 -0
  28. package/src/lib/pages/settings/apps/apps-list.d.ts +6 -0
  29. package/src/lib/pages/settings/apps/embedded-module-item.d.ts +10 -0
  30. package/src/lib/pages/settings/apps/install-or-upgrade-app.d.ts +6 -0
  31. package/src/lib/pages/settings/menu-designer/custom-node.d.ts +14 -0
  32. package/src/lib/pages/settings/menu-designer/menu-create-form.d.ts +5 -0
  33. package/src/lib/pages/settings/menu-designer/menu-designer.d.ts +1 -0
  34. package/src/lib/pages/settings/menu-designer/menu-item-edit.d.ts +8 -0
  35. package/src/lib/pages/settings/menu-designer/placeholder.d.ts +8 -0
  36. package/src/lib/pages/settings/security/components/domani-role/domain-role-form.d.ts +6 -0
  37. package/src/lib/pages/settings/security/components/domani-role/domain-role-grid.d.ts +1 -0
  38. package/src/lib/pages/settings/security/components/permission/create-custom-permission-form.d.ts +7 -0
  39. package/src/lib/pages/settings/security/components/permission/create-scope-form.d.ts +7 -0
  40. package/src/lib/pages/settings/security/components/permission/permission-grid.d.ts +1 -0
  41. package/src/lib/pages/settings/security/components/permission/permission-navigator.d.ts +8 -0
  42. package/src/lib/pages/settings/security/components/permission/update-permission.d.ts +5 -0
  43. package/src/lib/pages/settings/security/components/route-rule/route-rule-create-form.d.ts +7 -0
  44. package/src/lib/pages/settings/security/components/route-rule/route-rule-grid.d.ts +1 -0
  45. package/src/lib/pages/settings/security/components/user/user-form.d.ts +7 -0
  46. package/src/lib/pages/settings/security/components/user/users-grid.d.ts +1 -0
  47. package/src/lib/pages/settings/settings.d.ts +6 -0
  48. package/src/lib/pages/settings/token/token-row.d.ts +7 -0
  49. package/src/lib/pages/settings/token/tokens.d.ts +2 -0
  50. package/src/lib/pages/settings/ui/ui.d.ts +1 -0
  51. package/src/lib/services/app-jit-manager.d.ts +10 -0
  52. package/src/lib/services/app-menu.service.d.ts +5 -0
  53. package/src/lib/utils/icon-factory.d.ts +9 -0
  54. package/src/lib/utils/security/only-not-logged-route.d.ts +2 -0
  55. package/src/lib/utils/security/protected-route.d.ts +2 -0
  56. package/.babelrc +0 -12
  57. package/.eslintrc.json +0 -18
  58. package/jest.config.ts +0 -11
  59. package/project.json +0 -43
  60. package/src/index.ts +0 -1
  61. package/src/lib/app.module.css +0 -1
  62. package/src/lib/app.spec.tsx +0 -17
  63. package/src/lib/app.tsx +0 -374
  64. package/src/lib/components/error-page/404.tsx +0 -16
  65. package/src/lib/components/routes/main-routes.tsx +0 -26
  66. package/src/lib/layouts/blank/blank-layout.tsx +0 -10
  67. package/src/lib/layouts/main/app-bar.tsx +0 -192
  68. package/src/lib/layouts/main/app-layout.tsx +0 -52
  69. package/src/lib/layouts/main/content.tsx +0 -10
  70. package/src/lib/layouts/main/footer-bar.tsx +0 -76
  71. package/src/lib/layouts/main/navbar-item.module.css +0 -49
  72. package/src/lib/layouts/main/navbar-item.tsx +0 -129
  73. package/src/lib/layouts/main/navbar.tsx +0 -38
  74. package/src/lib/layouts/main/search-bar.tsx +0 -44
  75. package/src/lib/layouts/main/shell-spotlight.tsx +0 -58
  76. package/src/lib/models/app-jit.ts +0 -6
  77. package/src/lib/pages/general/fluxo-plugin-loader.tsx +0 -22
  78. package/src/lib/pages/login/account-confirmation.tsx +0 -86
  79. package/src/lib/pages/login/change-password.tsx +0 -58
  80. package/src/lib/pages/login/forgot-password.tsx +0 -53
  81. package/src/lib/pages/login/login-page.tsx +0 -70
  82. package/src/lib/pages/login/reset-password.tsx +0 -91
  83. package/src/lib/pages/settings/apps/add-jit-app.tsx +0 -79
  84. package/src/lib/pages/settings/apps/app-item.tsx +0 -157
  85. package/src/lib/pages/settings/apps/app-jit-item.tsx +0 -105
  86. package/src/lib/pages/settings/apps/apps-list.tsx +0 -171
  87. package/src/lib/pages/settings/apps/embedded-module-item.tsx +0 -66
  88. package/src/lib/pages/settings/apps/install-or-upgrade-app.tsx +0 -105
  89. package/src/lib/pages/settings/menu-designer/custom-node.module.css +0 -34
  90. package/src/lib/pages/settings/menu-designer/custom-node.tsx +0 -160
  91. package/src/lib/pages/settings/menu-designer/menu-create-form.tsx +0 -109
  92. package/src/lib/pages/settings/menu-designer/menu-designer.module.css +0 -19
  93. package/src/lib/pages/settings/menu-designer/menu-designer.tsx +0 -463
  94. package/src/lib/pages/settings/menu-designer/menu-item-edit.tsx +0 -115
  95. package/src/lib/pages/settings/menu-designer/placeholder.module.css +0 -8
  96. package/src/lib/pages/settings/menu-designer/placeholder.tsx +0 -13
  97. package/src/lib/pages/settings/security/components/domani-role/domain-role-form.tsx +0 -67
  98. package/src/lib/pages/settings/security/components/domani-role/domain-role-grid.tsx +0 -139
  99. package/src/lib/pages/settings/security/components/permission/create-custom-permission-form.tsx +0 -64
  100. package/src/lib/pages/settings/security/components/permission/create-scope-form.tsx +0 -158
  101. package/src/lib/pages/settings/security/components/permission/permission-grid.tsx +0 -304
  102. package/src/lib/pages/settings/security/components/permission/permission-navigator.tsx +0 -320
  103. package/src/lib/pages/settings/security/components/permission/update-permission.tsx +0 -54
  104. package/src/lib/pages/settings/security/components/route-rule/route-rule-create-form.tsx +0 -59
  105. package/src/lib/pages/settings/security/components/route-rule/route-rule-grid.tsx +0 -229
  106. package/src/lib/pages/settings/security/components/user/user-form.tsx +0 -123
  107. package/src/lib/pages/settings/security/components/user/users-grid.tsx +0 -127
  108. package/src/lib/pages/settings/settings.tsx +0 -298
  109. package/src/lib/pages/settings/token/token-row.tsx +0 -69
  110. package/src/lib/pages/settings/token/tokens.tsx +0 -73
  111. package/src/lib/pages/settings/ui/ui.tsx +0 -149
  112. package/src/lib/services/app-jit-manager.ts +0 -92
  113. package/src/lib/services/app-menu.service.ts +0 -35
  114. package/src/lib/utils/icon-factory.tsx +0 -25
  115. package/src/lib/utils/security/only-not-logged-route.tsx +0 -17
  116. package/src/lib/utils/security/protected-route.tsx +0 -47
  117. package/tsconfig.json +0 -20
  118. package/tsconfig.lib.json +0 -24
  119. package/tsconfig.spec.json +0 -20
@@ -1,320 +0,0 @@
1
- import React, {useEffect, useState} from "react";
2
- import {
3
- FluxoClientSys,
4
- Permission, PermissionScope
5
- } from "@fluxo-dev/api-client-base";
6
- import {Badge, Checkbox, Grid, Group, Loader, NavLink, ScrollArea, Stack, Text, TextInput} from "@mantine/core";
7
- import {IconSearch} from '@tabler/icons-react';
8
- import {NoData} from "@fluxo-dev/ui-components";
9
- import {showNotification} from "@mantine/notifications";
10
-
11
- export interface PermissionNavigatorProps {
12
- context: {type: 'domainRole' | 'menu' | 'route-rule', id: string};
13
- onUpdate: (currentPermissionCount: number) => void;
14
- }
15
-
16
- export function PermissionNavigator(props: PermissionNavigatorProps) {
17
-
18
- const [structuredPermissions, setStructuredPermissions] = useState<PermissionScope[]>();
19
- const [domainRolePermissions, setDomainRolePermissions] = useState<Permission[]>([]);
20
-
21
- const [structuredPermissionLoaded, setStructuredPermissionLoaded] = useState<boolean>(false);
22
- const [domainRolePermissionLoaded, setDomainRolePermissionLoaded] = useState<boolean>(false);
23
-
24
- //const [currentPackageName, setCurrentPackageName] = useState<StructuredPermissionsPackageName>();
25
-
26
- const [selectedPermissionsIds, setSelectedPermissionsIds] = useState<number[]>([]);
27
-
28
- const [currentScope, setCurrentScope] = useState<string>();
29
- const [currentPackageName, setCurrentPackageName] = useState<string>();
30
- const [currentNamespace, setCurrentNamespace] = useState<string>();
31
-
32
- const [currentPermissions, setCurrentPermissions] = useState<Permission[]>([]);
33
-
34
-
35
- useEffect(() => {
36
- props.onUpdate(selectedPermissionsIds.length);
37
- }, [selectedPermissionsIds])
38
-
39
- useEffect(() => {
40
- FluxoClientSys.Instance.security.permission.getPermissionScopes()
41
- .then((res) => {
42
- setStructuredPermissions(res);
43
- setStructuredPermissionLoaded(true);
44
- })
45
-
46
- if(props.context.type === 'domainRole') {
47
-
48
- FluxoClientSys.Instance.security.domainRole.getPermissions(props.context.id)
49
- .then((res) => {
50
- setDomainRolePermissions(res);
51
- setDomainRolePermissionLoaded(true);
52
- });
53
-
54
- } else if(props.context.type === 'menu') {
55
-
56
- FluxoClientSys.Instance.configuration.getMenuItemPermissions(props.context.id)
57
- .then((res) => {
58
- setDomainRolePermissions(res);
59
- setDomainRolePermissionLoaded(true);
60
- });
61
- } else {
62
-
63
- FluxoClientSys.Instance.security.routeRule.getPermissions(props.context.id)
64
- .then((res) => {
65
- setDomainRolePermissions(res);
66
- setDomainRolePermissionLoaded(true);
67
- });
68
- }
69
-
70
- }, [])
71
-
72
- useEffect(() => {
73
- if(structuredPermissionLoaded && domainRolePermissionLoaded) {
74
- const initPermissions = [...domainRolePermissions.map((p) => p.id)];
75
- setSelectedPermissionsIds(initPermissions);
76
- }
77
- }, [structuredPermissionLoaded, domainRolePermissionLoaded])
78
-
79
- const addOrRemovePermission = (permissionId: number) => {
80
- if(props.context.type === 'domainRole') {
81
- addOrRemovePermissionForDomainRole(permissionId);
82
- } else if(props.context.type === 'menu') {
83
- addOrRemovePermissionForMenu(permissionId);
84
- } else if(props.context.type === 'route-rule') {
85
- addOrRemovePermissionForRouteRule(permissionId);
86
- }
87
- }
88
-
89
- const addOrRemovePermissionForRouteRule = (menuItemId: number) => {
90
- if(selectedPermissionsIds.includes(menuItemId)) {
91
-
92
- FluxoClientSys.Instance.security.routeRule.removePermission(+props.context.id, menuItemId)
93
- .then((res) => {
94
- setSelectedPermissionsIds(selectedPermissionsIds.filter((p) => p !== menuItemId));
95
- showNotification({
96
- title: "Permesso rimosso",
97
- message: "Il permesso è stato rimosso correttamente",
98
- color: "green",
99
- });
100
- })
101
- .catch((err) => {
102
- showNotification({
103
- title: "Errore",
104
- message: "Si è verificato un errore durante la rimozione del permesso",
105
- color: "red",
106
- });
107
- });
108
-
109
- } else {
110
-
111
- FluxoClientSys.Instance.security.routeRule.addPermission(+props.context.id, menuItemId)
112
- .then((res) => {
113
- setSelectedPermissionsIds([...selectedPermissionsIds, menuItemId]);
114
- showNotification({
115
- title: "Permesso aggiunto",
116
- message: "Il permesso è stato aggiunto correttamente",
117
- color: "green",
118
- });
119
- })
120
- .catch((err) => {
121
- showNotification({
122
- title: "Errore",
123
- message: "Si è verificato un errore durante l'aggiunta del permesso",
124
- color: "red",
125
- });
126
- });
127
- }
128
- }
129
- const addOrRemovePermissionForMenu = (menuItemId: number) => {
130
- if(selectedPermissionsIds.includes(menuItemId)) {
131
-
132
- FluxoClientSys.Instance.configuration.removeMenuItemPermission(+props.context.id, menuItemId)
133
- .then((res) => {
134
- setSelectedPermissionsIds(selectedPermissionsIds.filter((p) => p !== menuItemId));
135
- showNotification({
136
- title: "Permesso rimosso",
137
- message: "Il permesso è stato rimosso correttamente",
138
- color: "green",
139
- });
140
- })
141
- .catch((err) => {
142
- showNotification({
143
- title: "Errore",
144
- message: "Si è verificato un errore durante la rimozione del permesso",
145
- color: "red",
146
- });
147
- });
148
-
149
- } else {
150
-
151
- FluxoClientSys.Instance.configuration.addMenuItemPermission(+props.context.id, menuItemId)
152
- .then((res) => {
153
- setSelectedPermissionsIds([...selectedPermissionsIds, menuItemId]);
154
- showNotification({
155
- title: "Permesso aggiunto",
156
- message: "Il permesso è stato aggiunto correttamente",
157
- color: "green",
158
- });
159
- })
160
- .catch((err) => {
161
- showNotification({
162
- title: "Errore",
163
- message: "Si è verificato un errore durante l'aggiunta del permesso",
164
- color: "red",
165
- });
166
- });
167
- }
168
- }
169
-
170
- const addOrRemovePermissionForDomainRole = (permissionId: number) => {
171
- if(selectedPermissionsIds.includes(permissionId)) {
172
-
173
- FluxoClientSys.Instance.security.domainRole.removePermission(+props.context.id, permissionId)
174
- .then((res) => {
175
- setSelectedPermissionsIds(selectedPermissionsIds.filter((p) => p !== permissionId));
176
- showNotification({
177
- title: "Permesso rimosso",
178
- message: "Il permesso è stato rimosso correttamente",
179
- color: "green",
180
- });
181
- })
182
- .catch((err) => {
183
- showNotification({
184
- title: "Errore",
185
- message: "Si è verificato un errore durante la rimozione del permesso",
186
- color: "red",
187
- });
188
- });
189
-
190
- } else {
191
-
192
- FluxoClientSys.Instance.security.domainRole.addPermission(+props.context.id, permissionId)
193
- .then((res) => {
194
- setSelectedPermissionsIds([...selectedPermissionsIds, permissionId]);
195
- showNotification({
196
- title: "Permesso aggiunto",
197
- message: "Il permesso è stato aggiunto correttamente",
198
- color: "green",
199
- });
200
- })
201
- .catch((err) => {
202
- showNotification({
203
- title: "Errore",
204
- message: "Si è verificato un errore durante l'aggiunta del permesso",
205
- color: "red",
206
- });
207
- });
208
- }
209
- }
210
-
211
- const getScopes = () => {
212
- if(structuredPermissions === undefined) return [];
213
- return [...new Set(structuredPermissions.map(a => a.scope))];
214
- }
215
-
216
- const getPackageNames = (scope: string) => {
217
- if(structuredPermissions === undefined) return [];
218
- return [...new Set(structuredPermissions.filter(a => a.scope === scope).map(a => a.packageName))];
219
- }
220
-
221
- const getNamespaces = (scope: string, packageName: string) => {
222
- if(structuredPermissions === undefined) return [];
223
- return [...new Set(structuredPermissions.filter(a => a.scope === scope && a.packageName === packageName).map(a => a.namespace))];
224
- }
225
-
226
- const getPermissions = (scope: string, packageName: string, namespace: string) => {
227
- FluxoClientSys.Instance.security.permission.getPermissionsInScope(scope, packageName, namespace)
228
- .then((res) => {
229
- setCurrentPermissions(res);
230
- })
231
- .catch((err) => {
232
- showNotification({
233
- title: "Errore",
234
- message: "Si è verificato un errore durante il caricamento dei permessi",
235
- color: "red",
236
- })
237
- })
238
- }
239
-
240
- return (
241
- <>
242
- {!(structuredPermissionLoaded && domainRolePermissionLoaded) ?
243
- <Loader /> :
244
-
245
- <Stack gap={8}>
246
-
247
- <Grid h={480} m={0} mt={1}>
248
- <Grid.Col span={4} p={0} style={{border: '1px solid #ececec', borderRight: 'none'}}>
249
-
250
- <ScrollArea h={430}>
251
- {getScopes().map((s) => {
252
- return (
253
- <NavLink key={s} label={s} leftSection={<Badge size="xs" variant="filled" color="yellow" w={16} h={16} p={0}>{99}</Badge>}>
254
- <>
255
- {getPackageNames(s).map((n) => {
256
- return (
257
- <NavLink
258
- key={n}
259
- label={n}
260
- leftSection={<Badge size="xs" variant="filled" color="yellow" w={16} h={16} p={0}>{99}</Badge>}>
261
-
262
- {getNamespaces(s, n).map((ns) => {
263
- return (
264
- <NavLink
265
- key={ns}
266
- label={ns}
267
- onClick={() => {
268
- setCurrentScope(s);
269
- setCurrentPackageName(n);
270
- setCurrentNamespace(ns);
271
- getPermissions(s, n, ns)
272
- }}
273
- leftSection={<Badge size="xs" variant="filled" color="yellow" w={16} h={16} p={0}>{99}</Badge>} />
274
- )
275
- })}
276
-
277
- </NavLink>
278
- )
279
- })}
280
- </>
281
- </NavLink>
282
- )
283
- })}
284
- </ScrollArea>
285
- </Grid.Col>
286
- <Grid.Col h={480} span={8} p={0} style={{border: '1px solid #ececec'}}>
287
-
288
- {(currentPackageName && currentScope && currentNamespace) ?
289
- <>
290
- <Group justify={'space-between'} style={{background: '#ececec', marginBottom: 8}}>
291
- <Text size={'md'} p={8}>{`${currentScope}.${currentPackageName}.${currentNamespace}`}</Text>
292
- <TextInput pr={8} leftSection={<IconSearch size={16} />} placeholder={'Cerca'} />
293
- </Group>
294
- <ScrollArea h={430}>
295
- <Stack style={{width: '100%'}} p={8}>
296
- {currentPermissions?.map((p) => {
297
- return (
298
- <Checkbox
299
- key={p.id}
300
- description={p.identifier}
301
- label={!p.isCustom ? p.description : <>{p.description}<Badge ml={8}>Personalizzato</Badge></>}
302
- onChange={() => addOrRemovePermission(p.id)}
303
- checked={selectedPermissionsIds.includes(p.id)}
304
- />
305
- )
306
- })}
307
- </Stack>
308
- </ScrollArea>
309
- </> :
310
- <div style={{marginTop: 32}}>
311
- <NoData message={'Seleziona un package'} />
312
- </div>
313
- }
314
- </Grid.Col>
315
- </Grid>
316
- </Stack>
317
- }
318
- </>
319
- )
320
- }
@@ -1,54 +0,0 @@
1
- import React from "react";
2
- import {Button, Group, Stack, Textarea} from "@mantine/core";
3
- import {FluxoClientSys, InstallPermissionCommand} from "@fluxo-dev/api-client-base";
4
- import {showNotification} from "@mantine/notifications";
5
-
6
- export interface UpdatePermissionProps {
7
- onUpdated: () => void;
8
- onCanceled: () => void;
9
- }
10
-
11
- export function UpdatePermission(props: UpdatePermissionProps) {
12
-
13
- const [permissionsJson, setPermissionsJson] = React.useState<string>('');
14
-
15
- const updatePermissions = () => {
16
- try{
17
- const data = JSON.parse(permissionsJson) as InstallPermissionCommand;
18
-
19
- FluxoClientSys.Instance.security.permission.installPermissions(data)
20
- .then(() => {
21
-
22
- showNotification({
23
- title: 'Operazione completata',
24
- color: 'green',
25
- message: `I permessi sono stati aggiornati con successo`,
26
- })
27
-
28
- props.onUpdated();
29
- }, (err) => {
30
- showNotification({
31
- title: 'Operazione fallita',
32
- color: 'red',
33
- message: `Non è stato possibile aggiornare i permessi: ${err.message}`,
34
- });
35
- });
36
- }catch (err) {
37
- showNotification({
38
- title: 'Operazione fallita',
39
- color: 'red',
40
- message: `Il file non è valido.`,
41
- });
42
- }
43
- }
44
-
45
- return (
46
- <Stack>
47
- <Textarea minRows={20} value={permissionsJson} onChange={(v) => setPermissionsJson(v.target.value)} />
48
- <Group justify={'right'}>
49
- <Button onClick={props.onCanceled}>Annulla</Button>
50
- <Button onClick={updatePermissions} disabled={!permissionsJson}>Aggiorna</Button>
51
- </Group>
52
- </Stack>
53
- )
54
- }
@@ -1,59 +0,0 @@
1
- import React, {useState} from "react";
2
- import {FluxoClientSys, RouteRule} from "@fluxo-dev/api-client-base";
3
- import {showNotification} from "@mantine/notifications";
4
- import {Alert, Button, Divider, Group, Stack, TextInput} from "@mantine/core";
5
- import {IconInfoCircle} from "@tabler/icons-react";
6
-
7
- export interface RouteRuleCreateFormProps {
8
- scope: string;
9
- packageName: string;
10
- onCanceled: () => void;
11
- onCreated: () => void;
12
- }
13
-
14
- export function RouteRuleCreateForm(props: RouteRuleCreateFormProps) {
15
- const [identifier, setIdentifier] = useState<string>('');
16
-
17
- const createRouteRule = () => {
18
- if(!identifier) return;
19
-
20
- const command: RouteRule = {
21
- scope: props.scope,
22
- packageName: props.packageName,
23
- route: identifier,
24
- }
25
- FluxoClientSys.Instance.security.routeRule.create(command)
26
- .then(() => {
27
- showNotification({
28
- title: 'Regola creata',
29
- message: `La regola ${props.scope}.${props.packageName}.${identifier} è stato creata con successo.`,
30
- color: 'green'
31
- })
32
- props.onCreated();
33
- })
34
- .catch(() => {
35
- showNotification({
36
- title: 'Errore',
37
- message: `Si è verificato un errore durante la creazione della regola ${props.scope}.${props.packageName}.${identifier}.`,
38
- color: 'red'
39
- })
40
- });
41
- }
42
-
43
- return (
44
- <Stack>
45
- <TextInput label={"Identificatore"} placeholder={'Es: create'} required onChange={(v) => setIdentifier(v.target.value)} />
46
-
47
- <p>Rotta: {`${props.scope}/${props.packageName}/${identifier}`}</p>
48
- <Divider />
49
- <Group justify={'right'}>
50
- <Button variant={'subtle'} onClick={props.onCanceled}>Annulla</Button>
51
- <Button
52
- disabled={!identifier}
53
- onClick={createRouteRule}>
54
- Salva
55
- </Button>
56
- </Group>
57
- </Stack>
58
- )
59
- }
@@ -1,229 +0,0 @@
1
- import {ActionIcon, Button, Center, Divider, Grid, Group, Modal, Select, Stack, Table, Text} from "@mantine/core";
2
- import {DataCard} from "@fluxo-dev/ui-components";
3
- import React, {useEffect, useState} from "react";
4
- import {FluxoClientSys, PermissionScope, RouteRule} from "@fluxo-dev/api-client-base";
5
- import {IconCloudOff, IconLock, IconPlus, IconTrash} from "@tabler/icons-react";
6
- import {PermissionNavigator} from "../permission/permission-navigator";
7
- import {RouteRuleCreateForm} from "./route-rule-create-form";
8
- import {showNotification} from "@mantine/notifications";
9
-
10
- export function RouteRuleGrid() {
11
-
12
- const [permissionScopes, setPermissionScopes] = useState<PermissionScope[]>([]);
13
- const [permissionScopesLoaded, setPermissionScopesLoaded] = useState<boolean>(false);
14
-
15
- const [currentScope, setCurrentScope] = useState<string | null>(null);
16
- const [currentPackageName, setCurrentPackageName] = useState<string | null>(null);
17
- const [routeRules, setRouteRules] = useState<RouteRule[]>([]);
18
- const [permissionLoading, setPermissionLoading] = useState<boolean>(false);
19
-
20
- const [currentRouteRule, setCurrentRouteRule] = useState<RouteRule | undefined>();
21
- const [managePermissionModalOpened, setManagePermissionModalOpened] = useState<boolean>(false);
22
-
23
- const [createRouteRuleModalOpened, setCreateRouteRuleModalOpened] = useState<boolean>(false);
24
-
25
- useEffect(() => {
26
- loadPermissionScopes();
27
- }, [])
28
-
29
- useEffect(() => {
30
- if(currentScope && currentPackageName)
31
- getRouteRulesForScope();
32
- else
33
- setRouteRules([]);
34
- }, [currentScope, currentPackageName]);
35
-
36
- const getRouteRulesForScope = () => {
37
-
38
- if(!currentScope || !currentPackageName) {
39
- return;
40
- }
41
-
42
- setPermissionLoading(true);
43
-
44
- FluxoClientSys.Instance.security.routeRule.getRouteRulesForScope(currentScope, currentPackageName)
45
- .then((res) => {
46
- setRouteRules(res);
47
- setPermissionLoading(false);
48
- })
49
- }
50
-
51
- const loadPermissionScopes = () => {
52
- FluxoClientSys.Instance.security.permission.getPermissionScopes()
53
- .then((res) => {
54
- setPermissionScopes(res);
55
- setPermissionScopesLoaded(true);
56
- })
57
- }
58
-
59
- const deleteRouteRule = (routeRule: RouteRule) => {
60
- FluxoClientSys.Instance.security.routeRule.delete(routeRule.id!.toString())
61
- .then(() => {
62
- showNotification({
63
- title: 'Regola eliminata',
64
- message: `La regola ${routeRule.scope}.${routeRule.packageName}.${routeRule.route} è stato eliminata con successo.`,
65
- color: 'green'
66
- })
67
- getRouteRulesForScope();
68
- })
69
- .catch(() => {
70
- showNotification({
71
- title: 'Errore',
72
- message: `Si è verificato un errore durante l'eliminazione della regola ${routeRule.scope}.${routeRule.packageName}.${routeRule.route}.`,
73
- color: 'red'
74
- })
75
- });
76
- }
77
-
78
- const getScopes = () => {
79
- if(permissionScopes === undefined) return [];
80
- return [...new Set(permissionScopes.map(a => a.scope))];
81
- }
82
-
83
- const getPackageNames = (scope: string | null) => {
84
- if(permissionScopes === undefined || !scope) return [];
85
- return [...new Set(permissionScopes.filter(a => a.scope === scope).map(a => a.packageName))];
86
- }
87
-
88
- return (
89
- <DataCard title={'Regole sulle rotte'}>
90
- <Stack>
91
- <Grid>
92
- <Grid.Col span={6}>
93
- <Select
94
- data={getScopes()}
95
- searchable
96
- placeholder={'Seleziona uno scope'}
97
- value={currentScope}
98
- label={'Scope'}
99
- onChange={(v) => {
100
- setCurrentScope(v)
101
- setCurrentPackageName(null);
102
- }} />
103
- </Grid.Col>
104
- <Grid.Col span={6}>
105
- <Select
106
- disabled={!currentScope}
107
- searchable
108
- placeholder={'Seleziona un package name'}
109
- data={getPackageNames(currentScope)}
110
- value={currentPackageName}
111
- label={'Package name'}
112
- onChange={(v) => {
113
- setCurrentPackageName(v)
114
- }} />
115
- </Grid.Col>
116
- </Grid>
117
-
118
- <Divider />
119
-
120
- {(currentScope && currentPackageName && !permissionLoading && routeRules.length) === 0 &&
121
- <Stack>
122
- <Group justify={'right'} align={'center'}>
123
- <Button leftSection={<IconPlus size={18}/>} onClick={() => setCreateRouteRuleModalOpened(true)}>Nuova regola</Button>
124
- </Group>
125
- <Center>
126
- <Text size={'md'}>Nessuna regola esistente.</Text>
127
- </Center>
128
- </Stack>
129
- }
130
-
131
- {(!currentScope || !currentPackageName) &&
132
- <Stack align={'center'} mt={32} mb={32}>
133
- <IconCloudOff color={'gray'} size={64} />
134
- <Center>
135
- <Text size={'md'}>Seleziona uno scope e un package name per visualizzare i permessi associati.</Text>
136
- </Center>
137
- </Stack>
138
- }
139
-
140
- {!permissionLoading && routeRules.length > 0 &&
141
- <Stack>
142
- <Group justify={'right'} align={'center'}>
143
- <Button leftSection={<IconPlus size={18}/>} onClick={() => setCreateRouteRuleModalOpened(true)}>Nuova regola</Button>
144
- </Group>
145
- <Table highlightOnHover>
146
- <Table.Thead>
147
- <Table.Tr>
148
- <Table.Th>Id</Table.Th>
149
- <Table.Th>Scope</Table.Th>
150
- <Table.Th>Rotta</Table.Th>
151
- <Table.Th>Permessi</Table.Th>
152
- <Table.Th style={{maxWidth: 80, width: 80}}>Azioni</Table.Th>
153
- </Table.Tr>
154
- </Table.Thead>
155
- <Table.Tbody>
156
- {routeRules.map((element, i) => {
157
- return (
158
- <Table.Tr key={i}>
159
- <Table.Td>{element.id}</Table.Td>
160
- <Table.Td>{`${element.scope}.${element.packageName}`}</Table.Td>
161
- <Table.Td>{`/${element.scope}/${element.packageName}/${element.route}`}</Table.Td>
162
- <Table.Td>{element.permissionsCount}</Table.Td>
163
- <Table.Td style={{maxWidth: 130, width: 130}}>
164
- <Group>
165
- <ActionIcon onClick={() => {
166
- setCurrentRouteRule(element);
167
- setManagePermissionModalOpened(true);
168
- }}>
169
- <IconLock size={18} />
170
- </ActionIcon>
171
- <ActionIcon onClick={() => {
172
- deleteRouteRule(element);
173
- }}>
174
- <IconTrash size={18} />
175
- </ActionIcon>
176
- </Group>
177
-
178
- </Table.Td>
179
- </Table.Tr>
180
- )
181
- })}
182
- </Table.Tbody>
183
- </Table>
184
- </Stack>
185
- }
186
-
187
- </Stack>
188
-
189
- {currentRouteRule &&
190
- <Modal
191
- size={'60%'}
192
- centered
193
- opened={managePermissionModalOpened}
194
- onClose={() => {
195
- getRouteRulesForScope();
196
- setManagePermissionModalOpened(false);
197
- setCurrentRouteRule(undefined);
198
- }}
199
- title={`Gestione permessi ${currentRouteRule.route}`}>
200
- <PermissionNavigator
201
- context={{type: 'route-rule', id: currentRouteRule.id!.toString()}}
202
- onUpdate={() => {}}
203
- />
204
- </Modal>
205
- }
206
-
207
- <Modal
208
- size={'60%'}
209
- centered
210
- opened={createRouteRuleModalOpened}
211
- onClose={() => {
212
- getRouteRulesForScope();
213
- setCreateRouteRuleModalOpened(false);
214
- }}
215
- title={`Crea nuova regola`}>
216
- <RouteRuleCreateForm
217
- scope={currentScope!}
218
- packageName={currentPackageName!}
219
- onCreated={() => {
220
- getRouteRulesForScope();
221
- setCreateRouteRuleModalOpened(false);
222
- }}
223
- onCanceled={() => {setCreateRouteRuleModalOpened(false)}}
224
- />
225
- </Modal>
226
-
227
- </DataCard>
228
- )
229
- }