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

Enhancement: Make empty defaults in Config into optional props #136

Merged
merged 8 commits into from
Jan 28, 2025

Conversation

epsilonError
Copy link
Contributor

@epsilonError epsilonError commented Jan 10, 2025

Description

startTime and endTime have a default/unused/unset/empty value of null.

The Multiple Section Start/End Time setting for the changed mixins are optional. Currently the UI has a checkbox that when clicked reveals the forms to collect Single and/or Multiple Section info.

This pull request changes the constructed Optional Types to include whether or not the the forms are used/viewable.

The UI form's viewability (or user disinterest in the optional config) is represented by the property being Optional (either absent or set as undefined). This stands in for the unchecked boolean nature of the checkbox.

Once viewable (or user has expressed interest) then the form's default state is shown.

The functionality added here is a backwards compatible way to make the startTime and endTime optional properties in the stored Token ATM Configuration.

The goal is to reduce the stored JSON length since undefined props are stripped when stringified. This is a useful change for possibly adding startTime and endTime configuration to the baseline Token Option Mixin. Which means they would be included as a choice in all Token Options.

Adding a required startTime: null & endTime: null to every Token Option would needlessly increase the length/size of the Token ATM Configuration.

The backwards compatible change adds:

  • acceptance of undefined/absent startTime or endTime in the Token ATM Configuration,
  • converts these optionals into their default null property for use at runtime, and
  • changes nulls into undefined when writing them back to the Token ATM Configuration. This will strip nulls from existing Token Option configurations when they are next saved.

The stripping of nulls will break the Token ATM Configuration's compatibility with earlier versions of Token ATM. So while this change is backwards compatible, previous version are not forward compatible with this change.

In addition to implementing optional props for startTime & endTime this pull request also includes, 2 enhancements:

  1. Raw Token Option Data generators to improve the test surface for Token Options. Implemented to have full parity with the existing EarnBySurvey Token Option tests and automatically increase the test space of valid tests. The raw data generators create valid raw data equivalents of valid data examples. An optional boolean flag can be provided to generate valid but not equal raw data. This combination allows gradually increasing the token option data values that are tested for proper encoding/decoding, using a minimal number of valid examples to tests the breadth of possible data situations, and provides a baseline for ensuring backwards compatibility with existing Token ATM Configurations and runtimes.
  2. Automated tests for the Placeholder Token Option following the EarnBySurvey tests as a template and using raw data generators for Placeholder Token Option Data.

Testing Note

Test if the enhancement works as described. Perform all tests for both Optional Multiple Section Start Times and Optional Multiple Section End Times. Currently these 2 mixins are only used by the Placeholder Token Option.

Some Specific Baseline Tests:

  1. Applicable property can have null value in Token ATM Configuration Included in automated tests
  2. Token Option UI continues to be viewable as described in Feature: Placeholder Token Option #105
  3. Token Option UI still allows editing, validating, and saving applicable Token Option
  4. Saving Placeholder Token Options, strips property -> null pairs from the saved Token ATM Configuration (Automated tests show this should be the case, but also should also be verified on Canvas)
  5. Start Time and End Time UI defaults continue to follow the description in Feature: Placeholder Token Option #105
  6. Both properties continue to save time and multi-section values in the Token ATM Configuration (Automated tests show this should be the case, but should also be verified on Canvas)

`startTime` and `endTime` have a default/unused/unset/empty value of
`null`.

The Multiple Section Start/End Time setting for these mixins are
optional. Currently the UI has a checkbox that when clicked reveals the
forms to collect Single and/or Multiple Section info.

This commit changes the constructed Optional Types to include whether or
not the the forms are used/viewable.

The UI form's viewability (or user disinterest in the optional config)
is represented by the property being Optional (either absent or set as
undefined). This stands in for the unchecked boolean nature of the
checkbox.

Once viewable (or user has expressed interest) then the form's default
state is shown.

The functionality added here is a backwards compatible way to make the
`startTime` and `endTime` optional properties in the stored Token ATM
Configuration.

The goal is reduce the stored JSON length since undefined props are
stripped when stringified. This is a useful change for possibly adding
`startTime` and `endTime` configuration to the baseline Token Option
Mixin. Which means they would be included as a choice in all Token
Options.

Adding a required `startTime: null` & `endTime: null` to every Token
Option would needlessly increase the length/size of the Token ATM
Configuration.

The backwards compatible change adds:
- acceptance of undefined/absent `startTime` or `endTime` in the Token
ATM Configuration,
- converts the optionals into their default `null` property for use at
runtime, and
- changes `null`s into `undefined` when writing them back to the
Token ATM Configuration. This will strip `null`s from existing Token
Option configurations when they are next saved.

The stripping of `null`s will break the Token ATM Configuration's
compatiblity with earlier versions of Token ATM. So while this change is
backwards compatible, it is not downgrade compatible.
@epsilonError
Copy link
Contributor Author

Implementing automated tests showed some errors with this implementation. Converting back to draft pull request.

@epsilonError epsilonError marked this pull request as draft January 23, 2025 00:08
Properly implements partial `startTime` and `endTime`s and provides tests to
ensure backwards compatibility.

Error occured because `io-ts` type's `.validate()` performs the transformation.
And the `chain` function was calling the Partial's `validate` and then the original
`validate`.

This implementation instead checks that the type is a Partial one,
handles the undefined case, and uses the original's `validate` to keep the
data backwards compatible.

This implementation also replaces `null` `startTime` and `endTime`s with `undefined``
which are stripped when stringified by JSON.
@epsilonError epsilonError marked this pull request as ready for review January 27, 2025 23:31
@epsilonError
Copy link
Contributor Author

Implementation now passes further automated tests. Pull request reopened for review, and Description and Testing Note have been updated.

@epsilonError
Copy link
Contributor Author

epsilonError commented Jan 28, 2025

Testing Results

  • 1. Existing Token ATM Configurations with { startTime: null, endTime: null } still load
  • 2. Placeholder Token Option UI still opens and is interact-able
  • 3. Optional Start Time and End Time and section overrides can still be edited, validated, and saved
  • 4. Re-saving existing Placeholder Token Options strips null startTimes and endTimes from the Token ATM Configuration
  • 5. Optional Start Time and End Time date/time inputs use the default auto-fill and continue to function
  • 6. Section overrides and default datetimes are preserved when re-saved using this pull request

@epsilonError epsilonError merged commit e6bce0b into main Jan 28, 2025
1 check passed
@epsilonError epsilonError deleted the enhancement-optional-mixin-props-optional branch January 28, 2025 00:10
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.

1 participant