@antscorp/antsomi-ui 2.0.116 → 2.0.118

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.
@@ -1,2 +1,3 @@
1
+ import React from 'react';
1
2
  import { ShareAccessProps } from './types';
2
- export declare const ShareAccess: (props: ShareAccessProps) => import("react/jsx-runtime").JSX.Element;
3
+ export declare const ShareAccess: React.MemoExoticComponent<(props: ShareAccessProps) => import("react/jsx-runtime").JSX.Element>;
@@ -1,32 +1,35 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  /* eslint-disable react/jsx-no-constructed-context-values */
3
- import { useReducer } from 'react';
3
+ import { memo, useReducer } from 'react';
4
+ import isEqual from 'react-fast-compare';
4
5
  import { ShareAccessDispatchContext, ShareAccessStateContext } from './context';
5
6
  import { LayoutContent } from './components';
6
7
  import { shareAccessReducer } from './reducer';
7
8
  import { updateObjAccessInfo } from './actions';
8
9
  import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks/useDeepCompareEffect';
9
- import { safeParseAccessInfo } from './utils';
10
- export const ShareAccess = (props) => {
11
- const { accessInfo, excludeUserAccess, userId, onChange, userPermission } = props;
12
- const [state, dispatch] = useReducer(shareAccessReducer(onChange), {
10
+ import { fromRaw, safeParseAccessInfo } from './utils';
11
+ export const ShareAccess = memo((props) => {
12
+ const { accessInfo, rawAccessInfo, excludeUserAccess, userId, onChange, onRawChange, userPermission, isLoading, } = props;
13
+ const [state, dispatch] = useReducer(shareAccessReducer(onChange, onRawChange), {
13
14
  modalTransferOwnership: {
14
15
  open: false,
15
16
  userToOwnerShipId: -1,
16
17
  },
17
18
  });
18
19
  useDeepCompareEffect(() => {
19
- if (!accessInfo)
20
+ const resolved = rawAccessInfo ? fromRaw(rawAccessInfo) : accessInfo;
21
+ if (!resolved)
20
22
  return;
21
23
  dispatch(updateObjAccessInfo({
22
- updated: safeParseAccessInfo(accessInfo),
24
+ updated: safeParseAccessInfo(resolved),
23
25
  triggerOut: false,
24
26
  }));
25
- }, [accessInfo]);
27
+ }, [accessInfo, rawAccessInfo]);
26
28
  return (_jsx(ShareAccessStateContext.Provider, { value: {
27
29
  ...state,
28
30
  excludeUserAccess,
29
31
  accessUserId: userId,
30
32
  accessUserPermission: userPermission,
33
+ isLoading,
31
34
  }, children: _jsx(ShareAccessDispatchContext.Provider, { value: dispatch, children: _jsx(LayoutContent, { ...props }) }) }));
32
- };
35
+ }, isEqual);
@@ -1,13 +1,14 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useShareAccess } from '../../hooks';
2
3
  import { GeneralAccess } from '../GeneralAccess';
3
4
  import { ModalTransferOwnership } from '../ModalTransferOwnerShip/ModalTransferOwnerShip';
4
5
  import { PeopleAccess } from '../PeopleAccess';
5
6
  import { SearchUser } from '../SearchUser';
6
7
  import { StyledLayoutContentRoot } from './styled';
8
+ import { Spin } from '@antscorp/antsomi-ui/es/components/atoms';
7
9
  export const LayoutContent = (props) => {
8
10
  const { getUserInfo, generalAccessSettings, excludeUserAccess, placeholder, allowAddUser = true, hideTransferOwnership, } = props;
9
- // const { state } = useShareAccess();
10
- // const { allowEdit, allowView } = state;
11
- // if (!allowEdit && !allowView) return null;
12
- return (_jsxs(StyledLayoutContentRoot, { children: [allowAddUser && _jsx(SearchUser, { getUserInfo: getUserInfo, placeholder: placeholder }), _jsx(PeopleAccess, { excludeUserAccess: excludeUserAccess, hideTransferOwnership: hideTransferOwnership }), _jsx(GeneralAccess, { generalAccessSettings: generalAccessSettings }), _jsx(ModalTransferOwnership, {})] }));
11
+ const { state } = useShareAccess();
12
+ 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, {})] }) }));
13
14
  };
