aefis-core-ui 2.2.3 → 2.2.5

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,21 @@ 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
+
2308
+ // TODO: create FormChip (or similar) and use contextful version there. Pure
2309
+ // and Contextful component should be seperated
2310
+ const formControl = useFormControl();
2311
+ const _canDelete = canDelete && !(formControl != null && formControl.disabled);
2312
+ const Chip = () => {
2313
+ return /*#__PURE__*/jsx(Chip$1, _extends({
2314
+ role: role || "presentation",
2315
+ "aria-label": label
2316
+ }, chipProps, _canDelete && {
2317
+ onDelete
2318
+ }, {
2319
+ disabled: formControl == null ? void 0 : formControl.disabled
2320
+ }));
2321
+ };
2313
2322
 
2314
2323
  /**return tooltipText ? (
2315
2324
  <Tooltip title={tooltipText}>
@@ -2349,12 +2358,6 @@ Chip.propTypes = {
2349
2358
  /** ARIA Role attribute */
2350
2359
  role: PropTypes.string
2351
2360
  };
2352
- Chip.defaultProps = {
2353
- size: "medium",
2354
- variant: "default",
2355
- canRemove: false,
2356
- displayType: "default"
2357
- };
2358
2361
 
2359
2362
  const colorPalette$v = {
2360
2363
  light: grey[200],
@@ -6882,12 +6885,9 @@ const sanitizedEval = (code, context, options) => {
6882
6885
  }
6883
6886
  };
6884
6887
 
6888
+ // TODO: move this to a state
6885
6889
  let token = "";
6886
- const apiClient = axios.create({
6887
- validateStatus: false
6888
- //baseURL: process.env.NODE_ENV === "development" ? "" : "/ui"
6889
- });
6890
-
6890
+ const apiClient = axios.create({});
6891
6891
  const parseQueryParam = url => {
6892
6892
  const hashIndex = url.indexOf("#");
6893
6893
  const noHashExists = hashIndex === -1;
@@ -6934,44 +6934,11 @@ apiClient.interceptors.request.use(config => {
6934
6934
  for (const key in queryParams) {
6935
6935
  queryParams[key] = objectParse(queryParams[key]);
6936
6936
  }
6937
- config.params = _.merge(queryParams, config.params);
6937
+ config.params = merge(queryParams, config.params);
6938
6938
  config.url = urlOrigin;
6939
6939
  }
6940
6940
  return config;
6941
6941
  });
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
6942
  function download(url) {
6976
6943
  apiClient.request({
6977
6944
  url: url,
@@ -6992,33 +6959,32 @@ function download(url) {
6992
6959
  link.remove();
6993
6960
  });
6994
6961
  }
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);
6962
+ function get(endPoint, config = {}) {
6963
+ const isGateway = endPoint.includes("http://gateway") || endPoint.includes("https://gateway");
6964
+ return apiClient.get(endPoint, _extends({}, config, {
6965
+ headers: _extends({}, config.headers, isGateway && {
6966
+ Authorization: `Bearer ${token}`
6967
+ })
6968
+ }));
7003
6969
  }
