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

AFD HTML-only endpoints and selection implementation #1587

Merged
merged 16 commits into from
Aug 26, 2024

Conversation

eric-gade
Copy link
Collaborator

@eric-gade eric-gade commented Aug 21, 2024

What does this PR do? 🛠️

This PR mainly implements #1528, which called for a custom endpoint for HTML-only retrieval of AFD markup (designed to be used by a frontend component).

In the course of working on this ticket, some other changes were made -- see the next section.

This PR also includes a partial implementation of #1529, though it is "switched off" here

What does the reviewer need to know? 🤔

New routes

In order to facilitate the independent AFD viewer page with WFO and version switching, we need to add several routes and Drupal render-array #theme configurations. Note that we are now using the practice of starting routes with /wx/ if they retrieve data that is designed for consumption by frontend components (and not the general public).

Here is a table describing the various routes and what they are for:

route responds with description
/afd full page Will check all available AFDs across the country and redirect to the URL representing the most recent for any WFO. If passed a wfo querystring param, will redirect to the most recent for the given WFO. If passed an id querystring param, it will redirect to the specific page for that AFD and corresponding WFO.
/afd/{wfo} full page Will retrieve the most recent AFD for the given WFO and redirect to the corresponding page.
/afd/{wfo}/{afd_id} full page Will display the AFD viewer page for the with the given AFD presented. The specific version and wfo will also be selected by default in their corresponding select menus
/wx/afd/{id} markup only Responds with only the HTML markup for the the given AFD. Designed to be used by a frontend component
/wx/afd/locations/{wfo} markup only Responds only with HTML markup of <options> elements representing the available AFD versions for the given WFO. This is designed for use on the frontend, in order to repopulate the versions select menu when the WFO has changed

Non-JS functionality

This implementation does not make use of any JS or frontend components for dynamically loading AFD information, even though the routes are present and tested.

Instead, it uses basic form submission with querystrings to the /afd route described above. We did this in order to formally wire up the logic we would need anyway on the backend. Because of this change, we have added a submit button that is not in the original design. In consultation with @partly-igor , we are considering keeping this button even when we add the JS component, so that the interaction is clear.

Bundling updates

We discovered an issue whereby the bundle data for products was incomplete. When getting AFD references for either the whole country (/products/types/AFD) or a given WFO (/products/types/AFD/locations/OKX), there will be references to product IDs that will eventually expire and no longer be available via the API after some time. To deal with this, we've decided to limit the number of references in each of these files to just 10, and then to add all the AFDs for each reference to the bundle. That way we have all the information in perpetuity, and tests will not call out to the real API looking for data that likely doesn't exist anymore.

Screenshots (if appropriate): 📸

Apparently this cannot be used as the name for a Controller's handler function
-- What
We now trim the AFD references for each WFO (in this case OKX and TAE)
down to just 10 entries. We also then add each of product data files
that are referenced. This last step is necessary because otherwise
tests or examples would reach the live API to get the product by
ID. The problem is that after some time these product IDs can no
longer be found by the API. These changes will help prevent that inconsistency
-- What
Now all the /wx/ routes should be rendering correctly. Additionally,
we have fixed the "transclusion" that occurred by using the page
\#theme render array value for the individual afd render template. We
now have separate structures and references.
This is disabled by default (not loaded onto the page)
@eric-gade eric-gade marked this pull request as ready for review August 21, 2024 20:31
@eric-gade eric-gade mentioned this pull request Aug 23, 2024
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.

Gonna make a couple tweaks, but this is awesome. Great work!

Comment on lines +213 to +215
- name: dump drupal logs
if: always()
run: docker compose logs drupal
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
- name: dump drupal logs
if: always()
run: docker compose logs drupal

This is just for debugging. Not sure we want it always?

{
$afd = $this->dataLayer->getProduct($id);
if ($afd) {
$afd = $this->dataLayer->getProduct($id);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious why this is called again. 🤔

Comment on lines 291 to 298
if (!$afd || !array_key_exists("productText", $afd)) {
return null;
}
$rx = "/AFD(?<wfo>[A-Z]{3})/";
if (preg_match($rx, $afd["productText"], $matches)) {
return $matches["wfo"];
}
return null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should switch to using the issuingOffice field. If that begins with a K, we strip of the K and use the remaining 3 letters. Otherwise, we'll use a lookup table provided by @coreypieper in Slack

$versions = $this->weatherData->getLatestAFDReferences($wfo_code);
$afd = $this->weatherData->getAFDById($afd_id);
if (!$afd) {
// This is where you 404
Copy link
Collaborator

Choose a reason for hiding this comment

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

Curious if there's a reason not to go ahead and add the 404 here. I'll leave this alone and we can discuss next week.

* Get the AFD viewer page with the given
* AFD and its WFO already populated
*/
public function byId($afd_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This function isn't referenced in the routing yaml. Gonna leave it alone and we can discuss when you're back!

<h1>Area Forecast Discussion (AFD)</h1>
{% if wfo is not null %}
<h2>latest for {{wfo}}</h2>
<h2>Issued by {{wfo}} at {{afd.issuanceTime}}</h2>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
<h2>Issued by {{wfo}} at {{afd.issuanceTime}}</h2>
<h2>Issued by {{wfo | upper}} at {{afd.issuanceTime}}</h2>

Comment on lines +43 to +70
async handleWFOSelectionUpdated(event){
this.disableInputs();
const wfoCode = event.target.value;
const afdSelectElement = document.getElementById('version-selector');
const url = `/wx/afd/locations/${wfoCode}`;
const response = await fetch(url);
if(response.ok){
afdSelectElement.innerHTML = "";
const markup = await response.text();
afdSelectElement.innerHTML = markup;
}
this.enableInputs();
}

async handleAFDSelectionUpdated(event){
this.disableInputs();
const id = event.target.value;
const afdContainer = this.querySelector('.afd-content');
if(!afdContainer){
return;
}
const response = await fetch(`/wx/afd/${id}`);
if(response.ok){
const markup = await response.text();
afdContainer.outerHTML = markup;
}
this.enableInputs();
}
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 so slick. Love it.

@greg-does-weather greg-does-weather merged commit e762f92 into main Aug 26, 2024
18 checks passed
@greg-does-weather greg-does-weather deleted the eg-1528-afd-html-endpoint branch August 26, 2024 16:28
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