@esvndev/es-data-sharing 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
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
6
  import { Trash2 } from 'becoxy-icons';
7
7
 
@@ -84,28 +84,44 @@ 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 resolvedParentOrg = useMemo(() => {
118
+ if (parentOrgName)
119
+ return parentOrgName;
120
+ const rootOrg = orgList.find(o => !o.parentId);
121
+ if (!rootOrg)
122
+ return '';
123
+ return rootOrg.orgCode ? `${rootOrg.orgName} (${rootOrg.orgCode})` : rootOrg.orgName;
124
+ }, [parentOrgName, orgList]);
109
125
  const handleToggleSelectAll = (checked) => {
110
126
  const filteredIds = new Set(filtered.map(f => f.targetOrgId));
111
127
  const next = orgList.map(item => {
@@ -142,9 +158,115 @@ const OrgTable = ({ orgList, onChangeOrg, showEffectiveDate = false }) => {
142
158
  const next = orgList.map(item => item.targetOrgId === targetOrgId ? { ...item, [field]: value } : item);
143
159
  onChangeOrg(next);
144
160
  };
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)))) })] }) })] }) }));
161
+ const handleCellChange = (args, handleCallback) => {
162
+ const item = args.rowData;
163
+ const field = args.field;
164
+ if (field === 'effectiveFrom' || field === 'effectiveTo') {
165
+ const rawVal = item?.[field];
166
+ const normalized = rawVal ? String(rawVal).substring(0, 10) : null;
167
+ handleFieldChange(item.targetOrgId, field, normalized);
168
+ }
169
+ handleCallback(item, args.indexRow);
170
+ };
171
+ const headerColumns = useMemo(() => [
172
+ {
173
+ field: 'isSelected',
174
+ headerText: '',
175
+ width: 50,
176
+ minWidth: 50,
177
+ maxWidth: 50,
178
+ textAlign: 'center',
179
+ fixedType: 'left',
180
+ allowFiltering: false,
181
+ allowSortering: false,
182
+ allowResizing: false,
183
+ editEnable: false,
184
+ headerTemplate: () => (jsx("div", { className: "d-flex justify-content-center", onClick: e => e.stopPropagation(), children: jsx(Input, { type: "checkbox", title: String(t('DataSharing_SelectAll', 'Chọn tất cả')), checked: allFilteredSelected, onChange: e => handleToggleSelectAll(e.target.checked) }) })),
185
+ template: (props) => (jsx("div", { className: "d-flex justify-content-center", onClick: e => e.stopPropagation(), children: jsx(Input, { type: "checkbox", checked: Boolean(props.rowData?.isSelected), onChange: e => handleSelectRow(props.rowData?.targetOrgId, e.target.checked) }) }))
186
+ },
187
+ {
188
+ field: 'orgName',
189
+ headerText: String(t('DataSharing_Organization', 'Đơn vị')),
190
+ headerTooltip: String(t('DataSharing_Organization', 'Đơn vị')),
191
+ width: 260,
192
+ minWidth: 160,
193
+ fixedType: 'left',
194
+ editEnable: false,
195
+ template: (props) => (jsxs("div", { children: [jsx("div", { className: "fw-bold", children: props.rowData?.orgName }), jsxs("span", { className: "text-muted small", children: ["(", props.rowData?.orgCode, ")"] })] }))
196
+ },
197
+ {
198
+ field: 'orgType',
199
+ headerText: String(t('DataSharing_OrgType', 'Loại')),
200
+ headerTooltip: String(t('DataSharing_OrgType', 'Loại')),
201
+ width: 110,
202
+ minWidth: 95,
203
+ textAlign: 'center',
204
+ visible: false,
205
+ editEnable: false,
206
+ template: (props) => (jsx(Badge, { color: props.rowData?.orgType === 'Công ty' ? 'light-primary' : 'light-info', children: props.rowData?.orgType === 'Công ty'
207
+ ? t('DataSharing_Company', 'Công ty')
208
+ : t('DataSharing_Branch', 'Chi nhánh') }))
209
+ },
210
+ {
211
+ field: 'isInheritMaster',
212
+ headerText: String(t('DataSharing_InheritMaster', 'Kế thừa gốc')),
213
+ headerTooltip: String(t('DataSharing_InheritMaster', 'Kế thừa gốc')),
214
+ width: 115,
215
+ minWidth: 100,
216
+ textAlign: 'center',
217
+ visible: false,
218
+ allowFiltering: false,
219
+ editEnable: false,
220
+ template: (props) => (jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", onClick: e => e.stopPropagation(), children: jsx(Input, { type: "switch", checked: Boolean(props.rowData?.isInheritMaster), onChange: e => handleFieldChange(props.rowData?.targetOrgId, 'isInheritMaster', e.target.checked) }) }))
221
+ },
222
+ {
223
+ field: 'canOverrideConfig',
224
+ headerText: String(t('DataSharing_CanOverride', 'Cấu hình riêng')),
225
+ headerTooltip: String(t('DataSharing_CanOverride', 'Cấu hình riêng')),
226
+ width: 125,
227
+ minWidth: 110,
228
+ textAlign: 'center',
229
+ allowFiltering: false,
230
+ editEnable: false,
231
+ template: (props) => (jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", onClick: e => e.stopPropagation(), children: jsx(Input, { type: "switch", disabled: !props.rowData?.isSelected, checked: Boolean(props.rowData?.canOverrideConfig), onChange: e => handleFieldChange(props.rowData?.targetOrgId, 'canOverrideConfig', e.target.checked) }) }))
232
+ },
233
+ {
234
+ field: 'effectiveFrom',
235
+ headerText: String(t('DataSharing_EffectiveFrom', 'Hiệu lực từ')),
236
+ headerTooltip: String(t('DataSharing_EffectiveFrom', 'Hiệu lực từ')),
237
+ type: 'date',
238
+ editType: 'date',
239
+ textAlign: 'center',
240
+ visible: false,
241
+ width: 145,
242
+ minWidth: 120,
243
+ editEnable: (rowData) => Boolean(rowData?.isSelected)
244
+ },
245
+ {
246
+ field: 'effectiveTo',
247
+ headerText: String(t('DataSharing_EffectiveTo', 'Hiệu lực đến')),
248
+ headerTooltip: String(t('DataSharing_EffectiveTo', 'Hiệu lực đến')),
249
+ type: 'date',
250
+ editType: 'date',
251
+ textAlign: 'center',
252
+ visible: false,
253
+ width: 145,
254
+ minWidth: 120,
255
+ editEnable: (rowData) => Boolean(rowData?.isSelected)
256
+ },
257
+ {
258
+ field: 'statusText',
259
+ headerText: String(t('DataSharing_Status', 'Trạng thái')),
260
+ headerTooltip: String(t('DataSharing_Status', 'Trạng thái')),
261
+ width: 125,
262
+ minWidth: 105,
263
+ textAlign: 'center',
264
+ visible: false,
265
+ editEnable: false,
266
+ template: (props) => props.rowData?.isSelected ? (jsx("span", { className: "badge bg-light-success text-success", children: t('DataSharing_Sharing', 'Đang chia sẻ') })) : (jsx("span", { className: "badge bg-light-secondary text-secondary", children: t('DataSharing_NotShared', 'Chưa chia sẻ') }))
267
+ }
268
+ ], [allFilteredSelected, orgList, filtered, t]);
269
+ return (jsx(Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxs(CardBody, { className: "d-flex flex-column", children: [jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2", children: [jsxs("div", { children: [jsx("h5", { className: "mb-0 fw-bolder", children: t('DataSharing_OrgScope', 'Phạm vi chia sẻ xuống đơn vị') }), jsxs("div", { className: "d-flex align-items-center gap-2 mt-1", children: [jsxs(Badge, { color: "light-primary", className: "text-primary", children: [t('DataSharing_Sharing', 'Đang chia sẻ'), ": ", selectedCount, "/", orgList.length] }), jsxs(Badge, { color: "light-info", className: "text-info", children: [t('DataSharing_CanOverride', 'Cấu hình riêng'), ": ", overrideCount] })] })] }), jsxs("div", { className: "d-flex align-items-center gap-1", style: { minWidth: '280px' }, children: [jsx(Input, { type: "search", bsSize: "sm", placeholder: t('DataSharing_SearchOrg', 'Tìm kiếm đơn vị...'), value: search, onChange: e => setSearch(e.target.value) }), jsxs(Input, { type: "select", bsSize: "sm", style: { width: '125px' }, value: filterType, onChange: e => setFilterType(e.target.value), children: [jsx("option", { value: "ALL", children: t('DataSharing_All', 'Tất cả') }), jsx("option", { value: "C\u00F4ng ty", children: t('DataSharing_Company', 'Công ty') }), jsx("option", { value: "Chi nh\u00E1nh", children: t('DataSharing_Branch', 'Chi nhánh') })] })] })] }), (resolvedParentOrg || selectedCount > 0) && (jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center gap-2 mb-2", children: [jsx("div", { children: resolvedParentOrg && (jsxs("div", { className: "es-parent-org-pill", children: [jsxs("span", { className: "text-muted", children: [t('DataSharing_ParentOrg', 'Công ty mẹ'), ":"] }), jsxs("span", { className: "fw-bold text-primary", children: ["\uD83C\uDFE2 ", resolvedParentOrg] })] })) }), selectedCount > 0 && (jsxs("div", { className: "d-flex gap-2 ms-auto", children: [jsx(Button, { size: "sm", color: "primary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: () => handleToggleAllOverride(true), children: t('DataSharing_EnableAllOverride', 'Cho phép tất cả cấu hình riêng') }), jsx(Button, { size: "sm", color: "secondary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: () => handleToggleAllOverride(false), children: t('DataSharing_DisableAllOverride', 'Chỉ kế thừa gốc') })] }))] })), jsx("div", { className: "flex-grow-1 es-data-sharing-grid-wrap", style: { minHeight: 0 }, children: jsx(GridComponent, { dataSource: gridDataSource, editAble: false, rowEditable: (rowData) => Boolean(rowData?.isSelected), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, onRowStyles: (rowData) => rowData?.isSelected ? { backgroundColor: 'rgba(115, 103, 240, 0.06)' } : {}, height: 360, allowResizing: true, t: t, showEmptyText: false }, "DataSharingOrgScopeGrid") })] }) }));
148
270
  };
149
271
 
150
272
  function resolveFieldDisplayValue(field, rowData, rawVal) {
@@ -307,11 +429,11 @@ const OverrideTable = ({ orgList, overrideColumns, masterData, onChangeOverride,
307
429
  }
308
430
  handleCallback(item, args.indexRow);
309
431
  };
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.') })] })] }));
432
+ return (jsxs("div", { className: "es-data-sharing-override-table", children: [editableOrgs.length > 1 && onApplyFirstToAll && (jsx("div", { className: "d-flex justify-content-end mb-2", children: jsxs(Button, { size: "sm", color: "primary", outline: true, className: "py-0 px-2", style: { fontSize: '12px' }, onClick: onApplyFirstToAll, children: ["\uD83D\uDCCB ", t('DataSharing_ApplyFirstToAll', 'Áp dụng cấu hình dòng đầu cho các đơn vị khác')] }) })), selectedOrgs.length === 0 ? (jsx("div", { className: "border rounded text-center text-muted py-4 bg-light small", children: t('DataSharing_NoOrgSelected', 'Chưa có đơn vị nào được chọn chia sẻ ở bảng trên.') })) : (jsx("div", { className: "es-data-sharing-grid-wrap", children: jsx(GridComponent, { dataSource: gridDataSource, editAble: editableOrgs.length > 0, rowEditable: (rowData) => Boolean(rowData?._canOverrideConfig), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, height: 280, allowResizing: true, t: t, format: {
433
+ decimalSeparator: '.',
434
+ thousandSeparator: ',',
435
+ decimalScale: 0
436
+ }, showEmptyText: false }, "DataSharingOverrideGrid") })), jsxs("div", { className: "d-flex align-items-center mt-2 es-override-note", children: [jsx("span", { className: "me-1", children: "\u2139\uFE0F" }), jsx("span", { children: t('DataSharing_OverrideNote', 'Thông tin gốc do công ty mẹ quản lý. Các đơn vị được bật "Cấu hình riêng" sẽ có thể nhập thông số riêng tại đây.') })] })] }));
315
437
  };
316
438
 
317
439
  const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
@@ -467,83 +589,149 @@ const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
467
589
  emitUpdatedRows(item?.rows ?? []);
468
590
  }
469
591
  };
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: {
592
+ return (jsx("div", { className: "es-data-sharing-detail-tab es-data-sharing-grid-wrap", children: jsx(GridComponent, { dataSource: activeGridRows, editAble: true, lang: i18n.language || 'vi', showToolbar: false, onDataChange: emitUpdatedRows, defaultValue: defaultValue, columns: headerColumns, onCellChange: handleCellChange, toolbarItems: toolbarBottomItems, commandClick: handleCommandClick, height: 280, allowResizing: true, t: t, format: {
471
593
  decimalSeparator: '.',
472
594
  thousandSeparator: ',',
473
595
  decimalScale: 2
474
596
  }, showEmptyText: false }, `DataSharingDetailGrid_${tabConfig.key}`) }));
475
597
  };
476
598
 
477
- const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList = [], entityId, entityIds, orgList, setOrgList, detailData, setDetailData, isGlobalShared, setIsGlobalShared, onSave, loading = false }) => {
599
+ const DataSharingContent = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, setOrgList, detailData, setDetailData, isGlobalShared, onToggleGlobalShared, onChangeOverride, onApplyFirstToAll, showMasterCard: propShowMasterCard, showOrgScope: propShowOrgScope, showConfigTabs: propShowConfigTabs, showOverrideTab: propShowOverrideTab, showSummaryTab: propShowSummaryTab, showGlobalSharedSwitch: propShowGlobalSharedSwitch }) => {
478
600
  const { t } = useTranslation();
479
- const [activeTab, setActiveTab] = useState('override');
480
- const [saving, setSaving] = useState(false);
601
+ const showMasterCard = propShowMasterCard ?? config.showMasterCard ?? true;
602
+ const showOrgScope = propShowOrgScope ?? config.showOrgScope ?? true;
603
+ const showConfigTabs = propShowConfigTabs ?? config.showConfigTabs ?? true;
604
+ const showOverrideTab = propShowOverrideTab ?? config.showOverrideTab ?? true;
605
+ const showSummaryTab = propShowSummaryTab ?? config.showSummaryTab ?? true;
606
+ const showGlobalSharedSwitch = propShowGlobalSharedSwitch ?? config.showGlobalSharedSwitch ?? true;
607
+ const detailTabs = config.detailTabs ?? [];
608
+ const hasVisibleTabs = showConfigTabs && (showOverrideTab || detailTabs.length > 0 || showSummaryTab);
609
+ const getFirstVisibleTab = () => {
610
+ if (showOverrideTab)
611
+ return 'override';
612
+ if (detailTabs.length > 0)
613
+ return `detail:${detailTabs[0].key}`;
614
+ return 'summary';
615
+ };
616
+ const [activeTab, setActiveTab] = useState(getFirstVisibleTab);
617
+ useEffect(() => {
618
+ const validTabs = [];
619
+ if (showOverrideTab)
620
+ validTabs.push('override');
621
+ detailTabs.forEach(tab => validTabs.push(`detail:${tab.key}`));
622
+ if (showSummaryTab)
623
+ validTabs.push('summary');
624
+ if (validTabs.length > 0 && !validTabs.includes(activeTab)) {
625
+ setActiveTab(validTabs[0]);
626
+ }
627
+ }, [showOverrideTab, showSummaryTab, detailTabs, activeTab]);
628
+ const selectedOrgs = orgList.filter(o => o.isSelected);
629
+ const showTopRow = showMasterCard || showOrgScope;
630
+ const masterColMd = showOrgScope ? 5 : 12;
631
+ const orgColMd = showMasterCard ? 7 : 12;
632
+ return (jsxs("div", { className: "es-data-sharing-content", children: [showTopRow && (jsxs(Row, { className: hasVisibleTabs ? 'mb-3' : 'mb-0', children: [showMasterCard && (jsx(Col, { md: masterColMd, className: showOrgScope ? 'mb-2 mb-md-0' : '', children: isBatchMode ? (jsx(BatchMasterCard, { title: config.masterCardTitle ?? config.title, items: masterDataList, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) : (jsx(MasterCard, { title: config.masterCardTitle ?? config.title, fields: config.masterFields ?? [], data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) })), showOrgScope && (jsx(Col, { md: orgColMd, children: jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, parentOrgName: parentOrgName ?? config.parentOrgName }) }))] })), hasVisibleTabs && (jsxs("div", { className: "es-data-sharing-tabs-section", children: [jsxs(Nav, { tabs: true, className: "mb-2", children: [showOverrideTab && (jsx(NavItem, { children: jsxs(NavLink, { className: classnames({ active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: ["\u2699\uFE0F ", t('DataSharing_OrgConfigTab', 'Cấu hình theo đơn vị'), selectedOrgs.length > 0 && (jsx(Badge, { color: "light-primary", className: "ms-1 text-primary", children: selectedOrgs.length }))] }) })), detailTabs.map(tab => {
633
+ const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
634
+ return (jsx(NavItem, { children: jsxs(NavLink, { className: classnames({ active: activeTab === `detail:${tab.key}` }), onClick: () => setActiveTab(`detail:${tab.key}`), style: { cursor: 'pointer' }, children: [tab.icon ? `${tab.icon} ` : '📄 ', t(tab.title), jsx(Badge, { color: "light-info", className: "ms-1 text-info", children: activeCount })] }) }, tab.key));
635
+ }), showSummaryTab && (jsx(NavItem, { children: jsxs(NavLink, { className: classnames({ active: activeTab === 'summary' }), onClick: () => setActiveTab('summary'), style: { cursor: 'pointer' }, children: ["\uD83D\uDD52 ", t('DataSharing_SummaryTab', 'Tổng hợp phân quyền')] }) }))] }), jsxs(TabContent, { activeTab: activeTab, children: [showOverrideTab && (jsx(TabPane, { tabId: "override", children: jsx(OverrideTable, { orgList: orgList, overrideColumns: config.overrideColumns ?? [], masterData: isBatchMode ? undefined : masterData, onChangeOverride: onChangeOverride, onApplyFirstToAll: onApplyFirstToAll }) })), detailTabs.map(tab => (jsx(TabPane, { tabId: `detail:${tab.key}`, children: jsx(DetailTabTable, { tabConfig: tab, orgList: orgList, rows: detailData[tab.key] ?? [], onChangeRows: updatedRows => setDetailData(prev => ({
636
+ ...prev,
637
+ [tab.key]: updatedRows
638
+ })) }) }, tab.key))), showSummaryTab && (jsx(TabPane, { tabId: "summary", children: jsxs("div", { className: "es-data-sharing-summary-box", children: [jsx("div", { className: "fw-bold mb-2 small text-dark", children: t('DataSharing_SummaryTitle', 'Tóm tắt cấu hình chuẩn bị áp dụng') }), jsxs("div", { className: "es-summary-grid", children: [jsxs("div", { className: "es-summary-item", children: [jsx("div", { className: "es-summary-label", children: t('DataSharing_SummaryScope', 'Phạm vi') }), jsx("div", { className: "es-summary-value", children: isGlobalShared
639
+ ? t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn')
640
+ : `${selectedOrgs.length} ${t('DataSharing_Organization', 'Đơn vị')}` })] }), jsxs("div", { className: "es-summary-item", children: [jsx("div", { className: "es-summary-label", children: t('DataSharing_SummaryOverride', 'Đơn vị cho phép cấu hình riêng') }), jsx("div", { className: "es-summary-value", children: selectedOrgs.filter(o => o.canOverrideConfig).length })] }), detailTabs.map(tab => (jsxs("div", { className: "es-summary-item", children: [jsx("div", { className: "es-summary-label", children: t(tab.title) }), jsx("div", { className: "es-summary-value", children: (detailData[tab.key] ?? []).filter(r => !r._deleted).length })] }, tab.key)))] })] }) }))] })] }))] }));
641
+ };
642
+
643
+ function applyGlobalSharedToOrgList(orgList, checked, sharingLabel) {
644
+ if (!checked)
645
+ return orgList;
646
+ return orgList.map(o => ({
647
+ ...o,
648
+ isSelected: true,
649
+ status: 1,
650
+ statusText: sharingLabel
651
+ }));
652
+ }
653
+ function updateOrgOverrideValue(orgList, targetOrgId, fieldKey, value) {
654
+ return orgList.map(item => {
655
+ if (item.targetOrgId !== targetOrgId)
656
+ return item;
657
+ return {
658
+ ...item,
659
+ overrideData: {
660
+ ...item.overrideData,
661
+ [fieldKey]: value
662
+ }
663
+ };
664
+ });
665
+ }
666
+ function applyFirstOverrideToAll(orgList) {
667
+ const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
668
+ if (editableOrgs.length < 2)
669
+ return orgList;
670
+ const firstData = editableOrgs[0].overrideData ?? {};
671
+ return orgList.map(item => {
672
+ if (!item.isSelected || !item.canOverrideConfig)
673
+ return item;
674
+ return {
675
+ ...item,
676
+ overrideData: {
677
+ ...firstData
678
+ }
679
+ };
680
+ });
681
+ }
682
+ function buildDataSharingPayload(params) {
683
+ const { config, entityId, entityIds, isGlobalShared, orgList, detailData } = params;
481
684
  const isBatchMode = (entityIds?.length ?? 0) > 1;
482
685
  const detailTabs = config.detailTabs ?? [];
686
+ return {
687
+ entityType: config.entityType,
688
+ entityId,
689
+ ...(isBatchMode ? { entityIds } : {}),
690
+ isGlobalShared,
691
+ sharingList: orgList.map(o => ({
692
+ TargetOrgId: o.targetOrgId,
693
+ IsInheritMaster: o.isInheritMaster,
694
+ CanOverrideConfig: o.canOverrideConfig,
695
+ EffectiveFrom: o.effectiveFrom || null,
696
+ EffectiveTo: o.effectiveTo || null,
697
+ Status: o.isSelected ? 1 : 0
698
+ })),
699
+ orgConfigList: orgList
700
+ .filter(o => o.isSelected && o.canOverrideConfig)
701
+ .map(o => ({
702
+ OrganizationId: o.targetOrgId,
703
+ ...o.overrideData
704
+ })),
705
+ ...(detailTabs.length > 0 ? { detailData } : {})
706
+ };
707
+ }
708
+
709
+ const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList = [], parentOrgName, entityId, entityIds, orgList, setOrgList, detailData, setDetailData, isGlobalShared, setIsGlobalShared, onSave, loading = false, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }) => {
710
+ const { t } = useTranslation();
711
+ const [saving, setSaving] = useState(false);
712
+ const isBatchMode = (entityIds?.length ?? 0) > 1;
483
713
  const handleToggleGlobalShared = (checked) => {
484
714
  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
- }
715
+ const sharingLabel = t('DataSharing_Sharing', 'Đang chia sẻ');
716
+ setOrgList(prev => applyGlobalSharedToOrgList(prev, checked, sharingLabel));
493
717
  };
494
718
  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
- }));
719
+ setOrgList(prev => updateOrgOverrideValue(prev, targetOrgId, fieldKey, value));
506
720
  };
