Skip to content

Commit 9e58a84

Browse files
committed
SDK-A Refactored code to remove all lint errors
1 parent b4f9937 commit 9e58a84

File tree

17 files changed

+765
-713
lines changed

17 files changed

+765
-713
lines changed

.eslintrc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"prettier/prettier": "off",
2828

2929
// Disable rules from shared configs we're not ready for yet.
30-
"sonarjs/cognitive-complexity": ["warn", 20],
30+
"sonarjs/cognitive-complexity": ["error", 20],
3131
"sonarjs/no-duplicate-string": "off",
3232

3333
//

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
"build:dev": "run-p -l lint build-angularsdk",
1818
"build:dev:ci": "npm run clean && npm install && npm run build:dev",
1919
"lint": "run-p -cl lint:*",
20-
"lint:es": "eslint --color --cache --cache-location node_modules/.cache/eslint/ \"projects/angular-test-app/src/**\" \"packages/angular-sdk-components/src/**\"",
20+
"lint:es": "eslint --color --cache --cache-location node_modules/.cache/eslint/ \"projects/angular-test-app/src/**\" \"packages/angular-sdk-components/src/**\" --max-warnings=0",
2121
"lint:format": "prettier --log-level warn -c .",
2222
"fix": "run-s -cl fix:*",
23-
"fix:es": "eslint --color --fix --cache --cache-location node_modules/.cache/eslint/ \"projects/angular-test-app/src/**\" \"packages/angular-sdk-components/src/**\"",
23+
"fix:es": "eslint --color --fix --cache --cache-location node_modules/.cache/eslint/ \"projects/angular-test-app/src/**\" \"packages/angular-sdk-components/src/**\" --max-warnings=0",
2424
"fix:format": "prettier --log-level warn -w .",
2525
"start-dev": "ng serve --port 3500",
2626
"start-dev-https": "ng serve --port 3500 --ssl --ssl-key ./keys/sdk-a.key --ssl-cert ./keys/sdk-a.crt",

