@esvndev/es-data-sharing 0.0.0-stage → 1.1.0
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/README.md +60 -2
- package/dist/component/common/dynamic-field-input.d.ts +11 -0
- package/dist/component/common/grid-column-builder.d.ts +10 -0
- package/dist/component/master-info/master-card.d.ts +11 -0
- package/dist/component/modal/batch-master-card.d.ts +9 -0
- package/dist/component/modal/index.d.ts +22 -0
- package/dist/component/modal/modal-sharing.d.ts +21 -0
- package/dist/component/org-detail/detail-tab-table.d.ts +10 -0
- package/dist/component/org-override/override-table.d.ts +11 -0
- package/dist/component/org-scope/org-table.d.ts +9 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +644 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +642 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles/index.css +34 -0
- package/dist/styles/index.css.map +1 -0
- package/dist/styles/modal.css +10 -0
- package/dist/styles/modal.css.map +1 -0
- package/dist/types/index.d.ts +89 -0
- package/package.json +59 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,644 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var react = require('react');
|
|
5
|
+
var reactstrap = require('reactstrap');
|
|
6
|
+
var reactI18next = require('react-i18next');
|
|
7
|
+
var esGridTemplate = require('es-grid-template');
|
|
8
|
+
var becoxyIcons = require('becoxy-icons');
|
|
9
|
+
|
|
10
|
+
var classnames$1 = {exports: {}};
|
|
11
|
+
|
|
12
|
+
/*!
|
|
13
|
+
Copyright (c) 2018 Jed Watson.
|
|
14
|
+
Licensed under the MIT License (MIT), see
|
|
15
|
+
http://jedwatson.github.io/classnames
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
(function (module) {
|
|
19
|
+
/* global define */
|
|
20
|
+
|
|
21
|
+
(function () {
|
|
22
|
+
|
|
23
|
+
var hasOwn = {}.hasOwnProperty;
|
|
24
|
+
|
|
25
|
+
function classNames () {
|
|
26
|
+
var classes = '';
|
|
27
|
+
|
|
28
|
+
for (var i = 0; i < arguments.length; i++) {
|
|
29
|
+
var arg = arguments[i];
|
|
30
|
+
if (arg) {
|
|
31
|
+
classes = appendClass(classes, parseValue(arg));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return classes;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parseValue (arg) {
|
|
39
|
+
if (typeof arg === 'string' || typeof arg === 'number') {
|
|
40
|
+
return arg;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (typeof arg !== 'object') {
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (Array.isArray(arg)) {
|
|
48
|
+
return classNames.apply(null, arg);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {
|
|
52
|
+
return arg.toString();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
var classes = '';
|
|
56
|
+
|
|
57
|
+
for (var key in arg) {
|
|
58
|
+
if (hasOwn.call(arg, key) && arg[key]) {
|
|
59
|
+
classes = appendClass(classes, key);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return classes;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function appendClass (value, newClass) {
|
|
67
|
+
if (!newClass) {
|
|
68
|
+
return value;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (value) {
|
|
72
|
+
return value + ' ' + newClass;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return value + newClass;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (module.exports) {
|
|
79
|
+
classNames.default = classNames;
|
|
80
|
+
module.exports = classNames;
|
|
81
|
+
} else {
|
|
82
|
+
window.classNames = classNames;
|
|
83
|
+
}
|
|
84
|
+
}());
|
|
85
|
+
}(classnames$1));
|
|
86
|
+
|
|
87
|
+
var classnames = classnames$1.exports;
|
|
88
|
+
|
|
89
|
+
const MasterCard = ({ title, fields, data, isGlobalShared, onToggleGlobalShared }) => {
|
|
90
|
+
return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center mb-3", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary p-50 me-2 rounded", children: jsxRuntime.jsx("span", { className: "avatar-content fs-4", children: "\uD83C\uDFE2" }) }), jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: title })] }), jsxRuntime.jsx("div", { className: "master-fields-list", children: fields.map(f => (jsxRuntime.jsxs("div", { className: "mb-2 row align-items-center", children: [jsxRuntime.jsxs("label", { className: "col-5 text-muted small mb-0", children: [f.label, ":"] }), jsxRuntime.jsx("div", { className: "col-7 fw-bold text-truncate text-dark", title: data[f.key] ? String(data[f.key]) : '', children: data[f.key] !== undefined && data[f.key] !== null && data[f.key] !== '' ? String(data[f.key]) : '-' })] }, f.key))) }), jsxRuntime.jsx("hr", { className: "my-3" }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between p-2 rounded bg-light-secondary bg-opacity-10", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: "Danh m\u1EE5c d\u00F9ng chung to\u00E0n t\u1EADp \u0111o\u00E0n" }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: "T\u1EF1 \u0111\u1ED9ng c\u1EA5p quy\u1EC1n s\u1EED d\u1EE5ng cho t\u1EA5t c\u1EA3 \u0111\u01A1n v\u1ECB th\u00E0nh vi\u00EAn" })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] })] }) }));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const BatchMasterCard = ({ title, items, isGlobalShared, onToggleGlobalShared }) => {
|
|
94
|
+
const { t } = reactI18next.useTranslation();
|
|
95
|
+
return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between mb-2", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary p-50 me-2 rounded", children: jsxRuntime.jsx("span", { className: "avatar-content fs-4", children: "\uD83D\uDCE6" }) }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_BatchModeSubtitle', 'Chế độ chia sẻ hàng loạt') })] })] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", pill: true, children: [items.length, " ", t('DataSharing_SelectedItems', 'đối tượng')] })] }), jsxRuntime.jsx("div", { className: "border rounded bg-white p-2", style: { maxHeight: '215px', overflowY: 'auto' }, children: items.map((item, idx) => (jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between py-1 border-bottom last-no-border", children: [jsxRuntime.jsxs("div", { className: "text-truncate me-2", children: [jsxRuntime.jsx("span", { className: "fw-bold text-primary me-1", children: item.code || item.Code || '-' }), jsxRuntime.jsx("span", { className: "small text-dark", children: item.name || item.Name || '' })] }), item.taxCode && jsxRuntime.jsx("small", { className: "text-muted text-nowrap", children: item.taxCode })] }, item.id || item.Id || idx))) }), jsxRuntime.jsx("hr", { className: "my-3" }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between p-2 rounded bg-light-secondary bg-opacity-10", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn') }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: t('DataSharing_GlobalSharedDesc', 'Tự động cấp quyền sử dụng cho tất cả đơn vị thành viên') })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] })] }) }));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const OrgTable = ({ orgList, onChangeOrg, showEffectiveDate = false }) => {
|
|
99
|
+
const { t } = reactI18next.useTranslation();
|
|
100
|
+
const [search, setSearch] = react.useState('');
|
|
101
|
+
const [filterType, setFilterType] = react.useState('ALL');
|
|
102
|
+
const filtered = orgList.filter(o => {
|
|
103
|
+
const matchSearch = o.orgName.toLowerCase().includes(search.toLowerCase()) ||
|
|
104
|
+
o.orgCode.toLowerCase().includes(search.toLowerCase());
|
|
105
|
+
const matchType = filterType === 'ALL' || o.orgType === filterType;
|
|
106
|
+
return matchSearch && matchType;
|
|
107
|
+
});
|
|
108
|
+
const selectedCount = orgList.filter(o => o.isSelected).length;
|
|
109
|
+
const overrideCount = orgList.filter(o => o.isSelected && o.canOverrideConfig).length;
|
|
110
|
+
const allFilteredSelected = filtered.length > 0 && filtered.every(o => o.isSelected);
|
|
111
|
+
const handleToggleSelectAll = (checked) => {
|
|
112
|
+
const filteredIds = new Set(filtered.map(f => f.targetOrgId));
|
|
113
|
+
const next = orgList.map(item => {
|
|
114
|
+
if (!filteredIds.has(item.targetOrgId))
|
|
115
|
+
return item;
|
|
116
|
+
return {
|
|
117
|
+
...item,
|
|
118
|
+
isSelected: checked,
|
|
119
|
+
status: checked ? 1 : 0,
|
|
120
|
+
statusText: checked ? t('DataSharing_Sharing', 'Đang chia sẻ') : t('DataSharing_NotShared', 'Chưa chia sẻ')
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
onChangeOrg(next);
|
|
124
|
+
};
|
|
125
|
+
const handleToggleAllOverride = (enable) => {
|
|
126
|
+
const next = orgList.map(item => item.isSelected ? { ...item, canOverrideConfig: enable } : item);
|
|
127
|
+
onChangeOrg(next);
|
|
128
|
+
};
|
|
129
|
+
const handleSelectRow = (targetOrgId, checked) => {
|
|
130
|
+
const next = orgList.map(item => {
|
|
131
|
+
if (item.targetOrgId === targetOrgId) {
|
|
132
|
+
return {
|
|
133
|
+
...item,
|
|
134
|
+
isSelected: checked,
|
|
135
|
+
status: checked ? 1 : 0,
|
|
136
|
+
statusText: checked ? t('DataSharing_Sharing', 'Đang chia sẻ') : t('DataSharing_NotShared', 'Chưa chia sẻ')
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
return item;
|
|
140
|
+
});
|
|
141
|
+
onChangeOrg(next);
|
|
142
|
+
};
|
|
143
|
+
const handleFieldChange = (targetOrgId, field, value) => {
|
|
144
|
+
const next = orgList.map(item => item.targetOrgId === targetOrgId ? { ...item, [field]: value } : item);
|
|
145
|
+
onChangeOrg(next);
|
|
146
|
+
};
|
|
147
|
+
return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t('DataSharing_OrgScope', 'Phạm vi chia sẻ xuống đơn vị') }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2 mt-1", children: [jsxRuntime.jsxs(reactstrap.Badge, { color: "light-primary", className: "text-primary", children: [t('DataSharing_Sharing', 'Đang chia sẻ'), ": ", selectedCount, "/", orgList.length] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "light-info", className: "text-info", children: [t('DataSharing_CanOverride', 'Cấu hình riêng'), ": ", overrideCount] })] })] }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-1", style: { minWidth: '280px' }, children: [jsxRuntime.jsx(reactstrap.Input, { type: "search", bsSize: "sm", placeholder: t('DataSharing_SearchOrg', 'Tìm kiếm đơn vị...'), value: search, onChange: e => setSearch(e.target.value) }), jsxRuntime.jsxs(reactstrap.Input, { type: "select", bsSize: "sm", style: { width: '125px' }, value: filterType, onChange: e => setFilterType(e.target.value), children: [jsxRuntime.jsx("option", { value: "ALL", children: t('DataSharing_All', 'Tất cả') }), jsxRuntime.jsx("option", { value: "C\u00F4ng ty", children: t('DataSharing_Company', 'Công ty') }), jsxRuntime.jsx("option", { value: "Chi nh\u00E1nh", children: t('DataSharing_Branch', 'Chi nhánh') })] })] })] }), selectedCount > 0 && (jsxRuntime.jsxs("div", { className: "d-flex justify-content-end gap-2 mb-2", children: [jsxRuntime.jsx(reactstrap.Button, { size: "sm", color: "primary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: () => handleToggleAllOverride(true), children: t('DataSharing_EnableAllOverride', 'Cho phép tất cả cấu hình riêng') }), jsxRuntime.jsx(reactstrap.Button, { size: "sm", color: "secondary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: () => handleToggleAllOverride(false), children: t('DataSharing_DisableAllOverride', 'Chỉ kế thừa gốc') })] })), jsxRuntime.jsx("div", { className: "table-responsive border rounded", style: { maxHeight: '235px' }, children: jsxRuntime.jsxs(reactstrap.Table, { size: "sm", hover: true, className: "align-middle mb-0", children: [jsxRuntime.jsx("thead", { className: "table-light sticky-top", children: jsxRuntime.jsxs("tr", { children: [jsxRuntime.jsx("th", { style: { width: 42 }, className: "text-center", children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", title: t('DataSharing_SelectAll', 'Chọn tất cả'), checked: allFilteredSelected, onChange: e => handleToggleSelectAll(e.target.checked) }) }), jsxRuntime.jsx("th", { children: t('DataSharing_Organization', 'Đơn vị') }), jsxRuntime.jsx("th", { style: { width: 90 }, children: t('DataSharing_OrgType', 'Loại') }), jsxRuntime.jsx("th", { className: "text-center", style: { width: 105 }, children: t('DataSharing_InheritMaster', 'Kế thừa gốc') }), jsxRuntime.jsx("th", { className: "text-center", style: { width: 120 }, children: t('DataSharing_CanOverride', 'Cấu hình riêng') }), showEffectiveDate && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("th", { style: { width: 135 }, children: t('DataSharing_EffectiveFrom', 'Hiệu lực từ') }), jsxRuntime.jsx("th", { style: { width: 135 }, children: t('DataSharing_EffectiveTo', 'Hiệu lực đến') })] })), jsxRuntime.jsx("th", { style: { width: 110 }, children: t('DataSharing_Status', 'Trạng thái') })] }) }), jsxRuntime.jsx("tbody", { children: filtered.length === 0 ? (jsxRuntime.jsx("tr", { children: jsxRuntime.jsx("td", { colSpan: showEffectiveDate ? 8 : 6, className: "text-center text-muted py-3", children: t('DataSharing_NoOrgFound', 'Không tìm thấy đơn vị phù hợp') }) })) : (filtered.map(row => (jsxRuntime.jsxs("tr", { className: row.isSelected ? 'table-primary bg-opacity-10' : '', children: [jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", checked: row.isSelected, onChange: e => handleSelectRow(row.targetOrgId, e.target.checked) }) }), jsxRuntime.jsxs("td", { children: [jsxRuntime.jsx("div", { className: "fw-bold", children: row.orgName }), jsxRuntime.jsxs("span", { className: "text-muted small", children: ["(", row.orgCode, ")"] })] }), jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Badge, { color: row.orgType === 'Công ty' ? 'light-primary' : 'light-info', children: row.orgType === 'Công ty'
|
|
148
|
+
? t('DataSharing_Company', 'Công ty')
|
|
149
|
+
: t('DataSharing_Branch', 'Chi nhánh') }) }), jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: row.isInheritMaster, onChange: e => handleFieldChange(row.targetOrgId, 'isInheritMaster', e.target.checked) }) }) }), jsxRuntime.jsx("td", { className: "text-center", children: jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", disabled: !row.isSelected, checked: row.canOverrideConfig, onChange: e => handleFieldChange(row.targetOrgId, 'canOverrideConfig', e.target.checked) }) }) }), showEffectiveDate && (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Input, { bsSize: "sm", type: "date", disabled: !row.isSelected, value: row.effectiveFrom ? String(row.effectiveFrom).substring(0, 10) : '', onChange: e => handleFieldChange(row.targetOrgId, 'effectiveFrom', e.target.value || null) }) }), jsxRuntime.jsx("td", { children: jsxRuntime.jsx(reactstrap.Input, { bsSize: "sm", type: "date", disabled: !row.isSelected, value: row.effectiveTo ? String(row.effectiveTo).substring(0, 10) : '', onChange: e => handleFieldChange(row.targetOrgId, 'effectiveTo', e.target.value || null) }) })] })), jsxRuntime.jsx("td", { children: row.isSelected ? (jsxRuntime.jsx("span", { className: "badge bg-light-success text-success", children: t('DataSharing_Sharing', 'Đang chia sẻ') })) : (jsxRuntime.jsx("span", { className: "badge bg-light-secondary text-secondary", children: t('DataSharing_NotShared', 'Chưa chia sẻ') })) })] }, row.targetOrgId)))) })] }) })] }) }));
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
function resolveFieldDisplayValue(field, rowData, rawVal) {
|
|
153
|
+
const fieldKey = field.fieldKey ?? 'value';
|
|
154
|
+
const fieldLabel = field.fieldLabel ?? 'label';
|
|
155
|
+
if (field.type === 'select' || field.type === 'selectTable') {
|
|
156
|
+
const found = (field.options ?? []).find(opt => opt?.[fieldKey] === rawVal ||
|
|
157
|
+
opt?.value === rawVal ||
|
|
158
|
+
(opt?.key !== undefined && rowData?.bankCode && opt.key === rowData.bankCode));
|
|
159
|
+
if (found) {
|
|
160
|
+
return found.name || found[fieldLabel] || rawVal;
|
|
161
|
+
}
|
|
162
|
+
return rowData?.name || rawVal || '';
|
|
163
|
+
}
|
|
164
|
+
return rawVal ?? '';
|
|
165
|
+
}
|
|
166
|
+
function buildGridColumns(fields, options) {
|
|
167
|
+
const { t, isFieldEditable, formatDisplayValue } = options;
|
|
168
|
+
return fields.map(field => {
|
|
169
|
+
const fieldKey = field.fieldKey ?? 'value';
|
|
170
|
+
const fieldLabel = field.fieldLabel ?? 'label';
|
|
171
|
+
const numericWidth = typeof field.width === 'number' ? field.width : 170;
|
|
172
|
+
let editType = 'text';
|
|
173
|
+
let type = undefined;
|
|
174
|
+
if (field.type === 'select') {
|
|
175
|
+
editType = 'select';
|
|
176
|
+
}
|
|
177
|
+
else if (field.type === 'selectTable') {
|
|
178
|
+
editType = 'selectTable';
|
|
179
|
+
}
|
|
180
|
+
else if (field.type === 'number' || field.type === 'numeric') {
|
|
181
|
+
editType = 'numeric';
|
|
182
|
+
type = 'number';
|
|
183
|
+
}
|
|
184
|
+
else if (field.type === 'currency') {
|
|
185
|
+
editType = 'currency';
|
|
186
|
+
type = 'number';
|
|
187
|
+
}
|
|
188
|
+
else if (field.type === 'date') {
|
|
189
|
+
editType = 'date';
|
|
190
|
+
type = 'date';
|
|
191
|
+
}
|
|
192
|
+
else if (field.type === 'checkbox' || field.type === 'switch') {
|
|
193
|
+
editType = 'checkbox';
|
|
194
|
+
type = 'checkbox';
|
|
195
|
+
}
|
|
196
|
+
const col = {
|
|
197
|
+
field: field.key,
|
|
198
|
+
headerText: field.label,
|
|
199
|
+
headerTooltip: String(t(field.label, field.label)),
|
|
200
|
+
width: numericWidth,
|
|
201
|
+
minWidth: Math.min(numericWidth, 120),
|
|
202
|
+
type,
|
|
203
|
+
editType,
|
|
204
|
+
textAlign: field.textAlign,
|
|
205
|
+
fixedType: field.fixedType,
|
|
206
|
+
editEnable: (rowData) => {
|
|
207
|
+
if (field.readonly)
|
|
208
|
+
return false;
|
|
209
|
+
return isFieldEditable ? isFieldEditable(field, rowData) : true;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
if (field.type === 'select') {
|
|
213
|
+
col.editSelectSettings = {
|
|
214
|
+
options: field.options ?? [],
|
|
215
|
+
fieldLabel: fieldLabel
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
else if (field.type === 'selectTable') {
|
|
219
|
+
col.editSelectSettings = {
|
|
220
|
+
options: field.options ?? [],
|
|
221
|
+
fieldLabel: fieldLabel,
|
|
222
|
+
fieldKey: fieldKey,
|
|
223
|
+
columns: field.selectTableColumns ?? [],
|
|
224
|
+
menuWidth: field.menuWidth ?? 580
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
if (field.type === 'checkbox' || field.type === 'switch') {
|
|
228
|
+
col.textAlign = field.textAlign ?? 'center';
|
|
229
|
+
col.template = (props) => (jsxRuntime.jsx(reactstrap.Input, { className: "form-check-input", type: "checkbox", disabled: true, checked: Boolean(props.rowData?.[field.key]), value: props.rowData?.[field.key] }));
|
|
230
|
+
}
|
|
231
|
+
else if (field.type === 'select' || field.type === 'selectTable' || formatDisplayValue) {
|
|
232
|
+
col.template = (props) => {
|
|
233
|
+
const rawVal = props.rowData?.[field.key];
|
|
234
|
+
const resolved = resolveFieldDisplayValue(field, props.rowData, rawVal);
|
|
235
|
+
if (formatDisplayValue) {
|
|
236
|
+
return formatDisplayValue(field, props.rowData, resolved);
|
|
237
|
+
}
|
|
238
|
+
return resolved ?? '';
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
return col;
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const OverrideTable = ({ orgList, overrideColumns, masterData, onChangeOverride, onApplyFirstToAll }) => {
|
|
246
|
+
const { t, i18n } = reactI18next.useTranslation();
|
|
247
|
+
const selectedOrgs = orgList.filter(o => o.isSelected);
|
|
248
|
+
const editableOrgs = selectedOrgs.filter(o => o.canOverrideConfig);
|
|
249
|
+
const gridDataSource = react.useMemo(() => selectedOrgs.map(org => {
|
|
250
|
+
const row = {
|
|
251
|
+
rowId: org.targetOrgId,
|
|
252
|
+
targetOrgId: org.targetOrgId,
|
|
253
|
+
orgName: org.orgName,
|
|
254
|
+
orgCode: org.orgCode,
|
|
255
|
+
_canOverrideConfig: Boolean(org.canOverrideConfig)
|
|
256
|
+
};
|
|
257
|
+
overrideColumns.forEach(col => {
|
|
258
|
+
if (org.canOverrideConfig) {
|
|
259
|
+
row[col.key] = org.overrideData?.[col.key] ?? col.defaultValue ?? '';
|
|
260
|
+
}
|
|
261
|
+
else {
|
|
262
|
+
row[col.key] = masterData?.[col.key] ?? '';
|
|
263
|
+
}
|
|
264
|
+
});
|
|
265
|
+
return row;
|
|
266
|
+
}), [selectedOrgs, overrideColumns, masterData]);
|
|
267
|
+
const headerColumns = react.useMemo(() => {
|
|
268
|
+
const baseCols = [
|
|
269
|
+
{
|
|
270
|
+
field: '#',
|
|
271
|
+
headerText: 'STT',
|
|
272
|
+
textAlign: 'center',
|
|
273
|
+
width: 50,
|
|
274
|
+
minWidth: 50,
|
|
275
|
+
maxWidth: 70,
|
|
276
|
+
fixedType: 'left'
|
|
277
|
+
},
|
|
278
|
+
{
|
|
279
|
+
field: 'orgName',
|
|
280
|
+
headerText: t('DataSharing_Organization', 'Đơn vị'),
|
|
281
|
+
headerTooltip: t('DataSharing_Organization', 'Đơn vị'),
|
|
282
|
+
width: 220,
|
|
283
|
+
minWidth: 180,
|
|
284
|
+
fixedType: 'left',
|
|
285
|
+
editEnable: false,
|
|
286
|
+
template: (props) => (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold", children: props.rowData?.orgName }), jsxRuntime.jsxs("small", { className: "text-muted", children: ["(", props.rowData?.orgCode, ")"] })] }))
|
|
287
|
+
}
|
|
288
|
+
];
|
|
289
|
+
const dynamicCols = buildGridColumns(overrideColumns, {
|
|
290
|
+
t,
|
|
291
|
+
isFieldEditable: (_field, rowData) => Boolean(rowData?._canOverrideConfig),
|
|
292
|
+
formatDisplayValue: (_field, rowData, resolved) => {
|
|
293
|
+
if (!rowData?._canOverrideConfig) {
|
|
294
|
+
const hasMasterVal = resolved !== undefined && resolved !== null && resolved !== '';
|
|
295
|
+
return (jsxRuntime.jsx("span", { className: "text-muted fst-italic", children: hasMasterVal
|
|
296
|
+
? `${t('DataSharing_InheritFromMaster', 'Kế thừa')}: ${String(resolved)}`
|
|
297
|
+
: t('DataSharing_InheritFromMaster', 'Kế thừa từ gốc') }));
|
|
298
|
+
}
|
|
299
|
+
return resolved ?? '';
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
return [...baseCols, ...dynamicCols];
|
|
303
|
+
}, [overrideColumns, t]);
|
|
304
|
+
const handleCellChange = (args, handleCallback) => {
|
|
305
|
+
const item = args.rowData;
|
|
306
|
+
const field = args.field;
|
|
307
|
+
if (field && item?._canOverrideConfig) {
|
|
308
|
+
onChangeOverride(item.targetOrgId, field, item[field]);
|
|
309
|
+
}
|
|
310
|
+
handleCallback(item, args.indexRow);
|
|
311
|
+
};
|
|
312
|
+
return (jsxRuntime.jsxs("div", { className: "es-data-sharing-override-table", children: [editableOrgs.length > 1 && onApplyFirstToAll && (jsxRuntime.jsx("div", { className: "d-flex justify-content-end mb-2", children: jsxRuntime.jsxs(reactstrap.Button, { size: "sm", color: "primary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: onApplyFirstToAll, children: ["\uD83D\uDCCB ", t('DataSharing_ApplyFirstToAll', 'Áp dụng cấu hình dòng đầu cho các đơn vị khác')] }) })), selectedOrgs.length === 0 ? (jsxRuntime.jsx("div", { className: "border rounded text-center text-muted py-4 bg-light small", children: t('DataSharing_NoOrgSelected', 'Chưa có đơn vị nào được chọn chia sẻ ở bảng trên.') })) : (jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: editableOrgs.length > 0, rowEditable: (rowData) => Boolean(rowData?._canOverrideConfig), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, allowResizing: true, t: t, format: {
|
|
313
|
+
decimalSeparator: '.',
|
|
314
|
+
thousandSeparator: ',',
|
|
315
|
+
decimalScale: 0
|
|
316
|
+
}, showEmptyText: false }, "DataSharingOverrideGrid")), jsxRuntime.jsxs("div", { className: "d-flex align-items-center mt-2 text-muted small p-1 bg-light rounded", children: [jsxRuntime.jsx("span", { className: "me-1", children: "\u2139\uFE0F" }), jsxRuntime.jsx("span", { children: t('DataSharing_OverrideNote', 'Thông tin gốc do công ty mẹ quản lý. Các đơn vị được bật "Cấu hình riêng" sẽ có thể nhập thông số riêng tại đây.') })] })] }));
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
|
|
320
|
+
const { t, i18n } = reactI18next.useTranslation();
|
|
321
|
+
const selectedOrgs = orgList.filter(o => o.isSelected);
|
|
322
|
+
const availableOrgs = selectedOrgs.length > 0 ? selectedOrgs : orgList;
|
|
323
|
+
const orgOptions = react.useMemo(() => [
|
|
324
|
+
{ label: t('DataSharing_SharedForAllOrgs', 'Dùng chung toàn tập đoàn'), value: '' },
|
|
325
|
+
...availableOrgs.map(org => ({
|
|
326
|
+
label: `${org.orgName} (${org.orgCode})`,
|
|
327
|
+
value: org.targetOrgId
|
|
328
|
+
}))
|
|
329
|
+
], [availableOrgs, t]);
|
|
330
|
+
const defaultValue = react.useMemo(() => {
|
|
331
|
+
const base = {
|
|
332
|
+
organizationId: '',
|
|
333
|
+
...(tabConfig.defaultRow ?? {})
|
|
334
|
+
};
|
|
335
|
+
tabConfig.columns.forEach(col => {
|
|
336
|
+
if (base[col.key] === undefined && col.defaultValue !== undefined) {
|
|
337
|
+
base[col.key] = col.defaultValue;
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
return base;
|
|
341
|
+
}, [tabConfig]);
|
|
342
|
+
const activeGridRows = react.useMemo(() => (rows ?? [])
|
|
343
|
+
.filter(r => !r._deleted)
|
|
344
|
+
.map(r => ({
|
|
345
|
+
...r,
|
|
346
|
+
organizationId: r.organizationId ?? ''
|
|
347
|
+
})), [rows]);
|
|
348
|
+
const emitUpdatedRows = (nextActiveRows) => {
|
|
349
|
+
const normalizedActive = (nextActiveRows ?? []).map((row, idx) => ({
|
|
350
|
+
...row,
|
|
351
|
+
organizationId: row.organizationId ? String(row.organizationId) : null,
|
|
352
|
+
sortOrder: idx + 1
|
|
353
|
+
}));
|
|
354
|
+
// Enforce uniqueScopeKey checkboxes across updated rows
|
|
355
|
+
tabConfig.columns.forEach(col => {
|
|
356
|
+
if ((col.type === 'checkbox' || col.type === 'switch') && col.uniqueScopeKey !== undefined) {
|
|
357
|
+
const seen = new Set();
|
|
358
|
+
normalizedActive.forEach(r => {
|
|
359
|
+
const scopeVal = r[col.uniqueScopeKey] ? String(r[col.uniqueScopeKey]) : '';
|
|
360
|
+
if (r[col.key]) {
|
|
361
|
+
if (seen.has(scopeVal)) {
|
|
362
|
+
r[col.key] = false;
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
seen.add(scopeVal);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
const activeIds = new Set(normalizedActive.map(r => r.id).filter(Boolean));
|
|
372
|
+
const softDeletedPersisted = (rows ?? [])
|
|
373
|
+
.filter(r => r.id && !activeIds.has(r.id))
|
|
374
|
+
.map(r => ({ ...r, _deleted: true }));
|
|
375
|
+
onChangeRows([...normalizedActive, ...softDeletedPersisted]);
|
|
376
|
+
};
|
|
377
|
+
const headerColumns = react.useMemo(() => {
|
|
378
|
+
const baseCols = [
|
|
379
|
+
{
|
|
380
|
+
field: '#',
|
|
381
|
+
headerText: 'STT',
|
|
382
|
+
textAlign: 'center',
|
|
383
|
+
width: 50,
|
|
384
|
+
minWidth: 50,
|
|
385
|
+
maxWidth: 70,
|
|
386
|
+
fixedType: 'left'
|
|
387
|
+
},
|
|
388
|
+
{
|
|
389
|
+
field: 'organizationId',
|
|
390
|
+
headerText: t('DataSharing_Organization', 'Đơn vị áp dụng'),
|
|
391
|
+
headerTooltip: t('DataSharing_Organization', 'Đơn vị áp dụng'),
|
|
392
|
+
editType: 'select',
|
|
393
|
+
editEnable: true,
|
|
394
|
+
editSelectSettings: {
|
|
395
|
+
options: orgOptions,
|
|
396
|
+
fieldLabel: 'label'
|
|
397
|
+
},
|
|
398
|
+
template: (props) => {
|
|
399
|
+
const orgId = props.rowData?.organizationId ?? '';
|
|
400
|
+
if (!orgId) {
|
|
401
|
+
return t('DataSharing_SharedForAllOrgs', 'Dùng chung toàn tập đoàn');
|
|
402
|
+
}
|
|
403
|
+
const found = orgList.find(o => String(o.targetOrgId).toLowerCase() === String(orgId).toLowerCase());
|
|
404
|
+
return found ? `${found.orgName} (${found.orgCode})` : orgId;
|
|
405
|
+
},
|
|
406
|
+
width: 230,
|
|
407
|
+
minWidth: 180
|
|
408
|
+
}
|
|
409
|
+
];
|
|
410
|
+
const dynamicCols = buildGridColumns(tabConfig.columns, { t });
|
|
411
|
+
const commandCols = tabConfig.allowDelete === false
|
|
412
|
+
? []
|
|
413
|
+
: [
|
|
414
|
+
{
|
|
415
|
+
field: 'command',
|
|
416
|
+
visible: true,
|
|
417
|
+
textAlign: 'center',
|
|
418
|
+
fixedType: 'right',
|
|
419
|
+
width: 50,
|
|
420
|
+
minWidth: 50,
|
|
421
|
+
maxWidth: 50,
|
|
422
|
+
commandItems: [
|
|
423
|
+
{
|
|
424
|
+
id: 'DELETE',
|
|
425
|
+
title: '',
|
|
426
|
+
icon: jsxRuntime.jsx(becoxyIcons.Trash2, { fontSize: 16 }),
|
|
427
|
+
tooltip: String(t('Delete', 'Xóa'))
|
|
428
|
+
}
|
|
429
|
+
]
|
|
430
|
+
}
|
|
431
|
+
];
|
|
432
|
+
return [...baseCols, ...dynamicCols, ...commandCols];
|
|
433
|
+
}, [tabConfig.columns, tabConfig.allowDelete, orgOptions, orgList, t]);
|
|
434
|
+
const handleCellChange = (args, handleCallback) => {
|
|
435
|
+
const item = args.rowData;
|
|
436
|
+
const val = args.option;
|
|
437
|
+
const field = args.field;
|
|
438
|
+
const colDef = tabConfig.columns.find(c => c.key === field);
|
|
439
|
+
if (colDef?.autoFillMap && val && typeof val === 'object') {
|
|
440
|
+
Object.entries(colDef.autoFillMap).forEach(([targetKey, sourceKey]) => {
|
|
441
|
+
const sourceVal = val[sourceKey];
|
|
442
|
+
if (sourceVal !== undefined && sourceVal !== null) {
|
|
443
|
+
item[targetKey] = sourceVal;
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
if (colDef && (colDef.type === 'checkbox' || colDef.type === 'switch') && colDef.uniqueScopeKey !== undefined && item[colDef.key]) {
|
|
448
|
+
const currentScope = item[colDef.uniqueScopeKey] ?? '';
|
|
449
|
+
args.rowsData?.forEach((row) => {
|
|
450
|
+
if (row.rowId !== item.rowId && (row[colDef.uniqueScopeKey] ?? '') === currentScope) {
|
|
451
|
+
row[colDef.key] = false;
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
emitUpdatedRows(args.rowsData ?? []);
|
|
455
|
+
}
|
|
456
|
+
handleCallback(item, args.indexRow);
|
|
457
|
+
};
|
|
458
|
+
const toolbarBottomItems = tabConfig.allowAdd === false
|
|
459
|
+
? []
|
|
460
|
+
: [
|
|
461
|
+
{ key: 'ADD', label: 'Add item', position: 'Bottom', align: 'left' },
|
|
462
|
+
{ key: 'INSERT_AFTER', label: 'Insert item after', position: 'Bottom', align: 'left' },
|
|
463
|
+
{ key: 'INSERT_BEFORE', label: 'Insert item before', position: 'Bottom', align: 'left' },
|
|
464
|
+
{ key: 'DUPLICATE', label: 'Duplicate', position: 'Bottom', align: 'left' },
|
|
465
|
+
{ key: 'DELETE', label: 'Delete all item', position: 'Bottom', align: 'left' }
|
|
466
|
+
];
|
|
467
|
+
const handleCommandClick = (item) => {
|
|
468
|
+
if (item.id === 'DELETE') {
|
|
469
|
+
emitUpdatedRows(item?.rows ?? []);
|
|
470
|
+
}
|
|
471
|
+
};
|
|
472
|
+
return (jsxRuntime.jsx("div", { className: "es-data-sharing-detail-tab", children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: activeGridRows, editAble: true, lang: i18n.language || 'vi', showToolbar: false, onDataChange: emitUpdatedRows, defaultValue: defaultValue, columns: headerColumns, onCellChange: handleCellChange, toolbarItems: toolbarBottomItems, commandClick: handleCommandClick, allowResizing: true, t: t, format: {
|
|
473
|
+
decimalSeparator: '.',
|
|
474
|
+
thousandSeparator: ',',
|
|
475
|
+
decimalScale: 2
|
|
476
|
+
}, showEmptyText: false }, `DataSharingDetailGrid_${tabConfig.key}`) }));
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList = [], entityId, entityIds, orgList, setOrgList, detailData, setDetailData, isGlobalShared, setIsGlobalShared, onSave, loading = false }) => {
|
|
480
|
+
const { t } = reactI18next.useTranslation();
|
|
481
|
+
const [activeTab, setActiveTab] = react.useState('override');
|
|
482
|
+
const [saving, setSaving] = react.useState(false);
|
|
483
|
+
const isBatchMode = (entityIds?.length ?? 0) > 1;
|
|
484
|
+
const detailTabs = config.detailTabs ?? [];
|
|
485
|
+
const handleToggleGlobalShared = (checked) => {
|
|
486
|
+
setIsGlobalShared(checked);
|
|
487
|
+
if (checked) {
|
|
488
|
+
setOrgList(prev => prev.map(o => ({
|
|
489
|
+
...o,
|
|
490
|
+
isSelected: true,
|
|
491
|
+
status: 1,
|
|
492
|
+
statusText: t('DataSharing_Sharing', 'Đang chia sẻ')
|
|
493
|
+
})));
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
const handleChangeOverride = (targetOrgId, fieldKey, value) => {
|
|
497
|
+
setOrgList(prev => prev.map(item => {
|
|
498
|
+
if (item.targetOrgId !== targetOrgId)
|
|
499
|
+
return item;
|
|
500
|
+
return {
|
|
501
|
+
...item,
|
|
502
|
+
overrideData: {
|
|
503
|
+
...item.overrideData,
|
|
504
|
+
[fieldKey]: value
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
}));
|
|
508
|
+
};
|
|
509
|
+
const handleApplyFirstToAll = () => {
|
|
510
|
+
const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
|
|
511
|
+
if (editableOrgs.length < 2)
|
|
512
|
+
return;
|
|
513
|
+
const firstData = editableOrgs[0].overrideData ?? {};
|
|
514
|
+
setOrgList(prev => prev.map(item => {
|
|
515
|
+
if (!item.isSelected || !item.canOverrideConfig)
|
|
516
|
+
return item;
|
|
517
|
+
return {
|
|
518
|
+
...item,
|
|
519
|
+
overrideData: {
|
|
520
|
+
...firstData
|
|
521
|
+
}
|
|
522
|
+
};
|
|
523
|
+
}));
|
|
524
|
+
};
|
|
525
|
+
const handleSubmit = async () => {
|
|
526
|
+
setSaving(true);
|
|
527
|
+
try {
|
|
528
|
+
const payload = {
|
|
529
|
+
entityType: config.entityType,
|
|
530
|
+
entityId,
|
|
531
|
+
...(isBatchMode ? { entityIds } : {}),
|
|
532
|
+
isGlobalShared,
|
|
533
|
+
sharingList: orgList.map(o => ({
|
|
534
|
+
TargetOrgId: o.targetOrgId,
|
|
535
|
+
IsInheritMaster: o.isInheritMaster,
|
|
536
|
+
CanOverrideConfig: o.canOverrideConfig,
|
|
537
|
+
EffectiveFrom: o.effectiveFrom || null,
|
|
538
|
+
EffectiveTo: o.effectiveTo || null,
|
|
539
|
+
Status: o.isSelected ? 1 : 0
|
|
540
|
+
})),
|
|
541
|
+
orgConfigList: orgList
|
|
542
|
+
.filter(o => o.isSelected && o.canOverrideConfig)
|
|
543
|
+
.map(o => ({
|
|
544
|
+
OrganizationId: o.targetOrgId,
|
|
545
|
+
...o.overrideData
|
|
546
|
+
})),
|
|
547
|
+
...(detailTabs.length > 0 ? { detailData } : {})
|
|
548
|
+
};
|
|
549
|
+
await onSave(payload);
|
|
550
|
+
toggle();
|
|
551
|
+
}
|
|
552
|
+
finally {
|
|
553
|
+
setSaving(false);
|
|
554
|
+
}
|
|
555
|
+
};
|
|
556
|
+
const selectedOrgs = orgList.filter(o => o.isSelected);
|
|
557
|
+
return (jsxRuntime.jsxs(reactstrap.Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsxRuntime.jsx(reactstrap.ModalHeader, { toggle: toggle, className: "border-bottom pb-2", children: jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("span", { className: "me-2 fs-4", children: "\uD83D\uDD17" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2", children: [jsxRuntime.jsx("h4", { className: "mb-0 fw-bolder", children: t(config.title) }), isBatchMode && (jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", children: [t('DataSharing_BatchSharing', 'Chia sẻ hàng loạt'), " (", entityIds?.length, ")"] }))] }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_Subtitle', 'Quản lý chia sẻ dữ liệu và phân quyền theo đơn vị thành viên') })] })] }) }), jsxRuntime.jsx(reactstrap.ModalBody, { className: "p-3", children: loading ? (jsxRuntime.jsxs("div", { className: "text-center py-5", children: [jsxRuntime.jsx("div", { className: "spinner-border text-primary", role: "status", children: jsxRuntime.jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsxRuntime.jsx("div", { className: "mt-2 text-muted", children: t('DataSharing_Loading', 'Đang tải dữ liệu chia sẻ...') })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(reactstrap.Row, { className: "mb-3", children: [jsxRuntime.jsx(reactstrap.Col, { md: 5, className: "mb-2 mb-md-0", children: isBatchMode ? (jsxRuntime.jsx(BatchMasterCard, { title: config.masterCardTitle, items: masterDataList, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared })) : (jsxRuntime.jsx(MasterCard, { title: config.masterCardTitle, fields: config.masterFields, data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared })) }), jsxRuntime.jsx(reactstrap.Col, { md: 7, children: jsxRuntime.jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, showEffectiveDate: config.showEffectiveDate }) })] }), jsxRuntime.jsxs(reactstrap.Nav, { tabs: true, className: "mb-2", children: [jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: ["\u2699\uFE0F ", t('DataSharing_OrgConfigTab', 'Cấu hình theo đơn vị'), selectedOrgs.length > 0 && (jsxRuntime.jsx(reactstrap.Badge, { color: "light-primary", className: "ms-1 text-primary", children: selectedOrgs.length }))] }) }), detailTabs.map(tab => {
|
|
558
|
+
const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
|
|
559
|
+
return (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === `detail:${tab.key}` }), onClick: () => setActiveTab(`detail:${tab.key}`), style: { cursor: 'pointer' }, children: [tab.icon ? `${tab.icon} ` : '📄 ', t(tab.title), jsxRuntime.jsx(reactstrap.Badge, { color: "light-info", className: "ms-1 text-info", children: activeCount })] }) }, tab.key));
|
|
560
|
+
}), jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'summary' }), onClick: () => setActiveTab('summary'), style: { cursor: 'pointer' }, children: ["\uD83D\uDD52 ", t('DataSharing_SummaryTab', 'Tổng hợp phân quyền')] }) })] }), jsxRuntime.jsxs(reactstrap.TabContent, { activeTab: activeTab, children: [jsxRuntime.jsx(reactstrap.TabPane, { tabId: "override", children: jsxRuntime.jsx(OverrideTable, { orgList: orgList, overrideColumns: config.overrideColumns, masterData: isBatchMode ? undefined : masterData, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll }) }), detailTabs.map(tab => (jsxRuntime.jsx(reactstrap.TabPane, { tabId: `detail:${tab.key}`, children: jsxRuntime.jsx(DetailTabTable, { tabConfig: tab, orgList: orgList, rows: detailData[tab.key] ?? [], onChangeRows: updatedRows => setDetailData(prev => ({
|
|
561
|
+
...prev,
|
|
562
|
+
[tab.key]: updatedRows
|
|
563
|
+
})) }) }, tab.key))), jsxRuntime.jsx(reactstrap.TabPane, { tabId: "summary", children: jsxRuntime.jsxs("div", { className: "border rounded p-3 small", children: [jsxRuntime.jsxs("div", { className: "fw-bold mb-2", children: [t('DataSharing_SummaryTitle', 'Tóm tắt cấu hình chuẩn bị áp dụng'), ":"] }), jsxRuntime.jsxs("ul", { className: "mb-0 ps-3", children: [jsxRuntime.jsxs("li", { children: [t('DataSharing_SummaryScope', 'Phạm vi'), ":", ' ', jsxRuntime.jsx("strong", { children: isGlobalShared
|
|
564
|
+
? t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn')
|
|
565
|
+
: `${selectedOrgs.length} ${t('DataSharing_Organization', 'Đơn vị')}` })] }), jsxRuntime.jsxs("li", { children: [t('DataSharing_SummaryOverride', 'Đơn vị cho phép cấu hình riêng'), ":", ' ', jsxRuntime.jsx("strong", { children: selectedOrgs.filter(o => o.canOverrideConfig).length })] }), detailTabs.map(tab => (jsxRuntime.jsxs("li", { children: [t(tab.title), ":", ' ', jsxRuntime.jsx("strong", { children: (detailData[tab.key] ?? []).filter(r => !r._deleted).length })] }, tab.key)))] })] }) })] })] })) }), jsxRuntime.jsxs(reactstrap.ModalFooter, { className: "border-top pt-2", children: [jsxRuntime.jsx(reactstrap.Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') }), jsxRuntime.jsx(reactstrap.Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? t('DataSharing_Saving', 'Đang lưu...') : t('DataSharing_Save', 'Cập nhật chia sẻ') })] })] }));
|
|
566
|
+
};
|
|
567
|
+
|
|
568
|
+
const DataSharingComponent = react.forwardRef(({ database, fetchSharingData, onSave, onSuccess }, ref) => {
|
|
569
|
+
const [isOpen, setIsOpen] = react.useState(false);
|
|
570
|
+
const [loading, setLoading] = react.useState(false);
|
|
571
|
+
const [config, setConfig] = react.useState(null);
|
|
572
|
+
const [masterData, setMasterData] = react.useState({});
|
|
573
|
+
const [masterDataList, setMasterDataList] = react.useState([]);
|
|
574
|
+
const [entityId, setEntityId] = react.useState('');
|
|
575
|
+
const [entityIds, setEntityIds] = react.useState(undefined);
|
|
576
|
+
const [activeDatabase, setActiveDatabase] = react.useState(database);
|
|
577
|
+
const [isGlobalShared, setIsGlobalShared] = react.useState(false);
|
|
578
|
+
const [orgList, setOrgList] = react.useState([]);
|
|
579
|
+
const [detailData, setDetailData] = react.useState({});
|
|
580
|
+
react.useImperativeHandle(ref, () => ({
|
|
581
|
+
open: async (params) => {
|
|
582
|
+
const targetDb = params.database ?? database;
|
|
583
|
+
const ids = params.entityIds?.filter(Boolean) ?? [];
|
|
584
|
+
const isBatch = ids.length > 1;
|
|
585
|
+
const primaryEntityId = params.entityId || ids[0] || '';
|
|
586
|
+
setIsOpen(true);
|
|
587
|
+
setConfig(params.config);
|
|
588
|
+
setMasterData(params.masterData ?? params.masterDataList?.[0] ?? {});
|
|
589
|
+
setMasterDataList(params.masterDataList ?? (params.masterData ? [params.masterData] : []));
|
|
590
|
+
setEntityId(primaryEntityId);
|
|
591
|
+
setEntityIds(isBatch ? ids : undefined);
|
|
592
|
+
setActiveDatabase(targetDb);
|
|
593
|
+
setIsGlobalShared(params.initialGlobalShared || false);
|
|
594
|
+
setDetailData(params.initialDetailData ?? {});
|
|
595
|
+
if (fetchSharingData && primaryEntityId) {
|
|
596
|
+
setLoading(true);
|
|
597
|
+
try {
|
|
598
|
+
const res = await fetchSharingData(params.entityType, primaryEntityId, targetDb);
|
|
599
|
+
if (isBatch) {
|
|
600
|
+
// In batch mode, load org tree cleanly without inheriting single-item selections
|
|
601
|
+
setIsGlobalShared(false);
|
|
602
|
+
setOrgList((res.orgList ?? []).map(o => ({
|
|
603
|
+
...o,
|
|
604
|
+
isSelected: false,
|
|
605
|
+
isInheritMaster: true,
|
|
606
|
+
canOverrideConfig: false,
|
|
607
|
+
status: 0,
|
|
608
|
+
overrideData: {}
|
|
609
|
+
})));
|
|
610
|
+
setDetailData({});
|
|
611
|
+
}
|
|
612
|
+
else {
|
|
613
|
+
setIsGlobalShared(res.isGlobalShared);
|
|
614
|
+
setOrgList(res.orgList ?? []);
|
|
615
|
+
setDetailData(res.detailData ?? params.initialDetailData ?? {});
|
|
616
|
+
}
|
|
617
|
+
}
|
|
618
|
+
finally {
|
|
619
|
+
setLoading(false);
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
},
|
|
623
|
+
close: () => {
|
|
624
|
+
setIsOpen(false);
|
|
625
|
+
}
|
|
626
|
+
}));
|
|
627
|
+
if (!isOpen || !config)
|
|
628
|
+
return null;
|
|
629
|
+
const handleSave = async (payload) => {
|
|
630
|
+
const finalPayload = activeDatabase
|
|
631
|
+
? { ...payload, database: activeDatabase }
|
|
632
|
+
: payload;
|
|
633
|
+
if (onSave) {
|
|
634
|
+
await onSave(finalPayload);
|
|
635
|
+
}
|
|
636
|
+
if (onSuccess) {
|
|
637
|
+
onSuccess();
|
|
638
|
+
}
|
|
639
|
+
};
|
|
640
|
+
return (jsxRuntime.jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading }));
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
module.exports = DataSharingComponent;
|
|
644
|
+
//# sourceMappingURL=index.js.map
|