Skip to content

feat(forms): prevent form elements deletion when they are used by conditions #19219

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

ccailly
Copy link
Member

@ccailly ccailly commented Mar 18, 2025

Checklist before requesting a review

Please delete options that are not relevant.

  • I have read the CONTRIBUTING document.
  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.

Description

#19204 must be merged before

Prevent the deletion of a question, section or comment if it is used as a condition.
Add a modal to display which elements have conditions that use the element you wish to delete.

Screenshots (if appropriate):

image

@ccailly ccailly self-assigned this Mar 18, 2025
@ccailly ccailly added the Forms label Mar 18, 2025
@ccailly ccailly added this to the 11.0.0 milestone Mar 18, 2025
@ccailly ccailly force-pushed the feature/form-prevent-deleting-block-conditions branch from c24e35b to 4e576b8 Compare April 16, 2025 11:36
@ccailly ccailly marked this pull request as ready for review April 17, 2025 11:41
Copy link
Contributor

@AdrienClairembault AdrienClairembault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, can you also take into account the form destinations conditions ?

Note that form destination data doesn't exist in the form editor so you will probably need to include it in some hidden inputs.

# http://glpi-project.org
#
# @copyright 2015-2025 Teclib' and contributors.
# @copyright 2003-2014 by the INDEPNET Development Team.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# @copyright 2003-2014 by the INDEPNET Development Team.

* @param {jQuery} block The block element to check
* @returns {boolean} True if the block can be deleted, false otherwise
*/
#checkBlockConditionDependencies(type, block) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small distinction here but aren't block only questions and comments ?
If this is also used on sections, which are block, the name should be more generic (checkItemConditionDependencies ?)

@@ -1460,4 +1460,188 @@ describe ('Conditions', () => {
'First section',
]);
});

it('can delete a question used in conditions', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('can delete a question used in conditions', () => {
it("can't delete a question used in conditions", () => {

cy.findByRole('dialog', {'name': 'Block has conditions and cannot be deleted'}).should('not.exist');
});

it('can delete a comment used in conditions', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('can delete a comment used in conditions', () => {
it("can't delete a comment used in conditions", () => {

cy.findByRole('dialog', {'name': 'Block has conditions and cannot be deleted'}).should('not.exist');
});

it('can delete a section used in conditions', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it('can delete a section used in conditions', () => {
it("can't delete a section used in conditions", () => {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants