Skip to content

fix: handle removing first item from Contact and links#2128

Merged
davehakkens merged 5 commits intomasterfrom
fix/removing-first-item-of-array
Mar 21, 2023
Merged

fix: handle removing first item from Contact and links#2128
davehakkens merged 5 commits intomasterfrom
fix/removing-first-item-of-array

Conversation

@thisislawatts
Copy link
Contributor

@thisislawatts thisislawatts commented Feb 26, 2023

PR Checklist

PR Type

  • 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)
  • Developer experience (improves developer workflows for contributing to the project)

Description

Fixes an issue that occurs when attempting to remove the first list item from Contacts and Links.
Seems to be coming from: https://github.com/ONEARMY/community-platform/blob/master/src/pages/Settings/content/formSections/Fields/Link.field.tsx#L136:L136

Related chatter:

Git Issues

Closes issue reported:
https://discord.com/channels/586676777334865928/1079116300133072897/1079116300133072897

@cypress
Copy link

cypress bot commented Feb 26, 2023

Passing run #3047 ↗︎

0 73 3 0 Flakiness 0

Details:

fix: remove disabled attr
Project: onearmy-community-platform Commit: 162bebeb3b
Status: Passed Duration: 03:33 💡
Started: Mar 19, 2023 9:08 PM Ended: Mar 19, 2023 9:11 PM

This comment has been generated by cypress-bot as a result of this project's GitHub integration settings.

@thisislawatts
Copy link
Contributor Author

Working on a test to capture this fix. Think it will need to be at the e2e level as we don't have much testing infrastructure at a lower level around these pages.

@thisislawatts thisislawatts marked this pull request as ready for review February 26, 2023 16:01
@thisislawatts thisislawatts requested a review from a team as a code owner February 26, 2023 16:01
@davehakkens davehakkens added the Review allow-preview ✅ Has received manual check for malicious code and can be safely built for preview label Mar 11, 2023
@davehakkens
Copy link
Contributor

I get this popup when removing the link.
Might be due to local testing?
afbeelding

And then this one
afbeelding

And the link doest get deleted..
But i'll try preview

@github-actions
Copy link
Contributor

github-actions bot commented Mar 11, 2023

Visit the preview URL for this PR (updated for commit 162bebe):

https://onearmy-next--pr2128-fix-removing-first-i-qwt8q33h.web.app

(expires Fri, 21 Apr 2023 21:16:42 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 6d65e4f8fee2f6ab2da0c1c3b85b8797d66afa59

@davehakkens
Copy link
Contributor

Same behaviour on Preview.
But thinking about this.. Filling in a contact detail is mandatory at the moment.
Why would there even be an option to delete it? -It can only be replaced by another link..
🤔

@thisislawatts
Copy link
Contributor Author

thisislawatts commented Mar 12, 2023

Thanks for taking a look @davehakkens and catching that debugging alert. I have added an automated linter to catch those in future. I will play about with this a bit more locally, it makes sense that if you add a few more links you should be able to delete the first item. Although I understand that we also expect there to be one item entered.

@thisislawatts
Copy link
Contributor Author

@davehakkens, updated so that the Delete button is only available if there are multiple fields available.

There is only a single field available:
Screenshot 2023-03-13 at 20 06 48

There are multiple links added so any one can be removed. Although it is not possible to safe a profile using an empty value
Screenshot 2023-03-13 at 20 06 55

@davehakkens
Copy link
Contributor

There are multiple links added so any one can be removed. Although it is not possible to safe a profile using an empty value

Nice solution @thisislawatts. However the first/top url doest get removed here when i click delete button. Delete works for all the other ones but not the first

@thisislawatts
Copy link
Contributor Author

Thanks for taking a look @davehakkens, I imagine that is why the tests are failing. Will circle back around to this tomorrow evening.

@thisislawatts thisislawatts force-pushed the fix/removing-first-item-of-array branch from a068f7c to 162bebe Compare March 19, 2023 20:59
@davehakkens
Copy link
Contributor

Is this ready to test again @thisislawatts ?

@thisislawatts
Copy link
Contributor Author

Please do

@davehakkens
Copy link
Contributor

works perfect 👌

@davehakkens davehakkens added the Stage: 🖼️ Design Approved Tagged when design is tested and approved label Mar 20, 2023
Copy link
Contributor

@AlfonsoGhislieri AlfonsoGhislieri 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 @thisislawatts, great idea to add uuid as a key for the links!

Thought: Seeing as we are using a modal for the profile link deletion, as seen here, it could be nice to create a reusable modal.

I've noticed there are a few of these delete modals in the code base which would benefit from this as well (eg in HowtoStep.form and OpeningHoursPicker.field. This would help make sure that any change to the modal design can be applied easily across all components. Moreover, we could also then use it for the deletion of comments as well maybe?

I don't think this should this should fall into the scope of this bug fix, but could be something to as a potential issue if you agree?

}

async function handleDelete(_id: string) {
// eslint-disable-next-line no-alert
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: are we planning on making these into custom modals down the line?

// eslint-disable-next-line no-alert
const confirmation = window.confirm(
'Are you sure you want to delete this comment?',
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

@thisislawatts
Copy link
Contributor Author

Thought: Seeing as we are using a modal for the profile link deletion, as seen here, it could be nice to create a reusable modal.

This is a reusable Modal element from oa-components, is there anything about the current implementation that could be improved to make it easier to reuse?

I've noticed there are a few of these delete modals in the code base which would benefit from this as well (eg in HowtoStep.form and OpeningHoursPicker.field. This would help make sure that any change to the modal design can be applied easily across all components. Moreover, we could also then use it for the deletion of comments as well maybe?

I don't think this should this should fall into the scope of this bug fix, but could be something to as a potential issue if you agree?

Definitely worth raising something like Consistent use of alert/modal as a separate issue, these are not consistent across the site and I think it would be great to make this experience a bit smoother. Specifically on this page I do not think an alert/modal is necessary as the removal action is not immediately destructive. The user needs to click 'Save' before the change will be persisted.

@AlfonsoGhislieri
Copy link
Contributor

AlfonsoGhislieri commented Mar 21, 2023

This is a reusable Modal element from oa-components, is there anything about the current implementation that could be improved to make it easier to reuse?

Ah I didn't realize it was a custom component, my bad, I assumed it was something like react-modal. Nonetheless, my thinking was that the buttons and styling could be extracted into a 'delete' modal component, and just have to pass the desired text down as a prop. Here and here are where I saw the same modal with all the same code inside of each.

The state of the modal could then be stored in something like context or redux, not sure if either is used for the project. This would avoid having to have all the logic for opening and closing the modals inside of each component.

Maybe this is just overcomplicating something that is fine, and most likely not very much a priority, but it just stuck out to me as not being very DRY.

Definitely worth raising something like Consistent use of alert/modal as a separate issue, these are not consistent across the site and I think it would be great to make this experience a bit smoother. Specifically on this page I do not think an alert/modal is necessary as the removal action is not immediately destructive. The user needs to click 'Save' before the change will be persisted.

Yes definitely, as I was going through the site at times it felt odd to use the modal and then later on have the window popout instead. I'll look into raising a issue relating to more consistent use of modals!

@davehakkens davehakkens merged commit 49bd749 into master Mar 21, 2023
@davehakkens davehakkens deleted the fix/removing-first-item-of-array branch March 21, 2023 19:45
@cypress cypress bot mentioned this pull request Mar 21, 2023
@onearmy-bot
Copy link
Collaborator

🎉 This PR is included in version 1.41.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Research 🧪 Review allow-preview ✅ Has received manual check for malicious code and can be safely built for preview Stage: 🖼️ Design Approved Tagged when design is tested and approved

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants