Skip to content
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

Map over list of eventComment #3689

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Arashfa0301
Copy link
Contributor

@Arashfa0301 Arashfa0301 commented Mar 15, 2023

Description

Improved companyInterestPage by mapping over a list of eventComment field instead of directly having the code snippets for each comment

Testing

  • I have thoroughly tested my changes.

@Arashfa0301 Arashfa0301 added review-needed Pull requests that need review small-fix Pull requests that fix something small labels Mar 15, 2023
@Arashfa0301 Arashfa0301 self-assigned this Mar 15, 2023
@ivarnakken
Copy link
Member

ivarnakken commented Mar 15, 2023

haha sorry, but you'll have to change up the logic here with the migration over to react-final-form. The values need to be spied on, like in the new version of the code. Should be simple to do though.

)}
{eventCommentFields.map((event, i) => {
return (
event.active && (
Copy link
Member

Choose a reason for hiding this comment

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

It makes more sense to filter the list instead. Either here or in the declaration.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code snippet is now updated. Could you check and tell me if filtering is needed now or not.

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 could try to put showComment and the spyValue part in the eventCommentFields list, but maybe filtering isn't necessary now??

Copy link
Member

@norbye norbye left a comment

Choose a reason for hiding this comment

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

LGTM:) lots of love for the reduction of duplicate code

Comment on lines +948 to +952
{eventCommentFields.map((event) => {
return spyValues((values: CompanyInterestFormEntity) => {
const showComment = values.events?.some(
(e) => e.name === event.name && e.checked === true
);
Copy link
Member

Choose a reason for hiding this comment

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

Haven't looked into how these values work exactly, so I'm just throwing it out there so you can decide if it makes sense.

As you're checking the array for events that are .checked (I assume that you have covered all the event names in the array above - so that the e.name === event.name check would only make sure that specific event is checked), could it be an option to instead do something like the following?

spyValues((values: CompanyInterestFormEntity) => 
    values.events?.filter(event => event.checked).map(event => {
        const eventFields = eventCommentFields[event.name]
        return (...);
    })
)

For it to make sense, eventCommentFields would need to be an object with what is currently the name: "" value as the key.

Just an alternative approach to do the same thing, but it would shorten it down a little bit more, and remove the need for the some() calls and boolean values making it a little bit more readable(:

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor

@PeterJFB PeterJFB left a comment

Choose a reason for hiding this comment

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

+1 on @norbye comment, then :shipit:

@ivarnakken ivarnakken added the technical-debt Pull requests that reduces technical debt label Apr 9, 2023
@erlingfn erlingfn added changes-requested Pull requests with requested changes and removed review-needed Pull requests that need review labels Apr 18, 2023
Copy link
Member

@eikhr eikhr left a comment

Choose a reason for hiding this comment

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

Huge improvement! I like @norbye's suggestion, but I think it's fine as it is too:)

Comment on lines +948 to +952
{eventCommentFields.map((event) => {
return spyValues((values: CompanyInterestFormEntity) => {
const showComment = values.events?.some(
(e) => e.name === event.name && e.checked === true
);
Copy link
Member

Choose a reason for hiding this comment

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

@ivarnakken
Copy link
Member

@Arashfa0301 Any updates on this? Would be nice to eventually get it in

@eikhr
Copy link
Member

eikhr commented Sep 22, 2023

@Arashfa0301 can we get this merged?

@ivarnakken
Copy link
Member

@Arashfa0301

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes-requested Pull requests with requested changes small-fix Pull requests that fix something small technical-debt Pull requests that reduces technical debt
Projects
None yet
7 participants