-
Notifications
You must be signed in to change notification settings - Fork 441
DeleteConfirmationDialogComponent Details
This component is implemented to replace all the deletion confirmation dialogs rendered all over the code. We rendered a different partial every time we needed a modal of this type.
From now on, we just have to render DeleteConfirmationDialogComponent
, passing specific parameters, wherever we have a deletion action.
Those dialogs are based on the Bootstrap Modal, as you can see now in app/components/delete_confirmation_dialog_component.html.haml
.
When we only have one element to delete on the page, i.e "Delete project" on the project overview page, we just need to
- render the component passing all the parameters
= render DeleteConfirmationDialogComponent.new(modal_id: 'delete-foo-modal',
method: :delete,
options: { remote: true,
modal_title: 'Do you really want to remove this foo?',
confirmation_text: "Please confirm you want to remove this foo",
action: foo_path(@foo) })
- render the link or button that triggers the deletion action, passing
data-toggle=modal
anddata-target=<modal_id>
. So clicking on this delete link, the correct modal will open.
= link_to('#', title: 'Delete attribute', data: { toggle: 'modal',
target: '#delete-foo-modal' }) do # modal_id that we passed to the component
%i.fas.fa-times-circle.text-danger
When the page contains many elements of the same type that can be deleted, i.e. many files inside a package, we need to open the modal specifying which element is affected and maybe also some specific texts per element.
This is the tricky part. We follow the instructions from Bootstrap Modal - Varying modal content that suggest modifying the content of the modal by JavaScript after rendering the modal.
To do so, we need to
- render the component passing only the parameters that are not going to vary among the elements:
= render DeleteConfirmationDialogComponent.new(modal_id: 'delete-foo-modal',
method: :delete,
options: { remote: true,
modal_title: 'Do you really want to remove this foo?' })
- render the link or button that triggers the deletion action, passing
data-toggle=modal
,data-target=<modal_id>
and all the values that vary among elements.
= link_to('#', title: 'Delete attribute', data: { toggle: 'modal',
target: '#delete-foo-modal', # modal_id that we passed to the component
action: foo_path(@foo), # a different action per element
confirmation_text: "Please confirm the deletion of the foo '#{@foo.name}'" }) do # a different text per element
%i.fas.fa-times-circle.text-danger
When a user clicks on the deletion link, a piece of JavaScript code called from the component retrieves all the data attributes of the element and with them modifies the content of the modal.
- Development Environment Overview
- Development Environment Tips & Tricks
- Spec-Tips
- Code Style
- Rubocop
- Testing with VCR
- Authentication
- Authorization
- Autocomplete
- BS Requests
- Events
- ProjectLog
- Notifications
- Feature Toggles
- Build Results
- Attrib classes
- Flags
- The BackendPackage Cache
- Maintenance classes
- Cloud uploader
- Delayed Jobs
- Staging Workflow
- StatusHistory
- OBS API
- Owner Search
- Search
- Links
- Distributions
- Repository
- Data Migrations
- next_rails
- Ruby Update
- Rails Profiling
- Installing a local LDAP-server
- Remote Pairing Setup Guide
- Factory Dashboard
- osc
- Setup an OBS Development Environment on macOS
- Run OpenQA smoketest locally
- Responsive Guidelines
- Importing database dumps
- Problem Statement & Solution
- Kickoff New Stuff
- New Swagger API doc
- Documentation and Communication
- GitHub Actions
- How to Introduce Software Design Patterns
- Query Objects
- Services
- View Components
- RFC: Core Components
- RFC: Decorator Pattern
- RFC: Backend models