aefis-core-ui 2.2.3 → 2.2.4

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.
@@ -10,6 +10,7 @@ import { red, orange, green, blue, grey, yellow, indigo, purple, cyan, teal, lim
10
10
  import makeStyles$1 from '@mui/styles/makeStyles';
11
11
  import withStyles from '@mui/styles/withStyles';
12
12
  import { useTheme, alpha, createTheme as createTheme$1, ThemeProvider, styled as styled$1, StyledEngineProvider } from '@mui/material/styles';
13
+ import { useFormControl } from '@mui/material/FormControl';
13
14
  import mustache from 'mustache';
14
15
  import { Box as Box$2 } from '@mui/system';
15
16
  import { Skeleton as Skeleton$4, TextField as TextField$1, Box as Box$3 } from '@mui/material/';
@@ -42,7 +43,7 @@ import { AnimatePresence, motion } from 'framer-motion';
42
43
  import CircularProgress$1 from '@mui/material/CircularProgress';
43
44
  import { useQuery, useInfiniteQuery, useQueryClient, useMutation, QueryClient, QueryClientProvider } from 'react-query';
44
45
  import axios from 'axios';
45
- import _ from 'lodash';
46
+ import _, { merge } from 'lodash';
46
47
  import qs from 'query-string';
47
48
  import SortIcon from '@mui/icons-material/Sort';
48
49
  import { useSnackbar, SnackbarProvider } from 'notistack';
@@ -71,7 +72,6 @@ import isEmpty from 'lodash/isEmpty';
71
72
  import compose from 'lodash/fp/compose';
72
73
  import Chip$2 from '@mui/material/Chip';
73
74
  import TextField$2 from '@mui/material/TextField';
74
- import { useFormControl } from '@mui/material/FormControl';
75
75
  import get$1 from 'lodash/get';
76
76
  import isPlainObject from 'lodash/isPlainObject';
77
77
  import ToggleButton$1 from '@mui/material/ToggleButton';
@@ -2249,10 +2249,10 @@ ClickWrapper.propTypes = {
2249
2249
  const Chip = ({
2250
2250
  id,
2251
2251
  colorPalette,
2252
- size,
2252
+ size: _size2 = "medium",
2253
2253
  icon,
2254
2254
  label,
2255
- displayType,
2255
+ displayType: _displayType = "default",
2256
2256
  deleteIcon,
2257
2257
  onDelete,
2258
2258
  canDelete,
@@ -2260,7 +2260,7 @@ const Chip = ({
2260
2260
  }) => {
2261
2261
  const keyValue = useUID();
2262
2262
  const colors = _extends({}, defaultColorPalette, colorPalette);
2263
- const _size = size === "medium" || size === "large" ? "medium" : size;
2263
+ const _size = _size2 === "medium" || _size2 === "large" ? "medium" : _size2;
2264
2264
  const styles = {
2265
2265
  outlined: {
2266
2266
  borderWidth: 2,
@@ -2280,14 +2280,14 @@ const Chip = ({
2280
2280
  }
2281
2281
  };
2282
2282
  let chipStyles = styles.chip;
2283
- if (displayType === "outlined") chipStyles = styles.outlined;
2284
- if (displayType === "withOutline") chipStyles = styles.withOutline;
2283
+ if (_displayType === "outlined") chipStyles = styles.outlined;
2284
+ if (_displayType === "withOutline") chipStyles = styles.withOutline;
2285
2285
  const chipProps = {
2286
2286
  key: id || keyValue,
2287
2287
  icon,
2288
2288
  label,
2289
2289
  sx: chipStyles,
2290
- variant: displayType === "withOutline" ? "default" : displayType,
2290
+ variant: _displayType === "withOutline" ? "default" : _displayType,
2291
2291
  size: _size,
2292
2292
  deleteIcon: deleteIcon || /*#__PURE__*/jsx(ClickWrapper, {
2293
2293
  label: label,
@@ -2304,12 +2304,20 @@ const Chip = ({
2304
2304
  })
2305
2305
  })
2306
2306
  };
2307
- const Chip = () => /*#__PURE__*/jsx(Chip$1, _extends({
2308
- role: role || "presentation",
2309
- "aria-label": label
2310
- }, chipProps, canDelete && {
2311
- onDelete
2312
- }));
2307
+ const {
2308
+ disabled
2309
+ } = useFormControl();
2310
+ const _canDelete = canDelete && !disabled;
2311
+ const Chip = () => {
2312
+ return /*#__PURE__*/jsx(Chip$1, _extends({
2313
+ role: role || "presentation",
2314
+ "aria-label": label
2315
+ }, chipProps, _canDelete && {
2316
+ onDelete
2317
+ }, {
2318
+ disabled: disabled
2319
+ }));
2320
+ };
2313
2321
 
2314
2322
  /**return tooltipText ? (
2315
2323
  <Tooltip title={tooltipText}>
@@ -2349,12 +2357,6 @@ Chip.propTypes = {
2349
2357
  /** ARIA Role attribute */
2350
2358
  role: PropTypes.string
2351
2359
  };
2352
- Chip.defaultProps = {
2353
- size: "medium",
2354
- variant: "default",
2355
- canRemove: false,
2356
- displayType: "default"
2357
- };
2358
2360
 
2359
2361
  const colorPalette$v = {
2360
2362
  light: grey[200],
@@ -6882,12 +6884,9 @@ const sanitizedEval = (code, context, options) => {
6882
6884
  }
6883
6885
  };
6884
6886
 
6887
+ // TODO: move this to a state
6885
6888
  let token = "";
6886
- const apiClient = axios.create({
6887
- validateStatus: false
6888
- //baseURL: process.env.NODE_ENV === "development" ? "" : "/ui"
6889
- });
6890
-
6889
+ const apiClient = axios.create({});
6891
6890
  const parseQueryParam = url => {
6892
6891
  const hashIndex = url.indexOf("#");
6893
6892
  const noHashExists = hashIndex === -1;
@@ -6934,44 +6933,11 @@ apiClient.interceptors.request.use(config => {
6934
6933
  for (const key in queryParams) {
6935
6934
  queryParams[key] = objectParse(queryParams[key]);
6936
6935
  }
6937
- config.params = _.merge(queryParams, config.params);
6936
+ config.params = merge(queryParams, config.params);
6938
6937
  config.url = urlOrigin;
6939
6938
  }
6940
6939
  return config;
6941
6940
  });
6942
- const getLoggerErrorMessage = error => {
6943
- if (error.response) {
6944
- var _error$response, _error$request, _error$response2, _error$response2$conf, _error$response2$conf2;
6945
- const status = (_error$response = error.response) == null ? void 0 : _error$response.status;
6946
- const URL = (_error$request = error.request) == null ? void 0 : _error$request.responseURL;
6947
- const method = (_error$response2 = error.response) == null ? void 0 : (_error$response2$conf = _error$response2.config) == null ? void 0 : (_error$response2$conf2 = _error$response2$conf.method) == null ? void 0 : _error$response2$conf2.toUpperCase();
6948
- const message = `RequestError: [${method}] ${status} ${URL}`;
6949
- return message;
6950
- } else if (error.request) {
6951
- return "RequestError: No Response";
6952
- } else {
6953
- return `RequestError: ${error.message.toString()}`;
6954
- }
6955
- };
6956
-
6957
- // Error is formatted to react query and reporting is handled by react-query
6958
- // This prevent re-tried queries to trigger logger request
6959
- const loggerForwardError = promise => (...args) => {
6960
- return promise(...args).catch(error => {
6961
- if (window.logger) {
6962
- var _error$response3, _error$response3$conf, _window$logger;
6963
- const message = getLoggerErrorMessage(error);
6964
- const requestBody = ((_error$response3 = error.response) == null ? void 0 : (_error$response3$conf = _error$response3.config) == null ? void 0 : _error$response3$conf.data) || null;
6965
- (_window$logger = window.logger) == null ? void 0 : _window$logger.logELKEvent == null ? void 0 : _window$logger.logELKEvent({
6966
- name: message,
6967
- data: requestBody
6968
- });
6969
- throw message;
6970
- } else {
6971
- throw error;
6972
- }
6973
- });
6974
- };
6975
6941
  function download(url) {
6976
6942
  apiClient.request({
6977
6943
  url: url,
@@ -6992,33 +6958,32 @@ function download(url) {
6992
6958
  link.remove();
6993
6959
  });
6994
6960
  }
6995
- function get() {
6996
- let args = [...arguments];
6997
- if (args[0].includes("http://gateway") || args[0].includes("https://gateway")) {
6998
- args[1]["headers"] = {
6999
- Authorization: "Bearer " + token
7000
- };
7001
- }
7002
- return apiClient.get(...args);
6961
+ function get(endPoint, config = {}) {
6962
+ const isGateway = endPoint.includes("http://gateway") || endPoint.includes("https://gateway");
6963
+ return apiClient.get(endPoint, _extends({}, config, {
6964
+ headers: _extends({}, config.headers, isGateway && {
6965
+ Authorization: `Bearer ${token}`
6966
+ })
6967
+ }));
7003
6968
  }
7004
- function post() {
7005
- return apiClient.post(...arguments);
6969
+ function post(...args) {
6970
+ return apiClient.post(...args);
7006
6971
  }
7007
- function put() {
7008
- return apiClient.put(...arguments);
6972
+ function put(...args) {
6973
+ return apiClient.put(...args);
7009
6974
  }
7010
- function destroy() {
7011
- return apiClient.destroy(...arguments);
6975
+ function destroy(...args) {
6976
+ return apiClient.delete(...args);
7012
6977
  }
7013
6978
  async function setUserToken(t) {
7014
6979
  token = t;
7015
6980
  }
7016
6981
  var http = {
7017
- get: loggerForwardError(get),
7018
- post: loggerForwardError(post),
7019
- put: loggerForwardError(put),
7020
- download: loggerForwardError(download),
7021
- delete: loggerForwardError(destroy),
6982
+ get,
6983
+ post,
6984
+ put,
6985
+ download,
6986
+ delete: destroy,
7022
6987
  setUserToken
7023
6988
  };
7024
6989
 
@@ -7200,6 +7165,23 @@ let dataSourceConfiguration = {
7200
7165
  }
7201
7166
  };
7202
7167
 
7168
+ // TODO: move this function to logger
7169
+ const getLoggerErrorMessage = error => {
7170
+ if (!error.isAxiosError) return (error == null ? void 0 : error.toString()) || "Undefined error";
7171
+ if (error.response) {
7172
+ var _error$response, _error$request, _error$response2, _error$response2$conf, _error$response2$conf2;
7173
+ const status = (_error$response = error.response) == null ? void 0 : _error$response.status;
7174
+ const URL = (_error$request = error.request) == null ? void 0 : _error$request.responseURL;
7175
+ const method = (_error$response2 = error.response) == null ? void 0 : (_error$response2$conf = _error$response2.config) == null ? void 0 : (_error$response2$conf2 = _error$response2$conf.method) == null ? void 0 : _error$response2$conf2.toUpperCase();
7176
+ const message = `RequestError: [${method}] ${status} ${URL}`;
7177
+ return message;
7178
+ } else if (error.request) {
7179
+ return "RequestError: No Response";
7180
+ } else {
7181
+ return `RequestError: ${error.message.toString()}`;
7182
+ }
7183
+ };
7184
+
7203
7185
  /**
7204
7186
  * wraps function and reports (fire request) to Logger
7205
7187
  * @param {function} onError
@@ -7208,11 +7190,29 @@ let dataSourceConfiguration = {
7208
7190
  const logger = onError => (error, ...rest) => {
7209
7191
  var _window$logger;
7210
7192
  onError == null ? void 0 : onError(error, ...rest);
7211
- const event = {
7212
- name: (error == null ? void 0 : error.toString()) || "Undefined error"
7213
- };
7214
- (_window$logger = window.logger) == null ? void 0 : _window$logger.sendLog == null ? void 0 : _window$logger.sendLog(event);
7193
+ (_window$logger = window.logger) == null ? void 0 : _window$logger.sendLog({
7194
+ name: getLoggerErrorMessage(error),
7195
+ data: error
7196
+ });
7215
7197
  };
7198
+
7199
+ /**
7200
+ * Promisify fetch, this is required for useQuery to handle error properly.
7201
+ * @param {Promise} fetch
7202
+ * @returns Promise
7203
+ */
7204
+ const promisifyRequest = fetch => (...args) => new Promise(async (resolve, reject) => {
7205
+ try {
7206
+ const res = await fetch(...args);
7207
+ resolve(res);
7208
+ } catch (error) {
7209
+ var _window$logger2;
7210
+ reject(error);
7211
+ (_window$logger2 = window.logger) == null ? void 0 : _window$logger2.logEvent({
7212
+ name: getLoggerErrorMessage(error)
7213
+ });
7214
+ }
7215
+ });
7216
7216
  const getGenericBusinessObjectAction = source => {
7217
7217
  var typeAction = source.split("_");
7218
7218
  return typeAction.length === 2 ? `businessObject_${typeAction[1]}` : source;
@@ -7368,7 +7368,7 @@ const useDataSourceQuery = (dataSource, parameters, options, templateContext) =>
7368
7368
  return runQuery(dataSource, parameters, templateContext);
7369
7369
  };
7370
7370
  const fetchStrategy = configuration && typeof configuration.endPoint === "function" ? configuration.endPoint : fetch;
7371
- return useQuery([dataSource, parameters], fetchStrategy, _extends({}, (configuration == null ? void 0 : configuration.options) || {}, options, {
7371
+ return useQuery([dataSource, parameters], promisifyRequest(fetchStrategy), _extends({}, (configuration == null ? void 0 : configuration.options) || {}, options, {
7372
7372
  onError: logger(options == null ? void 0 : options.onError)
7373
7373
  }));
7374
7374
  };
@@ -7391,12 +7391,11 @@ const useDataSourceInfiniteQuery = (dataSource, parameters, initialParameters, o
7391
7391
  const configuration = getConfiguration(dataSource);
7392
7392
  const fetch = ({
7393
7393
  pageParam: _pageParam = initialParameters
7394
- }) => {
7395
- return runQuery(dataSource, _extends({}, parameters, _pageParam));
7396
- };
7394
+ }) => runQuery(dataSource, _extends({}, parameters, _pageParam));
7397
7395
  const fetchStrategy = configuration && typeof configuration.endPoint === "function" ? configuration.endPoint : fetch;
7398
- return useInfiniteQuery([dataSource, parameters], fetchStrategy, _extends({}, configuration ? configuration.options : {}, options, {
7399
- onError: logger(options == null ? void 0 : options.onError)
7396
+ return useInfiniteQuery([dataSource, parameters], promisifyRequest(fetchStrategy), _extends({}, configuration ? configuration.options : {}, options, {
7397
+ onError: logger(options == null ? void 0 : options.onError),
7398
+ retry: false
7400
7399
  }));
7401
7400
  };
7402
7401
 
@@ -7415,7 +7414,6 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7415
7414
  var _mutationOptions;
7416
7415
  const queryClient = useQueryClient();
7417
7416
  const configuration = getConfiguration(dataSource);
7418
- getEndpoint(dataSource, configuration);
7419
7417
  const invalidateFunction = () => {
7420
7418
  if (invalidateQueries) {
7421
7419
  for (let q of invalidateQueries) {
@@ -7442,11 +7440,11 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7442
7440
  };
7443
7441
  }
7444
7442
  function requestCall(requestBody) {
7445
- const request = axios[httpMethodType];
7443
+ const request = http[httpMethodType];
7446
7444
  const endPoint = getEndpoint(dataSource, configuration); //?
7447
7445
  if (httpMethodType === "get" || httpMethodType === "delete") {
7448
7446
  // INFO (Caveat!): requestBody is used as query param in case of
7449
- // httpMethodType is get or delete
7447
+ // httpMethodType is GET or DELETE
7450
7448
  const params = _extends({}, baseParameters, requestBody);
7451
7449
  return request(endPoint, {
7452
7450
  params
@@ -7454,7 +7452,7 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7454
7452
  }
7455
7453
  return request(endPoint, requestBody);
7456
7454
  }
7457
- return useMutation(requestCall, _extends({}, mutationOptions, {
7455
+ return useMutation(promisifyRequest(requestCall), _extends({}, mutationOptions, {
7458
7456
  onError: logger((_mutationOptions = mutationOptions) == null ? void 0 : _mutationOptions.onError)
7459
7457
  }));
7460
7458
  };
@@ -11278,7 +11276,8 @@ const BusinessObjectPicker = _ref => {
11278
11276
  tooltipText: option.description,
11279
11277
  size: props.size === "medium" || props.size === "small" ? "small" : "large",
11280
11278
  onDelete: () => handleTagDelete(option),
11281
- canDelete: true
11279
+ canDelete: true,
11280
+ displayType: "default"
11282
11281
  })
11283
11282
  }, getKey(option))), [props.size, getKey, getLabel, handleTagDelete]);
11284
11283
  const renderTypeTags = useCallback(value => value.map(option => /*#__PURE__*/jsx(Box$1, {
@@ -11327,7 +11326,11 @@ const BusinessObjectPicker = _ref => {
11327
11326
  value: value,
11328
11327
  renderOption: renderOptionProp || (props.type ? renderBusinessObject : renderOption),
11329
11328
  noOptionsText: status === "error" ? "Error loading options" : "No options",
11330
- getOptionDisabled: optionItem => (optionItem == null ? void 0 : optionItem.__type) === "loadMore" || (optionItem == null ? void 0 : optionItem.__type) === "noOption",
11329
+ getOptionDisabled: optionItem => {
11330
+ if (props.disabled) return true;
11331
+ const type = optionItem == null ? void 0 : optionItem.__type;
11332
+ return type === "loadMore" || type === "noOption";
11333
+ },
11331
11334
  handleHomeEndKeys: true
11332
11335
  // INFO: freeSolo prevents warning:
11333
11336
  // https://stackoverflow.com/questions/61947941/material-ui-autocomplete-warning-the-value-provided-to-autocomplete-is-invalid
@@ -11355,7 +11358,7 @@ const BusinessObjectPicker = _ref => {
11355
11358
  style: {
11356
11359
  color: red[500]
11357
11360
  }
11358
- }), listSelect !== true && /*#__PURE__*/jsx(IconButton$1, {
11361
+ }), listSelect !== true && /*#__PURE__*/jsx(IconButton, {
11359
11362
  "aria-label": open ? `hide options` : "show options",
11360
11363
  size: "small",
11361
11364
  onClick: () => {
@@ -11368,7 +11371,7 @@ const BusinessObjectPicker = _ref => {
11368
11371
  [classes.expandOpen]: open
11369
11372
  })
11370
11373
  })
11371
- }), enhancedSearch && /*#__PURE__*/jsx(IconButton$1, {
11374
+ }), enhancedSearch && /*#__PURE__*/jsx(IconButton, {
11372
11375
  "aria-label": "search",
11373
11376
  size: "small",
11374
11377
  onKeyDown: handleKeyDown,
@@ -11376,6 +11379,7 @@ const BusinessObjectPicker = _ref => {
11376
11379
  name: events.OPEN_ENHANCED_SEARCH_DIALOG,
11377
11380
  payload: true
11378
11381
  }),
11382
+ disabled: props.disabled,
11379
11383
  children: /*#__PURE__*/jsx(Search, {})
11380
11384
  })]
11381
11385
  })
@@ -11398,13 +11402,14 @@ const BusinessObjectPicker = _ref => {
11398
11402
  flexDirection: "column",
11399
11403
  padding: 1
11400
11404
  },
11401
- children: /*#__PURE__*/jsx(IconButton$1, {
11405
+ children: /*#__PURE__*/jsx(IconButton, {
11402
11406
  onClick: () => {
11403
11407
  eventDispatch({
11404
11408
  name: events.OPEN_ADD_ITEM_DIALOG,
11405
11409
  payload: true
11406
11410
  });
11407
11411
  },
11412
+ disabled: props.disabled,
11408
11413
  children: /*#__PURE__*/jsx(AddIcon, {
11409
11414
  sx: {
11410
11415
  color: "grey"