@antscorp/antsomi-ui 1.3.3-beta.64 → 1.3.3-beta.66

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.
@@ -453,10 +453,7 @@ export const AdvancedPicker = props => {
453
453
  const newDate = getNewDate(item, index);
454
454
  setState(state => (Object.assign(Object.assign({}, state), { date: dayjs(newDate).format(format) })));
455
455
  } }, item)))))) : (React.createElement(React.Fragment, null,
456
- React.createElement(Select, { getPopupContainer: triggerNode => {
457
- console.log(triggerNode.parentNode);
458
- return triggerNode.parentNode;
459
- }, options: newCalculationTypes.map(({ label, value }) => ({
456
+ React.createElement(Select, { getPopupContainer: triggerNode => triggerNode.parentNode, options: newCalculationTypes.map(({ label, value }) => ({
460
457
  value,
461
458
  label: t(label),
462
459
  })), value: option.calculationType.value, onChange: value => {
@@ -464,10 +461,7 @@ export const AdvancedPicker = props => {
464
461
  onChangeOption({ calculationType });
465
462
  } }),
466
463
  React.createElement(InputNumber, { value: option.value, style: { width: '100%' }, min: 0, showHandler: false, onChange: value => onChangeOption({ value }) }),
467
- React.createElement(Select, { getPopupContainer: triggerNode => {
468
- console.log(triggerNode.parentNode);
469
- return triggerNode.parentNode;
470
- }, options: newCalculationDates.map(calculationDate => (Object.assign(Object.assign({}, calculationDate), { label: t(calculationDate.label) }))), value: option.calculationDate.value, onChange: value => {
464
+ React.createElement(Select, { getPopupContainer: triggerNode => triggerNode.parentNode, options: newCalculationDates.map(calculationDate => (Object.assign(Object.assign({}, calculationDate), { label: t(calculationDate.label) }))), value: option.calculationDate.value, onChange: value => {
471
465
  const calculationDate = newCalculationDates.find(calculationDate => calculationDate.value === value);
472
466
  onChangeOption({ calculationDate });
473
467
  } }))),
@@ -89,7 +89,7 @@ export const RichMenuCell = props => {
89
89
  React.createElement("source", { src: videoUrl, type: "video/mp4" }))),
90
90
  previewImage && (videoState.status === 'idle' || isPreview) && (React.createElement(ThumbnailBox, null,
91
91
  React.createElement(Image, { src: previewImage, alt: "thumbnail" }))),
92
- (videoState.status === 'idle' || isPreview) && videoUrl && (React.createElement(VideoAction, null,
92
+ (videoState.status === 'idle' || isPreview) && videoUrl && (React.createElement(VideoAction, { className: "video-capture-action-ignore" },
93
93
  React.createElement(ActionButton, { id: "video-capture-action-play", onClick: handleVideoPlay },
94
94
  React.createElement(Icon, { type: "icon-ants-play-circle", size: 24, style: { width: 26, color: '#fff' } }),
95
95
  isAddLabel && React.createElement(ActionButtonLabel, null, "Play")),
@@ -104,7 +104,7 @@ export const ThumbnailBox = styled.div `
104
104
  export const Image = styled.img `
105
105
  width: 100%;
106
106
  height: 100%;
107
- object-fit: cover;
107
+ object-fit: contain;
108
108
  `;
109
109
  export const Link = styled.a `
110
110
  display: flex;
@@ -5,7 +5,7 @@ import { LayoutContent } from './components';
5
5
  import { shareAccessReducer } from './reducer';
6
6
  import { updateObjAccessInfo } from './actions';
7
7
  export const ShareAccess = (props) => {
8
- const { accessInfo, userId, onChange } = props;
8
+ const { accessInfo, userId, onChange, userPermission } = props;
9
9
  const [state, dispatch] = useReducer(shareAccessReducer(onChange), {
10
10
  modalTransferOwnership: {
11
11
  open: false,
@@ -17,7 +17,7 @@ export const ShareAccess = (props) => {
17
17
  return;
18
18
  dispatch(updateObjAccessInfo(accessInfo));
19
19
  }, [accessInfo]);
20
- return (React.createElement(ShareAccessStateContext.Provider, { value: Object.assign(Object.assign({}, state), { accessUserId: userId }) },
20
+ return (React.createElement(ShareAccessStateContext.Provider, { value: Object.assign(Object.assign({}, state), { accessUserId: userId, accessUserPermission: userPermission }) },
21
21
  React.createElement(ShareAccessDispatchContext.Provider, { value: dispatch },
22
22
  React.createElement(LayoutContent, Object.assign({}, props)))));
23
23
  };
@@ -16,7 +16,7 @@ const ROLE_BY_ACTIONS = {
16
16
  export const PeopleAccess = (props) => {
17
17
  const { allowChangeOnwership } = props;
18
18
  const { state, dispatch } = useShareAccess();
19
- const { accessInfo, userAccess } = state;
19
+ const { accessInfo, accessUserId, accessUserPermission } = state;
20
20
  const handleClickAction = (actKey, updatedUserId) => {
21
21
  if (!accessInfo || !dispatch)
22
22
  return;
@@ -72,7 +72,12 @@ export const PeopleAccess = (props) => {
72
72
  return (React.createElement(StyledPeopleAccessRoot, null,
73
73
  React.createElement("div", { className: "title" }, "People with access"),
74
74
  React.createElement(List, { dataSource: accessInfo.listAccess, renderItem: access => {
75
- const actions = getActionsByUser(userAccess === null || userAccess === void 0 ? void 0 : userAccess.userId, access.userId, accessInfo);
75
+ const actions = getActionsByUser({
76
+ userId: accessUserId,
77
+ updatedUserId: access.userId,
78
+ objectAccessInfo: accessInfo,
79
+ userPermission: accessUserPermission,
80
+ });
76
81
  if (!allowChangeOnwership) {
77
82
  remove(actions, act => act.key === PEOPLE_ACTION_KEYS.TO_OWNER);
78
83
  }
@@ -67,3 +67,9 @@ export declare const GENERATE_DESCRIPTION: {
67
67
  [x: number]: string;
68
68
  };
69
69
  };
70
+ export declare const MENU_PERMISSION: {
71
+ readonly NONE: 1;
72
+ readonly CREATED_BY_USER: 2;
73
+ readonly MANAGEMENT_BY_USER: 3;
74
+ readonly EVERYTHING: 4;
75
+ };
@@ -87,3 +87,9 @@ export const GENERATE_DESCRIPTION = {
87
87
  [PUBLIC_ROLE.ONLY_VIEWER]: 'Only people with access can open this item.',
88
88
  },
89
89
  };
90
+ export const MENU_PERMISSION = {
91
+ NONE: 1,
92
+ CREATED_BY_USER: 2,
93
+ MANAGEMENT_BY_USER: 3,
94
+ EVERYTHING: 4,
95
+ };
@@ -1,11 +1,14 @@
1
1
  /// <reference types="react" />
2
2
  export declare const useShareAccess: () => {
3
3
  state: {
4
- userAccess: import("../types").UserAccessInfo | undefined;
5
4
  allowEdit: boolean;
6
- allowView: number | undefined;
5
+ allowView: boolean;
7
6
  accessInfo?: import("../types").ObjectAccessInfo | undefined;
8
7
  accessUserId?: number | undefined;
8
+ accessUserPermission?: {
9
+ view: number;
10
+ edit: number;
11
+ } | undefined;
9
12
  modalTransferOwnership: {
10
13
  open: boolean;
11
14
  userToOwnerShipId: number;
@@ -1,15 +1,27 @@
1
1
  import { useContext, useMemo } from 'react';
2
+ import { MENU_PERMISSION } from '../constants';
2
3
  import { ShareAccessDispatchContext, ShareAccessStateContext } from '../context';
4
+ import { composeObjectMenuPermissions } from '../utils';
3
5
  export const useShareAccess = () => {
4
- var _a;
6
+ var _a, _b, _c;
5
7
  const state = useContext(ShareAccessStateContext);
6
8
  const dispatch = useContext(ShareAccessDispatchContext);
7
9
  if (!state) {
8
10
  throw new Error('useShareAccess must be used within a ShareAccessProvider');
9
11
  }
10
12
  const userAccess = useMemo(() => { var _a; return (_a = state.accessInfo) === null || _a === void 0 ? void 0 : _a.listAccess.find(access => access.userId === state.accessUserId); }, [state.accessUserId, (_a = state.accessInfo) === null || _a === void 0 ? void 0 : _a.listAccess]);
13
+ const { edit: allowEdit, view: allowView } = composeObjectMenuPermissions({
14
+ menuPermission: {
15
+ view: ((_b = state.accessUserPermission) === null || _b === void 0 ? void 0 : _b.view) || MENU_PERMISSION.NONE,
16
+ edit: ((_c = state.accessUserPermission) === null || _c === void 0 ? void 0 : _c.edit) || MENU_PERMISSION.NONE,
17
+ },
18
+ objectPermission: {
19
+ edit: !!(userAccess === null || userAccess === void 0 ? void 0 : userAccess.allowEdit),
20
+ view: !!(userAccess === null || userAccess === void 0 ? void 0 : userAccess.allowView),
21
+ },
22
+ });
11
23
  return {
12
- state: Object.assign(Object.assign({}, state), { userAccess, allowEdit: !!(userAccess === null || userAccess === void 0 ? void 0 : userAccess.allowEdit), allowView: userAccess === null || userAccess === void 0 ? void 0 : userAccess.allowView }),
24
+ state: Object.assign(Object.assign({}, state), { allowEdit, allowView }),
13
25
  dispatch,
14
26
  };
15
27
  };
@@ -1 +1,3 @@
1
- export * from './ShareAccess';
1
+ export { ShareAccess } from './ShareAccess';
2
+ export * as Constants from './constants';
3
+ export * as Utils from './utils';
@@ -1 +1,3 @@
1
- export * from './ShareAccess';
1
+ export { ShareAccess } from './ShareAccess';
2
+ export * as Constants from './constants';
3
+ export * as Utils from './utils';
@@ -28,6 +28,10 @@ export type ObjectAccessInfo = {
28
28
  };
29
29
  export type ShareAccessProps = {
30
30
  userId?: number;
31
+ userPermission?: {
32
+ edit: number;
33
+ view: number;
34
+ };
31
35
  accessInfo?: ObjectAccessInfo;
32
36
  allowChangeOnwership?: boolean;
33
37
  getUserInfo?(search: string, signal: AbortSignal): Promise<UserInfo[]> | UserInfo[];
@@ -36,6 +40,10 @@ export type ShareAccessProps = {
36
40
  export type ShareAccessState = {
37
41
  accessInfo?: ObjectAccessInfo;
38
42
  accessUserId?: number;
43
+ accessUserPermission?: {
44
+ view: number;
45
+ edit: number;
46
+ };
39
47
  modalTransferOwnership: {
40
48
  open: boolean;
41
49
  userToOwnerShipId: number;
@@ -1,5 +1,27 @@
1
1
  import { ObjectAccessInfo } from './types';
2
- export declare const getActionsByUser: (userId?: number, updatedUserId?: number, objectAccessInfo?: ObjectAccessInfo) => ({
2
+ export declare const mergePermission: (objectPermissionAllow: boolean, menuPermissionValue: number) => boolean;
3
+ export declare const composeObjectMenuPermissions: (params: {
4
+ objectPermission: {
5
+ edit: boolean;
6
+ view: boolean;
7
+ };
8
+ menuPermission: {
9
+ edit: number;
10
+ view: number;
11
+ };
12
+ }) => {
13
+ edit: boolean;
14
+ view: boolean;
15
+ };
16
+ export declare const getActionsByUser: (args: {
17
+ userId?: number;
18
+ userPermission?: {
19
+ view: number;
20
+ edit: number;
21
+ };
22
+ updatedUserId?: number;
23
+ objectAccessInfo?: ObjectAccessInfo;
24
+ }) => ({
3
25
  readonly label: "Viewer";
4
26
  readonly key: "to_viewer";
5
27
  } | {
@@ -1,21 +1,51 @@
1
- import { PEOPLE_ACTIONS, PEOPLE_ACTION_KEYS, ROLE_MAPPING } from './constants';
1
+ import { MENU_PERMISSION, PEOPLE_ACTIONS, PEOPLE_ACTION_KEYS, ROLE_MAPPING } from './constants';
2
2
  import { remove } from 'lodash';
3
- export const getActionsByUser = (userId, updatedUserId, objectAccessInfo) => {
3
+ export const mergePermission = (objectPermissionAllow, menuPermissionValue) => {
4
+ const valueMapping = {
5
+ [`${MENU_PERMISSION.NONE}_false`]: false,
6
+ [`${MENU_PERMISSION.CREATED_BY_USER}_false`]: false,
7
+ [`${MENU_PERMISSION.MANAGEMENT_BY_USER}_false`]: false,
8
+ [`${MENU_PERMISSION.EVERYTHING}_false`]: true,
9
+ [`${MENU_PERMISSION.NONE}_true`]: false,
10
+ [`${MENU_PERMISSION.CREATED_BY_USER}_true`]: true,
11
+ [`${MENU_PERMISSION.MANAGEMENT_BY_USER}_true`]: true,
12
+ [`${MENU_PERMISSION.EVERYTHING}_true`]: true,
13
+ };
14
+ return !!valueMapping[`${menuPermissionValue}_${objectPermissionAllow}`];
15
+ };
16
+ export const composeObjectMenuPermissions = (params) => {
17
+ const { menuPermission, objectPermission } = params;
18
+ const edit = mergePermission(objectPermission.edit, menuPermission.edit);
19
+ const view = mergePermission(objectPermission.view, menuPermission.view);
20
+ return { edit, view };
21
+ };
22
+ export const getActionsByUser = (args) => {
23
+ const { userId, userPermission, updatedUserId, objectAccessInfo } = args;
4
24
  if (!userId || !updatedUserId || !objectAccessInfo)
5
25
  return [];
6
26
  const { ownerId } = objectAccessInfo;
7
27
  const user = objectAccessInfo.listAccess.find(access => access.userId === userId);
8
28
  const updatedUser = objectAccessInfo.listAccess.find(access => access.userId === updatedUserId);
9
- if (!user || !updatedUser || !user.allowEdit || updatedUser.userId === ownerId)
29
+ const { edit: allowEdit } = composeObjectMenuPermissions({
30
+ objectPermission: {
31
+ view: !!(user === null || user === void 0 ? void 0 : user.allowView),
32
+ edit: !!(user === null || user === void 0 ? void 0 : user.allowEdit),
33
+ },
34
+ menuPermission: {
35
+ view: (userPermission === null || userPermission === void 0 ? void 0 : userPermission.view) || MENU_PERMISSION.NONE,
36
+ edit: (userPermission === null || userPermission === void 0 ? void 0 : userPermission.edit) || MENU_PERMISSION.NONE,
37
+ },
38
+ });
39
+ if (!user || !updatedUser || !allowEdit || updatedUser.userId === ownerId)
10
40
  return [];
11
41
  const actions = Object.values(PEOPLE_ACTION_KEYS);
12
- if (user.userId !== ownerId) {
42
+ if (userId !== ownerId) {
13
43
  remove(actions, actKey => actKey === PEOPLE_ACTION_KEYS.TO_OWNER);
14
44
  }
15
- if (user.allowEdit && updatedUser.role === ROLE_MAPPING.EDITOR) {
45
+ if (allowEdit && updatedUser.role === ROLE_MAPPING.EDITOR) {
16
46
  remove(actions, actKey => actKey === PEOPLE_ACTION_KEYS.TO_EDITOR);
17
47
  }
18
- if (user.allowEdit && updatedUser.role === ROLE_MAPPING.VIEWER) {
48
+ if (allowEdit && updatedUser.role === ROLE_MAPPING.VIEWER) {
19
49
  remove(actions, actKey => actKey === PEOPLE_ACTION_KEYS.TO_VIEWER);
20
50
  }
21
51
  return actions.map(actKey => PEOPLE_ACTIONS[actKey]);
@@ -18,10 +18,9 @@ export { IconSelection } from './IconSelection';
18
18
  export { IconSelectionRenderer } from './IconSelection/components/Icon';
19
19
  export { AlignSetting } from './AlignSetting';
20
20
  export { EdgeSetting } from './EdgeSetting';
21
- export { ShareAccess } from './ShareAccess';
21
+ export { ShareAccess, Constants as ShareAccessConstants, Utils as ShareAccessUtils, } from './ShareAccess';
22
22
  export { Collapse } from './Collapse';
23
23
  export { TreeSelect } from './TreeSelect';
24
- export { Result } from './Result';
25
24
  export { Card } from './Card';
26
25
  export { InputNumberWithUnit } from './InputNumberWithUnit';
27
26
  export { GradientSetting } from './GradientSetting';
@@ -18,10 +18,9 @@ export { IconSelection } from './IconSelection';
18
18
  export { IconSelectionRenderer } from './IconSelection/components/Icon';
19
19
  export { AlignSetting } from './AlignSetting';
20
20
  export { EdgeSetting } from './EdgeSetting';
21
- export { ShareAccess } from './ShareAccess';
21
+ export { ShareAccess, Constants as ShareAccessConstants, Utils as ShareAccessUtils, } from './ShareAccess';
22
22
  export { Collapse } from './Collapse';
23
23
  export { TreeSelect } from './TreeSelect';
24
- export { Result } from './Result';
25
24
  export { Card } from './Card';
26
25
  export { InputNumberWithUnit } from './InputNumberWithUnit';
27
26
  export { GradientSetting } from './GradientSetting';
@@ -14,8 +14,8 @@
14
14
  "firstDayOfMonth": "First day of this month",
15
15
  "firstDayOfQuarter": "First day of this quarter",
16
16
  "firstDayOfYear": "First day of this year",
17
- "lastDayOfWeekMonSun": "First day of this week (Mon - Sun)",
18
- "lastDayOfWeekSunSat": "First day of this week (Sun - Sat)",
17
+ "lastDayOfWeekMonSun": "Last day of this week (Mon - Sun)",
18
+ "lastDayOfWeekSunSat": "Last day of this week (Sun - Sat)",
19
19
  "lastDayOfMonth": "Last day of this month",
20
20
  "lastDayOfQuarter": "Last day of this quarter",
21
21
  "lastDayOfYear": "Last day of this year",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antscorp/antsomi-ui",
3
- "version": "1.3.3-beta.64",
3
+ "version": "1.3.3-beta.66",
4
4
  "description": "An enterprise-class UI design language and React UI library.",
5
5
  "sideEffects": [
6
6
  "dist/*",
@@ -93,7 +93,6 @@
93
93
  "devDependencies": {
94
94
  "@ant-design/cssinjs": "^1.6.2",
95
95
  "@antscorp/eslint-config-antsomi": "1.0.4",
96
- "@antscorp/icons": "0.27.4",
97
96
  "@babel/cli": "^7.23.4",
98
97
  "@babel/core": "^7.21.3",
99
98
  "@babel/plugin-proposal-class-properties": "^7.18.6",