@tap-payments/os-micro-frontend-shared 0.1.435-test.1 → 0.1.435-test.1-test.2
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.
|
@@ -9,23 +9,23 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { useCallback, useMemo, useState } from 'react';
|
|
11
11
|
import { updateColumnSelection } from '../../../../utils/index.js';
|
|
12
|
-
import { handleTemplateUpdate,
|
|
12
|
+
import { handleTemplateUpdate, mapColumnsToLayoutSection, convertTemplateToColumnsView, convertTemplatesToColumnsView, isTemplateMatchingId, replaceTemplateInList, updateCurrentTemplate, } from '../utils';
|
|
13
13
|
export function useCustomTableViews({ templates, setTemplates, createTemplate, updateTemplate, deleteTemplate, tableMode, lang = 'en', columnModifiers, }) {
|
|
14
|
-
const [
|
|
14
|
+
const [selectedViewId, setSelectedViewId] = useState(undefined);
|
|
15
15
|
const onCreateCustomView = useCallback(({ name, layout }) => __awaiter(this, void 0, void 0, function* () {
|
|
16
16
|
var _a;
|
|
17
17
|
const created = yield createTemplate({ name, layout: [layout] });
|
|
18
18
|
if (created) {
|
|
19
19
|
const normalized = handleTemplateUpdate(created);
|
|
20
20
|
setTemplates((prev) => [...prev, normalized]);
|
|
21
|
-
|
|
21
|
+
setSelectedViewId(normalized.id);
|
|
22
22
|
return { id: created.id, name: (_a = created.name) !== null && _a !== void 0 ? _a : '' };
|
|
23
23
|
}
|
|
24
|
-
}), [createTemplate, setTemplates
|
|
24
|
+
}), [createTemplate, setTemplates]);
|
|
25
25
|
const onDeleteCustomView = useCallback((templateId) => __awaiter(this, void 0, void 0, function* () {
|
|
26
26
|
yield deleteTemplate(templateId);
|
|
27
27
|
setTemplates((prev) => prev.filter((t) => !isTemplateMatchingId(t, templateId)));
|
|
28
|
-
|
|
28
|
+
setSelectedViewId((current) => (current === templateId ? undefined : current));
|
|
29
29
|
}), [deleteTemplate, setTemplates]);
|
|
30
30
|
const onUpdateDefaultView = useCallback((columns) => {
|
|
31
31
|
const defaultTemplate = templates.find((t) => t.default);
|
|
@@ -43,9 +43,9 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
43
43
|
if (updated) {
|
|
44
44
|
const normalized = handleTemplateUpdate(updated);
|
|
45
45
|
setTemplates((prev) => replaceTemplateInList(prev, (t) => isTemplateMatchingId(t, viewId), normalized));
|
|
46
|
-
|
|
46
|
+
setSelectedViewId(normalized.id);
|
|
47
47
|
}
|
|
48
|
-
}), [templates,
|
|
48
|
+
}), [templates, updateTemplate, setTemplates]);
|
|
49
49
|
const customViews = useMemo(() => ({
|
|
50
50
|
templates,
|
|
51
51
|
onCreateCustomView,
|
|
@@ -54,51 +54,21 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
54
54
|
onUpdateDefaultView,
|
|
55
55
|
}), [templates, onCreateCustomView, onEditCustomView, onDeleteCustomView, onUpdateDefaultView]);
|
|
56
56
|
const onViewChange = useCallback((view) => {
|
|
57
|
-
|
|
57
|
+
setSelectedViewId(view === null || view === void 0 ? void 0 : view.id);
|
|
58
58
|
}, []);
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var _a;
|
|
65
|
-
return ({
|
|
66
|
-
name: item.name,
|
|
67
|
-
selected: item.selected,
|
|
68
|
-
menuItems: ((_a = item.menuItems) !== null && _a !== void 0 ? _a : []).map((menuItem) => ({
|
|
69
|
-
name: menuItem.name,
|
|
70
|
-
selected: menuItem.selected,
|
|
71
|
-
})),
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
const columnsSignature = (_b = selectedView.columns) !== null && _b !== void 0 ? _b : [];
|
|
75
|
-
const viewWithLayout = selectedView;
|
|
76
|
-
const layoutSignature = ((_c = viewWithLayout.layout) !== null && _c !== void 0 ? _c : []).map((layout) => {
|
|
77
|
-
var _a;
|
|
78
|
-
return ({
|
|
79
|
-
code: layout.code,
|
|
80
|
-
columns: ((_a = layout.columns) !== null && _a !== void 0 ? _a : []).map((col) => col.code),
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
return JSON.stringify({
|
|
84
|
-
id: selectedView.id,
|
|
85
|
-
columns: columnsSignature,
|
|
86
|
-
submenu: submenuSignature,
|
|
87
|
-
layout: layoutSignature,
|
|
88
|
-
});
|
|
89
|
-
}, [selectedView]);
|
|
90
|
-
const columnsViewData = useMemo(() => {
|
|
91
|
-
const currentSelectedView = selectedView;
|
|
92
|
-
let templateColumnsView = [];
|
|
93
|
-
if (currentSelectedView) {
|
|
94
|
-
const viewWithLayout = currentSelectedView;
|
|
95
|
-
const hasLayout = !!viewWithLayout.layout;
|
|
96
|
-
templateColumnsView = convertTemplateToColumnsView(viewWithLayout, tableMode);
|
|
97
|
-
if (templateColumnsView.length === 0 && !hasLayout && (templates === null || templates === void 0 ? void 0 : templates.length) > 0) {
|
|
98
|
-
templateColumnsView = convertTemplatesToColumnsView(templates, tableMode);
|
|
99
|
-
}
|
|
59
|
+
const activeTemplate = useMemo(() => {
|
|
60
|
+
if (!(templates === null || templates === void 0 ? void 0 : templates.length))
|
|
61
|
+
return undefined;
|
|
62
|
+
if (!selectedViewId || selectedViewId === 'default') {
|
|
63
|
+
return templates.find((template) => template.default) || templates[0];
|
|
100
64
|
}
|
|
101
|
-
|
|
65
|
+
return (templates.find((template) => isTemplateMatchingId(template, selectedViewId)) ||
|
|
66
|
+
templates.find((template) => template.default) ||
|
|
67
|
+
templates[0]);
|
|
68
|
+
}, [templates, selectedViewId]);
|
|
69
|
+
const columnsViewData = useMemo(() => {
|
|
70
|
+
let templateColumnsView = activeTemplate ? convertTemplateToColumnsView(activeTemplate, tableMode) : [];
|
|
71
|
+
if (templateColumnsView.length === 0 && (templates === null || templates === void 0 ? void 0 : templates.length) > 0) {
|
|
102
72
|
templateColumnsView = convertTemplatesToColumnsView(templates, tableMode);
|
|
103
73
|
}
|
|
104
74
|
if (templateColumnsView.length === 0) {
|
|
@@ -116,11 +86,11 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
116
86
|
return result;
|
|
117
87
|
}
|
|
118
88
|
return templateColumnsView;
|
|
119
|
-
}, [tableMode, templates,
|
|
89
|
+
}, [tableMode, templates, activeTemplate, columnModifiers]);
|
|
120
90
|
return {
|
|
121
91
|
customViews,
|
|
122
92
|
onViewChange,
|
|
123
93
|
columnsViewData,
|
|
124
|
-
selectedViewId
|
|
94
|
+
selectedViewId,
|
|
125
95
|
};
|
|
126
96
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tap-payments/os-micro-frontend-shared",
|
|
3
3
|
"description": "Shared components and utilities for Tap Payments micro frontends",
|
|
4
|
-
"version": "0.1.435-test.1",
|
|
5
|
-
"testVersion":
|
|
4
|
+
"version": "0.1.435-test.1-test.2",
|
|
5
|
+
"testVersion": 2,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|