asab_webui_components 26.1.6 → 26.1.8

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.
package/README.md CHANGED
@@ -20,7 +20,7 @@ Possible imports:
20
20
  - Service
21
21
  - Renderer
22
22
  - Humanize, humanizeToString
23
- - DataTable2, DataTableCard2, DataTableCardFooter2, DataTableFilter2, DataTableAdvFilterSingleValue2, DataTableAdvFilterMultiValue2
23
+ - DataTable2, DataTableCard2, DataTableCardFooter2, DataTableFilter2, DataTableAdvFilterSingleValue2, DataTableAdvFilterMultiValue2, DataTableAdvCustomFilter
24
24
  - Spinner
25
25
  - ControlledSwitch
26
26
  - UncontrolledSwitch
@@ -406,13 +406,9 @@ function DataTableCardPill2(_ref6) {
406
406
  getParam,
407
407
  watchParams,
408
408
  getAllParams,
409
- removeSinglePill,
410
409
  removeMultiPill,
411
- getFilterField
410
+ removeSinglePill
412
411
  } = (0, _DataTableContext.useDataTableContext)();
413
- var {
414
- t
415
- } = (0, _reactI18next.useTranslation)();
416
412
  var displayPillArea = (0, _react.useMemo)(() => {
417
413
  if (getAllParams() && Object.keys(getAllParams()).some(key => key.startsWith('a'))) {
418
414
  return true;
@@ -426,49 +422,75 @@ function DataTableCardPill2(_ref6) {
426
422
  minHeight: rowHeight
427
423
  }
428
424
  }, Object.keys(getAllParams()).map(key => {
429
- if (key.startsWith("a")) {
425
+ if (key.startsWith('a')) {
430
426
  var value = getParam(key, {
431
427
  splitBy: ','
432
428
  });
433
429
  return value.length > 1 ? value.map(val => /*#__PURE__*/_react.default.createElement("span", {
434
430
  key: "".concat(key).concat(val),
435
431
  className: "datatable-cardpill mx-1"
436
- }, /*#__PURE__*/_react.default.createElement(_reactstrap.Badge, {
437
- color: "primary",
438
- pill: true
439
- }, "".concat(getFilterField(key.substring(1)), ": ").concat(val), isLoading == true ? /*#__PURE__*/_react.default.createElement("i", {
440
- className: "bi bi-x ps-1",
441
- title: t('General|Remove')
442
- }) : /*#__PURE__*/_react.default.createElement("i", {
443
- className: "bi bi-x ps-1 datatable-cardpill-icon",
444
- title: t('General|Remove'),
445
- onClick: () => removeMultiPill(key, val)
446
- })))) : /*#__PURE__*/_react.default.createElement("span", {
432
+ }, /*#__PURE__*/_react.default.createElement(DataTableBadge, {
433
+ item: key,
434
+ value: val,
435
+ isLoading: isLoading,
436
+ onRemove: () => removeMultiPill(key, val)
437
+ }))) : /*#__PURE__*/_react.default.createElement("span", {
447
438
  key: "".concat(key).concat(value),
448
439
  className: "datatable-cardpill mx-1"
449
- }, /*#__PURE__*/_react.default.createElement(_reactstrap.Badge, {
450
- color: "primary",
451
- pill: true
452
- }, "".concat(getFilterField(key.substring(1)), ": ").concat(value), isLoading == true ? /*#__PURE__*/_react.default.createElement("i", {
453
- className: "bi bi-x ps-1",
454
- title: t('General|Remove')
455
- }) : /*#__PURE__*/_react.default.createElement("i", {
456
- className: "bi bi-x ps-1 datatable-cardpill-icon",
457
- title: t('General|Remove'),
458
- onClick: () => removeSinglePill(key)
459
- })));
440
+ }, /*#__PURE__*/_react.default.createElement(DataTableBadge, {
441
+ item: key,
442
+ value: value,
443
+ isLoading: isLoading,
444
+ onRemove: () => removeSinglePill(key)
445
+ }));
460
446
  } else {
461
447
  return null;
462
448
  }
463
449
  }));
