aefis-core-ui 2.2.3-rc5 → 2.2.3-rc7

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.
@@ -3296,12 +3296,12 @@ const outcomeConfiguration = {
3296
3296
  // about solution: https://stackoverflow.com/questions/22820162/mustache-js-escaping
3297
3297
  mustache.escape = _ => _;
3298
3298
  function compile() {}
3299
- function render$2(template, data, defaultValue) {
3299
+ function render$1(template, data, defaultValue) {
3300
3300
  return template ? mustache.render(template, data) : defaultValue;
3301
3301
  }
3302
3302
  var template = {
3303
3303
  compile,
3304
- render: render$2
3304
+ render: render$1
3305
3305
  };
3306
3306
 
3307
3307
  // Copyright (c) 2020 AEFIS, all rights reserved.
@@ -7663,69 +7663,6 @@ TextSearch.propTypes = {
7663
7663
  bottomGutter: PropTypes.number
7664
7664
  };
7665
7665
 
7666
- const {
7667
- render: render$1
7668
- } = template;
7669
-
7670
- /**
7671
- * This function returns unique field inside filter item using render.
7672
- *
7673
- * @param {object} item
7674
- * @param {object} filter
7675
- * @returns {string}
7676
- */
7677
- const getFilterItemId = (item, configItem = {}) => {
7678
- var _item$data;
7679
- if (item.id) {
7680
- return item.id;
7681
- }
7682
- const template = configItem.idTemplate || configItem.template || configItem.optionTemplate;
7683
- if (template) {
7684
- return render$1(template, item.data || item);
7685
- }
7686
- if ((_item$data = item.data) != null && _item$data.id) {
7687
- return item.data.id;
7688
- }
7689
- };
7690
-
7691
- /**
7692
- * This function checks filter items; if index and id fields are missing then
7693
- * try to sets them with possible ways.
7694
- *
7695
- * @param {array} filters
7696
- * @param {array} configuration
7697
- * @returns {array}
7698
- */
7699
- const formatFilters = (filters = [], configuration = []) => filters.map(filter => {
7700
- var _ref, _filter$index, _filter$id, _configuration$index, _configuration$index2, _configuration$index3, _configuration$index4, _configuration$index5;
7701
- // TODO: index should be defined on filters. There should not be need of
7702
- // search of index value throught type or map values.
7703
- const index = (_ref = (_filter$index = filter == null ? void 0 : filter.index) != null ? _filter$index : findIndexByType(filter, configuration)) != null ? _ref : findIndexByMap(filter, configuration);
7704
- const id = (_filter$id = filter == null ? void 0 : filter.id) != null ? _filter$id : getFilterItemId(filter, configuration[index]);
7705
-
7706
- // TODO: These properties should ONLY be defined either in configuration
7707
- // or filters; currently data can be defined from both sources. Filter
7708
- // data prioritised over configuratuon.
7709
- const {
7710
- map = (_configuration$index = configuration[index]) == null ? void 0 : _configuration$index.map,
7711
- type = (_configuration$index2 = configuration[index]) == null ? void 0 : _configuration$index2.type,
7712
- template = (_configuration$index3 = configuration[index]) == null ? void 0 : _configuration$index3.template,
7713
- idTemplate = (_configuration$index4 = configuration[index]) == null ? void 0 : _configuration$index4.idTemplate,
7714
- optionTemplate = (_configuration$index5 = configuration[index]) == null ? void 0 : _configuration$index5.optionTemplate
7715
- } = filter;
7716
- return _extends({}, filter, {
7717
- template,
7718
- idTemplate,
7719
- optionTemplate,
7720
- type,
7721
- map,
7722
- index,
7723
- id
7724
- });
7725
- });
7726
- const findIndexByType = (filter, configuration) => filter.type !== undefined ? configuration.findIndex(config => config.type === filter.type) : undefined;
7727
- const findIndexByMap = (filter, configuration) => filter.map !== undefined ? configuration.findIndex(config => config.map === filter.map) : undefined;
7728
-
7729
7666
  const mapFilters = newFilters => {
7730
7667
  const mappedFilters = {};
7731
7668
  newFilters.map(filter => {
@@ -8100,7 +8037,8 @@ const FilterChips = ({
8100
8037
  const Filters = useMemo(() => {
8101
8038
  return /*#__PURE__*/jsx(Box$1, {
8102
8039
  sx: {
8103
- display: "flex"
8040
+ display: "flex",
8041
+ flexFlow: "wrap"
8104
8042
  },
8105
8043
  children: _filters.map(filter => /*#__PURE__*/jsx(Grow, {
8106
8044
  in: true,
@@ -8115,7 +8053,7 @@ const FilterChips = ({
8115
8053
  displayOptions: {
8116
8054
  hasIcon: filter.type !== "keyword"
8117
8055
  },
8118
- type: "businessObject",
8056
+ type: filter.type || "businessObject",
8119
8057
  template: filter.template,
8120
8058
  data: filter.data,
8121
8059
  onDelete: () => {
@@ -8126,7 +8064,11 @@ const FilterChips = ({
8126
8064
  }, `filterPanelFilter-${filter.index}-${filter.id}`))
8127
8065
  });
8128
8066
  }, [_filters]);
8129
- const SortItems = useMemo(() => /*#__PURE__*/jsx(Fragment, {
8067
+ const SortItems = useMemo(() => /*#__PURE__*/jsx(Box$1, {
8068
+ sx: {
8069
+ display: "flex",
8070
+ flexFlow: "wrap"
8071
+ },
8130
8072
  children: _sort.map(sortItem => /*#__PURE__*/jsx(Grow, {
8131
8073
  in: true,
8132
8074
  children: /*#__PURE__*/jsx("div", {
@@ -8364,6 +8306,36 @@ PanelDisplay.propTypes = {
8364
8306
  renderFilterSelection: PropTypes.bool
8365
8307
  };
8366
8308
 
8309
+ const usePrevState = (callback, current) => {
8310
+ const [prev, setPrev] = useState(current);
8311
+ if (prev !== current) {
8312
+ callback(prev, current);
8313
+ setPrev(current);
8314
+ }
8315
+ };
8316
+
8317
+ const useFilterState = filtersProp => {
8318
+ const [filters, _setFilters] = useState(filtersProp);
8319
+ const setFilters = useCallback((filters = []) => {
8320
+ const sorted = filters.sort((a, b) => a.index - b.index);
8321
+ _setFilters(sorted);
8322
+ }, []);
8323
+ usePrevState(() => {
8324
+ setFilters(filtersProp);
8325
+ }, filtersProp);
8326
+ return [filters, setFilters];
8327
+ };
8328
+
8329
+ const getItemId = (item, filter) => item.id || template.render(filter.idTemplate || filter.optionTemplate, item);
8330
+ const formatFilterItem = (index, filter, data) => ({
8331
+ index: index,
8332
+ id: getItemId(data, filter),
8333
+ type: filter.type,
8334
+ template: filter.optionTemplate,
8335
+ idTemplate: filter.idTemplate,
8336
+ map: filter.map,
8337
+ data
8338
+ });
8367
8339
  const mapSort = value => value.map(i => i.map);
8368
8340
  const getSearchFilter = newFilters => (newFilters == null ? void 0 : newFilters.filter(filter => (filter == null ? void 0 : filter.type) === "keyword").map(item => item.data.id)) || [];
8369
8341
 
@@ -8382,7 +8354,7 @@ const FilterPanel = props => {
8382
8354
  searchTooltip,
8383
8355
  searchPlaceHolderText,
8384
8356
  configuration,
8385
- filters: filtersProp,
8357
+ filters: filtersProp = [],
8386
8358
  displayType,
8387
8359
  limitTags,
8388
8360
  bottomGutter,
@@ -8392,14 +8364,10 @@ const FilterPanel = props => {
8392
8364
  sort: sortProp
8393
8365
  } = props;
8394
8366
  const [menuPosition, setMenuPosition] = useState(null);
8395
- const [filters, setFilters] = useState([]);
8367
+ const [filters, setFilters] = useFilterState(filtersProp);
8396
8368
  const [sort, setSort] = useState(sortProp || []);
8397
8369
  const [panelSearch, setPanelSearch] = useState([]);
8398
8370
  const [pickerFilters, setPickerFilters] = useState([]);
8399
- useEffect(() => {
8400
- const formattedFilters = formatFilters(filtersProp, configuration);
8401
- setFilters(formattedFilters);
8402
- }, [filtersProp]);
8403
8371
 
8404
8372
  // TODO: replace it with useMemo
8405
8373
  useEffect(() => {
@@ -8425,9 +8393,8 @@ const FilterPanel = props => {
8425
8393
  onDataChange(filteredData, filterParameters, filters);
8426
8394
  }
8427
8395
  }, [filters, sort]);
8428
- const removeFilter = filter => {
8429
- console.log("remove filter ", filter);
8430
- const newFilterArray = filters == null ? void 0 : filters.filter(i => i.index !== filter.index || filter.id !== i.id);
8396
+ const removeFilter = (filter = []) => {
8397
+ const newFilterArray = filters.filter(i => i.index !== filter.index || filter.id !== i.id);
8431
8398
  setFilters(newFilterArray);
8432
8399
  if (!onApplyFilters) {
8433
8400
  if ((filter == null ? void 0 : filter.type) === "keyword" && onSearchChange) {
@@ -8464,69 +8431,14 @@ const FilterPanel = props => {
8464
8431
  onChange(mapFilters(newFilterArray), newFilterArray);
8465
8432
  }
8466
8433
  };
8467
- /** Had to revert this function as filters were not working properly
8468
- const handleSetFilterType = (inputIndex, configItem, data = []) => {
8469
- const newFiltersByUpdatedIndex = data.map((filterItem) => {
8470
- return {
8471
- index: inputIndex,
8472
- id: filterItem.id || getFilterItemId(configItem, filterItem),
8473
- type: configItem.type,
8474
- template: configItem.optionTemplate,
8475
- idTemplate: configItem.idTemplate,
8476
- map: configItem.map,
8477
- data: filterItem
8478
- };
8479
- });
8480
- const filtersByUnupdatedIndex = filters.filter((i) => i.index !== inputIndex);
8481
- const newFilters = [...filtersByUnupdatedIndex, ...newFiltersByUpdatedIndex];
8482
- setFilters(newFilters);
8483
- if (onChange) {
8484
- // TO-CHECK: what does mapFilters do?
8485
- onChange(mapFilters(newFilters), newFilters);
8486
- }
8487
- }; */
8488
-
8489
8434
  const handleSetFilterType = (index, filter, data) => {
8490
- const getItemId = item => item.id || template.render(filter.idTemplate || filter.optionTemplate, item);
8491
- if (!Array.isArray(data)) {
8492
- const _newFilterArray = filters.filter(i => index !== i.index);
8493
- if (data) {
8494
- const newItemId = getItemId(data);
8495
- _newFilterArray.push({
8496
- index: index,
8497
- id: newItemId,
8498
- type: filter.type,
8499
- template: filter.optionTemplate,
8500
- idTemplate: filter.idTemplate,
8501
- map: filter.map,
8502
- data: data
8503
- });
8504
- }
8505
- setFilters(_newFilterArray);
8506
- if (onChange && !onApplyFilters) {
8507
- onChange(mapFilters(_newFilterArray), _newFilterArray);
8508
- }
8509
- return;
8510
- }
8511
- data.map(item => {
8512
- const newItemId = getItemId(item);
8513
- if (!filters.find(i => i.index === index && i.id === newItemId)) {
8514
- filters.push({
8515
- index: index,
8516
- id: newItemId,
8517
- type: filter.type,
8518
- template: filter.optionTemplate,
8519
- idTemplate: filter.idTemplate,
8520
- map: filter.map,
8521
- data: item
8522
- });
8523
- }
8524
- });
8525
- const newFilterArray = filters.filter(i => index !== i.index || index === i.index && data.find(d => i.data.id === d.id));
8526
- setFilters(newFilterArray);
8527
- if (onChange && !onApplyFilters) {
8528
- onChange(mapFilters(newFilterArray), newFilterArray);
8529
- }
8435
+ let _data = data;
8436
+ if (!Array.isArray(data)) _data = data ? [data] : [];
8437
+ const filtersWithoutUpdatedField = filters.filter(filter => index !== filter.index);
8438
+ const newUpdatedFilters = _data.map(d => formatFilterItem(index, filter, d));
8439
+ const newFilters = filtersWithoutUpdatedField.concat(newUpdatedFilters);
8440
+ setFilters(newFilters);
8441
+ if (!onApplyFilters) onChange == null ? void 0 : onChange(mapFilters(newFilters), newFilters);
8530
8442
  };
8531
8443
  const handleSortChange = value => {
8532
8444
  setSort(value);
@@ -9962,13 +9874,13 @@ const Drawer = props => {
9962
9874
  };
9963
9875
  const theme = useTheme$1();
9964
9876
  const appBarStyle = {
9965
- primary: {
9877
+ primary: _extends({
9966
9878
  color: "#ffffff"
9967
- },
9968
- secondary: {
9879
+ }, props.appBarStyle),
9880
+ secondary: _extends({
9969
9881
  backgroundColor: "#ffffff",
9970
9882
  color: "#333333"
9971
- }
9883
+ }, props.appBarStyle)
9972
9884
  };
9973
9885
  const closeDrawerIconStyle = {
9974
9886
  color: props.headerColor === "secondary" ? "rgba(0, 0, 0, 0.54)" : "#ffffff",
@@ -10176,6 +10088,8 @@ Drawer.propTypes = {
10176
10088
  menuPositionOffset: PropTypes.oneOf(["none", "primaryMenu", "secondaryMenu"]),
10177
10089
  /** Additional styles to apply to the drawer paper. */
10178
10090
  paperStyle: PropTypes.any,
10091
+ /** Additional styles to apply to the appbar. */
10092
+ appBarStyle: PropTypes.any,
10179
10093
  /** Whether or not to show the header divider */
10180
10094
  headerDivider: PropTypes.bool,
10181
10095
  /** The component to use while rendering the drawer title */