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

update useGenericObjectState types #3274

Conversation

christianvogt
Copy link
Contributor

https://issues.redhat.com/browse/RHOAIENG-9748

Description

Improves the typing of useGenericObjectState such that the value is properly typed depending on the supplied property key. As a result, any unmatched value will result in a typescript error.

Extracted common types for model serving into a separate type definition to be used by common form components.

Additionally, updated useGenericObjectState to accept a function to coincide with the API of useState. This function argument can be used when the computation of default data is expensive.

How Has This Been Tested?

npm run test:type-check
Ran existing tests.

Test Impact

N/A

Request review criteria:

Self checklist (all need to be checked):

  • The developer has manually tested the changes and verified that the changes work
  • Testing instructions have been added in the PR body (for PRs involving changes that are not immediately obvious).
  • The developer has added tests or explained why testing cannot be added (unit or cypress tests for related changes)

If you have UI changes:

  • Included any necessary screenshots or gifs if it was a UI change.
  • Included tags to the UX team if it was a UI/UX change.

After the PR is posted & before it merges:

  • The developer has tested their solution on a cluster by using the image produced by the PR to main

Copy link

codecov bot commented Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 84.89%. Comparing base (7ff95e0) to head (bea9b86).
Report is 9 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3274      +/-   ##
==========================================
+ Coverage   84.87%   84.89%   +0.01%     
==========================================
  Files        1307     1307              
  Lines       29188    29183       -5     
  Branches     7872     7872              
==========================================
  Hits        24774    24774              
+ Misses       4414     4409       -5     
Files with missing lines Coverage Δ
...epts/pipelines/content/createRun/useRunFormData.ts 88.75% <100.00%> (ø)
...elRegistry/screens/RegisterModel/RegisterModel.tsx 100.00% <ø> (ø)
...Registry/screens/RegisterModel/RegisterVersion.tsx 88.23% <ø> (-0.66%) ⬇️
...s/RegisterModel/RegistrationCommonFormSections.tsx 95.12% <100.00%> (ø)
...iceModal/InferenceServiceServingRuntimeSection.tsx 94.73% <100.00%> (ø)
.../ServingRuntimeModal/AuthServingRuntimeSection.tsx 93.10% <100.00%> (ø)
...ngRuntimeModal/ServingRuntimeSizeExpandedField.tsx 77.77% <100.00%> (ø)
.../ServingRuntimeModal/ServingRuntimeSizeSection.tsx 97.50% <100.00%> (ø)
...s/ServingRuntimeModal/ServingRuntimeTokenInput.tsx 48.48% <100.00%> (ø)
...ServingRuntimeModal/ServingRuntimeTokenSection.tsx 89.47% <100.00%> (ø)
... and 5 more

... and 3 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7ff95e0...bea9b86. Read the comment docs.

export type UpdateObjectAtPropAndValue<T> = (propKey: keyof T, propValue: ValueOf<T>) => void;
export type UpdateObjectAtPropAndValue<T> = <K extends keyof T>(
propKey: K,
propValue: Partial<T>[K],
Copy link
Member

Choose a reason for hiding this comment

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

Won't this break the sanctity of our type behind the object store?

I can send undefined to a value required by the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The current types are already broken in that I can supply a value from any prop for any key.
This isn't a perfect solution but a step that's better IMO. Enforces correct type but is allowing undefined.

I suppose we can always keep looking for the perfect solution...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Went with another approach that required altering several components which utilize this type. I was not able to find a solution whereby only the UpdateObjectAtPropAndValue could be updated and solve all use cases.

Copy link
Contributor

openshift-ci bot commented Oct 7, 2024

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: jeff-phillips-18

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-merge-bot openshift-merge-bot bot merged commit c4e2940 into opendatahub-io:main Oct 7, 2024
8 checks passed
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.

3 participants