orc-shared 5.7.0-dev.14 → 5.7.0-dev.15

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.
@@ -175,14 +175,19 @@ var InputBase = function InputBase(_ref) {
175
175
  });
176
176
  }
177
177
  if (isAdvancedNumericInput) {
178
+ var _numericInputProps$de;
178
179
  if (inputAttributes.max === undefined) {
179
180
  inputAttributes.max = 2147483647;
180
181
  }
181
182
  if (inputAttributes.min === undefined) {
182
183
  inputAttributes.min = -2147483648;
183
184
  }
185
+ var decimalScale = (_numericInputProps$de = numericInputProps == null ? void 0 : numericInputProps.decimalScale) != null ? _numericInputProps$de : 0;
186
+ var lengthForMin = Math.trunc(inputAttributes.min).toString().length;
187
+ var lengthForMax = Math.trunc(inputAttributes.max).toString().length;
188
+ inputAttributes.maxLength = Math.max(lengthForMin, lengthForMax) + (decimalScale > 0 ? decimalScale + 1 : 0);
184
189
  inputAttributes.isAllowed = function (val) {
185
- return val.value === "" || val.value === "-" || val.floatValue >= inputAttributes.min && val.floatValue <= inputAttributes.max;
190
+ return val.value === "" || val.value === "-" || val.value !== null;
186
191
  };
187
192
  }
188
193
  var defaultRows = 4;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "orc-shared",
3
- "version": "5.7.0-dev.14",
3
+ "version": "5.7.0-dev.15",
4
4
  "description": "Shared code for Orckestra applications",
5
5
  "main": "./src/index.js",
6
6
  "exports": {
@@ -146,12 +146,15 @@ const InputBase = ({ inputProps }) => {
146
146
  inputAttributes.min = -2147483648;
147
147
  }
148
148
 
149
+ const decimalScale = numericInputProps?.decimalScale ?? 0;
150
+
151
+ const lengthForMin = Math.trunc(inputAttributes.min).toString().length;
152
+ const lengthForMax = Math.trunc(inputAttributes.max).toString().length;
153
+
154
+ inputAttributes.maxLength = Math.max(lengthForMin, lengthForMax) + (decimalScale > 0 ? decimalScale + 1 : 0);
155
+
149
156
  inputAttributes.isAllowed = val => {
150
- return (
151
- val.value === "" ||
152
- val.value === "-" ||
153
- (val.floatValue >= inputAttributes.min && val.floatValue <= inputAttributes.max)
154
- );
157
+ return val.value === "" || val.value === "-" || val.value !== null;
155
158
  };
156
159
  }
157
160
 
@@ -436,6 +436,166 @@ describe("AdvancedNumericInput", () => {
436
436
  expect(advInput.props().decimalScale, "to be", 2);
437
437
  });
438
438
 
439
+ it("Renders InputBase component as advanced numeric input without min max", () => {
440
+ const inputProps = new InputBaseProps();
441
+ const aLabel = "aLabel";
442
+ const aValue = "value";
443
+
444
+ inputProps.set(InputBaseProps.propNames.update, update);
445
+ inputProps.set(InputBaseProps.propNames.value, aValue);
446
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
447
+ inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
448
+ inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 2 });
449
+
450
+ const component = <InputBase inputProps={inputProps} />;
451
+
452
+ const mountedComponent = mount(component);
453
+
454
+ const advInput = mountedComponent.find("AdvancedNumericInput");
455
+ expect(advInput.props().decimalScale, "to be", 2);
456
+ expect(advInput.props().min, "to be", -2147483648);
457
+ expect(advInput.props().max, "to be", 2147483647);
458
+ expect(advInput.props().maxLength, "to be", 14);
459
+ });
460
+
461
+ it("Renders InputBase component as advanced numeric input without min", () => {
462
+ const inputProps = new InputBaseProps();
463
+ const aLabel = "aLabel";
464
+ const aValue = "value";
465
+
466
+ inputProps.set(InputBaseProps.propNames.update, update);
467
+ inputProps.set(InputBaseProps.propNames.value, aValue);
468
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
469
+ inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
470
+ inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 0 });
471
+ inputProps.set(InputBaseProps.propNames.inputAttributes, { max: 122 });
472
+
473
+ const component = <InputBase inputProps={inputProps} />;
474
+
475
+ const mountedComponent = mount(component);
476
+
477
+ const advInput = mountedComponent.find("AdvancedNumericInput");
478
+ expect(advInput.props().decimalScale, "to be", 0);
479
+ expect(advInput.props().min, "to be", -2147483648);
480
+ expect(advInput.props().max, "to be", 122);
481
+ expect(advInput.props().maxLength, "to be", 11);
482
+ });
483
+
484
+ it("Renders InputBase component as advanced numeric input without max", () => {
485
+ const inputProps = new InputBaseProps();
486
+ const aLabel = "aLabel";
487
+ const aValue = "value";
488
+
489
+ inputProps.set(InputBaseProps.propNames.update, update);
490
+ inputProps.set(InputBaseProps.propNames.value, aValue);
491
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
492
+ inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
493
+ inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 2 });
494
+ inputProps.set(InputBaseProps.propNames.inputAttributes, { min: -9.9 });
495
+
496
+ const component = <InputBase inputProps={inputProps} />;
497
+
498
+ const mountedComponent = mount(component);
499
+
500
+ const advInput = mountedComponent.find("AdvancedNumericInput");
501
+ expect(advInput.props().decimalScale, "to be", 2);
502
+ expect(advInput.props().min, "to be", -9.9);
503
+ expect(advInput.props().max, "to be", 2147483647);
504
+ expect(advInput.props().maxLength, "to be", 13);
505
+ });
506
+
507
+ it("Renders InputBase component as advanced numeric input with negative min positive max", () => {
508
+ const inputProps = new InputBaseProps();
509
+ const aLabel = "aLabel";
510
+ const aValue = "value";
511
+
512
+ inputProps.set(InputBaseProps.propNames.update, update);
513
+ inputProps.set(InputBaseProps.propNames.value, aValue);
514
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
515
+ inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
516
+ inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 1 });
517
+ inputProps.set(InputBaseProps.propNames.inputAttributes, { min: -999.9, max: 9.8 });
518
+
519
+ const component = <InputBase inputProps={inputProps} />;
520
+
521
+ const mountedComponent = mount(component);
522
+
523
+ const advInput = mountedComponent.find("AdvancedNumericInput");
524
+ expect(advInput.props().decimalScale, "to be", 1);
525
+ expect(advInput.props().min, "to be", -999.9);
526
+ expect(advInput.props().max, "to be", 9.8);
527
+ expect(advInput.props().maxLength, "to be", 6);
528
+ });
529
+
530
+ it("Renders InputBase component as advanced numeric input with negative min large positive max", () => {
531
+ const inputProps = new InputBaseProps();
532
+ const aLabel = "aLabel";
533
+ const aValue = "value";
534
+
535
+ inputProps.set(InputBaseProps.propNames.update, update);
536
+ inputProps.set(InputBaseProps.propNames.value, aValue);
537
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
538
+ inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
539
+ inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 1 });
540
+ inputProps.set(InputBaseProps.propNames.inputAttributes, { min: -9.9, max: 99999.8 });
541
+
542
+ const component = <InputBase inputProps={inputProps} />;
543
+
544
+ const mountedComponent = mount(component);
545
+
546
+ const advInput = mountedComponent.find("AdvancedNumericInput");
547
+ expect(advInput.props().decimalScale, "to be", 1);
548
+ expect(advInput.props().min, "to be", -9.9);
549
+ expect(advInput.props().max, "to be", 99999.8);
550
+ expect(advInput.props().maxLength, "to be", 7);
551
+ });
552
+
553
+ it("Renders InputBase component as advanced numeric input with negative min negative max", () => {
554
+ const inputProps = new InputBaseProps();
555
+ const aLabel = "aLabel";
556
+ const aValue = "value";
557
+
558
+ inputProps.set(InputBaseProps.propNames.update, update);
559
+ inputProps.set(InputBaseProps.propNames.value, aValue);
560
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
561
+ inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
562
+ inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 3 });
563
+ inputProps.set(InputBaseProps.propNames.inputAttributes, { min: -99.9, max: -9.8 });
564
+
565
+ const component = <InputBase inputProps={inputProps} />;
566
+
567
+ const mountedComponent = mount(component);
568
+
569
+ const advInput = mountedComponent.find("AdvancedNumericInput");
570
+ expect(advInput.props().decimalScale, "to be", 3);
571
+ expect(advInput.props().min, "to be", -99.9);
572
+ expect(advInput.props().max, "to be", -9.8);
573
+ expect(advInput.props().maxLength, "to be", 7);
574
+ });
575
+
576
+ it("Renders InputBase component as advanced numeric input with positive min positive max", () => {
577
+ const inputProps = new InputBaseProps();
578
+ const aLabel = "aLabel";
579
+ const aValue = "value";
580
+
581
+ inputProps.set(InputBaseProps.propNames.update, update);
582
+ inputProps.set(InputBaseProps.propNames.value, aValue);
583
+ inputProps.set(InputBaseProps.propNames.label, aLabel);
584
+ inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
585
+ inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 5 });
586
+ inputProps.set(InputBaseProps.propNames.inputAttributes, { min: 9.9, max: 99.8 });
587
+
588
+ const component = <InputBase inputProps={inputProps} />;
589
+
590
+ const mountedComponent = mount(component);
591
+
592
+ const advInput = mountedComponent.find("AdvancedNumericInput");
593
+ expect(advInput.props().decimalScale, "to be", 5);
594
+ expect(advInput.props().min, "to be", 9.9);
595
+ expect(advInput.props().max, "to be", 99.8);
596
+ expect(advInput.props().maxLength, "to be", 8);
597
+ });
598
+
439
599
  it("Change advanced numeric input value", () => {
440
600
  const inputProps = new InputBaseProps();
441
601
  const aLabel = "aLabel";
@@ -686,116 +846,6 @@ describe("AdvancedNumericInput", () => {
686
846
  // no idea what to assert here, this test is mostly for code coverage
687
847
  });
688
848
 
689
- it("Change advanced numeric input value with min value out of default bounds", () => {
690
- const inputProps = new InputBaseProps();
691
- const aLabel = "aLabel";
692
- const aValue = "12.2";
693
- const metadata = {
694
- test: "value",
695
- };
696
-
697
- inputProps.set(InputBaseProps.propNames.update, update);
698
- inputProps.set(InputBaseProps.propNames.value, aValue);
699
- inputProps.set(InputBaseProps.propNames.label, aLabel);
700
- inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
701
- inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 2 });
702
- inputProps.set(InputBaseProps.propNames.metadata, metadata);
703
-
704
- const component = <InputBase inputProps={inputProps} />;
705
- const mountedComponent = mount(component);
706
- const input = mountedComponent.find("input");
707
- input.simulate("change", { target: { value: "-3147483648", focus: noop } });
708
-
709
- expect(update, "not to have calls satisfying", [{ args: ["-3147483648", metadata] }]);
710
-
711
- input.simulate("change", { target: { value: "-111", focus: noop } });
712
- expect(update, "to have calls satisfying", [{ args: ["-111", metadata] }]);
713
- });
714
-
715
- it("Change advanced numeric input value with min value out of specified bounds", () => {
716
- const inputProps = new InputBaseProps();
717
- const aLabel = "aLabel";
718
- const aValue = "12.2";
719
- const metadata = {
720
- test: "value",
721
- };
722
-
723
- inputProps.set(InputBaseProps.propNames.update, update);
724
- inputProps.set(InputBaseProps.propNames.value, aValue);
725
- inputProps.set(InputBaseProps.propNames.label, aLabel);
726
- inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
727
- inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 2 });
728
- inputProps.set(InputBaseProps.propNames.metadata, metadata);
729
- inputProps.set(InputBaseProps.propNames.inputAttributes, {
730
- min: -100,
731
- });
732
-
733
- const component = <InputBase inputProps={inputProps} />;
734
- const mountedComponent = mount(component);
735
- const input = mountedComponent.find("input");
736
- input.simulate("change", { target: { value: "-2000", focus: noop } });
737
-
738
- expect(update, "not to have calls satisfying", [{ args: ["-2000", metadata] }]);
739
-
740
- input.simulate("change", { target: { value: "-11", focus: noop } });
741
- expect(update, "to have calls satisfying", [{ args: ["-11", metadata] }]);
742
- });
743
-
744
- it("Change advanced numeric input value with max value out of default bounds", () => {
745
- const inputProps = new InputBaseProps();
746
- const aLabel = "aLabel";
747
- const aValue = "12.2";
748
- const metadata = {
749
- test: "value",
750
- };
751
-
752
- inputProps.set(InputBaseProps.propNames.update, update);
753
- inputProps.set(InputBaseProps.propNames.value, aValue);
754
- inputProps.set(InputBaseProps.propNames.label, aLabel);
755
- inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
756
- inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 2 });
757
- inputProps.set(InputBaseProps.propNames.metadata, metadata);
758
-
759
- const component = <InputBase inputProps={inputProps} />;
760
- const mountedComponent = mount(component);
761
- const input = mountedComponent.find("input");
762
- input.simulate("change", { target: { value: "3147483648", focus: noop } });
763
-
764
- expect(update, "not to have calls satisfying", [{ args: ["3147483648", metadata] }]);
765
-
766
- input.simulate("change", { target: { value: "111", focus: noop } });
767
- expect(update, "to have calls satisfying", [{ args: ["111", metadata] }]);
768
- });
769
-
770
- it("Change advanced numeric input value with max value out of specified bounds", () => {
771
- const inputProps = new InputBaseProps();
772
- const aLabel = "aLabel";
773
- const aValue = "12.2";
774
- const metadata = {
775
- test: "value",
776
- };
777
-
778
- inputProps.set(InputBaseProps.propNames.update, update);
779
- inputProps.set(InputBaseProps.propNames.value, aValue);
780
- inputProps.set(InputBaseProps.propNames.label, aLabel);
781
- inputProps.set(InputBaseProps.propNames.type, "AdvancedNumericInput");
782
- inputProps.set(InputBaseProps.propNames.numericInputProps, { decimalScale: 2 });
783
- inputProps.set(InputBaseProps.propNames.metadata, metadata);
784
- inputProps.set(InputBaseProps.propNames.inputAttributes, {
785
- max: 100,
786
- });
787
-
788
- const component = <InputBase inputProps={inputProps} />;
789
- const mountedComponent = mount(component);
790
- const input = mountedComponent.find("input");
791
- input.simulate("change", { target: { value: "2000", focus: noop } });
792
-
793
- expect(update, "not to have calls satisfying", [{ args: ["2000", metadata] }]);
794
-
795
- input.simulate("change", { target: { value: "11", focus: noop } });
796
- expect(update, "to have calls satisfying", [{ args: ["11", metadata] }]);
797
- });
798
-
799
849
  it("Change advanced numeric input value: dash is allowed", () => {
800
850
  const inputProps = new InputBaseProps();
801
851
  const aLabel = "aLabel";