@antscorp/antsomi-ui 2.0.117 → 2.0.119

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.
@@ -7,23 +7,24 @@ import { LayoutContent } from './components';
7
7
  import { shareAccessReducer } from './reducer';
8
8
  import { updateObjAccessInfo } from './actions';
9
9
  import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks/useDeepCompareEffect';
10
- import { safeParseAccessInfo } from './utils';
10
+ import { fromRaw, safeParseAccessInfo } from './utils';
11
11
  export const ShareAccess = memo((props) => {
12
- const { accessInfo, excludeUserAccess, userId, onChange, userPermission, isLoading } = props;
13
- const [state, dispatch] = useReducer(shareAccessReducer(onChange), {
12
+ const { accessInfo, rawAccessInfo, excludeUserAccess, userId, onChange, onRawChange, userPermission, isLoading, } = props;
13
+ const [state, dispatch] = useReducer(shareAccessReducer(onChange, onRawChange), {
14
14
  modalTransferOwnership: {
15
15
  open: false,
16
16
  userToOwnerShipId: -1,
17
17
  },
18
18
  });
19
19
  useDeepCompareEffect(() => {
20
- if (!accessInfo)
20
+ const resolved = rawAccessInfo ? fromRaw(rawAccessInfo) : accessInfo;
21
+ if (!resolved)
21
22
  return;
22
23
  dispatch(updateObjAccessInfo({
23
- updated: safeParseAccessInfo(accessInfo),
24
+ updated: safeParseAccessInfo(resolved),
24
25
  triggerOut: false,
25
26
  }));
26
- }, [accessInfo]);
27
+ }, [accessInfo, rawAccessInfo]);
27
28
  return (_jsx(ShareAccessStateContext.Provider, { value: {
28
29
  ...state,
29
30
  excludeUserAccess,
@@ -5,10 +5,9 @@ import { ModalTransferOwnership } from '../ModalTransferOwnerShip/ModalTransferO
5
5
  import { PeopleAccess } from '../PeopleAccess';
6
6
  import { SearchUser } from '../SearchUser';
7
7
  import { StyledLayoutContentRoot } from './styled';
8
- import { Spin } from '@antscorp/antsomi-ui/es/components/atoms';
9
8
  export const LayoutContent = (props) => {
10
- const { getUserInfo, generalAccessSettings, excludeUserAccess, placeholder, allowAddUser = true, hideTransferOwnership, } = props;
9
+ const { getUserInfo, generalAccessSettings, excludeUserAccess, placeholder, allowAddUser = true, hideTransferOwnership, className, } = props;
11
10
  const { state } = useShareAccess();
12
11
  const { isLoading } = state;
13
- return (_jsx(Spin, { spinning: !!isLoading, children: _jsxs(StyledLayoutContentRoot, { children: [!isLoading && allowAddUser && (_jsx(SearchUser, { getUserInfo: getUserInfo, placeholder: placeholder })), _jsx(PeopleAccess, { excludeUserAccess: excludeUserAccess, hideTransferOwnership: hideTransferOwnership }), _jsx(GeneralAccess, { generalAccessSettings: generalAccessSettings }), _jsx(ModalTransferOwnership, {})] }) }));
12
+ return (_jsxs(StyledLayoutContentRoot, { className: className, children: [!isLoading && allowAddUser && (_jsx(SearchUser, { getUserInfo: getUserInfo, placeholder: placeholder })), _jsx(PeopleAccess, { excludeUserAccess: excludeUserAccess, hideTransferOwnership: hideTransferOwnership }), _jsx(GeneralAccess, { generalAccessSettings: generalAccessSettings }), _jsx(ModalTransferOwnership, {})] }));
14
13
  };
@@ -3,7 +3,7 @@ export declare const useShareAccess: () => {
3
3
  state: {
4
4
  allowEdit: boolean;
5
5
  allowView: boolean;
6
- accessInfo?: import("../types").ObjectAccessInfo | undefined;
6
+ accessInfo?: import("..").ObjectAccessInfo | undefined;
7
7
  isLoading?: boolean | undefined;
8
8
  accessUserId?: number | undefined;
9
9
  accessUserPermission?: {
@@ -1,3 +1,4 @@
1
1
  export { ShareAccess } from './ShareAccess';
2
2
  export * as Constants from './constants';
3
3
  export * as Utils from './utils';
4
+ export type { ObjectAccessInfo, ObjectAccessInfoRaw, UserAccessInfo, UserAccessInfoRaw, ShareAccessProps, } from './types';
@@ -1,2 +1,2 @@
1
1
  import { ShareAccessAction, ShareAccessProps, ShareAccessState } from './types';
2
- export declare const shareAccessReducer: (onChange: ShareAccessProps['onChange']) => (state: ShareAccessState, action: ShareAccessAction) => ShareAccessState;
2
+ export declare const shareAccessReducer: (onChange: ShareAccessProps['onChange'], onRawChange: ShareAccessProps['onRawChange']) => (state: ShareAccessState, action: ShareAccessAction) => ShareAccessState;
@@ -1,13 +1,16 @@
1
1
  import produce from 'immer';
2
2
  import { TYPES } from './actions';
3
- import { mappingOutData } from './utils';
4
- export const shareAccessReducer = (onChange) => (state, action) => produce(state, draft => {
3
+ import { mappingOutData, toRaw } from './utils';
4
+ export const shareAccessReducer = (onChange, onRawChange) => (state, action) => produce(state, draft => {
5
5
  switch (action.type) {
6
6
  case TYPES.UPDATE_OBJECT_ACCESS_INFO: {
7
7
  const { updated, triggerOut = true } = action.payload;
8
+ // console.log({ action });
8
9
  draft.accessInfo = updated;
9
- if (onChange && triggerOut) {
10
- onChange(mappingOutData(action.payload.updated));
10
+ if (triggerOut) {
11
+ const mapped = mappingOutData(action.payload.updated);
12
+ onChange?.(mapped);
13
+ onRawChange?.(toRaw(mapped));
11
14
  }
12
15
  break;
13
16
  }
@@ -28,12 +28,30 @@ export type ObjectAccessInfo = {
28
28
  ownerId: number;
29
29
  listAccess: UserAccessInfo[];
30
30
  };
31
+ export type UserAccessInfoRaw = {
32
+ user_id: number;
33
+ role: number;
34
+ allow_view: number;
35
+ allow_edit: number;
36
+ allow_comment: number;
37
+ full_name?: string;
38
+ email?: string;
39
+ avatar?: string;
40
+ [key: string]: any;
41
+ };
42
+ export type ObjectAccessInfoRaw = {
43
+ is_public: number;
44
+ public_role: number | null;
45
+ owner_id?: number;
46
+ list_access: UserAccessInfoRaw[];
47
+ };
31
48
  export type ActionKey = (typeof PEOPLE_ACTION_KEYS)[keyof typeof PEOPLE_ACTION_KEYS];
32
49
  export type ExcludeUserAccess = Array<ActionKey>;
33
50
  export type GeneralAccessSettings = {
34
51
  publicOnlyWith?: boolean;
35
52
  };
36
53
  export type ShareAccessProps = {
54
+ className?: string;
37
55
  userId?: number;
38
56
  userPermission?: {
39
57
  edit: number;
@@ -47,6 +65,8 @@ export type ShareAccessProps = {
47
65
  getUserInfo?(search: string, signal: AbortSignal): Promise<UserInfo[]> | UserInfo[];
48
66
  generalAccessSettings?: GeneralAccessSettings;
49
67
  onChange?: (accessInfo: ObjectAccessInfo) => void;
68
+ rawAccessInfo?: ObjectAccessInfoRaw;
69
+ onRawChange?: (raw: ObjectAccessInfoRaw) => void;
50
70
  hideTransferOwnership?: boolean;
51
71
  };
52
72
  export type ShareAccessState = {
@@ -1,4 +1,4 @@
1
- import { ActionKey, ObjectAccessInfo, UserAccessInfo, UserInfo } from './types';
1
+ import { ActionKey, ObjectAccessInfo, ObjectAccessInfoRaw, UserAccessInfo, UserInfo } from './types';
2
2
  export declare const mergePermission: (objectPermissionAllow: boolean, menuPermissionValue: number) => boolean;
3
3
  export declare const composeObjectMenuPermissions: (params: {
4
4
  isPublic: boolean;
@@ -54,6 +54,8 @@ export declare const safeParseAccessInfo: (accessInfo: ObjectAccessInfo) => {
54
54
  isPublic: number;
55
55
  publicRole: number | null;
56
56
  };
57
+ export declare const fromRaw: (raw: ObjectAccessInfoRaw) => ObjectAccessInfo;
58
+ export declare const toRaw: (info: ObjectAccessInfo) => ObjectAccessInfoRaw;
57
59
  export declare const mappingOutData: (shareAccess: ObjectAccessInfo) => {
58
60
  isPublic: number;
59
61
  publicRole: number | null;
@@ -1,5 +1,5 @@
1
1
  import { MENU_PERMISSION, PEOPLE_ACTIONS, PEOPLE_ACTION_KEYS, PUBLIC_ROLE, REGEX_REMOVE_NAME, ROLE_ACCESS_LABEL, ROLE_MAPPING, } from './constants';
2
- import { remove } from 'lodash';
2
+ import { remove, mapKeys, camelCase, snakeCase } from 'lodash';
3
3
  import { snakeCaseToCamelCase } from '@antscorp/antsomi-ui/es/utils';
4
4
  export const mergePermission = (objectPermissionAllow, menuPermissionValue) => {
5
5
  const valueMapping = {
@@ -87,9 +87,42 @@ export const safeParseAccessInfo = (accessInfo) => {
87
87
  return {
88
88
  ...accessInfo,
89
89
  ownerId: +(ownerId || -1),
90
- listAccess: accessInfo?.listAccess?.map(user => ({ ...user, userId: +user.userId })),
90
+ listAccess: accessInfo?.listAccess?.map(user => ({
91
+ ...user,
92
+ userId: +user.userId,
93
+ role: +user.role,
94
+ allowView: +user.allowView,
95
+ allowEdit: +user.allowEdit,
96
+ allowComment: +user.allowComment,
97
+ })),
91
98
  };
92
99
  };
100
+ export const fromRaw = (raw) => ({
101
+ isPublic: raw.is_public,
102
+ publicRole: raw.public_role,
103
+ ownerId: raw.owner_id ?? -1,
104
+ listAccess: raw.list_access.map(u => ({
105
+ ...mapKeys(u, (_v, key) => camelCase(key)),
106
+ userId: u.user_id,
107
+ role: u.role,
108
+ allowView: u.allow_view,
109
+ allowEdit: u.allow_edit,
110
+ allowComment: u.allow_comment,
111
+ })),
112
+ });
113
+ export const toRaw = (info) => ({
114
+ is_public: info.isPublic,
115
+ public_role: info.publicRole,
116
+ owner_id: info.ownerId,
117
+ list_access: info.listAccess.map(u => ({
118
+ ...mapKeys(u, (_v, key) => snakeCase(key)),
119
+ user_id: u.userId,
120
+ role: u.role,
121
+ allow_view: u.allowView,
122
+ allow_edit: u.allowEdit,
123
+ allow_comment: u.allowComment,
124
+ })),
125
+ });
93
126
  export const mappingOutData = (shareAccess) => {
94
127
  const result = { ...shareAccess };
95
128
  result.listAccess = result.listAccess.map(accessInfo => {
@@ -23,6 +23,7 @@ export { IconSelectionRenderer } from './IconSelection/components/Icon';
23
23
  export { AlignSetting } from './AlignSetting';
24
24
  export { EdgeSetting } from './EdgeSetting';
25
25
  export { ShareAccess, Constants as ShareAccessConstants, Utils as ShareAccessUtils, } from './ShareAccess';
26
+ export type { ObjectAccessInfo, ObjectAccessInfoRaw, UserAccessInfo, UserAccessInfoRaw, ShareAccessProps, } from './ShareAccess';
26
27
  export { Collapse } from './Collapse';
27
28
  export { TreeSelect } from './TreeSelect';
28
29
  export { Card } from './Card';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "2.0.117",
3
+ "version": "2.0.119",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",