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
mgr/dashboard: Adds reusable deletion dialog #20899
Conversation
Could you please rebase this PR. |
315d078
to
6e451d1
Compare
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.
Shouldn't we wait for #21011 ?
export class DeletionModalComponent implements OnInit { | ||
@Input() metaType: string; | ||
@Input() pattern: string; | ||
@Input() btnClasses = 'btn btn-primary'; |
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.
Should be 'btn btn-sm btn-primary' (dashboard buttons are small).
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.
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.
fixed
</ng-container> | ||
|
||
<ng-container class="modal-footer"> | ||
<button type="button" |
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.
Shouldn't we use a "cd-submit-button" here (after #21011 is merged)?
With a "cd-submit-button" you will have auto focus on invalid field.
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.
fixed
</ng-template> | ||
|
||
<ng-template #deletionButtonLabel> | ||
<i class="fa fa-fw fa-trash-o"></i> |
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.
I'm sure we should use an icon on the "first" button, but IMO we don't need this icon on the modal "submit" button because we don't use icons on any other form submission (e.g. Pool creation, RBD creation).
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.
fixed
I do not like that the component does not take care about showing a progress spinner somewhere until the deletion is done. The current implementation forces the developer to do this on its own. |
import { BsModalRef, BsModalService } from 'ngx-bootstrap'; | ||
|
||
@Component({ | ||
selector: 'cd-deletion-modal', |
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.
Maybe consider to rename it to something like cd-deletion-button.
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.
done
} | ||
} | ||
|
||
openModal(template: TemplateRef<any>) { |
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.
I think we should name this method showModal
.
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.
renamed
|
||
constructor(private modalService: BsModalService) {} | ||
|
||
openModal(template: TemplateRef<any>) { |
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.
Consider renaming this method to showModal
.
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.
done
430f5d9
to
3819dbf
Compare
@ricardoasmarques it closes automatically if you provide a delete method that is a observable - If you don't you have to close it manually - You can see how each way can be done in this example. The problem is if the delete function is only triggered though |
@Devp00l The |
|
||
constructor(private modalService: BsModalService) {} | ||
|
||
openModal(template: TemplateRef<any>) { |
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.
This method is not used in this PR, so it can be removed, right?
</cd-modal> | ||
</ng-template> | ||
|
||
<ng-template #deletionButtonLabel> |
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.
This is not being used.
<ng-container *ngTemplateOutlet="deletionHeading"></ng-container> | ||
</ng-template> | ||
|
||
<ng-template #dialogDeleteButton> |
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.
I would suggest we don't create a template
for elements that are only used once.
cdSubmitButton
can be inserted directly in the the modal-footer element.
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's only possible to use the submit button with the right scope in the modal if its a template.
{{ metaType }} | ||
</ng-template> | ||
|
||
<ng-template #deletionDescription> |
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.
Same situation as cdSubmitButton
.
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.
Same here
export class DeletionButtonComponent implements OnInit { | ||
@ViewChild(SubmitButtonComponent) submitButton: SubmitButtonComponent; | ||
@Input() metaType: string; | ||
@Input() pattern: string; |
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.
Does it make sense to set a default value here?
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.
removed it
} | ||
|
||
invalidControl (control: FormControl, error?: string) { | ||
return control.dirty && control.invalid && (error ? control.errors[error] : true); |
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.
We should also check if the form is in the submitted state. something like (formDir.submitted || control.dirty) && ..
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.
Included
3819dbf
to
8ed827d
Compare
a79fc33
to
91f1112
Compare
Changed the button into a link - now you can use it everywhere :) |
<ng-container i18n> | ||
Delete | ||
</ng-container> | ||
{{ metaType }} |
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.
Shouldn't this be translated?
</span> | ||
<span class="help-block" | ||
*ngIf="invalidControl(formDir.submitted, 'pattern')"> | ||
'{{ confirmation.value }}' |
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.
Shouldn't this be translated?
<ng-container i18n> | ||
To confirm the deletion, enter | ||
</ng-container> | ||
<kbd>{{ pattern }}</kbd> |
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.
Shouldn't this be translated?
Per our discussion today, this PR should only include a component that represents the modal, and each developer is responsible for opening and closing that modal. After RBD management PR is merged, you should addapt your code based on mgr/dashboard: Add 'delete-confirmation-modal' component commit - |
f4dcc08
to
cb58f23
Compare
cb58f23
to
992bcff
Compare
Addressed all commits, added a |
} from '@angular/core'; | ||
import { FormControl, FormGroup, Validators } from '@angular/forms'; | ||
|
||
import { BsModalRef, BsModalService } from 'ngx-bootstrap'; |
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.
BsModalService
can be removed because it is not used.
992bcff
to
3f3f803
Compare
@ricardoasmarques Added the error to the @votdev removed the unused import |
@Devp00l can you please apply the following patch to guarantee that we stop the spinner button on RBD dialogs:
|
This component should be used each time you define a new modal. This will allows us to keep all modals with the same visual aspect. Signed-off-by: Tiago Melo <tmelo@suse.com> Signed-off-by: Stephan Müller <smueller@suse.com>
You can now simply use a deletion dialog without having to import a lot of different things from ngx-bootstrap. Its easy to extend the dialog by a detail description. Signed-off-by: Tiago Melo <tmelo@suse.com> Signed-off-by: Stephan Müller <smueller@suse.com>
This change was made because a link can be placed anywhere instead of a button element. Signed-off-by: Stephan Müller <smueller@suse.com>
Due to CSS problems the link solution wasn't the best way, now it will represent only the modal content. The downside of this solution is that it put's the burden on the developer to use it the right way and import a view things to get it working. But on the upside CSS styles will work as expected. The unit test example was updated accordingly this way it should be easy to understand how it can be implemented the right way. Signed-off-by: Stephan Müller <smueller@suse.com>
3f3f803
to
af4ebc6
Compare
@ricardoasmarques implemented your requested changes with unit tests |
@Devp00l this PR has a javascript error because you haven't applied all my patch, you missed this part:
FYI, this is the error, when trying to rollback an RBD snapshot:
|
This replaces usage of "delete-confirmation-modal" with the use of "delete-modal". Signed-off-by: Stephan Müller <smueller@suse.com>
af4ebc6
to
d110eba
Compare
@ricardoasmarques addressed your comment |
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.
Thanks, approved!
You can now simply use a deletion dialog without having to import a lot
of different things from ngx-bootstrap. Its easy to extend the dialog
by a detail description.
Signed-off-by: Stephan Müller smueller@suse.com
This commit is based on two commits from @tspmelo.
To see a working example look here
The updated example on how to use the different deletion methods can be found here