7004
- function post() {
7005
- return apiClient.post(...arguments);
6970
+ function post(...args) {
6971
+ return apiClient.post(...args);
7006
6972
  }
7007
- function put() {
7008
- return apiClient.put(...arguments);
6973
+ function put(...args) {
6974
+ return apiClient.put(...args);
7009
6975
  }
7010
- function destroy() {
7011
- return apiClient.destroy(...arguments);
6976
+ function destroy(...args) {
6977
+ return apiClient.delete(...args);
7012
6978
  }
7013
6979
  async function setUserToken(t) {
7014
6980
  token = t;
7015
6981
  }
7016
6982
  var http = {
7017
- get: loggerForwardError(get),
7018
- post: loggerForwardError(post),
7019
- put: loggerForwardError(put),
7020
- download: loggerForwardError(download),
7021
- delete: loggerForwardError(destroy),
6983
+ get,
6984
+ post,
6985
+ put,
6986
+ download,
6987
+ delete: destroy,
7022
6988
  setUserToken
7023
6989
  };
7024
6990
 
@@ -7200,6 +7166,23 @@ let dataSourceConfiguration = {
7200
7166
  }
7201
7167
  };
7202
7168
 
7169
+ // TODO: move this function to logger
7170
+ const getLoggerErrorMessage = error => {
7171
+ if (!error.isAxiosError) return (error == null ? void 0 : error.toString()) || "Undefined error";
7172
+ if (error.response) {
7173
+ var _error$response, _error$request, _error$response2, _error$response2$conf, _error$response2$conf2;
7174
+ const status = (_error$response = error.response) == null ? void 0 : _error$response.status;
7175
+ const URL = (_error$request = error.request) == null ? void 0 : _error$request.responseURL;
7176
+ 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();
7177
+ const message = `RequestError: [${method}] ${status} ${URL}`;
7178
+ return message;
7179
+ } else if (error.request) {
7180
+ return "RequestError: No Response";
7181
+ } else {
7182
+ return `RequestError: ${error.message.toString()}`;
7183
+ }
7184
+ };
7185
+
7203
7186
  /**
7204
7187
  * wraps function and reports (fire request) to Logger
7205
7188
  * @param {function} onError
@@ -7208,11 +7191,29 @@ let dataSourceConfiguration = {
7208
7191
  const logger = onError => (error, ...rest) => {
7209
7192
  var _window$logger;
7210
7193
  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);
7194
+ (_window$logger = window.logger) == null ? void 0 : _window$logger.sendLog({
7195
+ name: getLoggerErrorMessage(error),
7196
+ data: error
7197
+ });
7215
7198
  };
7199
+
7200
+ /**
7201
+ * Promisify fetch, this is required for useQuery to handle error properly.
7202
+ * @param {Promise} fetch
7203
+ * @returns Promise
7204
+ */
7205
+ const promisifyRequest = fetch => (...args) => new Promise(async (resolve, reject) => {
7206
+ try {
7207
+ const res = await fetch(...args);
7208
+ resolve(res);
7209
+ } catch (error) {
7210
+ var _window$logger2;
7211
+ reject(error);
7212
+ (_window$logger2 = window.logger) == null ? void 0 : _window$logger2.logEvent({
7213
+ name: getLoggerErrorMessage(error)
7214
+ });
7215
+ }
7216
+ });
7216
7217
  const getGenericBusinessObjectAction = source => {
7217
7218
  var typeAction = source.split("_");
7218
7219
  return typeAction.length === 2 ? `businessObject_${typeAction[1]}` : source;
@@ -7368,7 +7369,7 @@ const useDataSourceQuery = (dataSource, parameters, options, templateContext) =>
7368
7369
  return runQuery(dataSource, parameters, templateContext);
7369
7370
  };
7370
7371
  const fetchStrategy = configuration && typeof configuration.endPoint === "function" ? configuration.endPoint : fetch;
7371
- return useQuery([dataSource, parameters], fetchStrategy, _extends({}, (configuration == null ? void 0 : configuration.options) || {}, options, {
7372
+ return useQuery([dataSource, parameters], promisifyRequest(fetchStrategy), _extends({}, (configuration == null ? void 0 : configuration.options) || {}, options, {
7372
7373
  onError: logger(options == null ? void 0 : options.onError)
7373
7374
  }));
7374
7375
  };
@@ -7391,12 +7392,11 @@ const useDataSourceInfiniteQuery = (dataSource, parameters, initialParameters, o
7391
7392
  const configuration = getConfiguration(dataSource);
7392
7393
  const fetch = ({
7393
7394
  pageParam: _pageParam = initialParameters
7394
- }) => {
7395
- return runQuery(dataSource, _extends({}, parameters, _pageParam));
7396
- };
7395
+ }) => runQuery(dataSource, _extends({}, parameters, _pageParam));
7397
7396
  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)
7397
+ return useInfiniteQuery([dataSource, parameters], promisifyRequest(fetchStrategy), _extends({}, configuration ? configuration.options : {}, options, {
7398
+ onError: logger(options == null ? void 0 : options.onError),
7399
+ retry: false
7400
7400
  }));
7401
7401
  };
7402
7402
 
@@ -7415,7 +7415,6 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7415
7415
  var _mutationOptions;
7416
7416
  const queryClient = useQueryClient();
7417
7417
  const configuration = getConfiguration(dataSource);
7418
- getEndpoint(dataSource, configuration);
7419
7418
  const invalidateFunction = () => {
7420
7419
  if (invalidateQueries) {
7421
7420
  for (let q of invalidateQueries) {
@@ -7442,11 +7441,11 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7442
7441
  };
7443
7442
  }
7444
7443
  function requestCall(requestBody) {
7445
- const request = axios[httpMethodType];
7444
+ const request = http[httpMethodType];
7446
7445
  const endPoint = getEndpoint(dataSource, configuration); //?
7447
7446
  if (httpMethodType === "get" || httpMethodType === "delete") {
7448
7447
  // INFO (Caveat!): requestBody is used as query param in case of
7449
- // httpMethodType is get or delete
7448
+ // httpMethodType is GET or DELETE
7450
7449
  const params = _extends({}, baseParameters, requestBody);
7451
7450
  return request(endPoint, {
7452
7451
  params
@@ -7454,7 +7453,7 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7454
7453
  }
7455
7454
  return request(endPoint, requestBody);
7456
7455
  }
7457
- return useMutation(requestCall, _extends({}, mutationOptions, {
7456
+ return useMutation(promisifyRequest(requestCall), _extends({}, mutationOptions, {
7458
7457
  onError: logger((_mutationOptions = mutationOptions) == null ? void 0 : _mutationOptions.onError)
7459
7458
  }));
7460
7459
  };
@@ -11278,7 +11277,8 @@ const BusinessObjectPicker = _ref => {
11278
11277
  tooltipText: option.description,
11279
11278
  size: props.size === "medium" || props.size === "small" ? "small" : "large",
11280
11279
  onDelete: () => handleTagDelete(option),
11281
- canDelete: true
11280
+ canDelete: true,
11281
+ displayType: "default"
11282
11282
  })
11283
11283
  }, getKey(option))), [props.size, getKey, getLabel, handleTagDelete]);
11284
11284
  const renderTypeTags = useCallback(value => value.map(option => /*#__PURE__*/jsx(Box$1, {
@@ -11327,7 +11327,11 @@ const BusinessObjectPicker = _ref => {
11327
11327
  value: value,
11328
11328
  renderOption: renderOptionProp || (props.type ? renderBusinessObject : renderOption),
11329
11329
  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",
11330
+ getOptionDisabled: optionItem => {
11331
+ if (props.disabled) return true;
11332
+ const type = optionItem == null ? void 0 : optionItem.__type;
11333
+ return type === "loadMore" || type === "noOption";
11334
+ },
11331
11335
  handleHomeEndKeys: true
11332
11336
  // INFO: freeSolo prevents warning:
11333
11337
  // https://stackoverflow.com/questions/61947941/material-ui-autocomplete-warning-the-value-provided-to-autocomplete-is-invalid
@@ -11355,7 +11359,7 @@ const BusinessObjectPicker = _ref => {
11355
11359
  style: {
11356
11360
  color: red[500]
11357
11361
  }
11358
- }), listSelect !== true && /*#__PURE__*/jsx(IconButton$1, {
11362
+ }), listSelect !== true && /*#__PURE__*/jsx(IconButton, {
11359
11363
  "aria-label": open ? `hide options` : "show options",
11360
11364
  size: "small",
11361
11365
  onClick: () => {
@@ -11368,7 +11372,7 @@ const BusinessObjectPicker = _ref => {
11368
11372
  [classes.expandOpen]: open
11369
11373
  })
11370
11374
  })
11371
- }), enhancedSearch && /*#__PURE__*/jsx(IconButton$1, {
11375
+ }), enhancedSearch && /*#__PURE__*/jsx(IconButton, {
11372
11376
  "aria-label": "search",
11373
11377
  size: "small",
11374
11378
  onKeyDown: handleKeyDown,
@@ -11376,6 +11380,7 @@ const BusinessObjectPicker = _ref => {
11376
11380
  name: events.OPEN_ENHANCED_SEARCH_DIALOG,
11377
11381
  payload: true
11378
11382
  }),
11383
+ disabled: props.disabled,
11379
11384
  children: /*#__PURE__*/jsx(Search, {})
11380
11385
  })]
11381
11386
  })
@@ -11398,13 +11403,14 @@ const BusinessObjectPicker = _ref => {
11398
11403
  flexDirection: "column",
11399
11404
  padding: 1
11400
11405
  },
11401
- children: /*#__PURE__*/jsx(IconButton$1, {
11406
+ children: /*#__PURE__*/jsx(IconButton, {
11402
11407
  onClick: () => {
11403
11408
  eventDispatch({
11404
11409
  name: events.OPEN_ADD_ITEM_DIALOG,
11405
11410
  payload: true
11406
11411
  });
11407
11412
  },
11413
+ disabled: props.disabled,
11408
11414
  children: /*#__PURE__*/jsx(AddIcon, {
11409
11415
  sx: {
11410
11416
  color: "grey"