-
-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add logic to allow warnings for input fields #3256
base: master
Are you sure you want to change the base?
Changes from 17 commits
f6a29cd
e5cbaaa
3b99c72
b661cd0
0051ff3
51ae79f
e3a6a85
4ded5c1
8febd6f
78899c7
4196e13
b009f20
9262e7d
25817b0
02a4661
3a53132
8f8cda6
46a70b3
04346e2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,7 +1,7 @@ | ||||||||
import { QueryError } from 'mysql2'; | ||||||||
import { ToastrService } from 'ngx-toastr'; | ||||||||
import { Observable } from 'rxjs'; | ||||||||
import { FormControl, FormGroup } from '@angular/forms'; | ||||||||
import { FormControl, FormGroup, Validators } from '@angular/forms'; | ||||||||
|
||||||||
import { Class, StringKeys, TableRow } from '@keira/shared/constants'; | ||||||||
import { MysqlQueryService } from '@keira/shared/db-layer'; | ||||||||
|
@@ -82,10 +82,15 @@ export abstract class EditorService<T extends TableRow> extends SubscriptionHand | |||||||
} | ||||||||
|
||||||||
protected initForm(): void { | ||||||||
const defaultValues = new this._entityClass(); | ||||||||
|
||||||||
// Initialize the FormGroup | ||||||||
Exitare marked this conversation as resolved.
Show resolved
Hide resolved
Exitare marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
this._form = new FormGroup<ModelForm<T>>({} as any); | ||||||||
|
||||||||
// Loop through the fields and initialize controls with default values | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need this comment, IMHO the code seems already quite self-explanatory :)
Suggested change
|
||||||||
for (const field of this.fields) { | ||||||||
this._form.addControl(field, new FormControl()); | ||||||||
const defaultValue = defaultValues[field]; | ||||||||
this._form.addControl(field, new FormControl(defaultValue, [Validators.required])); | ||||||||
Comment on lines
+91
to
+92
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
} | ||||||||
|
||||||||
this.disableEntityIdField(); | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,19 +86,27 @@ export abstract class SingleRowEditorService<T extends TableRow> extends EditorS | |
|
||
protected updateFormAfterReload() { | ||
Exitare marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this._loading = true; | ||
|
||
for (const field of this.fields) { | ||
const control = this._form.controls[field]; | ||
/* istanbul ignore else */ | ||
if (control) { | ||
control.setValue(this._originalValue[field]); | ||
} else { | ||
console.error(`Control '${field}' does not exist!`); | ||
console.log(`----------- DEBUG CONTROL KEYS:`); | ||
for (const k of Object.keys(this._form.controls)) { | ||
console.log(k); | ||
// Ensure `field` is of type `string` | ||
Exitare marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (typeof field === 'string') { | ||
const control = this._form.controls[field]; | ||
Comment on lines
+92
to
+93
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is this change needed for the original purpose of the PR? in general, I'd prefer to split changes in several PRs, for example:
|
||
|
||
if (control) { | ||
const value = this._originalValue[field as keyof T]; // Ensure type safety here | ||
control.setValue(value as T[typeof field]); | ||
} else { | ||
console.error(`Control '${field}' does not exist!`); | ||
console.log(`----------- DEBUG CONTROL KEYS:`); | ||
for (const k of Object.keys(this._form.controls)) { | ||
console.log(k); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure about this code inside the else block, it seems more a debug code , we could keep it, but could you give me more insight about it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Exitare please do not mark comments as resolved without answering or addressing them There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I resolved it, because I removed it initially. But then one of the tests failed and I added it back, but didn't unresolve the issue here. |
||
} else { | ||
console.warn(`Field '${String(field)}' is not a valid string key.`); | ||
} | ||
} | ||
|
||
this._loading = false; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,16 +24,40 @@ | |
<keira-highlightjs-wrapper id="diff-query" [code]="editorService.diffQuery" [hidden]="showFullQuery()" /> | ||
<keira-highlightjs-wrapper id="full-query" [code]="editorService.fullQuery" [hidden]="!showFullQuery()" /> | ||
<div> | ||
<button type="button" class="btn btn-secondary btn-sm" (click)="copy()" id="copy-btn"> | ||
<button | ||
type="button" | ||
class="btn btn-secondary btn-sm" | ||
(click)="copy()" | ||
id="copy-btn" | ||
[disabled]="(validationService.validationPassed$ | async) === false" | ||
> | ||
<i class="fa fa-copy fa-sm"></i> {{ 'COPY' | translate }} | ||
</button> | ||
<button type="button" class="btn btn-primary btn-sm" (click)="execute()" id="execute-btn"> | ||
<button | ||
type="button" | ||
class="btn btn-primary btn-sm" | ||
(click)="execute()" | ||
id="execute-btn" | ||
[disabled]="(validationService.validationPassed$ | async) === false" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should avoid this repetition and wrap There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know how this requested change should look like because I used a variable before and it was requested to use the async pipe. Now it's back to variable again? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before it was a variable with a subscription running on ngOninit, this affects the component adding a dependency for the OnInit interface and moreover, it forces you to manage the subscribe/unsubscribe. Wrapping this into a variable can be done without ngOninit still and in the following way: protected readonly isValidationPassed$ = this.validationService.validationPassed$.pipe(map((val) => val === false)); Keeping in the template [disabled]="isValidationPassed$ | async" Or, you could use signals There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, for learning purposes. What's the undesirable part about having a dependency in the ngOnInit, besides the subscription management part. Is it a general best practice not to use the ngOnInit if possible? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Personally I avoid any kind of dependencies, so if we can avoid ngOnInit, ngOnChanges etc. in an elegant way I would not add them because It increases the complexity of the logic component |
||
> | ||
<i class="fa fa-bolt fa-sm"></i> {{ 'EXECUTE' | translate }} | ||
</button> | ||
<button type="button" class="btn btn-success btn-sm" (click)="copy(); execute()" id="execute-and-copy-btn"> | ||
<button | ||
type="button" | ||
class="btn btn-success btn-sm" | ||
(click)="copy(); execute()" | ||
id="execute-and-copy-btn" | ||
[disabled]="(validationService.validationPassed$ | async) === false" | ||
> | ||
<i class="fa fa-bolt fa-sm"></i> {{ 'EXECUTE_AND_COPY' | translate }} <i class="fa fa-copy fa-sm"></i> | ||
</button> | ||
<button type="button" class="btn btn-danger btn-sm float-end" (click)="reload()" id="reload-btn"> | ||
<button | ||
type="button" | ||
class="btn btn-danger btn-sm float-end" | ||
(click)="reload()" | ||
id="reload-btn" | ||
[disabled]="(validationService.validationPassed$ | async) === false" | ||
> | ||
<i class="fa fa-sync fa-sm"></i> {{ 'RELOAD' | translate }} | ||
</button> | ||
</div> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './electron.service'; | ||
export * from './config.service'; | ||
export * from './location.service'; | ||
export * from './validation.service'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does it have to be a singleton?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because validation should happen on a page by page basis and not on the app level ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should not be necessary, we could keep one instance for the entire application, so provide it in "root" and don't put it here.
If you find a strong reason to provide it inside the component then we could put it back.