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