@isettingkit/business-rules 0.1.16 → 0.1.18

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.
Files changed (2) hide show
  1. package/dist/index.es.js +89 -91
  2. package/package.json +3 -3
package/dist/index.es.js CHANGED
@@ -1,22 +1,22 @@
1
- import { jsxs as g, jsx as n, Fragment as F } from "react/jsx-runtime";
1
+ import { jsxs as g, jsx as n, Fragment as j } from "react/jsx-runtime";
2
2
  import { useFormik as Q } from "formik";
3
3
  import { useState as x, useEffect as q } from "react";
4
4
  import { Divider as E } from "@inubekit/divider";
5
5
  import { Stack as o } from "@inubekit/stack";
6
6
  import { Text as y } from "@inubekit/text";
7
7
  import { Toggle as P } from "@inubekit/toggle";
8
- import { ValueHowToSetUp as f, ValueDataType as R, parsePercentageString as Z, DecisionConditionRenderer as U } from "@isettingkit/input";
9
- import { Textarea as J } from "@inubekit/textarea";
10
- import { Date as L } from "@inubekit/date";
11
- import { Checkbox as K } from "@inubekit/checkbox";
12
- import { Button as M } from "@inubekit/button";
13
- import { object as $, string as z, number as O, mixed as H } from "yup";
8
+ import { ValueHowToSetUp as f, ValueDataType as A, DecisionConditionRenderer as M } from "@isettingkit/input";
9
+ import { Textarea as Z } from "@inubekit/textarea";
10
+ import { Date as z } from "@inubekit/date";
11
+ import { Checkbox as J } from "@inubekit/checkbox";
12
+ import { Button as L } from "@inubekit/button";
13
+ import { object as $, string as H, number as F, mixed as I } from "yup";
14
14
  import { DecisionViewConditionRenderer as V } from "@isettingkit/view";
15
- import { MdOutlineRemoveRedEye as W, MdOutlineDelete as X } from "react-icons/md";
16
- import { Icon as I } from "@inubekit/icon";
17
- import { inube as Y } from "@inubekit/foundations";
15
+ import { MdOutlineRemoveRedEye as K, MdOutlineDelete as W } from "react-icons/md";
16
+ import { Icon as N } from "@inubekit/icon";
17
+ import { inube as X } from "@inubekit/foundations";
18
18
  import B from "styled-components";
19
- const ee = (t) => {
19
+ const Y = (t) => {
20
20
  const {
21
21
  label: e,
22
22
  labelText: a,
@@ -28,7 +28,7 @@ const ee = (t) => {
28
28
  return /* @__PURE__ */ g(o, { direction: "column", margin: "10px 4px", children: [
29
29
  /* @__PURE__ */ n(y, { size: "large", appearance: "gray", weight: "bold", margin: "10px 0", children: a }),
30
30
  /* @__PURE__ */ n(o, { margin: "10px 0", children: /* @__PURE__ */ n(
31
- J,
31
+ Z,
32
32
  {
33
33
  id: "reasonChange",
34
34
  label: e,
@@ -43,7 +43,7 @@ const ee = (t) => {
43
43
  }
44
44
  ) })
45
45
  ] });
46
- }, ne = (t) => {
46
+ }, ee = (t) => {
47
47
  const {
48
48
  checked: e,
49
49
  children: a,
@@ -57,7 +57,7 @@ const ee = (t) => {
57
57
  };
58
58
  return q(() => {
59
59
  C(e);
60
- }, [e]), /* @__PURE__ */ g(F, { children: [
60
+ }, [e]), /* @__PURE__ */ g(j, { children: [
61
61
  /* @__PURE__ */ n(o, { children: /* @__PURE__ */ n(
62
62
  P,
63
63
  {
@@ -71,9 +71,9 @@ const ee = (t) => {
71
71
  children: /* @__PURE__ */ n(y, { size: "medium", type: "label", weight: "bold", children: c })
72
72
  }
73
73
  ) }),
74
- b && /* @__PURE__ */ n(F, { children: a })
74
+ b && /* @__PURE__ */ n(j, { children: a })
75
75
  ] });
76
- }, te = (t) => {
76
+ }, ne = (t) => {
77
77
  const {
78
78
  onHandleStartChange: e,
79
79
  onHandleEndChange: a,
@@ -84,7 +84,7 @@ const ee = (t) => {
84
84
  valueStart: d = "",
85
85
  valueEnd: b = ""
86
86
  } = t, [C, p] = x(c), [v, w] = x(d), [S, T] = x(b);
87
- return /* @__PURE__ */ g(F, { children: [
87
+ return /* @__PURE__ */ g(j, { children: [
88
88
  /* @__PURE__ */ g(o, { direction: "row", justifyContent: "space-between", margin: "10px 0", children: [
89
89
  /* @__PURE__ */ n(o, { children: /* @__PURE__ */ n(
90
90
  y,
@@ -105,7 +105,7 @@ const ee = (t) => {
105
105
  wrap: "wrap",
106
106
  gap: "4px",
107
107
  children: /* @__PURE__ */ n(
108
- K,
108
+ J,
109
109
  {
110
110
  label: "Cerrada",
111
111
  onChange: ({ target: s }) => {
@@ -120,7 +120,7 @@ const ee = (t) => {
120
120
  ] }),
121
121
  /* @__PURE__ */ g(o, { justifyContent: "space-between", gap: "24px", children: [
122
122
  /* @__PURE__ */ n(o, { width: "189px", children: /* @__PURE__ */ n(
123
- L,
123
+ z,
124
124
  {
125
125
  id: "dateStart",
126
126
  label: i,
@@ -133,7 +133,7 @@ const ee = (t) => {
133
133
  }
134
134
  ) }),
135
135
  C && /* @__PURE__ */ n(o, { width: "189px", children: /* @__PURE__ */ n(
136
- L,
136
+ z,
137
137
  {
138
138
  id: "dateEnd",
139
139
  label: l,
@@ -147,13 +147,13 @@ const ee = (t) => {
147
147
  ) })
148
148
  ] })
149
149
  ] });
150
- }, N = (t) => {
150
+ }, _ = (t) => {
151
151
  if ("value" in t && "valueUse" in t && t.value !== void 0) {
152
152
  const e = t.value, a = typeof e == "object" && "from" in e && typeof e.from == "number" ? e.from : 0, i = typeof e == "object" && "to" in e && typeof e.to == "number" ? e.to : 1 / 0;
153
153
  switch (t.valueUse) {
154
154
  case f.LIST_OF_VALUES:
155
155
  return {
156
- schema: H().test(
156
+ schema: I().test(
157
157
  "isArrayOrString",
158
158
  "Must be an array of strings/numbers or a single string",
159
159
  (l) => Array.isArray(l) ? l.every(
@@ -164,7 +164,7 @@ const ee = (t) => {
164
164
  };
165
165
  case f.LIST_OF_VALUES_MULTI:
166
166
  return {
167
- schema: H().test(
167
+ schema: I().test(
168
168
  "isArrayOrString",
169
169
  "Must be an array of strings/numbers or a single string",
170
170
  (l) => Array.isArray(l) ? l.every(
@@ -176,8 +176,8 @@ const ee = (t) => {
176
176
  case f.RANGE:
177
177
  return {
178
178
  schema: $({
179
- from: O().required("Range From is required").max(i, "'Range From' cannot be greater than 'Range To'").min(0, "'Range From' cannot be less than 0"),
180
- to: O().required("Range To is required").min(a, "'Range To' cannot be less than 'Range From'").min(0, "'Range To' cannot be less than 0")
179
+ from: F().required("Range From is required").max(i, "'Range From' cannot be greater than 'Range To'").min(0, "'Range From' cannot be less than 0"),
180
+ to: F().required("Range To is required").min(a, "'Range To' cannot be less than 'Range From'").min(0, "'Range To' cannot be less than 0")
181
181
  }),
182
182
  value: {
183
183
  from: a,
@@ -187,31 +187,31 @@ const ee = (t) => {
187
187
  case f.GREATER_THAN:
188
188
  case f.LESS_THAN:
189
189
  case f.EQUAL:
190
- return t.dataType === R.PERCENTAGE ? {
191
- schema: O().required("Percentage is required").min(0, "Percentage cannot be less than 0").max(100, "Percentage cannot be greater than 100"),
190
+ return t.dataType === A.PERCENTAGE ? {
191
+ schema: F().required("Percentage is required").min(0, "Percentage cannot be less than 0").max(100, "Percentage cannot be greater than 100"),
192
192
  value: e
193
193
  } : {
194
- schema: z().required("Required"),
194
+ schema: H().required("Required"),
195
195
  value: e
196
196
  };
197
197
  default:
198
198
  return {
199
- schema: z(),
199
+ schema: H(),
200
200
  value: void 0
201
201
  };
202
202
  }
203
203
  }
204
- }, ae = (t) => {
204
+ }, te = (t) => {
205
205
  const e = {}, a = {};
206
206
  if (t) {
207
- const i = N(t);
207
+ const i = _(t);
208
208
  i && (e[t.name] = i.schema, a[t.name] = i.value);
209
209
  }
210
210
  return t.conditions && t.conditions.forEach((i) => {
211
- const l = N(i);
211
+ const l = _(i);
212
212
  l && (e[i.name] = l.schema, a[i.name] = l.value);
213
213
  }), { validationSchema: $().shape(e), initialValues: a };
214
- }, j = (t) => {
214
+ }, U = (t) => {
215
215
  if (typeof t == "string")
216
216
  return t;
217
217
  if (typeof t == "object" && ("from" in t || "to" in t))
@@ -221,11 +221,11 @@ const ee = (t) => {
221
221
  };
222
222
  for (const e in t)
223
223
  if (Object.prototype.hasOwnProperty.call(t, e)) {
224
- const a = j(t[e]);
224
+ const a = U(t[e]);
225
225
  if (a) return a;
226
226
  }
227
227
  return "";
228
- }, re = (t) => {
228
+ }, ae = (t) => {
229
229
  const {
230
230
  decision: e,
231
231
  formik: a,
@@ -239,29 +239,29 @@ const ee = (t) => {
239
239
  } = t, [p, v] = x(!1), [w, S] = x(!0), T = {
240
240
  name: e.name,
241
241
  dataType: e.dataType,
242
- value: e.dataType === "percentage" ? Z(e.value) : e.value,
242
+ value: e.value,
243
243
  valueUse: e.valueUse,
244
244
  possibleValue: e.possibleValue
245
245
  };
246
246
  q(() => {
247
247
  console.log("Updated formik.errors in RulesFormUI:", a.errors);
248
248
  }, [a.errors]);
249
- const D = (r) => {
249
+ const k = (r) => {
250
250
  v(r.target.checked);
251
- }, k = (r) => {
251
+ }, D = (r) => {
252
252
  r.target.value ? S(!1) : S(!0);
253
253
  }, u = (r) => {
254
- const h = j(a.errors[r] || {});
254
+ const h = U(a.errors[r] || {});
255
255
  return typeof h == "string" ? h ? "invalid" : "pending" : h;
256
256
  }, s = (r) => {
257
- const h = j(a.errors[r] || {});
257
+ const h = U(a.errors[r] || {});
258
258
  return h;
259
259
  };
260
260
  return /* @__PURE__ */ g(o, { direction: "column", gap: "24px", children: [
261
- /* @__PURE__ */ g(o, { direction: "column", gap: "16", children: [
261
+ /* @__PURE__ */ g(o, { direction: "column", gap: "16px", children: [
262
262
  /* @__PURE__ */ n(y, { weight: "bold", size: "medium", children: d.criteria }),
263
263
  e && /* @__PURE__ */ n(
264
- U,
264
+ M,
265
265
  {
266
266
  element: T,
267
267
  onDecision: l,
@@ -285,7 +285,7 @@ const ee = (t) => {
285
285
  P,
286
286
  {
287
287
  id: "toogleNone",
288
- onChange: D,
288
+ onChange: k,
289
289
  checked: p,
290
290
  size: "small",
291
291
  children: /* @__PURE__ */ n(y, { size: "medium", type: "label", weight: "bold", children: d.none })
@@ -293,7 +293,7 @@ const ee = (t) => {
293
293
  )
294
294
  ] }),
295
295
  e.conditions && e.conditions.map((r) => /* @__PURE__ */ n(o, { direction: "column", children: /* @__PURE__ */ n(
296
- ne,
296
+ ee,
297
297
  {
298
298
  checked: !p,
299
299
  handleToggleChange: (h) => {
@@ -311,7 +311,7 @@ const ee = (t) => {
311
311
  labelToggle: r.name.split(/(?=[A-Z])/).join(" "),
312
312
  name: r.name.replace(" ", ""),
313
313
  children: /* @__PURE__ */ n(
314
- U,
314
+ M,
315
315
  {
316
316
  element: r,
317
317
  onDecision: i,
@@ -331,18 +331,18 @@ const ee = (t) => {
331
331
  ] }),
332
332
  /* @__PURE__ */ n(E, { dashed: !0 }),
333
333
  /* @__PURE__ */ n(o, { direction: "column", children: /* @__PURE__ */ n(
334
- ee,
334
+ Y,
335
335
  {
336
336
  label: d.reasonForChange,
337
337
  labelText: d.change,
338
- onHandleChange: k,
338
+ onHandleChange: D,
339
339
  placeholder: d.changePlaceholder,
340
340
  required: !0
341
341
  }
342
342
  ) }),
343
343
  /* @__PURE__ */ n(E, { dashed: !0 }),
344
344
  /* @__PURE__ */ n(o, { direction: "column", children: e && /* @__PURE__ */ n(
345
- te,
345
+ ne,
346
346
  {
347
347
  onHandleStartChange: (r) => c(r.target.value),
348
348
  onHandleEndChange: (r) => m(r.target.value),
@@ -355,9 +355,9 @@ const ee = (t) => {
355
355
  ) }),
356
356
  /* @__PURE__ */ n(E, { dashed: !0 }),
357
357
  /* @__PURE__ */ g(o, { direction: "row", justifyContent: "end", gap: "16px", children: [
358
- /* @__PURE__ */ n(M, { appearance: "gray", onClick: b, children: d.cancel }),
358
+ /* @__PURE__ */ n(L, { appearance: "gray", onClick: b, children: d.cancel }),
359
359
  /* @__PURE__ */ n(
360
- M,
360
+ L,
361
361
  {
362
362
  onClick: C,
363
363
  disabled: w || !a.isValid,
@@ -369,13 +369,13 @@ const ee = (t) => {
369
369
  ] });
370
370
  }, ke = (t) => {
371
371
  const { id: e, decision: a, onCancel: i, onSubmitEvent: l, textValues: c } = t, [m, d] = x(a), b = (u, s) => {
372
- D.setFieldValue(u, s), D.validateField(u);
372
+ k.setFieldValue(u, s), k.validateField(u);
373
373
  }, C = (u, s) => {
374
374
  const r = u instanceof Date ? u.toISOString() : u;
375
375
  d((h) => {
376
376
  if (!h.conditions)
377
377
  return h;
378
- const G = h.conditions.map((A) => A.name === s ? { ...A, value: r } : A);
378
+ const G = h.conditions.map((O) => O.name === s ? { ...O, value: r } : O);
379
379
  return {
380
380
  ...h,
381
381
  conditions: G
@@ -383,19 +383,19 @@ const ee = (t) => {
383
383
  }), b(s, r);
384
384
  }, p = (u) => {
385
385
  d(
386
- (s) => k(s, "value", u)
386
+ (s) => D(s, "value", u)
387
387
  );
388
388
  }, v = (u) => {
389
389
  d(
390
- (s) => k(s, "endDate", u)
390
+ (s) => D(s, "endDate", u)
391
391
  );
392
392
  }, w = (u) => {
393
393
  d(
394
- (s) => k(s, "startDate", u)
394
+ (s) => D(s, "startDate", u)
395
395
  );
396
- }, { validationSchema: S, initialValues: T } = ae(m);
396
+ }, { validationSchema: S, initialValues: T } = te(m);
397
397
  S.validate(T, { abortEarly: !1 }).then(() => console.log("Validation passed")).catch((u) => console.log("Validation failed:", u.errors));
398
- const D = Q({
398
+ const k = Q({
399
399
  initialValues: T,
400
400
  validationSchema: S,
401
401
  validateOnChange: !0,
@@ -403,16 +403,16 @@ const ee = (t) => {
403
403
  onSubmit: () => {
404
404
  l(m);
405
405
  }
406
- }), k = (u, s, r) => ({
406
+ }), D = (u, s, r) => ({
407
407
  ...u,
408
408
  ...u.decision,
409
409
  [s]: r
410
410
  });
411
411
  return /* @__PURE__ */ n(
412
- re,
412
+ ae,
413
413
  {
414
414
  id: e,
415
- formik: D,
415
+ formik: k,
416
416
  decision: m,
417
417
  onCancel: i,
418
418
  onSubmit: () => l(m),
@@ -423,7 +423,7 @@ const ee = (t) => {
423
423
  textValues: c
424
424
  }
425
425
  );
426
- }, _ = (t) => {
426
+ }, R = (t) => {
427
427
  if (!t)
428
428
  return;
429
429
  const e = t.value;
@@ -444,11 +444,11 @@ const ee = (t) => {
444
444
  return e.value;
445
445
  }
446
446
  return e;
447
- }, we = (t) => {
447
+ }, De = (t) => {
448
448
  const { decision: e, textValues: a } = t, i = (c) => c && Object.keys(c).length > 0, l = {
449
449
  name: e.name,
450
450
  dataType: e.dataType,
451
- value: e.value,
451
+ value: R(e),
452
452
  valueUse: e.valueUse
453
453
  };
454
454
  return /* @__PURE__ */ g(o, { direction: "column", gap: "24px", children: [
@@ -458,7 +458,7 @@ const ee = (t) => {
458
458
  V,
459
459
  {
460
460
  element: l,
461
- valueData: _(l)
461
+ valueData: R(l)
462
462
  }
463
463
  ) }, e.name) })
464
464
  ] }),
@@ -473,7 +473,7 @@ const ee = (t) => {
473
473
  ...c,
474
474
  value: m
475
475
  },
476
- valueData: _(c)
476
+ valueData: R(c)
477
477
  }
478
478
  ) }, c.name);
479
479
  })
@@ -488,11 +488,9 @@ const ee = (t) => {
488
488
  name: "Fecha de inicio",
489
489
  value: String(e.startDate),
490
490
  valueUse: f.EQUAL,
491
- dataType: R.DATE
491
+ dataType: A.DATE
492
492
  },
493
- valueData: new Date(e.startDate).toLocaleDateString(
494
- "en-CA"
495
- )
493
+ valueData: String(e.startDate)
496
494
  },
497
495
  "startDate"
498
496
  ),
@@ -503,25 +501,25 @@ const ee = (t) => {
503
501
  name: "Fecha de final",
504
502
  value: String(e.endDate),
505
503
  valueUse: f.EQUAL,
506
- dataType: R.DATE
504
+ dataType: A.DATE
507
505
  },
508
- valueData: new Date(e.endDate).toLocaleDateString("en-CA")
506
+ valueData: String(e.endDate)
509
507
  },
510
508
  "endDate"
511
509
  )
512
510
  ] })
513
511
  ] })
514
512
  ] });
515
- }, oe = B.div`
516
- border-radius: 8px;
517
- border: 1px solid ${Y.palette.neutral.N30};
518
- box-sizing: border-box;
519
- display: flex;
520
- flex-direction: column;
521
- height: 340px;
522
- width: 332px;
523
- box-shadow: 0px 4px 8px 3px rgba(0, 0, 0, 0.1);
524
- `, ie = B.div`
513
+ }, re = B.div`
514
+ & > div {
515
+ border-radius: 8px;
516
+ border: 1px solid ${X.palette.neutral.N30};
517
+ box-sizing: border-box;
518
+ // height: 340px;
519
+ // width: 332px;
520
+ box-shadow: 0px 4px 8px 3px rgba(0, 0, 0, 0.1);
521
+ }
522
+ `, oe = B.div`
525
523
  width: 100%;
526
524
  height: 100%;
527
525
  overflow-y: auto;
@@ -539,32 +537,32 @@ const ee = (t) => {
539
537
  background-color: #ebecf0;
540
538
  border-radius: 8px;
541
539
  }
542
- `, Ee = (t) => {
540
+ `, we = (t) => {
543
541
  const { children: e, handleDelete: a, handleView: i, id: l } = t;
544
- return /* @__PURE__ */ g(oe, { children: [
545
- /* @__PURE__ */ n(o, { height: "282px", gap: "24px", direction: "column", children: /* @__PURE__ */ n(ie, { children: /* @__PURE__ */ n(o, { direction: "column", margin: "10px", children: e }) }) }),
542
+ return /* @__PURE__ */ n(re, { children: /* @__PURE__ */ g(o, { direction: "column", width: "100%", height: "100%", children: [
543
+ /* @__PURE__ */ n(o, { height: "282px", gap: "24px", direction: "column", children: /* @__PURE__ */ n(oe, { children: /* @__PURE__ */ n(o, { direction: "column", margin: "10px", children: e }) }) }),
546
544
  /* @__PURE__ */ g(o, { gap: "16px", direction: "column", margin: "2px 12px", children: [
547
545
  /* @__PURE__ */ n(E, {}),
548
546
  /* @__PURE__ */ g(o, { gap: "16px", justifyContent: "end", children: [
549
547
  /* @__PURE__ */ n(
550
- I,
548
+ N,
551
549
  {
552
550
  appearance: "dark",
553
551
  size: "24px",
554
552
  cursorHover: !0,
555
- icon: /* @__PURE__ */ n(W, {}),
553
+ icon: /* @__PURE__ */ n(K, {}),
556
554
  onClick: () => {
557
555
  i(l);
558
556
  }
559
557
  }
560
558
  ),
561
559
  /* @__PURE__ */ n(
562
- I,
560
+ N,
563
561
  {
564
562
  cursorHover: !0,
565
563
  appearance: "dark",
566
564
  size: "24px",
567
- icon: /* @__PURE__ */ n(X, {}),
565
+ icon: /* @__PURE__ */ n(W, {}),
568
566
  onClick: () => {
569
567
  a(l);
570
568
  }
@@ -572,10 +570,10 @@ const ee = (t) => {
572
570
  )
573
571
  ] })
574
572
  ] })
575
- ] });
573
+ ] }) });
576
574
  };
577
575
  export {
578
- Ee as BusinessRuleCard,
579
- we as BusinessRuleView,
576
+ we as BusinessRuleCard,
577
+ De as BusinessRuleView,
580
578
  ke as RulesForm
581
579
  };
package/package.json CHANGED
@@ -10,7 +10,7 @@
10
10
  ],
11
11
  "description": "",
12
12
  "private": false,
13
- "version": "0.1.16",
13
+ "version": "0.1.18",
14
14
  "type": "module",
15
15
  "exports": {
16
16
  ".": {
@@ -48,8 +48,8 @@
48
48
  "@inubekit/text": "^2.17.0",
49
49
  "@inubekit/textarea": "^2.45.0",
50
50
  "@inubekit/toggle": "^3.8.2",
51
- "@isettingkit/input": "^0.1.24",
52
- "@isettingkit/view": "^0.1.13"
51
+ "@isettingkit/input": "^0.1.26",
52
+ "@isettingkit/view": "^0.1.14"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "formik": "^2.4.6",