-
Notifications
You must be signed in to change notification settings - Fork 1
Feature/awf/cleanup time agg param#212 #231
Conversation
Refactor such that IndicatorQueryOpts.params now has type IndicatorParams which can be extended with additional parameters for some indicators. Improves type checking and prevents us from having to write duplicate interface defs for indicators that need to extend the params of IndicatorQueryOpts
Gives these EventEmitters a more specific API contract, to always be of type IndicatorParams, which includes "subtypes" such as ThresholdIndicatorParams
Includes a few more places where we can better typecast params to the new IndicatorParam type
Most of below lifted from an offline discussion, but copied here for visibility (@jcahail): I chose to go with only the We could potentially revisit this if we hear a bunch of users requesting it, but for now its less effort and less complicated for users to just omit the option. |
@@ -62,11 +62,11 @@ export class ThresholdComponent implements AfterViewInit, OnInit { | |||
ngAfterViewInit() { | |||
// Since valueChanges triggers initially before parent is ready, wait until | |||
// parent is ready here and trigger it to draw chart with extra parameters. | |||
this.thresholdParamSelected.emit({data: { | |||
this.thresholdParamSelected.emit({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the data
object removed here? You had asked for it to be added in another PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I had misunderstood what the original problem was based on the comments before, combined with forgetting the details of how EventEmitter
s work. What's here now is the proper way to return data via event emitters, if you do not need the DOM Event
import { TimeAggParam } from './time-agg-param.enum'; | ||
|
||
export interface IndicatorParams { | ||
climateModels?: ClimateModel[]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noticed these are all optional. Shouldn't they be required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because none of these params are required to make an API request, they all have defaults.
@@ -17,7 +17,6 @@ export class ChartService { | |||
|
|||
private timeOptions = { | |||
'yearly': '%Y', | |||
'daily': '%Y-%m-%d', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a quarterly format added here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, we don't use it but it wouldn't hurt to be thorough
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, can't do this now. It would require additional refactoring. In the quarterly case, we need to convert the keys in the API (e.g. 2010-3) into the start date for a "quarter" which would be July 1, 2010 for 2010-3, and that can't be done with D3.timeParse
. We'd need this refactor for pretty much all of the other remaining valid time aggs if we chose to display them in the lab UI.
src/app/charts/chart.component.ts
Outdated
@@ -115,18 +116,15 @@ export class ChartComponent implements OnChanges, OnDestroy, AfterViewInit { | |||
this.cancelDataRequest(); | |||
} | |||
|
|||
updateChart(extraParams: any) { | |||
updateChart(extraParams: IndicatorParams) { | |||
this.cancelDataRequest(); | |||
this.chartData = []; | |||
this.rawChartData = []; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not understanding why the typecheck doesn't complain when ThresholdIndicatorParams are sent through
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because interface ThresholdIndicatorParams
extends interface IndicatorParams
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah interesting. Extending works the opposite direction I was expecting, then. Cool.
@@ -0,0 +1,10 @@ | |||
import { ClimateModel } from './climate-model.model'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now there are two models:
indicator-parameters.model.ts
indicator-params.model.ts
in the models folder, and that is confusing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any suggestions for better names? otherwise I'll try to come up with something
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been using the term "extra params"
Maybe
indicator-extra-params?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or perhaps indicator-query-parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have indicator-query-opts and these params aren't always the subset that are the extra params. They're really the GET params to an API request. What about the following refactor:
IndicatorQueryOpts -> IndicatorRequestOpts
IndicatorParams -> IndicatorGetParams
- Leave
IndicatorParam
unchanged
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK IndicatorRequestOpts
2 -- > IndicatorParamsList? or IndicatorQueryStringParams?
OK IndicatorParam
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IndicatorQueryParams
would just be a shorter version of your second option that isn't any less descriptive. How about that? Definitely like your second suggestion, which is more properly named than even IndicatorGetParams
, than the first.
To hopefully reduce confusion: - IndicatorQueryOpts -> IndicatorRequestOpts - IndicatorParams -> IndicatorQueryParams - No change to IndicatorParam
Overview
Replaces the
string
type of thetime_aggregation
indicator param with a new enum typeTimeAggParam
. This allows for improved type checking.Assigned both of you so you can see this change. @flibbertigibbet because I mentioned I was making it in a previous PR you authored, and @fungjj92 so it can inform your work on the percentile indicator params.
Demo
No user facing changes
Notes
To make this easier, I replaced the subclassing of IndicatoryQueryOpts by making IndicatorQueryOpts.params have a new IndicatorParams interface that can be extended instead of the QueryOpts interfaces. This provides a much improved type interface for these, and allows us to better type check the params as they're passed around the app, especially when we construct requests to IndicatorService and when we pass the params around via EventEmitters.
The models folder is getting pretty big, and its now very unwieldy to import one item from each file everywhere. I considered adding an index.ts to the models folder and exporting all of the items in that folder there and updating import statements across the app, but that would have cluttered the intent of this PR. Maybe a good separate issue.
Testing Instructions
App should continue to function
Closes #212