8000 few properties were not getting updated via rules on form initialization by barshat7 · Pull Request #1274 · adobe/aem-core-forms-components · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

few properties were not getting updated via rules on form initialization #1274

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

Merged
merged 5 commits into from
Aug 7, 2024

Conversation

barshat7
Copy link
Contributor
@barshat7 barshat7 commented Jun 18, 2024

Description

Some Properties like 'required' 'description' and 'label' were not getting updated when set via rule 'When Form is Initialized'.
Further, the 'description' was never getting updated as if no description was authored initially then the description div was explicitly ignored in the Sightly. As a fix, included the long description div (which is always hidden by default until question mark icon is clicked), and marked the questionMark div as hidden unless we see that the description is present.

Related Issue

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes and the overall coverage did not decrease.
  • All unit tests pass on CircleCi.
  • I ran all tests locally and they pass.

@barshat7 barshat7 force-pushed the update_properties_via_rule_editor_fix branch from 70676c1 to ced74c9 Compare June 18, 2024 10:36
@adobe-bot
Copy link

Lighthouse scores (mobile)

Performance Accessibility Best-Practices SEO
Scores 89 96 100 75

@adobe-bot
Copy link

Lighthouse scores (desktop)

Performance Accessibility Best-Practices SEO
Scores 100 96 100 75

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@@ -111,6 +111,11 @@ Cypress.on('uncaught:exception', (err, runnable) => {
return false;
}

// this error can come if properties are set via rule editor on form initialization (Since field are yet not initialized completely)
if (err.message.includes('some error occurred while triggering event on guideBridge')) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

The test case should fail, why is this part of whitelist ? Please remove this

const formContainerPath = this.formContainer.getPath();
window.guideBridge.trigger(eventType, eventPayload, formContainerPath);
} catch (e) {
console.log('some error occurred while triggering event on guideBridge', e);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why did you add a try catch here, ideally the code should break. Can you describe the use-case

Copy link
Collaborator
@rismehta rismehta left a comment

Choose a reason for hiding this comment

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

check comments

@barshat7 barshat7 force-pushed the update_properties_via_rule_editor_fix branch 2 times, most recently from f333ae0 to 8e15491 Compare June 25, 2024 11:23
@@ -263,13 +263,13 @@ describe("setFocus on the first invalid field on submission", () => {
});

it("check if invalid field gets focus on submit button click", () => {
cy.get('button').should('be.visible').click().then(() => {
cy.get('button').last().should('be.visible').click().then(() => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Please don't change anything in an existing test case, unless there is backward incompatible change

10000

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously we did not include the questionMark div if long description was not set, but since the setProperty can be called at runtime and even if long description was not set we need to set it in runtime, then we need to have this div. As per this change https://github.com/adobe/aem-core-forms-components/pull/1274/files#:~:text=%3Cbutton%20class%3D%22%24%7BbemBlock%7D__questionmark%22%20style%3D%22%24%7BlongDescription%20%3F%20%27%27%20%3A%20%27display%3Anone%3B%27%7D%20title%3D%22Help%20text%22%3E

Now in the test cases the selectors were wrong as it was assuming that there would only be one button in the form, so I had to update the selectors.
Not sure if this would be backward incompatible though

Copy link
Collaborator

Choose a reason for hiding this comment

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

But this would pollute the HTML with unncessary markup for each field, thus can impact HTML parsing even for use-cases where description is not set at runtime, which is incorrect.

Ideally, at runtime, we should generate the markup if description is set at runtime.

@barshat7 barshat7 force-pushed the update_properties_via_rule_editor_fix branch from 8e15491 to eb407cd Compare June 26, 2024 09:44
this.description.querySelector("p").innerHTML = description;
const questionMarkDiv = this.getQuestionMarkDiv();
if (questionMarkDiv) {
questionMarkDiv.style.display = "block";
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should not be updating styles via code, this might override the theme, and might conflict. What is the use-case to override style

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The requirement is that if long description is not set during authoring then the questionMark div and description div should be present in DOM but hidden. And if by any rule the description is set in runtime, then they should be visible. I guess we could do that by adding 'data-cmp-visible' attribute instead

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, please check this comment on the overall design, #1274 (comment)

@@ -1,4 +1,4 @@
<template data-sly-template.questionMark="${@ componentId, longDescription, bemBlock}">
<button class="${bemBlock}__questionmark" data-sly-test="${longDescription}" title="Help text">
<button class="${bemBlock}__questionmark" style="${longDescription ? '' : 'display:none;'} title="Help text">
Copy link
Collaborator

Choose a reason for hiding this comment

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

styles need to come via theme, code should not add inline style, it would override other styles provided by customer. This looks incorrect to me

<div class="${bemBlock}__longdescription" id="${componentId}__longdescription" style="${wcmmode.edit && longDescription ? '' : 'display:none;'} aria-live="polite">
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do we need inline style

Copy link
Collaborator
@rismehta rismehta left a comment

Choose a reason for hiding this comment

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

check comments

@rismehta
Copy link
Collaborator

Also, do we have a customer who has asked for this change ? Can you link the JIRA in the PR

@barshat7 barshat7 force-pushed the update_properties_via_rule_editor_fix branch 2 times, most recently from 67c2dab to 2146629 Compare July 7, 2024 11:17
Copy link
codecov bot commented Jul 7, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.67%. Comparing base (565fe32) to head (0f54c90).
Report is 1 commits behind head on dev.

Additional details and impacted files
@@            Coverage Diff            @@
##                dev    #1274   +/-   ##
=========================================
  Coverage     81.67%   81.67%           
  Complexity      853      853           
=========================================
  Files            97       97           
  Lines          2259     2259           
  Branches        304      304           
=========================================
  Hits           1845     1845           
  Misses          255      255           
  Partials        159      159           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@adobe-bot
Copy link

Lighthouse scores (mobile)

Performance Accessibility Best-Practices SEO
Scores 89 96 100 75

@adobe-bot
Copy link

Lighthouse scores (desktop)

Performance Accessibility Best-Practices SEO
Scores 100 96 100 75

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

2 similar comments
@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@barshat7 barshat7 force-pushed the update_properties_via_rule_editor_fix branch from 052c13a to c214205 Compare July 7, 2024 11:58
@adobe-bot
Copy link

Lighthouse scores (desktop)

Performance Accessibility Best-Practices SEO
Scores 100 96 100 75

@adobe-bot
Copy link

Lighthouse scores (mobile)

Performance Accessibility Best-Practices SEO
Scores 90 96 100 75

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

2 similar comments
@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@github-actions github-actions bot force-pushed the update_properties_via_rule_editor_fix branch from 26fbb13 to 765666f Compare July 30, 2024 10:11
@adobe-bot
Copy link

Lighthouse scores (desktop)

Performance Accessibility Best-Practices SEO
Scores 100 96 96 75

@adobe-bot
Copy link

Lighthouse scores (mobile)

Performance Accessibility Best-Practices SEO
Scores 89 96 96 75

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

2 similar comments
@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

} else {
this.#addDescriptionInRuntime();
}
this.getDescription().querySelector("p").innerHTML = descriptionText;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You would need to sanitize this HTML, we already do this for enumNames,

window.DOMPurify ?  window.DOMPurify.sanitize(descriptionText) : descriptionText

* @param {string} descriptionText - The description.
*/
updateDescription(descriptionText) {
if (descriptionText !== undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  if (typeof descriptionText !== 'undefined') {
        const descriptionElement = this.getDescription();
        if (descriptionElement) {
            let pElement = descriptionElement.querySelector("p");
            if (!pElement) {
                // If the description is updated via rule then it might not have <p> tags
                pElement = document.createElement('p');
                descriptionElement.appendChild(pElement);
            }
            pElement.textContent = descriptionText;
        } else {
            this.#addDescriptionInRuntime(descriptionText);
        }
    }
    ```

}
}

#addDescriptionInRuntime() {
console.log('adding description in runtime')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove the console log

#addDescriptionInRuntime() {
console.log('adding description in runtime')
// add question mark icon
const bemClass = Array.from(this.element.classList).filter(bemClass => !bemClass.includes('--'))[0];
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets make the code NPE safe

 // add question mark icon
    const bemClass = Array.from(this.element.classList).find(bemClass => !bemClass.includes('--'));
    const labelContainer = this.element.querySelector(`.${bemClass}__label-container`);
    if (labelContainer) {
        const qmButton = document.createElement('button');
        qmButton.className = `${bemClass}__questionmark`;
        qmButton.title = 'Help text';
        labelContainer.appendChild(qmButton);
    } else {
        console.error('Label container not found');
        return;
    }

    // add description div
    const descriptionDiv = document.createElement('div');
    descriptionDiv.className = `${bemClass}__longdescription`;
    descriptionDiv.id = `${this.getId()}__longdescription`;
    descriptionDiv.setAttribute('aria-live', 'polite');
    descriptionDiv.setAttribute('data-cmp-visible', 'false');
    
    const pElement = document.createElement('p');
    if (typeof descriptionText !== 'undefined') {
        pElement.textContent = descriptionText;
    }
    descriptionDiv.appendChild(pElement);

    const errorDiv = this.getErrorDiv();
    if (errorDiv) {
        this.element.insertBefore(descriptionDiv, errorDiv);
    } else {
        console.error('Error div not found');
        return;
    }

Copy link
Collaborator
@rismehta rismehta left a comment

Choose a reason for hiding this comment

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

check comments

@barshat7 barshat7 force-pushed the update_properties_via_rule_editor_fix branch from 765666f to f747f3b Compare August 6, 2024 10:19
few properties were not getting updated via rules on form initialization

few properties were not getting updated via rules on form initialization

few properties were not getting updated via rules on form initialization

update properties fix via rule editor
few properties were not getting updated via rules on form initialization
few properties were not getting updated via rules on form initialization
@github-actions github-actions bot force-pushed the update_properties_via_rule_editor_fix branch from f747f3b to 0f54c90 Compare August 6, 2024 10:20
@adobe-bot
Copy link

Lighthouse scores (desktop)

Performance Accessibility Best-Practices SEO
Scores 100 96 96 75

@adobe-bot
Copy link

Lighthouse scores (mobile)

Performance Accessibility Best-Practices SEO
Scores 90 96 96 75

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

2 similar comments
@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@adobe-bot
Copy link

Accessibility Violations Found

Id Impact
label-title-only serious
target-size serious

@rismehta rismehta merged commit ccaa486 into dev Aug 7, 2024
9 checks passed
@rismehta rismehta deleted the update_properties_via_rule_editor_fix branch August 7, 2024 05:33
dmaurya929 pushed a commit that referenced this pull request Aug 13, 2024
…ion (#1274)

* This is a combination of 2 commits.

few properties were not getting updated via rules on form initialization

few properties were not getting updated via rules on form initialization

few properties were not getting updated via rules on form initialization

update properties fix via rule editor

* few properties were not getting updated via rules on form initialization

few properties were not getting updated via rules on form initialization

* few properties were not getting updated via rules on form initialization

few properties were not getting updated via rules on form initialization

* update af-core version

* few properties were not getting updated via rules on form initialization- refactoring
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this p 3ADA ull request may close these issues.

3 participants
0