@michalrakus/x-react-web-lib 1.15.0 → 1.16.0

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.
@@ -12,6 +12,7 @@ export interface XAutoCompleteProps extends XFormComponentProps<XObject> {
12
12
  assocForm?: JSX.Element;
13
13
  filter?: XFilterProp;
14
14
  sortField?: string | DataTableSortMeta[];
15
+ fields?: string[];
15
16
  suggestions?: any[];
16
17
  lazy?: boolean;
17
18
  width?: string;
@@ -89,7 +89,7 @@ var XAutoComplete = /** @class */ (function (_super) {
89
89
  switch (_b.label) {
90
90
  case 0:
91
91
  if (!(this.props.suggestions === undefined)) return [3 /*break*/, 2];
92
- return [4 /*yield*/, XUtils_1.XUtils.fetchRows(this.xAssoc.entityName, this.getFilterBase(this.props.filter), (_a = this.props.sortField) !== null && _a !== void 0 ? _a : this.props.displayField)];
92
+ return [4 /*yield*/, XUtils_1.XUtils.fetchRows(this.xAssoc.entityName, this.getFilterBase(this.props.filter), (_a = this.props.sortField) !== null && _a !== void 0 ? _a : this.props.displayField, this.props.fields)];
93
93
  case 1:
94
94
  suggestions = _b.sent();
95
95
  this.setState({ suggestions: suggestions }, setStateCallback);
@@ -5,5 +5,6 @@ export declare const XCalendar: (props: {
5
5
  onChange: (value: Date | null) => void;
6
6
  onBlur?: ((event: React.FocusEvent<HTMLInputElement, Element>) => void) | undefined;
7
7
  readOnly?: boolean | undefined;
8
+ error?: string | undefined;
8
9
  datetime?: boolean | undefined;
9
10
  }) => JSX.Element;
@@ -1,4 +1,15 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
2
13
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
14
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
15
  };
@@ -7,6 +18,7 @@ exports.XCalendar = void 0;
7
18
  var react_1 = __importDefault(require("react"));
8
19
  var calendar_1 = require("primereact/calendar");
9
20
  var XUtilsConversions_1 = require("../serverApi/XUtilsConversions");
21
+ var XUtils_1 = require("./XUtils");
10
22
  // wrapper for Calendar component, maybe better name would be XInputDateBase
11
23
  var XCalendar = function (props) {
12
24
  var _a;
@@ -22,6 +34,6 @@ var XCalendar = function (props) {
22
34
  }
23
35
  };
24
36
  var datetime = (_a = props.datetime) !== null && _a !== void 0 ? _a : false;
25
- return (react_1.default.createElement(calendar_1.Calendar, { id: props.id, value: props.value, onChange: onChange, disabled: props.readOnly, showIcon: true, showOnFocus: false, dateFormat: (0, XUtilsConversions_1.dateFormatCalendar)(), showTime: datetime, showSeconds: datetime, inputClassName: datetime ? 'x-input-datetime' : 'x-input-date', onBlur: props.onBlur }));
37
+ return (react_1.default.createElement(calendar_1.Calendar, __assign({ id: props.id, value: props.value, onChange: onChange, disabled: props.readOnly, showIcon: true, showOnFocus: false, dateFormat: (0, XUtilsConversions_1.dateFormatCalendar)(), showTime: datetime, showSeconds: datetime, inputClassName: datetime ? 'x-input-datetime' : 'x-input-date', onBlur: props.onBlur }, XUtils_1.XUtils.createErrorProps(props.error))));
26
38
  };
27
39
  exports.XCalendar = XCalendar;
@@ -1,6 +1,7 @@
1
1
  export declare enum XEnvVar {
2
2
  REACT_APP_BACKEND_URL = "REACT_APP_BACKEND_URL",
3
3
  REACT_APP_AUTH = "REACT_APP_AUTH",
4
+ REACT_APP_AUTH_OFF_USERNAME = "REACT_APP_AUTH_OFF_USERNAME",
4
5
  REACT_APP_AUTH0_DOMAIN = "REACT_APP_AUTH0_DOMAIN",
5
6
  REACT_APP_AUTH0_CLIENT_ID = "REACT_APP_AUTH0_CLIENT_ID",
6
7
  REACT_APP_AUTH0_AUDIENCE = "REACT_APP_AUTH0_AUDIENCE",
@@ -9,6 +10,7 @@ export declare enum XEnvVar {
9
10
  REACT_APP_MS_ENTRA_ID_BACKEND_SCOPE = "REACT_APP_MS_ENTRA_ID_BACKEND_SCOPE"
10
11
  }
11
12
  export declare enum XReactAppAuth {
13
+ OFF = "OFF",
12
14
  LOCAL = "LOCAL",
13
15
  AUTH0 = "AUTH0",
14
16
  MS_ENTRA_ID = "MS_ENTRA_ID"
@@ -6,6 +6,7 @@ var XEnvVar;
6
6
  (function (XEnvVar) {
7
7
  XEnvVar["REACT_APP_BACKEND_URL"] = "REACT_APP_BACKEND_URL";
8
8
  XEnvVar["REACT_APP_AUTH"] = "REACT_APP_AUTH";
9
+ XEnvVar["REACT_APP_AUTH_OFF_USERNAME"] = "REACT_APP_AUTH_OFF_USERNAME";
9
10
  XEnvVar["REACT_APP_AUTH0_DOMAIN"] = "REACT_APP_AUTH0_DOMAIN";
10
11
  XEnvVar["REACT_APP_AUTH0_CLIENT_ID"] = "REACT_APP_AUTH0_CLIENT_ID";
11
12
  XEnvVar["REACT_APP_AUTH0_AUDIENCE"] = "REACT_APP_AUTH0_AUDIENCE";
@@ -17,6 +18,7 @@ var XEnvVar;
17
18
  // enum for values of the environment variable REACT_APP_AUTH
18
19
  var XReactAppAuth;
19
20
  (function (XReactAppAuth) {
21
+ XReactAppAuth["OFF"] = "OFF";
20
22
  XReactAppAuth["LOCAL"] = "LOCAL";
21
23
  XReactAppAuth["AUTH0"] = "AUTH0";
22
24
  XReactAppAuth["MS_ENTRA_ID"] = "MS_ENTRA_ID";
@@ -55,15 +55,15 @@ export declare abstract class XFormBase extends Component<XFormProps> {
55
55
  formReadOnlyBase(field: string): boolean;
56
56
  onClickSave(): Promise<void>;
57
57
  onClickCancel(): void;
58
- validateSave(): boolean;
59
- validateForm(): XErrorMap;
58
+ validateSave(): Promise<boolean>;
59
+ validateForm(): Promise<XErrorMap>;
60
60
  fieldValidation(): XErrorMap;
61
61
  getErrorMessagesForAssoc(oneToManyAssoc: string): string;
62
62
  static saveErrorsIntoXRowTechData(row: any, xErrors: XErrors): void;
63
63
  formReadOnly(object: XObject, field: string): boolean;
64
64
  createNewObject(): XObject;
65
65
  preInitForm(object: XObject, operationType: OperationType.Insert | OperationType.Update): void;
66
- validate(object: XObject): XErrors;
66
+ validate(object: XObject): Promise<XErrors>;
67
67
  preSave(object: XObject): void;
68
68
  saveRow(): Promise<any>;
69
69
  }
@@ -383,9 +383,9 @@ var XFormBase = /** @class */ (function (_super) {
383
383
  var isAddRow, object, e_4;
384
384
  return __generator(this, function (_a) {
385
385
  switch (_a.label) {
386
- case 0:
387
- //console.log("zavolany onClickSave");
388
- if (!this.validateSave()) {
386
+ case 0: return [4 /*yield*/, this.validateSave()];
387
+ case 1:
388
+ if (!(_a.sent())) {
389
389
  return [2 /*return*/];
390
390
  }
391
391
  // docasne na testovanie
@@ -402,18 +402,18 @@ var XFormBase = /** @class */ (function (_super) {
402
402
  // }
403
403
  this.preSave(this.state.object);
404
404
  isAddRow = this.isAddRow();
405
- _a.label = 1;
406
- case 1:
407
- _a.trys.push([1, 3, , 4]);
408
- return [4 /*yield*/, this.saveRow()];
405
+ _a.label = 2;
409
406
  case 2:
410
- object = _a.sent();
411
- return [3 /*break*/, 4];
407
+ _a.trys.push([2, 4, , 5]);
408
+ return [4 /*yield*/, this.saveRow()];
412
409
  case 3:
410
+ object = _a.sent();
411
+ return [3 /*break*/, 5];
412
+ case 4:
413
413
  e_4 = _a.sent();
414
414
  XUtils_1.XUtils.showErrorMessage("Save row failed.", e_4);
415
415
  return [2 /*return*/]; // zostavame vo formulari
416
- case 4:
416
+ case 5:
417
417
  if (this.props.onSaveOrCancel !== undefined) {
418
418
  // formular je zobrazeny v dialogu
419
419
  this.props.onSaveOrCancel(object, isAddRow ? XUtils_1.OperationType.Insert : XUtils_1.OperationType.Update);
@@ -438,74 +438,90 @@ var XFormBase = /** @class */ (function (_super) {
438
438
  }
439
439
  };
440
440
  XFormBase.prototype.validateSave = function () {
441
- var e_5, _a, e_6, _b;
442
- var xErrorMap = this.validateForm();
443
- // zatial takto jednoducho
444
- var msg = XUtils_1.XUtils.getErrorMessages(xErrorMap);
445
- try {
446
- // este spracujeme editovatelne tabulky
447
- for (var _c = __values(this.xFormDataTableList), _d = _c.next(); !_d.done; _d = _c.next()) {
448
- var xFormDataTable = _d.value;
449
- //msg += xFormDataTable.getErrorMessages();
450
- msg += this.getErrorMessagesForAssoc(xFormDataTable.props.assocField);
451
- }
452
- }
453
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
454
- finally {
455
- try {
456
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
457
- }
458
- finally { if (e_5) throw e_5.error; }
459
- }
460
- try {
461
- // este spracujeme oneToMany asociacie, ktore boli explicitne uvedene, ze ich treba validovat
462
- // (validaciu treba nakodit vo formulari, zavolat z metody validate() a ukoncit zavolanim XFormBase.saveErrorsIntoXRowTechData)
463
- for (var _e = __values(this.assocToValidateList), _f = _e.next(); !_f.done; _f = _e.next()) {
464
- var assocToValidate = _f.value;
465
- msg += this.getErrorMessagesForAssoc(assocToValidate);
466
- }
467
- }
468
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
469
- finally {
470
- try {
471
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
472
- }
473
- finally { if (e_6) throw e_6.error; }
474
- }
475
- var ok = true;
476
- if (msg !== "") {
477
- alert(msg);
478
- ok = false;
479
- }
480
- return ok;
441
+ return __awaiter(this, void 0, void 0, function () {
442
+ var xErrorMap, msg, _a, _b, xFormDataTable, _c, _d, assocToValidate, ok;
443
+ var e_5, _e, e_6, _f;
444
+ return __generator(this, function (_g) {
445
+ switch (_g.label) {
446
+ case 0: return [4 /*yield*/, this.validateForm()];
447
+ case 1:
448
+ xErrorMap = _g.sent();
449
+ msg = XUtils_1.XUtils.getErrorMessages(xErrorMap);
450
+ try {
451
+ // este spracujeme editovatelne tabulky
452
+ for (_a = __values(this.xFormDataTableList), _b = _a.next(); !_b.done; _b = _a.next()) {
453
+ xFormDataTable = _b.value;
454
+ //msg += xFormDataTable.getErrorMessages();
455
+ msg += this.getErrorMessagesForAssoc(xFormDataTable.props.assocField);
456
+ }
457
+ }
458
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
459
+ finally {
460
+ try {
461
+ if (_b && !_b.done && (_e = _a.return)) _e.call(_a);
462
+ }
463
+ finally { if (e_5) throw e_5.error; }
464
+ }
465
+ try {
466
+ // este spracujeme oneToMany asociacie, ktore boli explicitne uvedene, ze ich treba validovat
467
+ // (validaciu treba nakodit vo formulari, zavolat z metody validate() a ukoncit zavolanim XFormBase.saveErrorsIntoXRowTechData)
468
+ for (_c = __values(this.assocToValidateList), _d = _c.next(); !_d.done; _d = _c.next()) {
469
+ assocToValidate = _d.value;
470
+ msg += this.getErrorMessagesForAssoc(assocToValidate);
471
+ }
472
+ }
473
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
474
+ finally {
475
+ try {
476
+ if (_d && !_d.done && (_f = _c.return)) _f.call(_c);
477
+ }
478
+ finally { if (e_6) throw e_6.error; }
479
+ }
480
+ ok = true;
481
+ if (msg !== "") {
482
+ alert(msg);
483
+ ok = false;
484
+ }
485
+ return [2 /*return*/, ok];
486
+ }
487
+ });
488
+ });
481
489
  };
482
490
  XFormBase.prototype.validateForm = function () {
483
- var e_7, _a;
484
- var xErrorMap = this.fieldValidation();
485
- // form validation
486
- var xErrors = this.validate(this.getXObject());
487
- try {
488
- for (var _b = __values(Object.entries(xErrors)), _c = _b.next(); !_c.done; _c = _b.next()) {
489
- var _d = __read(_c.value, 2), field = _d[0], error = _d[1];
490
- if (error) {
491
- // skusime zistit label
492
- var xFormComponent = this.findXFormComponent(field);
493
- var fieldLabel = xFormComponent ? xFormComponent.getLabel() : undefined;
494
- xErrorMap[field] = __assign(__assign({}, xErrorMap[field]), { form: error, fieldLabel: fieldLabel });
491
+ return __awaiter(this, void 0, void 0, function () {
492
+ var xErrorMap, xErrors, _a, _b, _c, field, error, xFormComponent, fieldLabel;
493
+ var e_7, _d;
494
+ return __generator(this, function (_e) {
495
+ switch (_e.label) {
496
+ case 0:
497
+ xErrorMap = this.fieldValidation();
498
+ return [4 /*yield*/, this.validate(this.getXObject())];
499
+ case 1:
500
+ xErrors = _e.sent();
501
+ try {
502
+ for (_a = __values(Object.entries(xErrors)), _b = _a.next(); !_b.done; _b = _a.next()) {
503
+ _c = __read(_b.value, 2), field = _c[0], error = _c[1];
504
+ if (error) {
505
+ xFormComponent = this.findXFormComponent(field);
506
+ fieldLabel = xFormComponent ? xFormComponent.getLabel() : undefined;
507
+ xErrorMap[field] = __assign(__assign({}, xErrorMap[field]), { form: error, fieldLabel: fieldLabel });
508
+ }
509
+ }
510
+ }
511
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
512
+ finally {
513
+ try {
514
+ if (_b && !_b.done && (_d = _a.return)) _d.call(_a);
515
+ }
516
+ finally { if (e_7) throw e_7.error; }
517
+ }
518
+ // TODO - optimalizacia - netreba setovat stav ak by sme sli prec z formulara (ak by zbehla validacia aj save a isli by sme naspet do browsu)
519
+ // setujeme aj this.state.object, lebo mohli pribudnut/odbudnut chyby na rowData v editovatelnych tabulkach
520
+ this.setState({ object: this.state.object, errorMap: xErrorMap });
521
+ return [2 /*return*/, xErrorMap];
495
522
  }
496
- }
497
- }
498
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
499
- finally {
500
- try {
501
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
502
- }
503
- finally { if (e_7) throw e_7.error; }
504
- }
505
- // TODO - optimalizacia - netreba setovat stav ak by sme sli prec z formulara (ak by zbehla validacia aj save a isli by sme naspet do browsu)
506
- // setujeme aj this.state.object, lebo mohli pribudnut/odbudnut chyby na rowData v editovatelnych tabulkach
507
- this.setState({ object: this.state.object, errorMap: xErrorMap });
508
- return xErrorMap;
523
+ });
524
+ });
509
525
  };
510
526
  XFormBase.prototype.fieldValidation = function () {
511
527
  var e_8, _a, e_9, _b;
@@ -603,7 +619,11 @@ var XFormBase = /** @class */ (function (_super) {
603
619
  };
604
620
  // this method can be overriden in subclass if needed (custom validation)
605
621
  XFormBase.prototype.validate = function (object) {
606
- return {};
622
+ return __awaiter(this, void 0, void 0, function () {
623
+ return __generator(this, function (_a) {
624
+ return [2 /*return*/, {}];
625
+ });
626
+ });
607
627
  };
608
628
  // this method can be overriden in subclass if needed (to modify object before save)
609
629
  XFormBase.prototype.preSave = function (object) {
@@ -11,15 +11,17 @@ var XFormRowCol = function (props) {
11
11
  // ak chceme zmenit child element, tak treba bud vytvorit novy alebo vyklonovat
12
12
  // priklad je na https://soshace.com/building-react-components-using-children-props-and-context-api/
13
13
  childElemList = react_1.default.Children.map(props.children, function (child) {
14
+ // chceli by sme klonovat len nase X* komponenty (napr. XInputText)
15
+ // ak vyklonujeme cudziu komponentu (napr. div), funguje, ale prida do nej property labelstyle=[object Object]
16
+ // child.type.name vracia nazov komponenty (napr. XInputText) ale ked sa vytvori optimalizovany build, uz to nefunguje (uz je tam napr. "t")
17
+ // takze zatial klonujeme vzdy
14
18
  var _a, _b;
15
- // klonujeme len nase X* komponenty (napr. XInputText), child.type.name vracia nazov komponenty (napr. XInputText)
16
- // ak vyklonujeme cudziu komponentu, funguje, ale prida do nej property labelstyle=[object Object]
17
- if (child.type.name && child.type.name.startsWith("X")) {
18
- return react_1.default.cloneElement(child, { form: (_a = child.props.form) !== null && _a !== void 0 ? _a : props.form, labelStyle: (_b = child.props.labelStyle) !== null && _b !== void 0 ? _b : props.labelStyle });
19
- }
20
- else {
21
- return child;
22
- }
19
+ //if (child.type.name && child.type.name.startsWith("X")) {
20
+ return react_1.default.cloneElement(child, { form: (_a = child.props.form) !== null && _a !== void 0 ? _a : props.form, labelStyle: (_b = child.props.labelStyle) !== null && _b !== void 0 ? _b : props.labelStyle });
21
+ //}
22
+ //else {
23
+ // return child;
24
+ //}
23
25
  });
24
26
  }
25
27
  else {
@@ -56,7 +56,7 @@ var XInputDate = /** @class */ (function (_super) {
56
56
  // note: style overrides size (width of the input according to character count)
57
57
  return (react_1.default.createElement("div", { className: "field grid" },
58
58
  react_1.default.createElement("label", { htmlFor: this.props.field, className: "col-fixed", style: this.getLabelStyle() }, this.getLabel()),
59
- react_1.default.createElement(XCalendar_1.XCalendar, { id: this.props.field, value: this.getValue(), onChange: this.onValueChange, readOnly: this.isReadOnly(), datetime: this.xField.type === 'datetime', onBlur: this.onBlur })));
59
+ react_1.default.createElement(XCalendar_1.XCalendar, { id: this.props.field, value: this.getValue(), onChange: this.onValueChange, readOnly: this.isReadOnly(), error: this.getError(), datetime: this.xField.type === 'datetime', onBlur: this.onBlur })));
60
60
  };
61
61
  return XInputDate;
62
62
  }(XInput_1.XInput));
@@ -126,7 +126,7 @@ var XUtilsMetadata = /** @class */ (function () {
126
126
  width = XUtilsMetadata.computeColumnWidthBase(size, 0.5 + 0.5);
127
127
  }
128
128
  else if (xField.type === "date") {
129
- width = XUtilsMetadata.computeColumnWidthBase(10, 0.25 + 1.25 + 0.25); // napr. 31.12.2021, 1.25 rem date picker button
129
+ width = XUtilsMetadata.computeColumnWidthBase(11, 0.25 + 1.25 + 0.25); // napr. 31.12.2021 (poznamka: dal som 11 lebo vo filtri nebolo vidno cely datum), 1.25 rem date picker button
130
130
  }
131
131
  else if (xField.type === "datetime") {
132
132
  width = XUtilsMetadata.computeColumnWidthBase(10 + 9, 0.25 + 1.25 + 0.25); // napr. 31.12.2021 03:03:00
@@ -10,5 +10,6 @@ export declare class XUtilsCommon {
10
10
  static getDayName(date: Date | null | undefined): string | undefined;
11
11
  static dateAddDays(date: Date | null, days: number): Date | null;
12
12
  static findFirstMatch(pattern: RegExp, value: string): string | null;
13
+ static sqlMaxDateIfNull(sqlExp: string): string;
13
14
  }
14
15
  export declare const dateFormat: any;
@@ -172,6 +172,10 @@ var XUtilsCommon = /** @class */ (function () {
172
172
  var match = pattern.exec(value);
173
173
  return match != null ? match[0] : null;
174
174
  };
175
+ // to be used in sql expressions
176
+ XUtilsCommon.sqlMaxDateIfNull = function (sqlExp) {
177
+ return "coalesce(".concat(sqlExp, ", '9999-12-31'::DATE)");
178
+ };
175
179
  XUtilsCommon.newLine = '\n';
176
180
  return XUtilsCommon;
177
181
  }());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@michalrakus/x-react-web-lib",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "clean": "rimraf lib",