packages/angular-sdk-components/src/lib/_components/field/auto-complete/auto-complete.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ interface AutoCompleteProps extends PConnFieldProps {
4242
MatAutocompleteModule,
4343
MatOptionModule,
4444
forwardRef(() => ComponentMapperComponent)
45-
]
45+
],
46+
providers: [DatapageService]
4647
})
4748
export class AutoCompleteComponent implements OnInit, OnDestroy {
4849
@Input() pConn$: typeof PConnect;

packages/angular-sdk-components/src/lib/_components/field/check-box/check-box.component.ts

Lines changed: 68 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -137,93 +137,23 @@ export class CheckBoxComponent implements OnInit, OnDestroy {
137137

138138
// updateSelf
139139
updateSelf(): void {
140-
// moved this from ngOnInit() and call this from there instead...
141140
this.configProps$ = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps()) as CheckboxProps;
142141

143142
this.testId = this.configProps$.testId;
144143
this.displayMode$ = this.configProps$.displayMode;
145144
this.label$ = this.configProps$.label;
146-
if (this.label$ != '') {
147-
this.showLabel$ = true;
148-
}
145+
this.showLabel$ = !!this.label$;
149146

150147
this.actionsApi = this.pConn$.getActionsApi();
151148
this.propName = this.pConn$.getStateProps().value;
152149
this.variant = this.configProps$.variant;
153150

154-
// multi case
155151
this.selectionMode = this.configProps$.selectionMode;
152+
156153
if (this.selectionMode === 'multi') {
157-
this.referenceList = this.configProps$.referenceList;
158-
this.selectionList = this.configProps$.selectionList;
159-
this.selectedvalues = this.configProps$.readonlyContextList;
160-
this.primaryField = this.configProps$.primaryField;
161-
this.bReadonly$ = this.configProps$.renderMode === 'ReadOnly' || this.displayMode$ === 'DISPLAY_ONLY' || this.configProps$.readOnly;
162-
163-
this.datasource = this.configProps$.datasource;
164-
this.selectionKey = this.configProps$.selectionKey;
165-
const listSourceItems = this.datasource?.source ?? [];
166-
const dataField = this.selectionKey?.split?.('.')[1] ?? '';
167-
const listToDisplay: any[] = [];
168-
listSourceItems.forEach(element => {
169-
element.selected = this.selectedvalues?.some?.(data => data[dataField] === element.key);
170-
listToDisplay.push(element);
171-
});
172-
this.listOfCheckboxes = listToDisplay;
154+
this.handleMultiMode();
173155
} else {
174-
if (this.configProps$.value != undefined) {
175-
this.value$ = this.configProps$.value;
176-
}
177-
178-
this.caption$ = this.configProps$.caption;
179-
this.helperText = this.configProps$.helperText;
180-
this.trueLabel$ = this.configProps$.trueLabel || 'Yes';
181-
this.falseLabel$ = this.configProps$.falseLabel || 'No';
182-
183-
// timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
184-
setTimeout(() => {
185-
if (this.configProps$.required != null) {
186-
this.bRequired$ = this.utils.getBooleanValue(this.configProps$.required);
187-
}
188-
this.cdRef.detectChanges();
189-
});
190-
191-
if (this.configProps$.visibility != null) {
192-
this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
193-
}
194-
195-
// disabled
196-
if (this.configProps$.disabled != undefined) {
197-
this.bDisabled$ = this.utils.getBooleanValue(this.configProps$.disabled);
198-
}
199-
200-
if (this.configProps$.readOnly != null) {
201-
this.bReadonly$ = this.utils.getBooleanValue(this.configProps$.readOnly);
202-
}
203-
204-
if (this.bDisabled$ || this.bReadonly$) {
205-
this.fieldControl.disable();
206-
} else {
207-
this.fieldControl.enable();
208-
}
209-
210-
this.componentReference = this.pConn$.getStateProps().value;
211-
212-
// eslint-disable-next-line sonarjs/no-redundant-boolean
213-
if (this.value$ === 'true' || this.value$ == true) {
214-
this.isChecked$ = true;
215-
} else {
216-
this.isChecked$ = false;
217-
}
218-
// trigger display of error message with field control
219-
if (this.angularPConnectData.validateMessage != null && this.angularPConnectData.validateMessage != '') {
220-
const timer = interval(100).subscribe(() => {
221-
this.fieldControl.setErrors({ message: true });
222-
this.fieldControl.markAsTouched();
223-
224-
timer.unsubscribe();
225-
});
226-
}
156+
this.handleSingleMode();
227157
}
228158
}
229159

@@ -278,4 +208,68 @@ export class CheckBoxComponent implements OnInit, OnDestroy {
278208

279209
return errMessage;
280210
}
211+
212+
private handleMultiMode(): void {
213+
this.referenceList = this.configProps$.referenceList;
214+
this.selectionList = this.configProps$.selectionList;
215+
this.selectedvalues = this.configProps$.readonlyContextList;
216+
this.primaryField = this.configProps$.primaryField;
217+
this.bReadonly$ = this.configProps$.renderMode === 'ReadOnly' || this.displayMode$ === 'DISPLAY_ONLY' || this.configProps$.readOnly;
218+
219+
this.datasource = this.configProps$.datasource;
220+
this.selectionKey = this.configProps$.selectionKey;
221+
const listSourceItems = this.datasource?.source ?? [];
222+
const dataField = this.selectionKey?.split?.('.')[1] ?? '';
223+
this.listOfCheckboxes = listSourceItems.map(element => {
224+
element.selected = this.selectedvalues?.some?.(data => data[dataField] === element.key);
225+
return element;
226+
});
227+
}
228+
229+
private handleSingleMode(): void {
230+
if (this.configProps$.value != undefined) {
231+
this.value$ = this.configProps$.value;
232+
}
233+
234+
this.caption$ = this.configProps$.caption;
235+
this.helperText = this.configProps$.helperText;
236+
this.trueLabel$ = this.configProps$.trueLabel || 'Yes';
237+
this.falseLabel$ = this.configProps$.falseLabel || 'No';
238+
239+
setTimeout(() => {
240+
if (this.configProps$.required != null) {
241+
this.bRequired$ = this.utils.getBooleanValue(this.configProps$.required);
242+
}
243+
this.cdRef.detectChanges();
244+
});
245+
246+
if (this.configProps$.visibility != null) {
247+
this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
248+
}
249+
250+
if (this.configProps$.disabled != undefined) {
251+
this.bDisabled$ = this.utils.getBooleanValue(this.configProps$.disabled);
252+
}
253+
254+
if (this.configProps$.readOnly != null) {
255+
this.bReadonly$ = this.utils.getBooleanValue(this.configProps$.readOnly);
256+
}
257+
258+
if (this.bDisabled$ || this.bReadonly$) {
259+
this.fieldControl.disable();
260+
} else {
261+
this.fieldControl.enable();
262+
}
263+
264+
this.componentReference = this.pConn$.getStateProps().value;
265+
this.isChecked$ = this.utils.getBooleanValue(this.value$);
266+
267+
if (this.angularPConnectData.validateMessage) {
268+
const timer = interval(100).subscribe(() => {
269+
this.fieldControl.setErrors({ message: true });
270+
this.fieldControl.markAsTouched();
271+
timer.unsubscribe();
272+
});
273+
}
274+
}
281275
}

