@tap-payments/os-micro-frontend-shared 0.1.438-test.4 → 0.1.438-test.6
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.
|
@@ -80,34 +80,6 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
80
80
|
const orderedColumns = mode === 'sheet' ? [indexColumn, dateColumn, ...restColumns] : [dateColumn, ...restColumns];
|
|
81
81
|
return orderedColumns.filter((column) => Boolean(column));
|
|
82
82
|
}, [createRequiredColumn]);
|
|
83
|
-
const alignCreatedTemplateToCurrentMode = useCallback((createdTemplate) => {
|
|
84
|
-
var _a, _b, _c, _d;
|
|
85
|
-
const normalized = handleTemplateUpdate(createdTemplate);
|
|
86
|
-
const selectedModeCode = tableMode === 'sheet' ? 'sheet' : 'advanced';
|
|
87
|
-
const otherModeCode = tableMode === 'sheet' ? 'advanced' : 'sheet';
|
|
88
|
-
const selectedModeLayout = (_a = normalized.layout) === null || _a === void 0 ? void 0 : _a.find((section) => {
|
|
89
|
-
var _a;
|
|
90
|
-
const code = (_a = section.code) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
91
|
-
if (selectedModeCode === 'advanced')
|
|
92
|
-
return code === 'advanced' || code === 'default';
|
|
93
|
-
return code === 'sheet' || code === 'sheets';
|
|
94
|
-
});
|
|
95
|
-
const defaultOtherModeLayout = (_b = defaultTemplate === null || defaultTemplate === void 0 ? void 0 : defaultTemplate.layout) === null || _b === void 0 ? void 0 : _b.find((section) => {
|
|
96
|
-
var _a;
|
|
97
|
-
const code = (_a = section.code) === null || _a === void 0 ? void 0 : _a.toLowerCase();
|
|
98
|
-
if (otherModeCode === 'advanced')
|
|
99
|
-
return code === 'advanced' || code === 'default';
|
|
100
|
-
return code === 'sheet' || code === 'sheets';
|
|
101
|
-
});
|
|
102
|
-
const nextLayout = [];
|
|
103
|
-
if (selectedModeLayout) {
|
|
104
|
-
nextLayout.push(Object.assign(Object.assign({}, selectedModeLayout), { columns: [...((_c = selectedModeLayout.columns) !== null && _c !== void 0 ? _c : [])] }));
|
|
105
|
-
}
|
|
106
|
-
if (defaultOtherModeLayout) {
|
|
107
|
-
nextLayout.push(Object.assign(Object.assign({}, defaultOtherModeLayout), { columns: [...((_d = defaultOtherModeLayout.columns) !== null && _d !== void 0 ? _d : [])] }));
|
|
108
|
-
}
|
|
109
|
-
return nextLayout.length > 0 ? Object.assign(Object.assign({}, normalized), { layout: nextLayout }) : normalized;
|
|
110
|
-
}, [tableMode, defaultTemplate]);
|
|
111
83
|
useEffect(() => {
|
|
112
84
|
if (!defaultTemplate) {
|
|
113
85
|
setSelectedTemplateId(undefined);
|
|
@@ -126,12 +98,12 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
126
98
|
var _a;
|
|
127
99
|
const created = yield createTemplate({ name, layout: [layout] });
|
|
128
100
|
if (created) {
|
|
129
|
-
const normalized =
|
|
101
|
+
const normalized = handleTemplateUpdate(created);
|
|
130
102
|
setTemplates((prev) => [...prev, normalized]);
|
|
131
103
|
setSelectedTemplateId(normalized.id);
|
|
132
104
|
return { id: created.id, name: (_a = created.name) !== null && _a !== void 0 ? _a : '' };
|
|
133
105
|
}
|
|
134
|
-
}), [createTemplate, setTemplates
|
|
106
|
+
}), [createTemplate, setTemplates]);
|
|
135
107
|
const onDeleteCustomView = useCallback((templateId) => __awaiter(this, void 0, void 0, function* () {
|
|
136
108
|
yield deleteTemplate(templateId);
|
|
137
109
|
setTemplates((prev) => prev.filter((t) => !isTemplateMatchingId(t, templateId)));
|
|
@@ -149,15 +121,9 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
149
121
|
const onEditCustomView = useCallback((viewId, data) => __awaiter(this, void 0, void 0, function* () {
|
|
150
122
|
const template = templates.find((t) => isTemplateMatchingId(t, viewId));
|
|
151
123
|
const { name, layout } = updateCurrentTemplate(template, data);
|
|
152
|
-
const optimisticTemplate = template ? Object.assign(Object.assign({}, template), { name, layout }) : undefined;
|
|
153
|
-
if (optimisticTemplate) {
|
|
154
|
-
const optimisticNormalized = handleTemplateUpdate(optimisticTemplate);
|
|
155
|
-
setTemplates((prev) => replaceTemplateInList(prev, (t) => isTemplateMatchingId(t, viewId), optimisticNormalized));
|
|
156
|
-
}
|
|
157
124
|
const updated = yield updateTemplate(viewId, { name, layout });
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const normalized = handleTemplateUpdate(candidateTemplate);
|
|
125
|
+
if (updated) {
|
|
126
|
+
const normalized = handleTemplateUpdate(updated);
|
|
161
127
|
setTemplates((prev) => replaceTemplateInList(prev, (t) => isTemplateMatchingId(t, viewId), normalized));
|
|
162
128
|
setSelectedTemplateId(normalized.id);
|
|
163
129
|
}
|
|
@@ -195,7 +161,6 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
195
161
|
if (templateColumnsView.length === 0) {
|
|
196
162
|
return [];
|
|
197
163
|
}
|
|
198
|
-
templateColumnsView = normalizeMandatoryColumns(templateColumnsView, tableMode);
|
|
199
164
|
if (columnModifiers === null || columnModifiers === void 0 ? void 0 : columnModifiers.length) {
|
|
200
165
|
let result = templateColumnsView;
|
|
201
166
|
for (const mod of columnModifiers) {
|
|
@@ -205,9 +170,9 @@ export function useCustomTableViews({ templates, setTemplates, createTemplate, u
|
|
|
205
170
|
selected: mod.selected,
|
|
206
171
|
});
|
|
207
172
|
}
|
|
208
|
-
return result;
|
|
173
|
+
return normalizeMandatoryColumns(result, tableMode);
|
|
209
174
|
}
|
|
210
|
-
return templateColumnsView;
|
|
175
|
+
return normalizeMandatoryColumns(templateColumnsView, tableMode);
|
|
211
176
|
}, [tableMode, templates, selectedTemplateId, defaultTemplate, columnModifiers, normalizeMandatoryColumns]);
|
|
212
177
|
return {
|
|
213
178
|
customViews,
|
|
@@ -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.6",
|
|
5
|
+
"testVersion": 6,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "build/index.js",
|
|
8
8
|
"module": "build/index.js",
|