-
-
Notifications
You must be signed in to change notification settings - Fork 176
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
Typescriptize reports files #5079
base: beta
Are you sure you want to change the base?
Conversation
…eports-files # Conflicts: # jsapp/js/popoverMenu.scss
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.
Besides some questions and a tiny bug the functionality seems all intact. I have a suggestion though, do you think we can split a PR like this into multiple? A typescriptization IMO should be singular and (almost) trivial--if the compiler doesn't complain and we do a quick review then it should be merged. This would remove a lot of noise and confusion if there's a refactor that's coming as well.
* the Chart.js), the latter is the instance of a report style (as Back end | ||
* understands it). | ||
*/ | ||
export const REPORT_STYLES: ReportStyleDefinitions = Object.freeze({ |
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 trying to understand this as I don't encounter using mapped types often and at first glace this feels very circular.
So ReportStyleName
is just a union of strings that we get from Chart.js. ReportStyleDefinition
is an interface that ties up the report style strings from Chart.js with a string label and a chartJsType
. In essence the existence of ReportStyleDefinition
is to combine together the type, label and Chart.js stuff for each graph type.
Then ReportStyleDefinitions
is a mapped type that creates an instance which has each unioned string in ReportStyleName
as a value and its type is ReportStyleDefinition
. We then manually set REPORT_STYLES
to fit this type?
Then we have a ReportStyle
type, which by the looks of it are settings/configs that can be applied to each report and change the way it's presented. Do you think this could have a better name, such as ReportStyleSettings
?
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.
Yeah, this weird construct is needed so everything ties together in the places that use the const. I renamed REPORT_STYLES
to CHART_STYLES
(and all the other related things renamed to use "chart" word) to make it less confusing.
|
||
const reportData = this.props.reportData; | ||
|
||
// TODO: the code below is very convoluted and hard to read/understand, even |
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.
Oh my 🥲 if you have some time I would love to know how this works--assuming you had time to figure it out while doing this typescriptization
defaultStyle: ReportStyle; | ||
} | ||
|
||
export default function ChartColorsPicker(props: ChartColorsPickerProps) { |
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 do we switch this one to a functional component? Some of the other typescriptization files remained as class components
import type {FailResponse} from 'js/dataInterface'; | ||
|
||
interface QuestionGraphSettingsProps { | ||
parentState: ReportsState; |
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.
Would it be hard to refactor this into a store of some kind? Maybe a good second issue for the furture
} | ||
} | ||
|
||
const tabs: ReportsModalTabName[] = ['chart-type', 'colors']; |
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.
Think we talked about this before but just quickly, do we think using enums here is too redundant?
// HACK: We no longer keep built PreparedTable in state, it's simply rebuilt | ||
// during render. We keep this to ensure that re-render happens when props | ||
// change. | ||
static getDerivedStateFromProps() { |
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.
Not sure if I'm not reading the diffs correctly, but was this method never used? I don't see it removed anywhere except here
@@ -169,59 +169,6 @@ | |||
} | |||
} | |||
|
|||
.popover-menu--custom-reports { |
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 didn't see this change mentioned in the description, were these just unused styles?
if (!this.props.disableEscClose && (evt.keyCode === KEY_CODES.ESC || evt.key === 'Escape')) { | ||
this.props.onClose.call(evt); | ||
} | ||
} | ||
|
||
backdropClick(evt) { | ||
backdropClick(evt: TouchEvent) { |
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.
This error happens when clicking the backdrop now:
Uncaught TypeError: this is undefined
backdropClick modal.tsx:72
Checklist
Description
Migrated all reports related code to TypeScript, so it's easier to improve it in future. Also changed the UI responsible for creating new reports, so it's clearer how to add new custom report.
Notes
I didn't want to go too far with refactoring the code, just the bare minimum to make the code work consistently and be mostly readable.
Changes here:
jsapp/js/components/common/modal.tsx
to TypeScriptModal
component (this is the old deprecated one). The unmount process wasn't really removing the listener./jsapp/js/components/reports/
to TS.AssetResponse
, and defined all the shared types of reports inreportsConstants.ts
filereports.utils.ts
file for keeping some reusable functionsReportsModalTabs
component to remove duplicated code being used in two placesgetReportData
(fromdataInterface.ts
) function types, as paginated response doesn't follow our usualPaginatedResponse<T>
txtid
function from CoffeeScript file toutils.ts
, so it was available for refactored reports codeRelated issues
Build atop #5046