-
Notifications
You must be signed in to change notification settings - Fork 87
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/logic: Validate webpack upgrades are ready for React migration #1201
Conversation
408744d
to
5e1fb12
Compare
fc6dfda
to
4c146f3
Compare
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.
tiny nitpicks, otherwise lgtm!
src/public/modules/forms/services/form-logic/form-logic.client.service.ts
Outdated
Show resolved
Hide resolved
src/types/form_logic.ts
Outdated
|
||
type LogicCondition<K extends LogicField, V extends LogicConditionState> = [ | ||
K, | ||
Array<V>, |
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.
nit - we use []
notation rather than Array<>
everywhere else in the repo
Array<V>, | |
V[], |
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, I'd like to keep this to emphasize that LogicCondition
is a two-element array. I'm also not sure if there's much value in enforcing T[]
instead of Array<T>
throughout the codebase, the former notation is a shorthand that emphasises iteration behavior, whereas the latter emphasises that arrays are actually higher-kinded types over another generic type. So I think both could be useful.
Problems
PRs feat: Restore "Bulk Attachment Download Frontend (#640)" + webpack improvements #980 and fix/webpack: Allow ES8 syntax and automatically target IE11 #981 upgraded the frontend webpack build, which was supposed to allow the team to ship a mixture of AngularJS/JavaScript and TypeScript in the latest ES8 syntax without worrying about IE11 compatibility or polyfills.
There was also a lack of typing in client-side logic. This is dangerous when migrating to React, as logic conditions are wholly-determined on the frontend.
Solution
This PR validates those upgrades by demonstrating the conversion of the frontend FormLogic service to TypeScript. Controller code previously used to calculate which if-fields and then-conditions to display in the frontend have also been extracted into the service.
The type
LogicConditions
has also been introduced to constrain the correct pairing between field types and logical comparison operators as far as possible. It is itself composed ofCategoricalLogicCondition
,BinaryLogicCondition
andNumericalLogicCondition
types to differentiate between the different logical operations. The types are not constructed from a statistical POV for simplicity (e.g. the Rating field is technically an ordinal data type) or for historical reasons (binary data is a special case of categorical data).Tests have also been added to ensure the above. Nevertheless, the changes so far only address frontend use cases; any server-side changes will be in a separate PR.
This PR also moved some JSDocs in the routes to be closer to the APIs that they are supposed to be describing.
Dependencies
A dev-dependency
jest-extended
was introduced to take advantage of better utility functions for arrays not available injest
.