@esvndev/es-data-sharing 1.1.0 → 1.3.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/master-info/master-card.d.ts +1 -0
- package/dist/component/modal/batch-master-card.d.ts +1 -0
- package/dist/component/modal/data-sharing-content.d.ts +18 -0
- package/dist/component/modal/index.d.ts +19 -2
- package/dist/component/modal/modal-sharing.d.ts +3 -2
- package/dist/component/modal/sharing-helpers.d.ts +12 -0
- package/dist/component/org-scope/org-table.d.ts +1 -1
- package/dist/index.d.ts +93 -8
- package/dist/index.js +314 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +308 -90
- package/dist/index.mjs.map +1 -1
- package/dist/styles/index.css +246 -5
- package/dist/styles/index.css.map +1 -1
- package/dist/styles/modal.css +48 -4
- package/dist/styles/modal.css.map +1 -1
- package/dist/types/index.d.ts +22 -6
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
3
5
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
6
|
var react = require('react');
|
|
5
|
-
var reactstrap = require('reactstrap');
|
|
6
7
|
var reactI18next = require('react-i18next');
|
|
8
|
+
var reactstrap = require('reactstrap');
|
|
7
9
|
var esGridTemplate = require('es-grid-template');
|
|
8
10
|
var becoxyIcons = require('becoxy-icons');
|
|
9
11
|
|
|
@@ -86,28 +88,46 @@ var classnames$1 = {exports: {}};
|
|
|
86
88
|
|
|
87
89
|
var classnames = classnames$1.exports;
|
|
88
90
|
|
|
89
|
-
const MasterCard = ({ title, fields, data, isGlobalShared, onToggleGlobalShared }) => {
|
|
90
|
-
|
|
91
|
+
const MasterCard = ({ title, fields, data, isGlobalShared, onToggleGlobalShared, showGlobalSharedSwitch = true }) => {
|
|
92
|
+
const { t } = reactI18next.useTranslation();
|
|
93
|
+
return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center es-master-header", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsxRuntime.jsx("span", { className: "avatar-content fs-5", children: "\uD83C\uDFE2" }) }), jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) })] }), jsxRuntime.jsx("div", { className: "master-fields-list flex-grow-1", children: fields.map(f => (jsxRuntime.jsxs("div", { className: "row mx-0 align-items-center es-master-field-row", children: [jsxRuntime.jsxs("label", { className: "col-5 ps-0 text-muted small mb-0", children: [t(f.label), ":"] }), jsxRuntime.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 && (jsxRuntime.jsx("div", { className: "mt-auto pt-3", children: jsxRuntime.jsxs("div", { className: `d-flex align-items-center justify-content-between es-global-shared-box ${isGlobalShared ? 'is-active' : ''}`, children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn') }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: t('DataSharing_GlobalSharedDesc', 'Tự động cấp quyền sử dụng cho tất cả đơn vị thành viên') })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] }) }))] }) }));
|
|
91
94
|
};
|
|
92
95
|
|
|
93
|
-
const BatchMasterCard = ({ title, items, isGlobalShared, onToggleGlobalShared }) => {
|
|
96
|
+
const BatchMasterCard = ({ title, items, isGlobalShared, onToggleGlobalShared, showGlobalSharedSwitch = true }) => {
|
|
94
97
|
const { t } = reactI18next.useTranslation();
|
|
95
|
-
return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between
|
|
98
|
+
return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between es-master-header", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsxRuntime.jsx("span", { className: "avatar-content fs-5", children: "\uD83D\uDCE6" }) }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_BatchModeSubtitle', 'Chế độ chia sẻ hàng loạt') })] })] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", pill: true, children: [items.length, " ", t('DataSharing_SelectedItems', 'đối tượng')] })] }), jsxRuntime.jsx("div", { className: "p-2 flex-grow-1 es-batch-items-list", children: items.map((item, idx) => (jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between py-1 border-bottom last-no-border", children: [jsxRuntime.jsxs("div", { className: "text-truncate me-2", children: [jsxRuntime.jsx("span", { className: "fw-bold text-primary me-1", children: item.code || item.Code || '-' }), jsxRuntime.jsx("span", { className: "small text-dark", children: item.name || item.Name || '' })] }), item.taxCode && jsxRuntime.jsx("small", { className: "text-muted text-nowrap", children: item.taxCode })] }, item.id || item.Id || idx))) }), showGlobalSharedSwitch && (jsxRuntime.jsx("div", { className: "mt-auto pt-3", children: jsxRuntime.jsxs("div", { className: `d-flex align-items-center justify-content-between es-global-shared-box ${isGlobalShared ? 'is-active' : ''}`, children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn') }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: t('DataSharing_GlobalSharedDesc', 'Tự động cấp quyền sử dụng cho tất cả đơn vị thành viên') })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] }) }))] }) }));
|
|
96
99
|
};
|
|
97
100
|
|
|
98
|
-
const OrgTable = ({ orgList, onChangeOrg,
|
|
99
|
-
const { t } = reactI18next.useTranslation();
|
|
101
|
+
const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
|
|
102
|
+
const { t, i18n } = reactI18next.useTranslation();
|
|
100
103
|
const [search, setSearch] = react.useState('');
|
|
101
104
|
const [filterType, setFilterType] = react.useState('ALL');
|
|
102
|
-
const filtered = orgList.filter(o => {
|
|
105
|
+
const filtered = react.useMemo(() => orgList.filter(o => {
|
|
103
106
|
const matchSearch = o.orgName.toLowerCase().includes(search.toLowerCase()) ||
|
|
104
107
|
o.orgCode.toLowerCase().includes(search.toLowerCase());
|
|
105
108
|
const matchType = filterType === 'ALL' || o.orgType === filterType;
|
|
106
109
|
return matchSearch && matchType;
|
|
107
|
-
});
|
|
110
|
+
}), [orgList, search, filterType]);
|
|
111
|
+
const gridDataSource = react.useMemo(() => filtered.map(o => ({
|
|
112
|
+
...o,
|
|
113
|
+
rowId: o.targetOrgId,
|
|
114
|
+
statusText: o.isSelected
|
|
115
|
+
? t('DataSharing_Sharing', 'Đang chia sẻ')
|
|
116
|
+
: t('DataSharing_NotShared', 'Chưa chia sẻ')
|
|
117
|
+
})), [filtered, t]);
|
|
108
118
|
const selectedCount = orgList.filter(o => o.isSelected).length;
|
|
109
119
|
const overrideCount = orgList.filter(o => o.isSelected && o.canOverrideConfig).length;
|
|
110
120
|
const allFilteredSelected = filtered.length > 0 && filtered.every(o => o.isSelected);
|
|
121
|
+
const selectedFiltered = filtered.filter(o => o.isSelected);
|
|
122
|
+
const allFilteredOverride = selectedFiltered.length > 0 && selectedFiltered.every(o => o.canOverrideConfig);
|
|
123
|
+
const resolvedParentOrg = react.useMemo(() => {
|
|
124
|
+
if (parentOrgName)
|
|
125
|
+
return parentOrgName;
|
|
126
|
+
const rootOrg = orgList.find(o => !o.parentId);
|
|
127
|
+
if (!rootOrg)
|
|
128
|
+
return '';
|
|
129
|
+
return rootOrg.orgCode ? `${rootOrg.orgName} (${rootOrg.orgCode})` : rootOrg.orgName;
|
|
130
|
+
}, [parentOrgName, orgList]);
|
|
111
131
|
const handleToggleSelectAll = (checked) => {
|
|
112
132
|
const filteredIds = new Set(filtered.map(f => f.targetOrgId));
|
|
113
133
|
const next = orgList.map(item => {
|
|
@@ -123,7 +143,10 @@ const OrgTable = ({ orgList, onChangeOrg, showEffectiveDate = false }) => {
|
|
|
123
143
|
onChangeOrg(next);
|
|
124
144
|
};
|
|
125
145
|
const handleToggleAllOverride = (enable) => {
|
|
126
|
-
const
|
|
146
|
+
const filteredIds = new Set(filtered.map(f => f.targetOrgId));
|
|
147
|
+
const next = orgList.map(item => item.isSelected && filteredIds.has(item.targetOrgId)
|
|
148
|
+
? { ...item, canOverrideConfig: enable }
|
|
149
|
+
: item);
|
|
127
150
|
onChangeOrg(next);
|
|
128
151
|
};
|
|
129
152
|
const handleSelectRow = (targetOrgId, checked) => {
|
|
@@ -144,9 +167,117 @@ const OrgTable = ({ orgList, onChangeOrg, showEffectiveDate = false }) => {
|
|
|
144
167
|
const next = orgList.map(item => item.targetOrgId === targetOrgId ? { ...item, [field]: value } : item);
|
|
145
168
|
onChangeOrg(next);
|
|
146
169
|
};
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
170
|
+
const handleCellChange = (args, handleCallback) => {
|
|
171
|
+
const item = args.rowData;
|
|
172
|
+
const field = args.field;
|
|
173
|
+
if (field === 'effectiveFrom' || field === 'effectiveTo') {
|
|
174
|
+
const rawVal = item?.[field];
|
|
175
|
+
const normalized = rawVal ? String(rawVal).substring(0, 10) : null;
|
|
176
|
+
handleFieldChange(item.targetOrgId, field, normalized);
|
|
177
|
+
}
|
|
178
|
+
handleCallback(item, args.indexRow);
|
|
179
|
+
};
|
|
180
|
+
const headerColumns = react.useMemo(() => [
|
|
181
|
+
{
|
|
182
|
+
field: 'isSelected',
|
|
183
|
+
headerText: '',
|
|
184
|
+
width: 44,
|
|
185
|
+
minWidth: 44,
|
|
186
|
+
maxWidth: 44,
|
|
187
|
+
textAlign: 'center',
|
|
188
|
+
allowFiltering: false,
|
|
189
|
+
allowSortering: false,
|
|
190
|
+
allowResizing: false,
|
|
191
|
+
editEnable: false,
|
|
192
|
+
headerTemplate: () => (jsxRuntime.jsx("div", { className: "d-flex justify-content-center", onClick: e => e.stopPropagation(), children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", title: String(t('DataSharing_SelectAll', 'Chọn tất cả')), checked: allFilteredSelected, onChange: e => handleToggleSelectAll(e.target.checked) }) })),
|
|
193
|
+
template: (props) => (jsxRuntime.jsx("div", { className: "d-flex justify-content-center", onClick: e => e.stopPropagation(), children: jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", checked: Boolean(props.rowData?.isSelected), onChange: e => handleSelectRow(props.rowData?.targetOrgId, e.target.checked) }) }))
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
field: 'orgName',
|
|
197
|
+
headerText: String(t('DataSharing_Organization', 'Đơn vị')),
|
|
198
|
+
headerTooltip: String(t('DataSharing_Organization', 'Đơn vị')),
|
|
199
|
+
width: 420,
|
|
200
|
+
minWidth: 220,
|
|
201
|
+
editEnable: false,
|
|
202
|
+
template: (props) => (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold", children: props.rowData?.orgName }), jsxRuntime.jsxs("span", { className: "text-muted small", children: ["(", props.rowData?.orgCode, ")"] })] }))
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
field: 'orgType',
|
|
206
|
+
headerText: String(t('DataSharing_OrgType', 'Loại')),
|
|
207
|
+
headerTooltip: String(t('DataSharing_OrgType', 'Loại')),
|
|
208
|
+
width: 110,
|
|
209
|
+
minWidth: 95,
|
|
210
|
+
textAlign: 'center',
|
|
211
|
+
visible: false,
|
|
212
|
+
editEnable: false,
|
|
213
|
+
template: (props) => (jsxRuntime.jsx(reactstrap.Badge, { color: props.rowData?.orgType === 'Công ty' ? 'light-primary' : 'light-info', children: props.rowData?.orgType === 'Công ty'
|
|
214
|
+
? t('DataSharing_Company', 'Công ty')
|
|
215
|
+
: t('DataSharing_Branch', 'Chi nhánh') }))
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
field: 'isInheritMaster',
|
|
219
|
+
headerText: String(t('DataSharing_InheritMaster', 'Kế thừa gốc')),
|
|
220
|
+
headerTooltip: String(t('DataSharing_InheritMaster', 'Kế thừa gốc')),
|
|
221
|
+
width: 115,
|
|
222
|
+
minWidth: 100,
|
|
223
|
+
textAlign: 'center',
|
|
224
|
+
visible: false,
|
|
225
|
+
allowFiltering: false,
|
|
226
|
+
editEnable: false,
|
|
227
|
+
template: (props) => (jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", onClick: e => e.stopPropagation(), children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: Boolean(props.rowData?.isInheritMaster), onChange: e => handleFieldChange(props.rowData?.targetOrgId, 'isInheritMaster', e.target.checked) }) }))
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
field: 'canOverrideConfig',
|
|
231
|
+
headerText: String(t('DataSharing_CanOverride', 'Cấu hình riêng')),
|
|
232
|
+
headerTooltip: String(t('DataSharing_CanOverride', 'Cấu hình riêng')),
|
|
233
|
+
width: 145,
|
|
234
|
+
minWidth: 120,
|
|
235
|
+
textAlign: 'center',
|
|
236
|
+
allowFiltering: false,
|
|
237
|
+
allowSortering: false,
|
|
238
|
+
editEnable: false,
|
|
239
|
+
headerTemplate: () => (jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-center gap-1", onClick: e => e.stopPropagation(), children: [jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", disabled: selectedFiltered.length === 0, checked: allFilteredOverride, title: String(allFilteredOverride
|
|
240
|
+
? t('DataSharing_DisableAllOverride', 'Chỉ kế thừa gốc')
|
|
241
|
+
: t('DataSharing_EnableAllOverride', 'Cho phép tất cả cấu hình riêng')), onChange: e => handleToggleAllOverride(e.target.checked) }), jsxRuntime.jsx("span", { children: t('DataSharing_CanOverride', 'Cấu hình riêng') })] })),
|
|
242
|
+
template: (props) => (jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", onClick: e => e.stopPropagation(), children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", disabled: !props.rowData?.isSelected, checked: Boolean(props.rowData?.canOverrideConfig), onChange: e => handleFieldChange(props.rowData?.targetOrgId, 'canOverrideConfig', e.target.checked) }) }))
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
field: 'effectiveFrom',
|
|
246
|
+
headerText: String(t('DataSharing_EffectiveFrom', 'Hiệu lực từ')),
|
|
247
|
+
headerTooltip: String(t('DataSharing_EffectiveFrom', 'Hiệu lực từ')),
|
|
248
|
+
type: 'date',
|
|
249
|
+
editType: 'date',
|
|
250
|
+
textAlign: 'center',
|
|
251
|
+
visible: false,
|
|
252
|
+
width: 145,
|
|
253
|
+
minWidth: 120,
|
|
254
|
+
editEnable: (rowData) => Boolean(rowData?.isSelected)
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
field: 'effectiveTo',
|
|
258
|
+
headerText: String(t('DataSharing_EffectiveTo', 'Hiệu lực đến')),
|
|
259
|
+
headerTooltip: String(t('DataSharing_EffectiveTo', 'Hiệu lực đến')),
|
|
260
|
+
type: 'date',
|
|
261
|
+
editType: 'date',
|
|
262
|
+
textAlign: 'center',
|
|
263
|
+
visible: false,
|
|
264
|
+
width: 145,
|
|
265
|
+
minWidth: 120,
|
|
266
|
+
editEnable: (rowData) => Boolean(rowData?.isSelected)
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
field: 'statusText',
|
|
270
|
+
headerText: String(t('DataSharing_Status', 'Trạng thái')),
|
|
271
|
+
headerTooltip: String(t('DataSharing_Status', 'Trạng thái')),
|
|
272
|
+
width: 125,
|
|
273
|
+
minWidth: 105,
|
|
274
|
+
textAlign: 'center',
|
|
275
|
+
visible: false,
|
|
276
|
+
editEnable: false,
|
|
277
|
+
template: (props) => props.rowData?.isSelected ? (jsxRuntime.jsx("span", { className: "badge bg-light-success text-success", children: t('DataSharing_Sharing', 'Đang chia sẻ') })) : (jsxRuntime.jsx("span", { className: "badge bg-light-secondary text-secondary", children: t('DataSharing_NotShared', 'Chưa chia sẻ') }))
|
|
278
|
+
}
|
|
279
|
+
], [allFilteredSelected, allFilteredOverride, selectedFiltered.length, orgList, filtered, t]);
|
|
280
|
+
return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t('DataSharing_OrgScope', 'Phạm vi chia sẻ xuống đơn vị') }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2 mt-1", children: [jsxRuntime.jsxs(reactstrap.Badge, { color: "light-primary", className: "text-primary", children: [t('DataSharing_Sharing', 'Đang chia sẻ'), ": ", selectedCount, "/", orgList.length] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "light-info", className: "text-info", children: [t('DataSharing_CanOverride', 'Cấu hình riêng'), ": ", overrideCount] })] })] }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-1", style: { minWidth: '280px' }, children: [jsxRuntime.jsx(reactstrap.Input, { type: "search", bsSize: "sm", placeholder: t('DataSharing_SearchOrg', 'Tìm kiếm đơn vị...'), value: search, onChange: e => setSearch(e.target.value) }), jsxRuntime.jsxs(reactstrap.Input, { type: "select", bsSize: "sm", style: { width: '125px' }, value: filterType, onChange: e => setFilterType(e.target.value), children: [jsxRuntime.jsx("option", { value: "ALL", children: t('DataSharing_All', 'Tất cả') }), jsxRuntime.jsx("option", { value: "C\u00F4ng ty", children: t('DataSharing_Company', 'Công ty') }), jsxRuntime.jsx("option", { value: "Chi nh\u00E1nh", children: t('DataSharing_Branch', 'Chi nhánh') })] })] })] }), resolvedParentOrg && (jsxRuntime.jsx("div", { className: "mb-2", children: jsxRuntime.jsxs("div", { className: "es-parent-org-pill", children: [jsxRuntime.jsxs("span", { className: "text-muted", children: [t('DataSharing_ParentOrg', 'Công ty mẹ'), ":"] }), jsxRuntime.jsxs("span", { className: "fw-bold text-primary", children: ["\uD83C\uDFE2 ", resolvedParentOrg] })] }) })), jsxRuntime.jsx("div", { className: "flex-grow-1 es-data-sharing-grid-wrap", style: { minHeight: 0 }, children: jsxRuntime.jsx(esGridTemplate.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") })] }) }));
|
|
150
281
|
};
|
|
151
282
|
|
|
152
283
|
function resolveFieldDisplayValue(field, rowData, rawVal) {
|
|
@@ -309,11 +440,11 @@ const OverrideTable = ({ orgList, overrideColumns, masterData, onChangeOverride,
|
|
|
309
440
|
}
|
|
310
441
|
handleCallback(item, args.indexRow);
|
|
311
442
|
};
|
|
312
|
-
return (jsxRuntime.jsxs("div", { className: "es-data-sharing-override-table", children: [editableOrgs.length > 1 && onApplyFirstToAll && (jsxRuntime.jsx("div", { className: "d-flex justify-content-end mb-2", children: jsxRuntime.jsxs(reactstrap.Button, {
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
443
|
+
return (jsxRuntime.jsxs("div", { className: "es-data-sharing-override-table", children: [editableOrgs.length > 1 && onApplyFirstToAll && (jsxRuntime.jsx("div", { className: "d-flex justify-content-end mb-2", children: jsxRuntime.jsxs(reactstrap.Button, { type: "button", size: "sm", color: "light", className: "es-apply-first-btn d-inline-flex align-items-center gap-1", onClick: onApplyFirstToAll, children: [jsxRuntime.jsx(becoxyIcons.Copy, { fontSize: 14 }), jsxRuntime.jsx("span", { children: t('DataSharing_ApplyFirstToAll', 'Áp dụng cấu hình dòng đầu cho các đơn vị khác') })] }) })), selectedOrgs.length === 0 ? (jsxRuntime.jsx("div", { className: "border rounded text-center text-muted py-4 bg-light small", children: t('DataSharing_NoOrgSelected', 'Chưa có đơn vị nào được chọn chia sẻ ở bảng trên.') })) : (jsxRuntime.jsx("div", { className: "es-data-sharing-grid-wrap", children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: editableOrgs.length > 0, rowEditable: (rowData) => Boolean(rowData?._canOverrideConfig), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, height: 280, allowResizing: true, t: t, format: {
|
|
444
|
+
decimalSeparator: '.',
|
|
445
|
+
thousandSeparator: ',',
|
|
446
|
+
decimalScale: 0
|
|
447
|
+
}, showEmptyText: false }, "DataSharingOverrideGrid") })), jsxRuntime.jsxs("div", { className: "d-flex align-items-center mt-2 es-override-note", children: [jsxRuntime.jsx("span", { className: "me-1", children: "\u2139\uFE0F" }), jsxRuntime.jsx("span", { children: t('DataSharing_OverrideNote', 'Thông tin gốc do công ty mẹ quản lý. Các đơn vị được bật "Cấu hình riêng" sẽ có thể nhập thông số riêng tại đây.') })] })] }));
|
|
317
448
|
};
|
|
318
449
|
|
|
319
450
|
const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
|
|
@@ -469,83 +600,149 @@ const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
|
|
|
469
600
|
emitUpdatedRows(item?.rows ?? []);
|
|
470
601
|
}
|
|
471
602
|
};
|
|
472
|
-
return (jsxRuntime.jsx("div", { className: "es-data-sharing-detail-tab", children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: activeGridRows, editAble: true, lang: i18n.language || 'vi', showToolbar: false, onDataChange: emitUpdatedRows, defaultValue: defaultValue, columns: headerColumns, onCellChange: handleCellChange, toolbarItems: toolbarBottomItems, commandClick: handleCommandClick, allowResizing: true, t: t, format: {
|
|
603
|
+
return (jsxRuntime.jsx("div", { className: "es-data-sharing-detail-tab es-data-sharing-grid-wrap", children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: activeGridRows, editAble: true, lang: i18n.language || 'vi', showToolbar: false, onDataChange: emitUpdatedRows, defaultValue: defaultValue, columns: headerColumns, onCellChange: handleCellChange, toolbarItems: toolbarBottomItems, commandClick: handleCommandClick, height: 280, allowResizing: true, t: t, format: {
|
|
473
604
|
decimalSeparator: '.',
|
|
474
605
|
thousandSeparator: ',',
|
|
475
606
|
decimalScale: 2
|
|
476
607
|
}, showEmptyText: false }, `DataSharingDetailGrid_${tabConfig.key}`) }));
|
|
477
608
|
};
|
|
478
609
|
|
|
479
|
-
const
|
|
610
|
+
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 }) => {
|
|
480
611
|
const { t } = reactI18next.useTranslation();
|
|
481
|
-
const
|
|
482
|
-
const
|
|
612
|
+
const showMasterCard = propShowMasterCard ?? config.showMasterCard ?? true;
|
|
613
|
+
const showOrgScope = propShowOrgScope ?? config.showOrgScope ?? true;
|
|
614
|
+
const showConfigTabs = propShowConfigTabs ?? config.showConfigTabs ?? true;
|
|
615
|
+
const showOverrideTab = propShowOverrideTab ?? config.showOverrideTab ?? true;
|
|
616
|
+
const showSummaryTab = propShowSummaryTab ?? config.showSummaryTab ?? true;
|
|
617
|
+
const showGlobalSharedSwitch = propShowGlobalSharedSwitch ?? config.showGlobalSharedSwitch ?? true;
|
|
618
|
+
const detailTabs = config.detailTabs ?? [];
|
|
619
|
+
const hasVisibleTabs = showConfigTabs && (showOverrideTab || detailTabs.length > 0 || showSummaryTab);
|
|
620
|
+
const getFirstVisibleTab = () => {
|
|
621
|
+
if (showOverrideTab)
|
|
622
|
+
return 'override';
|
|
623
|
+
if (detailTabs.length > 0)
|
|
624
|
+
return `detail:${detailTabs[0].key}`;
|
|
625
|
+
return 'summary';
|
|
626
|
+
};
|
|
627
|
+
const [activeTab, setActiveTab] = react.useState(getFirstVisibleTab);
|
|
628
|
+
react.useEffect(() => {
|
|
629
|
+
const validTabs = [];
|
|
630
|
+
if (showOverrideTab)
|
|
631
|
+
validTabs.push('override');
|
|
632
|
+
detailTabs.forEach(tab => validTabs.push(`detail:${tab.key}`));
|
|
633
|
+
if (showSummaryTab)
|
|
634
|
+
validTabs.push('summary');
|
|
635
|
+
if (validTabs.length > 0 && !validTabs.includes(activeTab)) {
|
|
636
|
+
setActiveTab(validTabs[0]);
|
|
637
|
+
}
|
|
638
|
+
}, [showOverrideTab, showSummaryTab, detailTabs, activeTab]);
|
|
639
|
+
const selectedOrgs = orgList.filter(o => o.isSelected);
|
|
640
|
+
const showTopRow = showMasterCard || showOrgScope;
|
|
641
|
+
const masterColMd = showOrgScope ? 5 : 12;
|
|
642
|
+
const orgColMd = showMasterCard ? 7 : 12;
|
|
643
|
+
return (jsxRuntime.jsxs("div", { className: "es-data-sharing-content", children: [showTopRow && (jsxRuntime.jsxs(reactstrap.Row, { className: hasVisibleTabs ? 'mb-3' : 'mb-0', children: [showMasterCard && (jsxRuntime.jsx(reactstrap.Col, { md: masterColMd, className: showOrgScope ? 'mb-2 mb-md-0' : '', children: isBatchMode ? (jsxRuntime.jsx(BatchMasterCard, { title: config.masterCardTitle ?? config.title, items: masterDataList, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) : (jsxRuntime.jsx(MasterCard, { title: config.masterCardTitle ?? config.title, fields: config.masterFields ?? [], data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) })), showOrgScope && (jsxRuntime.jsx(reactstrap.Col, { md: orgColMd, children: jsxRuntime.jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, parentOrgName: parentOrgName ?? config.parentOrgName }) }))] })), hasVisibleTabs && (jsxRuntime.jsxs("div", { className: "es-data-sharing-tabs-section", children: [jsxRuntime.jsxs(reactstrap.Nav, { tabs: true, className: "mb-2", children: [showOverrideTab && (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: ["\u2699\uFE0F ", t('DataSharing_OrgConfigTab', 'Cấu hình theo đơn vị'), selectedOrgs.length > 0 && (jsxRuntime.jsx(reactstrap.Badge, { color: "light-primary", className: "ms-1 text-primary", children: selectedOrgs.length }))] }) })), detailTabs.map(tab => {
|
|
644
|
+
const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
|
|
645
|
+
return (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === `detail:${tab.key}` }), onClick: () => setActiveTab(`detail:${tab.key}`), style: { cursor: 'pointer' }, children: [tab.icon ? `${tab.icon} ` : '📄 ', t(tab.title), jsxRuntime.jsx(reactstrap.Badge, { color: "light-info", className: "ms-1 text-info", children: activeCount })] }) }, tab.key));
|
|
646
|
+
}), showSummaryTab && (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'summary' }), onClick: () => setActiveTab('summary'), style: { cursor: 'pointer' }, children: ["\uD83D\uDD52 ", t('DataSharing_SummaryTab', 'Tổng hợp phân quyền')] }) }))] }), jsxRuntime.jsxs(reactstrap.TabContent, { activeTab: activeTab, children: [showOverrideTab && (jsxRuntime.jsx(reactstrap.TabPane, { tabId: "override", children: jsxRuntime.jsx(OverrideTable, { orgList: orgList, overrideColumns: config.overrideColumns ?? [], masterData: isBatchMode ? undefined : masterData, onChangeOverride: onChangeOverride, onApplyFirstToAll: onApplyFirstToAll }) })), detailTabs.map(tab => (jsxRuntime.jsx(reactstrap.TabPane, { tabId: `detail:${tab.key}`, children: jsxRuntime.jsx(DetailTabTable, { tabConfig: tab, orgList: orgList, rows: detailData[tab.key] ?? [], onChangeRows: updatedRows => setDetailData(prev => ({
|
|
647
|
+
...prev,
|
|
648
|
+
[tab.key]: updatedRows
|
|
649
|
+
})) }) }, tab.key))), showSummaryTab && (jsxRuntime.jsx(reactstrap.TabPane, { tabId: "summary", children: jsxRuntime.jsxs("div", { className: "es-data-sharing-summary-box", children: [jsxRuntime.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') }), jsxRuntime.jsxs("div", { className: "es-summary-grid", children: [jsxRuntime.jsxs("div", { className: "es-summary-item", children: [jsxRuntime.jsx("div", { className: "es-summary-label", children: t('DataSharing_SummaryScope', 'Phạm vi') }), jsxRuntime.jsx("div", { className: "es-summary-value", children: isGlobalShared
|
|
650
|
+
? t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn')
|
|
651
|
+
: `${selectedOrgs.length} ${t('DataSharing_Organization', 'Đơn vị')}` })] }), jsxRuntime.jsxs("div", { className: "es-summary-item", children: [jsxRuntime.jsx("div", { className: "es-summary-label", children: t('DataSharing_SummaryOverride', 'Đơn vị cho phép cấu hình riêng') }), jsxRuntime.jsx("div", { className: "es-summary-value", children: selectedOrgs.filter(o => o.canOverrideConfig).length })] }), detailTabs.map(tab => (jsxRuntime.jsxs("div", { className: "es-summary-item", children: [jsxRuntime.jsx("div", { className: "es-summary-label", children: t(tab.title) }), jsxRuntime.jsx("div", { className: "es-summary-value", children: (detailData[tab.key] ?? []).filter(r => !r._deleted).length })] }, tab.key)))] })] }) }))] })] }))] }));
|
|
652
|
+
};
|
|
653
|
+
|
|
654
|
+
function applyGlobalSharedToOrgList(orgList, checked, sharingLabel) {
|
|
655
|
+
if (!checked)
|
|
656
|
+
return orgList;
|
|
657
|
+
return orgList.map(o => ({
|
|
658
|
+
...o,
|
|
659
|
+
isSelected: true,
|
|
660
|
+
status: 1,
|
|
661
|
+
statusText: sharingLabel
|
|
662
|
+
}));
|
|
663
|
+
}
|
|
664
|
+
function updateOrgOverrideValue(orgList, targetOrgId, fieldKey, value) {
|
|
665
|
+
return orgList.map(item => {
|
|
666
|
+
if (item.targetOrgId !== targetOrgId)
|
|
667
|
+
return item;
|
|
668
|
+
return {
|
|
669
|
+
...item,
|
|
670
|
+
overrideData: {
|
|
671
|
+
...item.overrideData,
|
|
672
|
+
[fieldKey]: value
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
});
|
|
676
|
+
}
|
|
677
|
+
function applyFirstOverrideToAll(orgList) {
|
|
678
|
+
const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
|
|
679
|
+
if (editableOrgs.length < 2)
|
|
680
|
+
return orgList;
|
|
681
|
+
const firstData = editableOrgs[0].overrideData ?? {};
|
|
682
|
+
return orgList.map(item => {
|
|
683
|
+
if (!item.isSelected || !item.canOverrideConfig)
|
|
684
|
+
return item;
|
|
685
|
+
return {
|
|
686
|
+
...item,
|
|
687
|
+
overrideData: {
|
|
688
|
+
...firstData
|
|
689
|
+
}
|
|
690
|
+
};
|
|
691
|
+
});
|
|
692
|
+
}
|
|
693
|
+
function buildDataSharingPayload(params) {
|
|
694
|
+
const { config, entityId, entityIds, isGlobalShared, orgList, detailData } = params;
|
|
483
695
|
const isBatchMode = (entityIds?.length ?? 0) > 1;
|
|
484
696
|
const detailTabs = config.detailTabs ?? [];
|
|
697
|
+
return {
|
|
698
|
+
entityType: config.entityType,
|
|
699
|
+
entityId,
|
|
700
|
+
...(isBatchMode ? { entityIds } : {}),
|
|
701
|
+
isGlobalShared,
|
|
702
|
+
sharingList: orgList.map(o => ({
|
|
703
|
+
TargetOrgId: o.targetOrgId,
|
|
704
|
+
IsInheritMaster: o.isInheritMaster,
|
|
705
|
+
CanOverrideConfig: o.canOverrideConfig,
|
|
706
|
+
EffectiveFrom: o.effectiveFrom || null,
|
|
707
|
+
EffectiveTo: o.effectiveTo || null,
|
|
708
|
+
Status: o.isSelected ? 1 : 0
|
|
709
|
+
})),
|
|
710
|
+
orgConfigList: orgList
|
|
711
|
+
.filter(o => o.isSelected && o.canOverrideConfig)
|
|
712
|
+
.map(o => ({
|
|
713
|
+
OrganizationId: o.targetOrgId,
|
|
714
|
+
...o.overrideData
|
|
715
|
+
})),
|
|
716
|
+
...(detailTabs.length > 0 ? { detailData } : {})
|
|
717
|
+
};
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
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 }) => {
|
|
721
|
+
const { t } = reactI18next.useTranslation();
|
|
722
|
+
const [saving, setSaving] = react.useState(false);
|
|
723
|
+
const isBatchMode = (entityIds?.length ?? 0) > 1;
|
|
485
724
|
const handleToggleGlobalShared = (checked) => {
|
|
486
725
|
setIsGlobalShared(checked);
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
...o,
|
|
490
|
-
isSelected: true,
|
|
491
|
-
status: 1,
|
|
492
|
-
statusText: t('DataSharing_Sharing', 'Đang chia sẻ')
|
|
493
|
-
})));
|
|
494
|
-
}
|
|
726
|
+
const sharingLabel = t('DataSharing_Sharing', 'Đang chia sẻ');
|
|
727
|
+
setOrgList(prev => applyGlobalSharedToOrgList(prev, checked, sharingLabel));
|
|
495
728
|
};
|
|
496
729
|
const handleChangeOverride = (targetOrgId, fieldKey, value) => {
|
|
497
|
-
setOrgList(prev => prev
|
|
498
|
-
if (item.targetOrgId !== targetOrgId)
|
|
499
|
-
return item;
|
|
500
|
-
return {
|
|
501
|
-
...item,
|
|
502
|
-
overrideData: {
|
|
503
|
-
...item.overrideData,
|
|
504
|
-
[fieldKey]: value
|
|
505
|
-
}
|
|
506
|
-
};
|
|
507
|
-
}));
|
|
730
|
+
setOrgList(prev => updateOrgOverrideValue(prev, targetOrgId, fieldKey, value));
|
|
508
731
|
};
|
|
509
732
|
const handleApplyFirstToAll = () => {
|
|
510
|
-
|
|
511
|
-
if (editableOrgs.length < 2)
|
|
512
|
-
return;
|
|
513
|
-
const firstData = editableOrgs[0].overrideData ?? {};
|
|
514
|
-
setOrgList(prev => prev.map(item => {
|
|
515
|
-
if (!item.isSelected || !item.canOverrideConfig)
|
|
516
|
-
return item;
|
|
517
|
-
return {
|
|
518
|
-
...item,
|
|
519
|
-
overrideData: {
|
|
520
|
-
...firstData
|
|
521
|
-
}
|
|
522
|
-
};
|
|
523
|
-
}));
|
|
733
|
+
setOrgList(prev => applyFirstOverrideToAll(prev));
|
|
524
734
|
};
|
|
525
735
|
const handleSubmit = async () => {
|
|
526
736
|
setSaving(true);
|
|
527
737
|
try {
|
|
528
|
-
const payload = {
|
|
529
|
-
|
|
738
|
+
const payload = buildDataSharingPayload({
|
|
739
|
+
config,
|
|
530
740
|
entityId,
|
|
531
|
-
|
|
741
|
+
entityIds,
|
|
532
742
|
isGlobalShared,
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
CanOverrideConfig: o.canOverrideConfig,
|
|
537
|
-
EffectiveFrom: o.effectiveFrom || null,
|
|
538
|
-
EffectiveTo: o.effectiveTo || null,
|
|
539
|
-
Status: o.isSelected ? 1 : 0
|
|
540
|
-
})),
|
|
541
|
-
orgConfigList: orgList
|
|
542
|
-
.filter(o => o.isSelected && o.canOverrideConfig)
|
|
543
|
-
.map(o => ({
|
|
544
|
-
OrganizationId: o.targetOrgId,
|
|
545
|
-
...o.overrideData
|
|
546
|
-
})),
|
|
547
|
-
...(detailTabs.length > 0 ? { detailData } : {})
|
|
548
|
-
};
|
|
743
|
+
orgList,
|
|
744
|
+
detailData
|
|
745
|
+
});
|
|
549
746
|
await onSave(payload);
|
|
550
747
|
toggle();
|
|
551
748
|
}
|
|
@@ -553,30 +750,41 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList =
|
|
|
553
750
|
setSaving(false);
|
|
554
751
|
}
|
|
555
752
|
};
|
|
556
|
-
|
|
557
|
-
return (jsxRuntime.jsxs(reactstrap.Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsxRuntime.jsx(reactstrap.ModalHeader, { toggle: toggle, className: "border-bottom pb-2", children: jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("span", { className: "me-2 fs-4", children: "\uD83D\uDD17" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2", children: [jsxRuntime.jsx("h4", { className: "mb-0 fw-bolder", children: t(config.title) }), isBatchMode && (jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", children: [t('DataSharing_BatchSharing', 'Chia sẻ hàng loạt'), " (", entityIds?.length, ")"] }))] }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_Subtitle', 'Quản lý chia sẻ dữ liệu và phân quyền theo đơn vị thành viên') })] })] }) }), jsxRuntime.jsx(reactstrap.ModalBody, { className: "p-3", children: loading ? (jsxRuntime.jsxs("div", { className: "text-center py-5", children: [jsxRuntime.jsx("div", { className: "spinner-border text-primary", role: "status", children: jsxRuntime.jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsxRuntime.jsx("div", { className: "mt-2 text-muted", children: t('DataSharing_Loading', 'Đang tải dữ liệu chia sẻ...') })] })) : (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsxs(reactstrap.Row, { className: "mb-3", children: [jsxRuntime.jsx(reactstrap.Col, { md: 5, className: "mb-2 mb-md-0", children: isBatchMode ? (jsxRuntime.jsx(BatchMasterCard, { title: config.masterCardTitle, items: masterDataList, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared })) : (jsxRuntime.jsx(MasterCard, { title: config.masterCardTitle, fields: config.masterFields, data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared })) }), jsxRuntime.jsx(reactstrap.Col, { md: 7, children: jsxRuntime.jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, showEffectiveDate: config.showEffectiveDate }) })] }), jsxRuntime.jsxs(reactstrap.Nav, { tabs: true, className: "mb-2", children: [jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: ["\u2699\uFE0F ", t('DataSharing_OrgConfigTab', 'Cấu hình theo đơn vị'), selectedOrgs.length > 0 && (jsxRuntime.jsx(reactstrap.Badge, { color: "light-primary", className: "ms-1 text-primary", children: selectedOrgs.length }))] }) }), detailTabs.map(tab => {
|
|
558
|
-
const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
|
|
559
|
-
return (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === `detail:${tab.key}` }), onClick: () => setActiveTab(`detail:${tab.key}`), style: { cursor: 'pointer' }, children: [tab.icon ? `${tab.icon} ` : '📄 ', t(tab.title), jsxRuntime.jsx(reactstrap.Badge, { color: "light-info", className: "ms-1 text-info", children: activeCount })] }) }, tab.key));
|
|
560
|
-
}), jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'summary' }), onClick: () => setActiveTab('summary'), style: { cursor: 'pointer' }, children: ["\uD83D\uDD52 ", t('DataSharing_SummaryTab', 'Tổng hợp phân quyền')] }) })] }), jsxRuntime.jsxs(reactstrap.TabContent, { activeTab: activeTab, children: [jsxRuntime.jsx(reactstrap.TabPane, { tabId: "override", children: jsxRuntime.jsx(OverrideTable, { orgList: orgList, overrideColumns: config.overrideColumns, masterData: isBatchMode ? undefined : masterData, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll }) }), detailTabs.map(tab => (jsxRuntime.jsx(reactstrap.TabPane, { tabId: `detail:${tab.key}`, children: jsxRuntime.jsx(DetailTabTable, { tabConfig: tab, orgList: orgList, rows: detailData[tab.key] ?? [], onChangeRows: updatedRows => setDetailData(prev => ({
|
|
561
|
-
...prev,
|
|
562
|
-
[tab.key]: updatedRows
|
|
563
|
-
})) }) }, tab.key))), jsxRuntime.jsx(reactstrap.TabPane, { tabId: "summary", children: jsxRuntime.jsxs("div", { className: "border rounded p-3 small", children: [jsxRuntime.jsxs("div", { className: "fw-bold mb-2", children: [t('DataSharing_SummaryTitle', 'Tóm tắt cấu hình chuẩn bị áp dụng'), ":"] }), jsxRuntime.jsxs("ul", { className: "mb-0 ps-3", children: [jsxRuntime.jsxs("li", { children: [t('DataSharing_SummaryScope', 'Phạm vi'), ":", ' ', jsxRuntime.jsx("strong", { children: isGlobalShared
|
|
564
|
-
? t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn')
|
|
565
|
-
: `${selectedOrgs.length} ${t('DataSharing_Organization', 'Đơn vị')}` })] }), jsxRuntime.jsxs("li", { children: [t('DataSharing_SummaryOverride', 'Đơn vị cho phép cấu hình riêng'), ":", ' ', jsxRuntime.jsx("strong", { children: selectedOrgs.filter(o => o.canOverrideConfig).length })] }), detailTabs.map(tab => (jsxRuntime.jsxs("li", { children: [t(tab.title), ":", ' ', jsxRuntime.jsx("strong", { children: (detailData[tab.key] ?? []).filter(r => !r._deleted).length })] }, tab.key)))] })] }) })] })] })) }), jsxRuntime.jsxs(reactstrap.ModalFooter, { className: "border-top pt-2", children: [jsxRuntime.jsx(reactstrap.Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') }), jsxRuntime.jsx(reactstrap.Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? t('DataSharing_Saving', 'Đang lưu...') : t('DataSharing_Save', 'Cập nhật chia sẻ') })] })] }));
|
|
753
|
+
return (jsxRuntime.jsxs(reactstrap.Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsxRuntime.jsx(reactstrap.ModalHeader, { toggle: toggle, children: jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("span", { className: "me-2 es-data-sharing-header-icon", children: "\uD83D\uDD17" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2", children: [jsxRuntime.jsx("h4", { className: "mb-0 fw-bolder", children: t(config.title) }), isBatchMode && (jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", children: [t('DataSharing_BatchSharing', 'Chia sẻ hàng loạt'), " (", entityIds?.length, ")"] }))] }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_Subtitle', 'Quản lý chia sẻ dữ liệu và phân quyền theo đơn vị thành viên') })] })] }) }), jsxRuntime.jsx(reactstrap.ModalBody, { children: loading ? (jsxRuntime.jsxs("div", { className: "text-center py-5", children: [jsxRuntime.jsx("div", { className: "spinner-border text-primary", role: "status", children: jsxRuntime.jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsxRuntime.jsx("div", { className: "mt-2 text-muted", children: t('DataSharing_Loading', 'Đang tải dữ liệu chia sẻ...') })] })) : (jsxRuntime.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 })) }), jsxRuntime.jsxs(reactstrap.ModalFooter, { children: [jsxRuntime.jsx(reactstrap.Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? t('DataSharing_Saving', 'Đang lưu...') : t('DataSharing_Save', 'Cập nhật chia sẻ') }), jsxRuntime.jsx(reactstrap.Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') })] })] }));
|
|
566
754
|
};
|
|
567
755
|
|
|
568
|
-
const
|
|
756
|
+
const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, onChangeOrgList, detailData: controlledDetailData, onChangeDetailData, isGlobalShared: controlledGlobalShared = false, onChangeGlobalShared, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }) => {
|
|
757
|
+
const { t } = reactI18next.useTranslation();
|
|
758
|
+
const [internalDetailData, setInternalDetailData] = react.useState({});
|
|
759
|
+
const detailData = controlledDetailData ?? internalDetailData;
|
|
760
|
+
const setDetailData = onChangeDetailData ?? setInternalDetailData;
|
|
761
|
+
const handleToggleGlobalShared = (checked) => {
|
|
762
|
+
onChangeGlobalShared?.(checked);
|
|
763
|
+
const sharingLabel = t('DataSharing_Sharing', 'Đang chia sẻ');
|
|
764
|
+
onChangeOrgList(prev => applyGlobalSharedToOrgList(prev, checked, sharingLabel));
|
|
765
|
+
};
|
|
766
|
+
const handleChangeOverride = (targetOrgId, fieldKey, value) => {
|
|
767
|
+
onChangeOrgList(prev => updateOrgOverrideValue(prev, targetOrgId, fieldKey, value));
|
|
768
|
+
};
|
|
769
|
+
const handleApplyFirstToAll = () => {
|
|
770
|
+
onChangeOrgList(prev => applyFirstOverrideToAll(prev));
|
|
771
|
+
};
|
|
772
|
+
return (jsxRuntime.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 }));
|
|
773
|
+
};
|
|
774
|
+
const DataSharingComponent = react.forwardRef(({ database, parentOrgName, fetchSharingData, onSave, onSuccess, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }, ref) => {
|
|
569
775
|
const [isOpen, setIsOpen] = react.useState(false);
|
|
570
776
|
const [loading, setLoading] = react.useState(false);
|
|
571
777
|
const [config, setConfig] = react.useState(null);
|
|
572
778
|
const [masterData, setMasterData] = react.useState({});
|
|
573
779
|
const [masterDataList, setMasterDataList] = react.useState([]);
|
|
780
|
+
const [activeParentOrgName, setActiveParentOrgName] = react.useState(parentOrgName);
|
|
574
781
|
const [entityId, setEntityId] = react.useState('');
|
|
575
782
|
const [entityIds, setEntityIds] = react.useState(undefined);
|
|
576
783
|
const [activeDatabase, setActiveDatabase] = react.useState(database);
|
|
577
784
|
const [isGlobalShared, setIsGlobalShared] = react.useState(false);
|
|
578
785
|
const [orgList, setOrgList] = react.useState([]);
|
|
579
786
|
const [detailData, setDetailData] = react.useState({});
|
|
787
|
+
const [openVisibility, setOpenVisibility] = react.useState({});
|
|
580
788
|
react.useImperativeHandle(ref, () => ({
|
|
581
789
|
open: async (params) => {
|
|
582
790
|
const targetDb = params.database ?? database;
|
|
@@ -587,15 +795,27 @@ const DataSharingComponent = react.forwardRef(({ database, fetchSharingData, onS
|
|
|
587
795
|
setConfig(params.config);
|
|
588
796
|
setMasterData(params.masterData ?? params.masterDataList?.[0] ?? {});
|
|
589
797
|
setMasterDataList(params.masterDataList ?? (params.masterData ? [params.masterData] : []));
|
|
798
|
+
setActiveParentOrgName(params.parentOrgName ?? parentOrgName);
|
|
590
799
|
setEntityId(primaryEntityId);
|
|
591
800
|
setEntityIds(isBatch ? ids : undefined);
|
|
592
801
|
setActiveDatabase(targetDb);
|
|
593
802
|
setIsGlobalShared(params.initialGlobalShared || false);
|
|
594
803
|
setDetailData(params.initialDetailData ?? {});
|
|
804
|
+
setOpenVisibility({
|
|
805
|
+
showMasterCard: params.showMasterCard,
|
|
806
|
+
showOrgScope: params.showOrgScope,
|
|
807
|
+
showConfigTabs: params.showConfigTabs,
|
|
808
|
+
showOverrideTab: params.showOverrideTab,
|
|
809
|
+
showSummaryTab: params.showSummaryTab,
|
|
810
|
+
showGlobalSharedSwitch: params.showGlobalSharedSwitch
|
|
811
|
+
});
|
|
595
812
|
if (fetchSharingData && primaryEntityId) {
|
|
596
813
|
setLoading(true);
|
|
597
814
|
try {
|
|
598
815
|
const res = await fetchSharingData(params.entityType, primaryEntityId, targetDb);
|
|
816
|
+
if (res.parentOrgName) {
|
|
817
|
+
setActiveParentOrgName(res.parentOrgName);
|
|
818
|
+
}
|
|
599
819
|
if (isBatch) {
|
|
600
820
|
// In batch mode, load org tree cleanly without inheriting single-item selections
|
|
601
821
|
setIsGlobalShared(false);
|
|
@@ -637,8 +857,15 @@ const DataSharingComponent = react.forwardRef(({ database, fetchSharingData, onS
|
|
|
637
857
|
onSuccess();
|
|
638
858
|
}
|
|
639
859
|
};
|
|
640
|
-
return (jsxRuntime.jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading }));
|
|
860
|
+
return (jsxRuntime.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 }));
|
|
641
861
|
});
|
|
642
862
|
|
|
643
|
-
|
|
863
|
+
exports.BatchMasterCard = BatchMasterCard;
|
|
864
|
+
exports.DataSharingPanel = DataSharingPanel;
|
|
865
|
+
exports.DetailTabTable = DetailTabTable;
|
|
866
|
+
exports.MasterCard = MasterCard;
|
|
867
|
+
exports.OrgTable = OrgTable;
|
|
868
|
+
exports.OverrideTable = OverrideTable;
|
|
869
|
+
exports.buildDataSharingPayload = buildDataSharingPayload;
|
|
870
|
+
exports["default"] = DataSharingComponent;
|
|
644
871
|
//# sourceMappingURL=index.js.map
|