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