@followupus/common 0.8.5 → 0.8.6

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
@@ -1,6 +1,7 @@
1
1
  # common
2
2
 
3
3
  ## add a changelog after some modifications
4
+
4
5
  ```sh
5
6
  pnpm changeset
6
7
  ```
package/dist/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './shared/index.js';
2
- export * from './utils/index.js';
1
+ export * from "./shared/index.js";
2
+ export * from "./utils/index.js";
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- export * from './shared/index.js';
2
- export * from './utils/index.js';
1
+ export * from "./shared/index.js";
2
+ export * from "./utils/index.js";
@@ -1,4 +1,4 @@
1
- import { IBaseCustomColumn, IBaseGroup, IFilter, IFilterCondition, IPureBoard } from './types';
1
+ import { IBaseCustomColumn, IBaseGroup, IFilter, IFilterCondition, IPureBoard } from "./types";
2
2
  export declare const COLUMN_TYPES: {
3
3
  NUMBER: string;
4
4
  TEXT: string;
@@ -52,6 +52,7 @@ export declare const DATE_GROUPS: {
52
52
  THIS_MONTH: string;
53
53
  FUTURE: string;
54
54
  };
55
+ export declare const isLinkedColumns: (columnType?: string) => boolean;
55
56
  export declare const getColumnValueType: (columnType: string) => "string" | "number" | "object" | "stringArray" | "objectArray";
56
57
  export declare const getDateGroupKey: (dateStr: string) => string | null;
57
58
  export declare const getValidConditions: (filter: IFilter, headers?: IBaseCustomColumn[], currentUserId?: string) => IFilterCondition[];
@@ -1,5 +1,5 @@
1
1
  import dayjs from "dayjs";
2
- import _ from 'lodash';
2
+ import _ from "lodash";
3
3
  export const COLUMN_TYPES = {
4
4
  NUMBER: "number",
5
5
  TEXT: "string",
@@ -75,6 +75,12 @@ export const COLUMN_OP_TYPES = {
75
75
  OP_TYPES.EMPTY,
76
76
  OP_TYPES.NOT_EMPTY,
77
77
  ],
78
+ [COLUMN_TYPES.TAGS]: [
79
+ OP_TYPES.IS,
80
+ OP_TYPES.IS_NOT,
81
+ OP_TYPES.EMPTY,
82
+ OP_TYPES.NOT_EMPTY,
83
+ ],
78
84
  [COLUMN_TYPES.PEOPLE]: [
79
85
  OP_TYPES.IS,
80
86
  OP_TYPES.IS_NOT,
@@ -110,6 +116,11 @@ export const DATE_GROUPS = {
110
116
  THIS_MONTH: "thisMonth",
111
117
  FUTURE: "future",
112
118
  };
119
+ export const isLinkedColumns = (columnType) => {
120
+ if (!columnType)
121
+ return false;
122
+ return [COLUMN_TYPES.LINKED_COLUMN, COLUMN_TYPES.REF_LINED_COLUMN].includes(columnType);
123
+ };
113
124
  export const getColumnValueType = (columnType) => {
114
125
  switch (columnType) {
115
126
  case COLUMN_TYPES.PEOPLE:
@@ -117,6 +128,7 @@ export const getColumnValueType = (columnType) => {
117
128
  case COLUMN_TYPES.TAGS:
118
129
  return "stringArray";
119
130
  case COLUMN_TYPES.TIMELINE:
131
+ case COLUMN_TYPES.TIME_TRACKING:
120
132
  return "object";
121
133
  case COLUMN_TYPES.NUMBER:
122
134
  case COLUMN_TYPES.HOURS:
@@ -169,7 +181,13 @@ export const getValidConditions = (filter, headers, currentUserId) => {
169
181
  }
170
182
  newFilter.criteria.forEach(c => {
171
183
  const validHeader = headers.find(h => h.columnId === c.columnId);
172
- if (validHeader?.type === COLUMN_TYPES.PEOPLE) {
184
+ let checkHeader = validHeader;
185
+ if (isLinkedColumns(validHeader?.type)) {
186
+ checkHeader = validHeader?.linked;
187
+ }
188
+ if (!checkHeader)
189
+ return;
190
+ if (checkHeader?.type === COLUMN_TYPES.PEOPLE) {
173
191
  if (c.value?.find(val => val === THEMSELVES) && currentUserId) {
174
192
  const idx = c.value.findIndex(val => val === THEMSELVES);
175
193
  if (idx > -1)
@@ -182,21 +200,28 @@ export const getValidConditions = (filter, headers, currentUserId) => {
182
200
  const validHeader = headers.find(h => h.columnId === c.columnId);
183
201
  if (!validHeader)
184
202
  return false;
185
- const validOperate = COLUMN_OP_TYPES[validHeader.type].includes(c.op);
203
+ let checkHeader = validHeader;
204
+ if (isLinkedColumns(validHeader.type)) {
205
+ checkHeader = validHeader.linked;
206
+ }
207
+ if (!checkHeader)
208
+ return false;
209
+ const validOperate = COLUMN_OP_TYPES[checkHeader.type]?.includes(c.op);
186
210
  if (!validOperate)
187
211
  return false;
188
212
  const isDropdown = [
189
213
  COLUMN_TYPES.DROPDOWN,
190
214
  COLUMN_TYPES.STATUS,
191
215
  COLUMN_TYPES.PRIORITY,
192
- ].includes(validHeader.type);
216
+ COLUMN_TYPES.TAGS,
217
+ ].includes(checkHeader.type);
193
218
  switch (c.op) {
194
219
  case OP_TYPES.IS:
195
220
  case OP_TYPES.IS_NOT:
196
221
  return (c.blank ||
197
222
  (!!c.value?.filter(v => !!v || v === 0)?.length &&
198
223
  (!isDropdown ||
199
- c.value.some(v => validHeader.dropdowns?.find(d => d.key === v)))));
224
+ c.value.some(v => checkHeader.dropdowns?.find(d => d.key === v)))));
200
225
  case OP_TYPES.EMPTY:
201
226
  case OP_TYPES.NOT_EMPTY:
202
227
  return true;
@@ -264,16 +289,19 @@ const isContains = (itemVal, valueType, condition) => {
264
289
  const checkVal = condition.value?.length
265
290
  ? condition.value[0]
266
291
  : "";
292
+ const ignoreCaseCheck = (val, contains) => {
293
+ return !!val?.toLowerCase()?.includes(contains?.toLowerCase());
294
+ };
267
295
  switch (valueType) {
268
296
  case "number":
269
297
  return itemVal || itemVal === 0
270
- ? itemVal.toString().includes(checkVal)
298
+ ? itemVal?.toString()?.includes(checkVal)
271
299
  : false;
272
300
  case "string":
273
- return !!itemVal && itemVal.includes(checkVal);
301
+ return !!itemVal && ignoreCaseCheck(itemVal, checkVal);
274
302
  case "stringArray":
275
303
  return itemVal?.length
276
- ? itemVal.some(val => val.includes(checkVal))
304
+ ? itemVal.some(val => ignoreCaseCheck(val, checkVal))
277
305
  : false;
278
306
  default:
279
307
  break;
@@ -345,70 +373,92 @@ export const filterItemsByConditions = (groups, filter, headers, currentUserId)
345
373
  }
346
374
  groups.forEach(g => {
347
375
  g.items = g.items?.filter(item => {
348
- let match = false;
376
+ let isItemMatched = false;
349
377
  for (const condition of validConditions) {
350
378
  const header = headers?.find(h => h.columnId === condition.columnId);
351
- const valueType = getColumnValueType(header?.type ?? "");
352
- const itemVal = item.data?.[condition.columnId]?.value;
353
- const isDate = header?.type === COLUMN_TYPES.DATE;
354
- switch (condition.op) {
355
- case OP_TYPES.IS:
356
- match = isDate
357
- ? isDateInConditionValues(itemVal, condition)
358
- : isInConditionValues(itemVal, valueType, condition);
359
- break;
360
- case OP_TYPES.IS_NOT:
361
- match = isDate
362
- ? !isDateInConditionValues(itemVal, condition)
363
- : !isInConditionValues(itemVal, valueType, condition);
364
- break;
365
- case OP_TYPES.EMPTY:
366
- match = isEmpty(itemVal, valueType);
367
- break;
368
- case OP_TYPES.NOT_EMPTY:
369
- match = !isEmpty(itemVal, valueType);
370
- break;
371
- case OP_TYPES.CONTAINS:
372
- match = isContains(itemVal, valueType, condition);
373
- break;
374
- case OP_TYPES.NOT_CONTAINS:
375
- match = !isContains(itemVal, valueType, condition);
376
- break;
377
- case OP_TYPES.EQUAL:
378
- match = isEquals(itemVal, valueType, condition);
379
- break;
380
- case OP_TYPES.NOT_EQUAL:
381
- match = !isEquals(itemVal, valueType, condition);
382
- break;
383
- case OP_TYPES.GREATER:
384
- match =
385
- typeof itemVal === "number"
386
- ? isGreater(itemVal, condition)
387
- : false;
388
- break;
389
- case OP_TYPES.GREATER_EQUAL:
390
- match =
391
- typeof itemVal === "number"
392
- ? isGreaterEqual(itemVal, condition)
393
- : false;
394
- break;
395
- case OP_TYPES.LESS_EQUAL:
396
- match =
397
- typeof itemVal === "number"
398
- ? isLessEqual(itemVal, condition)
399
- : false;
400
- break;
401
- case OP_TYPES.LESS:
402
- match =
403
- typeof itemVal === "number" ? isLess(itemVal, condition) : false;
404
- break;
405
- default:
406
- break;
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"
420
+ ? isGreater(itemVal, condition)
421
+ : false;
422
+ break;
423
+ case OP_TYPES.GREATER_EQUAL:
424
+ match =
425
+ typeof itemVal === "number"
426
+ ? isGreaterEqual(itemVal, condition)
427
+ : false;
428
+ break;
429
+ case OP_TYPES.LESS_EQUAL:
430
+ match =
431
+ typeof itemVal === "number"
432
+ ? isLessEqual(itemVal, condition)
433
+ : false;
434
+ break;
435
+ case OP_TYPES.LESS:
436
+ match =
437
+ typeof itemVal === "number"
438
+ ? isLess(itemVal, condition)
439
+ : false;
440
+ break;
441
+ default:
442
+ break;
443
+ }
444
+ return match;
445
+ };
446
+ const itemValue = isLinkedColumn
447
+ ? item.data?.[condition.columnId]
448
+ : item.data?.[condition.columnId]?.value;
449
+ if (isLinkedColumn) {
450
+ isItemMatched = !!itemValue?.some((item) => {
451
+ const val = item.value;
452
+ return checkConditionFn(val);
453
+ });
454
+ }
455
+ else {
456
+ isItemMatched = checkConditionFn(itemValue);
407
457
  }
408
- if (!match)
458
+ if (!isItemMatched)
409
459
  return false;
410
460
  }
411
- return match;
461
+ return isItemMatched;
412
462
  });
413
463
  });
414
464
  return groups;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@followupus/common",
3
- "version": "0.8.5",
3
+ "version": "0.8.6",
4
4
  "description": "followup common utils npm package with TypeScript and VSCode",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",