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

Replace seamapi package with seam package #641

Merged
merged 77 commits into from
Jul 18, 2024
Merged

Replace seamapi package with seam package #641

merged 77 commits into from
Jul 18, 2024

Conversation

razor-x
Copy link
Member

@razor-x razor-x commented Jul 11, 2024

Gathering changes here: #640

I've added comments to the PR to focus on interesting changes. Most of the rest is just fixing type errors or normalizing the hooks.

@razor-x razor-x changed the title Replace seamapi with seam Replace seamapi package with seam packahge Jul 15, 2024
@razor-x razor-x changed the title Replace seamapi package with seam packahge Replace seamapi package with seam package Jul 15, 2024
@razor-x razor-x marked this pull request as ready for review July 17, 2024 22:00
@razor-x razor-x requested review from mikewuu and dawnho as code owners July 17, 2024 22:00
@razor-x razor-x requested review from phpnode and mikewuu and removed request for dawnho and mikewuu July 17, 2024 22:00
"@tanstack/react-query": "^5.27.5",
"classnames": "^2.3.2",
"luxon": "^3.3.0",
"queue": "^7.0.0",
"radash": "^12.1.0",
Copy link
Member

Choose a reason for hiding this comment

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

as we only use shake from this dep and as it is not typesafe, can we add a utility instead?

function filterUndefinedValues<T extends object>(input: T): {[K in keyof T as T[K] extends undefined ? never : K]: T[K]} {
  return Object.fromEntries(Object.entries(input).filter(([, value]) => value !== undefined)) as never
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, noted here: #641 (comment)

Copy link
Member Author

@razor-x razor-x Jul 18, 2024

Choose a reason for hiding this comment

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

as it is not typesafe

Dang, I thought / hoped it was typesafe

Copy link
Member Author

Choose a reason for hiding this comment

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

Merging this into the next version branch. Will do a followup PR to swap the dep since this one is so large and otherwise ready to go.

"@tanstack/react-query": "^5.27.5",
"classnames": "^2.3.2",
"luxon": "^3.3.0",
"queue": "^7.0.0",
"radash": "^12.1.0",
Copy link
Member Author

Choose a reason for hiding this comment

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

I added this dependency out of frustration for missing some simple utilities. Implementing shake instead of adding this is an alternative.

},
onSuccess: () => {
onSuccess: (data) => {
queryClient.setQueryData(
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that query invalidation is imperfect and a separate issue is tracking it here: #639

Comment on lines +194 to +207
{accessCode.starts_at != null && (
<div>
<div className='seam-label'>{t.start}</div>
<div className='seam-date'>{formatDate(accessCode.starts_at)}</div>
<div className='seam-time'>{formatTime(accessCode.starts_at)}</div>
</div>
)}
{accessCode.ends_at != null && (
<div>
<div className='seam-label'>{t.end}</div>
<div className='seam-date'>{formatDate(accessCode.ends_at)}</div>
<div className='seam-time'>{formatTime(accessCode.ends_at)}</div>
</div>
)}
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a case of the types fixing a bug :) There are a few other cases like this.

Comment on lines +33 to +35
if (device.can_program_online_access_codes == null) {
return null
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Added some check on flags where it made sense for this PR, but I thin there is more we can do #643

Comment on lines +156 to +166
const handleResponseError = (error: SeamHttpApiError): void => {
if (isSeamHttpInvalidInputError(error)) {
const errors = shake({
code: error.getValidationErrorMessages('code')[0],
name: error.getValidationErrorMessages('name')[0],
})

return
if (Object.keys(errors).length === 0) {
setResponseErrors({
unknown: error.message,
})
}
Copy link
Member Author

Choose a reason for hiding this comment

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

New SDK feature for validation messages.

NonNullable<Required<Pick<Device['properties'], 'locked'>>>
}

export const isLockDevice = (device: Device): device is LockDevice =>
Copy link
Member Author

Choose a reason for hiding this comment

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

These type guards are now application specific. In this case, Seam Components is defining how create logical device types optimized for its use case. See https://github.com/seamapi/react/blob/seam-http/src/lib/seam/noise-sensors/noise-sensor-device.ts and https://github.com/seamapi/react/blob/seam-http/src/lib/seam/thermostats/thermostat-device.ts

Copy link
Member Author

Choose a reason for hiding this comment

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

Functions here are used for optimistic updates and some input UX.

...device,
properties: {
...properties,
current_climate_setting: {
Copy link
Member Author

Choose a reason for hiding this comment

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

Optimistic updates for all thermostat hooks was expanded like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

New types fix some edge cases here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Using the new client here.

@razor-x razor-x merged commit b0d0a77 into tmp-next Jul 18, 2024
16 checks passed
@razor-x razor-x deleted the seam-http branch July 18, 2024 19:09
@razor-x razor-x mentioned this pull request Jul 19, 2024
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.

3 participants