464
450
  }
465
451
 
452
+ // Render a filter badge with custom or default content
453
+ function DataTableBadge(_ref7) {
454
+ var {
455
+ item,
456
+ value,
457
+ isLoading,
458
+ onRemove
459
+ } = _ref7;
460
+ var {
461
+ getFilterField,
462
+ getCustomPill
463
+ } = (0, _DataTableContext.useDataTableContext)();
464
+ var {
465
+ t
466
+ } = (0, _reactI18next.useTranslation)();
467
+
468
+ // Get custom pill
469
+ var CustomBadge = getCustomPill(item.substring(1));
470
+ if (CustomBadge) {
471
+ return /*#__PURE__*/_react.default.cloneElement(CustomBadge, {
472
+ isLoading
473
+ });
474
+ }
475
+ return /*#__PURE__*/_react.default.createElement(_reactstrap.Badge, {
476
+ color: "primary",
477
+ pill: true
478
+ }, "".concat(getFilterField(item.substring(1)), ": ").concat(value), isLoading == true ? /*#__PURE__*/_react.default.createElement("i", {
479
+ className: "bi bi-x ps-1",
480
+ title: t('General|Remove')
481
+ }) : /*#__PURE__*/_react.default.createElement("i", {
482
+ className: "bi bi-x ps-1 datatable-cardpill-icon",
483
+ title: t('General|Remove'),
484
+ onClick: onRemove
485
+ }));
486
+ }
487
+
466
488
  // Inner sorting function
