@followupus/common 0.8.7 → 0.8.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.
@@ -1,4 +1,4 @@
1
- import { IBaseCustomColumn, IBaseGroup, IFilter, IFilterCondition, IPureBoard } from "./types";
1
+ import { IBaseCustomColumn, IBaseGroup, IFilter, IFilterCondition, IPureBoard, IBaseItem } from "./types";
2
2
  export declare const COLUMN_TYPES: {
3
3
  NUMBER: string;
4
4
  TEXT: string;
@@ -58,4 +58,5 @@ export declare const getColumnValueType: (columnType: string) => "string" | "num
58
58
  export declare const getDateGroupKey: (dateStr: string) => string | null;
59
59
  export declare const getValidConditions: (filter: IFilter, headers?: IBaseCustomColumn[], currentUserId?: string, escapeHeaderCheck?: boolean) => IFilterCondition[];
60
60
  export declare const filterItemsByConditions: (groups: IBaseGroup[], filter: IFilter, headers?: IBaseCustomColumn[], currentUserId?: string) => IBaseGroup[];
61
+ export declare const isItemMatchedByConditions: (item: IBaseItem, filter: IFilter, headers?: IBaseCustomColumn[], currentUserId?: string) => boolean;
61
62
  export declare const filterBoardTree: (board: IPureBoard, filter: IFilter, currentUserId?: string) => IPureBoard;
@@ -372,6 +372,90 @@ const isLessEqual = (itemVal, condition) => {
372
372
  return parseVal ? itemVal <= parseVal : false;
373
373
  }
374
374
  };
375
+ const checkItemMatched = (item, validConditions, headers) => {
376
+ let isItemMatched = false;
377
+ for (const condition of validConditions) {
378
+ const header = headers?.find(h => h.columnId === condition.columnId);
379
+ const isLinkedColumn = isLinkedColumns(header?.type);
380
+ let checkHeader = header;
381
+ if (isLinkedColumn) {
382
+ checkHeader = header?.linked;
383
+ }
384
+ const valueType = getColumnValueType(checkHeader?.type ?? "");
385
+ const checkConditionFn = (itemVal) => {
386
+ let match = false;
387
+ const isDate = checkHeader?.type === COLUMN_TYPES.DATE;
388
+ switch (condition.op) {
389
+ case OP_TYPES.IS:
390
+ match = isDate
391
+ ? isDateInConditionValues(itemVal, condition)
392
+ : isInConditionValues(itemVal, valueType, condition);
393
+ break;
394
+ case OP_TYPES.IS_NOT:
395
+ match = isDate
396
+ ? !isDateInConditionValues(itemVal, condition)
397
+ : !isInConditionValues(itemVal, valueType, condition);
398
+ break;
399
+ case OP_TYPES.EMPTY:
400
+ match = isEmpty(itemVal, valueType);
401
+ break;
402
+ case OP_TYPES.NOT_EMPTY:
403
+ match = !isEmpty(itemVal, valueType);
404
+ break;
405
+ case OP_TYPES.CONTAINS:
406
+ match = isContains(itemVal, valueType, condition);
407
+ break;
408
+ case OP_TYPES.NOT_CONTAINS:
409
+ match = !isContains(itemVal, valueType, condition);
410
+ break;
411
+ case OP_TYPES.EQUAL:
412
+ match = isEquals(itemVal, valueType, condition);
413
+ break;
414
+ case OP_TYPES.NOT_EQUAL:
415
+ match = !isEquals(itemVal, valueType, condition);
416
+ break;
417
+ case OP_TYPES.GREATER:
418
+ match =
419
+ typeof itemVal === "number" ? isGreater(itemVal, condition) : false;
420
+ break;
421
+ case OP_TYPES.GREATER_EQUAL:
422
+ match =
423
+ typeof itemVal === "number"
424
+ ? isGreaterEqual(itemVal, condition)
425
+ : false;
426
+ break;
427
+ case OP_TYPES.LESS_EQUAL:
428
+ match =
429
+ typeof itemVal === "number"
430
+ ? isLessEqual(itemVal, condition)
431
+ : false;
432
+ break;
433
+ case OP_TYPES.LESS:
434
+ match =
435
+ typeof itemVal === "number" ? isLess(itemVal, condition) : false;
436
+ break;
437
+ default:
438
+ break;
439
+ }
440
+ return match;
441
+ };
442
+ const itemValue = isLinkedColumn
443
+ ? item.data?.[condition.columnId]
444
+ : item.data?.[condition.columnId]?.value;
445
+ if (isLinkedColumn) {
446
+ isItemMatched = !!itemValue?.some((item) => {
447
+ const val = item.value;
448
+ return checkConditionFn(val);
449
+ });
450
+ }
451
+ else {
452
+ isItemMatched = checkConditionFn(itemValue);
453
+ }
454
+ if (!isItemMatched)
455
+ return false;
456
+ }
457
+ return isItemMatched;
458
+ };
375
459
  export const filterItemsByConditions = (groups, filter, headers, currentUserId) => {
376
460
  if (!headers?.length)
377
461
  return groups;
@@ -381,96 +465,20 @@ export const filterItemsByConditions = (groups, filter, headers, currentUserId)
381
465
  }