packages/angular-sdk-components/src/lib/_components/field/currency/currency.component.ts

Lines changed: 73 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -115,44 +115,24 @@ export class CurrencyComponent implements OnInit, OnDestroy {
115115

116116
// updateSelf
117117
updateSelf(): void {
118-
// starting very simple...
119-
120-
// moved this from ngOnInit() and call this from there instead...
121118
this.configProps$ = this.pConn$.resolveConfigProps(this.pConn$.getConfigProps()) as CurrrencyProps;
122119
this.testId = this.configProps$.testId;
123120
this.label$ = this.configProps$.label;
124121
this.displayMode$ = this.configProps$.displayMode;
125122
this.inputMode = NgxCurrencyInputMode.Natural;
126-
let nValue: any = this.configProps$.value;
127-
if (nValue) {
128-
if (typeof nValue === 'string') {
129-
nValue = parseFloat(nValue);
130-
}
131-
this.value$ = nValue;
132-
} else {
133-
this.value$ = null;
134-
}
123+
124+
this.setValueFromConfig();
135125
this.fieldControl.setValue(this.value$);
126+
136127
this.helperText = this.configProps$.helperText;
137128
this.placeholder = this.configProps$.placeholder || '';
138129
const currencyISOCode = this.configProps$?.currencyISOCode ?? '';
139130

140-
const theSymbols = getCurrencyCharacters(currencyISOCode);
141-
this.currencySymbol = theSymbols.theCurrencySymbol;
142-
this.thousandSeparator = theSymbols.theDigitGroupSeparator;
143-
this.decimalSeparator = theSymbols.theDecimalIndicator;
144-
this.formatter = this.configProps$.formatter;
131+
this.setCurrencySymbols(currencyISOCode);
145132

146-
if (this.displayMode$ === 'DISPLAY_ONLY' || this.displayMode$ === 'STACKED_LARGE_VAL') {
147-
const theCurrencyOptions = getCurrencyOptions(currencyISOCode);
148-
if (this.formatter) {
149-
this.formattedValue = format(this.value$, this.formatter.toLowerCase(), theCurrencyOptions);
150-
} else {
151-
this.formattedValue = format(this.value$, 'currency', theCurrencyOptions);
152-
}
153-
}
133+
this.formatter = this.configProps$.formatter;
134+
this.setFormattedValue(currencyISOCode);
154135

155-
// timeout and detectChanges to avoid ExpressionChangedAfterItHasBeenCheckedError
156136
setTimeout(() => {
157137
if (this.configProps$.required != null) {
158138
this.bRequired$ = this.utils.getBooleanValue(this.configProps$.required);
@@ -164,38 +144,13 @@ export class CurrencyComponent implements OnInit, OnDestroy {
164144
this.bVisible$ = this.utils.getBooleanValue(this.configProps$.visibility);
165145
}
166146

167-
// disabled
168-
if (this.configProps$.disabled != undefined) {
169-
this.bDisabled$ = this.utils.getBooleanValue(this.configProps$.disabled);
170-
}
171-
172-
if (this.bDisabled$) {
173-
this.fieldControl.disable();
174-
} else {
175-
this.fieldControl.enable();
176-
}
177-
178-
if (this.configProps$.readOnly != null) {
179-
this.bReadonly$ = this.utils.getBooleanValue(this.configProps$.readOnly);
180-
}
181-
182-
if (this.configProps$.currencyISOCode != null) {
183-
this.currencyISOCode = this.configProps$.currencyISOCode;
184-
}
185-
147+
this.setDisabledState();
148+
this.setReadonlyState();
149+
this.setCurrencyISOCode();
186150
this.decimalPrecision = this.configProps$?.allowDecimals ? 2 : 0;
187-
188151
this.componentReference = this.pConn$.getStateProps().value;
189152

190-
// trigger display of error message with field control
191-
if (this.angularPConnectData.validateMessage != null && this.angularPConnectData.validateMessage != '') {
192-
const timer = interval(100).subscribe(() => {
193-
this.fieldControl.setErrors({ message: true });
194-
this.fieldControl.markAsTouched();
195-
196-
timer.unsubscribe();
197-
});
198-
}
153+
this.triggerErrorMessage();
199154
}
200155

201156
fieldOnBlur(event: any) {
@@ -236,4 +191,67 @@ export class CurrencyComponent implements OnInit, OnDestroy {
236191

237192
return errMessage;
238193
}
194+
195+
private setValueFromConfig() {
196+
let nValue: any = this.configProps$.value;
197+
if (nValue) {
198+
if (typeof nValue === 'string') {
199+
nValue = parseFloat(nValue);
200+
}
201+
this.value$ = nValue;
202+
} else {
203+
this.value$ = null;
204+
}
205+
}
206+
207+
private setCurrencySymbols(currencyISOCode: string) {
208+
const theSymbols = getCurrencyCharacters(currencyISOCode);
209+
this.currencySymbol = theSymbols.theCurrencySymbol;
210+
this.thousandSeparator = theSymbols.theDigitGroupSeparator;
211+
this.decimalSeparator = theSymbols.theDecimalIndicator;
212+
}
213+
214+
private setFormattedValue(currencyISOCode: string) {
215+
if (this.displayMode$ === 'DISPLAY_ONLY' || this.displayMode$ === 'STACKED_LARGE_VAL') {
216+
const theCurrencyOptions = getCurrencyOptions(currencyISOCode);
217+
if (this.formatter) {
218+
this.formattedValue = format(this.value$, this.formatter.toLowerCase(), theCurrencyOptions);
219+
} else {
220+
this.formattedValue = format(this.value$, 'currency', theCurrencyOptions);
221+
}
222+
}
223+
}
224+
225+
private setDisabledState() {
226+
if (this.configProps$.disabled != undefined) {
227+
this.bDisabled$ = this.utils.getBooleanValue(this.configProps$.disabled);
228+
}
229+
if (this.bDisabled$) {
230+
this.fieldControl.disable();
231+
} else {
232+
this.fieldControl.enable();
233+
}
234+
}
235+
236+
private setReadonlyState() {
237+
if (this.configProps$.readOnly != null) {
238+
this.bReadonly$ = this.utils.getBooleanValue(this.configProps$.readOnly);
239+
}
240+
}
241+
242+
private setCurrencyISOCode() {
243+
if (this.configProps$.currencyISOCode != null) {
244+
this.currencyISOCode = this.configProps$.currencyISOCode;
245+
}
246+
}
247+
248+
private triggerErrorMessage() {
249+
if (this.angularPConnectData.validateMessage != null && this.angularPConnectData.validateMessage != '') {
250+
const timer = interval(100).subscribe(() => {
251+
this.fieldControl.setErrors({ message: true });
252+
this.fieldControl.markAsTouched();
253+
timer.unsubscribe();
254+
});
255+
}
256+
}
239257
}

0 commit comments

Comments
 (0)