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

Refactor feature page chart methods #1031

Merged

Conversation

DanielRyanSmith
Copy link
Collaborator

Fixes #964

This change refactors some methods for generating the data used to populate the feature support and usage charts to maximize reusability, as well as adding new unit tests.

Copy link
Collaborator

@jcscottiii jcscottiii left a comment

Choose a reason for hiding this comment

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

Thanks so much for this Daniel!!

Added comments for/to:

  1. Remove runtime conversions to any
  2. Ensure we still have the fix from Fix: Feature usage chart pagination #1013
  3. Other nits

@jcscottiii
Copy link
Collaborator

Also: The playwright test is failing because it is showing only the last page of results.

image

This is fixed in #1013 but your current changes undo that (I think from a git conflict resolution). Once you revert, it should pass.

@DanielRyanSmith
Copy link
Collaborator Author

@jcscottiii You might want to check this again and view the changes on the last commit 70e0599 - I was not able to find a way to ensure we can use the this keyword after passing the dataFetcher functions as a parameter, since they will not have an explicit context in the location those functions are invoked. There might be a way to handle this more effectively, but using this within a function passed as a parameter is causing some issues.

Copy link
Collaborator

@jcscottiii jcscottiii left a comment

Choose a reason for hiding this comment

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

I see why pageComponent was needed to fix the playwright test. But we could leverage the same thing we do for LoadingTaskType.

type LoadingTaskType = '_loadingMetricsTask' | '_loadingUsageTask';
+type FetchTaskType = '_fetchFeatureSupportData' | '_fetchFeatureUsageData';

Then we can modify _startDataFetchingTask like the following

-  private async _startDataFetchingTask<T extends LoadingTaskType>(
-    manualRun: boolean,
-    dataFetcher: (
-      apiClient: APIClient,
-      featureId: string,
-      startDate: Date,
-      endDate: Date,
-    ) => Promise<void>,
-    taskType: T,
-  ) {
+  private async _startDataFetchingTask<
+    T extends LoadingTaskType,
+    F extends FetchTaskType,
+  >(manualRun: boolean, dataFetcher: F, taskType: T) {
...
-          await dataFetcher(apiClient, featureId, this.startDate, this.endDate);
+          await this[dataFetcher](
+            apiClient,
+            featureId,
+            this.startDate,
+            this.endDate,
+          );
...

And finally the two tasks would like this:

export class FeaturePage extends LitElement {
   private async _startFeatureSupportTask(manualRun: boolean) {
     await this._startDataFetchingTask(
       manualRun,
-      this._fetchFeatureSupportData,
+      '_fetchFeatureSupportData',
       '_loadingMetricsTask',
     );
   }
export class FeaturePage extends LitElement {
   private async _startFeatureUsageTask(manualRun: boolean) {
     await this._startDataFetchingTask(
       manualRun,
-      this._fetchFeatureUsageData,
+      '_fetchFeatureUsageData',
       '_loadingUsageTask',
     );
   }

@DanielRyanSmith DanielRyanSmith force-pushed the 964_refactor-chart-methods branch from 0fdb4e5 to 5b0cc78 Compare January 6, 2025 23:37
@jcscottiii jcscottiii added this pull request to the merge queue Jan 7, 2025
Merged via the queue into GoogleChrome:main with commit 6ff83f5 Jan 7, 2025
3 checks passed
@DanielRyanSmith DanielRyanSmith deleted the 964_refactor-chart-methods branch January 7, 2025 17:09
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.

[ENHANCEMENT] Refactor feature chart methods to be more generic and reusable
2 participants