467
- function DataTableSort2(_ref7) {
489
+ function DataTableSort2(_ref8) {
468
490
  var {
469
491
  title,
470
492
  field
471
- } = _ref7;
493
+ } = _ref8;
472
494
  var {
473
495
  onTriggerSort,
474
496
  getParam
@@ -347,9 +347,8 @@ export function DataTable2({columns, rows, limit, loading, rowHeight, rowStyle})
347
347
  }
348
348
 
349
349
  // Renders filter pills based on data table filter params
350
- function DataTableCardPill2({isLoading, rowHeight}) {
351
- const { getParam, watchParams, getAllParams, removeSinglePill, removeMultiPill, getFilterField } = useDataTableContext();
352
- const { t } = useTranslation();
350
+ function DataTableCardPill2({ isLoading, rowHeight }) {
351
+ const { getParam, watchParams, getAllParams, removeMultiPill, removeSinglePill } = useDataTableContext();
353
352
  const displayPillArea = useMemo(() => {
354
353
  if (getAllParams() && Object.keys(getAllParams()).some(key => key.startsWith('a'))) {
355
354
  return true;
@@ -360,54 +359,36 @@ function DataTableCardPill2({isLoading, rowHeight}) {
360
359
 
361
360
  return(
362
361
  displayPillArea &&
363
- <div className="datatable-cardpill-area" style={{minHeight: rowHeight}}>
362
+ <div className='datatable-cardpill-area' style={{minHeight: rowHeight}}>
364
363
  {Object.keys(getAllParams()).map((key) => {
365
- if (key.startsWith("a")) {
364
+ if (key.startsWith('a')) {
366
365
  const value = getParam(key, {splitBy: ','});
367
366
  return (
368
367
  (value.length > 1) ?
369
368
  value.map(val => (
370
369
  <span
371
370
  key={`${key}${val}`}
372
- className="datatable-cardpill mx-1"
371
+ className='datatable-cardpill mx-1'
373
372
  >
374
- <Badge color="primary" pill>
375
- {`${getFilterField(key.substring(1))}: ${val}`}
376
- {(isLoading == true) ?
377
- <i
378
- className="bi bi-x ps-1"
379
- title={t('General|Remove')}
380
- />
381
- :
382
- <i
383
- className="bi bi-x ps-1 datatable-cardpill-icon"
384
- title={t('General|Remove')}
385
- onClick={() => removeMultiPill(key, val)}
386
- />
387
- }
388
- </Badge>
373
+ <DataTableBadge
374
+ item={key}
375
+ value={val}
376
+ isLoading={isLoading}
377
+ onRemove={() => removeMultiPill(key, val)}
378
+ />
389
379
  </span>
390
380
  ))
391
381
  :
392
382
  <span
393
383
  key={`${key}${value}`}
394
- className="datatable-cardpill mx-1"
384
+ className='datatable-cardpill mx-1'
395
385
  >
396
- <Badge color="primary" pill>
397
- {`${getFilterField(key.substring(1))}: ${value}`}
398
- {(isLoading == true) ?
399
- <i
400
- className="bi bi-x ps-1"
401
- title={t('General|Remove')}
402
- />
403
- :
404
- <i
405
- className="bi bi-x ps-1 datatable-cardpill-icon"
406
- title={t('General|Remove')}
407
- onClick={() => removeSinglePill(key)}
408
- />
409
- }
410
- </Badge>
386
+ <DataTableBadge
387
+ item={key}
388
+ value={value}
389
+ isLoading={isLoading}
390
+ onRemove={() => removeSinglePill(key)}
391
+ />
411
392
  </span>
412
393
  )
413
394
  } else {
@@ -418,6 +399,37 @@ function DataTableCardPill2({isLoading, rowHeight}) {
418
399
  )
419
400
  }
420
401
 
402
+ // Render a filter badge with custom or default content
403
+ function DataTableBadge({ item, value, isLoading, onRemove }) {
404
+ const { getFilterField, getCustomPill } = useDataTableContext();
405
+ const { t } = useTranslation();
406
+
407
+ // Get custom pill
408
+ const CustomBadge = getCustomPill(item.substring(1));
409
+
410
+ if (CustomBadge) {
411
+ return React.cloneElement(CustomBadge, { isLoading });
412
+ }
413
+
414
+ return (
415
+ <Badge color='primary' pill>
416
+ {`${getFilterField(item.substring(1))}: ${value}`}
417
+ {(isLoading == true) ?
418
+ <i
419
+ className='bi bi-x ps-1'
420
+ title={t('General|Remove')}
421
+ />
422
+ :
423
+ <i
424
+ className='bi bi-x ps-1 datatable-cardpill-icon'
425
+ title={t('General|Remove')}
426
+ onClick={onRemove}
427
+ />
428
+ }
429
+ </Badge>
430
+ )
431
+ }
432
+
421
433
  // Inner sorting function
422
434
  function DataTableSort2({title, field}) {
423
435
  const { onTriggerSort, getParam } = useDataTableContext();
@@ -32,6 +32,7 @@ var DataTableContextProvider = _ref => {
32
32
  var [searchParams, setSearchParams] = (0, _reactRouterDom.useSearchParams)(defaultParams);
33
33
  var [stateParams, setStateParams] = (0, _react.useState)(defaultParams);
34
34
  var filterFieldsRef = (0, _react.useRef)({}); // Ref to store filter fields persistently without triggering re-renders.
35
+ var customPillRef = (0, _react.useRef)({}); // Ref for store obj with custom pulls with individual key access
35
36
 
36
37
  // Method to get param with option to set up splitting method used for searchParams
37
38
  var getParam = function getParam(param) {
@@ -332,12 +333,30 @@ var DataTableContextProvider = _ref => {
332
333
  // Method to set filter fields in filterFieldsRef
333
334
  var setFilterField = obj => {
334
335
  var fields = Object.entries(obj)[0];
335
- // Check and only add field if it doesnt exist
336
+ // Check and only add field if it doesn't exist
336
337
  if (!filterFieldsRef.current[fields[0]]) {
337
338
  filterFieldsRef.current[fields[0]] = fields[1];
338
339
  }
339
340
  };
340
341
 
342
+ // Retrieves a custom pill component by key
343
+ var getCustomPill = key => {
344
+ var _customPillRef$curren;
345
+ // Return stored pill component or null if doesn't exist
346
+ return ((_customPillRef$curren = customPillRef.current) === null || _customPillRef$curren === void 0 ? void 0 : _customPillRef$curren[key]) || null;
347
+ };
348
+
349
+ // Stores or updates a custom pill component in the reference
350
+ var setCustomPill = (pill, field) => {
351
+ // Initialize ref object if empty
352
+ if (!customPillRef.current) {
353
+ customPillRef.current = {};
354
+ }
355
+
356
+ // Store/update the pill component for the specified field
357
+ customPillRef.current[field] = pill;
358
+ };
359
+
341
360
  // Inner method to update search params
342
361
  var _updateSearchParams = (searchParams, params) => {
343
362
  Object.entries(params).forEach(_ref2 => {
@@ -368,6 +387,8 @@ var DataTableContextProvider = _ref => {
368
387
  serializeParams,
369
388
  getFilterField,
370
389
  setFilterField,
390
+ setCustomPill,
391
+ getCustomPill,
371
392
  watchParams: {
372
393
  searchParams,
373
394
  stateParams
@@ -12,6 +12,7 @@ const DataTableContextProvider = ({ children, disableParams, initialLimit }) =>
12
12
  const [searchParams, setSearchParams] = useSearchParams(defaultParams);
13
13
  const [stateParams, setStateParams] = useState(defaultParams);
14
14
  const filterFieldsRef = useRef({}); // Ref to store filter fields persistently without triggering re-renders.
15
+ const customPillRef = useRef({}); // Ref for store obj with custom pulls with individual key access
15
16
 
16
17
  // Method to get param with option to set up splitting method used for searchParams
17
18
  const getParam = (param, options = {}) => {
@@ -289,12 +290,29 @@ const DataTableContextProvider = ({ children, disableParams, initialLimit }) =>
289
290
  // Method to set filter fields in filterFieldsRef
290
291
  const setFilterField = (obj) => {
291
292
  const fields = Object.entries(obj)[0];
292
- // Check and only add field if it doesnt exist
293
+ // Check and only add field if it doesn't exist
293
294
  if (!filterFieldsRef.current[fields[0]]) {
294
295
  filterFieldsRef.current[fields[0]] = fields[1];
295
296
  }
296
297
  };
297
298
 
299
+ // Retrieves a custom pill component by key
300
+ const getCustomPill = (key) => {
301
+ // Return stored pill component or null if doesn't exist
302
+ return customPillRef.current?.[key] || null;
303
+ }
304
+
305
+ // Stores or updates a custom pill component in the reference
306
+ const setCustomPill = (pill, field) => {
307
+ // Initialize ref object if empty
308
+ if (!customPillRef.current) {
309
+ customPillRef.current = {};
310
+ }
311
+
312
+ // Store/update the pill component for the specified field
313
+ customPillRef.current[field] = pill;
314
+ }
315
+
298
316
  // Inner method to update search params
299
317
  const _updateSearchParams = (searchParams, params) => {
300
318
  Object.entries(params).forEach(([key, value]) => {
@@ -323,6 +341,8 @@ const DataTableContextProvider = ({ children, disableParams, initialLimit }) =>
323
341
  serializeParams,
324
342
  getFilterField,
325
343
  setFilterField,
344
+ setCustomPill,
345
+ getCustomPill,
326
346
  watchParams: { searchParams, stateParams } // Context value for watching params
327
347
  }), [searchParams, stateParams]);
328
348
 
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.DataTableAdvCustomFilter = DataTableAdvCustomFilter;
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _DataTableContext = require("../../DataTableContext.js");
9
+ function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
10
+ // Custom component for filtering in the table
11
+ function DataTableAdvCustomFilter(_ref) {
12
+ var {
13
+ field,
14
+ content,
15
+ customPill
16
+ } = _ref;
17
+ var {
18
+ updateSingleValueFilter,
19
+ setFilterField,
20
+ setCustomPill
21
+ } = (0, _DataTableContext.useDataTableContext)();
22
+
23
+ // Updates filter field and custom pill when dependencies change
24
+ (0, _react.useEffect)(() => {
25
+ // Register the filter field in data table context
26
+ setFilterField(field);
27
+ // Get the first key from field object
28
+ var fieldKey = Object.keys(field)[0];
29
+ // Store the custom pill component associated with this field
30
+ setCustomPill(customPill, fieldKey);
31
+ }, [customPill]);
32
+
33
+ // Transferring a function to the custom content for correct filter assignment
34
+ return content(updateSingleValueFilter);
35
+ }
@@ -0,0 +1,21 @@
1
+ import React, { useEffect } from 'react';
2
+
3
+ import { useDataTableContext } from '../../DataTableContext.jsx';
4
+
5
+ // Custom component for filtering in the table
6
+ export function DataTableAdvCustomFilter({ field, content, customPill }) {
7
+ const { updateSingleValueFilter, setFilterField, setCustomPill } = useDataTableContext();
8
+
9
+ // Updates filter field and custom pill when dependencies change
10
+ useEffect(() => {
11
+ // Register the filter field in data table context
12
+ setFilterField(field);
13
+ // Get the first key from field object
14
+ const fieldKey = Object.keys(field)[0];
15
+ // Store the custom pill component associated with this field
16
+ setCustomPill(customPill, fieldKey);
17
+ },[customPill]);
18
+
19
+ // Transferring a function to the custom content for correct filter assignment
20
+ return content(updateSingleValueFilter);
21
+ }
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.DataTableAdvFilterSingleValue2 = DataTableAdvFilterSingleValue2;
7
7
  var _react = _interopRequireWildcard(require("react"));
8
- var _reactI18next = require("react-i18next");
9
8
  var _reactstrap = require("reactstrap");
10
9
  var _DataTableContext = require("../../DataTableContext.js");
11
10
  require("./DataTableAdvFilter2.scss");
@@ -19,9 +18,6 @@ function DataTableAdvFilterSingleValue2(_ref) {
19
18
  updateSingleValueFilter,
20
19
  setFilterField
21
20
  } = (0, _DataTableContext.useDataTableContext)();
22
- var {
23
- t
24
- } = (0, _reactI18next.useTranslation)();
25
21
  var [dropdownOpen, setDropdownOpen] = (0, _react.useState)(false);
26
22
  var primaryFieldEntry = Object.entries(field)[0]; // Extracts the first key-value pair from the field object
27
23
 
@@ -1,5 +1,4 @@
1
1
  import React, { useState, useEffect } from 'react';
2
- import { useTranslation } from 'react-i18next';
3
2
 
4
3
  import {
5
4
  Dropdown, DropdownToggle, DropdownItem, DropdownMenu
@@ -10,7 +9,6 @@ import './DataTableAdvFilter2.scss';
10
9
 
11
10
  export function DataTableAdvFilterSingleValue2({ field, fieldItems }) {
12
11
  const { updateSingleValueFilter, setFilterField } = useDataTableContext();
13
- const { t } = useTranslation();
14
12
  const [ dropdownOpen, setDropdownOpen ] = useState(false);
15
13
  const primaryFieldEntry = Object.entries(field)[0]; // Extracts the first key-value pair from the field object
16
14
 
@@ -3,6 +3,12 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ Object.defineProperty(exports, "DataTableAdvCustomFilter", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _DataTableAdvCustomFilter.DataTableAdvCustomFilter;
10
+ }
11
+ });
6
12
  Object.defineProperty(exports, "DataTableAdvFilterMultiValue2", {
7
13
  enumerable: true,
8
14
  get: function get() {
@@ -23,4 +29,5 @@ Object.defineProperty(exports, "DataTableFilter2", {
23
29
  });
24
30
  var _DataTableSimpleFilter = require("./DataTableSimpleFilter2.js");
25
31
  var _DataTableAdvFilterSingleValue = require("./DataTableAdvFilterSingleValue2.js");
26
- var _DataTableAdvFilterMultiValue = require("./DataTableAdvFilterMultiValue2.js");
32
+ var _DataTableAdvFilterMultiValue = require("./DataTableAdvFilterMultiValue2.js");
33
+ var _DataTableAdvCustomFilter = require("./DataTableAdvCustomFilter.js");
@@ -1,3 +1,4 @@
1
1
  export { DataTableFilter2 } from './DataTableSimpleFilter2.jsx';
2
2
  export { DataTableAdvFilterSingleValue2 } from './DataTableAdvFilterSingleValue2.jsx';
3
3
  export { DataTableAdvFilterMultiValue2 } from './DataTableAdvFilterMultiValue2.jsx';
4
+ export { DataTableAdvCustomFilter } from './DataTableAdvCustomFilter.jsx';
@@ -4,6 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.validateDateTime = validateDateTime;
7
+ // For best performance, create a regular expression only once.
8
+ var n_digits = /^\d+n$/;
7
9
  function validateDateTime(value) {
8
10
  // Return 'Invalid Date' if the input is null or undefined
9
11
  if (value == null) {
@@ -18,6 +20,15 @@ function validateDateTime(value) {
18
20
 
19
21
  // Handle string values
20
22
  if (typeof value === 'string') {
23
+ // Check if string ends with 'n' AND verify the entire string consists only of digits followed by 'n'
24
+ if (value.endsWith('n') && n_digits.test(value)) {
25
+ try {
26
+ // Remove the 'n' suffix before converting to BigInt
27
+ return splDatetimeToIso(BigInt(value.slice(0, -1)));
28
+ } catch (_unused) {
29
+ return 'Invalid Date';
30
+ }
31
+ }
21
32
  return new Date(value);
22
33
  }
23
34
 
@@ -1,3 +1,6 @@
1
+ // For best performance, create a regular expression only once.
2
+ const n_digits = /^\d+n$/;
3
+
1
4
  export function validateDateTime(value) {
2
5
  // Return 'Invalid Date' if the input is null or undefined
3
6
  if (value == null) {
@@ -12,6 +15,15 @@ export function validateDateTime(value) {
12
15
 
13
16
  // Handle string values
14
17
  if (typeof value === 'string') {
18
+ // Check if string ends with 'n' AND verify the entire string consists only of digits followed by 'n'
19
+ if (value.endsWith('n') && n_digits.test(value)) {
20
+ try {
21
+ // Remove the 'n' suffix before converting to BigInt
22
+ return splDatetimeToIso(BigInt(value.slice(0, -1)));
23
+ } catch {
24
+ return 'Invalid Date';
25
+ }
26
+ }
15
27
  return new Date(value);
16
28
  }
17
29
 
package/dist/index.js CHANGED
@@ -70,6 +70,12 @@ Object.defineProperty(exports, "DataTable2", {
70
70
  return _DataTable.DataTable2;
71
71
  }
72
72
  });
73
+ Object.defineProperty(exports, "DataTableAdvCustomFilter", {
74
+ enumerable: true,
75
+ get: function get() {
76
+ return _index2.DataTableAdvCustomFilter;
77
+ }
78
+ });
73
79
  Object.defineProperty(exports, "DataTableAdvFilterMultiValue2", {
74
80
  enumerable: true,
75
81
  get: function get() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "asab_webui_components",
3
- "version": "26.1.6",
3
+ "version": "26.1.8",
4
4
  "license": "BSD-3-Clause",
5
5
  "description": "TeskaLabs ASAB WebUI Components Library",
6
6
  "contributors": [