Skip to content

[ui-Quick Start-Analytics] Updating the analytics Frontend code by integrating with new public API and using predefined hooks #4126

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

ananya-agarwal
Copy link
Collaborator

@ananya-agarwal ananya-agarwal commented Apr 23, 2025

What changes were proposed in this pull request?

Updating the analytics Frontend code by integrating with new public API sent by backend which was updated in the PR:
https://github.com/cloudera/hue/pull/4117/files

How was this patch tested?

The Analytics unit test has also been modified, manual testing

Updated Analytics:
Uploading Screen Recording 2025-06-06 at 3.04.31 PM.mov…

Please review Hue Contributing Guide before opening a pull request.

Copy link

github-actions bot commented Apr 23, 2025

✅ Test files were modified. Ensure that the tests cover all relevant changes. ✅

Copy link
Collaborator

@ramprasadagarwal ramprasadagarwal left a comment

Choose a reason for hiding this comment

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

Nice work.

Copy link

github-actions bot commented Apr 23, 2025

Python Code Coverage

Python Coverage Report •
FileStmtsMissCoverMissing
TOTAL541852707850% 
report-only-changed-files is enabled. No files were changed during this commit :)

Pytest Report

Tests Skipped Failures Errors Time
1186 106 💤 0 ❌ 0 🔥 6m 1s ⏱️

@ananya-agarwal ananya-agarwal changed the title [ui-Quick Start-Analytics] Updating the analytics Frontend code by integrating with new public API [ui-Quick Start-Analytics] Updating the analytics Frontend code by integrating with new public API and using predefined hooks May 13, 2025
@ananya-agarwal ananya-agarwal force-pushed the aticks branch 2 times, most recently from 5a620d6 to 8d1d537 Compare May 24, 2025 09:27
@bjornalm bjornalm requested a review from Copilot May 30, 2025 08:05
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request updates the analytics Frontend by integrating it with a new public API and refactoring the code to use predefined hooks for data loading and saving.

  • Updates in test files to use new API endpoints and payload properties.
  • Refactoring of the Analytics component to remove local state and use hook-based data management.
  • Updates to API utility constants and payload type definitions for consistency with the new API.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
desktop/core/src/desktop/js/apps/admin/Overview/OverviewTab.test.tsx Updated tests to call new API endpoint and validate payload using analytics_enabled.
desktop/core/src/desktop/js/apps/admin/Overview/Analytics.tsx Refactored Analytics component to use useLoadData and useSaveData hooks and wrapped the UI with a loading/error component.
desktop/core/src/desktop/js/apps/admin/Components/utils.ts Replaced the old API constant with new API endpoints and defined the payload interface.
Comments suppressed due to low confidence (2)

desktop/core/src/desktop/js/apps/admin/Overview/Analytics.tsx:87

  • Consider normalizing the API response to use a single property for the analytics status to reduce ambiguity in the 'checked' prop. If both properties are needed for backward compatibility, please add a comment explaining the rationale.
            checked={usageAnalyticsData?.analyticsEnabled ?? usageAnalyticsData?.analytics_enabled ?? false}

desktop/core/src/desktop/js/apps/admin/Overview/Analytics.tsx:90

  • Ensure that 'event.target.checked' reliably returns a boolean as expected by the API; consider adding additional type checking if necessary.
            onChange={event => updateAnalyticsPreference({ analytics_enabled: event.target.checked })}

@ananya-agarwal ananya-agarwal force-pushed the aticks branch 4 times, most recently from 0a58cba to 915f373 Compare June 6, 2025 09:31
Copy link

github-actions bot commented Jun 6, 2025

UI Coverage Report

Lines Statements Branches Functions
Coverage: 32%
39.15% (30527/77959) 31.01% (14247/45936) 23.89% (2130/8915)

Copy link

github-actions bot commented Jun 6, 2025

Python Code Coverage

Python Coverage Report •
FileStmtsMissCoverMissing
TOTAL541852707850% 
report-only-changed-files is enabled. No files were changed during this commit :)

Pytest Report

Tests Skipped Failures Errors Time
1186 106 💤 0 ❌ 0 🔥 5m 58s ⏱️

Copy link
Collaborator

@bjornalm bjornalm left a comment

Choose a reason for hiding this comment

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

LGTM

export const INSTALL_APP_EXAMPLES_API_URL = '/api/v1/install_app_examples';
export const INSTALL_AVAILABLE_EXAMPLES_API_URL = '/api/v1/available_app_examples';
export const HUE_DOCS_CONFIG_URL = 'https://docs.gethue.com/administrator/configuration/';
export const GET_USAGE_ANALYTICS_API_URL = '/api/v1/usage_analytics';
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Harshg999 Why do we have '/api/v1/usage_analytics/update' end point? If we are going for true restful APIs there would be no need for a specific update url right?

setCollectUsage(newPreference);
saveCollectUsagePreference(newPreference);
const handleAnalyticsCheckboxChange = (checked: boolean) => {
const formData = new FormData();
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we are using the new public APIs why are we still sending formData and not json?

@Harshg999 @ramprasadagarwal

save: updateAnalyticsPreference,
loading: updatingAnalyticsPreference,
error: updateAnalyticsPreferenceError
} = useSaveData<{ analytics_enabled: boolean }>(UPDATE_USAGE_ANALYTICS_API_URL, {
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ramprasadagarwal @ananya-agarwal for useLoadData we get cameCase response but for useSaveData we still get snake_case response, is that correct? And do we have a jira to sync them?

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.

4 participants