@outliant/sunrise-utils 1.1.4 → 1.1.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/.eslintrc CHANGED
@@ -48,6 +48,7 @@
48
48
  "space-infix-ops": "error",
49
49
  "no-undef": "error",
50
50
  "object-curly-spacing": ["error", "always"],
51
+ "no-unused-vars": "error",
51
52
  "indent": [
52
53
  "error",
53
54
  2,
package/CHANGELOG.md CHANGED
@@ -4,9 +4,25 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [1.1.6](https://github.com/outliant/sunrise-utils/compare/1.1.5...1.1.6)
8
+
9
+ - chore: change logic for last/next n days filter [`#10`](https://github.com/outliant/sunrise-utils/pull/10)
10
+
11
+ #### [1.1.5](https://github.com/outliant/sunrise-utils/compare/1.1.4...1.1.5)
12
+
13
+ > 19 May 2023
14
+
15
+ - Task/project banner #866a3c0ug [`#9`](https://github.com/outliant/sunrise-utils/pull/9)
16
+ - chore: filter checkbox [`fb8d601`](https://github.com/outliant/sunrise-utils/commit/fb8d6015b1ee2092fc69b64d10b0a26b59958574)
17
+ - chore: update spec [`bcbfd9a`](https://github.com/outliant/sunrise-utils/commit/bcbfd9ad5a21b412c160a85b05d63a43771bc084)
18
+ - chore: add checkbox filter [`dba4385`](https://github.com/outliant/sunrise-utils/commit/dba43855f8d9665325f5ba2dbec17f50abb3bb0b)
19
+
7
20
  #### [1.1.4](https://github.com/outliant/sunrise-utils/compare/1.1.3...1.1.4)
8
21
 
22
+ > 8 May 2023
23
+
9
24
  - chore: support user field type project fields #860qfghzp [`7f4688b`](https://github.com/outliant/sunrise-utils/commit/7f4688b270fe8734153613650c87eef28483068a)
25
+ - chore(release): 1.1.4 [`e3a9285`](https://github.com/outliant/sunrise-utils/commit/e3a9285af6da87760a8c1487542d2473bd3ee2ac)
10
26
 
11
27
  #### [1.1.3](https://github.com/outliant/sunrise-utils/compare/1.1.2...1.1.3)
12
28
 
package/constants.js ADDED
@@ -0,0 +1,18 @@
1
+ module.exports.PROJECT_BANNERS = [
2
+ {
3
+ label: 'Whale',
4
+ value: 'whale',
5
+ },
6
+ {
7
+ label: 'VIP',
8
+ value: 'vip',
9
+ },
10
+ {
11
+ label: 'Legal',
12
+ value: 'legal',
13
+ },
14
+ {
15
+ label: 'Escalation',
16
+ value: 'escalation',
17
+ }
18
+ ];
@@ -5,6 +5,7 @@ const buildIsGeneratedFilter = require('./isGeneratedFilter');
5
5
  const buildTagFilter = require('./tagFilter');
6
6
  const buildProjectFieldFilter = require('./projectFieldFilter');
7
7
  const buildProjectFilter = require('./projectFilter');
8
+ const { PROJECT_BANNERS } = require('../../constants');
8
9
 
9
10
  module.exports.defaultCustomColumns = [
10
11
  {
@@ -72,6 +73,13 @@ module.exports.defaultCustomColumns = [
72
73
  value: 'updated_at',
73
74
  type: 'updated_at',
74
75
  field_type: 'date'
76
+ },
77
+ {
78
+ name: 'Notable',
79
+ value: 'banner',
80
+ type: 'banner',
81
+ field_type: 'checkbox',
82
+ options: PROJECT_BANNERS
75
83
  }
76
84
  ];
77
85
 
@@ -9,7 +9,7 @@ module.exports = (filter) => {
9
9
  }
10
10
  };
11
11
 
12
- module.exports.isEqual = (filter) => {
12
+ module.exports.isEqual = () => {
13
13
  return {
14
14
  match: {
15
15
  on_hold: true
@@ -17,7 +17,7 @@ module.exports.isEqual = (filter) => {
17
17
  };
18
18
  };
19
19
 
20
- module.exports.isNotEqual = (filter) => {
20
+ module.exports.isNotEqual = () => {
21
21
  return {
22
22
  bool: {
23
23
  should: [
@@ -597,7 +597,6 @@ module.exports.lastNDays = (filter) => {
597
597
  }
598
598
  };
599
599
 
600
- console.log(JSON.stringify(res, null, 2));
601
600
  return res;
602
601
  }
603
602
 
@@ -35,13 +35,24 @@ module.exports.isEmpty = (filter) => {
35
35
 
36
36
  return {
37
37
  bool: {
38
- must: [
38
+ should: [
39
39
  {
40
40
  term: {
41
41
  [filter.type]: {
42
42
  value: ''
43
43
  }
44
44
  }
45
+ },
46
+ {
47
+ bool: {
48
+ must_not: [
49
+ {
50
+ exists: {
51
+ field: filter.type
52
+ }
53
+ }
54
+ ]
55
+ }
45
56
  }
46
57
  ]
47
58
  }
@@ -63,6 +74,13 @@ module.exports.isNotEmpty = (filter) => {
63
74
  }
64
75
  }
65
76
  }
77
+ ],
78
+ must: [
79
+ {
80
+ exists: {
81
+ field: filter.type
82
+ }
83
+ }
66
84
  ]
67
85
  }
68
86
  };
@@ -108,21 +126,34 @@ module.exports.isEqual = (filter) => {
108
126
  }
109
127
 
110
128
  if (filter.field_type === 'checkbox') {
111
- const value =
112
- typeof filter.value === 'string' ? value.split(';') : filter.value;
129
+ const value = typeof filter.value === 'string'
130
+ ? filter.value.split(';')
131
+ : filter.value;
132
+
133
+ const should = [];
134
+
135
+ value.forEach((x) => {
136
+ should.push({
137
+ match: {
138
+ [`${filter.type}.analyzed`]: {
139
+ query: x,
140
+ operator: 'and'
141
+ }
142
+ }
143
+ });
144
+
145
+ should.push({
146
+ term: {
147
+ [filter.type]: {
148
+ value: x
149
+ }
150
+ }
151
+ });
152
+ });
113
153
 
114
154
  return {
115
155
  bool: {
116
- should: value.map((x) => {
117
- return {
118
- match: {
119
- [`${filter.type}.analyzed`]: {
120
- query: x,
121
- operator: 'and'
122
- }
123
- }
124
- };
125
- })
156
+ should
126
157
  }
127
158
  };
128
159
  }
@@ -350,6 +381,39 @@ module.exports.isNotEqual = (filter) => {
350
381
  };
351
382
  }
352
383
 
384
+ if (filter.field_type === 'checkbox') {
385
+ const value = typeof filter.value === 'string'
386
+ ? filter.value.split(';')
387
+ : filter.value;
388
+
389
+ const should = [];
390
+
391
+ value.forEach((x) => {
392
+ should.push({
393
+ match: {
394
+ [`${filter.type}.analyzed`]: {
395
+ query: x,
396
+ operator: 'and'
397
+ }
398
+ }
399
+ });
400
+
401
+ should.push({
402
+ term: {
403
+ [filter.type]: {
404
+ value: x
405
+ }
406
+ }
407
+ });
408
+ });
409
+
410
+ return {
411
+ bool: {
412
+ should
413
+ }
414
+ };
415
+ }
416
+
353
417
  return {
354
418
  term: {
355
419
  [filter.type]: {
@@ -7,6 +7,7 @@ const buildCriticalPathFilter = require('./criticalPathFilter');
7
7
  const buildOnHoldFilter = require('./onHoldFilter');
8
8
  const buildAgeColorFilter = require('./buildAgeColorFilter');
9
9
  const buildProjectFieldFilter = require('../projectFilter/projectFieldFilter');
10
+ const { PROJECT_BANNERS } = require('../../constants');
10
11
 
11
12
  module.exports.taskStatusOptions = [
12
13
  {
@@ -177,6 +178,13 @@ module.exports.defaultCustomColumns = [
177
178
  value: 'marked_incomplete_at',
178
179
  type: 'marked_incomplete_at',
179
180
  field_type: 'date'
181
+ },
182
+ {
183
+ name: 'Notable',
184
+ value: 'project_banner',
185
+ type: 'project_banner',
186
+ field_type: 'checkbox',
187
+ options: PROJECT_BANNERS
180
188
  }
181
189
  ];
182
190
 
@@ -227,7 +227,9 @@ module.exports.isEqual = (filter) => {
227
227
  }
228
228
  }
229
229
  };
230
- } else if (filter.field_type === 'textarea') {
230
+ }
231
+
232
+ if (filter.field_type === 'textarea') {
231
233
  return {
232
234
  query_string: {
233
235
  fields: [filter.type],
@@ -236,6 +238,39 @@ module.exports.isEqual = (filter) => {
236
238
  };
237
239
  }
238
240
 
241
+ if (filter.field_type === 'checkbox') {
242
+ const value = typeof filter.value === 'string'
243
+ ? filter.value.split(';')
244
+ : filter.value;
245
+
246
+ const should = [];
247
+
248
+ value.forEach((x) => {
249
+ should.push({
250
+ match: {
251
+ [`${filter.type}.analyzed`]: {
252
+ query: x,
253
+ operator: 'and'
254
+ }
255
+ }
256
+ });
257
+
258
+ should.push({
259
+ term: {
260
+ [filter.type]: {
261
+ value: x
262
+ }
263
+ }
264
+ });
265
+ });
266
+
267
+ return {
268
+ bool: {
269
+ should
270
+ }
271
+ };
272
+ }
273
+
239
274
  return {
240
275
  bool: {
241
276
  must: [
@@ -299,18 +334,11 @@ module.exports.nextNDays = (filter) => {
299
334
  return null;
300
335
  }
301
336
 
302
- const today = moment()
303
- .startOf('day');
304
-
305
- const nextNDays = moment()
306
- .add(filter.value, 'd')
307
- .endOf('day');
308
-
309
337
  return {
310
338
  range: {
311
339
  [filter.type]: {
312
- gt: today.valueOf(),
313
- lt: nextNDays.valueOf()
340
+ lt: `now/d+${filter.value}d`,
341
+ gt: 'now/d'
314
342
  }
315
343
  }
316
344
  };
@@ -321,29 +349,11 @@ module.exports.lastNDays = (filter) => {
321
349
  return null;
322
350
  }
323
351
 
324
- const today = moment()
325
- .startOf('day');
326
-
327
- const lastNDays = moment()
328
- .subtract(filter.value, 'd')
329
- .endOf('day');
330
-
331
- const info = {
332
- today: {
333
- format: today.format('YYYY-MM-DD'),
334
- value: today.valueOf()
335
- },
336
- lastNDays: {
337
- format: lastNDays.format('YYYY-MM-DD'),
338
- value: lastNDays.valueOf()
339
- }
340
- };
341
-
342
352
  return {
343
353
  range: {
344
354
  [filter.type]: {
345
- lt: today.valueOf(),
346
- gt: lastNDays.valueOf()
355
+ gt: `now/d-${filter.value}d`,
356
+ lt: 'now/d'
347
357
  }
348
358
  }
349
359
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@outliant/sunrise-utils",
3
3
  "description": "Helper functions for project Sunrise",
4
- "version": "1.1.4",
4
+ "version": "1.1.6",
5
5
  "license": "ISC",
6
6
  "author": "Outliant",
7
7
  "main": "index.js",
@@ -3,6 +3,8 @@
3
3
  /* eslint-env node, mocha */
4
4
  const { expect } = require('chai');
5
5
 
6
+ const moment = require('moment');
7
+
6
8
  // To test
7
9
  const projectFieldFilter = require('../../../helpers/projectFilter/projectFieldFilter');
8
10
  const projectFilter = require('../../../helpers/projectFilter/projectFilter');
@@ -1016,8 +1018,13 @@ describe('projectFilter/projectFilter', () => {
1016
1018
  {
1017
1019
  range: {
1018
1020
  created_at: {
1019
- gt: 1682524800000,
1020
- lt: 1683043199999
1021
+ gt: moment()
1022
+ .startOf('day')
1023
+ .valueOf(),
1024
+ lt: moment()
1025
+ .add(5, 'd')
1026
+ .endOf('day')
1027
+ .valueOf()
1021
1028
  }
1022
1029
  }
1023
1030
  }
@@ -1040,8 +1047,13 @@ describe('projectFilter/projectFilter', () => {
1040
1047
  {
1041
1048
  range: {
1042
1049
  created_at: {
1043
- lt: 1682524800000,
1044
- gt: 1682351999999
1050
+ lt: moment()
1051
+ .startOf('day')
1052
+ .valueOf(),
1053
+ gt: moment()
1054
+ .subtract(3, 'd')
1055
+ .endOf('day')
1056
+ .valueOf()
1045
1057
  }
1046
1058
  }
1047
1059
  }
@@ -1060,13 +1072,24 @@ describe('projectFilter/projectFilter', () => {
1060
1072
  },
1061
1073
  output: {
1062
1074
  bool: {
1063
- must: [
1075
+ should: [
1064
1076
  {
1065
1077
  term: {
1066
1078
  created_at: {
1067
1079
  value: ""
1068
1080
  }
1069
1081
  }
1082
+ },
1083
+ {
1084
+ bool: {
1085
+ must_not: [
1086
+ {
1087
+ exists: {
1088
+ field: "created_at"
1089
+ }
1090
+ }
1091
+ ]
1092
+ }
1070
1093
  }
1071
1094
  ]
1072
1095
  }
@@ -1091,6 +1114,13 @@ describe('projectFilter/projectFilter', () => {
1091
1114
  }
1092
1115
  }
1093
1116
  }
1117
+ ],
1118
+ must: [
1119
+ {
1120
+ exists: {
1121
+ field: "created_at"
1122
+ }
1123
+ }
1094
1124
  ]
1095
1125
  }
1096
1126
  }
@@ -1101,6 +1131,7 @@ describe('projectFilter/projectFilter', () => {
1101
1131
  it(`${filter.input.condition}: ${JSON.stringify(
1102
1132
  filter.input.value
1103
1133
  )}`, (done) => {
1134
+
1104
1135
  const observed = projectFilter(filter.input);
1105
1136
 
1106
1137
  expect(observed).to.deep.equal(filter.output);
@@ -367,7 +367,7 @@ describe('taskPipeline', function () {
367
367
  script: {
368
368
  lang: 'painless',
369
369
  source:
370
- "\n try {\n String textInfo = '';\n def fields = params._source.fields;\n\n for (int i=0; i<fields.size(); i++) {\n if (fields[i].id.equals(params.value)) {\n\n if (fields[i].number != null) {\n return '';\n }\n \n textInfo = fields[i].text == null ? '' : fields[i].text;\n }\n\n }\n\n return textInfo;\n } catch (Exception err) {\n return '';\n }\n ",
370
+ "\n try {\n String textInfo = '';\n def fields = params._source.fields;\n\n for (int i=0; i<fields.size(); i++) {\n if (fields[i].id.equals(params.value)) {\n\n if (fields[i].number != null) {\n return '';\n }\n\n textInfo = fields[i].text == null ? '' : fields[i].text;\n if (fields[i].containsKey('computedText')) {\n textInfo = fields[i].computedText == null ? textInfo : fields[i].computedText;\n }\n }\n }\n\n return textInfo;\n } catch (Exception err) {\n return '';\n }\n ",
371
371
  params: { value: '38d423bf-fc24-4183-b8b7-15420c89e318' }
372
372
  },
373
373
  order: 'desc'