507
721
  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
- }));
722
+ setOrgList(prev => applyFirstOverrideToAll(prev));
522
723
  };
523
724
  const handleSubmit = async () => {
524
725
  setSaving(true);
525
726
  try {
526
- const payload = {
527
- entityType: config.entityType,
727
+ const payload = buildDataSharingPayload({
728
+ config,
528
729
  entityId,
529
- ...(isBatchMode ? { entityIds } : {}),
730
+ entityIds,
530
731
  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
- };
732
+ orgList,
733
+ detailData
734
+ });
547
735
  await onSave(payload);
548
736
  toggle();
549
737
  }
@@ -551,30 +739,41 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList =
551
739
  setSaving(false);
552
740
  }
553
741
  };
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ẻ') })] })] }));
742
+ return (jsxs(Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsx(ModalHeader, { toggle: toggle, children: jsxs("div", { className: "d-flex align-items-center", children: [jsx("span", { className: "me-2 es-data-sharing-header-icon", children: "\uD83D\uDD17" }), jsxs("div", { children: [jsxs("div", { className: "d-flex align-items-center gap-2", children: [jsx("h4", { className: "mb-0 fw-bolder", children: t(config.title) }), isBatchMode && (jsxs(Badge, { color: "primary", children: [t('DataSharing_BatchSharing', 'Chia sẻ hàng loạt'), " (", entityIds?.length, ")"] }))] }), jsx("small", { className: "text-muted", children: t('DataSharing_Subtitle', 'Quản lý chia sẻ dữ liệu và phân quyền theo đơn vị thành viên') })] })] }) }), jsx(ModalBody, { children: loading ? (jsxs("div", { className: "text-center py-5", children: [jsx("div", { className: "spinner-border text-primary", role: "status", children: jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsx("div", { className: "mt-2 text-muted", children: t('DataSharing_Loading', 'Đang tải dữ liệu chia sẻ...') })] })) : (jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab, showGlobalSharedSwitch: showGlobalSharedSwitch })) }), jsxs(ModalFooter, { children: [jsx(Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? t('DataSharing_Saving', 'Đang lưu...') : t('DataSharing_Save', 'Cập nhật chia sẻ') }), jsx(Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') })] })] }));
564
743
  };
565
744
 
566
- const DataSharingComponent = forwardRef(({ database, fetchSharingData, onSave, onSuccess }, ref) => {
745
+ const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, onChangeOrgList, detailData: controlledDetailData, onChangeDetailData, isGlobalShared: controlledGlobalShared = false, onChangeGlobalShared, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }) => {
746
+ const { t } = useTranslation();
747
+ const [internalDetailData, setInternalDetailData] = useState({});
748
+ const detailData = controlledDetailData ?? internalDetailData;
749
+ const setDetailData = onChangeDetailData ?? setInternalDetailData;
750
+ const handleToggleGlobalShared = (checked) => {
751
+ onChangeGlobalShared?.(checked);
752
+ const sharingLabel = t('DataSharing_Sharing', 'Đang chia sẻ');
753
+ onChangeOrgList(prev => applyGlobalSharedToOrgList(prev, checked, sharingLabel));
754
+ };
755
+ const handleChangeOverride = (targetOrgId, fieldKey, value) => {
756
+ onChangeOrgList(prev => updateOrgOverrideValue(prev, targetOrgId, fieldKey, value));
757
+ };
758
+ const handleApplyFirstToAll = () => {
759
+ onChangeOrgList(prev => applyFirstOverrideToAll(prev));
760
+ };
761
+ return (jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: onChangeOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: controlledGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab, showGlobalSharedSwitch: showGlobalSharedSwitch }));
762
+ };
763
+ const DataSharingComponent = forwardRef(({ database, parentOrgName, fetchSharingData, onSave, onSuccess, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }, ref) => {
567
764
  const [isOpen, setIsOpen] = useState(false);
568
765
  const [loading, setLoading] = useState(false);
569
766
  const [config, setConfig] = useState(null);
570
767
  const [masterData, setMasterData] = useState({});
571
768
  const [masterDataList, setMasterDataList] = useState([]);
769
+ const [activeParentOrgName, setActiveParentOrgName] = useState(parentOrgName);
572
770
  const [entityId, setEntityId] = useState('');
573
771
  const [entityIds, setEntityIds] = useState(undefined);
574
772
  const [activeDatabase, setActiveDatabase] = useState(database);
575
773
  const [isGlobalShared, setIsGlobalShared] = useState(false);
576
774
  const [orgList, setOrgList] = useState([]);
577
775
  const [detailData, setDetailData] = useState({});
776
+ const [openVisibility, setOpenVisibility] = useState({});
578
777
  useImperativeHandle(ref, () => ({
579
778
  open: async (params) => {
580
779
  const targetDb = params.database ?? database;
@@ -585,15 +784,27 @@ const DataSharingComponent = forwardRef(({ database, fetchSharingData, onSave, o
585
784
  setConfig(params.config);
586
785
  setMasterData(params.masterData ?? params.masterDataList?.[0] ?? {});
587
786
  setMasterDataList(params.masterDataList ?? (params.masterData ? [params.masterData] : []));
787
+ setActiveParentOrgName(params.parentOrgName ?? parentOrgName);
588
788
  setEntityId(primaryEntityId);
589
789
  setEntityIds(isBatch ? ids : undefined);
590
790
  setActiveDatabase(targetDb);
591
791
  setIsGlobalShared(params.initialGlobalShared || false);
592
792
  setDetailData(params.initialDetailData ?? {});
793
+ setOpenVisibility({
794
+ showMasterCard: params.showMasterCard,
795
+ showOrgScope: params.showOrgScope,
796
+ showConfigTabs: params.showConfigTabs,
797
+ showOverrideTab: params.showOverrideTab,
798
+ showSummaryTab: params.showSummaryTab,
799
+ showGlobalSharedSwitch: params.showGlobalSharedSwitch
800
+ });
593
801
  if (fetchSharingData && primaryEntityId) {
594
802
  setLoading(true);
595
803
  try {
596
804
  const res = await fetchSharingData(params.entityType, primaryEntityId, targetDb);
805
+ if (res.parentOrgName) {
806
+ setActiveParentOrgName(res.parentOrgName);
807
+ }
597
808
  if (isBatch) {
598
809
  // In batch mode, load org tree cleanly without inheriting single-item selections
599
810
  setIsGlobalShared(false);
@@ -635,8 +846,8 @@ const DataSharingComponent = forwardRef(({ database, fetchSharingData, onSave, o
635
846
  onSuccess();
636
847
  }
637
848
  };
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 }));
849
+ return (jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: activeParentOrgName ?? parentOrgName, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading, showMasterCard: openVisibility.showMasterCard ?? showMasterCard, showOrgScope: openVisibility.showOrgScope ?? showOrgScope, showConfigTabs: openVisibility.showConfigTabs ?? showConfigTabs, showOverrideTab: openVisibility.showOverrideTab ?? showOverrideTab, showSummaryTab: openVisibility.showSummaryTab ?? showSummaryTab, showGlobalSharedSwitch: openVisibility.showGlobalSharedSwitch ?? showGlobalSharedSwitch }));
639
850
  });
640
851
 
641
- export { DataSharingComponent as default };
852
+ export { BatchMasterCard, DataSharingPanel, DetailTabTable, MasterCard, OrgTable, OverrideTable, buildDataSharingPayload, DataSharingComponent as default };
642
853
  //# sourceMappingURL=index.mjs.map