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

[Publisher][Bug] Remove additional context logic from FormStore and DataEntryFormComponents #1341

Merged
merged 2 commits into from
May 30, 2024

Conversation

mxosman
Copy link
Contributor

@mxosman mxosman commented May 22, 2024

Description of the change

Remove additional context logic from FormStore and DataEntryFormComponents as contexts are no longer handled by the record page.

There was a bug reported in staging for agency 11 where opening up a monthly record resulted in a crash. The crash was a result of the record page validation of previously saved inputs attempting to delete an error on the metricsValues object (in the FormStore - this object keeps track of the metric values and error state for each metric value) for a metric that did not exist in this object.

How is this happening?
I'm not entirely sure when this happened or if it's always been this way, but it appears that when you add a value to the additional context field in the Metric Settings definition for a top-level metric, save it, and then delete the value and save it (so an empty string is saved) -- the empty string slips through this check here, and gets unnecessarily validated through this.updateContextValue:

if (context.value !== null && context.value !== undefined) {
this.updateContextValue(

It's still unclear whether this bug was here the entire time, or whether there was a relatively recent change in how empty string contexts are saved and later retrieved from the BE. But, I think the right move here would be to avoid running unnecessary logic for contexts in the FormStore and record page all together because they are not used in any way on the record page as they now live within the Metric Settings definitions and are handled by the MetricConfigStore.

Steps to repro:

  1. Switch to the commit before the temporary fix via git switch e695ea5cda6c015e5982f86853cbd579b74e061c --detach
  2. Choose any agency in staging
  3. Go to Metric Settings and choose an available metric (or make one available)
  4. Update the top-level metric definition by adding text in the additional context box, then save
  5. Go back to the same metric definition and delete everything in the additional context box, then save
  6. Find a record with matching frequency as the metric you just edited
  7. Observe the unglamorous crash, with the following similar message in the console: TypeError: Cannot read properties of undefined (reading 'SUPERVISION_FUNDING') at updateFieldErrorMessage (FormStore.ts:341:1)

I tested this using the agencies in our playbook, going through the repro steps and ensuring there are no issues in the record page, going through and adding data to the records, reloading, and publishing, and really any areas that involve the FormStore.

Type of change

All pull requests must have at least one of the following labels applied (otherwise the PR will fail):

Label Description
Type: Bug non-breaking change that fixes an issue
Type: Feature non-breaking change that adds functionality
Type: Breaking Change fix or feature that would cause existing functionality to not work as expected
Type: Non-breaking refactor change addresses some tech debt item or prepares for a later change, but does not change functionality
Type: Configuration Change adjusts configuration to achieve some end related to functionality, development, performance, or security
Type: Dependency Upgrade upgrades a project dependency - these changes are not included in release notes

Related issues

Closes Recidiviz/recidiviz-data#28666

Checklists

Development

This box MUST be checked by the submitter prior to merging:

  • Double- and triple-checked that there is no Personally Identifiable Information (PII) being mistakenly added in this pull request

These boxes should be checked by the submitter prior to merging:

  • Tests have been written to cover the code changed/added as part of this pull request

Code review

These boxes should be checked by reviewers prior to merging:

  • This pull request has a descriptive title and information useful to a reviewer
  • This pull request has been moved out of a Draft state, has no "Work In Progress" label, and has assigned reviewers
  • Potential security implications or infrastructural changes have been considered, if relevant

@mxosman mxosman force-pushed the mahmoud/fix-remove-context-logic-from-formstore branch from 5c4dad1 to 542d933 Compare May 22, 2024 21:02
@mxosman mxosman marked this pull request as ready for review May 30, 2024 15:03
@@ -158,68 +157,3 @@ export const DisaggregationDimensionTextInput = observer(
);
}
);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This entire component is not being used anywhere.

expect(
rootStore.formStore.metricsValues[0].PROSECUTION_STAFF.error?.message
).toBe("You are also required to enter a value for this field.");
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test no longer necessary as there are no context fields in the record pages.

).toEqual("100");

expect.hasAssertions();
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FormStore no longer needs to worry about the contexts, and as a result, updateContextValue will be deprecated.

metric.enabled
);
}
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No contexts in the record page means we don't have to loop through them and update/validate their values.

),
error: contextError,
};
}),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of this logic is unnecessary since we are deprecating updateContextValue and have no interest in the values of the context in the record page.

key: context.key,
value: contextValue,
});
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cleaning up anywhere else that has context logic.

contextKey
);
}
};
Copy link
Contributor Author

@mxosman mxosman May 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And finally - since we have no interest in anything context-related in the record page, we can safely deprecate this method and all of its dependants.

@helperbot-recidiviz
Copy link
Collaborator

@mxosman successfully triggered a playtest deployment. Full deployment usually takes 5 minutes. Your playtest link is https://mahmoudtest---publisher-web-b47yvyxs3q-uc.a.run.app/

@mxosman mxosman requested review from morden35, lilidworkin and a team May 30, 2024 15:39
Copy link
Collaborator

@lilidworkin lilidworkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for digging into this so deeply, figuring out the best fix, and testing so thoroughly!

@mxosman
Copy link
Contributor Author

mxosman commented May 30, 2024

Thank you for the quick review, Lili!

@mxosman mxosman merged commit b41431a into main May 30, 2024
8 checks passed
@mxosman mxosman deleted the mahmoud/fix-remove-context-logic-from-formstore branch May 30, 2024 21:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants