@esvndev/es-data-sharing 1.3.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,
@@ -120,14 +248,11 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
120
248
  const allFilteredSelected = filtered.length > 0 && filtered.every(o => o.isSelected);
121
249
  const selectedFiltered = filtered.filter(o => o.isSelected);
122
250
  const allFilteredOverride = selectedFiltered.length > 0 && selectedFiltered.every(o => o.canOverrideConfig);
123
- const resolvedParentOrg = react.useMemo(() => {
124
- if (parentOrgName)
125
- return parentOrgName;
126
- const rootOrg = orgList.find(o => !o.parentId);
127
- if (!rootOrg)
128
- return '';
129
- return rootOrg.orgCode ? `${rootOrg.orgName} (${rootOrg.orgCode})` : rootOrg.orgName;
130
- }, [parentOrgName, orgList]);
251
+ const resolvedParentOrg = react.useMemo(() => resolveCurrentOrgName({
252
+ parentOrgName,
253
+ organizationId,
254
+ orgList
255
+ }), [parentOrgName, organizationId, orgList]);
131
256
  const handleToggleSelectAll = (checked) => {
132
257
  const filteredIds = new Set(filtered.map(f => f.targetOrgId));
133
258
  const next = orgList.map(item => {
@@ -277,7 +402,7 @@ const OrgTable = ({ orgList, onChangeOrg, parentOrgName }) => {
277
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ẻ') }))
278
403
  }
279
404
  ], [allFilteredSelected, allFilteredOverride, selectedFiltered.length, orgList, filtered, t]);
280
- return (jsxRuntime.jsx(reactstrap.Card, { className: "border h-100 shadow-none mb-0 es-data-sharing-org-scope", children: jsxRuntime.jsxs(reactstrap.CardBody, { className: "d-flex flex-column", children: [jsxRuntime.jsxs("div", { className: "d-flex flex-wrap justify-content-between align-items-center mb-2 gap-2", children: [jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("h5", { className: "mb-0 fw-bolder", children: t('DataSharing_OrgScope', 'Phạm vi chia sẻ xuống đơn vị') }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2 mt-1", children: [jsxRuntime.jsxs(reactstrap.Badge, { color: "light-primary", className: "text-primary", children: [t('DataSharing_Sharing', 'Đang chia sẻ'), ": ", selectedCount, "/", orgList.length] }), jsxRuntime.jsxs(reactstrap.Badge, { color: "light-info", className: "text-info", children: [t('DataSharing_CanOverride', 'Cấu hình riêng'), ": ", overrideCount] })] })] }), jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-1", style: { minWidth: '280px' }, children: [jsxRuntime.jsx(reactstrap.Input, { type: "search", bsSize: "sm", placeholder: t('DataSharing_SearchOrg', 'Tìm kiếm đơn vị...'), value: search, onChange: e => setSearch(e.target.value) }), jsxRuntime.jsxs(reactstrap.Input, { type: "select", bsSize: "sm", style: { width: '125px' }, value: filterType, onChange: e => setFilterType(e.target.value), children: [jsxRuntime.jsx("option", { value: "ALL", children: t('DataSharing_All', 'Tất cả') }), jsxRuntime.jsx("option", { value: "C\u00F4ng ty", children: t('DataSharing_Company', 'Công ty') }), jsxRuntime.jsx("option", { value: "Chi nh\u00E1nh", children: t('DataSharing_Branch', 'Chi nhánh') })] })] })] }), resolvedParentOrg && (jsxRuntime.jsx("div", { className: "mb-2", children: jsxRuntime.jsxs("div", { className: "es-parent-org-pill", children: [jsxRuntime.jsxs("span", { className: "text-muted", children: [t('DataSharing_ParentOrg', 'Công ty mẹ'), ":"] }), jsxRuntime.jsxs("span", { className: "fw-bold text-primary", children: ["\uD83C\uDFE2 ", resolvedParentOrg] })] }) })), jsxRuntime.jsx("div", { className: "flex-grow-1 es-data-sharing-grid-wrap", style: { minHeight: 0 }, children: jsxRuntime.jsx(esGridTemplate.GridComponent, { dataSource: gridDataSource, editAble: false, rowEditable: (rowData) => Boolean(rowData?.isSelected), lang: i18n.language || 'vi', showToolbar: false, toolbarItems: [], columns: headerColumns, onCellChange: handleCellChange, onRowStyles: (rowData) => rowData?.isSelected ? { backgroundColor: 'rgba(115, 103, 240, 0.06)' } : {}, height: 360, allowResizing: true, t: t, showEmptyText: false }, "DataSharingOrgScopeGrid") })] }) }));
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") })] }) }));
281
406
  };
282
407
 
283
408
  function resolveFieldDisplayValue(field, rowData, rawVal) {
@@ -607,14 +732,13 @@ const DetailTabTable = ({ tabConfig, orgList, rows, onChangeRows }) => {
607
732
  }, showEmptyText: false }, `DataSharingDetailGrid_${tabConfig.key}`) }));
608
733
  };
609
734
 
610
- const DataSharingContent = ({ config, masterData = {}, masterDataList = [], parentOrgName, isBatchMode = false, orgList, setOrgList, detailData, setDetailData, isGlobalShared, onToggleGlobalShared, onChangeOverride, onApplyFirstToAll, showMasterCard: propShowMasterCard, showOrgScope: propShowOrgScope, showConfigTabs: propShowConfigTabs, showOverrideTab: propShowOverrideTab, showSummaryTab: propShowSummaryTab, showGlobalSharedSwitch: propShowGlobalSharedSwitch }) => {
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 }) => {
611
736
  const { t } = reactI18next.useTranslation();
612
737
  const showMasterCard = propShowMasterCard ?? config.showMasterCard ?? true;
613
738
  const showOrgScope = propShowOrgScope ?? config.showOrgScope ?? true;
614
739
  const showConfigTabs = propShowConfigTabs ?? config.showConfigTabs ?? true;
615
740
  const showOverrideTab = propShowOverrideTab ?? config.showOverrideTab ?? true;
616
741
  const showSummaryTab = propShowSummaryTab ?? config.showSummaryTab ?? true;
617
- const showGlobalSharedSwitch = propShowGlobalSharedSwitch ?? config.showGlobalSharedSwitch ?? true;
618
742
  const detailTabs = config.detailTabs ?? [];
619
743
  const hasVisibleTabs = showConfigTabs && (showOverrideTab || detailTabs.length > 0 || showSummaryTab);
620
744
  const getFirstVisibleTab = () => {
@@ -640,7 +764,7 @@ const DataSharingContent = ({ config, masterData = {}, masterDataList = [], pare
640
764
  const showTopRow = showMasterCard || showOrgScope;
641
765
  const masterColMd = showOrgScope ? 5 : 12;
642
766
  const orgColMd = showMasterCard ? 7 : 12;
643
- return (jsxRuntime.jsxs("div", { className: "es-data-sharing-content", children: [showTopRow && (jsxRuntime.jsxs(reactstrap.Row, { className: hasVisibleTabs ? 'mb-3' : 'mb-0', children: [showMasterCard && (jsxRuntime.jsx(reactstrap.Col, { md: masterColMd, className: showOrgScope ? 'mb-2 mb-md-0' : '', children: isBatchMode ? (jsxRuntime.jsx(BatchMasterCard, { title: config.masterCardTitle ?? config.title, items: masterDataList, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) : (jsxRuntime.jsx(MasterCard, { title: config.masterCardTitle ?? config.title, fields: config.masterFields ?? [], data: masterData, isGlobalShared: isGlobalShared, onToggleGlobalShared: onToggleGlobalShared, showGlobalSharedSwitch: showGlobalSharedSwitch })) })), showOrgScope && (jsxRuntime.jsx(reactstrap.Col, { md: orgColMd, children: jsxRuntime.jsx(OrgTable, { orgList: orgList, onChangeOrg: setOrgList, parentOrgName: parentOrgName ?? config.parentOrgName }) }))] })), hasVisibleTabs && (jsxRuntime.jsxs("div", { className: "es-data-sharing-tabs-section", children: [jsxRuntime.jsxs(reactstrap.Nav, { tabs: true, className: "mb-2", children: [showOverrideTab && (jsxRuntime.jsx(reactstrap.NavItem, { children: jsxRuntime.jsxs(reactstrap.NavLink, { className: classnames({ active: activeTab === 'override' }), onClick: () => setActiveTab('override'), style: { cursor: 'pointer' }, children: ["\u2699\uFE0F ", t('DataSharing_OrgConfigTab', 'Cấu hình theo đơn vị'), selectedOrgs.length > 0 && (jsxRuntime.jsx(reactstrap.Badge, { color: "light-primary", className: "ms-1 text-primary", children: selectedOrgs.length }))] }) })), detailTabs.map(tab => {
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 => {
644
768
  const activeCount = (detailData[tab.key] ?? []).filter(r => !r._deleted).length;
645
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));
646
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 => ({
@@ -651,73 +775,7 @@ const DataSharingContent = ({ config, masterData = {}, masterDataList = [], pare
651
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)))] })] }) }))] })] }))] }));
652
776
  };
653
777
 
654
- function applyGlobalSharedToOrgList(orgList, checked, sharingLabel) {
655
- if (!checked)
656
- return orgList;
657
- return orgList.map(o => ({
658
- ...o,
659
- isSelected: true,
660
- status: 1,
661
- statusText: sharingLabel
662
- }));
663
- }
664
- function updateOrgOverrideValue(orgList, targetOrgId, fieldKey, value) {
665
- return orgList.map(item => {
666
- if (item.targetOrgId !== targetOrgId)
667
- return item;
668
- return {
669
- ...item,
670
- overrideData: {
671
- ...item.overrideData,
672
- [fieldKey]: value
673
- }
674
- };
675
- });
676
- }
677
- function applyFirstOverrideToAll(orgList) {
678
- const editableOrgs = orgList.filter(o => o.isSelected && o.canOverrideConfig);
679
- if (editableOrgs.length < 2)
680
- return orgList;
681
- const firstData = editableOrgs[0].overrideData ?? {};
682
- return orgList.map(item => {
683
- if (!item.isSelected || !item.canOverrideConfig)
684
- return item;
685
- return {
686
- ...item,
687
- overrideData: {
688
- ...firstData
689
- }
690
- };
691
- });
692
- }
693
- function buildDataSharingPayload(params) {
694
- const { config, entityId, entityIds, isGlobalShared, orgList, detailData } = params;
695
- const isBatchMode = (entityIds?.length ?? 0) > 1;
696
- const detailTabs = config.detailTabs ?? [];
697
- return {
698
- entityType: config.entityType,
699
- entityId,
700
- ...(isBatchMode ? { entityIds } : {}),
701
- isGlobalShared,
702
- sharingList: orgList.map(o => ({
703
- TargetOrgId: o.targetOrgId,
704
- IsInheritMaster: o.isInheritMaster,
705
- CanOverrideConfig: o.canOverrideConfig,
706
- EffectiveFrom: o.effectiveFrom || null,
707
- EffectiveTo: o.effectiveTo || null,
708
- Status: o.isSelected ? 1 : 0
709
- })),
710
- orgConfigList: orgList
711
- .filter(o => o.isSelected && o.canOverrideConfig)
712
- .map(o => ({
713
- OrganizationId: o.targetOrgId,
714
- ...o.overrideData
715
- })),
716
- ...(detailTabs.length > 0 ? { detailData } : {})
717
- };
718
- }
719
-
720
- const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList = [], parentOrgName, entityId, entityIds, orgList, setOrgList, detailData, setDetailData, isGlobalShared, setIsGlobalShared, onSave, loading = false, showMasterCard, showOrgScope, showConfigTabs, showOverrideTab, showSummaryTab, showGlobalSharedSwitch }) => {
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 }) => {
721
779
  const { t } = reactI18next.useTranslation();
722
780
  const [saving, setSaving] = react.useState(false);
723
781
  const isBatchMode = (entityIds?.length ?? 0) > 1;
@@ -750,10 +808,10 @@ const ModalSharingView = ({ isOpen, toggle, config, masterData, masterDataList =
750
808
  setSaving(false);
751
809
  }
752
810
  };
753
- return (jsxRuntime.jsxs(reactstrap.Modal, { isOpen: isOpen, toggle: toggle, className: "modal-dialog-centered modal-xl es-data-sharing-modal", children: [jsxRuntime.jsx(reactstrap.ModalHeader, { toggle: toggle, children: jsxRuntime.jsxs("div", { className: "d-flex align-items-center", children: [jsxRuntime.jsx("span", { className: "me-2 es-data-sharing-header-icon", children: "\uD83D\uDD17" }), jsxRuntime.jsxs("div", { children: [jsxRuntime.jsxs("div", { className: "d-flex align-items-center gap-2", children: [jsxRuntime.jsx("h4", { className: "mb-0 fw-bolder", children: t(config.title) }), isBatchMode && (jsxRuntime.jsxs(reactstrap.Badge, { color: "primary", children: [t('DataSharing_BatchSharing', 'Chia sẻ hàng loạt'), " (", entityIds?.length, ")"] }))] }), jsxRuntime.jsx("small", { className: "text-muted", children: t('DataSharing_Subtitle', 'Quản lý chia sẻ dữ liệu và phân quyền theo đơn vị thành viên') })] })] }) }), jsxRuntime.jsx(reactstrap.ModalBody, { children: loading ? (jsxRuntime.jsxs("div", { className: "text-center py-5", children: [jsxRuntime.jsx("div", { className: "spinner-border text-primary", role: "status", children: jsxRuntime.jsx("span", { className: "visually-hidden", children: "Loading..." }) }), jsxRuntime.jsx("div", { className: "mt-2 text-muted", children: t('DataSharing_Loading', 'Đang tải dữ liệu chia sẻ...') })] })) : (jsxRuntime.jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab, showGlobalSharedSwitch: showGlobalSharedSwitch })) }), jsxRuntime.jsxs(reactstrap.ModalFooter, { children: [jsxRuntime.jsx(reactstrap.Button, { color: "primary", onClick: handleSubmit, disabled: saving || loading, children: saving ? t('DataSharing_Saving', 'Đang lưu...') : t('DataSharing_Save', 'Cập nhật chia sẻ') }), jsxRuntime.jsx(reactstrap.Button, { color: "secondary", outline: true, onClick: toggle, disabled: saving || loading, children: t('DataSharing_Cancel', 'Hủy') })] })] }));
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') })] })] }));
754
812
  };
755
813
 
756
- 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 }) => {
757
815
  const { t } = reactI18next.useTranslation();
758
816
  const [internalDetailData, setInternalDetailData] = react.useState({});
759
817
  const detailData = controlledDetailData ?? internalDetailData;
@@ -769,9 +827,9 @@ const DataSharingPanel = ({ config, masterData = {}, masterDataList = [], parent
769
827
  const handleApplyFirstToAll = () => {
770
828
  onChangeOrgList(prev => applyFirstOverrideToAll(prev));
771
829
  };
772
- return (jsxRuntime.jsx(DataSharingContent, { config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: parentOrgName, isBatchMode: isBatchMode, orgList: orgList, setOrgList: onChangeOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: controlledGlobalShared, onToggleGlobalShared: handleToggleGlobalShared, onChangeOverride: handleChangeOverride, onApplyFirstToAll: handleApplyFirstToAll, showMasterCard: showMasterCard, showOrgScope: showOrgScope, showConfigTabs: showConfigTabs, showOverrideTab: showOverrideTab, showSummaryTab: showSummaryTab, showGlobalSharedSwitch: showGlobalSharedSwitch }));
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 }));
773
831
  };
774
- 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) => {
775
833
  const [isOpen, setIsOpen] = react.useState(false);
776
834
  const [loading, setLoading] = react.useState(false);
777
835
  const [config, setConfig] = react.useState(null);
@@ -795,7 +853,7 @@ const DataSharingComponent = react.forwardRef(({ database, parentOrgName, fetchS
795
853
  setConfig(params.config);
796
854
  setMasterData(params.masterData ?? params.masterDataList?.[0] ?? {});
797
855
  setMasterDataList(params.masterDataList ?? (params.masterData ? [params.masterData] : []));
798
- setActiveParentOrgName(params.parentOrgName ?? parentOrgName);
856
+ setActiveParentOrgName(params.parentOrgName ?? params.config?.parentOrgName ?? parentOrgName);
799
857
  setEntityId(primaryEntityId);
800
858
  setEntityIds(isBatch ? ids : undefined);
801
859
  setActiveDatabase(targetDb);
@@ -806,14 +864,17 @@ const DataSharingComponent = react.forwardRef(({ database, parentOrgName, fetchS
806
864
  showOrgScope: params.showOrgScope,
807
865
  showConfigTabs: params.showConfigTabs,
808
866
  showOverrideTab: params.showOverrideTab,
809
- showSummaryTab: params.showSummaryTab,
810
- showGlobalSharedSwitch: params.showGlobalSharedSwitch
867
+ showSummaryTab: params.showSummaryTab
811
868
  });
812
869
  if (fetchSharingData && primaryEntityId) {
813
870
  setLoading(true);
814
871
  try {
815
872
  const res = await fetchSharingData(params.entityType, primaryEntityId, targetDb);
816
- if (res.parentOrgName) {
873
+ if (!params.parentOrgName &&
874
+ !params.config?.parentOrgName &&
875
+ !params.config?.organizationId &&
876
+ !parentOrgName &&
877
+ res.parentOrgName) {
817
878
  setActiveParentOrgName(res.parentOrgName);
818
879
  }
819
880
  if (isBatch) {
@@ -857,7 +918,7 @@ const DataSharingComponent = react.forwardRef(({ database, parentOrgName, fetchS
857
918
  onSuccess();
858
919
  }
859
920
  };
860
- return (jsxRuntime.jsx(ModalSharingView, { isOpen: isOpen, toggle: () => setIsOpen(false), config: config, masterData: masterData, masterDataList: masterDataList, parentOrgName: activeParentOrgName ?? parentOrgName, entityId: entityId, entityIds: entityIds, orgList: orgList, setOrgList: setOrgList, detailData: detailData, setDetailData: setDetailData, isGlobalShared: isGlobalShared, setIsGlobalShared: setIsGlobalShared, onSave: handleSave, loading: loading, showMasterCard: openVisibility.showMasterCard ?? showMasterCard, showOrgScope: openVisibility.showOrgScope ?? showOrgScope, showConfigTabs: openVisibility.showConfigTabs ?? showConfigTabs, showOverrideTab: openVisibility.showOverrideTab ?? showOverrideTab, showSummaryTab: openVisibility.showSummaryTab ?? showSummaryTab, showGlobalSharedSwitch: openVisibility.showGlobalSharedSwitch ?? showGlobalSharedSwitch }));
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 }));
861
922
  });
862
923
 
863
924
  exports.BatchMasterCard = BatchMasterCard;