aefis-core-ui 2.2.3-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';
@@ -5296,8 +5296,7 @@ const useStyles$y = makeStyles(theme => ({
5296
5296
  root: {
5297
5297
  margin: 0,
5298
5298
  padding: theme.spacing(2),
5299
- position: "relative",
5300
- minHeight: 60
5299
+ position: "relative"
5301
5300
  },
5302
5301
  closeButton: {
5303
5302
  position: "absolute",
@@ -6882,12 +6881,9 @@ const sanitizedEval = (code, context, options) => {
6882
6881
  }
6883
6882
  };
6884
6883
 
6884
+ // TODO: move this to a state
6885
6885
  let token = "";
6886
- const apiClient = axios.create({
6887
- validateStatus: false
6888
- //baseURL: process.env.NODE_ENV === "development" ? "" : "/ui"
6889
- });
6890
-
6886
+ const apiClient = axios.create({});
6891
6887
  const parseQueryParam = url => {
6892
6888
  const hashIndex = url.indexOf("#");
6893
6889
  const noHashExists = hashIndex === -1;
@@ -6934,44 +6930,11 @@ apiClient.interceptors.request.use(config => {
6934
6930
  for (const key in queryParams) {
6935
6931
  queryParams[key] = objectParse(queryParams[key]);
6936
6932
  }
6937
- config.params = _.merge(queryParams, config.params);
6933
+ config.params = merge(queryParams, config.params);
6938
6934
  config.url = urlOrigin;
6939
6935
  }
6940
6936
  return config;
6941
6937
  });
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
6938
  function download(url) {
6976
6939
  apiClient.request({
6977
6940
  url: url,
@@ -6992,33 +6955,32 @@ function download(url) {
6992
6955
  link.remove();
6993
6956
  });
6994
6957
  }
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);
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
+ }));
7003
6965
  }