382
466
  groups.forEach(g => {
383
467
  g.items = g.items?.filter(item => {
384
- let isItemMatched = false;
385
- for (const condition of validConditions) {
386
- const header = headers?.find(h => h.columnId === condition.columnId);
387
- const isLinkedColumn = isLinkedColumns(header?.type);
388
- let checkHeader = header;
389
- if (isLinkedColumn) {
390
- checkHeader = header?.linked;
391
- }
392
- const valueType = getColumnValueType(checkHeader?.type ?? "");
393
- const checkConditionFn = (itemVal) => {
394
- let match = false;
395
- const isDate = checkHeader?.type === COLUMN_TYPES.DATE;
396
- switch (condition.op) {
397
- case OP_TYPES.IS:
398
- match = isDate
399
- ? isDateInConditionValues(itemVal, condition)
400
- : isInConditionValues(itemVal, valueType, condition);
401
- break;
402
- case OP_TYPES.IS_NOT:
403
- match = isDate
404
- ? !isDateInConditionValues(itemVal, condition)
405
- : !isInConditionValues(itemVal, valueType, condition);
406
- break;
407
- case OP_TYPES.EMPTY:
408
- match = isEmpty(itemVal, valueType);
409
- break;
410
- case OP_TYPES.NOT_EMPTY:
411
- match = !isEmpty(itemVal, valueType);
412
- break;
413
- case OP_TYPES.CONTAINS:
414
- match = isContains(itemVal, valueType, condition);
415
- break;
416
- case OP_TYPES.NOT_CONTAINS:
417
- match = !isContains(itemVal, valueType, condition);
418
- break;
419
- case OP_TYPES.EQUAL:
420
- match = isEquals(itemVal, valueType, condition);
421
- break;
422
- case OP_TYPES.NOT_EQUAL:
423
- match = !isEquals(itemVal, valueType, condition);
424
- break;
425
- case OP_TYPES.GREATER:
426
- match =
427
- typeof itemVal === "number"
428
- ? isGreater(itemVal, condition)
429
- : false;
430
- break;
431
- case OP_TYPES.GREATER_EQUAL:
432
- match =
433
- typeof itemVal === "number"
434
- ? isGreaterEqual(itemVal, condition)
435
- : false;
436
- break;
437
- case OP_TYPES.LESS_EQUAL:
438
- match =
439
- typeof itemVal === "number"
440
- ? isLessEqual(itemVal, condition)
441
- : false;
442
- break;
443
- case OP_TYPES.LESS:
444
- match =
445
- typeof itemVal === "number"
446
- ? isLess(itemVal, condition)
447
- : false;
448
- break;
449
- default:
450
- break;
451
- }
452
- return match;
453
- };
454
- const itemValue = isLinkedColumn
455
- ? item.data?.[condition.columnId]
456
- : item.data?.[condition.columnId]?.value;
457
- if (isLinkedColumn) {
458
- isItemMatched = !!itemValue?.some((item) => {
459
- const val = item.value;
460
- return checkConditionFn(val);
461
- });
462
- }
463
- else {
464
- isItemMatched = checkConditionFn(itemValue);
465
- }
466
- if (!isItemMatched)
467
- return false;
468
- }
469
- return isItemMatched;
468
+ return checkItemMatched(item, validConditions, headers);
470
469
  });
471
470
  });
472
471
  return groups;
473
472
  };
473
+ export const isItemMatchedByConditions = (item, filter, headers, currentUserId) => {
474
+ if (!headers?.length)
475
+ return true;
476
+ const validConditions = getValidConditions(filter, headers, currentUserId);
477
+ if (!validConditions?.length) {
478
+ return true;
479
+ }
480
+ return checkItemMatched(item, validConditions, headers);
481
+ };
474
482
  export const filterBoardTree = (board, filter, currentUserId) => {
475
483
  if (!board?.groups?.length || !board?.headers?.length || !filter)
476
484
  return board;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@followupus/common",
3
- "version": "0.8.7",
3
+ "version": "0.8.8",
4
4
  "description": "followup common utils npm package with TypeScript and VSCode",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",