@fluxo-dev/shell-reporting 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.
package/package.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "name": "@fluxo-dev/shell-reporting",
3
+ "version": "0.0.12",
4
+ "module": "./index.esm.js",
5
+ "type": "module",
6
+ "main": "./index.esm.js"
7
+ }
@@ -0,0 +1,376 @@
1
+ import { _ as _objectWithoutPropertiesLoose, a as _extends, f as factory, u as useProps, I as InputBase, c as createReactComponent, b as _export, n as nativePromiseConstructor, d as fails$1, g as getBuiltIn$1, r as redefine$1, s as speciesConstructor$1, p as promiseResolve$1, S as Stack, T as Text, e as TextInput, G as Group, B as Button, h as showNotification, i as useNavigate, L as Loader, D as Divider, C as Center, M as Modal } from './index.esm2.js';
2
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
3
+ import { ShellPage, DataCard, ConfirmModal } from '@fluxo-dev/ui-components';
4
+ import * as React from 'react';
5
+ import React__default, { useRef, useCallback, useState, useEffect } from 'react';
6
+ import { FluxoClientSys } from '@fluxo-dev/api-client-base';
7
+ import 'react-dom';
8
+
9
+ var updateRef = function updateRef(ref, value) {
10
+ if (typeof ref === 'function') {
11
+ ref(value);
12
+ return;
13
+ }
14
+ ref.current = value;
15
+ };
16
+
17
+ var useComposedRef = function useComposedRef(libRef, userRef) {
18
+ var prevUserRef = useRef();
19
+ return useCallback(function (instance) {
20
+ libRef.current = instance;
21
+
22
+ if (prevUserRef.current) {
23
+ updateRef(prevUserRef.current, null);
24
+ }
25
+
26
+ prevUserRef.current = userRef;
27
+
28
+ if (!userRef) {
29
+ return;
30
+ }
31
+
32
+ updateRef(userRef, instance);
33
+ }, [userRef]);
34
+ };
35
+
36
+ var noop = function noop() {};
37
+
38
+ var _excluded = ["cacheMeasurements", "maxRows", "minRows", "onChange", "onHeightChange"];
39
+ var TextareaAutosize = function TextareaAutosize(_ref, userRef) {
40
+ _ref.cacheMeasurements;
41
+ _ref.maxRows;
42
+ _ref.minRows;
43
+ var _ref$onChange = _ref.onChange,
44
+ onChange = _ref$onChange === void 0 ? noop : _ref$onChange;
45
+ _ref.onHeightChange;
46
+ var props = _objectWithoutPropertiesLoose(_ref, _excluded);
47
+ props.value !== undefined;
48
+ var libRef = React.useRef(null);
49
+ var ref = useComposedRef(libRef, userRef);
50
+ React.useRef(0);
51
+ React.useRef();
52
+ return /*#__PURE__*/React.createElement("textarea", _extends({}, props, {
53
+ onChange: onChange,
54
+ ref: ref
55
+ }));
56
+ };
57
+ var index = /* #__PURE__ */React.forwardRef(TextareaAutosize);
58
+
59
+ var __defProp = Object.defineProperty;
60
+ var __defProps = Object.defineProperties;
61
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
62
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
63
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
64
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
65
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
66
+ var __spreadValues = (a, b) => {
67
+ for (var prop in b || (b = {}))
68
+ if (__hasOwnProp.call(b, prop))
69
+ __defNormalProp(a, prop, b[prop]);
70
+ if (__getOwnPropSymbols)
71
+ for (var prop of __getOwnPropSymbols(b)) {
72
+ if (__propIsEnum.call(b, prop))
73
+ __defNormalProp(a, prop, b[prop]);
74
+ }
75
+ return a;
76
+ };
77
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
78
+ var __objRest = (source, exclude) => {
79
+ var target = {};
80
+ for (var prop in source)
81
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
82
+ target[prop] = source[prop];
83
+ if (source != null && __getOwnPropSymbols)
84
+ for (var prop of __getOwnPropSymbols(source)) {
85
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
86
+ target[prop] = source[prop];
87
+ }
88
+ return target;
89
+ };
90
+ const defaultProps = {};
91
+ const Textarea = factory((props, ref) => {
92
+ const _a = useProps(
93
+ "Textarea",
94
+ defaultProps,
95
+ props
96
+ ), { autosize, maxRows, minRows, __staticSelector } = _a, others = __objRest(_a, ["autosize", "maxRows", "minRows", "__staticSelector"]);
97
+ const autosizeProps = autosize ? { maxRows, minRows } : {};
98
+ return /* @__PURE__ */ React__default.createElement(
99
+ InputBase,
100
+ __spreadValues(__spreadProps(__spreadValues({
101
+ component: autosize ? index : "textarea",
102
+ ref
103
+ }, others), {
104
+ __staticSelector: __staticSelector || "Textarea",
105
+ multiline: true,
106
+ "data-no-overflow": autosize && maxRows === void 0 || void 0
107
+ }), autosizeProps)
108
+ );
109
+ });
110
+ Textarea.classes = InputBase.classes;
111
+ Textarea.displayName = "@mantine/core/Textarea";
112
+
113
+ /**
114
+ * @tabler/icons-react v2.42.0 - MIT
115
+ */
116
+
117
+ var IconPlus = createReactComponent("plus", "IconPlus", [
118
+ ["path", { d: "M12 5l0 14", key: "svg-0" }],
119
+ ["path", { d: "M5 12l14 0", key: "svg-1" }]
120
+ ]);
121
+
122
+ /**
123
+ * @tabler/icons-react v2.42.0 - MIT
124
+ */
125
+
126
+ var IconReport = createReactComponent("report", "IconReport", [
127
+ [
128
+ "path",
129
+ { d: "M8 5h-2a2 2 0 0 0 -2 2v12a2 2 0 0 0 2 2h5.697", key: "svg-0" }
130
+ ],
131
+ ["path", { d: "M18 14v4h4", key: "svg-1" }],
132
+ ["path", { d: "M18 11v-4a2 2 0 0 0 -2 -2h-2", key: "svg-2" }],
133
+ [
134
+ "path",
135
+ {
136
+ d: "M8 3m0 2a2 2 0 0 1 2 -2h2a2 2 0 0 1 2 2v0a2 2 0 0 1 -2 2h-2a2 2 0 0 1 -2 -2z",
137
+ key: "svg-3"
138
+ }
139
+ ],
140
+ ["path", { d: "M18 18m-4 0a4 4 0 1 0 8 0a4 4 0 1 0 -8 0", key: "svg-4" }],
141
+ ["path", { d: "M8 11h4", key: "svg-5" }],
142
+ ["path", { d: "M8 15h3", key: "svg-6" }]
143
+ ]);
144
+
145
+ var $ = _export;
146
+ var NativePromise = nativePromiseConstructor;
147
+ var fails = fails$1;
148
+ var getBuiltIn = getBuiltIn$1;
149
+ var speciesConstructor = speciesConstructor$1;
150
+ var promiseResolve = promiseResolve$1;
151
+ var redefine = redefine$1.exports;
152
+
153
+ // Safari bug https://bugs.webkit.org/show_bug.cgi?id=200829
154
+ var NON_GENERIC = !!NativePromise && fails(function () {
155
+ NativePromise.prototype['finally'].call({ then: function () { /* empty */ } }, function () { /* empty */ });
156
+ });
157
+
158
+ // `Promise.prototype.finally` method
159
+ // https://tc39.github.io/ecma262/#sec-promise.prototype.finally
160
+ $({ target: 'Promise', proto: true, real: true, forced: NON_GENERIC }, {
161
+ 'finally': function (onFinally) {
162
+ var C = speciesConstructor(this, getBuiltIn('Promise'));
163
+ var isFunction = typeof onFinally == 'function';
164
+ return this.then(
165
+ isFunction ? function (x) {
166
+ return promiseResolve(C, onFinally()).then(function () { return x; });
167
+ } : onFinally,
168
+ isFunction ? function (e) {
169
+ return promiseResolve(C, onFinally()).then(function () { throw e; });
170
+ } : onFinally
171
+ );
172
+ }
173
+ });
174
+
175
+ // patch native Promise.prototype for native async functions
176
+ if (typeof NativePromise == 'function' && !NativePromise.prototype['finally']) {
177
+ redefine(NativePromise.prototype, 'finally', getBuiltIn('Promise').prototype['finally']);
178
+ }
179
+
180
+ function CreateReport(props) {
181
+ const [name, setName] = useState('');
182
+ const [note, setNote] = useState('');
183
+ const [loading, setLoading] = useState(false);
184
+ const createReport = () => {
185
+ if (!name) return;
186
+ const command = {
187
+ name: name,
188
+ annotations: note,
189
+ scope: props.scope,
190
+ packageName: props.packageName,
191
+ namespace: props.namespace,
192
+ id: props.id
193
+ };
194
+ setLoading(true);
195
+ FluxoClientSys.Instance.reporting.createReport(command).then(res => {
196
+ showNotification({
197
+ title: 'Report creato',
198
+ message: 'Il report è stato creato con successo',
199
+ color: 'teal'
200
+ });
201
+ props.onCreated(res);
202
+ }).catch(err => {
203
+ showNotification({
204
+ title: 'Errore',
205
+ message: 'Si è verificato un errore durante la creazione del report',
206
+ color: 'red'
207
+ });
208
+ }).finally(() => {
209
+ setLoading(false);
210
+ });
211
+ };
212
+ return jsxs(Stack, {
213
+ children: [jsxs(Text, {
214
+ children: [jsx("b", {
215
+ children: "Categoria:"
216
+ }), " ", props.scope, ".", props.packageName, ".", props.namespace, ".", props.id]
217
+ }), jsx(TextInput, {
218
+ disabled: loading,
219
+ label: 'Nome report',
220
+ onChange: v => setName(v.target.value)
221
+ }), jsx(Textarea, {
222
+ disabled: loading,
223
+ label: 'Note',
224
+ onChange: v => setNote(v.target.value)
225
+ }), jsxs(Group, {
226
+ justify: 'right',
227
+ children: [jsx(Button, {
228
+ disabled: loading,
229
+ onClick: props.onCancel,
230
+ variant: 'subtle',
231
+ children: "Annulla"
232
+ }), jsx(Button, {
233
+ onClick: createReport,
234
+ disabled: !name || loading,
235
+ children: "Crea"
236
+ })]
237
+ })]
238
+ });
239
+ }
240
+
241
+ function ReportsManager() {
242
+ const [reportsList, setReportsList] = useState([]);
243
+ const [loading, setLoading] = useState(true);
244
+ const navigate = useNavigate();
245
+ const [createReportModalOpened, setCreateReportModalOpened] = useState(false);
246
+ const [deleteReportModalOpened, setDeleteReportModalOpened] = useState(false);
247
+ const [currentId, setCurrentId] = useState();
248
+ const [currentScope, setCurrentScope] = useState('');
249
+ const [currentPackageName, setCurrentPackageName] = useState('');
250
+ const [currentNamespace, setCurrentNamespace] = useState('');
251
+ const [currentReportId, setCurrentReportId] = useState('');
252
+ const [currentReportName, setCurrentReportName] = useState('');
253
+ useEffect(() => {
254
+ refresh();
255
+ }, []);
256
+ const refresh = () => {
257
+ FluxoClientSys.Instance.reporting.getReportsList().then(res => {
258
+ setReportsList(res);
259
+ setLoading(false);
260
+ });
261
+ };
262
+ const deleteReport = () => {
263
+ if (!currentId) return;
264
+ FluxoClientSys.Instance.reporting.deleteReport(currentId).then(() => {
265
+ showNotification({
266
+ title: 'Report eliminato',
267
+ message: 'Il report è stato eliminato con successo',
268
+ color: 'success'
269
+ });
270
+ refresh();
271
+ }).catch(() => {
272
+ showNotification({
273
+ title: 'Errore',
274
+ message: 'Si è verificato un errore durante l\'eliminazione del report',
275
+ color: 'red'
276
+ });
277
+ }).finally(() => {
278
+ setDeleteReportModalOpened(false);
279
+ setCurrentId(undefined);
280
+ });
281
+ };
282
+ return jsxs(ShellPage, {
283
+ headerProps: {
284
+ title: 'Reports',
285
+ subtitle: ''
286
+ },
287
+ children: [loading ? jsx(Loader, {
288
+ size: 48,
289
+ style: {
290
+ margin: 'auto'
291
+ }
292
+ }) : jsx(Stack, {
293
+ children: reportsList.map(report => {
294
+ return jsx(DataCard, {
295
+ title: report.category,
296
+ actions: [{
297
+ label: 'Nuovo report',
298
+ icon: jsx(IconPlus, {
299
+ size: 18
300
+ }),
301
+ onClick: () => {
302
+ setCurrentScope(report.scope);
303
+ setCurrentPackageName(report.packageName);
304
+ setCurrentNamespace(report.namespace);
305
+ setCurrentReportId(report.reportTypeId);
306
+ setCreateReportModalOpened(true);
307
+ }
308
+ }],
309
+ children: jsxs(Stack, {
310
+ children: [report.reports.map((r, index) => {
311
+ return jsxs(Fragment, {
312
+ children: [jsxs(Group, {
313
+ justify: 'space-between',
314
+ children: [jsxs(Group, {
315
+ children: [jsx(IconReport, {
316
+ color: 'gray',
317
+ size: 18
318
+ }), jsx(Text, {
319
+ fw: 600,
320
+ size: 'md',
321
+ children: r.name
322
+ })]
323
+ }), jsxs(Group, {
324
+ children: [jsx(Button, {
325
+ onClick: () => navigate(r.id.toString()),
326
+ size: 'xs',
327
+ children: "Modifica"
328
+ }), jsx(Button, {
329
+ onClick: () => {
330
+ setCurrentId(r.id);
331
+ setCurrentReportName(r.name);
332
+ setDeleteReportModalOpened(true);
333
+ },
334
+ size: 'xs',
335
+ color: 'red',
336
+ children: "Elimina"
337
+ })]
338
+ })]
339
+ }), index !== report.reports.length - 1 && jsx(Divider, {})]
340
+ });
341
+ }), report.reports.length === 0 && jsx(Center, {
342
+ children: jsx(Text, {
343
+ size: 'md',
344
+ children: "Nessun report per la categoria"
345
+ })
346
+ })]
347
+ })
348
+ });
349
+ })
350
+ }), jsx(Modal, {
351
+ title: 'Nuovo report',
352
+ centered: true,
353
+ opened: createReportModalOpened,
354
+ onClose: () => setCreateReportModalOpened(false),
355
+ children: jsx(CreateReport, {
356
+ scope: currentScope,
357
+ packageName: currentPackageName,
358
+ namespace: currentNamespace,
359
+ id: currentReportId,
360
+ onCreated: newReportId => {
361
+ setCreateReportModalOpened(false);
362
+ navigate(newReportId.toString());
363
+ },
364
+ onCancel: () => setCreateReportModalOpened(false)
365
+ })
366
+ }), jsx(ConfirmModal, {
367
+ open: deleteReportModalOpened,
368
+ onButtonConfirmClick: () => deleteReport(),
369
+ onButtonCancelClick: () => setDeleteReportModalOpened(true),
370
+ title: 'Elimina report',
371
+ messageText: `Sei sicuro di voler eliminare il report ${currentReportName}?`
372
+ })]
373
+ });
374
+ }
375
+
376
+ export { ReportsManager as default };
package/src/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export { reportsModule } from './lib/fluxo-module';
2
+ export { ReportButton } from './lib/components/report-button';
3
+ export { ReportChooser } from './lib/components/report-chooser';
@@ -0,0 +1,16 @@
1
+ import { ButtonVariant } from "@mantine/core";
2
+ import React from "react";
3
+ export interface ReportButtonProps {
4
+ reportScope: string;
5
+ reportPackageName: string;
6
+ reportNamespace: string;
7
+ reportId: string;
8
+ initialParameters?: {
9
+ key: string;
10
+ value: string | number | boolean | Date;
11
+ }[];
12
+ label?: string;
13
+ icon?: React.ReactNode;
14
+ variant?: string | ButtonVariant | undefined;
15
+ }
16
+ export declare function ReportButton(props: ReportButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,13 @@
1
+ export interface ReportChooserProps {
2
+ reportScope: string;
3
+ reportPackageName: string;
4
+ reportNamespace: string;
5
+ reportId: string;
6
+ initialParameters?: {
7
+ key: string;
8
+ value: string | number | boolean | Date;
9
+ }[];
10
+ onCancel: () => void;
11
+ onSubmit: (reportId: string, parameters: string) => void;
12
+ }
13
+ export declare function ReportChooser(props: ReportChooserProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './report-designer';
@@ -0,0 +1,8 @@
1
+ import './report-designer.css';
2
+ export interface ReportDesignerProps {
3
+ mode: 'designer' | 'viewer';
4
+ reportId?: number;
5
+ reportParameters?: string;
6
+ }
7
+ export declare const ReportDesigner: (props: ReportDesignerProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default ReportDesigner;
@@ -0,0 +1,18 @@
1
+ import { ParametersSchema } from "@fluxo-dev/api-client-base";
2
+ export interface FiltersPanelProps {
3
+ useParametersSchema: boolean;
4
+ onFiltersChange: (parameters: {
5
+ [key: string]: any;
6
+ }) => void;
7
+ initialParameters?: {
8
+ key: string;
9
+ value: string | number | boolean | Date;
10
+ }[];
11
+ parametersSchema: ParametersSchema;
12
+ }
13
+ export declare function FiltersPanel(props: FiltersPanelProps): import("react/jsx-runtime").JSX.Element;
14
+ export declare namespace FiltersPanel {
15
+ var defaultProps: {
16
+ useParametersSchema: boolean;
17
+ };
18
+ }
@@ -0,0 +1,2 @@
1
+ import { EmbeddedModule } from "@fluxo-dev/api-client-base";
2
+ export declare const reportsModule: EmbeddedModule;
@@ -0,0 +1,9 @@
1
+ export interface CreateReportProps {
2
+ scope: string;
3
+ packageName: string;
4
+ namespace: string;
5
+ id: string;
6
+ onCreated: (id: number) => void;
7
+ onCancel: () => void;
8
+ }
9
+ export declare function CreateReport(props: CreateReportProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1 @@
1
+ export * from './reports-manager';
@@ -0,0 +1 @@
1
+ export default function ReportsManager(): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,3 @@
1
+ import { EmbeddedModuleNavigation } from "@fluxo-dev/api-client-base";
2
+ export declare const SuspenseWrapper: (props: any) => import("react/jsx-runtime").JSX.Element;
3
+ export declare const reportsNavigation: EmbeddedModuleNavigation;