@esvndev/es-data-sharing 1.3.0 → 1.5.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/master-info/master-card.d.ts +0 -3
- package/dist/component/modal/batch-master-card.d.ts +2 -3
- package/dist/component/modal/sharing-helpers.d.ts +5 -0
- package/dist/component/org-scope/org-table.d.ts +2 -0
- package/dist/index.d.ts +8 -9
- package/dist/index.js +177 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +178 -129
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css +249 -72
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/modal.css +50 -12
- package/dist/styles/modal.css.map +1 -1
- package/dist/types/index.d.ts +5 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import { useState, useMemo, useEffect, forwardRef, useImperativeHandle } from 'react';
|
|
3
3
|
import { useTranslation } from 'react-i18next';
|
|
4
|
-
import { Card, CardBody,
|
|
4
|
+
import { Card, CardBody, Badge, Input, Button, Row, Col, Nav, NavItem, NavLink, TabContent, TabPane, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
|
5
|
+
import { FileText, BeOrganization, Search, BecoxyOffice, Copy, Info, Trash2, Settings, Clock, Link2 } from 'becoxy-icons';
|
|
5
6
|
import { GridComponent } from 'es-grid-template';
|
|
6
|
-
import { Copy, Trash2 } from 'becoxy-icons';
|
|
7
7
|
|
|
8
8
|
var classnames$1 = {exports: {}};
|
|
9
9
|
|
|
@@ -84,26 +84,154 @@ var classnames$1 = {exports: {}};
|
|
|
84
84
|
|
|
85
85
|
var classnames = classnames$1.exports;
|
|
86
86
|
|
|
87
|
-
const MasterCard = ({ title, fields, data
|
|
87
|
+
const MasterCard = ({ title, fields, data }) => {
|
|
88
88
|
const { t } = useTranslation();
|
|
89
|
-
return (jsx(Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxs(CardBody, { className: "d-flex flex-column", children: [jsxs("div", { className: "d-flex align-items-center es-master-header", children: [jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsx(
|
|
89
|
+
return (jsx(Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxs(CardBody, { className: "d-flex flex-column", children: [jsxs("div", { className: "d-flex align-items-center es-master-header", children: [jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsx(FileText, { fontSize: 18 }) }), jsx("h5", { className: "mb-0 fw-bolder", children: t(title) })] }), jsx("div", { className: "master-fields-list flex-grow-1", children: fields.map(f => (jsxs("div", { className: "row mx-0 align-items-center es-master-field-row", children: [jsxs("label", { className: "col-5 ps-0 text-muted small mb-0", children: [t(f.label), ":"] }), jsx("div", { className: "col-7 pe-0 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))) })] }) }));
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
-
const BatchMasterCard = ({ title, items,
|
|
92
|
+
const BatchMasterCard = ({ title, items, fields = [] }) => {
|
|
93
93
|
const { t } = useTranslation();
|
|
94
|
-
|
|
94
|
+
const codeLabel = fields.find(f => f.key === 'code' || f.key === 'Code')?.label;
|
|
95
|
+
const nameLabel = fields.find(f => f.key === 'name' || f.key === 'Name')?.label;
|
|
96
|
+
const taxField = fields.find(f => f.key === 'taxCode' || f.key === 'TaxCode');
|
|
97
|
+
const primaryHeader = codeLabel && nameLabel
|
|
98
|
+
? `${t(codeLabel)} / ${t(nameLabel)}`
|
|
99
|
+
: t('DataSharing_BatchItemName', 'Mã / Tên');
|
|
100
|
+
const showTaxColumn = Boolean(taxField) || items.some(item => Boolean(item.taxCode || item.TaxCode));
|
|
101
|
+
const taxHeader = taxField
|
|
102
|
+
? t(taxField.label)
|
|
103
|
+
: t('DataSharing_TaxCode', 'Mã số thuế');
|
|
104
|
+
return (jsx(Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxs(CardBody, { className: "d-flex flex-column", children: [jsxs("div", { className: "d-flex align-items-center justify-content-between es-master-header", children: [jsxs("div", { className: "d-flex align-items-center", children: [jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsx(FileText, { fontSize: 18 }) }), 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, className: "es-batch-count-badge", children: [items.length, " ", t('DataSharing_SelectedItems', 'đối tượng')] })] }), jsxs("div", { className: "flex-grow-1 es-batch-items-list", children: [jsxs("div", { className: "es-batch-items-header d-flex align-items-center justify-content-between px-2 py-2 border-bottom", children: [jsx("span", { className: "fw-semibold", children: primaryHeader }), showTaxColumn && (jsx("span", { className: "fw-semibold text-nowrap ms-2", children: taxHeader }))] }), jsx("div", { className: "px-2", children: items.map((item, idx) => (jsxs("div", { className: "es-batch-row d-flex align-items-center justify-content-between py-2 border-bottom last-no-border", children: [jsxs("div", { className: "text-truncate me-2", children: [jsx("span", { className: "fw-bold es-batch-code me-1", children: item.code || item.Code || '-' }), jsx("span", { className: "small text-dark", children: item.name || item.Name || '' })] }), showTaxColumn && (jsx("small", { className: "text-muted text-nowrap", children: item.taxCode || item.TaxCode || '-' }))] }, item.id || item.Id || idx))) })] })] }) }));
|
|
95
105
|
};
|
|
96
106
|
|
|
97
|
-
|
|
107
|
+
function applyGlobalSharedToOrgList(orgList, checked, sharingLabel) {
|
|
108
|
+
if (!checked)
|
|
109
|
+
return orgList;
|
|
110
|
+
return orgList.map(o => ({
|
|
111
|
+
...o,
|
|
112
|
+
isSelected: true,
|
|
113
|
+
status: 1,
|
|
114
|
+
statusText: sharingLabel
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
function updateOrgOverrideValue(orgList, targetOrgId, fieldKey, value) {
|
|
118
|
+
return orgList.map(item => {
|
|
119
|
+
if (item.targetOrgId !== targetOrgId)
|
|
120
|
+
return item;
|
|
121
|
+
return {
|
|
122
|
+
...item,
|
|
123
|
+
overrideData: {
|
|
124
|
+
...item.overrideData,
|
|
125
|
+
[fieldKey]: value
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
function applyFirstOverrideToAll(orgList) {
|
|
131
|
+
const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
|
|
132
|
+
if (editableOrgs.length < 2)
|
|
133
|
+
return orgList;
|
|
134
|
+
const firstData = editableOrgs[0].overrideData ?? {};
|
|
135
|
+
return orgList.map(item => {
|
|
136
|
+
if (!item.isSelected || !item.canOverrideConfig)
|
|
137
|
+
return item;
|
|
138
|
+
return {
|
|
139
|
+
...item,
|
|
140
|
+
overrideData: {
|
|
141
|
+
...firstData
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function buildDataSharingPayload(params) {
|
|
147
|
+
const { config, entityId, entityIds, isGlobalShared, orgList, detailData } = params;
|
|
148
|
+
const isBatchMode = (entityIds?.length ?? 0) > 1;
|
|
149
|
+
const detailTabs = config.detailTabs ?? [];
|
|
150
|
+
return {
|
|
151
|
+
entityType: config.entityType,
|
|
152
|
+
entityId,
|
|
153
|
+
...(isBatchMode ? { entityIds } : {}),
|
|
154
|
+
isGlobalShared,
|
|
155
|
+
sharingList: orgList
|
|
156
|
+
.filter(o => o.isSelected)
|
|
157
|
+
.map(o => ({
|
|
158
|
+
TargetOrgId: o.targetOrgId,
|
|
159
|
+
IsInheritMaster: o.isInheritMaster,
|
|
160
|
+
CanOverrideConfig: o.canOverrideConfig,
|
|
161
|
+
EffectiveFrom: o.effectiveFrom || null,
|
|
162
|
+
EffectiveTo: o.effectiveTo || null,
|
|
163
|
+
Status: 1
|
|
164
|
+
})),
|
|
165
|
+
orgConfigList: orgList
|
|
166
|
+
.filter(o => o.isSelected && o.canOverrideConfig)
|
|
167
|
+
.map(o => ({
|
|
168
|
+
OrganizationId: o.targetOrgId,
|
|
169
|
+
...o.overrideData
|
|
170
|
+
})),
|
|
171
|
+
...(detailTabs.length > 0 ? { detailData } : {})
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
function findOrgInList(list, targetId) {
|
|
175
|
+
for (const item of list ?? []) {
|
|
176
|
+
if (item?.value === targetId ||
|
|
177
|
+
item?.id === targetId ||
|
|
178
|
+
item?.targetOrgId === targetId ||
|
|
179
|
+
item?.key === targetId ||
|
|
180
|
+
item?.code === targetId ||
|
|
181
|
+
item?.orgCode === targetId) {
|
|
182
|
+
return item;
|
|
183
|
+
}
|
|
184
|
+
if (Array.isArray(item?.children) && item.children.length > 0) {
|
|
185
|
+
const child = findOrgInList(item.children, targetId);
|
|
186
|
+
if (child)
|
|
187
|
+
return child;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
function formatOrgDisplay(org) {
|
|
193
|
+
if (!org)
|
|
194
|
+
return '';
|
|
195
|
+
const name = org.label ?? org.name ?? org.text ?? org.orgName ?? '';
|
|
196
|
+
const code = org.key ?? org.code ?? org.orgCode ?? '';
|
|
197
|
+
if (!name && !code)
|
|
198
|
+
return '';
|
|
199
|
+
return code ? `${name} (${code})` : String(name);
|
|
200
|
+
}
|
|
201
|
+
function resolveCurrentOrgName(params) {
|
|
202
|
+
const { parentOrgName, organizationId, orgList = [] } = params;
|
|
203
|
+
if (parentOrgName)
|
|
204
|
+
return parentOrgName;
|
|
205
|
+
if (organizationId) {
|
|
206
|
+
const matchedFromList = findOrgInList(orgList, organizationId);
|
|
207
|
+
const formatted = formatOrgDisplay(matchedFromList);
|
|
208
|
+
if (formatted)
|
|
209
|
+
return formatted;
|
|
210
|
+
if (typeof window !== 'undefined' && window.localStorage) {
|
|
211
|
+
try {
|
|
212
|
+
const raw = window.localStorage.getItem('organization');
|
|
213
|
+
if (raw) {
|
|
214
|
+
const stored = JSON.parse(raw);
|
|
215
|
+
if (stored && (stored.id === organizationId || stored.code === organizationId)) {
|
|
216
|
+
const storedFormatted = formatOrgDisplay(stored);
|
|
217
|
+
if (storedFormatted)
|
|
218
|
+
return storedFormatted;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
catch {
|
|
223
|
+
// Bỏ qua lỗi parse localStorage
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return '';
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
const OrgTable = ({ orgList, onChangeOrg, parentOrgName, parentOrgLabel, organizationId }) => {
|
|
98
231
|
const { t, i18n } = useTranslation();
|
|
99
232
|
const [search, setSearch] = useState('');
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const matchSearch = o.orgName.toLowerCase().includes(search.toLowerCase()) ||
|
|
103
|
-
o.orgCode.toLowerCase().includes(search.toLowerCase());
|
|
104
|
-
const matchType = filterType === 'ALL' || o.orgType === filterType;
|
|
105
|
-
return matchSearch && matchType;
|
|
106
|
-
}), [orgList, search, filterType]);
|
|
233
|
+
const filtered = useMemo(() => orgList.filter(o => o.orgName.toLowerCase().includes(search.toLowerCase()) ||
|
|
234
|
+
o.orgCode.toLowerCase().includes(search.toLowerCase())), [orgList, search]);
|
|
107
235
|
const gridDataSource = useMemo(() => filtered.map(o => ({
|
|
108
236
|
...o,
|
|
109
237
|
rowId: o.targetOrgId,
|
|
@@ -116,26 +244,21 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
|
|
|
116
244
|
const allFilteredSelected = filtered.length > 0 && filtered.every(o => o.isSelected);
|
|
117
245
|
const selectedFiltered = filtered.filter(o => o.isSelected);
|
|
118
246
|
const allFilteredOverride = selectedFiltered.length > 0 && selectedFiltered.every(o => o.canOverrideConfig);
|
|
119
|
-
const resolvedParentOrg = useMemo(() => {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
247
|
+
const resolvedParentOrg = useMemo(() => resolveCurrentOrgName({
|
|
248
|
+
parentOrgName,
|
|
249
|
+
organizationId,
|
|
250
|
+
orgList
|
|
251
|
+
}), [parentOrgName, organizationId, orgList]);
|
|
252
|
+
const applyOrgSelection = (item, checked) => ({
|
|
253
|
+
...item,
|
|
254
|
+
isSelected: checked,
|
|
255
|
+
canOverrideConfig: checked ? item.canOverrideConfig : false,
|
|
256
|
+
status: checked ? 1 : 0,
|
|
257
|
+
statusText: checked ? t('DataSharing_Sharing', 'Đang chia sẻ') : t('DataSharing_NotShared', 'Chưa chia sẻ')
|
|
258
|
+
});
|
|
127
259
|
const handleToggleSelectAll = (checked) => {
|
|
128
260
|
const filteredIds = new Set(filtered.map(f => f.targetOrgId));
|
|
129
|
-
const next = orgList.map(item =>
|
|
130
|
-
if (!filteredIds.has(item.targetOrgId))
|
|
131
|
-
return item;
|
|
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
|
-
});
|
|
261
|
+
const next = orgList.map(item => filteredIds.has(item.targetOrgId) ? applyOrgSelection(item, checked) : item);
|
|
139
262
|
onChangeOrg(next);
|
|
140
263
|
};
|
|
141
264
|
const handleToggleAllOverride = (enable) => {
|
|
@@ -146,17 +269,7 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
|
|
|
146
269
|
onChangeOrg(next);
|
|
147
270
|
};
|
|
148
271
|
const handleSelectRow = (targetOrgId, checked) => {
|
|
149
|
-
const next = orgList.map(item =>
|
|
150
|
-
if (item.targetOrgId === targetOrgId) {
|
|
151
|
-
return {
|
|
152
|
-
...item,
|
|
153
|
-
isSelected: checked,
|
|
154
|
-
status: checked ? 1 : 0,
|
|
155
|
-
statusText: checked ? t('DataSharing_Sharing', 'Đang chia sẻ') : t('DataSharing_NotShared', 'Chưa chia sẻ')
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
return item;
|
|
159
|
-
});
|
|
272
|
+
const next = orgList.map(item => item.targetOrgId === targetOrgId ? applyOrgSelection(item, checked) : item);
|
|
160
273
|
onChangeOrg(next);
|
|
161
274
|
};
|
|
162
275
|
const handleFieldChange = (targetOrgId, field, value) => {
|
|
@@ -177,9 +290,9 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
|
|
|
177
290
|
{
|
|
178
291
|
field: 'isSelected',
|
|
179
292
|
headerText: '',
|
|
180
|
-
width:
|
|
181
|
-
minWidth:
|
|
182
|
-
maxWidth:
|
|
293
|
+
width: 38,
|
|
294
|
+
minWidth: 38,
|
|
295
|
+
maxWidth: 38,
|
|
183
296
|
textAlign: 'center',
|
|
184
297
|
allowFiltering: false,
|
|
185
298
|
allowSortering: false,
|
|
@@ -273,7 +386,7 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
|
|
|
273
386
|
template: (props) => props.rowData?.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ẻ') }))
|
|
274
387
|
}
|
|
275
388
|
], [allFilteredSelected, allFilteredOverride, selectedFiltered.length, orgList, filtered, t]);
|
|
276
|
-
return (jsx(Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxs(CardBody, { className: "d-flex flex-column", 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: "
|
|
389
|
+
return (jsx(Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxs(CardBody, { className: "d-flex flex-column", children: [jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2", children: [jsxs("div", { className: "d-flex align-items-start gap-2", children: [jsx("div", { className: "es-org-scope-avatar", children: jsx(BeOrganization, { fontSize: 18 }) }), 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: "es-badge-sharing", children: [t('DataSharing_Sharing', 'Đang chia sẻ'), ": ", selectedCount, "/", orgList.length] }), jsxs(Badge, { color: "light-info", className: "es-badge-override", children: [t('DataSharing_CanOverride', 'Cấu hình riêng'), ": ", overrideCount] })] })] })] }), jsxs("div", { className: "d-flex align-items-center es-org-search-wrap", style: { minWidth: '220px' }, children: [jsx(Search, { fontSize: 15, className: "es-org-search-icon" }), jsx(Input, { type: "search", bsSize: "sm", placeholder: t('DataSharing_SearchOrg', 'Tìm kiếm đơn vị...'), value: search, onChange: e => setSearch(e.target.value) })] })] }), resolvedParentOrg && (jsx("div", { className: "mb-2", children: jsxs("div", { className: "es-parent-org-pill", children: [jsx(BecoxyOffice, { fontSize: 14, className: "text-muted flex-shrink-0" }), jsxs("span", { className: "text-muted", children: [parentOrgLabel ?? t('DataSharing_CurrentOrg', 'Công ty'), ":"] }), jsx("span", { className: "fw-bold es-parent-org-name", children: resolvedParentOrg })] }) })), jsx("div", { className: "flex-grow-1 es-data-sharing-grid-wrap", style: { minHeight: 0 }, children: jsx(GridComponent, { dataSource: gridDataSource, editAble: false, rowEditable: (rowData) => Boolean(rowData?.isSelected), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, onRowStyles: (rowData) => rowData?.isSelected ? { backgroundColor: 'rgba(242, 101, 34, 0.08)' } : {}, height: 360, allowResizing: true, t: t, showEmptyText: false }, "DataSharingOrgScopeGrid") })] }) }));
|
|
277
390
|
};
|
|
278
391
|
|
|
279
392
|
function resolveFieldDisplayValue(field, rowData, rawVal) {
|
|
@@ -440,7 +553,7 @@ const OverrideTable = ({ orgList, overrideColumns, masterData, onChangeOverride,
|
|
|
440
553
|
decimalSeparator: '.',
|
|
441
554
|
thousandSeparator: ',',
|
|
442
555
|
decimalScale: 0
|
|
443
|
-
}, showEmptyText: false }, "DataSharingOverrideGrid") })), jsxs("div", { className: "d-flex align-items-center mt-2 es-override-note", children: [jsx(
|
|
556
|
+
}, showEmptyText: false }, "DataSharingOverrideGrid") })), jsxs("div", { className: "d-flex align-items-center gap-1 mt-2 es-override-note", children: [jsx(Info, { fontSize: 15, className: "flex-shrink-0" }), 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.') })] })] }));
|
|
444
557
|
};
|
|
445
558
|
|
|
446
559
|
const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
|
|
@@ -603,14 +716,13 @@ const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
|
|
|
603
716
|
}, showEmptyText: false }, `DataSharingDetailGrid_${tabConfig.key}`) }));
|
|
604
717
|
};
|
|
605
718
|
|
|
606
|
-
const DataSharingContent = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, setOrgList, detailData, setDetailData, isGlobalShared, onToggleGlobalShared, onChangeOverride, onApplyFirstToAll, showMasterCard: propShowMasterCard, showOrgScope: propShowOrgScope, showConfigTabs: propShowConfigTabs, showOverrideTab: propShowOverrideTab, showSummaryTab: propShowSummaryTab
|
|
719
|
+
const DataSharingContent = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, setOrgList, detailData, setDetailData, isGlobalShared, onToggleGlobalShared, onChangeOverride, onApplyFirstToAll, showMasterCard: propShowMasterCard, showOrgScope: propShowOrgScope, showConfigTabs: propShowConfigTabs, showOverrideTab: propShowOverrideTab, showSummaryTab: propShowSummaryTab }) => {
|
|
607
720
|
const { t } = useTranslation();
|
|
608
721
|
const showMasterCard = propShowMasterCard ?? config.showMasterCard ?? true;
|
|
609
722
|
const showOrgScope = propShowOrgScope ?? config.showOrgScope ?? true;
|
|
610
723
|
const showConfigTabs = propShowConfigTabs ?? config.showConfigTabs ?? true;
|
|
611
724
|
const showOverrideTab = propShowOverrideTab ?? config.showOverrideTab ?? true;
|
|
612
725
|
const showSummaryTab = propShowSummaryTab ?? config.showSummaryTab ?? true;
|
|
613
|
-
const showGlobalSharedSwitch = propShowGlobalSharedSwitch ?? config.showGlobalSharedSwitch ?? true;
|
|
614
726
|
const detailTabs = config.detailTabs ?? [];
|
|
615
727
|
const hasVisibleTabs = showConfigTabs && (showOverrideTab || detailTabs.length > 0 || showSummaryTab);
|
|
616
728
|
const getFirstVisibleTab = () => {
|
|
@@ -636,10 +748,10 @@ const DataSharingContent = ({ config, masterData = {}, masterDataList = [], pare
|
|
|
636
748
|
const showTopRow = showMasterCard || showOrgScope;
|
|
637
749
|
const masterColMd = showOrgScope ? 5 : 12;
|
|
638
750
|
const orgColMd = showMasterCard ? 7 : 12;
|
|
639
|
-
return (jsxs("div", { className: "es-data-sharing-content", children: [showTopRow && (jsxs(Row, { className: hasVisibleTabs ? 'mb-3' : 'mb-0', children: [showMasterCard && (jsx(Col, { md: masterColMd, className: showOrgScope ? 'mb-2 mb-md-0' : '', children: isBatchMode ? (jsx(BatchMasterCard, { title: config.masterCardTitle ?? config.title, items: masterDataList,
|
|
751
|
+
return (jsxs("div", { className: "es-data-sharing-content", children: [showTopRow && (jsxs(Row, { className: hasVisibleTabs ? 'mb-3' : 'mb-0', children: [showMasterCard && (jsx(Col, { md: masterColMd, className: showOrgScope ? 'mb-2 mb-md-0' : '', children: isBatchMode ? (jsx(BatchMasterCard, { title: config.masterCardTitle ?? config.title, items: masterDataList, fields: config.masterFields ?? [] })) : (jsx(MasterCard, { title: config.masterCardTitle ?? config.title, fields: config.masterFields ?? [], data: masterData })) })), showOrgScope && (jsx(Col, { md: orgColMd, children: jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, parentOrgName: parentOrgName ?? config.parentOrgName, parentOrgLabel: config.parentOrgLabel, organizationId: config.organizationId }) }))] })), hasVisibleTabs && (jsxs("div", { className: "es-data-sharing-tabs-section", children: [jsxs(Nav, { tabs: true, className: "mb-2", children: [showOverrideTab && (jsx(NavItem, { children: jsxs(NavLink, { className: classnames('d-inline-flex align-items-center gap-1', { active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: [jsx(Settings, { fontSize: 15 }), jsx("span", { children: 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 => {
|
|
640
752
|
const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
|
|
641
|
-
return (jsx(NavItem, { children: jsxs(NavLink, { className: classnames({ active: activeTab === `detail:${tab.key}` }), onClick: () => setActiveTab(`detail:${tab.key}`), style: { cursor: 'pointer' }, children: [tab.icon ?
|
|
642
|
-
}), showSummaryTab && (jsx(NavItem, { children: jsxs(NavLink, { className: classnames({ active: activeTab === 'summary' }), onClick: () => setActiveTab('summary'), style: { cursor: 'pointer' }, children: [
|
|
753
|
+
return (jsx(NavItem, { children: jsxs(NavLink, { className: classnames('d-inline-flex align-items-center gap-1', { active: activeTab === `detail:${tab.key}` }), onClick: () => setActiveTab(`detail:${tab.key}`), style: { cursor: 'pointer' }, children: [tab.icon ? jsx("span", { children: tab.icon }) : jsx(FileText, { fontSize: 15 }), jsx("span", { children: t(tab.title) }), jsx(Badge, { color: "light-info", className: "ms-1 text-info", children: activeCount })] }) }, tab.key));
|
|
754
|
+
}), showSummaryTab && (jsx(NavItem, { children: jsxs(NavLink, { className: classnames('d-inline-flex align-items-center gap-1', { active: activeTab === 'summary' }), onClick: () => setActiveTab('summary'), style: { cursor: 'pointer' }, children: [jsx(Clock, { fontSize: 15 }), jsx("span", { children: t('DataSharing_SummaryTab', 'Tổng hợp phân quyền') })] }) }))] }), jsxs(TabContent, { activeTab: activeTab, children: [showOverrideTab && (jsx(TabPane, { tabId: "override", children: jsx(OverrideTable, { orgList: orgList, overrideColumns: config.overrideColumns ?? [], masterData: isBatchMode ? undefined : masterData, onChangeOverride: onChangeOverride, onApplyFirstToAll: onApplyFirstToAll }) })), detailTabs.map(tab => (jsx(TabPane, { tabId: `detail:${tab.key}`, children: jsx(DetailTabTable, { tabConfig: tab, orgList: orgList, rows: detailData[tab.key] ?? [], onChangeRows: updatedRows => setDetailData(prev => ({
|
|
643
755
|
...prev,
|
|
644
756
|
[tab.key]: updatedRows
|
|
645
757
|
})) }) }, tab.key))), showSummaryTab && (jsx(TabPane, { tabId: "summary", children: jsxs("div", { className: "es-data-sharing-summary-box", children: [jsx("div", { className: "fw-bold mb-2 small text-dark", children: t('DataSharing_SummaryTitle', 'Tóm tắt cấu hình chuẩn bị áp dụng') }), jsxs("div", { className: "es-summary-grid", children: [jsxs("div", { className: "es-summary-item", children: [jsx("div", { className: "es-summary-label", children: t('DataSharing_SummaryScope', 'Phạm vi') }), jsx("div", { className: "es-summary-value", children: isGlobalShared
|
|
@@ -647,73 +759,7 @@ const DataSharingContent = ({ config, masterData = {}, masterDataList = [], pare
|
|
|
647
759
|
: `${selectedOrgs.length} ${t('DataSharing_Organization', 'Đơn vị')}` })] }), jsxs("div", { className: "es-summary-item", children: [jsx("div", { className: "es-summary-label", children: t('DataSharing_SummaryOverride', 'Đơn vị cho phép cấu hình riêng') }), jsx("div", { className: "es-summary-value", children: selectedOrgs.filter(o => o.canOverrideConfig).length })] }), detailTabs.map(tab => (jsxs("div", { className: "es-summary-item", children: [jsx("div", { className: "es-summary-label", children: t(tab.title) }), jsx("div", { className: "es-summary-value", children: (detailData[tab.key] ?? []).filter(r => !r._deleted).length })] }, tab.key)))] })] }) }))] })] }))] }));
|
|
648
760
|
};
|
|
649
761
|
|
|
650
|
-
|
|
651
|
-
if (!checked)
|
|
652
|
-
return orgList;
|
|
653
|
-
return orgList.map(o => ({
|
|
654
|
-
...o,
|
|
655
|
-
isSelected: true,
|
|
656
|
-
status: 1,
|
|
657
|
-
statusText: sharingLabel
|
|
658
|
-
}));
|
|
659
|
-
}
|
|
660
|
-
function updateOrgOverrideValue(orgList, targetOrgId, fieldKey, value) {
|
|
661
|
-
return orgList.map(item => {
|
|
662
|
-
if (item.targetOrgId !== targetOrgId)
|
|
663
|
-
return item;
|
|
664
|
-
return {
|
|
665
|
-
...item,
|
|
666
|
-
overrideData: {
|
|
667
|
-
...item.overrideData,
|
|
668
|
-
[fieldKey]: value
|
|
669
|
-
}
|
|
670
|
-
};
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
function applyFirstOverrideToAll(orgList) {
|
|
674
|
-
const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
|
|
675
|
-
if (editableOrgs.length < 2)
|
|
676
|
-
return orgList;
|
|
677
|
-
const firstData = editableOrgs[0].overrideData ?? {};
|
|
678
|
-
return orgList.map(item => {
|
|
679
|
-
if (!item.isSelected || !item.canOverrideConfig)
|
|
680
|
-
return item;
|
|
681
|
-
return {
|
|
682
|
-
...item,
|
|
683
|
-
overrideData: {
|
|
684
|
-
...firstData
|
|
685
|
-
}
|
|
686
|
-
};
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
function buildDataSharingPayload(params) {
|
|
690
|
-
const { config, entityId, entityIds, isGlobalShared, orgList, detailData } = params;
|
|
691
|
-
const isBatchMode = (entityIds?.length ?? 0) > 1;
|
|
692
|
-
const detailTabs = config.detailTabs ?? [];
|
|
693
|
-
return {
|
|
694
|
-
entityType: config.entityType,
|
|
695
|
-
entityId,
|
|
696
|
-
...(isBatchMode ? { entityIds } : {}),
|
|
697
|
-
isGlobalShared,
|
|
698
|
-
sharingList: orgList.map(o => ({
|
|
699
|
-
TargetOrgId: o.targetOrgId,
|
|
700
|
-
IsInheritMaster: o.isInheritMaster,
|
|
701
|
-
CanOverrideConfig: o.canOverrideConfig,
|
|
702
|
-
EffectiveFrom: o.effectiveFrom || null,
|
|
703
|
-
EffectiveTo: o.effectiveTo || null,
|
|
704
|
-
Status: o.isSelected ? 1 : 0
|
|
705
|
-
})),
|
|
706
|
-
orgConfigList: orgList
|
|
707
|
-
.filter(o => o.isSelected && o.canOverrideConfig)
|
|
708
|
-
.map(o => ({
|
|
709
|
-
OrganizationId: o.targetOrgId,
|
|
710
|
-
...o.overrideData
|
|
711
|
-
})),
|
|
712
|
-
...(detailTabs.length > 0 ? { detailData } : {})
|
|
713
|
-
};
|
|
714
|
-
}
|
|
715
|
-
|
|
716
|
-
const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList = [], parentOrgName, entityId, entityIds, orgList, setOrgList, detailData, setDetailData, isGlobalShared, setIsGlobalShared, onSave, loading = false, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }) => {
|
|
762
|
+
const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList = [], parentOrgName, entityId, entityIds, orgList, setOrgList, detailData, setDetailData, isGlobalShared, setIsGlobalShared, onSave, loading = false, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab }) => {
|
|
717
763
|
const { t } = useTranslation();
|
|
718
764
|
const [saving, setSaving] = useState(false);
|
|
719
765
|
const isBatchMode = (entityIds?.length ?? 0) > 1;
|
|
@@ -746,10 +792,10 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList =
|
|
|
746
792
|
setSaving(false);
|
|
747
793
|
}
|
|
748
794
|
};
|
|
749
|
-
return (jsxs(Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsx(ModalHeader, { toggle: toggle, children: jsxs("div", { className: "d-flex align-items-center", children: [jsx("span", { className: "me-2 es-data-sharing-header-icon", children:
|
|
795
|
+
return (jsxs(Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsx(ModalHeader, { toggle: toggle, children: jsxs("div", { className: "d-flex align-items-center", children: [jsx("span", { className: "me-2 es-data-sharing-header-icon", children: jsx(Link2, { fontSize: 18 }) }), 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", className: "es-batch-badge", 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, { 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ẻ...') })] })) : (jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab })) }), jsxs(ModalFooter, { children: [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ẻ') }), jsx(Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') })] })] }));
|
|
750
796
|
};
|
|
751
797
|
|
|
752
|
-
const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, onChangeOrgList, detailData: controlledDetailData, onChangeDetailData, isGlobalShared: controlledGlobalShared = false, onChangeGlobalShared, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab
|
|
798
|
+
const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, onChangeOrgList, detailData: controlledDetailData, onChangeDetailData, isGlobalShared: controlledGlobalShared = false, onChangeGlobalShared, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab }) => {
|
|
753
799
|
const { t } = useTranslation();
|
|
754
800
|
const [internalDetailData, setInternalDetailData] = useState({});
|
|
755
801
|
const detailData = controlledDetailData ?? internalDetailData;
|
|
@@ -765,9 +811,9 @@ const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parent
|
|
|
765
811
|
const handleApplyFirstToAll = () => {
|
|
766
812
|
onChangeOrgList(prev => applyFirstOverrideToAll(prev));
|
|
767
813
|
};
|
|
768
|
-
return (jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: onChangeOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: controlledGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab
|
|
814
|
+
return (jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: onChangeOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: controlledGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab }));
|
|
769
815
|
};
|
|
770
|
-
const DataSharingComponent = forwardRef(({ database, parentOrgName, fetchSharingData, onSave, onSuccess, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab
|
|
816
|
+
const DataSharingComponent = forwardRef(({ database, parentOrgName, fetchSharingData, onSave, onSuccess, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab }, ref) => {
|
|
771
817
|
const [isOpen, setIsOpen] = useState(false);
|
|
772
818
|
const [loading, setLoading] = useState(false);
|
|
773
819
|
const [config, setConfig] = useState(null);
|
|
@@ -791,7 +837,7 @@ const DataSharingComponent = forwardRef(({ database, parentOrgName, fetchSharing
|
|
|
791
837
|
setConfig(params.config);
|
|
792
838
|
setMasterData(params.masterData ?? params.masterDataList?.[0] ?? {});
|
|
793
839
|
setMasterDataList(params.masterDataList ?? (params.masterData ? [params.masterData] : []));
|
|
794
|
-
setActiveParentOrgName(params.parentOrgName ?? parentOrgName);
|
|
840
|
+
setActiveParentOrgName(params.parentOrgName ?? params.config?.parentOrgName ?? parentOrgName);
|
|
795
841
|
setEntityId(primaryEntityId);
|
|
796
842
|
setEntityIds(isBatch ? ids : undefined);
|
|
797
843
|
setActiveDatabase(targetDb);
|
|
@@ -802,14 +848,17 @@ const DataSharingComponent = forwardRef(({ database, parentOrgName, fetchSharing
|
|
|
802
848
|
showOrgScope: params.showOrgScope,
|
|
803
849
|
showConfigTabs: params.showConfigTabs,
|
|
804
850
|
showOverrideTab: params.showOverrideTab,
|
|
805
|
-
showSummaryTab: params.showSummaryTab
|
|
806
|
-
showGlobalSharedSwitch: params.showGlobalSharedSwitch
|
|
851
|
+
showSummaryTab: params.showSummaryTab
|
|
807
852
|
});
|
|
808
853
|
if (fetchSharingData && primaryEntityId) {
|
|
809
854
|
setLoading(true);
|
|
810
855
|
try {
|
|
811
856
|
const res = await fetchSharingData(params.entityType, primaryEntityId, targetDb);
|
|
812
|
-
if (
|
|
857
|
+
if (!params.parentOrgName &&
|
|
858
|
+
!params.config?.parentOrgName &&
|
|
859
|
+
!params.config?.organizationId &&
|
|
860
|
+
!parentOrgName &&
|
|
861
|
+
res.parentOrgName) {
|
|
813
862
|
setActiveParentOrgName(res.parentOrgName);
|
|
814
863
|
}
|
|
815
864
|
if (isBatch) {
|
|
@@ -853,7 +902,7 @@ const DataSharingComponent = forwardRef(({ database, parentOrgName, fetchSharing
|
|
|
853
902
|
onSuccess();
|
|
854
903
|
}
|
|
855
904
|
};
|
|
856
|
-
return (jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: activeParentOrgName ?? parentOrgName, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading, showMasterCard: openVisibility.showMasterCard ?? showMasterCard, showOrgScope: openVisibility.showOrgScope ?? showOrgScope, showConfigTabs: openVisibility.showConfigTabs ?? showConfigTabs, showOverrideTab: openVisibility.showOverrideTab ?? showOverrideTab, showSummaryTab: openVisibility.showSummaryTab ?? showSummaryTab
|
|
905
|
+
return (jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: activeParentOrgName ?? parentOrgName, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading, showMasterCard: openVisibility.showMasterCard ?? showMasterCard, showOrgScope: openVisibility.showOrgScope ?? showOrgScope, showConfigTabs: openVisibility.showConfigTabs ?? showConfigTabs, showOverrideTab: openVisibility.showOverrideTab ?? showOverrideTab, showSummaryTab: openVisibility.showSummaryTab ?? showSummaryTab }));
|
|
857
906
|
});
|
|
858
907
|
|
|
859
908
|
export { BatchMasterCard, DataSharingPanel, DetailTabTable, MasterCard, OrgTable, OverrideTable, buildDataSharingPayload, DataSharingComponent as default };
|