@followupus/common 0.10.19 → 0.10.21

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.
@@ -9,6 +9,7 @@ export declare const ACTION_TYPE: {
9
9
  };
10
10
  export declare const OBJECT_TYPE: {
11
11
  WORKSPACE: string;
12
+ APP: string;
12
13
  FOLDER: string;
13
14
  BOARD: string;
14
15
  VIEW: string;
@@ -21,24 +22,25 @@ export declare const OBJECT_TYPE: {
21
22
  ACTION: string;
22
23
  };
23
24
  export declare const COLUMN_TYPES: {
24
- NUMBER: string;
25
25
  TEXT: string;
26
- DROPDOWN: string;
27
26
  DATE: string;
28
27
  STATUS: string;
29
28
  PRIORITY: string;
30
- LINK: string;
31
- TAGS: string;
32
- EMAIL: string;
33
29
  PEOPLE: string;
34
- LINKED_COLUMN: string;
35
- REF_LINED_COLUMN: string;
36
- FILES: string;
30
+ EMAIL: string;
31
+ PHONE: string;
37
32
  HOURS: string;
33
+ TIME_TRACKING: string;
38
34
  TIMELINE: string;
39
- PHONE: string;
40
35
  CURRENCY: string;
41
- TIME_TRACKING: string;
36
+ NUMBER: string;
37
+ DROPDOWN: string;
38
+ TAGS: string;
39
+ LINK: string;
40
+ FILES: string;
41
+ AUTO_NUMBER: string;
42
+ LINKED_COLUMN: string;
43
+ REF_LINED_COLUMN: string;
42
44
  CREATED_BY: string;
43
45
  CREATED_AT: string;
44
46
  };
@@ -98,7 +100,12 @@ export declare const getColumnTypeFromId: (columnId: string) => string | undefin
98
100
  export declare const getColumnValueType: (columnType: string) => "string" | "number" | "object" | "stringArray" | "objectArray";
99
101
  export declare const getFilterDateGroupKeys: (dateStr: string) => string[] | null;
100
102
  export declare const getDateGroupKey: (dateStr: string) => string | null;
103
+ export declare const extractDomain: (url?: string) => string | undefined;
101
104
  export declare const getValidConditions: (filter: IFilter, headers?: IBaseCustomColumn[], currentUserId?: string, escapeHeaderCheck?: boolean) => IFilterCondition[];
105
+ export declare const isDateMatchConditionValue: (dateVal: string, conditionValue: string | {
106
+ start: string;
107
+ end: string;
108
+ }) => boolean;
102
109
  export declare const isDateInConditionValues: (itemVal: any, condition: IFilterCondition) => boolean;
103
110
  export declare const filterItemsByConditions: (groups: IBaseGroup[], filter: IFilter, headers?: IBaseCustomColumn[], currentUserId?: string) => IBaseGroup[];
104
111
  export declare const isItemMatchedByConditions: (item: IBaseItem, filter: IFilter, headers?: IBaseCustomColumn[], currentUserId?: string) => boolean;
@@ -1,5 +1,7 @@
1
+ import { phoneCountryList } from "./phone";
1
2
  import dayjs from "dayjs";
2
3
  import _ from "lodash";
4
+ // the key order is used for Add Column Menu order, keep it
3
5
  //One-to-One Matching UI.
4
6
  export const ACTION_TYPE = {
5
7
  CREATE: "CREATE",
@@ -12,6 +14,7 @@ export const ACTION_TYPE = {
12
14
  // One-to-One Matching UI.
13
15
  export const OBJECT_TYPE = {
14
16
  WORKSPACE: "workspace",
17
+ APP: "app",
15
18
  FOLDER: "folder",
16
19
  BOARD: "board",
17
20
  VIEW: "view",
@@ -24,24 +27,25 @@ export const OBJECT_TYPE = {
24
27
  ACTION: "action",
25
28
  };
26
29
  export const COLUMN_TYPES = {
27
- NUMBER: "number",
28
30
  TEXT: "string",
29
- DROPDOWN: "dropdown",
30
31
  DATE: "date",
31
32
  STATUS: "status",
32
33
  PRIORITY: "priority",
33
- LINK: "link",
34
- TAGS: "tags",
35
- EMAIL: "email",
36
34
  PEOPLE: "people",
37
- LINKED_COLUMN: "linked_column",
38
- REF_LINED_COLUMN: "ref_linked_column",
39
- FILES: "files",
35
+ EMAIL: "email",
36
+ PHONE: "phone",
40
37
  HOURS: "hours",
38
+ TIME_TRACKING: "time_tracking",
41
39
  TIMELINE: "timeline",
42
- PHONE: "phone",
43
40
  CURRENCY: "currency",
44
- TIME_TRACKING: "time_tracking",
41
+ NUMBER: "number",
42
+ DROPDOWN: "dropdown",
43
+ TAGS: "tags",
44
+ LINK: "link",
45
+ FILES: "files",
46
+ AUTO_NUMBER: "auto_number",
47
+ LINKED_COLUMN: "linked_column",
48
+ REF_LINED_COLUMN: "ref_linked_column",
45
49
  CREATED_BY: "created_by",
46
50
  CREATED_AT: "created_at",
47
51
  };
@@ -71,6 +75,18 @@ export const COLUMN_OP_TYPES = {
71
75
  OP_TYPES.EMPTY,
72
76
  OP_TYPES.NOT_EMPTY,
73
77
  ],
78
+ [COLUMN_TYPES.LINK]: [
79
+ OP_TYPES.CONTAINS,
80
+ OP_TYPES.NOT_CONTAINS,
81
+ OP_TYPES.EMPTY,
82
+ OP_TYPES.NOT_EMPTY,
83
+ ],
84
+ [COLUMN_TYPES.PHONE]: [
85
+ OP_TYPES.CONTAINS,
86
+ OP_TYPES.NOT_CONTAINS,
87
+ OP_TYPES.EMPTY,
88
+ OP_TYPES.NOT_EMPTY,
89
+ ],
74
90
  [COLUMN_TYPES.EMAIL]: [
75
91
  OP_TYPES.CONTAINS,
76
92
  OP_TYPES.NOT_CONTAINS,
@@ -167,6 +183,8 @@ export const AUTOMATION_OP_TYPES = {
167
183
  OP_TYPES.NOT_EMPTY,
168
184
  ],
169
185
  [COLUMN_TYPES.EMAIL]: [OP_TYPES.CONTAINS, OP_TYPES.NOT_CONTAINS],
186
+ [COLUMN_TYPES.LINK]: [OP_TYPES.CONTAINS, OP_TYPES.NOT_CONTAINS],
187
+ [COLUMN_TYPES.PHONE]: [OP_TYPES.CONTAINS, OP_TYPES.NOT_CONTAINS],
170
188
  // [COLUMN_TYPES.DATE]: [
171
189
  // OP_TYPES.EQUAL,
172
190
  // OP_TYPES.NOT_EQUAL,
@@ -235,6 +253,7 @@ export const getColumnValueType = (columnType) => {
235
253
  case COLUMN_TYPES.TIMELINE:
236
254
  case COLUMN_TYPES.TIME_TRACKING:
237
255
  case COLUMN_TYPES.LINK:
256
+ case COLUMN_TYPES.PHONE:
238
257
  return "object";
239
258
  case COLUMN_TYPES.NUMBER:
240
259
  case COLUMN_TYPES.HOURS:
@@ -310,6 +329,22 @@ export const getDateGroupKey = (dateStr) => {
310
329
  }
311
330
  return DATE_GROUPS.FUTURE;
312
331
  };
332
+ export const extractDomain = (url) => {
333
+ const regex = /^(?:https?:\/\/)?(?:www\.)?([^/:]+)/i;
334
+ const match = url?.match(regex);
335
+ return match ? match[1] : undefined;
336
+ };
337
+ // export const extractDomainName = (url?: string) => {
338
+ // const regex = /^(?:https?:\/\/)?(?:www\.)?([^/:]+)/i;
339
+ // const match = url?.match(regex);
340
+ // if (!match) return undefined;
341
+ // const domainParts = match[1].split(".");
342
+ // if (domainParts.length > 1) {
343
+ // domainParts.pop();
344
+ // }
345
+ //
346
+ // return domainParts.join(".");
347
+ // };
313
348
  export const getValidConditions = (filter, headers, currentUserId, escapeHeaderCheck) => {
314
349
  const newFilter = _.cloneDeep(filter);
315
350
  if (!newFilter?.criteria?.length || !headers?.length) {
@@ -412,29 +447,34 @@ const isInConditionValues = (itemVal, valueType, condition) => {
412
447
  }
413
448
  return false;
414
449
  };
450
+ export const isDateMatchConditionValue = (dateVal, conditionValue) => {
451
+ const checkDate = dayjs(dateVal);
452
+ if (!checkDate.isValid())
453
+ return false;
454
+ if (conditionValue && typeof conditionValue === "object") {
455
+ // range
456
+ const startDt = dayjs(conditionValue.start);
457
+ const endDt = dayjs(conditionValue.end);
458
+ return (startDt.isValid() &&
459
+ endDt.isValid() &&
460
+ (checkDate.isAfter(startDt, "date") ||
461
+ checkDate.isSame(startDt, "date")) &&
462
+ (checkDate.isBefore(endDt, "date") || checkDate.isSame(endDt, "date")));
463
+ }
464
+ else if (dayjs(conditionValue).isValid()) {
465
+ return checkDate.isSame(dayjs(conditionValue), "date");
466
+ }
467
+ else {
468
+ const groupKeys = getFilterDateGroupKeys(dateVal);
469
+ return !!groupKeys?.includes(conditionValue);
470
+ }
471
+ };
415
472
  export const isDateInConditionValues = (itemVal, condition) => {
416
473
  if (!itemVal || !dayjs(itemVal).isValid()) {
417
474
  return !!condition.blank;
418
475
  }
419
- const itemDate = dayjs(itemVal);
420
476
  return !!condition.value?.some(c => {
421
- if (c && typeof c === "object") {
422
- // range
423
- const startDt = dayjs(c.start);
424
- const endDt = dayjs(c.end);
425
- return (startDt.isValid() &&
426
- endDt.isValid() &&
427
- (itemDate.isAfter(startDt, "date") ||
428
- itemDate.isSame(startDt, "date")) &&
429
- (itemDate.isBefore(endDt, "date") || itemDate.isSame(endDt, "date")));
430
- }
431
- else if (dayjs(c).isValid()) {
432
- return itemDate.isSame(dayjs(c), "date");
433
- }
434
- else {
435
- const groupKeys = getFilterDateGroupKeys(itemVal);
436
- return !!groupKeys?.includes(c);
437
- }
477
+ return isDateMatchConditionValue(itemVal, c);
438
478
  });
439
479
  // if (!groupKey) return !!condition.blank;
440
480
  // return !!condition.value?.find((dateGroup) => dateGroup === groupKey);
@@ -465,7 +505,13 @@ const isDateAfterConditionValues = (itemVal, condition) => {
465
505
  }
466
506
  });
467
507
  };
468
- const isEmpty = (itemVal, valueType) => {
508
+ const isEmpty = (itemVal, valueType, columnType) => {
509
+ const isLink = columnType === COLUMN_TYPES.LINK;
510
+ const isPhone = columnType === COLUMN_TYPES.PHONE;
511
+ if (isLink)
512
+ return !itemVal?.url;
513
+ if (isPhone)
514
+ return !itemVal?.value;
469
515
  switch (valueType) {
470
516
  case "number":
471
517
  case "string":
@@ -481,13 +527,28 @@ const isEmpty = (itemVal, valueType) => {
481
527
  }
482
528
  return true;
483
529
  };
484
- const isContains = (itemVal, valueType, condition) => {
530
+ const isContains = (itemVal, valueType, condition, columnType) => {
531
+ const isLink = columnType === COLUMN_TYPES.LINK;
532
+ const isPhone = columnType === COLUMN_TYPES.PHONE;
485
533
  const checkVal = condition.value?.length
486
534
  ? condition.value[0]
487
535
  : "";
488
536
  const ignoreCaseCheck = (val, contains) => {
489
537
  return !!val?.toLowerCase()?.includes(contains?.toLowerCase());
490
538
  };
539
+ if (isLink) {
540
+ return (ignoreCaseCheck(itemVal?.title ?? "", checkVal) ||
541
+ ignoreCaseCheck(extractDomain(itemVal?.url ?? "") ?? "", checkVal));
542
+ }
543
+ if (isPhone) {
544
+ const phoneNum = itemVal?.value && itemVal?.iso2
545
+ ? (phoneCountryList.find(k => k.iso2 === itemVal.iso2)?.code ?? "") +
546
+ itemVal.value
547
+ : "";
548
+ return !!phoneNum
549
+ ?.replaceAll(/\D/g, "")
550
+ ?.includes(checkVal?.replaceAll(/\D/g, ""));
551
+ }
491
552
  switch (valueType) {
492
553
  case "number":
493
554
  return itemVal || itemVal === 0
@@ -594,16 +655,16 @@ const checkItemMatched = (item, validConditions, headers, matchAny) => {
594
655
  match = isDate && isDateAfterConditionValues(itemVal, condition);
595
656
  break;
596
657
  case OP_TYPES.EMPTY:
597
- match = isEmpty(itemVal, valueType);
658
+ match = isEmpty(itemVal, valueType, checkHeader?.type);
598
659
  break;
599
660
  case OP_TYPES.NOT_EMPTY:
600
- match = !isEmpty(itemVal, valueType);
661
+ match = !isEmpty(itemVal, valueType, checkHeader?.type);
601
662
  break;
602
663
  case OP_TYPES.CONTAINS:
603
- match = isContains(itemVal, valueType, condition);
664
+ match = isContains(itemVal, valueType, condition, checkHeader?.type);
604
665
  break;
605
666
  case OP_TYPES.NOT_CONTAINS:
606
- match = !isContains(itemVal, valueType, condition);
667
+ match = !isContains(itemVal, valueType, condition, checkHeader?.type);
607
668
  break;
608
669
  case OP_TYPES.EQUAL:
609
670
  match = isEquals(itemVal, valueType, condition);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@followupus/common",
3
- "version": "0.10.19",
3
+ "version": "0.10.21",
4
4
  "description": "followup common utils npm package with TypeScript and VSCode",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",