Skip to content

Conversation

@bvandercar-vt
Copy link
Contributor

Checklist

  • [N/A] Includes tests
  • Update documentation

Changes proposed in this pull request:

Allow for stricter type on SegmentedControl than just string, which reduces the need for type casting in many cases (such as onChange call).

For example, you can still have just

<SegmentedControl

as before, for general string Options, or you can have

<SegmentedControl<OptionsEnum>

to make sure that all passed option values, and the onChange, have the OptionsEnum type.

Reviewers should focus on:

Improved type casting abilities, and mainly, the reduction of having to type cast.

Screenshot

No visual changes.

@changelog-app
Copy link

changelog-app bot commented Nov 7, 2024

Generate changelog in packages/core/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

feat(SegmentedControl): allow for passing stricter type for options


Generate changelog in packages/docs-app/changelog/@unreleased

What do the change types mean?
  • feature: A new feature of the service.
  • improvement: An incremental improvement in the functionality or operation of the service.
  • fix: Remedies the incorrect behaviour of a component of the service in a backwards-compatible way.
  • break: Has the potential to break consumers of this service's API, inclusive of both Palantir services
    and external consumers of the service's API (e.g. customer-written software or integrations).
  • deprecation: Advertises the intention to remove service functionality without any change to the
    operation of the service itself.
  • manualTask: Requires the possibility of manual intervention (running a script, eyeballing configuration,
    performing database surgery, ...) at the time of upgrade for it to succeed.
  • migration: A fully automatic upgrade migration task with no engineer input required.

Note: only one type should be chosen.

How are new versions calculated?
  • ❗The break and manual task changelog types will result in a major release!
  • 🐛 The fix changelog type will result in a minor release in most cases, and a patch release version for patch branches. This behaviour is configurable in autorelease.
  • ✨ All others will result in a minor version release.

Type

  • Feature
  • Improvement
  • Fix
  • Break
  • Deprecation
  • Manual task
  • Migration

Description

feat(SegmentedControl): allow for passing stricter type for options


Check the box to generate changelog(s)

  • Generate changelog entry


// This allows the ability to pass a more strict type for `options`/`onValueChange`
// i.e. <SegmentedControl<Intent> />
interface ReactFCWithGeneric extends React.FC<SegmentedControlProps> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit this is a specific interface for SegmentedControl so lets name it something in accordance with that.

Suggested change
interface ReactFCWithGeneric extends React.FC<SegmentedControlProps> {
interface GenericSegmentedControl extends React.FC<SegmentedControlProps> {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔️

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed and commented to match the other cases.

};
export const SizeSelect: React.FC<SizeSelectProps> = ({ label, size, optionLabels, onChange }) => (
<FormGroup label={label}>
<SegmentedControl<Size>
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of curiosity, in these types of cases if you omit <Size> is the generic type parameter properly inferred from the options array? I'm guessing not because there's no as const.

Copy link
Contributor Author

@bvandercar-vt bvandercar-vt Nov 13, 2024

Choose a reason for hiding this comment

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

I'm guessing not because there's no as const.

Correct, it can't be inferred from the options in that case. But it is inferred from the type of the value prop.

{ label: optionLabels[1], value: "regular" },
{ label: optionLabels[2], value: "large" },
]}
onValueChange={onChange}
Copy link
Contributor

Choose a reason for hiding this comment

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

Another point of curiosity (since we ran into this issue with another generic component recently), if you provide an arrow function here, does the type of the argument get properly inferred?

Copy link
Contributor Author

@bvandercar-vt bvandercar-vt Nov 13, 2024

Choose a reason for hiding this comment

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

Yes.

If you specify a type in the generic, it will make sure the onChange arg has the proper type`.

If you don't specify a generic, the arrow function argument is just string

@bvandercar-vt bvandercar-vt force-pushed the bvandercar/segmentedcontrol-value-types branch 4 times, most recently from 9fe373b to 92d2661 Compare January 27, 2025 23:38
@bvandercar-vt
Copy link
Contributor Author

@ggdouglas @jscheiny -- rebased this one.

@bvandercar-vt bvandercar-vt force-pushed the bvandercar/segmentedcontrol-value-types branch from 6eb66b1 to ad256bb Compare February 19, 2025 02:02
@bvandercar-vt bvandercar-vt force-pushed the bvandercar/segmentedcontrol-value-types branch from 497943c to bc3e966 Compare March 6, 2025 14:51
@bvandercar-vt bvandercar-vt force-pushed the bvandercar/segmentedcontrol-value-types branch from 199ce78 to 0eefcda Compare March 6, 2025 14:53
@bvandercar-vt bvandercar-vt deleted the bvandercar/segmentedcontrol-value-types branch July 31, 2025 14:46
@bvandercar-vt
Copy link
Contributor Author

Going to replace with a newer PR.

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.

2 participants