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

Topics tab refactoring #4826

Merged
merged 11 commits into from
Jan 3, 2025
Merged

Topics tab refactoring #4826

merged 11 commits into from
Jan 3, 2025

Conversation

gmechali
Copy link
Contributor

@gmechali gmechali commented Jan 3, 2025

Refactor the Topics menu to use a shared TopicItem for each of the buttons.

Only show the Topic button for categories for which we know we have data. We add a second call for the OVERVIEW chart config even when we're on a different category because we need it to identify which topics we have.

France: https://screenshot.googleplex.com/X4McSQ5qax7f9w7
USA: https://screenshot.googleplex.com/BUJQV8rxhfvvT2e

@gmechali gmechali requested a review from dwnoble January 3, 2025 21:10
@gmechali gmechali marked this pull request as ready for review January 3, 2025 21:11
@@ -128,6 +130,7 @@ def get_place_type_with_parent_places_links(dcid: str) -> str:
return ''


@cache.cached(timeout=TIMEOUT, query_string=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this needs to be @cache.memoize() to include the arguments in the cache key: https://flask-caching.readthedocs.io/en/latest/#memoization

Also-you can enable caching locally for testing by setting USE_MEMCACHE = True here

Copy link
Contributor Author

@gmechali gmechali Jan 3, 2025

Choose a reason for hiding this comment

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

Done and tested cache locally, confirming it's very fast now!

): string => {
const isOverview = category === "Overview";

let href = `/place/${place.dcid}`;
Copy link
Contributor

@dwnoble dwnoble Jan 3, 2025

Choose a reason for hiding this comment

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

Using URLSearchParams might make this more clear. Something like:

const href = `/place/${place.dcid}`;
const params = new URLSearchParams();

if (!isOverview) {
  params.set("category", category);
}
if (forceDevPlaces) {
  params.set("force_dev_places", "true");
}

const queryString = params.toString();
if (queryString) {
  return `${href}?${queryString}`;
} else {
  return href;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done - definitely cleans it up a bit, thanks!

})();
}, [place]);

useEffect(() => {
if (placeChartsApiResponse && placeChartsApiResponse.charts) {
const categories = new Set<string>();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this categories set used somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh i was using that before but then switched to using the translatedCategories directly, so I think we're good now. Removed.

});
setCategories(
["Overview"].concat(
Object.values(placeChartsApiResponse.translatedCategoryStrings)
Copy link
Contributor

Choose a reason for hiding this comment

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

I suspect this categories list should store both the english & translated values (one to use on the page text, and one to use in the URL param for the place page)

Copy link
Contributor

@dwnoble dwnoble Jan 3, 2025

Choose a reason for hiding this comment

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

Also- we should add "Overview": "_translated overview value_" to the translatedCategoryStrings entry in the API response.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah I see. Are the translation implemented yet? I tried using it with different HL params and it didnt do anything. I assume we'll need a bit more refactoring here, for example the overview topic will need a translation too, so it should come from the backend probably.
I added a todo to figure this part out.

Copy link
Contributor

Choose a reason for hiding this comment

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

The translations are implemented, but i think there's some extra wiring we need to do to get the frontend to pass the language to the API.

FR example in autopush: https://autopush.datacommons.org/api/dev-place/charts/country/LVA?category=Overview&hl=fr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ack will see what's up with those in follow up.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good!

@gmechali gmechali merged commit dba2831 into datacommonsorg:master Jan 3, 2025
9 checks passed
@gmechali gmechali deleted the topics branch January 3, 2025 23:18
gmechali added a commit to gmechali/website that referenced this pull request Jan 6, 2025
Refactor the Topics menu to use a shared TopicItem for each of the
buttons.

Only show the Topic button for categories for which we know we have
data. We add a second call for the OVERVIEW chart config even when we're
on a different category because we need it to identify which topics we
have.

France: https://screenshot.googleplex.com/X4McSQ5qax7f9w7
USA: https://screenshot.googleplex.com/BUJQV8rxhfvvT2e
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