Skip to content

fix: add cx-read-more component (for product reviews) #20250

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

Draft
wants to merge 24 commits into
base: develop
Choose a base branch
from

Conversation

uroslates
Copy link
Contributor

@uroslates uroslates requested a review from a team as a code owner April 30, 2025 11:31
@github-actions github-actions bot marked this pull request as draft April 30, 2025 11:31
@uroslates uroslates marked this pull request as ready for review May 5, 2025 09:51
Copy link

cypress bot commented May 5, 2025

spartacus    Run #48392

Run Properties:  status check passed Passed #48392  •  git commit 03d9f411a9 ℹ️: Merge 35e9fcedc55cf31f01f55ee2fbc3b574ac2dc124 into da0e035364973bc97dd2ae3d3a9b...
Project spartacus
Branch Review feature/CXSPA-9967
Run status status check passed Passed #48392
Run duration 04m 59s
Commit git commit 03d9f411a9 ℹ️: Merge 35e9fcedc55cf31f01f55ee2fbc3b574ac2dc124 into da0e035364973bc97dd2ae3d3a9b...
Committer Uros Lates
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 3
Tests that did not run due to a developer annotating a test with .skip  Pending 2
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 237
View all changes introduced in this branch ↗︎

@github-actions github-actions bot marked this pull request as draft May 5, 2025 14:47
@uroslates uroslates marked this pull request as ready for review May 5, 2025 14:59
@github-actions github-actions bot marked this pull request as draft May 5, 2025 16:19
@uroslates uroslates marked this pull request as ready for review May 6, 2025 08:30
@github-actions github-actions bot marked this pull request as draft May 6, 2025 10:49
@uroslates uroslates marked this pull request as ready for review May 8, 2025 08:43
@Input() readLessTranslation?: string = 'common.readLess';
@Input() maxLength = 360;

@Input() text: string = '';
Copy link
Contributor

Choose a reason for hiding this comment

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

To make this component more useful in other cases, should we include a translation key as an option for this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We alread have that - the labels are inputs (accepting translation keys) - here

@Input() readMoreTranslation?: string = 'common.readMore';
@Input() readLessTranslation?: string = 'common.readLess';

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, to be clear I mean @Input() text: I18nKey | string = '';. I suppose the other inputs should also have the I18nKey typing too right?

Copy link
Contributor Author

@uroslates uroslates May 20, 2025

Choose a reason for hiding this comment

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

Ah that. sorry the text is the actual text coming from the DB (so its should not be translatable - thats done in through the BE system).
As for the other 2 inputs NP I'll update it to have the name suffix I18nKey (to be more intuitive). As for they I18nKey type - i haven't found it and wouldn't like to introduce it now since its just a string. And introducing it now (and enforcing consistency) would require tons of changes on other places I guess. We could to that type of improvement globally as some other issue (if really required).

import { I18nModule } from '@spartacus/core';

/**
* Renders cx-read-more.
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a nice approach to the read more case. Simple enough to understand quickly and works well. Could we expand on jsdocs for the class and properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied! 👍

@@ -43,12 +46,16 @@ export class ProductReviewsComponent {
@ViewChild('writeReviewButton', { static: false })
writeReviewButton: ElementRef;

@Input() inputCharactersForReviewTitle = 255;
Copy link
Contributor

Choose a reason for hiding this comment

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

We should keep this behaviour feature toggled as I would consider it a breaking change. If it falls back to null, then I think the maxLength property wouldn't be applied.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the property name could also be changed to something closer to the attribute it affects like maxLengthReviewTitle. Just an example, but I think it could be more clear.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed! 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied! 👍

@@ -127,12 +134,53 @@ export class ProductReviewsComponent {
}
}

get reviewTitleCharacterLeft(): number {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not a huge fan of using getters this way as they retrigger on every component interaction (eg. clicking on the field triggers all, typing a character triggers all, etc). Its a big impact on performance at scale. It would be better if they could trigger only when the needed property changes.

Note: It could be an opportunity to look into the new angular signals.

image image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied 👍. Removed those and moved to template.

@@ -147,6 +166,16 @@ <h3>{{ 'productReview.overallRating' | cxTranslate }}</h3>
*cxFeature="'!formErrorsDescriptiveMessages'"
[control]="reviewForm.get('comment')"
></cx-form-errors>

<p
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please consult with UI designers on the styling details of this component? You can tag them on the onboarding chat with links to the PR (and maybe ticket for context).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we're talking about the characters limiting feature & form errors - I don't think this is necessary since this kind of feature was already implemented on few other places, so the implementation here is fully matching the other usages & styles.
But if needed I could do that. (or if its related to the read-more cmp)

@github-actions github-actions bot marked this pull request as draft May 12, 2025 08:01
@uroslates uroslates marked this pull request as ready for review May 12, 2025 08:33
Copy link
Contributor

Merge Checks Failed

Please push a commit to re-trigger the build.
To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`

@github-actions github-actions bot marked this pull request as draft May 12, 2025 09:08
@uroslates uroslates marked this pull request as ready for review May 12, 2025 09:13
@github-actions github-actions bot marked this pull request as draft May 12, 2025 10:31
@uroslates uroslates marked this pull request as ready for review May 12, 2025 10:32
@github-actions github-actions bot marked this pull request as draft May 12, 2025 10:32
@uroslates uroslates requested a review from Zeyber May 12, 2025 10:33
Copy link
Contributor

Merge Checks Failed

Please push a commit to re-trigger the build.
To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`

@uroslates uroslates marked this pull request as ready for review May 12, 2025 10:34
@github-actions github-actions bot marked this pull request as draft May 12, 2025 10:34
@uroslates uroslates marked this pull request as ready for review May 13, 2025 08:34
Copy link
Contributor

Merge Checks Failed

Please push a commit to re-trigger the build.
To push an empty commit you can use `git commit --allow-empty -m "Trigger Build"`

@github-actions github-actions bot marked this pull request as draft May 19, 2025 12:07
@uroslates uroslates marked this pull request as ready for review May 22, 2025 11:42
@github-actions github-actions bot marked this pull request as draft May 27, 2025 10:58
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 pull request may close these issues.

3 participants