Skip to content

Commit 7827f54

Browse files
kaur-mananjeetGT, ShreyaRajeshwari Kiwad
authored
Fix: Script Gen Textbox Input Don’t Accept Numbers Without Units (#48)
* TSP-947 Script generation infrastructure first cut * TSP-947 Fix multiple channel issue in script * TSP-948 Fix linting issues * TSP-Script-Gen-UI- Linting done (both angular and rust) * TSP-Script-Gen-UI step and sweep points update fixed to show on plot * TSP-Script-Gen All linitng done with standalones * TSP-960-Scrolling input containers to view done * TSP-Scrip-Gen-UI- Scroll into view feature done * Script-Gen-UI- UI changes done (through reviews from UX team) * Revert "Merge branch 'main' into task/TSP-960-style-layout" This reverts commit 12b90fcd4c35917273d40a01e1c5f21dfc5ac79e, reversing changes made to beb512d73be7731c565fec696796c0cd47e5878a. * Reapply "Merge branch 'main' into task/TSP-960-style-layout" This reverts commit 712497e134fc83278e4ec837ff50212ac1f77484. * TSP-960-Scroll-Into-View done with UI changes * TSP-944-resizing and layout of the input containers done * Script-Gen-UI- Fixed the error and bias plot background color * Script-Gen-UI- Sweep color fix * Script-Gen-UI- fixed arrows and step add and remove button * TSP-944- Input panes reflow when shrunk done * Added styles to timing popup * Removed files as per review comment * tsp-1123-Fix start and stop CSS in Step and Sweep Section * Fix start and stop border in step and sweep * tsp-1123-Fix leaking CSS in start and stop * Task/tsp-1201-Correct the spelling of the "Aperture" textbox in the Timing tab * task/tsp-1199-fix-automation name & IDs are missing for the combo box and textboxes in the Timing Tab * fix automation IDs for measure delay and rate * remove duplicate automationID from input-numeric * TSP-1202-add automation Names and automationIDs for Bias * Fix automation names for NPLC and Aperture in Timing * fix issue with automation names in timing and bias (script-gen) * fix: bias plot range for source range AUTO * fix: tsp-1230 and tsp-1231 -The automation name & IDs are missing for the combo box and textboxes in the Step -The automation name & IDs are missing for the combo box and textboxes in the Sweep * fix: Script Gen- Sweep Graph Preview Cuts Off End of Graph * refactor: move repeated code into function generatePlotData() * fix: restrict timing tab drag to webview panel * fix: Script Gen Textbox Input Don’t Accept Numbers Without Units --------- Co-authored-by: GT, Shreya <[email protected]> Co-authored-by: Rajeshwari Kiwad <[email protected]>
1 parent 077c21b commit 7827f54

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

script-gen-ui/src/app/components/controls/input-parser.util.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export const REVERSE_PREFIXES: Record<string, number> = {
2323
'T': 12,
2424
};
2525

26-
export function parseScientificInput(input: string): string {
27-
const regex = /^(-?[\d.]+)(e([+-]?\d+))?\s*([a-zA-Zµ]*)?\s*([a-zA-Z]+)$/;
26+
export function parseScientificInput(input: string, unit: string | undefined): string {
27+
const regex = /^(-?[\d.]+)(e([+-]?\d+))?\s*([a-zA-Zµ]?)\s*([a-zA-Z]+)?$/;
2828
const match = input.match(regex);
2929

3030
if (!match) {
@@ -38,7 +38,7 @@ export function parseScientificInput(input: string): string {
3838
let numericValue = parseFloat(value) * Math.pow(10, parseInt(exponent || '0'));
3939

4040
if (numericValue === 0) {
41-
return `0 ${baseUnit}`;
41+
return `0 ${baseUnit || unit}`;
4242
}
4343

4444
const existingExponent = REVERSE_PREFIXES[normalizedPrefix || ''] || 0;
@@ -49,18 +49,21 @@ export function parseScientificInput(input: string): string {
4949
const roundedValue = parseFloat(scaledValue.toFixed(3));
5050
const newPrefix = finalExponent === 0 ? '' : SCIENTIFIC_PREFIXES[finalExponent] || `e${finalExponent}`;
5151

52-
return `${roundedValue} ${newPrefix}${baseUnit || ''}`;
52+
return `${roundedValue} ${newPrefix}${baseUnit || unit || ''}`;
5353
}
5454

55-
export function parseToDecimal(input: string): number | null {
56-
const regex = /^(-?[\d.]+)(e([+-]?\d+))?\s*([a-zA-Zµ]*)?\s*([a-zA-Z]+)$/;
55+
export function parseToDecimal(input: string, unit?: string | undefined): number | null {
56+
const regex = /^(-?[\d.]+)(e([+-]?\d+))?\s*([a-zA-Zµ]?)\s*([a-zA-Z]+)?$/;
5757
const match = input.match(regex);
5858

5959
if (!match) {
6060
return null; // Invalid input
6161
}
6262

63-
const [, value, , exponent, prefix] = match;
63+
const [, value, , exponent, prefix, baseUnit] = match;
64+
if (baseUnit && baseUnit !== unit) {
65+
return null; // Incompatible units
66+
}
6467
let normalizedPrefix = prefix;
6568
if (normalizedPrefix === 'µ') normalizedPrefix = 'u';
6669

script-gen-ui/src/app/components/controls/input-plain/input-plain.component.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export class InputPlainComponent implements ControlValueAccessor, OnInit {
5050
// TODO: have to make the rounding off based on the resolution defined for each range
5151

5252
get displayValue(): string {
53-
const parsedValue = parseScientificInput(`${this._value} ${this.unit}`);
53+
const parsedValue = parseScientificInput(`${this._value} ${this.unit}`, this.unit);
5454
// If parseScientificInput returns a valid value, update _displayValue
5555
if (parsedValue && parsedValue !== 'Invalid input') {
5656
this._displayValue = parsedValue;
@@ -63,7 +63,7 @@ export class InputPlainComponent implements ControlValueAccessor, OnInit {
6363
}
6464

6565
set displayValue(val: string) {
66-
const decimalValue = parseToDecimal(val);
66+
const decimalValue = parseToDecimal(val,this.unit);
6767
if (decimalValue !== null) {
6868
this._value = decimalValue;
6969

@@ -96,12 +96,11 @@ export class InputPlainComponent implements ControlValueAccessor, OnInit {
9696

9797
onInputChange(event: Event): void {
9898
const inputElement = event.target as HTMLInputElement;
99-
10099
if (this.displayValue !== inputElement.value) {
101100
const previousValue = this.displayValue;
102101
this.displayValue = inputElement.value;
103102

104-
if (parseToDecimal(inputElement.value) === null) {
103+
if (parseToDecimal(inputElement.value, this.unit) === null) {
105104
inputElement.value = previousValue; // If the input is invalid, revert to the previous value
106105
} else {
107106
inputElement.value = this.displayValue; // Update the input element with the parsed value

0 commit comments

Comments
 (0)