Skip to content
This repository was archived by the owner on Sep 27, 2022. It is now read-only.

Handle zero availability case #149

Merged
merged 4 commits into from
Mar 10, 2022
Merged

Handle zero availability case #149

merged 4 commits into from
Mar 10, 2022

Conversation

froboy
Copy link
Contributor

@froboy froboy commented Feb 17, 2022

Activities may have zero spots available but still have signups open (if they have a wait list).

I needed to:

  • pass the 0 to the front-end instead of ''
  • have the front-end handle the zero value like "full"

Fixes #150

To test:

  • Set the spots available field on a session to 0
  • Observe that the front-end displays FULL

@@ -450,7 +450,7 @@ public function processResults(ResultSet $results, $log_id) {
'location_name' => '',
'location_address' => '',
'location_phone' => '',
'spots_available' => !$entity->field_availability->isEmpty() ? $entity->field_availability->value : '',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Drupal's isEmpty just wraps PHP's, which considers 0 as empty.

Copy link
Contributor

@duozersk duozersk Feb 19, 2022

Choose a reason for hiding this comment

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

No, Drupal's isEmpty() specifically checks for NULL - https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21TypedData%21Plugin%21DataType%21ItemList.php/function/ItemList%3A%3AisEmpty/9.3.x

I did a deep dive on it about a year ago: abe64f9 and c2495cb

Null coalescence on the value is probably doing the same thing, meaning that this code change shouldn't actually change a thing. I still tend to have Drupal API isEmpty() here.

Activity Finder 4 already uses the 0 value of available spots: https://github.com/ymcatwincities/openy_activity_finder/blob/4.x/openy_af4_vue_app/src/components/modals/ActivityDetails.vue#L254 - see getButtonTitle() and isRegisterDisabled(); and here https://github.com/ymcatwincities/openy_activity_finder/blob/4.x/openy_af4_vue_app/src/components/AvailableSpots.vue#L26

And you can see it working on the sandbox here: https://sandbox-carnation-cus-d9.openy.org/activity-finder-v4?step=results

image
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@duozersk thanks for your clarification. I think I had two issues:

  1. My project was on an older version and didn't have your new logic using Drupal's isEmpty, it was still using PHP's empty. I believe you're correct and my edit here is not necessary.
  2. My project it still using AF3, which uses the twig templates below. I think that change is still necessary, but won't be reflected in the sandbox as they're using AF4.

Copy link
Contributor

@duozersk duozersk left a comment

Choose a reason for hiding this comment

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

Drupal API is checking for NULL

@@ -450,7 +450,7 @@ public function processResults(ResultSet $results, $log_id) {
'location_name' => '',
'location_address' => '',
'location_phone' => '',
'spots_available' => !$entity->field_availability->isEmpty() ? $entity->field_availability->value : '',
Copy link
Contributor

@duozersk duozersk Feb 19, 2022

Choose a reason for hiding this comment

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

No, Drupal's isEmpty() specifically checks for NULL - https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21TypedData%21Plugin%21DataType%21ItemList.php/function/ItemList%3A%3AisEmpty/9.3.x

I did a deep dive on it about a year ago: abe64f9 and c2495cb

Null coalescence on the value is probably doing the same thing, meaning that this code change shouldn't actually change a thing. I still tend to have Drupal API isEmpty() here.

Activity Finder 4 already uses the 0 value of available spots: https://github.com/ymcatwincities/openy_activity_finder/blob/4.x/openy_af4_vue_app/src/components/modals/ActivityDetails.vue#L254 - see getButtonTitle() and isRegisterDisabled(); and here https://github.com/ymcatwincities/openy_activity_finder/blob/4.x/openy_af4_vue_app/src/components/AvailableSpots.vue#L26

And you can see it working on the sandbox here: https://sandbox-carnation-cus-d9.openy.org/activity-finder-v4?step=results

image
image

@podarok
Copy link
Contributor

podarok commented Mar 9, 2022

Is it ready ? @froboy

@froboy
Copy link
Contributor Author

froboy commented Mar 9, 2022

@podarok yes, I believe so.

@podarok podarok merged commit 61391c9 into ymcatwincities:4.x Mar 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow Sessions to have zero availability
3 participants