Skip to content

Conversation

@godzzo
Copy link
Contributor

@godzzo godzzo commented Feb 13, 2022

...like RepeatableComponent

This commit fixes #12499

What does it do?

Show the MainValue of the Components of a DynamicZone in the AccordionToggle.

Why is it needed?

To be able to distingish the Dzone components without unfold them.

How to test it?

  • Create a Component
  • Create a Collection
    • add DynamicZone
      • add the Component
  • Edit the Collection
    • edit DZone
      • add more Component instance
      • edit the mainField
      • check the AccordionToggle changes

Sample:
strapi_dzone_main_value

Related issue(s)/PR(s)

Related issue: #12499

@gu-stav gu-stav added the source: core:content-manager Source is core/content-manager package label Feb 14, 2022
@gu-stav
Copy link
Contributor

gu-stav commented Feb 22, 2022

@godzzo Thanks for your contribution again :) We had a quick look into the PR today and think it's a nice addition. I'll check & review your code in the coming days.

@gu-stav gu-stav self-assigned this Feb 22, 2022
Copy link
Contributor

@gu-stav gu-stav left a comment

Choose a reason for hiding this comment

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

As I already said: thank you for the contribution. I've added a couple of comments, but overall this is an addition we'd like to welcome.

import { get, toString } from 'lodash';
import { useCMEditViewDataManager } from '@strapi/helper-plugin';

function useMainValue(schema, componentFieldName) {
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 add a test for this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not familiar the testing in this project. Could you give me some docs and an example?

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 best would be to copy this file into a utils folder (e.g. ./utils/useMainValue.js. Then you can add a test folder within utils and write a basic unit-test similar to this one, which tests input / output.

Copy link
Contributor Author

@godzzo godzzo Mar 3, 2022

Choose a reason for hiding this comment

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

I have decoupled the displayedValue logic and pushed a unit test file for it.

In Win10 the jest could not find any test file, I tested on WSL2-Ubuntu.

testMatch: /**/tests/**/?(*.)+(spec|test).[jt]s?(x) - 0 matches

@codecov
Copy link

codecov bot commented Mar 1, 2022

Codecov Report

Base: 59.33% // Head: 59.33% // Decreases project coverage by -0.00% ⚠️

Coverage data is based on head (ab1d9e6) compared to base (a13b60d).
Patch coverage: 58.82% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #12500      +/-   ##
==========================================
- Coverage   59.33%   59.33%   -0.01%     
==========================================
  Files        1338     1342       +4     
  Lines       32724    32757      +33     
  Branches     6197     6199       +2     
==========================================
+ Hits        19417    19436      +19     
- Misses      11438    11450      +12     
- Partials     1869     1871       +2     
Flag Coverage Δ
front 63.63% <58.82%> (-0.01%) ⬇️
unit 49.80% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...s/DynamicZone/components/Component/utils/select.js 36.36% <36.36%> (ø)
...micZone/components/Component/hooks/useMainValue.js 58.33% <58.33%> (ø)
.../DynamicZone/components/Component/utils/connect.js 66.66% <66.66%> (ø)
...mponents/DynamicZone/components/Component/index.js 47.54% <100.00%> (+1.77%) ⬆️
...ts/DynamicZone/components/Component/utils/index.js 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@alexandrebodin alexandrebodin added the pr: fix This PR is fixing a bug label Mar 9, 2022
@alexandrebodin alexandrebodin requested a review from gu-stav March 9, 2022 16:14
@gu-stav gu-stav added pr: enhancement This PR adds or updates some part of the codebase or features and removed pr: fix This PR is fixing a bug labels Mar 10, 2022
Copy link
Contributor

@gu-stav gu-stav left a comment

Choose a reason for hiding this comment

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

Thanks again @godzzo. I've added two small comments. It would still be nice to have tests for useMainValue(). You can find a way to test hooks here: https://github.com/strapi/strapi/pull/12893/files#diff-9530f953e7c9e1ef6b200896b0fbcb9ee54c81ff875bbae6dc61b080e2c10d7f , but since the tests seem to create problems on your machine, you can let me know if you want me to push a test for it?


return layout;
}, [componentUid, getComponentLayout]);
const mainValue = useMainValue(componentLayoutData, [name, index]);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend to pass the mainValue as a prop from the DynamicZone/utils/select.js hook to avoid extreme rerendering of the components, it can cause performance issues at some point.

Copy link
Contributor Author

@godzzo godzzo Mar 30, 2022

Choose a reason for hiding this comment

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

I have created a new wrapper with utils/connect for DynamicZone/Component.

Please check this out. It is okay for using this separately for each Component?
(it feel cleaner for me and the RepeatableComponent/DraggedItem using the same way, if I see it correctly).

Or should I move the mainValue parsing here DynamicZone/utils/select.js:

  const dynamicDisplayedComponents = useMemo(
    () => get(modifiedData, [name], []).map(data => data.__component),
    [modifiedData, name]
  );

@gu-stav gu-stav self-requested a review April 4, 2022 07:36
@strapi-bot
Copy link

This pull request has been mentioned on Strapi Community Forum. There might be relevant details there:

https://forum.strapi.io/t/component-entry-titel-display-in-dynamic-zone/15478/3

@sjaga003
Copy link

Any chance this will get reviewed and merged? Would love to be able to use this feature

@gu-stav
Copy link
Contributor

gu-stav commented May 24, 2022

@sjaga003 I'll do another review as soon as possible - I think I'll manage it by next week.

@Zharkan
Copy link
Contributor

Zharkan commented Jun 7, 2022

@sjaga003 I'll do another review as soon as possible - I think I'll manage it by next week.

Nice, we need this.

@Sija

This comment was marked as spam.

@tpapamichail

This comment was marked as spam.

@mohdtaha60

This comment was marked as spam.

@Torsten85

This comment was marked as spam.

@Zharkan

This comment was marked as spam.

@sjaga003

This comment was marked as spam.

@derrickmehaffy
Copy link
Member

Hey all, let me request and update from the team

@gu-stav
Copy link
Contributor

gu-stav commented Aug 8, 2022

@derrickmehaffy I'm on it. The required design-System work is done, but I have to find some time to review this PR again.

@derrickmehaffy
Copy link
Member

@derrickmehaffy I'm on it. The required design-System work is done, but I have to find some time to review this PR again.

No problem thank you!

@gu-stav gu-stav force-pushed the godzzo/issue12499 branch from 62c179f to 5e8d63b Compare August 23, 2022 08:02
@gu-stav
Copy link
Contributor

gu-stav commented Aug 23, 2022

Hello 👋🏼 I've checked the PR again today, because now all required changes to the Accordion component are done, so that long titles don't overflow any longer.

I've found a couple of bugs:

  • only fields of type "text" as main-field are extracted properly; all the others lead to 1
  • all fields of type !== 'text' update on save, whereas type == 'text' updates on keydown
  • if no value was extracted, the seperator - is still rendered

Screenshot 2022-08-23 at 10 19 11

Would you still be available to fix those?

@godzzo
Copy link
Contributor Author

godzzo commented Nov 4, 2022

Hello @gu-stav !

Yes! I have tried to fix the 3 bugs you mentioned.

Please review it.

  • only fields of type "text" as main-field are extracted properly; all the others lead to 1
    • if it is not a title field (you could not choose as title of the DZone) then it will be the id field
    • that is why 1 is the value (of id) if you save that...
  • all fields of type !== 'text' update on save, whereas type == 'text' updates on keydown
    • id only got value if you save, otherwise will be update on keydown if I saw it correctly
    • I omit the id as MainField value, that is the fix about
  • if no value was extracted, the seperator - is still rendered
    • fixed

Copy link
Contributor

@gu-stav gu-stav left a comment

Choose a reason for hiding this comment

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

It works well on my side now. 🚀 Thanks for staying on it and fixing all the problems!

@gu-stav gu-stav merged commit e68bca1 into strapi:main Nov 11, 2022
@gu-stav gu-stav added this to the 4.5.1 milestone Nov 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: enhancement This PR adds or updates some part of the codebase or features source: core:content-manager Source is core/content-manager package

Projects

No open projects
Archived in project

Development

Successfully merging this pull request may close these issues.

DynamicZone - extend FriendlyName with MainValue like RepeatableComponent