@@ -19,7 +19,7 @@ const ROLE_BY_ACTIONS = {
19
19
  export const PeopleAccess = (props) => {
20
20
  const { excludeUserAccess, hideTransferOwnership } = props;
21
21
  const { state, dispatch } = useShareAccess();
22
- const { accessInfo, accessUserId, accessUserPermission } = state;
22
+ const { accessInfo, accessUserId, accessUserPermission, isLoading } = state;
23
23
  const dataSourceSorted = useMemo(() => {
24
24
  if (!Array.isArray(accessInfo?.listAccess))
25
25
  return [];
@@ -86,7 +86,7 @@ export const PeopleAccess = (props) => {
86
86
  };
87
87
  if (!accessInfo)
88
88
  return null;
89
- return (_jsxs(StyledPeopleAccessRoot, { children: [_jsx("div", { className: "title", children: "People with access" }), _jsx(List, { dataSource: dataSourceSorted, loading: { spinning: dataSourceSorted.length === 0, indicator: _jsx(Spin, {}) }, renderItem: access => {
89
+ return (_jsxs(StyledPeopleAccessRoot, { children: [_jsx("div", { className: "title", children: "People with access" }), _jsx(List, { dataSource: dataSourceSorted, loading: { spinning: !!isLoading, indicator: _jsx(Spin, {}) }, renderItem: access => {
90
90
  const actions = getActionsByUser({
91
91
  userId: accessUserId,
92
92
  updatedUserId: access.userId,
@@ -3,7 +3,8 @@ 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
+ isLoading?: boolean | undefined;
7
8
  accessUserId?: number | undefined;
8
9
  accessUserPermission?: {
9
10
  view: number;
@@ -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,15 @@
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
8
  draft.accessInfo = updated;
9
- if (onChange && triggerOut) {
10
- onChange(mappingOutData(action.payload.updated));
9
+ if (triggerOut) {
10
+ const mapped = mappingOutData(action.payload.updated);
11
+ onChange?.(mapped);
12
+ onRawChange?.(toRaw(mapped));
11
13
  }
12
14
  break;
13
15
  }
@@ -28,6 +28,19 @@ 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
+ };
38
+ export type ObjectAccessInfoRaw = {
39
+ is_public: number;
40
+ public_role: number | null;
41
+ owner_id?: number;
42
+ list_access: UserAccessInfoRaw[];
43
+ };
31
44
  export type ActionKey = (typeof PEOPLE_ACTION_KEYS)[keyof typeof PEOPLE_ACTION_KEYS];
32
45
  export type ExcludeUserAccess = Array<ActionKey>;
33
46
  export type GeneralAccessSettings = {
@@ -40,16 +53,20 @@ export type ShareAccessProps = {
40
53
  view: number;
41
54
  };
42
55
  accessInfo?: ObjectAccessInfo;
56
+ isLoading?: boolean;
43
57
  allowAddUser?: boolean;
44
58
  placeholder?: string;
45
59
  excludeUserAccess?: ExcludeUserAccess;
46
60
  getUserInfo?(search: string, signal: AbortSignal): Promise<UserInfo[]> | UserInfo[];
47
61
  generalAccessSettings?: GeneralAccessSettings;
48
62
  onChange?: (accessInfo: ObjectAccessInfo) => void;
63
+ rawAccessInfo?: ObjectAccessInfoRaw;
64
+ onRawChange?: (raw: ObjectAccessInfoRaw) => void;
49
65
  hideTransferOwnership?: boolean;
50
66
  };
51
67
  export type ShareAccessState = {
52
68
  accessInfo?: ObjectAccessInfo;
69
+ isLoading?: boolean;
53
70
  accessUserId?: number;
54
71
  accessUserPermission?: {
55
72
  view: number;
@@ -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;
@@ -90,6 +90,30 @@ export const safeParseAccessInfo = (accessInfo) => {
90
90
  listAccess: accessInfo?.listAccess?.map(user => ({ ...user, userId: +user.userId })),
91
91
  };
92
92
  };
93
+ export const fromRaw = (raw) => ({
94
+ isPublic: raw.is_public,
95
+ publicRole: raw.public_role,
96
+ ownerId: raw.owner_id ?? -1,
97
+ listAccess: raw.list_access.map(u => ({
98
+ userId: u.user_id,
99
+ role: u.role,
100
+ allowView: u.allow_view,
101
+ allowEdit: u.allow_edit,
102
+ allowComment: u.allow_comment,
103
+ })),
104
+ });
105
+ export const toRaw = (info) => ({
106
+ is_public: info.isPublic,
107
+ public_role: info.publicRole,
108
+ owner_id: info.ownerId,
109
+ list_access: info.listAccess.map(u => ({
110
+ user_id: u.userId,
111
+ role: u.role,
112
+ allow_view: u.allowView,
113
+ allow_edit: u.allowEdit,
114
+ allow_comment: u.allowComment,
115
+ })),
116
+ });
93
117
  export const mappingOutData = (shareAccess) => {
94
118
  const result = { ...shareAccess };
95
119
  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.116",
3
+ "version": "2.0.118",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",