@esvndev/es-data-sharing 1.2.0 → 1.4.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.
@@ -4,9 +4,6 @@ interface Props {
4
4
  title: string;
5
5
  fields: ISharingFieldDef[];
6
6
  data: Record<string, any>;
7
- isGlobalShared: boolean;
8
- onToggleGlobalShared: (val: boolean) => void;
9
- showGlobalSharedSwitch?: boolean;
10
7
  }
11
8
  export declare const MasterCard: React.FC<Props>;
12
9
  export {};
@@ -1,10 +1,9 @@
1
1
  import React from 'react';
2
+ import { ISharingFieldDef } from '../../types';
2
3
  interface Props {
3
4
  title: string;
4
5
  items: Record<string, any>[];
5
- isGlobalShared: boolean;
6
- onToggleGlobalShared: (val: boolean) => void;
7
- showGlobalSharedSwitch?: boolean;
6
+ fields?: ISharingFieldDef[];
8
7
  }
9
8
  export declare const BatchMasterCard: React.FC<Props>;
10
9
  export {};
@@ -10,3 +10,8 @@ export declare function buildDataSharingPayload(params: {
10
10
  orgList: IOrgSharingItem[];
11
11
  detailData: Record<string, Record<string, any>[]>;
12
12
  }): IDataSharingPayload;
13
+ export declare function resolveCurrentOrgName(params: {
14
+ parentOrgName?: string;
15
+ organizationId?: string;
16
+ orgList?: IOrgSharingItem[];
17
+ }): string;
@@ -4,6 +4,8 @@ interface Props {
4
4
  orgList: IOrgSharingItem[];
5
5
  onChangeOrg: (updatedList: IOrgSharingItem[]) => void;
6
6
  parentOrgName?: string;
7
+ parentOrgLabel?: string;
8
+ organizationId?: string;
7
9
  }
8
10
  export declare const OrgTable: React.FC<Props>;
9
11
  export {};
package/dist/index.d.ts CHANGED
@@ -48,15 +48,17 @@ interface ISharingSectionVisibility {
48
48
  showOverrideTab?: boolean;
49
49
  /** Hiện/ẩn tab Tổng hợp phân quyền (mặc định: true) */
50
50
  showSummaryTab?: boolean;
51
- /** Hiện/ẩn nút gạt "Danh mục dùng chung toàn tập đoàn" (mặc định: true) */
52
- showGlobalSharedSwitch?: boolean;
53
51
  }
54
52
  interface ISharingMetadataConfig extends ISharingSectionVisibility {
55
53
  entityType: string;
56
54
  title: string;
57
55
  masterCardTitle?: string;
58
- /** Tên/mã công ty mẹ hiển thị trên thanh tiêu đề của Phạm vi chia sẻ */
56
+ /** Nhãn hiển thị trước tên công ty ở khối Phạm vi chia sẻ */
57
+ parentOrgLabel?: string;
58
+ /** Tên/mã công ty hiển thị trên thanh tiêu đề của Phạm vi chia sẻ */
59
59
  parentOrgName?: string;
60
+ /** ID hoặc mã tổ chức hiện tại để tự động map tên/mã hiển thị */
61
+ organizationId?: string;
60
62
  masterFields?: ISharingFieldDef[];
61
63
  overrideColumns?: ISharingFieldDef[];
62
64
  detailTabs?: ISharingDetailTabConfig[];
@@ -147,6 +149,8 @@ interface Props$4 {
147
149
  orgList: IOrgSharingItem[];
148
150
  onChangeOrg: (updatedList: IOrgSharingItem[]) => void;
149
151
  parentOrgName?: string;
152
+ parentOrgLabel?: string;
153
+ organizationId?: string;
150
154
  }
151
155
  declare const OrgTable: React.FC<Props$4>;
152
156
 
@@ -154,18 +158,13 @@ interface Props$3 {
154
158
  title: string;
155
159
  fields: ISharingFieldDef[];
156
160
  data: Record<string, any>;
157
- isGlobalShared: boolean;
158
- onToggleGlobalShared: (val: boolean) => void;
159
- showGlobalSharedSwitch?: boolean;
160
161
  }
161
162
  declare const MasterCard: React.FC<Props$3>;
162
163
 
163
164
  interface Props$2 {
164
165
  title: string;
165
166
  items: Record<string, any>[];
166
- isGlobalShared: boolean;
167
- onToggleGlobalShared: (val: boolean) => void;
168
- showGlobalSharedSwitch?: boolean;
167
+ fields?: ISharingFieldDef[];
169
168
  }
170
169
  declare const BatchMasterCard: React.FC<Props$2>;
171
170
 
package/dist/index.js CHANGED
@@ -88,26 +88,154 @@ var classnames$1 = {exports: {}};
88
88
 
89
89
  var classnames = classnames$1.exports;
90
90
 
91
- const MasterCard = ({ title, fields, data, isGlobalShared, onToggleGlobalShared, showGlobalSharedSwitch = true }) => {
91
+ const MasterCard = ({ title, fields, data }) => {
92
92
  const { t } = reactI18next.useTranslation();
93
- return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center es-master-header", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsxRuntime.jsx("span", { className: "avatar-content fs-5", children: "\uD83C\uDFE2" }) }), jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) })] }), jsxRuntime.jsx("div", { className: "master-fields-list flex-grow-1", children: fields.map(f => (jsxRuntime.jsxs("div", { className: "row mx-0 align-items-center es-master-field-row", children: [jsxRuntime.jsxs("label", { className: "col-5 ps-0 text-muted small mb-0", children: [t(f.label), ":"] }), jsxRuntime.jsx("div", { className: "col-7 pe-0 fw-bold text-truncate text-dark", title: data[f.key] ? String(data[f.key]) : '', children: data[f.key] !== undefined && data[f.key] !== null && data[f.key] !== '' ? String(data[f.key]) : '-' })] }, f.key))) }), showGlobalSharedSwitch && (jsxRuntime.jsx("div", { className: "mt-auto pt-3", children: jsxRuntime.jsxs("div", { className: `d-flex align-items-center justify-content-between es-global-shared-box ${isGlobalShared ? 'is-active' : ''}`, children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn') }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: t('DataSharing_GlobalSharedDesc', 'Tự động cấp quyền sử dụng cho tất cả đơn vị thành viên') })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] }) }))] }) }));
93
+ return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center es-master-header", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsxRuntime.jsx("span", { className: "avatar-content fs-5", children: "\uD83C\uDFE2" }) }), jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) })] }), jsxRuntime.jsx("div", { className: "master-fields-list flex-grow-1", children: fields.map(f => (jsxRuntime.jsxs("div", { className: "row mx-0 align-items-center es-master-field-row", children: [jsxRuntime.jsxs("label", { className: "col-5 ps-0 text-muted small mb-0", children: [t(f.label), ":"] }), jsxRuntime.jsx("div", { className: "col-7 pe-0 fw-bold text-truncate text-dark", title: data[f.key] ? String(data[f.key]) : '', children: data[f.key] !== undefined && data[f.key] !== null && data[f.key] !== '' ? String(data[f.key]) : '-' })] }, f.key))) })] }) }));
94
94
  };
95
95
 
96
- const BatchMasterCard = ({ title, items, isGlobalShared, onToggleGlobalShared, showGlobalSharedSwitch = true }) => {
96
+ const BatchMasterCard = ({ title, items, fields = [] }) => {
97
97
  const { t } = reactI18next.useTranslation();
98
- return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between es-master-header", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsxRuntime.jsx("span", { className: "avatar-content fs-5", children: "\uD83D\uDCE6" }) }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_BatchModeSubtitle', 'Chế độ chia sẻ hàng loạt') })] })] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", pill: true, children: [items.length, " ", t('DataSharing_SelectedItems', 'đối tượng')] })] }), jsxRuntime.jsx("div", { className: "p-2 flex-grow-1 es-batch-items-list", children: items.map((item, idx) => (jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between py-1 border-bottom last-no-border", children: [jsxRuntime.jsxs("div", { className: "text-truncate me-2", children: [jsxRuntime.jsx("span", { className: "fw-bold text-primary me-1", children: item.code || item.Code || '-' }), jsxRuntime.jsx("span", { className: "small text-dark", children: item.name || item.Name || '' })] }), item.taxCode && jsxRuntime.jsx("small", { className: "text-muted text-nowrap", children: item.taxCode })] }, item.id || item.Id || idx))) }), showGlobalSharedSwitch && (jsxRuntime.jsx("div", { className: "mt-auto pt-3", children: jsxRuntime.jsxs("div", { className: `d-flex align-items-center justify-content-between es-global-shared-box ${isGlobalShared ? 'is-active' : ''}`, children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold small text-primary", children: t('DataSharing_GlobalShared', 'Danh mục dùng chung toàn tập đoàn') }), jsxRuntime.jsx("div", { className: "text-muted", style: { fontSize: '11px' }, children: t('DataSharing_GlobalSharedDesc', 'Tự động cấp quyền sử dụng cho tất cả đơn vị thành viên') })] }), jsxRuntime.jsx("div", { className: "form-check form-switch mb-0", children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", checked: isGlobalShared, onChange: e => onToggleGlobalShared(e.target.checked) }) })] }) }))] }) }));
98
+ const codeLabel = fields.find(f => f.key === 'code' || f.key === 'Code')?.label;
99
+ const nameLabel = fields.find(f => f.key === 'name' || f.key === 'Name')?.label;
100
+ const taxField = fields.find(f => f.key === 'taxCode' || f.key === 'TaxCode');
101
+ const primaryHeader = codeLabel && nameLabel
102
+ ? `${t(codeLabel)} / ${t(nameLabel)}`
103
+ : t('DataSharing_BatchItemName', 'Mã / Tên');
104
+ const showTaxColumn = Boolean(taxField) || items.some(item => Boolean(item.taxCode || item.TaxCode));
105
+ const taxHeader = taxField
106
+ ? t(taxField.label)
107
+ : t('DataSharing_TaxCode', 'Mã số thuế');
108
+ return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-master-card", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-between es-master-header", children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("div", { className: "avatar bg-light-primary me-2 es-master-avatar", children: jsxRuntime.jsx("span", { className: "avatar-content fs-5", children: "\uD83D\uDCE6" }) }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t(title) }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_BatchModeSubtitle', 'Chế độ chia sẻ hàng loạt') })] })] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", pill: true, className: "es-batch-count-badge", children: [items.length, " ", t('DataSharing_SelectedItems', 'đối tượng')] })] }), jsxRuntime.jsxs("div", { className: "flex-grow-1 es-batch-items-list", children: [jsxRuntime.jsxs("div", { className: "es-batch-items-header d-flex align-items-center justify-content-between px-2 py-2 border-bottom", children: [jsxRuntime.jsx("span", { className: "fw-semibold", children: primaryHeader }), showTaxColumn && (jsxRuntime.jsx("span", { className: "fw-semibold text-nowrap ms-2", children: taxHeader }))] }), jsxRuntime.jsx("div", { className: "px-2", children: items.map((item, idx) => (jsxRuntime.jsxs("div", { className: "es-batch-row d-flex align-items-center justify-content-between py-2 border-bottom last-no-border", children: [jsxRuntime.jsxs("div", { className: "text-truncate me-2", children: [jsxRuntime.jsx("span", { className: "fw-bold es-batch-code me-1", children: item.code || item.Code || '-' }), jsxRuntime.jsx("span", { className: "small text-dark", children: item.name || item.Name || '' })] }), showTaxColumn && (jsxRuntime.jsx("small", { className: "text-muted text-nowrap", children: item.taxCode || item.TaxCode || '-' }))] }, item.id || item.Id || idx))) })] })] }) }));
99
109
  };
100
110
 
101
- const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
111
+ function applyGlobalSharedToOrgList(orgList, checked, sharingLabel) {
112
+ if (!checked)
113
+ return orgList;
114
+ return orgList.map(o => ({
115
+ ...o,
116
+ isSelected: true,
117
+ status: 1,
118
+ statusText: sharingLabel
119
+ }));
120
+ }
121
+ function updateOrgOverrideValue(orgList, targetOrgId, fieldKey, value) {
122
+ return orgList.map(item => {
123
+ if (item.targetOrgId !== targetOrgId)
124
+ return item;
125
+ return {
126
+ ...item,
127
+ overrideData: {
128
+ ...item.overrideData,
129
+ [fieldKey]: value
130
+ }
131
+ };
132
+ });
133
+ }
134
+ function applyFirstOverrideToAll(orgList) {
135
+ const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
136
+ if (editableOrgs.length < 2)
137
+ return orgList;
138
+ const firstData = editableOrgs[0].overrideData ?? {};
139
+ return orgList.map(item => {
140
+ if (!item.isSelected || !item.canOverrideConfig)
141
+ return item;
142
+ return {
143
+ ...item,
144
+ overrideData: {
145
+ ...firstData
146
+ }
147
+ };
148
+ });
149
+ }
150
+ function buildDataSharingPayload(params) {
151
+ const { config, entityId, entityIds, isGlobalShared, orgList, detailData } = params;
152
+ const isBatchMode = (entityIds?.length ?? 0) > 1;
153
+ const detailTabs = config.detailTabs ?? [];
154
+ return {
155
+ entityType: config.entityType,
156
+ entityId,
157
+ ...(isBatchMode ? { entityIds } : {}),
158
+ isGlobalShared,
159
+ sharingList: orgList
160
+ .filter(o => o.isSelected)
161
+ .map(o => ({
162
+ TargetOrgId: o.targetOrgId,
163
+ IsInheritMaster: o.isInheritMaster,
164
+ CanOverrideConfig: o.canOverrideConfig,
165
+ EffectiveFrom: o.effectiveFrom || null,
166
+ EffectiveTo: o.effectiveTo || null,
167
+ Status: 1
168
+ })),
169
+ orgConfigList: orgList
170
+ .filter(o => o.isSelected && o.canOverrideConfig)
171
+ .map(o => ({
172
+ OrganizationId: o.targetOrgId,
173
+ ...o.overrideData
174
+ })),
175
+ ...(detailTabs.length > 0 ? { detailData } : {})
176
+ };
177
+ }
178
+ function findOrgInList(list, targetId) {
179
+ for (const item of list ?? []) {
180
+ if (item?.value === targetId ||
181
+ item?.id === targetId ||
182
+ item?.targetOrgId === targetId ||
183
+ item?.key === targetId ||
184
+ item?.code === targetId ||
185
+ item?.orgCode === targetId) {
186
+ return item;
187
+ }
188
+ if (Array.isArray(item?.children) && item.children.length > 0) {
189
+ const child = findOrgInList(item.children, targetId);
190
+ if (child)
191
+ return child;
192
+ }
193
+ }
194
+ return null;
195
+ }
196
+ function formatOrgDisplay(org) {
197
+ if (!org)
198
+ return '';
199
+ const name = org.label ?? org.name ?? org.text ?? org.orgName ?? '';
200
+ const code = org.key ?? org.code ?? org.orgCode ?? '';
201
+ if (!name && !code)
202
+ return '';
203
+ return code ? `${name} (${code})` : String(name);
204
+ }
205
+ function resolveCurrentOrgName(params) {
206
+ const { parentOrgName, organizationId, orgList = [] } = params;
207
+ if (parentOrgName)
208
+ return parentOrgName;
209
+ if (organizationId) {
210
+ const matchedFromList = findOrgInList(orgList, organizationId);
211
+ const formatted = formatOrgDisplay(matchedFromList);
212
+ if (formatted)
213
+ return formatted;
214
+ if (typeof window !== 'undefined' && window.localStorage) {
215
+ try {
216
+ const raw = window.localStorage.getItem('organization');
217
+ if (raw) {
218
+ const stored = JSON.parse(raw);
219
+ if (stored && (stored.id === organizationId || stored.code === organizationId)) {
220
+ const storedFormatted = formatOrgDisplay(stored);
221
+ if (storedFormatted)
222
+ return storedFormatted;
223
+ }
224
+ }
225
+ }
226
+ catch {
227
+ // Bỏ qua lỗi parse localStorage
228
+ }
229
+ }
230
+ }
231
+ return '';
232
+ }
233
+
234
+ const OrgTable = ({ orgList, onChangeOrg, parentOrgName, parentOrgLabel, organizationId }) => {
102
235
  const { t, i18n } = reactI18next.useTranslation();
103
236
  const [search, setSearch] = react.useState('');
104
- const [filterType, setFilterType] = react.useState('ALL');
105
- const filtered = react.useMemo(() => orgList.filter(o => {
106
- const matchSearch = o.orgName.toLowerCase().includes(search.toLowerCase()) ||
107
- o.orgCode.toLowerCase().includes(search.toLowerCase());
108
- const matchType = filterType === 'ALL' || o.orgType === filterType;
109
- return matchSearch && matchType;
110
- }), [orgList, search, filterType]);
237
+ const filtered = react.useMemo(() => orgList.filter(o => o.orgName.toLowerCase().includes(search.toLowerCase()) ||
238
+ o.orgCode.toLowerCase().includes(search.toLowerCase())), [orgList, search]);
111
239
  const gridDataSource = react.useMemo(() => filtered.map(o => ({
112
240
  ...o,
113
241
  rowId: o.targetOrgId,
@@ -118,14 +246,13 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
118
246
  const selectedCount = orgList.filter(o => o.isSelected).length;
119
247
  const overrideCount = orgList.filter(o => o.isSelected && o.canOverrideConfig).length;
120
248
  const allFilteredSelected = filtered.length > 0 && filtered.every(o => o.isSelected);
121
- const resolvedParentOrg = react.useMemo(() => {
122
- if (parentOrgName)
123
- return parentOrgName;
124
- const rootOrg = orgList.find(o => !o.parentId);
125
- if (!rootOrg)
126
- return '';
127
- return rootOrg.orgCode ? `${rootOrg.orgName} (${rootOrg.orgCode})` : rootOrg.orgName;
128
- }, [parentOrgName, orgList]);
249
+ const selectedFiltered = filtered.filter(o => o.isSelected);
250
+ const allFilteredOverride = selectedFiltered.length > 0 && selectedFiltered.every(o => o.canOverrideConfig);
251
+ const resolvedParentOrg = react.useMemo(() => resolveCurrentOrgName({
252
+ parentOrgName,
253
+ organizationId,
254
+ orgList
255
+ }), [parentOrgName, organizationId, orgList]);
129
256
  const handleToggleSelectAll = (checked) => {
130
257
  const filteredIds = new Set(filtered.map(f => f.targetOrgId));
131
258
  const next = orgList.map(item => {
@@ -141,7 +268,10 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
141
268
  onChangeOrg(next);
142
269
  };
143
270
  const handleToggleAllOverride = (enable) => {
144
- const next = orgList.map(item => item.isSelected ? { ...item, canOverrideConfig: enable } : item);
271
+ const filteredIds = new Set(filtered.map(f => f.targetOrgId));
272
+ const next = orgList.map(item => item.isSelected && filteredIds.has(item.targetOrgId)
273
+ ? { ...item, canOverrideConfig: enable }
274
+ : item);
145
275
  onChangeOrg(next);
146
276
  };
147
277
  const handleSelectRow = (targetOrgId, checked) => {
@@ -176,11 +306,10 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
176
306
  {
177
307
  field: 'isSelected',
178
308
  headerText: '',
179
- width: 50,
180
- minWidth: 50,
181
- maxWidth: 50,
309
+ width: 44,
310
+ minWidth: 44,
311
+ maxWidth: 44,
182
312
  textAlign: 'center',
183
- fixedType: 'left',
184
313
  allowFiltering: false,
185
314
  allowSortering: false,
186
315
  allowResizing: false,
@@ -192,9 +321,8 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
192
321
  field: 'orgName',
193
322
  headerText: String(t('DataSharing_Organization', 'Đơn vị')),
194
323
  headerTooltip: String(t('DataSharing_Organization', 'Đơn vị')),
195
- width: 260,
196
- minWidth: 160,
197
- fixedType: 'left',
324
+ width: 420,
325
+ minWidth: 220,
198
326
  editEnable: false,
199
327
  template: (props) => (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("div", { className: "fw-bold", children: props.rowData?.orgName }), jsxRuntime.jsxs("span", { className: "text-muted small", children: ["(", props.rowData?.orgCode, ")"] })] }))
200
328
  },
@@ -227,11 +355,15 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
227
355
  field: 'canOverrideConfig',
228
356
  headerText: String(t('DataSharing_CanOverride', 'Cấu hình riêng')),
229
357
  headerTooltip: String(t('DataSharing_CanOverride', 'Cấu hình riêng')),
230
- width: 125,
231
- minWidth: 110,
358
+ width: 145,
359
+ minWidth: 120,
232
360
  textAlign: 'center',
233
361
  allowFiltering: false,
362
+ allowSortering: false,
234
363
  editEnable: false,
364
+ headerTemplate: () => (jsxRuntime.jsxs("div", { className: "d-flex align-items-center justify-content-center gap-1", onClick: e => e.stopPropagation(), children: [jsxRuntime.jsx(reactstrap.Input, { type: "checkbox", disabled: selectedFiltered.length === 0, checked: allFilteredOverride, title: String(allFilteredOverride
365
+ ? t('DataSharing_DisableAllOverride', 'Chỉ kế thừa gốc')
366
+ : t('DataSharing_EnableAllOverride', 'Cho phép tất cả cấu hình riêng')), onChange: e => handleToggleAllOverride(e.target.checked) }), jsxRuntime.jsx("span", { children: t('DataSharing_CanOverride', 'Cấu hình riêng') })] })),
235
367
  template: (props) => (jsxRuntime.jsx("div", { className: "form-check form-switch d-flex justify-content-center mb-0", onClick: e => e.stopPropagation(), children: jsxRuntime.jsx(reactstrap.Input, { type: "switch", disabled: !props.rowData?.isSelected, checked: Boolean(props.rowData?.canOverrideConfig), onChange: e => handleFieldChange(props.rowData?.targetOrgId, 'canOverrideConfig', e.target.checked) }) }))
236
368
  },
237
369
  {
@@ -269,8 +401,8 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
269
401
  editEnable: false,
270
402
  template: (props) => props.rowData?.isSelected ? (jsxRuntime.jsx("span", { className: "badge bg-light-success text-success", children: t('DataSharing_Sharing', 'Đang chia sẻ') })) : (jsxRuntime.jsx("span", { className: "badge bg-light-secondary text-secondary", children: t('DataSharing_NotShared', 'Chưa chia sẻ') }))
271
403
  }
272
- ], [allFilteredSelected, orgList, filtered, t]);
273
- return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t('DataSharing_OrgScope', 'Phạm vi chia sẻ xuống đơn vị') }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2 mt-1", children: [jsxRuntime.jsxs(reactstrap.Badge, { color: "light-primary", className: "text-primary", children: [t('DataSharing_Sharing', 'Đang chia sẻ'), ": ", selectedCount, "/", orgList.length] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "light-info", className: "text-info", children: [t('DataSharing_CanOverride', 'Cấu hình riêng'), ": ", overrideCount] })] })] }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-1", style: { minWidth: '280px' }, children: [jsxRuntime.jsx(reactstrap.Input, { type: "search", bsSize: "sm", placeholder: t('DataSharing_SearchOrg', 'Tìm kiếm đơn vị...'), value: search, onChange: e => setSearch(e.target.value) }), jsxRuntime.jsxs(reactstrap.Input, { type: "select", bsSize: "sm", style: { width: '125px' }, value: filterType, onChange: e => setFilterType(e.target.value), children: [jsxRuntime.jsx("option", { value: "ALL", children: t('DataSharing_All', 'Tất cả') }), jsxRuntime.jsx("option", { value: "C\u00F4ng ty", children: t('DataSharing_Company', 'Công ty') }), jsxRuntime.jsx("option", { value: "Chi nh\u00E1nh", children: t('DataSharing_Branch', 'Chi nhánh') })] })] })] }), (resolvedParentOrg || selectedCount > 0) && (jsxRuntime.jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center gap-2 mb-2", children: [jsxRuntime.jsx("div", { children: resolvedParentOrg && (jsxRuntime.jsxs("div", { className: "es-parent-org-pill", children: [jsxRuntime.jsxs("span", { className: "text-muted", children: [t('DataSharing_ParentOrg', 'Công ty mẹ'), ":"] }), jsxRuntime.jsxs("span", { className: "fw-bold text-primary", children: ["\uD83C\uDFE2 ", resolvedParentOrg] })] })) }), selectedCount > 0 && (jsxRuntime.jsxs("div", { className: "d-flex gap-2 ms-auto", children: [jsxRuntime.jsx(reactstrap.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') }), jsxRuntime.jsx(reactstrap.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') })] }))] })), jsxRuntime.jsx("div", { className: "flex-grow-1 es-data-sharing-grid-wrap", style: { minHeight: 0 }, children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: false, rowEditable: (rowData) => Boolean(rowData?.isSelected), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, onRowStyles: (rowData) => rowData?.isSelected ? { backgroundColor: 'rgba(115, 103, 240, 0.06)' } : {}, height: 360, allowResizing: true, t: t, showEmptyText: false }, "DataSharingOrgScopeGrid") })] }) }));
404
+ ], [allFilteredSelected, allFilteredOverride, selectedFiltered.length, orgList, filtered, t]);
405
+ return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t('DataSharing_OrgScope', 'Phạm vi chia sẻ xuống đơn vị') }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2 mt-1", children: [jsxRuntime.jsxs(reactstrap.Badge, { color: "light-primary", className: "es-badge-sharing", children: [t('DataSharing_Sharing', 'Đang chia sẻ'), ": ", selectedCount, "/", orgList.length] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "light-info", className: "es-badge-override", children: [t('DataSharing_CanOverride', 'Cấu hình riêng'), ": ", overrideCount] })] })] }), jsxRuntime.jsx("div", { className: "d-flex align-items-center es-org-search-wrap", style: { minWidth: '220px' }, children: jsxRuntime.jsx(reactstrap.Input, { type: "search", bsSize: "sm", placeholder: t('DataSharing_SearchOrg', 'Tìm kiếm đơn vị...'), value: search, onChange: e => setSearch(e.target.value) }) })] }), resolvedParentOrg && (jsxRuntime.jsx("div", { className: "mb-2", children: jsxRuntime.jsxs("div", { className: "es-parent-org-pill", children: [jsxRuntime.jsxs("span", { className: "text-muted", children: [parentOrgLabel ?? t('DataSharing_CurrentOrg', 'Công ty'), ":"] }), jsxRuntime.jsxs("span", { className: "fw-bold es-parent-org-name", children: ["\uD83C\uDFE2 ", resolvedParentOrg] })] }) })), jsxRuntime.jsx("div", { className: "flex-grow-1 es-data-sharing-grid-wrap", style: { minHeight: 0 }, children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: false, rowEditable: (rowData) => Boolean(rowData?.isSelected), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, onRowStyles: (rowData) => rowData?.isSelected ? { backgroundColor: 'rgba(242, 101, 34, 0.08)' } : {}, height: 360, allowResizing: true, t: t, showEmptyText: false }, "DataSharingOrgScopeGrid") })] }) }));
274
406
  };
275
407
 
276
408
  function resolveFieldDisplayValue(field, rowData, rawVal) {
@@ -433,7 +565,7 @@ const OverrideTable = ({ orgList, overrideColumns, masterData, onChangeOverride,
433
565
  }
434
566
  handleCallback(item, args.indexRow);
435
567
  };
436
- return (jsxRuntime.jsxs("div", { className: "es-data-sharing-override-table", children: [editableOrgs.length > 1 && onApplyFirstToAll && (jsxRuntime.jsx("div", { className: "d-flex justify-content-end mb-2", children: jsxRuntime.jsxs(reactstrap.Button, { 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 ? (jsxRuntime.jsx("div", { className: "border rounded text-center text-muted py-4 bg-light small", children: t('DataSharing_NoOrgSelected', 'Chưa có đơn vị nào được chọn chia sẻ ở bảng trên.') })) : (jsxRuntime.jsx("div", { className: "es-data-sharing-grid-wrap", children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: editableOrgs.length > 0, rowEditable: (rowData) => Boolean(rowData?._canOverrideConfig), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, height: 280, allowResizing: true, t: t, format: {
568
+ return (jsxRuntime.jsxs("div", { className: "es-data-sharing-override-table", children: [editableOrgs.length > 1 && onApplyFirstToAll && (jsxRuntime.jsx("div", { className: "d-flex justify-content-end mb-2", children: jsxRuntime.jsxs(reactstrap.Button, { type: "button", size: "sm", color: "light", className: "es-apply-first-btn d-inline-flex align-items-center gap-1", onClick: onApplyFirstToAll, children: [jsxRuntime.jsx(becoxyIcons.Copy, { fontSize: 14 }), jsxRuntime.jsx("span", { children: t('DataSharing_ApplyFirstToAll', 'Áp dụng cấu hình dòng đầu cho các đơn vị khác') })] }) })), selectedOrgs.length === 0 ? (jsxRuntime.jsx("div", { className: "border rounded text-center text-muted py-4 bg-light small", children: t('DataSharing_NoOrgSelected', 'Chưa có đơn vị nào được chọn chia sẻ ở bảng trên.') })) : (jsxRuntime.jsx("div", { className: "es-data-sharing-grid-wrap", children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: editableOrgs.length > 0, rowEditable: (rowData) => Boolean(rowData?._canOverrideConfig), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, height: 280, allowResizing: true, t: t, format: {
437
569
  decimalSeparator: '.',
438
570
  thousandSeparator: ',',
439
571
  decimalScale: 0
@@ -600,14 +732,13 @@ const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
600
732
  }, showEmptyText: false }, `DataSharingDetailGrid_${tabConfig.key}`) }));
601
733
  };
602
734
 
603
- 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 }) => {
735
+ 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 }) => {
604
736
  const { t } = reactI18next.useTranslation();
605
737
  const showMasterCard = propShowMasterCard ?? config.showMasterCard ?? true;
606
738
  const showOrgScope = propShowOrgScope ?? config.showOrgScope ?? true;
607
739
  const showConfigTabs = propShowConfigTabs ?? config.showConfigTabs ?? true;
608
740
  const showOverrideTab = propShowOverrideTab ?? config.showOverrideTab ?? true;
609
741
  const showSummaryTab = propShowSummaryTab ?? config.showSummaryTab ?? true;
610
- const showGlobalSharedSwitch = propShowGlobalSharedSwitch ?? config.showGlobalSharedSwitch ?? true;
611
742
  const detailTabs = config.detailTabs ?? [];
612
743
  const hasVisibleTabs = showConfigTabs && (showOverrideTab || detailTabs.length > 0 || showSummaryTab);
613
744
  const getFirstVisibleTab = () => {
@@ -633,7 +764,7 @@ const DataSharingContent = ({ config, masterData = {}, masterDataList = [], pare
633
764
  const showTopRow = showMasterCard || showOrgScope;
634
765
  const masterColMd = showOrgScope ? 5 : 12;
635
766
  const orgColMd = showMasterCard ? 7 : 12;
636
- return (jsxRuntime.jsxs("div", { className: "es-data-sharing-content", children: [showTopRow && (jsxRuntime.jsxs(reactstrap.Row, { className: hasVisibleTabs ? 'mb-3' : 'mb-0', children: [showMasterCard && (jsxRuntime.jsx(reactstrap.Col, { md: masterColMd, className: showOrgScope ? 'mb-2 mb-md-0' : '', children: isBatchMode ? (jsxRuntime.jsx(BatchMasterCard, { title: config.masterCardTitle ?? config.title, items: masterDataList, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) : (jsxRuntime.jsx(MasterCard, { title: config.masterCardTitle ?? config.title, fields: config.masterFields ?? [], data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) })), showOrgScope && (jsxRuntime.jsx(reactstrap.Col, { md: orgColMd, children: jsxRuntime.jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, parentOrgName: parentOrgName ?? config.parentOrgName }) }))] })), hasVisibleTabs && (jsxRuntime.jsxs("div", { className: "es-data-sharing-tabs-section", children: [jsxRuntime.jsxs(reactstrap.Nav, { tabs: true, className: "mb-2", children: [showOverrideTab && (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: ["\u2699\uFE0F ", t('DataSharing_OrgConfigTab', 'Cấu hình theo đơn vị'), selectedOrgs.length > 0 && (jsxRuntime.jsx(reactstrap.Badge, { color: "light-primary", className: "ms-1 text-primary", children: selectedOrgs.length }))] }) })), detailTabs.map(tab => {
767
+ return (jsxRuntime.jsxs("div", { className: "es-data-sharing-content", children: [showTopRow && (jsxRuntime.jsxs(reactstrap.Row, { className: hasVisibleTabs ? 'mb-3' : 'mb-0', children: [showMasterCard && (jsxRuntime.jsx(reactstrap.Col, { md: masterColMd, className: showOrgScope ? 'mb-2 mb-md-0' : '', children: isBatchMode ? (jsxRuntime.jsx(BatchMasterCard, { title: config.masterCardTitle ?? config.title, items: masterDataList, fields: config.masterFields ?? [] })) : (jsxRuntime.jsx(MasterCard, { title: config.masterCardTitle ?? config.title, fields: config.masterFields ?? [], data: masterData })) })), showOrgScope && (jsxRuntime.jsx(reactstrap.Col, { md: orgColMd, children: jsxRuntime.jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, parentOrgName: parentOrgName ?? config.parentOrgName, parentOrgLabel: config.parentOrgLabel, organizationId: config.organizationId }) }))] })), hasVisibleTabs && (jsxRuntime.jsxs("div", { className: "es-data-sharing-tabs-section", children: [jsxRuntime.jsxs(reactstrap.Nav, { tabs: true, className: "mb-2", children: [showOverrideTab && (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: ["\u2699\uFE0F ", t('DataSharing_OrgConfigTab', 'Cấu hình theo đơn vị'), selectedOrgs.length > 0 && (jsxRuntime.jsx(reactstrap.Badge, { color: "light-primary", className: "ms-1 text-primary", children: selectedOrgs.length }))] }) })), detailTabs.map(tab => {
637
768
  const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
638
769
  return (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === `detail:${tab.key}` }), onClick: () => setActiveTab(`detail:${tab.key}`), style: { cursor: 'pointer' }, children: [tab.icon ? `${tab.icon} ` : '📄 ', t(tab.title), jsxRuntime.jsx(reactstrap.Badge, { color: "light-info", className: "ms-1 text-info", children: activeCount })] }) }, tab.key));
639
770
  }), showSummaryTab && (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'summary' }), onClick: () => setActiveTab('summary'), style: { cursor: 'pointer' }, children: ["\uD83D\uDD52 ", t('DataSharing_SummaryTab', 'Tổng hợp phân quyền')] }) }))] }), jsxRuntime.jsxs(reactstrap.TabContent, { activeTab: activeTab, children: [showOverrideTab && (jsxRuntime.jsx(reactstrap.TabPane, { tabId: "override", children: jsxRuntime.jsx(OverrideTable, { orgList: orgList, overrideColumns: config.overrideColumns ?? [], masterData: isBatchMode ? undefined : masterData, onChangeOverride: onChangeOverride, onApplyFirstToAll: onApplyFirstToAll }) })), detailTabs.map(tab => (jsxRuntime.jsx(reactstrap.TabPane, { tabId: `detail:${tab.key}`, children: jsxRuntime.jsx(DetailTabTable, { tabConfig: tab, orgList: orgList, rows: detailData[tab.key] ?? [], onChangeRows: updatedRows => setDetailData(prev => ({
@@ -644,73 +775,7 @@ const DataSharingContent = ({ config, masterData = {}, masterDataList = [], pare
644
775
  : `${selectedOrgs.length} ${t('DataSharing_Organization', 'Đơn vị')}` })] }), jsxRuntime.jsxs("div", { className: "es-summary-item", children: [jsxRuntime.jsx("div", { className: "es-summary-label", children: t('DataSharing_SummaryOverride', 'Đơn vị cho phép cấu hình riêng') }), jsxRuntime.jsx("div", { className: "es-summary-value", children: selectedOrgs.filter(o => o.canOverrideConfig).length })] }), detailTabs.map(tab => (jsxRuntime.jsxs("div", { className: "es-summary-item", children: [jsxRuntime.jsx("div", { className: "es-summary-label", children: t(tab.title) }), jsxRuntime.jsx("div", { className: "es-summary-value", children: (detailData[tab.key] ?? []).filter(r => !r._deleted).length })] }, tab.key)))] })] }) }))] })] }))] }));
645
776
  };
646
777
 
647
- function applyGlobalSharedToOrgList(orgList, checked, sharingLabel) {
648
- if (!checked)
649
- return orgList;
650
- return orgList.map(o => ({
651
- ...o,
652
- isSelected: true,
653
- status: 1,
654
- statusText: sharingLabel
655
- }));
656
- }
657
- function updateOrgOverrideValue(orgList, targetOrgId, fieldKey, value) {
658
- return orgList.map(item => {
659
- if (item.targetOrgId !== targetOrgId)
660
- return item;
661
- return {
662
- ...item,
663
- overrideData: {
664
- ...item.overrideData,
665
- [fieldKey]: value
666
- }
667
- };
668
- });
669
- }
670
- function applyFirstOverrideToAll(orgList) {
671
- const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
672
- if (editableOrgs.length < 2)
673
- return orgList;
674
- const firstData = editableOrgs[0].overrideData ?? {};
675
- return orgList.map(item => {
676
- if (!item.isSelected || !item.canOverrideConfig)
677
- return item;
678
- return {
679
- ...item,
680
- overrideData: {
681
- ...firstData
682
- }
683
- };
684
- });
685
- }
686
- function buildDataSharingPayload(params) {
687
- const { config, entityId, entityIds, isGlobalShared, orgList, detailData } = params;
688
- const isBatchMode = (entityIds?.length ?? 0) > 1;
689
- const detailTabs = config.detailTabs ?? [];
690
- return {
691
- entityType: config.entityType,
692
- entityId,
693
- ...(isBatchMode ? { entityIds } : {}),
694
- isGlobalShared,
695
- sharingList: orgList.map(o => ({
696
- TargetOrgId: o.targetOrgId,
697
- IsInheritMaster: o.isInheritMaster,
698
- CanOverrideConfig: o.canOverrideConfig,
699
- EffectiveFrom: o.effectiveFrom || null,
700
- EffectiveTo: o.effectiveTo || null,
701
- Status: o.isSelected ? 1 : 0
702
- })),
703
- orgConfigList: orgList
704
- .filter(o => o.isSelected && o.canOverrideConfig)
705
- .map(o => ({
706
- OrganizationId: o.targetOrgId,
707
- ...o.overrideData
708
- })),
709
- ...(detailTabs.length > 0 ? { detailData } : {})
710
- };
711
- }
712
-
713
- 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 }) => {
778
+ const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList = [], parentOrgName, entityId, entityIds, orgList, setOrgList, detailData, setDetailData, isGlobalShared, setIsGlobalShared, onSave, loading = false, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab }) => {
714
779
  const { t } = reactI18next.useTranslation();
715
780
  const [saving, setSaving] = react.useState(false);
716
781
  const isBatchMode = (entityIds?.length ?? 0) > 1;
@@ -743,10 +808,10 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList =
743
808
  setSaving(false);
744
809
  }
745
810
  };
746
- return (jsxRuntime.jsxs(reactstrap.Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsxRuntime.jsx(reactstrap.ModalHeader, { toggle: toggle, children: jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("span", { className: "me-2 es-data-sharing-header-icon", children: "\uD83D\uDD17" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2", children: [jsxRuntime.jsx("h4", { className: "mb-0 fw-bolder", children: t(config.title) }), isBatchMode && (jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", children: [t('DataSharing_BatchSharing', 'Chia sẻ hàng loạt'), " (", entityIds?.length, ")"] }))] }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_Subtitle', 'Quản lý chia sẻ dữ liệu và phân quyền theo đơn vị thành viên') })] })] }) }), jsxRuntime.jsx(reactstrap.ModalBody, { children: loading ? (jsxRuntime.jsxs("div", { className: "text-center py-5", children: [jsxRuntime.jsx("div", { className: "spinner-border text-primary", role: "status", children: jsxRuntime.jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsxRuntime.jsx("div", { className: "mt-2 text-muted", children: t('DataSharing_Loading', 'Đang tải dữ liệu chia sẻ...') })] })) : (jsxRuntime.jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab, showGlobalSharedSwitch: showGlobalSharedSwitch })) }), jsxRuntime.jsxs(reactstrap.ModalFooter, { children: [jsxRuntime.jsx(reactstrap.Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? t('DataSharing_Saving', 'Đang lưu...') : t('DataSharing_Save', 'Cập nhật chia sẻ') }), jsxRuntime.jsx(reactstrap.Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') })] })] }));
811
+ return (jsxRuntime.jsxs(reactstrap.Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsxRuntime.jsx(reactstrap.ModalHeader, { toggle: toggle, children: jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("span", { className: "me-2 es-data-sharing-header-icon", children: "\uD83D\uDD17" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2", children: [jsxRuntime.jsx("h4", { className: "mb-0 fw-bolder", children: t(config.title) }), isBatchMode && (jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", className: "es-batch-badge", children: [t('DataSharing_BatchSharing', 'Chia sẻ hàng loạt'), " (", entityIds?.length, ")"] }))] }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_Subtitle', 'Quản lý chia sẻ dữ liệu và phân quyền theo đơn vị thành viên') })] })] }) }), jsxRuntime.jsx(reactstrap.ModalBody, { children: loading ? (jsxRuntime.jsxs("div", { className: "text-center py-5", children: [jsxRuntime.jsx("div", { className: "spinner-border text-primary", role: "status", children: jsxRuntime.jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsxRuntime.jsx("div", { className: "mt-2 text-muted", children: t('DataSharing_Loading', 'Đang tải dữ liệu chia sẻ...') })] })) : (jsxRuntime.jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab })) }), jsxRuntime.jsxs(reactstrap.ModalFooter, { children: [jsxRuntime.jsx(reactstrap.Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? t('DataSharing_Saving', 'Đang lưu...') : t('DataSharing_Save', 'Cập nhật chia sẻ') }), jsxRuntime.jsx(reactstrap.Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') })] })] }));
747
812
  };
748
813
 
749
- const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, onChangeOrgList, detailData: controlledDetailData, onChangeDetailData, isGlobalShared: controlledGlobalShared = false, onChangeGlobalShared, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }) => {
814
+ const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, onChangeOrgList, detailData: controlledDetailData, onChangeDetailData, isGlobalShared: controlledGlobalShared = false, onChangeGlobalShared, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab }) => {
750
815
  const { t } = reactI18next.useTranslation();
751
816
  const [internalDetailData, setInternalDetailData] = react.useState({});
752
817
  const detailData = controlledDetailData ?? internalDetailData;
@@ -762,9 +827,9 @@ const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parent
762
827
  const handleApplyFirstToAll = () => {
763
828
  onChangeOrgList(prev => applyFirstOverrideToAll(prev));
764
829
  };
765
- return (jsxRuntime.jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: onChangeOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: controlledGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab, showGlobalSharedSwitch: showGlobalSharedSwitch }));
830
+ return (jsxRuntime.jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: onChangeOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: controlledGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab }));
766
831
  };
767
- const DataSharingComponent = react.forwardRef(({ database, parentOrgName, fetchSharingData, onSave, onSuccess, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }, ref) => {
832
+ const DataSharingComponent = react.forwardRef(({ database, parentOrgName, fetchSharingData, onSave, onSuccess, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab }, ref) => {
768
833
  const [isOpen, setIsOpen] = react.useState(false);
769
834
  const [loading, setLoading] = react.useState(false);
770
835
  const [config, setConfig] = react.useState(null);
@@ -788,7 +853,7 @@ const DataSharingComponent = react.forwardRef(({ database, parentOrgName, fetchS
788
853
  setConfig(params.config);
789
854
  setMasterData(params.masterData ?? params.masterDataList?.[0] ?? {});
790
855
  setMasterDataList(params.masterDataList ?? (params.masterData ? [params.masterData] : []));
791
- setActiveParentOrgName(params.parentOrgName ?? parentOrgName);
856
+ setActiveParentOrgName(params.parentOrgName ?? params.config?.parentOrgName ?? parentOrgName);
792
857
  setEntityId(primaryEntityId);
793
858
  setEntityIds(isBatch ? ids : undefined);
794
859
  setActiveDatabase(targetDb);
@@ -799,14 +864,17 @@ const DataSharingComponent = react.forwardRef(({ database, parentOrgName, fetchS
799
864
  showOrgScope: params.showOrgScope,
800
865
  showConfigTabs: params.showConfigTabs,
801
866
  showOverrideTab: params.showOverrideTab,
802
- showSummaryTab: params.showSummaryTab,
803
- showGlobalSharedSwitch: params.showGlobalSharedSwitch
867
+ showSummaryTab: params.showSummaryTab
804
868
  });
805
869
  if (fetchSharingData && primaryEntityId) {
806
870
  setLoading(true);
807
871
  try {
808
872
  const res = await fetchSharingData(params.entityType, primaryEntityId, targetDb);
809
- if (res.parentOrgName) {
873
+ if (!params.parentOrgName &&
874
+ !params.config?.parentOrgName &&
875
+ !params.config?.organizationId &&
876
+ !parentOrgName &&
877
+ res.parentOrgName) {
810
878
  setActiveParentOrgName(res.parentOrgName);
811
879
  }
812
880
  if (isBatch) {
@@ -850,7 +918,7 @@ const DataSharingComponent = react.forwardRef(({ database, parentOrgName, fetchS
850
918
  onSuccess();
851
919
  }
852
920
  };
853
- return (jsxRuntime.jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: activeParentOrgName ?? parentOrgName, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading, showMasterCard: openVisibility.showMasterCard ?? showMasterCard, showOrgScope: openVisibility.showOrgScope ?? showOrgScope, showConfigTabs: openVisibility.showConfigTabs ?? showConfigTabs, showOverrideTab: openVisibility.showOverrideTab ?? showOverrideTab, showSummaryTab: openVisibility.showSummaryTab ?? showSummaryTab, showGlobalSharedSwitch: openVisibility.showGlobalSharedSwitch ?? showGlobalSharedSwitch }));
921
+ return (jsxRuntime.jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: activeParentOrgName ?? parentOrgName, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading, showMasterCard: openVisibility.showMasterCard ?? showMasterCard, showOrgScope: openVisibility.showOrgScope ?? showOrgScope, showConfigTabs: openVisibility.showConfigTabs ?? showConfigTabs, showOverrideTab: openVisibility.showOverrideTab ?? showOverrideTab, showSummaryTab: openVisibility.showSummaryTab ?? showSummaryTab }));
854
922
  });
855
923
 
856
924
  exports.BatchMasterCard = BatchMasterCard;