@tap-payments/os-micro-frontend-shared 0.1.438-test.5 → 0.1.438-test.7
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.
|
@@ -13,6 +13,8 @@ import { handleTemplateUpdate, mapColumnsToLayoutSection, convertTemplateToColum
|
|
|
13
13
|
export function useCustomTableViews({ templates, setTemplates, createTemplate, updateTemplate, deleteTemplate, tableMode, lang = 'en', columnModifiers, }) {
|
|
14
14
|
const [selectedTemplateId, setSelectedTemplateId] = useState(undefined);
|
|
15
15
|
const defaultTemplate = useMemo(() => { var _a; return (_a = templates.find((t) => t.default)) !== null && _a !== void 0 ? _a : templates[0]; }, [templates]);
|
|
16
|
+
const getModeAliases = useCallback((mode) => (mode === 'sheet' ? ['sheet', 'sheets'] : ['advanced', 'default']), []);
|
|
17
|
+
const getOppositeModeCode = useCallback((mode) => (mode === 'sheet' ? 'Advanced' : 'Sheet'), []);
|
|
16
18
|
const createRequiredColumn = useCallback((code, sortOrder) => {
|
|
17
19
|
const label = code === 'date' ? 'Date' : 'Index';
|
|
18
20
|
return {
|
|
@@ -95,15 +97,23 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
95
97
|
}
|
|
96
98
|
}, [templates, defaultTemplate, selectedTemplateId]);
|
|
97
99
|
const onCreateCustomView = useCallback(({ name, layout }) => __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
var _a;
|
|
100
|
+
var _a, _b;
|
|
99
101
|
const created = yield createTemplate({ name, layout: [layout] });
|
|
100
102
|
if (created) {
|
|
101
|
-
const normalized = handleTemplateUpdate(created)
|
|
103
|
+
const normalized = handleTemplateUpdate(Object.assign(Object.assign({}, created), { layout: [
|
|
104
|
+
...((_a = created.layout) !== null && _a !== void 0 ? _a : []),
|
|
105
|
+
// Ensure the other mode does not inherit default columns.
|
|
106
|
+
{ code: getOppositeModeCode(tableMode), columns: [] },
|
|
107
|
+
].filter((section, index, all) => {
|
|
108
|
+
var _a;
|
|
109
|
+
const code = (_a = section.code) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
110
|
+
return all.findIndex((item) => { var _a; return ((_a = item.code) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === code; }) === index;
|
|
111
|
+
}) }));
|
|
102
112
|
setTemplates((prev) => [...prev, normalized]);
|
|
103
113
|
setSelectedTemplateId(normalized.id);
|
|
104
|
-
return { id: created.id, name: (
|
|
114
|
+
return { id: created.id, name: (_b = created.name) !== null && _b !== void 0 ? _b : '' };
|
|
105
115
|
}
|
|
106
|
-
}), [createTemplate, setTemplates]);
|
|
116
|
+
}), [createTemplate, setTemplates, tableMode, getOppositeModeCode]);
|
|
107
117
|
const onDeleteCustomView = useCallback((templateId) => __awaiter(this, void 0, void 0, function* () {
|
|
108
118
|
yield deleteTemplate(templateId);
|
|
109
119
|
setTemplates((prev) => prev.filter((t) => !isTemplateMatchingId(t, templateId)));
|
|
@@ -149,13 +159,15 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
149
159
|
setSelectedTemplateId((_a = matchingTemplate === null || matchingTemplate === void 0 ? void 0 : matchingTemplate.id) !== null && _a !== void 0 ? _a : defaultTemplate.id);
|
|
150
160
|
}, [templates, defaultTemplate]);
|
|
151
161
|
const columnsViewData = useMemo(() => {
|
|
152
|
-
var _a;
|
|
162
|
+
var _a, _b, _c;
|
|
153
163
|
const selectedTemplate = (_a = templates.find((t) => (selectedTemplateId ? isTemplateMatchingId(t, selectedTemplateId) : false))) !== null && _a !== void 0 ? _a : defaultTemplate;
|
|
154
164
|
let templateColumnsView = [];
|
|
165
|
+
const hasSelectedModeLayoutSection = (_c = (_b = selectedTemplate === null || selectedTemplate === void 0 ? void 0 : selectedTemplate.layout) === null || _b === void 0 ? void 0 : _b.some((section) => { var _a, _b; return getModeAliases(tableMode).includes((_b = (_a = section.code) === null || _a === void 0 ? void 0 : _a.toLowerCase()) !== null && _b !== void 0 ? _b : ''); })) !== null && _c !== void 0 ? _c : false;
|
|
155
166
|
if (selectedTemplate) {
|
|
156
167
|
templateColumnsView = convertTemplateToColumnsView(selectedTemplate, tableMode);
|
|
157
168
|
}
|
|
158
|
-
|
|
169
|
+
// Fallback to default template only when selected template has no layout for this mode.
|
|
170
|
+
if (templateColumnsView.length === 0 && (templates === null || templates === void 0 ? void 0 : templates.length) > 0 && !hasSelectedModeLayoutSection) {
|
|
159
171
|
templateColumnsView = convertTemplatesToColumnsView(templates, tableMode);
|
|
160
172
|
}
|
|
161
173
|
if (templateColumnsView.length === 0) {
|
|
@@ -173,7 +185,7 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
173
185
|
return normalizeMandatoryColumns(result, tableMode);
|
|
174
186
|
}
|
|
175
187
|
return normalizeMandatoryColumns(templateColumnsView, tableMode);
|
|
176
|
-
}, [tableMode, templates, selectedTemplateId, defaultTemplate, columnModifiers, normalizeMandatoryColumns]);
|
|
188
|
+
}, [tableMode, templates, selectedTemplateId, defaultTemplate, columnModifiers, normalizeMandatoryColumns, getModeAliases]);
|
|
177
189
|
return {
|
|
178
190
|
customViews,
|
|
179
191
|
onViewChange,
|
|
@@ -98,16 +98,26 @@ export const useViewsMenu = ({ mode, onViewChange, onCreateCustomView, onEditCus
|
|
|
98
98
|
setAnchorEl(null);
|
|
99
99
|
}, []);
|
|
100
100
|
const handleOpenEditDialog = useCallback((view) => {
|
|
101
|
-
|
|
101
|
+
var _a;
|
|
102
|
+
const latestView = (_a = allTemplates.find((templateView) => templateView.id === view.id)) !== null && _a !== void 0 ? _a : view;
|
|
103
|
+
setEditingView(latestView);
|
|
102
104
|
setShouldUseCurrentState(true);
|
|
103
105
|
setIsCreateDialogOpen(true);
|
|
104
|
-
}, []);
|
|
106
|
+
}, [allTemplates]);
|
|
105
107
|
const handleCloseCreateDialog = useCallback(() => {
|
|
106
108
|
setIsCreateDialogOpen(false);
|
|
107
109
|
setEditingView(null);
|
|
108
110
|
setShouldUseCurrentState(false);
|
|
109
111
|
setInitialColumnsForCreate(null);
|
|
110
112
|
}, []);
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!isCreateDialogOpen || !(editingView === null || editingView === void 0 ? void 0 : editingView.id))
|
|
115
|
+
return;
|
|
116
|
+
const latestEditingView = allTemplates.find((view) => view.id === editingView.id);
|
|
117
|
+
if (latestEditingView) {
|
|
118
|
+
setEditingView(latestEditingView);
|
|
119
|
+
}
|
|
120
|
+
}, [isCreateDialogOpen, editingView === null || editingView === void 0 ? void 0 : editingView.id, allTemplates]);
|
|
111
121
|
const handleSaveView = useCallback((data) => __awaiter(void 0, void 0, void 0, function* () {
|
|
112
122
|
if (editingView) {
|
|
113
123
|
const viewId = editingView.id;
|
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.438-test.
|
|
5
|
-
"testVersion":
|
|
4
|
+
"version": "0.1.438-test.7",
|
|
5
|
+
"testVersion": 7,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|