-
Notifications
You must be signed in to change notification settings - Fork 37
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
set unstable to latest customer-account internal state #1448
Conversation
be84199
to
9c193e0
Compare
@@ -50,10 +50,12 @@ export type { | |||
MapLocation, | |||
MaybeConditionalStyle, | |||
MaybeResponsiveConditionalStyle, | |||
IconSource, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those seemed to be missing. Other non-prop exports of components , like MapBounds
are exported here as well.
@@ -17,3 +17,13 @@ export class ExtensionHasNoMethodError extends Error { | |||
); | |||
} | |||
} | |||
|
|||
export class ExtensionHasNoFieldError extends Error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bunch of our hooks only work on the ODP. We're throwing this error when they are used outside of the ODP.
This is done so that we can keep the typings that we have. Alternatively, we'd have to mark all of them as optional which would be a breaking change for existing OSP/ODP extensions.
6ef36dd
to
6822b3d
Compare
This comment has been minimized.
This comment has been minimized.
export type { | ||
AccessibilityRole, | ||
ActionExtensionApi, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added new APIs
6822b3d
to
6d47c96
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Components and related types look good
@@ -5,14 +5,21 @@ import type { | |||
|
|||
import {useApi} from './api'; | |||
import {useSubscription} from './subscription'; | |||
import {ExtensionHasNoFieldError} from '../errors'; | |||
|
|||
/** | |||
* Returns the proposed `attributes` applied to the checkout. | |||
*/ | |||
export function useAttributes< | |||
Target extends RenderExtensionTarget = RenderExtensionTarget, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm... we limited it to only RenderOrderStatusExtensionTarget
to strongly suggest that it should only be used on order status page, why do we change it back to RenderExtensionTarget as it will not put any type check error for targets outside order status page ? https://github.com/Shopify/ui-extensions/blob/internal/packages/ui-extensions-react/src/surfaces/customer-account/hooks/attributes.ts#L24
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
adjusted it. Unfortunately, I had to update a bunch of tests to set extension.target
in the api as it would've otherwise failed. It's actually better, but it makes the PR seem bigger
6b9a15a
to
dd85a78
Compare
dd85a78
to
be9465d
Compare
>(filters: AppMetafieldFilters = {}): AppMetafieldEntry[] { | ||
const appMetafields = useSubscription(useApi<Target>().appMetafields); | ||
const api = useApi<Target>(); | ||
const extensionTarget = api.extension.target; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we switch https://github.com/Shopify/ui-extensions/pull/1448/files#diff-ccb0ccef13a6c51f7ca59868cf8bc5ef122d304f166692a758ea3e83abe796a3R24 error's constructor from
constructor(field: string, target: ExtensionTarget) {
to
constructor(field: string, target: RenderExtensionTarget) {
will we be able to get rid of the extra const here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it has unfortunately nothing to do with the Error.
Take this example here:
export function useAppMetafields<
Target extends RenderOrderStatusExtensionTarget = RenderOrderStatusExtensionTarget,
>(filters: AppMetafieldFilters = {}): AppMetafieldEntry[] {
const api = useApi<Target>();
const extensionTarget = api.extension.target;
if (!('appMetafields' in api)) {
// api will be `never` inside this if block. Even before we even use the `Error`
// it's because it's typing-wise impossible to get into this state
// you can't have no appMetafields and still have a valid `api` object. (technically)
// but not everybode uses TS, so we still want to throw if someone uses this hook for an extension point that does not make sense
throw new ExtensionHasNoFieldError('appMetafields', extensionTarget);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tophatted and looks good, let's release a new unstable version to have a test~
Background
This PR moves back our
internal
apis tounstable
in preparation for release.It mainly ports over new components (like Card) and APIs that we have added, but also includes some type renamings caused by clashes in OrderStatus and StandardApi.
The PR also ensures that hooks that only work on the ODP properly throw errors if used elsewhere.
🎩
Here's what I did on the spinstance to make this 🎩 able.
inside ui-extensions
To build the packages and make them consumable locally.
Then inside the customer account and extension repos
So both are now using the locally built version of
ui-extension
packages.I ran
type-check
inside in both repos, which succeeded.It'll run again properly in CI after we merge this PR and update the version properly in package.json
You can see the still working extension here.
customer-account.order.action.render
dev@shopify.com
https://identity.unstable-one.robin-drexler.us.spin.dev/services/mailChecklist