@followupus/common 0.7.6 → 0.7.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.
@@ -32,6 +32,7 @@ export interface DeltaMessages {
32
32
  payload: {
33
33
  syncData: DeltaObject[];
34
34
  lastSyncId: number;
35
+ rootType: keyof typeof DELTA_ROOT_SCHEMA_NAME;
35
36
  };
36
37
  }
37
38
  export declare const PREFIX_PK: {
@@ -7,9 +7,9 @@ export const DELTA_SCHEMA_NAME = {
7
7
  FOLDER: "FOLDER",
8
8
  };
9
9
  export const DELTA_ACTION = {
10
- DELETE: "D",
11
- UPDATE: "U",
12
- CREATE: "C",
10
+ DELETE: "delete",
11
+ UPDATE: "update",
12
+ CREATE: "create",
13
13
  };
14
14
  export const DELTA_ROOT_SCHEMA_NAME = {
15
15
  USERS: "USERS",
@@ -39,6 +39,10 @@ export declare const COLUMN_OP_TYPES: {
39
39
  export declare const AUTOMATION_OP_TYPES: {
40
40
  [x: string]: string[];
41
41
  };
42
+ export declare const DYNAMIC_VIEW_OP_TYPES: {
43
+ [x: string]: string[];
44
+ };
45
+ export declare const THEMSELVES = "self";
42
46
  export declare const DATE_GROUPS: {
43
47
  OVERDUE: string;
44
48
  TODAY: string;
@@ -50,6 +54,6 @@ export declare const DATE_GROUPS: {
50
54
  };
51
55
  export declare const getColumnValueType: (columnType: string) => "string" | "number" | "object" | "stringArray" | "objectArray";
52
56
  export declare const getDateGroupKey: (dateStr: string) => string | null;
53
- export declare const getValidConditions: (filter: IFilter, headers?: IBaseCustomColumn[]) => IFilterCondition[];
54
- export declare const filterItemsByConditions: (groups: IBaseGroup[], filter: IFilter, headers?: IBaseCustomColumn[]) => IBaseGroup[];
55
- export declare const filterBoardTree: (board: IPureBoard, filter: IFilter) => IPureBoard;
57
+ export declare const getValidConditions: (filter: IFilter, headers?: IBaseCustomColumn[], currentUserId?: string) => IFilterCondition[];
58
+ export declare const filterItemsByConditions: (groups: IBaseGroup[], filter: IFilter, headers?: IBaseCustomColumn[], currentUserId?: string) => IBaseGroup[];
59
+ export declare const filterBoardTree: (board: IPureBoard, filter: IFilter, currentUserId?: string) => IPureBoard;
@@ -1,4 +1,4 @@
1
- import * as _ from "lodash";
1
+ import { cloneDeep, isEqual } from "lodash";
2
2
  import dayjs from "dayjs";
3
3
  export const COLUMN_TYPES = {
4
4
  NUMBER: "number",
@@ -96,6 +96,11 @@ export const AUTOMATION_OP_TYPES = {
96
96
  OP_TYPES.NOT_EMPTY,
97
97
  ],
98
98
  };
99
+ export const DYNAMIC_VIEW_OP_TYPES = {
100
+ ...COLUMN_OP_TYPES,
101
+ [COLUMN_TYPES.TEXT]: [OP_TYPES.CONTAINS, OP_TYPES.NOT_CONTAINS],
102
+ };
103
+ export const THEMSELVES = "self";
99
104
  export const DATE_GROUPS = {
100
105
  OVERDUE: "overdue",
101
106
  TODAY: "today",
@@ -157,12 +162,23 @@ export const getDateGroupKey = (dateStr) => {
157
162
  }
158
163
  return DATE_GROUPS.FUTURE;
159
164
  };
160
- export const getValidConditions = (filter, headers) => {
161
- if (!filter.criteria?.length || !headers?.length) {
165
+ export const getValidConditions = (filter, headers, currentUserId) => {
166
+ const newFilter = cloneDeep(filter);
167
+ if (!newFilter.criteria?.length || !headers?.length) {
162
168
  return [];
163
169
  }
170
+ newFilter.criteria.forEach(c => {
171
+ const validHeader = headers.find(h => h.columnId === c.columnId);
172
+ if (validHeader?.type === COLUMN_TYPES.PEOPLE) {
173
+ if (c.value?.find(val => val === THEMSELVES) && currentUserId) {
174
+ const idx = c.value.findIndex(val => val === THEMSELVES);
175
+ if (idx > -1)
176
+ c.value.splice(idx, 1, currentUserId);
177
+ }
178
+ }
179
+ });
164
180
  // for dropdown, if set the option is in filter condition, and user delete the option. should ignore it or make the option can't be deleted
165
- return filter.criteria.filter(c => {
181
+ return newFilter.criteria.filter(c => {
166
182
  const validHeader = headers.find(h => h.columnId === c.columnId);
167
183
  if (!validHeader)
168
184
  return false;
@@ -210,11 +226,11 @@ const isInConditionValues = (itemVal, valueType, condition) => {
210
226
  condition.value.some(val => Array.isArray(itemVal) && itemVal?.includes(val)));
211
227
  case "object":
212
228
  return ((condition.blank && !itemVal) ||
213
- !!condition.value.find(val => _.isEqual(val, itemVal)));
229
+ !!condition.value.find(val => isEqual(val, itemVal)));
214
230
  case "objectArray":
215
231
  return ((condition.blank && !itemVal?.length) ||
216
232
  condition.value.some(val => Array.isArray(itemVal) &&
217
- itemVal.find(existVal => _.isEqual(val, existVal))));
233
+ itemVal.find(existVal => isEqual(val, existVal))));
218
234
  default:
219
235
  break;
220
236
  }
@@ -274,7 +290,7 @@ const isEquals = (itemVal, valueType, condition) => {
274
290
  case "string":
275
291
  return !!itemVal && checkVal === itemVal;
276
292
  case "object":
277
- return _.isEqual(itemVal, checkVal);
293
+ return isEqual(itemVal, checkVal);
278
294
  default:
279
295
  break;
280
296
  }
@@ -320,10 +336,10 @@ const isLessEqual = (itemVal, condition) => {
320
336
  return parseVal ? itemVal <= parseVal : false;
321
337
  }
322
338
  };
323
- export const filterItemsByConditions = (groups, filter, headers) => {
339
+ export const filterItemsByConditions = (groups, filter, headers, currentUserId) => {
324
340
  if (!headers?.length)
325
341
  return groups;
326
- const validConditions = getValidConditions(filter, headers);
342
+ const validConditions = getValidConditions(filter, headers, currentUserId);
327
343
  if (!validConditions?.length) {
328
344
  return groups;
329
345
  }
@@ -397,11 +413,11 @@ export const filterItemsByConditions = (groups, filter, headers) => {
397
413
  });
398
414
  return groups;
399
415
  };
400
- export const filterBoardTree = (board, filter) => {
416
+ export const filterBoardTree = (board, filter, currentUserId) => {
401
417
  if (!board?.groups?.length || !board?.headers?.length || !filter)
402
418
  return board;
403
419
  return {
404
420
  ...board,
405
- groups: filterItemsByConditions(board.groups, filter, board.headers),
421
+ groups: filterItemsByConditions(board.groups, filter, board.headers, currentUserId),
406
422
  };
407
423
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@followupus/common",
3
- "version": "0.7.6",
3
+ "version": "0.7.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",