awing-library 2.1.2-dev.8 → 2.1.2-dev.9

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.
Files changed (2) hide show
  1. package/dist/esm/index.js +60 -40
  2. package/package.json +1 -1
package/dist/esm/index.js CHANGED
@@ -111978,18 +111978,24 @@ const AutocompleteInput = fieldDefinition => {
111978
111978
  multiple = true,
111979
111979
  isDirectory = false,
111980
111980
  onValidateCustom,
111981
- disabled
111981
+ disabled,
111982
+ required = false
111982
111983
  } = fieldDefinition,
111983
- other = __rest$1(fieldDefinition, ["options", "value", "onChange", "readOnly", "error", "disableHelperText", "helperText", "disableClearable", "multiple", "isDirectory", "onValidateCustom", "disabled"]);
111984
+ other = __rest$1(fieldDefinition, ["options", "value", "onChange", "readOnly", "error", "disableHelperText", "helperText", "disableClearable", "multiple", "isDirectory", "onValidateCustom", "disabled", "required"]);
111985
+ console.log('fieldDefinition', fieldDefinition);
111984
111986
  const onValidate = val => {
111985
- if (!val) return false;
111986
- if (onValidateCustom) {
111987
- return onValidateCustom(val);
111988
- }
111989
- if (Array.isArray(val)) {
111990
- return arrayIsNotEmptyValid(val);
111987
+ if (required) {
111988
+ if (!val) return false;
111989
+ if (onValidateCustom) {
111990
+ return onValidateCustom(val);
111991
+ }
111992
+ if (Array.isArray(val)) {
111993
+ return arrayIsNotEmptyValid(val);
111994
+ } else {
111995
+ return notNullValid(val);
111996
+ }
111991
111997
  } else {
111992
- return notNullValid(val);
111998
+ return true;
111993
111999
  }
111994
112000
  };
111995
112001
  return jsxRuntimeExports.jsx(Autocomplete$2, Object.assign({
@@ -112019,6 +112025,7 @@ const AutocompleteInput = fieldDefinition => {
112019
112025
  renderInput: params => jsxRuntimeExports.jsx(TextField$1, Object.assign({}, params, other, {
112020
112026
  variant: "standard",
112021
112027
  error: error,
112028
+ required: required,
112022
112029
  helperText: !disableHelperText && error ? helperText !== null && helperText !== void 0 ? helperText : t('Common.InvalidData') : ''
112023
112030
  }))
112024
112031
  }, multiple && {
@@ -185090,9 +185097,32 @@ const Edit = () => {
185090
185097
  roleTagOptions,
185091
185098
  groupsTagOptions
185092
185099
  } = useContextUser();
185100
+ //GetUserById to get user information
185101
+ useEffect(() => {
185102
+ if (services) {
185103
+ setLoadingUser(true);
185104
+ services.getUserById({
185105
+ id: Number(userId)
185106
+ }).then(data => {
185107
+ setUser(data);
185108
+ setUserRoleAuthens(lodashExports.map(lodashExports.get(data, 'roleAuthens', []), i => {
185109
+ var _a;
185110
+ return {
185111
+ id: i.id,
185112
+ roleId: i.roleId,
185113
+ roleName: (_a = i === null || i === void 0 ? void 0 : i.role) === null || _a === void 0 ? void 0 : _a.name
185114
+ };
185115
+ }));
185116
+ }).finally(() => {
185117
+ setLoadingUser(false);
185118
+ });
185119
+ }
185120
+ }, []);
185121
+ //handle confirm exit
185093
185122
  const getUserRoles = () => {
185123
+ var _a;
185094
185124
  const userRolesInput = [];
185095
- const currentUserRoles = lodashExports.cloneDeep(lodashExports.get(user, 'roles', userRoleAuthens.map(i => i.roleId)));
185125
+ const currentUserRoles = lodashExports.cloneDeep(lodashExports.get(user, 'roles', (_a = user === null || user === void 0 ? void 0 : user.roleAuthens) === null || _a === void 0 ? void 0 : _a.map(i => i.roleId)));
185096
185126
  // add more new items
185097
185127
  lodashExports.each(currentUserRoles, i => {
185098
185128
  if (!lodashExports.find(userRoleAuthens, j => j.roleId === i)) {
@@ -185113,6 +185143,7 @@ const Edit = () => {
185113
185143
  });
185114
185144
  return userRolesInput;
185115
185145
  };
185146
+ //onUpdateUser function to update user information
185116
185147
  const onUpdateUser = async () => {
185117
185148
  if (!services) return;
185118
185149
  setLoadingUpdateUser(true);
@@ -185132,25 +185163,16 @@ const Edit = () => {
185132
185163
  setLoadingUpdateUser(false);
185133
185164
  });
185134
185165
  };
185135
- useEffect(() => {
185136
- if (services) {
185137
- setLoadingUser(true);
185138
- services.getUserById({
185139
- id: Number(userId)
185140
- }).then(data => {
185141
- setUser(data);
185142
- setUserRoleAuthens(lodashExports.map(lodashExports.get(data, 'roleAuthens', []), i => {
185143
- var _a;
185144
- return {
185145
- id: i.id,
185146
- roleId: i.roleId,
185147
- roleName: (_a = i === null || i === void 0 ? void 0 : i.role) === null || _a === void 0 ? void 0 : _a.name
185148
- };
185149
- }));
185150
- }).finally(() => {
185151
- setLoadingUser(false);
185166
+ const handleUpdate = useCallback((fieldsToUpdate, _formValid, key) => {
185167
+ if (!fieldsToUpdate || !Object.keys(fieldsToUpdate).length) return;
185168
+ setUser(prev => {
185169
+ if (!prev) return prev;
185170
+ return Object.assign(Object.assign({}, prev), {
185171
+ [key]: key !== 'roleAuthens' ? fieldsToUpdate[key] : fieldsToUpdate[key].map(i => ({
185172
+ roleId: i
185173
+ }))
185152
185174
  });
185153
- }
185175
+ });
185154
185176
  }, []);
185155
185177
  return jsxRuntimeExports.jsx(DrawerWrapper$1, {
185156
185178
  title: t('User.TitleEdit'),
@@ -185169,11 +185191,12 @@ const Edit = () => {
185169
185191
  required: true,
185170
185192
  length: 200
185171
185193
  }, {
185172
- fieldName: 'roles',
185173
- // multiple: true,
185194
+ fieldName: 'roleAuthens',
185195
+ multiple: true,
185174
185196
  type: FIELD_TYPE.AUTOCOMPLETE,
185175
185197
  label: t('User.Roles'),
185176
- options: roleTagOptions
185198
+ options: roleTagOptions,
185199
+ required: false
185177
185200
  },
185178
185201
  //Todo: API getUserById does not return groups, so we need to handle it later
185179
185202
  {
@@ -185181,7 +185204,8 @@ const Edit = () => {
185181
185204
  multiple: true,
185182
185205
  type: FIELD_TYPE.AUTOCOMPLETE,
185183
185206
  label: t('User.Groups'),
185184
- options: groupsTagOptions
185207
+ options: groupsTagOptions,
185208
+ required: false
185185
185209
  }, {
185186
185210
  fieldName: 'description',
185187
185211
  type: FIELD_TYPE.TEXT_AREA,
@@ -185190,19 +185214,15 @@ const Edit = () => {
185190
185214
  }],
185191
185215
  oldValue: user ? {
185192
185216
  name: user.name,
185193
- roles: (_a = user === null || user === void 0 ? void 0 : user.roleAuthens) === null || _a === void 0 ? void 0 : _a.map(i => i.roleId),
185217
+ roleAuthens: (_a = user === null || user === void 0 ? void 0 : user.roleAuthens) === null || _a === void 0 ? void 0 : _a.map(i => i.roleId),
185194
185218
  description: user.description,
185195
185219
  groups: user.groups
185196
185220
  } : undefined,
185197
- onUpdate: (obj, formValid) => {
185198
- var _a, _b;
185221
+ onUpdate: (obj, formValid, key) => {
185199
185222
  if (!lodashExports.isEmpty(obj)) {
185200
- obj && setUser(Object.assign(Object.assign(Object.assign({}, user), obj), {
185201
- roles: (_a = obj.roles) === null || _a === void 0 ? void 0 : _a.filter(role => role !== undefined),
185202
- groups: (_b = obj.groups) === null || _b === void 0 ? void 0 : _b.filter(group => group !== undefined)
185203
- }));
185223
+ handleUpdate(obj, formValid, key);
185204
185224
  setConfirmExit(true);
185205
- setReadyForSubmit(formValid);
185225
+ if (obj.name !== (user === null || user === void 0 ? void 0 : user.name)) setReadyForSubmit(formValid);
185206
185226
  }
185207
185227
  }
185208
185228
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "awing-library",
3
- "version": "2.1.2-dev.8",
3
+ "version": "2.1.2-dev.9",
4
4
  "main": "dist/esm/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/index.d.ts",