aefis-core-ui 2.2.2-rc4 → 2.3.0-rc1

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.
@@ -42,7 +42,7 @@ import { AnimatePresence, motion } from 'framer-motion';
42
42
  import CircularProgress$1 from '@mui/material/CircularProgress';
43
43
  import { useQuery, useInfiniteQuery, useQueryClient, useMutation, QueryClient, QueryClientProvider } from 'react-query';
44
44
  import axios from 'axios';
45
- import _ from 'lodash';
45
+ import _, { merge } from 'lodash';
46
46
  import qs from 'query-string';
47
47
  import SortIcon from '@mui/icons-material/Sort';
48
48
  import { useSnackbar, SnackbarProvider } from 'notistack';
@@ -6881,12 +6881,9 @@ const sanitizedEval = (code, context, options) => {
6881
6881
  }
6882
6882
  };
6883
6883
 
6884
+ // TODO: move this to a state
6884
6885
  let token = "";
6885
- const apiClient = axios.create({
6886
- validateStatus: false
6887
- //baseURL: process.env.NODE_ENV === "development" ? "" : "/ui"
6888
- });
6889
-
6886
+ const apiClient = axios.create({});
6890
6887
  const parseQueryParam = url => {
6891
6888
  const hashIndex = url.indexOf("#");
6892
6889
  const noHashExists = hashIndex === -1;
@@ -6933,44 +6930,11 @@ apiClient.interceptors.request.use(config => {
6933
6930
  for (const key in queryParams) {
6934
6931
  queryParams[key] = objectParse(queryParams[key]);
6935
6932
  }
6936
- config.params = _.merge(queryParams, config.params);
6933
+ config.params = merge(queryParams, config.params);
6937
6934
  config.url = urlOrigin;
6938
6935
  }
6939
6936
  return config;
6940
6937
  });
6941
- const getLoggerErrorMessage = error => {
6942
- if (error.response) {
6943
- var _error$response, _error$request, _error$response2, _error$response2$conf, _error$response2$conf2;
6944
- const status = (_error$response = error.response) == null ? void 0 : _error$response.status;
6945
- const URL = (_error$request = error.request) == null ? void 0 : _error$request.responseURL;
6946
- 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();
6947
- const message = `RequestError: [${method}] ${status} ${URL}`;
6948
- return message;
6949
- } else if (error.request) {
6950
- return "RequestError: No Response";
6951
- } else {
6952
- return `RequestError: ${error.message.toString()}`;
6953
- }
6954
- };
6955
-
6956
- // Error is formatted to react query and reporting is handled by react-query
6957
- // This prevent re-tried queries to trigger logger request
6958
- const loggerForwardError = promise => (...args) => {
6959
- return promise(...args).catch(error => {
6960
- if (window.logger) {
6961
- var _error$response3, _error$response3$conf, _window$logger;
6962
- const message = getLoggerErrorMessage(error);
6963
- const requestBody = ((_error$response3 = error.response) == null ? void 0 : (_error$response3$conf = _error$response3.config) == null ? void 0 : _error$response3$conf.data) || null;
6964
- (_window$logger = window.logger) == null ? void 0 : _window$logger.logELKEvent == null ? void 0 : _window$logger.logELKEvent({
6965
- name: message,
6966
- data: requestBody
6967
- });
6968
- throw message;
6969
- } else {
6970
- throw error;
6971
- }
6972
- });
6973
- };
6974
6938
  function download(url) {
6975
6939
  apiClient.request({
6976
6940
  url: url,
@@ -6991,33 +6955,32 @@ function download(url) {
6991
6955
  link.remove();
6992
6956
  });
6993
6957
  }
6994
- function get() {
6995
- let args = [...arguments];
6996
- if (args[0].includes("http://gateway") || args[0].includes("https://gateway")) {
6997
- args[1]["headers"] = {
6998
- Authorization: "Bearer " + token
6999
- };
7000
- }
7001
- return apiClient.get(...args);
6958
+ function get(endPoint, config = {}) {
6959
+ const isGateway = endPoint.includes("http://gateway") || endPoint.includes("https://gateway");
6960
+ return apiClient.get(endPoint, _extends({}, config, {
6961
+ headers: _extends({}, config.headers, isGateway && {
6962
+ Authorization: `Bearer ${token}`
6963
+ })
6964
+ }));
7002
6965
  }
7003
- function post() {
7004
- return apiClient.post(...arguments);
6966
+ function post(...args) {
6967
+ return apiClient.post(...args);
7005
6968
  }
7006
- function put() {
7007
- return apiClient.put(...arguments);
6969
+ function put(...args) {
6970
+ return apiClient.put(...args);
7008
6971
  }
7009
- function destroy() {
7010
- return apiClient.destroy(...arguments);
6972
+ function destroy(...args) {
6973
+ return apiClient.delete(...args);
7011
6974
  }
7012
6975
  async function setUserToken(t) {
7013
6976
  token = t;
7014
6977
  }
7015
6978
  var http = {
7016
- get: loggerForwardError(get),
7017
- post: loggerForwardError(post),
7018
- put: loggerForwardError(put),
7019
- download: loggerForwardError(download),
7020
- delete: loggerForwardError(destroy),
6979
+ get,
6980
+ post,
6981
+ put,
6982
+ download,
6983
+ delete: destroy,
7021
6984
  setUserToken
7022
6985
  };
7023
6986
 
@@ -7199,6 +7162,23 @@ let dataSourceConfiguration = {
7199
7162
  }
7200
7163
  };
7201
7164
 
7165
+ // TODO: move this function to logger
7166
+ const getLoggerErrorMessage = error => {
7167
+ if (!error.isAxiosError) return (error == null ? void 0 : error.toString()) || "Undefined error";
7168
+ if (error.response) {
7169
+ var _error$response, _error$request, _error$response2, _error$response2$conf, _error$response2$conf2;
7170
+ const status = (_error$response = error.response) == null ? void 0 : _error$response.status;
7171
+ const URL = (_error$request = error.request) == null ? void 0 : _error$request.responseURL;
7172
+ 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();
7173
+ const message = `RequestError: [${method}] ${status} ${URL}`;
7174
+ return message;
7175
+ } else if (error.request) {
7176
+ return "RequestError: No Response";
7177
+ } else {
7178
+ return `RequestError: ${error.message.toString()}`;
7179
+ }
7180
+ };
7181
+
7202
7182
  /**
7203
7183
  * wraps function and reports (fire request) to Logger
7204
7184
  * @param {function} onError
@@ -7207,11 +7187,29 @@ let dataSourceConfiguration = {
7207
7187
  const logger = onError => (error, ...rest) => {
7208
7188
  var _window$logger;
7209
7189
  onError == null ? void 0 : onError(error, ...rest);
7210
- const event = {
7211
- name: (error == null ? void 0 : error.toString()) || "Undefined error"
7212
- };
7213
- (_window$logger = window.logger) == null ? void 0 : _window$logger.sendLog == null ? void 0 : _window$logger.sendLog(event);
7190
+ (_window$logger = window.logger) == null ? void 0 : _window$logger.sendLog({
7191
+ name: getLoggerErrorMessage(error),
7192
+ data: error
7193
+ });
7214
7194
  };
7195
+
7196
+ /**
7197
+ * Promisify fetch, this is required for useQuery to handle error properly.
7198
+ * @param {Promise} fetch
7199
+ * @returns Promise
7200
+ */
7201
+ const promisifyRequest = fetch => (...args) => new Promise(async (resolve, reject) => {
7202
+ try {
7203
+ const res = await fetch(...args);
7204
+ resolve(res);
7205
+ } catch (error) {
7206
+ var _window$logger2;
7207
+ reject(error);
7208
+ (_window$logger2 = window.logger) == null ? void 0 : _window$logger2.logEvent({
7209
+ name: getLoggerErrorMessage(error)
7210
+ });
7211
+ }
7212
+ });
7215
7213
  const getGenericBusinessObjectAction = source => {
7216
7214
  var typeAction = source.split("_");
7217
7215
  return typeAction.length === 2 ? `businessObject_${typeAction[1]}` : source;
@@ -7367,7 +7365,7 @@ const useDataSourceQuery = (dataSource, parameters, options, templateContext) =>
7367
7365
  return runQuery(dataSource, parameters, templateContext);
7368
7366
  };
7369
7367
  const fetchStrategy = configuration && typeof configuration.endPoint === "function" ? configuration.endPoint : fetch;
7370
- return useQuery([dataSource, parameters], fetchStrategy, _extends({}, (configuration == null ? void 0 : configuration.options) || {}, options, {
7368
+ return useQuery([dataSource, parameters], promisifyRequest(fetchStrategy), _extends({}, (configuration == null ? void 0 : configuration.options) || {}, options, {
7371
7369
  onError: logger(options == null ? void 0 : options.onError)
7372
7370
  }));
7373
7371
  };
@@ -7390,12 +7388,11 @@ const useDataSourceInfiniteQuery = (dataSource, parameters, initialParameters, o
7390
7388
  const configuration = getConfiguration(dataSource);
7391
7389
  const fetch = ({
7392
7390
  pageParam: _pageParam = initialParameters
7393
- }) => {
7394
- return runQuery(dataSource, _extends({}, parameters, _pageParam));
7395
- };
7391
+ }) => runQuery(dataSource, _extends({}, parameters, _pageParam));
7396
7392
  const fetchStrategy = configuration && typeof configuration.endPoint === "function" ? configuration.endPoint : fetch;
7397
- return useInfiniteQuery([dataSource, parameters], fetchStrategy, _extends({}, configuration ? configuration.options : {}, options, {
7398
- onError: logger(options == null ? void 0 : options.onError)
7393
+ return useInfiniteQuery([dataSource, parameters], promisifyRequest(fetchStrategy), _extends({}, configuration ? configuration.options : {}, options, {
7394
+ onError: logger(options == null ? void 0 : options.onError),
7395
+ retry: false
7399
7396
  }));
7400
7397
  };
7401
7398
 
@@ -7414,7 +7411,6 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7414
7411
  var _mutationOptions;
7415
7412
  const queryClient = useQueryClient();
7416
7413
  const configuration = getConfiguration(dataSource);
7417
- getEndpoint(dataSource, configuration);
7418
7414
  const invalidateFunction = () => {
7419
7415
  if (invalidateQueries) {
7420
7416
  for (let q of invalidateQueries) {
@@ -7441,11 +7437,11 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7441
7437
  };
7442
7438
  }
7443
7439
  function requestCall(requestBody) {
7444
- const request = axios[httpMethodType];
7440
+ const request = http[httpMethodType];
7445
7441
  const endPoint = getEndpoint(dataSource, configuration); //?
7446
7442
  if (httpMethodType === "get" || httpMethodType === "delete") {
7447
7443
  // INFO (Caveat!): requestBody is used as query param in case of
7448
- // httpMethodType is get or delete
7444
+ // httpMethodType is GET or DELETE
7449
7445
  const params = _extends({}, baseParameters, requestBody);
7450
7446
  return request(endPoint, {
7451
7447
  params
@@ -7453,7 +7449,7 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7453
7449
  }
7454
7450
  return request(endPoint, requestBody);
7455
7451
  }
7456
- return useMutation(requestCall, _extends({}, mutationOptions, {
7452
+ return useMutation(promisifyRequest(requestCall), _extends({}, mutationOptions, {
7457
7453
  onError: logger((_mutationOptions = mutationOptions) == null ? void 0 : _mutationOptions.onError)
7458
7454
  }));
7459
7455
  };
@@ -10750,7 +10746,7 @@ const RichDataTable = /*#__PURE__*/forwardRef(function RichDatatable(props, ref)
10750
10746
  exportOptions: props.exportOptions,
10751
10747
  actions: props.actions && props.actions.length > 0 || props.addAction ? updateActions(props.actions, handleDrawerOpen, enableTableRowAction, selectedRowCount, Add) : undefined,
10752
10748
  onFilterClick: isFilterPanelEnabled ? handleFilterClick : undefined,
10753
- hasFilters: filterPanelState.filterCount > 0 || filterPanelState.sortCount > 0 || filterPanelState.searchText,
10749
+ hasFilters: filterPanelState.filterCount > 0 || filterPanelState.sortCount > 0 || !!filterPanelState.searchText,
10754
10750
  disableFilterButton: isFetching
10755
10751
  }, props.titleAndActionHeaderProps)), /*#__PURE__*/jsx(DataTable, _extends({}, props, {
10756
10752
  tableRef: DataTableRef,
@@ -17290,6 +17286,9 @@ const Upload = props => {
17290
17286
  type: (message == null ? void 0 : message.type) || "info",
17291
17287
  canDismiss: (message == null ? void 0 : message.canDismiss) || true
17292
17288
  };
17289
+ const {
17290
+ error
17291
+ } = useNotify();
17293
17292
  const filePondProps = {
17294
17293
  acceptedFileTypes: acceptedFileTypes ? acceptedFileTypes : isImage ? ["image/*"] : null,
17295
17294
  files,
@@ -17301,7 +17300,16 @@ const Upload = props => {
17301
17300
  headers: {
17302
17301
  Methods: "POST"
17303
17302
  },
17304
- onload: handleUploadResponse
17303
+ onload: handleUploadResponse,
17304
+ onerror: e => {
17305
+ var _window$logger;
17306
+ const message = `The image could not be uploaded.`;
17307
+ error(message);
17308
+ (_window$logger = window.logger) == null ? void 0 : _window$logger.sendLog({
17309
+ name: message,
17310
+ data: e
17311
+ });
17312
+ }
17305
17313
  },
17306
17314
  load: handleLoad,
17307
17315
  revert: handleDelete