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/logic: Validate webpack upgrades are ready for React migration #1201

Merged
merged 23 commits into from
Mar 9, 2021

Conversation

liangyuanruo
Copy link
Contributor

@liangyuanruo liangyuanruo commented Feb 21, 2021

Problems

  1. 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.

  2. 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 of CategoricalLogicCondition, BinaryLogicCondition and NumericalLogicCondition 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 in jest.

@liangyuanruo liangyuanruo force-pushed the refactor/logic branch 2 times, most recently from 408744d to 5e1fb12 Compare March 8, 2021 02:41
@liangyuanruo liangyuanruo marked this pull request as ready for review March 8, 2021 08:42
@liangyuanruo liangyuanruo requested a review from karrui March 8, 2021 08:42
Copy link
Contributor

@mantariksh mantariksh left a 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/types/form_logic.ts Outdated Show resolved Hide resolved
src/types/form_logic.ts Show resolved Hide resolved
src/types/form_logic.ts Show resolved Hide resolved
src/types/form_logic.ts Show resolved Hide resolved

type LogicCondition<K extends LogicField, V extends LogicConditionState> = [
K,
Array<V>,
Copy link
Contributor

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

Suggested change
Array<V>,
V[],

Copy link
Contributor Author

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.

@liangyuanruo liangyuanruo merged commit 081e18e into develop Mar 9, 2021
@liangyuanruo liangyuanruo deleted the refactor/logic branch March 9, 2021 08:49
@tshuli tshuli mentioned this pull request Mar 10, 2021
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.

None yet

3 participants