@esvndev/es-data-sharing 1.0.0 → 1.2.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 +189 -14
- 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 +1 -0
- package/dist/component/modal/batch-master-card.d.ts +10 -0
- package/dist/component/modal/data-sharing-content.d.ts +18 -0
- package/dist/component/modal/index.d.ts +24 -4
- package/dist/component/modal/modal-sharing.d.ts +7 -2
- package/dist/component/modal/sharing-helpers.d.ts +12 -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 +137 -16
- package/dist/index.js +694 -69
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +688 -72
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css +209 -6
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/modal.css +29 -5
- package/dist/styles/modal.css.map +1 -1
- package/dist/types/index.d.ts +61 -12
- package/package.json +5 -3
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { jsx, jsxs
|
|
2
|
-
import { useState, forwardRef, useImperativeHandle } from 'react';
|
|
3
|
-
import {
|
|
1
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
2
|
+
import { useState, useMemo, useEffect, forwardRef, useImperativeHandle } from 'react';
|
|
3
|
+
import { useTranslation } from 'react-i18next';
|
|
4
|
+
import { Card, CardBody, Input, Badge, Button, Row, Col, Nav, NavItem, NavLink, TabContent, TabPane, Modal, ModalHeader, ModalBody, ModalFooter } from 'reactstrap';
|
|
5
|
+
import { GridComponent } from 'es-grid-template';
|
|
6
|
+
import { Trash2 } from 'becoxy-icons';
|
|
4
7
|
|
|
5
8
|
var classnames$1 = {exports: {}};
|
|
6
9
|
|
|
@@ -81,19 +84,62 @@ var classnames$1 = {exports: {}};
|
|
|
81
84
|
|
|
82
85
|
var classnames = classnames$1.exports;
|
|
83
86
|
|
|
84
|
-
const MasterCard = ({ title, fields, data, isGlobalShared, onToggleGlobalShared }) => {
|
|
85
|
-
|
|
87
|
+
const MasterCard = ({ title, fields, data, isGlobalShared, onToggleGlobalShared, showGlobalSharedSwitch = true }) => {
|
|
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("span", { className: "avatar-content fs-5", children: "\uD83C\uDFE2" }) }), 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))) }), showGlobalSharedSwitch && (jsx("div", { className: "mt-auto pt-3", children: jsxs("div", { className: `d-flex align-items-center justify-content-between es-global-shared-box ${isGlobalShared ? 'is-active' : ''}`, 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) }) })] }) }))] }) }));
|
|
86
90
|
};
|
|
87
91
|
|
|
88
|
-
const
|
|
92
|
+
const BatchMasterCard = ({ title, items, isGlobalShared, onToggleGlobalShared, showGlobalSharedSwitch = true }) => {
|
|
93
|
+
const { t } = useTranslation();
|
|
94
|
+
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("span", { className: "avatar-content fs-5", 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: "p-2 flex-grow-1 es-batch-items-list", 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))) }), showGlobalSharedSwitch && (jsx("div", { className: "mt-auto pt-3", children: jsxs("div", { className: `d-flex align-items-center justify-content-between es-global-shared-box ${isGlobalShared ? 'is-active' : ''}`, 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) }) })] }) }))] }) }));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
|
|
98
|
+
const { t, i18n } = useTranslation();
|
|
89
99
|
const [search, setSearch] = useState('');
|
|
90
100
|
const [filterType, setFilterType] = useState('ALL');
|
|
91
|
-
const filtered = orgList.filter(o => {
|
|
101
|
+
const filtered = useMemo(() => orgList.filter(o => {
|
|
92
102
|
const matchSearch = o.orgName.toLowerCase().includes(search.toLowerCase()) ||
|
|
93
103
|
o.orgCode.toLowerCase().includes(search.toLowerCase());
|
|
94
104
|
const matchType = filterType === 'ALL' || o.orgType === filterType;
|
|
95
105
|
return matchSearch && matchType;
|
|
96
|
-
});
|
|
106
|
+
}), [orgList, search, filterType]);
|
|
107
|
+
const gridDataSource = useMemo(() => filtered.map(o => ({
|
|
108
|
+
...o,
|
|
109
|
+
rowId: o.targetOrgId,
|
|
110
|
+
statusText: o.isSelected
|
|
111
|
+
? t('DataSharing_Sharing', 'Đang chia sẻ')
|
|
112
|
+
: t('DataSharing_NotShared', 'Chưa chia sẻ')
|
|
113
|
+
})), [filtered, t]);
|
|
114
|
+
const selectedCount = orgList.filter(o => o.isSelected).length;
|
|
115
|
+
const overrideCount = orgList.filter(o => o.isSelected && o.canOverrideConfig).length;
|
|
116
|
+
const allFilteredSelected = filtered.length > 0 && filtered.every(o => o.isSelected);
|
|
117
|
+
const resolvedParentOrg = useMemo(() => {
|
|
118
|
+
if (parentOrgName)
|
|
119
|
+
return parentOrgName;
|
|
120
|
+
const rootOrg = orgList.find(o => !o.parentId);
|
|
121
|
+
if (!rootOrg)
|
|
122
|
+
return '';
|
|
123
|
+
return rootOrg.orgCode ? `${rootOrg.orgName} (${rootOrg.orgCode})` : rootOrg.orgName;
|
|
124
|
+
}, [parentOrgName, orgList]);
|
|
125
|
+
const handleToggleSelectAll = (checked) => {
|
|
126
|
+
const filteredIds = new Set(filtered.map(f => f.targetOrgId));
|
|
127
|
+
const next = orgList.map(item => {
|
|
128
|
+
if (!filteredIds.has(item.targetOrgId))
|
|
129
|
+
return item;
|
|
130
|
+
return {
|
|
131
|
+
...item,
|
|
132
|
+
isSelected: checked,
|
|
133
|
+
status: checked ? 1 : 0,
|
|
134
|
+
statusText: checked ? t('DataSharing_Sharing', 'Đang chia sẻ') : t('DataSharing_NotShared', 'Chưa chia sẻ')
|
|
135
|
+
};
|
|
136
|
+
});
|
|
137
|
+
onChangeOrg(next);
|
|
138
|
+
};
|
|
139
|
+
const handleToggleAllOverride = (enable) => {
|
|
140
|
+
const next = orgList.map(item => item.isSelected ? { ...item, canOverrideConfig: enable } : item);
|
|
141
|
+
onChangeOrg(next);
|
|
142
|
+
};
|
|
97
143
|
const handleSelectRow = (targetOrgId, checked) => {
|
|
98
144
|
const next = orgList.map(item => {
|
|
99
145
|
if (item.targetOrgId === targetOrgId) {
|
|
@@ -101,84 +147,591 @@ const OrgTable = ({ orgList, onChangeOrg }) => {
|
|
|
101
147
|
...item,
|
|
102
148
|
isSelected: checked,
|
|
103
149
|
status: checked ? 1 : 0,
|
|
104
|
-
statusText: checked ? 'Đang chia sẻ' : 'Chưa chia sẻ'
|
|
150
|
+
statusText: checked ? t('DataSharing_Sharing', 'Đang chia sẻ') : t('DataSharing_NotShared', 'Chưa chia sẻ')
|
|
105
151
|
};
|
|
106
152
|
}
|
|
107
153
|
return item;
|
|
108
154
|
});
|
|
109
155
|
onChangeOrg(next);
|
|
110
156
|
};
|
|
111
|
-
const
|
|
112
|
-
const next = orgList.map(item => item.targetOrgId === targetOrgId ? { ...item,
|
|
157
|
+
const handleFieldChange = (targetOrgId, field, value) => {
|
|
158
|
+
const next = orgList.map(item => item.targetOrgId === targetOrgId ? { ...item, [field]: value } : item);
|
|
113
159
|
onChangeOrg(next);
|
|
114
160
|
};
|
|
115
|
-
const
|
|
116
|
-
const
|
|
117
|
-
|
|
161
|
+
const handleCellChange = (args, handleCallback) => {
|
|
162
|
+
const item = args.rowData;
|
|
163
|
+
const field = args.field;
|
|
164
|
+
if (field === 'effectiveFrom' || field === 'effectiveTo') {
|
|
165
|
+
const rawVal = item?.[field];
|
|
166
|
+
const normalized = rawVal ? String(rawVal).substring(0, 10) : null;
|
|
167
|
+
handleFieldChange(item.targetOrgId, field, normalized);
|
|
168
|
+
}
|
|
169
|
+
handleCallback(item, args.indexRow);
|
|
170
|
+
};
|
|
171
|
+
const headerColumns = useMemo(() => [
|
|
172
|
+
{
|
|
173
|
+
field: 'isSelected',
|
|
174
|
+
headerText: '',
|
|
175
|
+
width: 50,
|
|
176
|
+
minWidth: 50,
|
|
177
|
+
maxWidth: 50,
|
|
178
|
+
textAlign: 'center',
|
|
179
|
+
fixedType: 'left',
|
|
180
|
+
allowFiltering: false,
|
|
181
|
+
allowSortering: false,
|
|
182
|
+
allowResizing: false,
|
|
183
|
+
editEnable: false,
|
|
184
|
+
headerTemplate: () => (jsx("div", { className: "d-flex justify-content-center", onClick: e => e.stopPropagation(), children: jsx(Input, { type: "checkbox", title: String(t('DataSharing_SelectAll', 'Chọn tất cả')), checked: allFilteredSelected, onChange: e => handleToggleSelectAll(e.target.checked) }) })),
|
|
185
|
+
template: (props) => (jsx("div", { className: "d-flex justify-content-center", onClick: e => e.stopPropagation(), children: jsx(Input, { type: "checkbox", checked: Boolean(props.rowData?.isSelected), onChange: e => handleSelectRow(props.rowData?.targetOrgId, e.target.checked) }) }))
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
field: 'orgName',
|
|
189
|
+
headerText: String(t('DataSharing_Organization', 'Đơn vị')),
|
|
190
|
+
headerTooltip: String(t('DataSharing_Organization', 'Đơn vị')),
|
|
191
|
+
width: 260,
|
|
192
|
+
minWidth: 160,
|
|
193
|
+
fixedType: 'left',
|
|
194
|
+
editEnable: false,
|
|
195
|
+
template: (props) => (jsxs("div", { children: [jsx("div", { className: "fw-bold", children: props.rowData?.orgName }), jsxs("span", { className: "text-muted small", children: ["(", props.rowData?.orgCode, ")"] })] }))
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
field: 'orgType',
|
|
199
|
+
headerText: String(t('DataSharing_OrgType', 'Loại')),
|
|
200
|
+
headerTooltip: String(t('DataSharing_OrgType', 'Loại')),
|
|
201
|
+
width: 110,
|
|
202
|
+
minWidth: 95,
|
|
203
|
+
textAlign: 'center',
|
|
204
|
+
visible: false,
|
|
205
|
+
editEnable: false,
|
|
206
|
+
template: (props) => (jsx(Badge, { color: props.rowData?.orgType === 'Công ty' ? 'light-primary' : 'light-info', children: props.rowData?.orgType === 'Công ty'
|
|
207
|
+
? t('DataSharing_Company', 'Công ty')
|
|
208
|
+
: t('DataSharing_Branch', 'Chi nhánh') }))
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
field: 'isInheritMaster',
|
|
212
|
+
headerText: String(t('DataSharing_InheritMaster', 'Kế thừa gốc')),
|
|
213
|
+
headerTooltip: String(t('DataSharing_InheritMaster', 'Kế thừa gốc')),
|
|
214
|
+
width: 115,
|
|
215
|
+
minWidth: 100,
|
|
216
|
+
textAlign: 'center',
|
|
217
|
+
visible: false,
|
|
218
|
+
allowFiltering: false,
|
|
219
|
+
editEnable: false,
|
|
220
|
+
template: (props) => (jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", onClick: e => e.stopPropagation(), children: jsx(Input, { type: "switch", checked: Boolean(props.rowData?.isInheritMaster), onChange: e => handleFieldChange(props.rowData?.targetOrgId, 'isInheritMaster', e.target.checked) }) }))
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
field: 'canOverrideConfig',
|
|
224
|
+
headerText: String(t('DataSharing_CanOverride', 'Cấu hình riêng')),
|
|
225
|
+
headerTooltip: String(t('DataSharing_CanOverride', 'Cấu hình riêng')),
|
|
226
|
+
width: 125,
|
|
227
|
+
minWidth: 110,
|
|
228
|
+
textAlign: 'center',
|
|
229
|
+
allowFiltering: false,
|
|
230
|
+
editEnable: false,
|
|
231
|
+
template: (props) => (jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", onClick: e => e.stopPropagation(), children: jsx(Input, { type: "switch", disabled: !props.rowData?.isSelected, checked: Boolean(props.rowData?.canOverrideConfig), onChange: e => handleFieldChange(props.rowData?.targetOrgId, 'canOverrideConfig', e.target.checked) }) }))
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
field: 'effectiveFrom',
|
|
235
|
+
headerText: String(t('DataSharing_EffectiveFrom', 'Hiệu lực từ')),
|
|
236
|
+
headerTooltip: String(t('DataSharing_EffectiveFrom', 'Hiệu lực từ')),
|
|
237
|
+
type: 'date',
|
|
238
|
+
editType: 'date',
|
|
239
|
+
textAlign: 'center',
|
|
240
|
+
visible: false,
|
|
241
|
+
width: 145,
|
|
242
|
+
minWidth: 120,
|
|
243
|
+
editEnable: (rowData) => Boolean(rowData?.isSelected)
|
|
244
|
+
},
|
|
245
|
+
{
|
|
246
|
+
field: 'effectiveTo',
|
|
247
|
+
headerText: String(t('DataSharing_EffectiveTo', 'Hiệu lực đến')),
|
|
248
|
+
headerTooltip: String(t('DataSharing_EffectiveTo', 'Hiệu lực đến')),
|
|
249
|
+
type: 'date',
|
|
250
|
+
editType: 'date',
|
|
251
|
+
textAlign: 'center',
|
|
252
|
+
visible: false,
|
|
253
|
+
width: 145,
|
|
254
|
+
minWidth: 120,
|
|
255
|
+
editEnable: (rowData) => Boolean(rowData?.isSelected)
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
field: 'statusText',
|
|
259
|
+
headerText: String(t('DataSharing_Status', 'Trạng thái')),
|
|
260
|
+
headerTooltip: String(t('DataSharing_Status', 'Trạng thái')),
|
|
261
|
+
width: 125,
|
|
262
|
+
minWidth: 105,
|
|
263
|
+
textAlign: 'center',
|
|
264
|
+
visible: false,
|
|
265
|
+
editEnable: false,
|
|
266
|
+
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ẻ') }))
|
|
267
|
+
}
|
|
268
|
+
], [allFilteredSelected, orgList, filtered, t]);
|
|
269
|
+
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: "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') })] })] })] }), (resolvedParentOrg || selectedCount > 0) && (jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center gap-2 mb-2", children: [jsx("div", { children: resolvedParentOrg && (jsxs("div", { className: "es-parent-org-pill", children: [jsxs("span", { className: "text-muted", children: [t('DataSharing_ParentOrg', 'Công ty mẹ'), ":"] }), jsxs("span", { className: "fw-bold text-primary", children: ["\uD83C\uDFE2 ", resolvedParentOrg] })] })) }), selectedCount > 0 && (jsxs("div", { className: "d-flex gap-2 ms-auto", 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: "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(115, 103, 240, 0.06)' } : {}, height: 360, allowResizing: true, t: t, showEmptyText: false }, "DataSharingOrgScopeGrid") })] }) }));
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
function resolveFieldDisplayValue(field, rowData, rawVal) {
|
|
273
|
+
const fieldKey = field.fieldKey ?? 'value';
|
|
274
|
+
const fieldLabel = field.fieldLabel ?? 'label';
|
|
275
|
+
if (field.type === 'select' || field.type === 'selectTable') {
|
|
276
|
+
const found = (field.options ?? []).find(opt => opt?.[fieldKey] === rawVal ||
|
|
277
|
+
opt?.value === rawVal ||
|
|
278
|
+
(opt?.key !== undefined && rowData?.bankCode && opt.key === rowData.bankCode));
|
|
279
|
+
if (found) {
|
|
280
|
+
return found.name || found[fieldLabel] || rawVal;
|
|
281
|
+
}
|
|
282
|
+
return rowData?.name || rawVal || '';
|
|
283
|
+
}
|
|
284
|
+
return rawVal ?? '';
|
|
285
|
+
}
|
|
286
|
+
function buildGridColumns(fields, options) {
|
|
287
|
+
const { t, isFieldEditable, formatDisplayValue } = options;
|
|
288
|
+
return fields.map(field => {
|
|
289
|
+
const fieldKey = field.fieldKey ?? 'value';
|
|
290
|
+
const fieldLabel = field.fieldLabel ?? 'label';
|
|
291
|
+
const numericWidth = typeof field.width === 'number' ? field.width : 170;
|
|
292
|
+
let editType = 'text';
|
|
293
|
+
let type = undefined;
|
|
294
|
+
if (field.type === 'select') {
|
|
295
|
+
editType = 'select';
|
|
296
|
+
}
|
|
297
|
+
else if (field.type === 'selectTable') {
|
|
298
|
+
editType = 'selectTable';
|
|
299
|
+
}
|
|
300
|
+
else if (field.type === 'number' || field.type === 'numeric') {
|
|
301
|
+
editType = 'numeric';
|
|
302
|
+
type = 'number';
|
|
303
|
+
}
|
|
304
|
+
else if (field.type === 'currency') {
|
|
305
|
+
editType = 'currency';
|
|
306
|
+
type = 'number';
|
|
307
|
+
}
|
|
308
|
+
else if (field.type === 'date') {
|
|
309
|
+
editType = 'date';
|
|
310
|
+
type = 'date';
|
|
311
|
+
}
|
|
312
|
+
else if (field.type === 'checkbox' || field.type === 'switch') {
|
|
313
|
+
editType = 'checkbox';
|
|
314
|
+
type = 'checkbox';
|
|
315
|
+
}
|
|
316
|
+
const col = {
|
|
317
|
+
field: field.key,
|
|
318
|
+
headerText: field.label,
|
|
319
|
+
headerTooltip: String(t(field.label, field.label)),
|
|
320
|
+
width: numericWidth,
|
|
321
|
+
minWidth: Math.min(numericWidth, 120),
|
|
322
|
+
type,
|
|
323
|
+
editType,
|
|
324
|
+
textAlign: field.textAlign,
|
|
325
|
+
fixedType: field.fixedType,
|
|
326
|
+
editEnable: (rowData) => {
|
|
327
|
+
if (field.readonly)
|
|
328
|
+
return false;
|
|
329
|
+
return isFieldEditable ? isFieldEditable(field, rowData) : true;
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
if (field.type === 'select') {
|
|
333
|
+
col.editSelectSettings = {
|
|
334
|
+
options: field.options ?? [],
|
|
335
|
+
fieldLabel: fieldLabel
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
else if (field.type === 'selectTable') {
|
|
339
|
+
col.editSelectSettings = {
|
|
340
|
+
options: field.options ?? [],
|
|
341
|
+
fieldLabel: fieldLabel,
|
|
342
|
+
fieldKey: fieldKey,
|
|
343
|
+
columns: field.selectTableColumns ?? [],
|
|
344
|
+
menuWidth: field.menuWidth ?? 580
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
if (field.type === 'checkbox' || field.type === 'switch') {
|
|
348
|
+
col.textAlign = field.textAlign ?? 'center';
|
|
349
|
+
col.template = (props) => (jsx(Input, { className: "form-check-input", type: "checkbox", disabled: true, checked: Boolean(props.rowData?.[field.key]), value: props.rowData?.[field.key] }));
|
|
350
|
+
}
|
|
351
|
+
else if (field.type === 'select' || field.type === 'selectTable' || formatDisplayValue) {
|
|
352
|
+
col.template = (props) => {
|
|
353
|
+
const rawVal = props.rowData?.[field.key];
|
|
354
|
+
const resolved = resolveFieldDisplayValue(field, props.rowData, rawVal);
|
|
355
|
+
if (formatDisplayValue) {
|
|
356
|
+
return formatDisplayValue(field, props.rowData, resolved);
|
|
357
|
+
}
|
|
358
|
+
return resolved ?? '';
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
return col;
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
const OverrideTable = ({ orgList, overrideColumns, masterData, onChangeOverride, onApplyFirstToAll }) => {
|
|
366
|
+
const { t, i18n } = useTranslation();
|
|
367
|
+
const selectedOrgs = orgList.filter(o => o.isSelected);
|
|
368
|
+
const editableOrgs = selectedOrgs.filter(o => o.canOverrideConfig);
|
|
369
|
+
const gridDataSource = useMemo(() => selectedOrgs.map(org => {
|
|
370
|
+
const row = {
|
|
371
|
+
rowId: org.targetOrgId,
|
|
372
|
+
targetOrgId: org.targetOrgId,
|
|
373
|
+
orgName: org.orgName,
|
|
374
|
+
orgCode: org.orgCode,
|
|
375
|
+
_canOverrideConfig: Boolean(org.canOverrideConfig)
|
|
376
|
+
};
|
|
377
|
+
overrideColumns.forEach(col => {
|
|
378
|
+
if (org.canOverrideConfig) {
|
|
379
|
+
row[col.key] = org.overrideData?.[col.key] ?? col.defaultValue ?? '';
|
|
380
|
+
}
|
|
381
|
+
else {
|
|
382
|
+
row[col.key] = masterData?.[col.key] ?? '';
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
return row;
|
|
386
|
+
}), [selectedOrgs, overrideColumns, masterData]);
|
|
387
|
+
const headerColumns = useMemo(() => {
|
|
388
|
+
const baseCols = [
|
|
389
|
+
{
|
|
390
|
+
field: '#',
|
|
391
|
+
headerText: 'STT',
|
|
392
|
+
textAlign: 'center',
|
|
393
|
+
width: 50,
|
|
394
|
+
minWidth: 50,
|
|
395
|
+
maxWidth: 70,
|
|
396
|
+
fixedType: 'left'
|
|
397
|
+
},
|
|
398
|
+
{
|
|
399
|
+
field: 'orgName',
|
|
400
|
+
headerText: t('DataSharing_Organization', 'Đơn vị'),
|
|
401
|
+
headerTooltip: t('DataSharing_Organization', 'Đơn vị'),
|
|
402
|
+
width: 220,
|
|
403
|
+
minWidth: 180,
|
|
404
|
+
fixedType: 'left',
|
|
405
|
+
editEnable: false,
|
|
406
|
+
template: (props) => (jsxs("div", { children: [jsx("div", { className: "fw-bold", children: props.rowData?.orgName }), jsxs("small", { className: "text-muted", children: ["(", props.rowData?.orgCode, ")"] })] }))
|
|
407
|
+
}
|
|
408
|
+
];
|
|
409
|
+
const dynamicCols = buildGridColumns(overrideColumns, {
|
|
410
|
+
t,
|
|
411
|
+
isFieldEditable: (_field, rowData) => Boolean(rowData?._canOverrideConfig),
|
|
412
|
+
formatDisplayValue: (_field, rowData, resolved) => {
|
|
413
|
+
if (!rowData?._canOverrideConfig) {
|
|
414
|
+
const hasMasterVal = resolved !== undefined && resolved !== null && resolved !== '';
|
|
415
|
+
return (jsx("span", { className: "text-muted fst-italic", children: hasMasterVal
|
|
416
|
+
? `${t('DataSharing_InheritFromMaster', 'Kế thừa')}: ${String(resolved)}`
|
|
417
|
+
: t('DataSharing_InheritFromMaster', 'Kế thừa từ gốc') }));
|
|
418
|
+
}
|
|
419
|
+
return resolved ?? '';
|
|
420
|
+
}
|
|
421
|
+
});
|
|
422
|
+
return [...baseCols, ...dynamicCols];
|
|
423
|
+
}, [overrideColumns, t]);
|
|
424
|
+
const handleCellChange = (args, handleCallback) => {
|
|
425
|
+
const item = args.rowData;
|
|
426
|
+
const field = args.field;
|
|
427
|
+
if (field && item?._canOverrideConfig) {
|
|
428
|
+
onChangeOverride(item.targetOrgId, field, item[field]);
|
|
429
|
+
}
|
|
430
|
+
handleCallback(item, args.indexRow);
|
|
118
431
|
};
|
|
119
|
-
return (
|
|
432
|
+
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("div", { className: "es-data-sharing-grid-wrap", children: jsx(GridComponent, { dataSource: gridDataSource, editAble: editableOrgs.length > 0, rowEditable: (rowData) => Boolean(rowData?._canOverrideConfig), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, height: 280, allowResizing: true, t: t, format: {
|
|
433
|
+
decimalSeparator: '.',
|
|
434
|
+
thousandSeparator: ',',
|
|
435
|
+
decimalScale: 0
|
|
436
|
+
}, showEmptyText: false }, "DataSharingOverrideGrid") })), jsxs("div", { className: "d-flex align-items-center mt-2 es-override-note", 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
437
|
};
|
|
121
438
|
|
|
122
|
-
const
|
|
439
|
+
const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
|
|
440
|
+
const { t, i18n } = useTranslation();
|
|
123
441
|
const selectedOrgs = orgList.filter(o => o.isSelected);
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
442
|
+
const availableOrgs = selectedOrgs.length > 0 ? selectedOrgs : orgList;
|
|
443
|
+
const orgOptions = useMemo(() => [
|
|
444
|
+
{ label: t('DataSharing_SharedForAllOrgs', 'Dùng chung toàn tập đoàn'), value: '' },
|
|
445
|
+
...availableOrgs.map(org => ({
|
|
446
|
+
label: `${org.orgName} (${org.orgCode})`,
|
|
447
|
+
value: org.targetOrgId
|
|
448
|
+
}))
|
|
449
|
+
], [availableOrgs, t]);
|
|
450
|
+
const defaultValue = useMemo(() => {
|
|
451
|
+
const base = {
|
|
452
|
+
organizationId: '',
|
|
453
|
+
...(tabConfig.defaultRow ?? {})
|
|
454
|
+
};
|
|
455
|
+
tabConfig.columns.forEach(col => {
|
|
456
|
+
if (base[col.key] === undefined && col.defaultValue !== undefined) {
|
|
457
|
+
base[col.key] = col.defaultValue;
|
|
458
|
+
}
|
|
459
|
+
});
|
|
460
|
+
return base;
|
|
461
|
+
}, [tabConfig]);
|
|
462
|
+
const activeGridRows = useMemo(() => (rows ?? [])
|
|
463
|
+
.filter(r => !r._deleted)
|
|
464
|
+
.map(r => ({
|
|
465
|
+
...r,
|
|
466
|
+
organizationId: r.organizationId ?? ''
|
|
467
|
+
})), [rows]);
|
|
468
|
+
const emitUpdatedRows = (nextActiveRows) => {
|
|
469
|
+
const normalizedActive = (nextActiveRows ?? []).map((row, idx) => ({
|
|
470
|
+
...row,
|
|
471
|
+
organizationId: row.organizationId ? String(row.organizationId) : null,
|
|
472
|
+
sortOrder: idx + 1
|
|
473
|
+
}));
|
|
474
|
+
// Enforce uniqueScopeKey checkboxes across updated rows
|
|
475
|
+
tabConfig.columns.forEach(col => {
|
|
476
|
+
if ((col.type === 'checkbox' || col.type === 'switch') && col.uniqueScopeKey !== undefined) {
|
|
477
|
+
const seen = new Set();
|
|
478
|
+
normalizedActive.forEach(r => {
|
|
479
|
+
const scopeVal = r[col.uniqueScopeKey] ? String(r[col.uniqueScopeKey]) : '';
|
|
480
|
+
if (r[col.key]) {
|
|
481
|
+
if (seen.has(scopeVal)) {
|
|
482
|
+
r[col.key] = false;
|
|
483
|
+
}
|
|
484
|
+
else {
|
|
485
|
+
seen.add(scopeVal);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
const activeIds = new Set(normalizedActive.map(r => r.id).filter(Boolean));
|
|
492
|
+
const softDeletedPersisted = (rows ?? [])
|
|
493
|
+
.filter(r => r.id && !activeIds.has(r.id))
|
|
494
|
+
.map(r => ({ ...r, _deleted: true }));
|
|
495
|
+
onChangeRows([...normalizedActive, ...softDeletedPersisted]);
|
|
496
|
+
};
|
|
497
|
+
const headerColumns = useMemo(() => {
|
|
498
|
+
const baseCols = [
|
|
499
|
+
{
|
|
500
|
+
field: '#',
|
|
501
|
+
headerText: 'STT',
|
|
502
|
+
textAlign: 'center',
|
|
503
|
+
width: 50,
|
|
504
|
+
minWidth: 50,
|
|
505
|
+
maxWidth: 70,
|
|
506
|
+
fixedType: 'left'
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
field: 'organizationId',
|
|
510
|
+
headerText: t('DataSharing_Organization', 'Đơn vị áp dụng'),
|
|
511
|
+
headerTooltip: t('DataSharing_Organization', 'Đơn vị áp dụng'),
|
|
512
|
+
editType: 'select',
|
|
513
|
+
editEnable: true,
|
|
514
|
+
editSelectSettings: {
|
|
515
|
+
options: orgOptions,
|
|
516
|
+
fieldLabel: 'label'
|
|
517
|
+
},
|
|
518
|
+
template: (props) => {
|
|
519
|
+
const orgId = props.rowData?.organizationId ?? '';
|
|
520
|
+
if (!orgId) {
|
|
521
|
+
return t('DataSharing_SharedForAllOrgs', 'Dùng chung toàn tập đoàn');
|
|
522
|
+
}
|
|
523
|
+
const found = orgList.find(o => String(o.targetOrgId).toLowerCase() === String(orgId).toLowerCase());
|
|
524
|
+
return found ? `${found.orgName} (${found.orgCode})` : orgId;
|
|
525
|
+
},
|
|
526
|
+
width: 230,
|
|
527
|
+
minWidth: 180
|
|
528
|
+
}
|
|
529
|
+
];
|
|
530
|
+
const dynamicCols = buildGridColumns(tabConfig.columns, { t });
|
|
531
|
+
const commandCols = tabConfig.allowDelete === false
|
|
532
|
+
? []
|
|
533
|
+
: [
|
|
534
|
+
{
|
|
535
|
+
field: 'command',
|
|
536
|
+
visible: true,
|
|
537
|
+
textAlign: 'center',
|
|
538
|
+
fixedType: 'right',
|
|
539
|
+
width: 50,
|
|
540
|
+
minWidth: 50,
|
|
541
|
+
maxWidth: 50,
|
|
542
|
+
commandItems: [
|
|
543
|
+
{
|
|
544
|
+
id: 'DELETE',
|
|
545
|
+
title: '',
|
|
546
|
+
icon: jsx(Trash2, { fontSize: 16 }),
|
|
547
|
+
tooltip: String(t('Delete', 'Xóa'))
|
|
548
|
+
}
|
|
549
|
+
]
|
|
550
|
+
}
|
|
551
|
+
];
|
|
552
|
+
return [...baseCols, ...dynamicCols, ...commandCols];
|
|
553
|
+
}, [tabConfig.columns, tabConfig.allowDelete, orgOptions, orgList, t]);
|
|
554
|
+
const handleCellChange = (args, handleCallback) => {
|
|
555
|
+
const item = args.rowData;
|
|
556
|
+
const val = args.option;
|
|
557
|
+
const field = args.field;
|
|
558
|
+
const colDef = tabConfig.columns.find(c => c.key === field);
|
|
559
|
+
if (colDef?.autoFillMap && val && typeof val === 'object') {
|
|
560
|
+
Object.entries(colDef.autoFillMap).forEach(([targetKey, sourceKey]) => {
|
|
561
|
+
const sourceVal = val[sourceKey];
|
|
562
|
+
if (sourceVal !== undefined && sourceVal !== null) {
|
|
563
|
+
item[targetKey] = sourceVal;
|
|
564
|
+
}
|
|
565
|
+
});
|
|
566
|
+
}
|
|
567
|
+
if (colDef && (colDef.type === 'checkbox' || colDef.type === 'switch') && colDef.uniqueScopeKey !== undefined && item[colDef.key]) {
|
|
568
|
+
const currentScope = item[colDef.uniqueScopeKey] ?? '';
|
|
569
|
+
args.rowsData?.forEach((row) => {
|
|
570
|
+
if (row.rowId !== item.rowId && (row[colDef.uniqueScopeKey] ?? '') === currentScope) {
|
|
571
|
+
row[colDef.key] = false;
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
emitUpdatedRows(args.rowsData ?? []);
|
|
575
|
+
}
|
|
576
|
+
handleCallback(item, args.indexRow);
|
|
577
|
+
};
|
|
578
|
+
const toolbarBottomItems = tabConfig.allowAdd === false
|
|
579
|
+
? []
|
|
580
|
+
: [
|
|
581
|
+
{ key: 'ADD', label: 'Add item', position: 'Bottom', align: 'left' },
|
|
582
|
+
{ key: 'INSERT_AFTER', label: 'Insert item after', position: 'Bottom', align: 'left' },
|
|
583
|
+
{ key: 'INSERT_BEFORE', label: 'Insert item before', position: 'Bottom', align: 'left' },
|
|
584
|
+
{ key: 'DUPLICATE', label: 'Duplicate', position: 'Bottom', align: 'left' },
|
|
585
|
+
{ key: 'DELETE', label: 'Delete all item', position: 'Bottom', align: 'left' }
|
|
586
|
+
];
|
|
587
|
+
const handleCommandClick = (item) => {
|
|
588
|
+
if (item.id === 'DELETE') {
|
|
589
|
+
emitUpdatedRows(item?.rows ?? []);
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
return (jsx("div", { className: "es-data-sharing-detail-tab es-data-sharing-grid-wrap", 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, height: 280, allowResizing: true, t: t, format: {
|
|
593
|
+
decimalSeparator: '.',
|
|
594
|
+
thousandSeparator: ',',
|
|
595
|
+
decimalScale: 2
|
|
596
|
+
}, showEmptyText: false }, `DataSharingDetailGrid_${tabConfig.key}`) }));
|
|
131
597
|
};
|
|
132
598
|
|
|
133
|
-
const
|
|
134
|
-
const
|
|
599
|
+
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, showGlobalSharedSwitch: propShowGlobalSharedSwitch }) => {
|
|
600
|
+
const { t } = useTranslation();
|
|
601
|
+
const showMasterCard = propShowMasterCard ?? config.showMasterCard ?? true;
|
|
602
|
+
const showOrgScope = propShowOrgScope ?? config.showOrgScope ?? true;
|
|
603
|
+
const showConfigTabs = propShowConfigTabs ?? config.showConfigTabs ?? true;
|
|
604
|
+
const showOverrideTab = propShowOverrideTab ?? config.showOverrideTab ?? true;
|
|
605
|
+
const showSummaryTab = propShowSummaryTab ?? config.showSummaryTab ?? true;
|
|
606
|
+
const showGlobalSharedSwitch = propShowGlobalSharedSwitch ?? config.showGlobalSharedSwitch ?? true;
|
|
607
|
+
const detailTabs = config.detailTabs ?? [];
|
|
608
|
+
const hasVisibleTabs = showConfigTabs && (showOverrideTab || detailTabs.length > 0 || showSummaryTab);
|
|
609
|
+
const getFirstVisibleTab = () => {
|
|
610
|
+
if (showOverrideTab)
|
|
611
|
+
return 'override';
|
|
612
|
+
if (detailTabs.length > 0)
|
|
613
|
+
return `detail:${detailTabs[0].key}`;
|
|
614
|
+
return 'summary';
|
|
615
|
+
};
|
|
616
|
+
const [activeTab, setActiveTab] = useState(getFirstVisibleTab);
|
|
617
|
+
useEffect(() => {
|
|
618
|
+
const validTabs = [];
|
|
619
|
+
if (showOverrideTab)
|
|
620
|
+
validTabs.push('override');
|
|
621
|
+
detailTabs.forEach(tab => validTabs.push(`detail:${tab.key}`));
|
|
622
|
+
if (showSummaryTab)
|
|
623
|
+
validTabs.push('summary');
|
|
624
|
+
if (validTabs.length > 0 && !validTabs.includes(activeTab)) {
|
|
625
|
+
setActiveTab(validTabs[0]);
|
|
626
|
+
}
|
|
627
|
+
}, [showOverrideTab, showSummaryTab, detailTabs, activeTab]);
|
|
628
|
+
const selectedOrgs = orgList.filter(o => o.isSelected);
|
|
629
|
+
const showTopRow = showMasterCard || showOrgScope;
|
|
630
|
+
const masterColMd = showOrgScope ? 5 : 12;
|
|
631
|
+
const orgColMd = showMasterCard ? 7 : 12;
|
|
632
|
+
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, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) : (jsx(MasterCard, { title: config.masterCardTitle ?? config.title, fields: config.masterFields ?? [], data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) })), showOrgScope && (jsx(Col, { md: orgColMd, children: jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, parentOrgName: parentOrgName ?? config.parentOrgName }) }))] })), 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({ 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 => {
|
|
633
|
+
const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
|
|
634
|
+
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));
|
|
635
|
+
}), showSummaryTab && (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: [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 => ({
|
|
636
|
+
...prev,
|
|
637
|
+
[tab.key]: updatedRows
|
|
638
|
+
})) }) }, 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
|
|
639
|
+
? t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn')
|
|
640
|
+
: `${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)))] })] }) }))] })] }))] }));
|
|
641
|
+
};
|
|
642
|
+
|
|
643
|
+
function applyGlobalSharedToOrgList(orgList, checked, sharingLabel) {
|
|
644
|
+
if (!checked)
|
|
645
|
+
return orgList;
|
|
646
|
+
return orgList.map(o => ({
|
|
647
|
+
...o,
|
|
648
|
+
isSelected: true,
|
|
649
|
+
status: 1,
|
|
650
|
+
statusText: sharingLabel
|
|
651
|
+
}));
|
|
652
|
+
}
|
|
653
|
+
function updateOrgOverrideValue(orgList, targetOrgId, fieldKey, value) {
|
|
654
|
+
return orgList.map(item => {
|
|
655
|
+
if (item.targetOrgId !== targetOrgId)
|
|
656
|
+
return item;
|
|
657
|
+
return {
|
|
658
|
+
...item,
|
|
659
|
+
overrideData: {
|
|
660
|
+
...item.overrideData,
|
|
661
|
+
[fieldKey]: value
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
});
|
|
665
|
+
}
|
|
666
|
+
function applyFirstOverrideToAll(orgList) {
|
|
667
|
+
const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
|
|
668
|
+
if (editableOrgs.length < 2)
|
|
669
|
+
return orgList;
|
|
670
|
+
const firstData = editableOrgs[0].overrideData ?? {};
|
|
671
|
+
return orgList.map(item => {
|
|
672
|
+
if (!item.isSelected || !item.canOverrideConfig)
|
|
673
|
+
return item;
|
|
674
|
+
return {
|
|
675
|
+
...item,
|
|
676
|
+
overrideData: {
|
|
677
|
+
...firstData
|
|
678
|
+
}
|
|
679
|
+
};
|
|
680
|
+
});
|
|
681
|
+
}
|
|
682
|
+
function buildDataSharingPayload(params) {
|
|
683
|
+
const { config, entityId, entityIds, isGlobalShared, orgList, detailData } = params;
|
|
684
|
+
const isBatchMode = (entityIds?.length ?? 0) > 1;
|
|
685
|
+
const detailTabs = config.detailTabs ?? [];
|
|
686
|
+
return {
|
|
687
|
+
entityType: config.entityType,
|
|
688
|
+
entityId,
|
|
689
|
+
...(isBatchMode ? { entityIds } : {}),
|
|
690
|
+
isGlobalShared,
|
|
691
|
+
sharingList: orgList.map(o => ({
|
|
692
|
+
TargetOrgId: o.targetOrgId,
|
|
693
|
+
IsInheritMaster: o.isInheritMaster,
|
|
694
|
+
CanOverrideConfig: o.canOverrideConfig,
|
|
695
|
+
EffectiveFrom: o.effectiveFrom || null,
|
|
696
|
+
EffectiveTo: o.effectiveTo || null,
|
|
697
|
+
Status: o.isSelected ? 1 : 0
|
|
698
|
+
})),
|
|
699
|
+
orgConfigList: orgList
|
|
700
|
+
.filter(o => o.isSelected && o.canOverrideConfig)
|
|
701
|
+
.map(o => ({
|
|
702
|
+
OrganizationId: o.targetOrgId,
|
|
703
|
+
...o.overrideData
|
|
704
|
+
})),
|
|
705
|
+
...(detailTabs.length > 0 ? { detailData } : {})
|
|
706
|
+
};
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
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 }) => {
|
|
710
|
+
const { t } = useTranslation();
|
|
135
711
|
const [saving, setSaving] = useState(false);
|
|
712
|
+
const isBatchMode = (entityIds?.length ?? 0) > 1;
|
|
136
713
|
const handleToggleGlobalShared = (checked) => {
|
|
137
714
|
setIsGlobalShared(checked);
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
...o,
|
|
141
|
-
isSelected: true,
|
|
142
|
-
status: 1,
|
|
143
|
-
statusText: 'Đang chia sẻ'
|
|
144
|
-
})));
|
|
145
|
-
}
|
|
715
|
+
const sharingLabel = t('DataSharing_Sharing', 'Đang chia sẻ');
|
|
716
|
+
setOrgList(prev => applyGlobalSharedToOrgList(prev, checked, sharingLabel));
|
|
146
717
|
};
|
|
147
718
|
const handleChangeOverride = (targetOrgId, fieldKey, value) => {
|
|
148
|
-
setOrgList(prev => prev
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
...item,
|
|
153
|
-
overrideData: {
|
|
154
|
-
...item.overrideData,
|
|
155
|
-
[fieldKey]: value
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
}));
|
|
719
|
+
setOrgList(prev => updateOrgOverrideValue(prev, targetOrgId, fieldKey, value));
|
|
720
|
+
};
|
|
721
|
+
const handleApplyFirstToAll = () => {
|
|
722
|
+
setOrgList(prev => applyFirstOverrideToAll(prev));
|
|
159
723
|
};
|
|
160
724
|
const handleSubmit = async () => {
|
|
161
725
|
setSaving(true);
|
|
162
726
|
try {
|
|
163
|
-
const payload = {
|
|
164
|
-
|
|
727
|
+
const payload = buildDataSharingPayload({
|
|
728
|
+
config,
|
|
165
729
|
entityId,
|
|
730
|
+
entityIds,
|
|
166
731
|
isGlobalShared,
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
CanOverrideConfig: o.canOverrideConfig,
|
|
171
|
-
EffectiveFrom: o.effectiveFrom || null,
|
|
172
|
-
EffectiveTo: o.effectiveTo || null,
|
|
173
|
-
Status: o.isSelected ? 1 : 0
|
|
174
|
-
})),
|
|
175
|
-
orgConfigList: orgList
|
|
176
|
-
.filter(o => o.isSelected)
|
|
177
|
-
.map(o => ({
|
|
178
|
-
OrganizationId: o.targetOrgId,
|
|
179
|
-
...o.overrideData
|
|
180
|
-
}))
|
|
181
|
-
};
|
|
732
|
+
orgList,
|
|
733
|
+
detailData
|
|
734
|
+
});
|
|
182
735
|
await onSave(payload);
|
|
183
736
|
toggle();
|
|
184
737
|
}
|
|
@@ -186,30 +739,90 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, entityId, orgLis
|
|
|
186
739
|
setSaving(false);
|
|
187
740
|
}
|
|
188
741
|
};
|
|
189
|
-
return (jsxs(Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsx(ModalHeader, { toggle: toggle,
|
|
742
|
+
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: "\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, { 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, showGlobalSharedSwitch: showGlobalSharedSwitch })) }), 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') })] })] }));
|
|
190
743
|
};
|
|
191
744
|
|
|
192
|
-
const
|
|
745
|
+
const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, onChangeOrgList, detailData: controlledDetailData, onChangeDetailData, isGlobalShared: controlledGlobalShared = false, onChangeGlobalShared, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }) => {
|
|
746
|
+
const { t } = useTranslation();
|
|
747
|
+
const [internalDetailData, setInternalDetailData] = useState({});
|
|
748
|
+
const detailData = controlledDetailData ?? internalDetailData;
|
|
749
|
+
const setDetailData = onChangeDetailData ?? setInternalDetailData;
|
|
750
|
+
const handleToggleGlobalShared = (checked) => {
|
|
751
|
+
onChangeGlobalShared?.(checked);
|
|
752
|
+
const sharingLabel = t('DataSharing_Sharing', 'Đang chia sẻ');
|
|
753
|
+
onChangeOrgList(prev => applyGlobalSharedToOrgList(prev, checked, sharingLabel));
|
|
754
|
+
};
|
|
755
|
+
const handleChangeOverride = (targetOrgId, fieldKey, value) => {
|
|
756
|
+
onChangeOrgList(prev => updateOrgOverrideValue(prev, targetOrgId, fieldKey, value));
|
|
757
|
+
};
|
|
758
|
+
const handleApplyFirstToAll = () => {
|
|
759
|
+
onChangeOrgList(prev => applyFirstOverrideToAll(prev));
|
|
760
|
+
};
|
|
761
|
+
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, showGlobalSharedSwitch: showGlobalSharedSwitch }));
|
|
762
|
+
};
|
|
763
|
+
const DataSharingComponent = forwardRef(({ database, parentOrgName, fetchSharingData, onSave, onSuccess, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }, ref) => {
|
|
193
764
|
const [isOpen, setIsOpen] = useState(false);
|
|
194
765
|
const [loading, setLoading] = useState(false);
|
|
195
766
|
const [config, setConfig] = useState(null);
|
|
196
767
|
const [masterData, setMasterData] = useState({});
|
|
768
|
+
const [masterDataList, setMasterDataList] = useState([]);
|
|
769
|
+
const [activeParentOrgName, setActiveParentOrgName] = useState(parentOrgName);
|
|
197
770
|
const [entityId, setEntityId] = useState('');
|
|
771
|
+
const [entityIds, setEntityIds] = useState(undefined);
|
|
772
|
+
const [activeDatabase, setActiveDatabase] = useState(database);
|
|
198
773
|
const [isGlobalShared, setIsGlobalShared] = useState(false);
|
|
199
774
|
const [orgList, setOrgList] = useState([]);
|
|
775
|
+
const [detailData, setDetailData] = useState({});
|
|
776
|
+
const [openVisibility, setOpenVisibility] = useState({});
|
|
200
777
|
useImperativeHandle(ref, () => ({
|
|
201
778
|
open: async (params) => {
|
|
779
|
+
const targetDb = params.database ?? database;
|
|
780
|
+
const ids = params.entityIds?.filter(Boolean) ?? [];
|
|
781
|
+
const isBatch = ids.length > 1;
|
|
782
|
+
const primaryEntityId = params.entityId || ids[0] || '';
|
|
202
783
|
setIsOpen(true);
|
|
203
784
|
setConfig(params.config);
|
|
204
|
-
setMasterData(params.masterData);
|
|
205
|
-
|
|
785
|
+
setMasterData(params.masterData ?? params.masterDataList?.[0] ?? {});
|
|
786
|
+
setMasterDataList(params.masterDataList ?? (params.masterData ? [params.masterData] : []));
|
|
787
|
+
setActiveParentOrgName(params.parentOrgName ?? parentOrgName);
|
|
788
|
+
setEntityId(primaryEntityId);
|
|
789
|
+
setEntityIds(isBatch ? ids : undefined);
|
|
790
|
+
setActiveDatabase(targetDb);
|
|
206
791
|
setIsGlobalShared(params.initialGlobalShared || false);
|
|
207
|
-
|
|
792
|
+
setDetailData(params.initialDetailData ?? {});
|
|
793
|
+
setOpenVisibility({
|
|
794
|
+
showMasterCard: params.showMasterCard,
|
|
795
|
+
showOrgScope: params.showOrgScope,
|
|
796
|
+
showConfigTabs: params.showConfigTabs,
|
|
797
|
+
showOverrideTab: params.showOverrideTab,
|
|
798
|
+
showSummaryTab: params.showSummaryTab,
|
|
799
|
+
showGlobalSharedSwitch: params.showGlobalSharedSwitch
|
|
800
|
+
});
|
|
801
|
+
if (fetchSharingData && primaryEntityId) {
|
|
208
802
|
setLoading(true);
|
|
209
803
|
try {
|
|
210
|
-
const res = await fetchSharingData(params.entityType,
|
|
211
|
-
|
|
212
|
-
|
|
804
|
+
const res = await fetchSharingData(params.entityType, primaryEntityId, targetDb);
|
|
805
|
+
if (res.parentOrgName) {
|
|
806
|
+
setActiveParentOrgName(res.parentOrgName);
|
|
807
|
+
}
|
|
808
|
+
if (isBatch) {
|
|
809
|
+
// In batch mode, load org tree cleanly without inheriting single-item selections
|
|
810
|
+
setIsGlobalShared(false);
|
|
811
|
+
setOrgList((res.orgList ?? []).map(o => ({
|
|
812
|
+
...o,
|
|
813
|
+
isSelected: false,
|
|
814
|
+
isInheritMaster: true,
|
|
815
|
+
canOverrideConfig: false,
|
|
816
|
+
status: 0,
|
|
817
|
+
overrideData: {}
|
|
818
|
+
})));
|
|
819
|
+
setDetailData({});
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
setIsGlobalShared(res.isGlobalShared);
|
|
823
|
+
setOrgList(res.orgList ?? []);
|
|
824
|
+
setDetailData(res.detailData ?? params.initialDetailData ?? {});
|
|
825
|
+
}
|
|
213
826
|
}
|
|
214
827
|
finally {
|
|
215
828
|
setLoading(false);
|
|
@@ -223,15 +836,18 @@ const DataSharingComponent = forwardRef(({ fetchSharingData, onSave, onSuccess }
|
|
|
223
836
|
if (!isOpen || !config)
|
|
224
837
|
return null;
|
|
225
838
|
const handleSave = async (payload) => {
|
|
839
|
+
const finalPayload = activeDatabase
|
|
840
|
+
? { ...payload, database: activeDatabase }
|
|
841
|
+
: payload;
|
|
226
842
|
if (onSave) {
|
|
227
|
-
await onSave(
|
|
843
|
+
await onSave(finalPayload);
|
|
228
844
|
}
|
|
229
845
|
if (onSuccess) {
|
|
230
846
|
onSuccess();
|
|
231
847
|
}
|
|
232
848
|
};
|
|
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 }));
|
|
849
|
+
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, showGlobalSharedSwitch: openVisibility.showGlobalSharedSwitch ?? showGlobalSharedSwitch }));
|
|
234
850
|
});
|
|
235
851
|
|
|
236
|
-
export { DataSharingComponent as default };
|
|
852
|
+
export { BatchMasterCard, DataSharingPanel, DetailTabTable, MasterCard, OrgTable, OverrideTable, buildDataSharingPayload, DataSharingComponent as default };
|
|
237
853
|
//# sourceMappingURL=index.mjs.map
|