7004
- function post() {
7005
- return apiClient.post(...arguments);
6966
+ function post(...args) {
6967
+ return apiClient.post(...args);
7006
6968
  }
7007
- function put() {
7008
- return apiClient.put(...arguments);
6969
+ function put(...args) {
6970
+ return apiClient.put(...args);
7009
6971
  }
7010
- function destroy() {
7011
- return apiClient.destroy(...arguments);
6972
+ function destroy(...args) {
6973
+ return apiClient.delete(...args);
7012
6974
  }
7013
6975
  async function setUserToken(t) {
7014
6976
  token = t;
7015
6977
  }
7016
6978
  var http = {
7017
- get: loggerForwardError(get),
7018
- post: loggerForwardError(post),
7019
- put: loggerForwardError(put),
7020
- download: loggerForwardError(download),
7021
- delete: loggerForwardError(destroy),
6979
+ get,
6980
+ post,
6981
+ put,
6982
+ download,
6983
+ delete: destroy,
7022
6984
  setUserToken
7023
6985
  };
7024
6986
 
@@ -7200,6 +7162,23 @@ let dataSourceConfiguration = {
7200
7162
  }
7201
7163
  };
7202
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
+
7203
7182
  /**
7204
7183
  * wraps function and reports (fire request) to Logger
7205
7184
  * @param {function} onError
@@ -7208,11 +7187,29 @@ let dataSourceConfiguration = {
7208
7187
  const logger = onError => (error, ...rest) => {
7209
7188
  var _window$logger;
7210
7189
  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);
7190
+ (_window$logger = window.logger) == null ? void 0 : _window$logger.sendLog({
7191
+ name: getLoggerErrorMessage(error),
7192
+ data: error
7193
+ });
7215
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
+ });
7216
7213
  const getGenericBusinessObjectAction = source => {
7217
7214
  var typeAction = source.split("_");
7218
7215
  return typeAction.length === 2 ? `businessObject_${typeAction[1]}` : source;
@@ -7368,7 +7365,7 @@ const useDataSourceQuery = (dataSource, parameters, options, templateContext) =>
7368
7365
  return runQuery(dataSource, parameters, templateContext);
7369
7366
  };
7370
7367
  const fetchStrategy = configuration && typeof configuration.endPoint === "function" ? configuration.endPoint : fetch;
7371
- 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, {
7372
7369
  onError: logger(options == null ? void 0 : options.onError)
7373
7370
  }));
7374
7371
  };
@@ -7391,12 +7388,11 @@ const useDataSourceInfiniteQuery = (dataSource, parameters, initialParameters, o
7391
7388
  const configuration = getConfiguration(dataSource);
7392
7389
  const fetch = ({
7393
7390
  pageParam: _pageParam = initialParameters
7394
- }) => {
7395
- return runQuery(dataSource, _extends({}, parameters, _pageParam));
7396
- };
7391
+ }) => runQuery(dataSource, _extends({}, parameters, _pageParam));
7397
7392
  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)
7393
+ return useInfiniteQuery([dataSource, parameters], promisifyRequest(fetchStrategy), _extends({}, configuration ? configuration.options : {}, options, {
7394
+ onError: logger(options == null ? void 0 : options.onError),
7395
+ retry: false
7400
7396
  }));
7401
7397
  };
7402
7398
 
@@ -7415,7 +7411,6 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7415
7411
  var _mutationOptions;
7416
7412
  const queryClient = useQueryClient();
7417
7413
  const configuration = getConfiguration(dataSource);
7418
- getEndpoint(dataSource, configuration);
7419
7414
  const invalidateFunction = () => {
7420
7415
  if (invalidateQueries) {
7421
7416
  for (let q of invalidateQueries) {
@@ -7442,11 +7437,11 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7442
7437
  };
7443
7438
  }
7444
7439
  function requestCall(requestBody) {
7445
- const request = axios[httpMethodType];
7440
+ const request = http[httpMethodType];
7446
7441
  const endPoint = getEndpoint(dataSource, configuration); //?
7447
7442
  if (httpMethodType === "get" || httpMethodType === "delete") {
7448
7443
  // INFO (Caveat!): requestBody is used as query param in case of
7449
- // httpMethodType is get or delete
7444
+ // httpMethodType is GET or DELETE
7450
7445
  const params = _extends({}, baseParameters, requestBody);
7451
7446
  return request(endPoint, {
7452
7447
  params
@@ -7454,7 +7449,7 @@ const useDataSourceMutation = (dataSource, baseParameters, options, invalidateQu
7454
7449
  }
7455
7450
  return request(endPoint, requestBody);
7456
7451
  }
7457
- return useMutation(requestCall, _extends({}, mutationOptions, {
7452
+ return useMutation(promisifyRequest(requestCall), _extends({}, mutationOptions, {
7458
7453
  onError: logger((_mutationOptions = mutationOptions) == null ? void 0 : _mutationOptions.onError)
7459
7454
  }));
7460
7455
  };
@@ -10751,7 +10746,7 @@ const RichDataTable = /*#__PURE__*/forwardRef(function RichDatatable(props, ref)
10751
10746
  exportOptions: props.exportOptions,
10752
10747
  actions: props.actions && props.actions.length > 0 || props.addAction ? updateActions(props.actions, handleDrawerOpen, enableTableRowAction, selectedRowCount, Add) : undefined,
10753
10748
  onFilterClick: isFilterPanelEnabled ? handleFilterClick : undefined,
10754
- hasFilters: filterPanelState.filterCount > 0 || filterPanelState.sortCount > 0 || filterPanelState.searchText,
10749
+ hasFilters: filterPanelState.filterCount > 0 || filterPanelState.sortCount > 0 || !!filterPanelState.searchText,
10755
10750
  disableFilterButton: isFetching
10756
10751
  }, props.titleAndActionHeaderProps)), /*#__PURE__*/jsx(DataTable, _extends({}, props, {
10757
10752
  tableRef: DataTableRef,
@@ -14659,7 +14654,36 @@ Header.propTypes = {
14659
14654
  allStepsCompleted: PropTypes.bool
14660
14655
  };
14661
14656
 
14657
+ // Copyright (c) 2022 HelioCampus Inc., all rights reserved.
14662
14658
  const useStyles$5 = makeStyles(theme => ({
14659
+ container: {
14660
+ position: "absolute",
14661
+ overflowY: "auto",
14662
+ left: 0,
14663
+ right: 0,
14664
+ bottom: 64,
14665
+ top: 178
14666
+ },
14667
+ tabBar: {
14668
+ borderBottom: "1px solid rgba(0, 0, 0, 0.12)",
14669
+ zIndex: 1,
14670
+ background: "#ffffff",
14671
+ padding: theme.spacing(2)
14672
+ },
14673
+ scrolledTabBar: {
14674
+ zIndex: 1,
14675
+ borderBottom: "none",
14676
+ background: "#ffffff",
14677
+ padding: theme.spacing(2),
14678
+ boxShadow: "0px 2px 4px -4px rgba(0,0,0,0.2), 0px 4px 5px 0px rgba(0,0,0,0.14), 0px 1px 10px -10px rgba(0,0,0,0.12)"
14679
+ },
14680
+ bottomBar: {
14681
+ borderTop: "1px solid rgba(0, 0, 0, 0.12)"
14682
+ },
14683
+ scrolledBottomBar: {
14684
+ borderTop: "none",
14685
+ boxShadow: "0px -4px 8px -4px rgba(0,0,0,0.12)"
14686
+ },
14663
14687
  buttonContainer: {
14664
14688
  marginLeft: "auto",
14665
14689
  display: "flex"
@@ -14672,7 +14696,7 @@ const useStyles$5 = makeStyles(theme => ({
14672
14696
  marginRight: 8
14673
14697
  }
14674
14698
  }));
14675
- const bottomBarDefaultStyle = {
14699
+ const bottomBarStyle = {
14676
14700
  background: "#ffffff",
14677
14701
  display: "flex",
14678
14702
  minHeight: 64,
@@ -14688,7 +14712,7 @@ const bottomBarDefaultStyle = {
14688
14712
  right: 0
14689
14713
  };
14690
14714
 
14691
- /** Component to display a "stepper" wizard panel for multiple step processes with swipeable tabs. Designed to be display within a Drawer component. */
14715
+ /** Component to display a "stepper" wizard panel for multiple step proceses with swipeable tabs. Designed to be display within a Drawer component. */
14692
14716
 
14693
14717
  const WizardPanel = props => {
14694
14718
  var _props$panels;
@@ -14720,34 +14744,9 @@ const WizardPanel = props => {
14720
14744
  props.onComplete && props.onComplete();
14721
14745
  };
14722
14746
  const theme = useTheme$1();
14723
- const stepsContainer = {
14724
- position: "absolute",
14725
- overflowY: "auto",
14726
- left: 0,
14727
- right: 0,
14728
- bottom: 64,
14729
- top: 178
14730
- };
14731
14747
  const containerStyle = {
14732
14748
  backgroundColor: props.cardContent ? "rgb(239, 242, 246)" : "rgb(255,255,255)"
14733
14749
  };
14734
- const tabBarStyle = {
14735
- borderBottom: "1px solid rgba(0, 0, 0, 0.12)",
14736
- zIndex: 1,
14737
- background: "#ffffff",
14738
- padding: props.display === "drawer" ? 2 : "0px 0px 16px 0px"
14739
- };
14740
- const scrolledTabBarStyle = {
14741
- zIndex: 1,
14742
- borderBottom: "none",
14743
- background: "#ffffff",
14744
- padding: props.display === "drawer" ? 2 : "0px 0px 16px 0px",
14745
- boxShadow: "0px 2px 4px -4px rgba(0,0,0,0.2), 0px 4px 5px 0px rgba(0,0,0,0.14), 0px 1px 10px -10px rgba(0,0,0,0.12)"
14746
- };
14747
- const bottomBarStyle = _extends({}, bottomBarDefaultStyle, {
14748
- borderTop: "none",
14749
- boxShadow: props.display === "drawer" ? "0px -4px 8px -4px rgba(0,0,0,0.12)" : "none"
14750
- });
14751
14750
  useEffect(() => {
14752
14751
  var _containerRef$current;
14753
14752
  (_containerRef$current = containerRef.current) == null ? void 0 : _containerRef$current.scrollTo == null ? void 0 : _containerRef$current.scrollTo({
@@ -14761,9 +14760,9 @@ const WizardPanel = props => {
14761
14760
  }, [props.completed]);
14762
14761
  return /*#__PURE__*/jsxs(Fragment, {
14763
14762
  children: [/*#__PURE__*/jsx(AppBar$1, {
14764
- position: props.display === "drawer" ? "sticky" : "relative",
14763
+ position: "sticky",
14765
14764
  component: "div",
14766
- sx: scrollTrigger ? scrolledTabBarStyle : tabBarStyle,
14765
+ className: scrollTrigger ? classes.scrolledTabBar : classes.tabBar,
14767
14766
  elevation: 0,
14768
14767
  color: "default",
14769
14768
  children: /*#__PURE__*/jsx(Header, {
@@ -14774,7 +14773,7 @@ const WizardPanel = props => {
14774
14773
  }), /*#__PURE__*/jsx(Box$1, {
14775
14774
  ref: containerRef,
14776
14775
  sx: containerStyle,
14777
- style: props.display === "drawer" ? stepsContainer : undefined,
14776
+ className: classes.container,
14778
14777
  children: /*#__PURE__*/jsx(SwipeableViews, {
14779
14778
  axis: theme.direction === "rtl" ? "x-reverse" : "x",
14780
14779
  index: activeStep,
@@ -14791,6 +14790,7 @@ const WizardPanel = props => {
14791
14790
  })
14792
14791
  }), /*#__PURE__*/jsx(Box$1, {
14793
14792
  style: bottomBarStyle,
14793
+ className: classes.scrolledBottomBar,
14794
14794
  children: /*#__PURE__*/jsxs(Box$1, {
14795
14795
  className: classes.buttonContainer,
14796
14796
  children: [/*#__PURE__*/jsx(Button, {
@@ -14851,12 +14851,9 @@ WizardPanel.defaultProps = {
14851
14851
  completed: false,
14852
14852
  completeButtonText: "Finish",
14853
14853
  disableComplete: false,
14854
- completing: false,
14855
- display: "drawer"
14854
+ completing: false
14856
14855
  };
14857
14856
  WizardPanel.propTypes = {
14858
- /** Where to display the panel, a dialog or drawer. */
14859
- display: PropTypes.oneOf(["drawer"], ["dialog"]),
14860
14857
  /** The data defining the wizard steps and content. */
14861
14858
  panels: PropTypes.arrayOf(PropTypes.shape({
14862
14859
  id: PropTypes.any.isRequired,
@@ -17289,6 +17286,9 @@ const Upload = props => {
17289
17286
  type: (message == null ? void 0 : message.type) || "info",
17290
17287
  canDismiss: (message == null ? void 0 : message.canDismiss) || true
17291
17288
  };
17289
+ const {
17290
+ error
17291
+ } = useNotify();
17292
17292
  const filePondProps = {
17293
17293
  acceptedFileTypes: acceptedFileTypes ? acceptedFileTypes : isImage ? ["image/*"] : null,
17294
17294
  files,
@@ -17300,7 +17300,16 @@ const Upload = props => {
17300
17300
  headers: {
17301
17301
  Methods: "POST"
17302
17302
  },
17303
- 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
+ }
17304
17313
  },
17305
17314
  load: handleLoad,
17306
17315
  revert: handleDelete