@michalrakus/x-react-web-lib 1.38.0 → 1.38.2

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.
@@ -202,6 +202,7 @@ exports.XLazyDataTable = (0, react_1.forwardRef)(function (_a, ref) {
202
202
  var createFiltersInit = function () {
203
203
  var e_2, _a;
204
204
  var filtersInit = {};
205
+ // warning note: props.children are used to get props of XLazyColumn whereas dataTableEl.current.props.children are used to get props of Primereact DataTable
205
206
  //let columns = dataTableEl.current.props.children; - does not work
206
207
  var columns = props.children;
207
208
  try {
@@ -358,6 +359,7 @@ exports.XLazyDataTable = (0, react_1.forwardRef)(function (_a, ref) {
358
359
  return filtersInit;
359
360
  };
360
361
  var _y = __read((0, useXStateStorageBase_1.useXStateStorageBase)(props.stateStorage, getStateKey(XStateKeySuffix.filters), filtersInitialStateFunction), 2), filters = _y[0], setFilters = _y[1]; // filtrovanie na "controlled manner" (moze sa sem nainicializovat nejaka hodnota)
362
+ var matchModeChangeFieldRef = (0, react_1.useRef)(null);
361
363
  var initFtsInputValue = props.fullTextSearch ? createInitFtsInputValue() : undefined;
362
364
  var _z = __read((0, useXStateStorage_1.useXStateStorage)(props.stateStorage, getStateKey(XStateKeySuffix.ftsInputValue), initFtsInputValue), 2), ftsInputValue = _z[0], setFtsInputValue = _z[1];
363
365
  var _0 = __read((0, useXStateStorage_1.useXStateStorage)(props.stateStorage, getStateKey(XStateKeySuffix.optionalCustomFilter), undefined), 2), optionalCustomFilter = _0[0], setOptionalCustomFilter = _0[1];
@@ -417,14 +419,62 @@ exports.XLazyDataTable = (0, react_1.forwardRef)(function (_a, ref) {
417
419
  return [2 /*return*/];
418
420
  });
419
421
  }); };
420
- var onFilter = function (event) {
421
- // pozor! tato metoda sa nevola, odkedy vzdy pouzivame filterElement na elemente Column (mame vo filtri vlastne komponenty ktore priamo volaju setFilters(...))
422
- //console.log("zavolany onFilter - this.state.filters = " + JSON.stringify(filters));
423
- //console.log("zavolany onFilter - event.filters = " + JSON.stringify(event.filters));
422
+ var onFilter = function (e) {
423
+ // HEY! this method is not called (on filter value change) since we use filterElement on component Column (in filter there are always custom components those call direct setFilters(...))
424
+ // this method is called (probably) only when user changes match mode
425
+ //console.log("called onFilter - this.state.filters = " + JSON.stringify(filters));
426
+ //console.log("called onFilter - event.filters = " + JSON.stringify(e.filters));
427
+ var filtersChanged = false;
428
+ var changedField = matchModeChangeFieldRef.current;
429
+ if (changedField) {
430
+ // method onFilterMatchModeChange was called (user changed match mode)
431
+ var filterValueOld = filters[changedField];
432
+ var filterValue = e.filters[changedField];
433
+ if (filterValueOld && filterValue) { // should be always true
434
+ var xFilterValueOld = filterValueOld; // works only for filterDisplay="row"
435
+ var xFilterValue = filterValue; // works only for filterDisplay="row"
436
+ if (xFilterValue.matchMode !== xFilterValueOld.matchMode) {
437
+ var isNotNullValueAlias = "<".concat((0, XLocale_1.xLocaleOption)('xIsNotNull'), ">");
438
+ var isNullValueAlias = "<".concat((0, XLocale_1.xLocaleOption)('xIsNull'), ">");
439
+ var xFilterMatchMode = xFilterValue.matchMode;
440
+ if (xFilterMatchMode === FindParam_1.XFilterMatchMode.X_IS_NOT_NULL || xFilterMatchMode === FindParam_1.XFilterMatchMode.X_IS_NULL) {
441
+ var newValue = null;
442
+ // for string types we set alias, for other types we set null (alias is not displayed -> NaN or Invalid date are displayed)
443
+ var xField = XUtilsMetadataCommon_1.XUtilsMetadataCommon.getXFieldByPath(xEntity, changedField);
444
+ if (xField.type === "string" || xField.type === "jsonb") {
445
+ if (xFilterMatchMode === FindParam_1.XFilterMatchMode.X_IS_NOT_NULL) {
446
+ newValue = isNotNullValueAlias;
447
+ }
448
+ else {
449
+ // xFilterMatchMode === XFilterMatchMode.X_IS_NULL
450
+ newValue = isNullValueAlias;
451
+ }
452
+ }
453
+ xFilterValue.value = newValue;
454
+ filtersChanged = true;
455
+ }
456
+ else if (xFilterMatchMode === FindParam_1.XFilterMatchMode.X_AUTO_COMPLETE) {
457
+ xFilterValue.value = null;
458
+ filtersChanged = true;
459
+ }
460
+ // all other match modes - change to null, if previous match mode was X_IS_NOT_NULL or X_IS_NULL or X_AUTO_COMPLETE
461
+ else if (xFilterValue.value === isNotNullValueAlias || xFilterValue.value === isNullValueAlias || typeof xFilterValue.value === 'object') {
462
+ xFilterValue.value = null;
463
+ filtersChanged = true;
464
+ }
465
+ }
466
+ }
467
+ matchModeChangeFieldRef.current = null;
468
+ }
469
+ var filtersNew = e.filters;
470
+ if (filtersChanged) {
471
+ // clone needed if there was change, otherwise react does not show the change
472
+ filtersNew = __assign({}, filtersNew);
473
+ }
424
474
  // tymto zavolanim sa zapise znak zapisany klavesnicou do inputu filtra (ak prikaz zakomentujeme, input filtra zostane prazdny)
425
- setFilters(event.filters);
475
+ setFilters(filtersNew);
426
476
  removePagingFromStorage();
427
- loadDataBaseIfAutoFilter(event.filters, false);
477
+ loadDataBaseIfAutoFilter(filtersNew, false); // TODO - pass value Column.props.autoFilter here
428
478
  };
429
479
  var onSort = function (event) {
430
480
  //console.log("zavolany onSort - this.state.multiSortMeta = " + JSON.stringify(multiSortMeta));
@@ -1046,23 +1096,15 @@ exports.XLazyDataTable = (0, react_1.forwardRef)(function (_a, ref) {
1046
1096
  }
1047
1097
  return betweenFilter;
1048
1098
  };
1049
- // after change from match mode xAutoComplete input displays [object Object] - trying resolving this hug does not work - I have no idea why
1050
- /*
1051
- const onFilterMatchModeChange = (e: ColumnFilterMatchModeChangeEvent): void => {
1052
- console.log(e.matchMode);
1053
- console.log(e.field);
1054
- console.log(getFilterValue(e.field));
1055
- console.log(typeof (getFilterValue(e.field)));
1056
- if (e.matchMode !== XFilterMatchMode.X_AUTO_COMPLETE) {
1057
- const filterValue: any | null = getFilterValue(e.field);
1058
- if (filterValue !== null && typeof filterValue === 'object') {
1059
- console.log("idem volat setFilterValue");
1060
- setFilterValue(e.field, null);
1061
- console.log(getFilterValue(e.field));
1062
- }
1063
- }
1064
- }
1065
- */
1099
+ var onFilterMatchModeChange = function (e) {
1100
+ //console.log(e.matchMode);
1101
+ //console.log(e.field);
1102
+ // warning: we can not change/set the filter value for the column where match mode was changed
1103
+ // if we call setFilters in this method, then after finishing this method primereact calls another setting of "filters" and that second call overwrites our change
1104
+ // this method is only "read only" and the change must be done in onFilter method
1105
+ // we only save the field of the column where the match mode was changed - it is used later in onFilter method
1106
+ matchModeChangeFieldRef.current = e.field;
1107
+ };
1066
1108
  var valueAsUI = function (value, xField, contentType, fieldSetId) {
1067
1109
  var valueResult;
1068
1110
  if (xField.type === "boolean") {
@@ -1322,7 +1364,8 @@ exports.XLazyDataTable = (0, react_1.forwardRef)(function (_a, ref) {
1322
1364
  }
1323
1365
  else if (xField.type === "string") {
1324
1366
  var stringValue = getFilterValue(childColumn.props.field);
1325
- filterElement = react_1.default.createElement(XInputTextBase_1.XInputTextBase, { value: stringValue, onChange: function (value) { return setFilterValue(childColumn.props.field, value, undefined, undefined, childColumn.props.autoFilter); } });
1367
+ var xFilterMatchMode = getFilterMatchMode(childColumn.props.field);
1368
+ filterElement = react_1.default.createElement(XInputTextBase_1.XInputTextBase, { value: stringValue, onChange: function (value) { return setFilterValue(childColumn.props.field, value, undefined, undefined, childColumn.props.autoFilter); }, readOnly: xFilterMatchMode === FindParam_1.XFilterMatchMode.X_IS_NOT_NULL || xFilterMatchMode === FindParam_1.XFilterMatchMode.X_IS_NULL });
1326
1369
  }
1327
1370
  else if (xField.type === "date" || xField.type === "datetime") {
1328
1371
  betweenFilter = getBetweenFilter(childColumn.props.betweenFilter, props.betweenFilter);
@@ -1385,6 +1428,8 @@ exports.XLazyDataTable = (0, react_1.forwardRef)(function (_a, ref) {
1385
1428
  //filterMatchModeOptions = primeReactContext.filterMatchModeOptions![dataType].map((key) => ({ label: prLocaleOption(key), value: key }));
1386
1429
  filterMatchModeOptions = (primeReactContext && primeReactContext.filterMatchModeOptions[dataType].map(function (key) { return ({ label: (0, XLocale_1.prLocaleOption)(key), value: key }); })) ||
1387
1430
  api_1.default.filterMatchModeOptions[dataType].map(function (key) { return ({ label: (0, XLocale_1.prLocaleOption)(key), value: key }); });
1431
+ filterMatchModeOptions.push({ label: (0, XLocale_1.xLocaleOption)('xIsNotNull'), value: FindParam_1.XFilterMatchMode.X_IS_NOT_NULL });
1432
+ filterMatchModeOptions.push({ label: (0, XLocale_1.xLocaleOption)('xIsNull'), value: FindParam_1.XFilterMatchMode.X_IS_NULL });
1388
1433
  if (isAutoCompleteInFilterEnabled(childColumn.props)) {
1389
1434
  filterMatchModeOptions.push({ label: (0, XLocale_1.xLocaleOption)('xAutoComplete'), value: FindParam_1.XFilterMatchMode.X_AUTO_COMPLETE });
1390
1435
  }
@@ -1444,7 +1489,7 @@ exports.XLazyDataTable = (0, react_1.forwardRef)(function (_a, ref) {
1444
1489
  }
1445
1490
  footer = aggregateValue;
1446
1491
  }
1447
- return react_1.default.createElement(column_1.Column, { field: childColumn.props.field, header: header, footer: footer, filter: true, sortable: true, filterElement: filterElement, dataType: dataType, showFilterMenu: showFilterMenu, filterMatchModeOptions: filterMatchModeOptions, showClearButton: showClearButton, onFilterMatchModeChange: undefined /*onFilterMatchModeChange*/, body: body, headerStyle: headerStyle, align: align });
1492
+ return react_1.default.createElement(column_1.Column, { field: childColumn.props.field, header: header, footer: footer, filter: true, sortable: true, filterElement: filterElement, dataType: dataType, showFilterMenu: showFilterMenu, filterMatchModeOptions: filterMatchModeOptions, showClearButton: showClearButton, onFilterMatchModeChange: onFilterMatchModeChange, body: body, headerStyle: headerStyle, align: align });
1448
1493
  });
1449
1494
  // align-items-center centruje vertikalne (posuva smerom dolu do stredu)
1450
1495
  // x-lazy-datatable-label-right-compensation - vyvazuje label, aby item-y v strede isli aspon priblizne do stredu
@@ -15,6 +15,8 @@ export interface XLocaleOptions {
15
15
  cancel?: string;
16
16
  optimisticLockFailed?: string;
17
17
  formRemoveRowConfirm?: string;
18
+ xIsNotNull?: string;
19
+ xIsNull?: string;
18
20
  xAutoComplete?: string;
19
21
  expRowCount?: string;
20
22
  expExportType?: string;
@@ -96,6 +96,7 @@ export declare class XUtils {
96
96
  * @param envVar
97
97
  */
98
98
  static getEnvVarValue(envVarEnum: XEnvVar): string;
99
+ static getEnvVarValueBase(envVarEnum: string): string;
99
100
  static removeRow(entity: string, row: any): Promise<void>;
100
101
  static isReadOnly(path: string, readOnlyInit?: boolean): boolean;
101
102
  static isReadOnlyTableField(path: string | undefined, readOnly: XTableFieldReadOnlyProp | undefined, object: XObject | null, tableRow: any): boolean;
@@ -537,6 +537,9 @@ var XUtils = exports.XUtils = /** @class */ (function () {
537
537
  * @param envVar
538
538
  */
539
539
  XUtils.getEnvVarValue = function (envVarEnum) {
540
+ return XUtils.getEnvVarValueBase(envVarEnum);
541
+ };
542
+ XUtils.getEnvVarValueBase = function (envVarEnum) {
540
543
  var value = process.env[envVarEnum];
541
544
  if (value === undefined) {
542
545
  throw "Environment variable ".concat(envVarEnum, " - value not found. Check configuration file .env*");
@@ -20,6 +20,8 @@
20
20
  "pessimisticLockNotAcquired": "The row is being edited by the user {lockXUser} from {lockDate}\nDo you still want to edit the row? (The choice Cancel will open the form in read only mode).",
21
21
  "optimisticLockFailed": "Someone else has changed the row during the editation. Sorry, you have to cancel the editation and start the editation again.",
22
22
  "formRemoveRowConfirm": "Are you sure to remove the row?",
23
+ "xIsNotNull": "Is not null",
24
+ "xIsNull": "Is null",
23
25
  "xAutoComplete": "Autocomplete",
24
26
  "expRowCount": "Row count",
25
27
  "expExportType": "Export type",
@@ -14,6 +14,8 @@ export interface XCustomFilterItem {
14
14
  }
15
15
  export type XCustomFilter = XCustomFilterItem | XCustomFilterItem[];
16
16
  export declare enum XFilterMatchMode {
17
+ X_IS_NOT_NULL = "isNotNull",
18
+ X_IS_NULL = "isNull",
17
19
  X_AUTO_COMPLETE = "xAutoComplete",
18
20
  X_FILTER_ELEMENT = "xFilterElement"
19
21
  }
@@ -11,6 +11,8 @@ var ResultType;
11
11
  // additional match modes (extension to primereact enum FilterMatchMode)
12
12
  var XFilterMatchMode;
13
13
  (function (XFilterMatchMode) {
14
+ XFilterMatchMode["X_IS_NOT_NULL"] = "isNotNull";
15
+ XFilterMatchMode["X_IS_NULL"] = "isNull";
14
16
  XFilterMatchMode["X_AUTO_COMPLETE"] = "xAutoComplete";
15
17
  XFilterMatchMode["X_FILTER_ELEMENT"] = "xFilterElement"; // custom filter element (defined in filterElement property)
16
18
  })(XFilterMatchMode || (exports.XFilterMatchMode = XFilterMatchMode = {}));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michalrakus/x-react-web-lib",
3
- "version": "1.38.0",
3
+ "version": "1.38.2",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rimraf lib",