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

Weather Story WFO Publish Confirmation #1392

Merged
merged 9 commits into from
Jul 2, 2024

Conversation

eric-gade
Copy link
Collaborator

What does this PR do? 🛠️

After eons, this PR addresses #1269. The gist is that when creating a new Weather Story and entering a linked WFO, authors should see a dialog of some sort informing them that there is another Weather Story already published with the same WFO. The dialog will have options to save a draft, cancel, or "replace" -- meaning unpublish the other Weather Story first, then publish the new one.

What does the reviewer need to know? 🤔

Hey, isn't there a way to already do this?

th

No.

I spent a significant amount of time trying to get this "confirmation, with original form data" concept to work via various Drupal APIs and patterns. None of them worked.

After days of poking at it, I threw my hands up and decided to go with Javascript and some basic hook/template alterations.

Ok, sure, but how does it work?

We add a custom JS file as a theme library called weather-story-modal-dialog which handles the logic of an otherwise inert <dialog> element that is now present in the template for adding weather stories.

In the admin theme file, we add a few helper methods and hooks that will load this library.

Additionally, if the form is a Weather Story create form, the hook will query the system for all weather stories that are currently published, passing information about all of them -- including and especially information about their linked WFO Terms -- to the template file as a JSON object tucked away in a script tag.

If the user decides to publish anyway, all existing published Weather Stories with the same WFO will be archived. This happens by default in the publish action now, and is not unique to the dialog.

Boring! How can I just try it out?

Here are some steps to follow to try it out locally:

  • zap your containers
  • Create a Weather Story for a specific WFO
  • Publish the story
  • Go back to the content page, and try to add a new Weather Story. Select the same WFO
  • Click "Preview"
  • Click the back link
  • Click "Publish"
  • A dialog should appear warning you about the original story being already published. Click "replace"
  • You should see a message saying the new story was published and the old one was unpublished
  • In the content list, there should only be one published weather story

Screenshots (if appropriate): 📸

Visual summary of "replacing" with a new weather story for Nashville

Screenshot 2024-06-26 at 4 23 21 PM
Screenshot 2024-06-26 at 4 23 53 PM
Screenshot 2024-06-26 at 4 24 26 PM
Screenshot 2024-06-26 at 4 24 36 PM
Screenshot 2024-06-26 at 4 24 43 PM

Copy link
Collaborator

@greg-does-weather greg-does-weather 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 quite good. I know it's not what you originally set out to do, but this is nice. One comment that I think needs fixed, but once that's done, I think this is ready to ship and celebrate.

Comment on lines 109 to 112
// First, archive any Weather Story nodes that are already
// published if they have the same WFO as was submitted
$wfo_id = $formState->getValue("field_wfo")[0]["target_id"];
weathergov_unpublish_published_weather_stories($wfo_id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there needs to be a check around this for the node type. Otherwise, publishing a new node of any type that happens to have a WFO field will unpublish weather stories for that WFO.

image

To reproduce:

  1. create a weather story for a WFO
  2. publish it
  3. create a WFO promo for the same WFO
  4. publish it

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Whoa, oof. Good catch

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Should be fixed now in 7cd1aba thanks

Comment on lines +81 to +85
// The data attribute will reference the id
// of a target button to programmatically click
// on the page's actual form.
// If there is no target, the modal will simply close
const targetButton = document.getElementById(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is clever.

As pointed out by Greg, publishing any other type of content node was
unpublishing all Weather Story nodes because we were not checking the
node type during the publish hook.

This commit adds a check.
@eric-gade eric-gade force-pushed the eg-1269-basic-js-ws-confirmation branch from 9b8a534 to 690e6ba Compare June 28, 2024 13:31
Copy link
Collaborator

@greg-does-weather greg-does-weather 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

@eric-gade eric-gade merged commit 3abde7e into main Jul 2, 2024
13 checks passed
@eric-gade eric-gade deleted the eg-1269-basic-js-ws-confirmation branch July 2, 2024 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants