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

Add discard option #42

Merged
merged 7 commits into from
Jun 18, 2024
Merged

Conversation

NickChokas
Copy link
Contributor

@NickChokas NickChokas commented Jun 6, 2024

Type of change (place an x in the [ ] that applies)

  • New sample
  • New feature
  • Bug fix
  • Documentation

Summary

The goal of this PR is to add a "Discard" option to the Draft Message overflow menu, giving the user the option to quickly Delete the Draft if it's not needed. The added logic in create_draft/interactivity_handler.ts will Delete the message from the Draft Slack Channel and also delete the respective record from the drafts.ts Datastore.

image

Requirements (place an x in each [ ] that applies)

  • I’ve checked my submission against the Samples Checklist to ensure it complies with all standards
  • I have ensured the changes I am contributing align with existing patterns and have tested and linted my code
  • I've read and agree to the Code of Conduct

Copy link

salesforce-cla bot commented Jun 6, 2024

Thanks for the contribution! Before we can merge this, we need @NickChokas to sign the Salesforce Inc. Contributor License Agreement.

@NickChokas NickChokas marked this pull request as ready for review June 6, 2024 19:12
@misscoded misscoded added the enhancement New feature or request label Jun 6, 2024
@misscoded misscoded requested review from zimeg and srajiang June 6, 2024 19:15
@srajiang
Copy link
Member

srajiang commented Jun 6, 2024

👋 @NickChokas Thanks so much for this contribution and for this great addition. Would you mind signing the CLA agreement? You should see it linked above on this page.

@NickChokas
Copy link
Contributor Author

NickChokas commented Jun 6, 2024

👋 @NickChokas Thanks so much for this contribution and for this great addition. Would you mind signing the CLA agreement? You should see it linked above on this page.

👋 srajiang - Absolutely! I think it should be good actually:
image

Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

➕ This is super slick! And the code looks great! Left a few comments with some thoughts, but I think all of it can be ignored without problem. Giving an approval now and can merge soon, but will wait a bit for adjustments if you want to make those.

Thanks a ton for sending this in! ❤️

Comment on lines 77 to 78
// If the user selects to discard the draft message
if (action.selected_option.value == "discard_message_overflow") {
Copy link
Member

Choose a reason for hiding this comment

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

IMO it makes sense to break both the edit_message_overflow and discard_message_overflow into separate functions since, once the action.selected_option.value is decided, these branches end with exit or error.

It'd make openDraftEditView act more as a handler which might make parsing a bit easier, but perhaps not... This is personal preference for sure, so your call on this change!

functions/create_draft/interactivity_handler.ts Outdated Show resolved Hide resolved
functions/create_draft/interactivity_handler.ts Outdated Show resolved Hide resolved
functions/create_draft/interactivity_handler.ts Outdated Show resolved Hide resolved
Comment on lines 94 to 98
// Delete the draft from the 'drafts' Datstore
const deleteResp = await client.apps.datastore.delete({
datastore: DraftDatastore.name,
id: id,
});
Copy link
Member

Choose a reason for hiding this comment

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

Without getting too deep in thought, I might opt to delete from the datastore before deleting the message in case something goes wrong with the datastore. In either case an error from either of these gets us into a weird state, so I don't think this has to be changed, but would rather the datastore act as a source of drafting truths if possible!

Copy link
Contributor Author

@NickChokas NickChokas Jun 15, 2024

Choose a reason for hiding this comment

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

Ahh yeah that makes sense to me. I'll move the Delete Datastore operation before the Slack Message Deletion 👌

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the update! Realizing now that moving the datastore check first might also let us return from the function early and avoid deleting the chat message after an error 😳

I'm thinking a try / catch wrapping this function could be interesting, then throwing errors instead of returning early 🤔 But an early return works well too!

Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

All awesome changes, thank you! 👏 This is looking great and about ready to merge but some small things popped out after those changes for me.

Left a few comments around handling more error cases that I think are worth considering, mostly around guarding against strange function behavior and all. Once that seems alright, I believe this'll be a sure way to delete drafts 💪

Comment on lines 94 to 98
// Delete the draft from the 'drafts' Datstore
const deleteResp = await client.apps.datastore.delete({
datastore: DraftDatastore.name,
id: id,
});
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the update! Realizing now that moving the datastore check first might also let us return from the function early and avoid deleting the chat message after an error 😳

I'm thinking a try / catch wrapping this function could be interesting, then throwing errors instead of returning early 🤔 But an early return works well too!

functions/create_draft/interactivity_handler.ts Outdated Show resolved Hide resolved
functions/create_draft/interactivity_handler.ts Outdated Show resolved Hide resolved
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

Thank you for adding the try / catch! This is getting so close to the ideal control flow IMO ✨ Left one more comment around a throw for earlier returns, but all else looks great!

functions/create_draft/interactivity_handler.ts Outdated Show resolved Hide resolved
Copy link
Member

@zimeg zimeg left a comment

Choose a reason for hiding this comment

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

Awesome! Appreciate all of these updates so much, this is a super nice enhancement to add 👏

Tested this and it all works as expected and feels nice! Error handling all looks good too so I think it's time to merge 🚀

@zimeg zimeg merged commit 73dc10a into slack-samples:main Jun 18, 2024
2 checks passed
@NickChokas
Copy link
Contributor Author

Awesome! Appreciate all of these updates so much, this is a super nice enhancement to add 👏

Tested this and it all works as expected and feels nice! Error handling all looks good too so I think it's time to merge 🚀

Thanks again! This was fun!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla:signed enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants