terrastories icon indicating copy to clipboard operation
terrastories copied to clipboard

[Rails] Don't pass orphaned Stories (e.g. no Places or Speakers) to React

Open rudokemper opened this issue 2 years ago • 9 comments

Currently, it's not possible to create a Story without selecting at least one Place and at least one Speaker.

However, it is possible to delete Places and Speakers, which if done can leave a Story "orphaned" (e.g. it exists but has no Places, or Speakers, or both).

It's fine to keep it this way on the Rails side for now -- we need to think about our data structures more -- but we should handle this on the React side.

What is happening now is that the stories will still show up in StoryList. Only, if there are no Speakers, nothing will show at the top, and (worse) if there are no Places, clicking on the card does nothing.

Let's filter out any stories that have 0 Places or 0 Speakers on the React front end. This also means we should filter out any markers on the map that ONLY have stories that have been filtered out.

Acceptance criteria:

  • [ ] If I create a Story, a Place, and a Speaker, and then I delete the Place OR the Speaker (or both), the Story should continue to exist in Rails but it should not be passed to React (e.g. it doesn't show up in StoryList component).
  • [ ] If I create a Story, a Place, and a Speaker, and I delete the Speaker, the Story should not be passed to React, and the Place should also not be passed to React (IF is the only Story associated with it; it should continue to appear on the map if it has other Stories with the minimum validation of >1 Place and >1 Speaker).

rudokemper avatar Sep 23 '23 19:09 rudokemper

I can take this one!

ice1080 avatar Oct 04 '23 04:10 ice1080

Question on this one, assuming for @rudokemper, I'll be filtering out the orphaned stories from dashboard/stories_controller, but should do the same to api/stories_controller? I'm less familiar with what the api module is used for

ice1080 avatar Oct 04 '23 04:10 ice1080

Great question. That is actually used by a new Terrastories React view at https://github.com/terrastories/explore-terrastories, which we still need to document properly. I think it'd be good to filter it out from there as well.

rudokemper avatar Oct 04 '23 12:10 rudokemper

Thanks for the follow up! Regarding this issue, I've got the changes locally but wanted to make sure there are no tests around the pages or dashboard controllers (except Manage Community). Is this correct or am I not seeing them?

A related note, here is a potential way to avoid orphaned parents in this situation. Our use case would be slightly more complex since there are two children to check in the parent, but could still work. https://stackoverflow.com/questions/5866378/delete-orphaned-parent

ice1080 avatar Oct 05 '23 03:10 ice1080

Thank you! I don't believe we have any tests for the pages or controllers. That would be a welcome addition, but I'm also happy to test your work locally for this.

If I'm understanding that article correctly, the suggestion would be to delete any parent if there are no more children left, right? That would not be desirable in our use case; a user might be drafting content and we want to be very intentional about giving them complete control over their actions. Some of our users are not very technical and a piece of content disappearing on them (because it was deleted due to orphanage) could be confusing.

rudokemper avatar Oct 05 '23 12:10 rudokemper

I'm new to rails but not to unit testing, so I'll see if I can put together a couple tests around these.

What you mentioned makes sense in terms of not wanting content to disappear because it's deleted, however wouldn't that pretty much be the case with acceptance 1? If they delete the last speaker or place attached to a story, then that story no longer shows up in the list of stories that can be edited right? So they won't be able to add a speaker/place back? Or did I misinterpret this one?

ice1080 avatar Oct 05 '23 15:10 ice1080

Acceptance criteria #1 means that the story should continue to exist in the db and is accessible for editing or viewing in Rails, but it should no longer show in the StoryList component on React (on the front end, e.g. /home/ route)

rudokemper avatar Oct 05 '23 15:10 rudokemper

Got it! I'll update my work; it might be that both acc 1 and 2 are complete by the work for 2.

ice1080 avatar Oct 05 '23 15:10 ice1080

This one is ready for review @rudokemper! #971

ice1080 avatar Oct 06 '23 04:10 ice1080