@esvndev/es-data-sharing 0.0.0-stage → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +60 -2
- package/dist/component/common/dynamic-field-input.d.ts +11 -0
- package/dist/component/common/grid-column-builder.d.ts +10 -0
- package/dist/component/master-info/master-card.d.ts +11 -0
- package/dist/component/modal/batch-master-card.d.ts +9 -0
- package/dist/component/modal/index.d.ts +22 -0
- package/dist/component/modal/modal-sharing.d.ts +21 -0
- package/dist/component/org-detail/detail-tab-table.d.ts +10 -0
- package/dist/component/org-override/override-table.d.ts +11 -0
- package/dist/component/org-scope/org-table.d.ts +9 -0
- package/dist/index.d.ts +113 -0
- package/dist/index.js +644 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +642 -0
- package/dist/index.mjs.map +1 -0
- package/dist/styles/index.css +34 -0
- package/dist/styles/index.css.map +1 -0
- package/dist/styles/modal.css +10 -0
- package/dist/styles/modal.css.map +1 -0
- package/dist/types/index.d.ts +89 -0
- package/package.json +59 -4
package/README.md
CHANGED
|
@@ -1,3 +1,61 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @esvndev/es-data-sharing
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Module chia sẻ dữ liệu (Data Sharing) và cấu hình theo đơn vị thành viên dùng chung cho toàn bộ hệ thống ERP Becoxy (PO, SO, WMS, MES, HRM...).
|
|
4
|
+
|
|
5
|
+
## Cài đặt và sử dụng
|
|
6
|
+
|
|
7
|
+
### 1. Build package
|
|
8
|
+
```bash
|
|
9
|
+
cd D:\Becoxy\es-data-sharing
|
|
10
|
+
npm install
|
|
11
|
+
npm run build
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
### 2. Sử dụng trong React Component
|
|
15
|
+
```tsx
|
|
16
|
+
import React, { useRef } from 'react';
|
|
17
|
+
import DataSharingComponent, {
|
|
18
|
+
IFDataSharingRef,
|
|
19
|
+
ISharingMetadataConfig
|
|
20
|
+
} from '@esvndev/es-data-sharing';
|
|
21
|
+
|
|
22
|
+
const sharingConfig: ISharingMetadataConfig = {
|
|
23
|
+
entityType: 'SUPPLIER',
|
|
24
|
+
title: 'Chia sẻ Nhà cung cấp',
|
|
25
|
+
masterCardTitle: 'Thông tin nhà cung cấp gốc',
|
|
26
|
+
masterFields: [
|
|
27
|
+
{ key: 'Code', label: 'Mã nhà cung cấp', required: true },
|
|
28
|
+
{ key: 'Name', label: 'Tên nhà cung cấp', required: true }
|
|
29
|
+
],
|
|
30
|
+
overrideColumns: [
|
|
31
|
+
{ key: 'VendorCode', label: 'Mã NCC nội bộ', type: 'text' },
|
|
32
|
+
{ key: 'DebtDay', label: 'Số ngày nợ', type: 'number' }
|
|
33
|
+
]
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const MyComponent = () => {
|
|
37
|
+
const sharingRef = useRef<IFDataSharingRef>(null);
|
|
38
|
+
|
|
39
|
+
const handleOpenSharing = (rowData: any) => {
|
|
40
|
+
sharingRef.current?.open({
|
|
41
|
+
entityType: 'SUPPLIER',
|
|
42
|
+
entityId: rowData.id,
|
|
43
|
+
masterData: rowData,
|
|
44
|
+
config: sharingConfig
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<>
|
|
50
|
+
<button onClick={() => handleOpenSharing(row)}>Chia sẻ</button>
|
|
51
|
+
<DataSharingComponent
|
|
52
|
+
ref={sharingRef}
|
|
53
|
+
onSave={async (payload) => {
|
|
54
|
+
// Gọi API Backend lưu Sys_DataSharing và ObjectOrg
|
|
55
|
+
console.log('Lưu payload:', payload);
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
</>
|
|
59
|
+
);
|
|
60
|
+
};
|
|
61
|
+
```
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ISharingFieldDef } from '../../types';
|
|
3
|
+
interface Props {
|
|
4
|
+
field: ISharingFieldDef;
|
|
5
|
+
value: any;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
placeholder?: string;
|
|
8
|
+
onChange: (val: any, selectedOption?: any) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const DynamicFieldInput: React.FC<Props>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ColumnTable } from 'es-grid-template';
|
|
3
|
+
import { ISharingFieldDef } from '../../types';
|
|
4
|
+
export interface BuildGridColumnOptions {
|
|
5
|
+
t: (key: string, fallback?: any) => any;
|
|
6
|
+
isFieldEditable?: (field: ISharingFieldDef, rowData: any) => boolean;
|
|
7
|
+
formatDisplayValue?: (field: ISharingFieldDef, rowData: any, resolvedDisplay: any) => React.ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare function resolveFieldDisplayValue(field: ISharingFieldDef, rowData: Record<string, any> | undefined, rawVal: any): any;
|
|
10
|
+
export declare function buildGridColumns(fields: ISharingFieldDef[], options: BuildGridColumnOptions): ColumnTable<any>[];
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ISharingFieldDef } from '../../types';
|
|
3
|
+
interface Props {
|
|
4
|
+
title: string;
|
|
5
|
+
fields: ISharingFieldDef[];
|
|
6
|
+
data: Record<string, any>;
|
|
7
|
+
isGlobalShared: boolean;
|
|
8
|
+
onToggleGlobalShared: (val: boolean) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const MasterCard: React.FC<Props>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IOrgSharingItem, IFDataSharingOpenParams, IDataSharingPayload } from '../../types';
|
|
3
|
+
export interface IFDataSharingRef {
|
|
4
|
+
open: (params: IFDataSharingOpenParams) => void;
|
|
5
|
+
close: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface IFDataSharingProps {
|
|
8
|
+
/** Tên DB dự án cho môi trường Test (ví dụ: process.env.REACT_APP_SHARING_DATABASE). Trên Cloud để trống để API tự lấy theo JWT claim "data". */
|
|
9
|
+
database?: string;
|
|
10
|
+
/** Function gọi lấy dữ liệu chia sẻ + cấu hình đơn vị + detailData (như ObjectBank) */
|
|
11
|
+
fetchSharingData?: (entityType: string, entityId: string, database?: string) => Promise<{
|
|
12
|
+
isGlobalShared: boolean;
|
|
13
|
+
orgList: IOrgSharingItem[];
|
|
14
|
+
detailData?: Record<string, Record<string, any>[]>;
|
|
15
|
+
}>;
|
|
16
|
+
/** Function callback lưu dữ liệu */
|
|
17
|
+
onSave?: (payload: IDataSharingPayload) => Promise<void>;
|
|
18
|
+
/** Callback sau khi lưu thành công */
|
|
19
|
+
onSuccess?: () => void;
|
|
20
|
+
}
|
|
21
|
+
declare const DataSharingComponent: React.ForwardRefExoticComponent<IFDataSharingProps & React.RefAttributes<IFDataSharingRef>>;
|
|
22
|
+
export default DataSharingComponent;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ISharingMetadataConfig, IOrgSharingItem, IDataSharingPayload } from '../../types';
|
|
3
|
+
interface Props {
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
toggle: () => void;
|
|
6
|
+
config: ISharingMetadataConfig;
|
|
7
|
+
masterData: Record<string, any>;
|
|
8
|
+
masterDataList?: Record<string, any>[];
|
|
9
|
+
entityId: string;
|
|
10
|
+
entityIds?: string[];
|
|
11
|
+
orgList: IOrgSharingItem[];
|
|
12
|
+
setOrgList: React.Dispatch<React.SetStateAction<IOrgSharingItem[]>>;
|
|
13
|
+
detailData: Record<string, Record<string, any>[]>;
|
|
14
|
+
setDetailData: React.Dispatch<React.SetStateAction<Record<string, Record<string, any>[]>>>;
|
|
15
|
+
isGlobalShared: boolean;
|
|
16
|
+
setIsGlobalShared: React.Dispatch<React.SetStateAction<boolean>>;
|
|
17
|
+
onSave: (payload: IDataSharingPayload) => Promise<void>;
|
|
18
|
+
loading?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare const ModalSharingView: React.FC<Props>;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IOrgSharingItem, ISharingDetailTabConfig } from '../../types';
|
|
3
|
+
interface Props {
|
|
4
|
+
tabConfig: ISharingDetailTabConfig;
|
|
5
|
+
orgList: IOrgSharingItem[];
|
|
6
|
+
rows: Record<string, any>[];
|
|
7
|
+
onChangeRows: (updatedRows: Record<string, any>[]) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare const DetailTabTable: React.FC<Props>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IOrgSharingItem, ISharingFieldDef } from '../../types';
|
|
3
|
+
interface Props {
|
|
4
|
+
orgList: IOrgSharingItem[];
|
|
5
|
+
overrideColumns: ISharingFieldDef[];
|
|
6
|
+
masterData?: Record<string, any>;
|
|
7
|
+
onChangeOverride: (targetOrgId: string, fieldKey: string, value: any) => void;
|
|
8
|
+
onApplyFirstToAll?: () => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const OverrideTable: React.FC<Props>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { IOrgSharingItem } from '../../types';
|
|
3
|
+
interface Props {
|
|
4
|
+
orgList: IOrgSharingItem[];
|
|
5
|
+
onChangeOrg: (updatedList: IOrgSharingItem[]) => void;
|
|
6
|
+
showEffectiveDate?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare const OrgTable: React.FC<Props>;
|
|
9
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
type FieldType = 'text' | 'number' | 'numeric' | 'currency' | 'select' | 'selectTable' | 'user' | 'date' | 'switch' | 'checkbox';
|
|
4
|
+
interface ISharingFieldOption {
|
|
5
|
+
label: string;
|
|
6
|
+
value: any;
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}
|
|
9
|
+
interface ISharingFieldDef {
|
|
10
|
+
key: string;
|
|
11
|
+
label: string;
|
|
12
|
+
type?: FieldType;
|
|
13
|
+
optionsApi?: string;
|
|
14
|
+
options?: ISharingFieldOption[];
|
|
15
|
+
selectTableColumns?: any[];
|
|
16
|
+
menuWidth?: number;
|
|
17
|
+
fieldLabel?: string;
|
|
18
|
+
fieldKey?: string;
|
|
19
|
+
/** Map target field -> option source field when selecting an option (e.g. { bankCode: 'key', name: 'name', swiftCode: 'swiftCode' }) */
|
|
20
|
+
autoFillMap?: Record<string, string>;
|
|
21
|
+
/** Enforce only 1 true checkbox per scope key (e.g. 'organizationId') */
|
|
22
|
+
uniqueScopeKey?: string;
|
|
23
|
+
textAlign?: 'left' | 'center' | 'right';
|
|
24
|
+
fixedType?: 'left' | 'right';
|
|
25
|
+
required?: boolean;
|
|
26
|
+
readonly?: boolean;
|
|
27
|
+
placeholder?: string;
|
|
28
|
+
defaultValue?: any;
|
|
29
|
+
width?: number | string;
|
|
30
|
+
}
|
|
31
|
+
interface ISharingDetailTabConfig {
|
|
32
|
+
key: string;
|
|
33
|
+
title: string;
|
|
34
|
+
icon?: string;
|
|
35
|
+
columns: ISharingFieldDef[];
|
|
36
|
+
allowAdd?: boolean;
|
|
37
|
+
allowDelete?: boolean;
|
|
38
|
+
defaultRow?: Record<string, any>;
|
|
39
|
+
}
|
|
40
|
+
interface ISharingMetadataConfig {
|
|
41
|
+
entityType: string;
|
|
42
|
+
title: string;
|
|
43
|
+
masterCardTitle: string;
|
|
44
|
+
masterFields: ISharingFieldDef[];
|
|
45
|
+
overrideColumns: ISharingFieldDef[];
|
|
46
|
+
detailTabs?: ISharingDetailTabConfig[];
|
|
47
|
+
showEffectiveDate?: boolean;
|
|
48
|
+
}
|
|
49
|
+
interface IOrgSharingItem {
|
|
50
|
+
targetOrgId: string;
|
|
51
|
+
orgCode: string;
|
|
52
|
+
orgName: string;
|
|
53
|
+
orgType: string;
|
|
54
|
+
parentId?: string | null;
|
|
55
|
+
isSelected: boolean;
|
|
56
|
+
isInheritMaster: boolean;
|
|
57
|
+
canOverrideConfig: boolean;
|
|
58
|
+
effectiveFrom?: string | null;
|
|
59
|
+
effectiveTo?: string | null;
|
|
60
|
+
status: number;
|
|
61
|
+
statusText?: string;
|
|
62
|
+
overrideData?: Record<string, any>;
|
|
63
|
+
}
|
|
64
|
+
interface IDataSharingPayload {
|
|
65
|
+
entityType: string;
|
|
66
|
+
entityId: string;
|
|
67
|
+
entityIds?: string[];
|
|
68
|
+
isGlobalShared: boolean;
|
|
69
|
+
sharingList: {
|
|
70
|
+
TargetOrgId: string;
|
|
71
|
+
IsInheritMaster: boolean;
|
|
72
|
+
CanOverrideConfig: boolean;
|
|
73
|
+
EffectiveFrom?: string | null;
|
|
74
|
+
EffectiveTo?: string | null;
|
|
75
|
+
Status: number;
|
|
76
|
+
}[];
|
|
77
|
+
orgConfigList?: Record<string, any>[];
|
|
78
|
+
detailData?: Record<string, Record<string, any>[]>;
|
|
79
|
+
database?: string;
|
|
80
|
+
}
|
|
81
|
+
interface IFDataSharingOpenParams {
|
|
82
|
+
entityType: string;
|
|
83
|
+
entityId?: string;
|
|
84
|
+
entityIds?: string[];
|
|
85
|
+
masterData?: Record<string, any>;
|
|
86
|
+
masterDataList?: Record<string, any>[];
|
|
87
|
+
config: ISharingMetadataConfig;
|
|
88
|
+
initialGlobalShared?: boolean;
|
|
89
|
+
initialDetailData?: Record<string, Record<string, any>[]>;
|
|
90
|
+
database?: string;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
interface IFDataSharingRef {
|
|
94
|
+
open: (params: IFDataSharingOpenParams) => void;
|
|
95
|
+
close: () => void;
|
|
96
|
+
}
|
|
97
|
+
interface IFDataSharingProps {
|
|
98
|
+
/** Tên DB dự án cho môi trường Test (ví dụ: process.env.REACT_APP_SHARING_DATABASE). Trên Cloud để trống để API tự lấy theo JWT claim "data". */
|
|
99
|
+
database?: string;
|
|
100
|
+
/** Function gọi lấy dữ liệu chia sẻ + cấu hình đơn vị + detailData (như ObjectBank) */
|
|
101
|
+
fetchSharingData?: (entityType: string, entityId: string, database?: string) => Promise<{
|
|
102
|
+
isGlobalShared: boolean;
|
|
103
|
+
orgList: IOrgSharingItem[];
|
|
104
|
+
detailData?: Record<string, Record<string, any>[]>;
|
|
105
|
+
}>;
|
|
106
|
+
/** Function callback lưu dữ liệu */
|
|
107
|
+
onSave?: (payload: IDataSharingPayload) => Promise<void>;
|
|
108
|
+
/** Callback sau khi lưu thành công */
|
|
109
|
+
onSuccess?: () => void;
|
|
110
|
+
}
|
|
111
|
+
declare const DataSharingComponent: React.ForwardRefExoticComponent<IFDataSharingProps & React.RefAttributes<IFDataSharingRef>>;
|
|
112
|
+
|
|
113
|
+
export { FieldType, IDataSharingPayload, IFDataSharingOpenParams, IFDataSharingProps, IFDataSharingRef, IOrgSharingItem, ISharingDetailTabConfig, ISharingFieldDef, ISharingFieldOption, ISharingMetadataConfig, DataSharingComponent as default };
|