Skip to content

Commit 077bc51

Browse files
committed
Address admin app home review comments
1 parent 4d3f74e commit 077bc51

7 files changed

Lines changed: 27 additions & 31 deletions

File tree

packages/ui-extensions-tester/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ Imports and executes the extension module's default export, rendering the extens
401401

402402
A mock `shopify` global, typed correctly for the target under test. You can mutate any property.
403403

404-
When testing `admin.app.home.render`, the mock `shopify` object also includes `toast`, `app`, and `loading()`.
404+
When testing `admin.app.home.render`, the mock `shopify` object also includes `toast`, `app`, `loading()`, `tools`, and `intents.request`.
405405

406406
When testing `admin.app.intent.render`, the mock `shopify.intents` object also includes `response.ok()`, `response.error()`, and `response.closed()`.
407407

packages/ui-extensions-tester/src/admin/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension.shopify.storage = createStorage({
2525

2626
## 🏠 App home mocks
2727

28-
The `admin.app.home.render` target mock includes `shopify.toast`, `shopify.app`, and `shopify.loading()`.
28+
The `admin.app.home.render` target mock includes `shopify.toast`, `shopify.app`, `shopify.loading()`, `shopify.tools`, and `shopify.intents.request`.
2929

3030
## 🧭 App intent mocks
3131

packages/ui-extensions-tester/src/admin/factories.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,16 @@ function createMockToolsApi(): Tools {
134134
}
135135

136136
function createAppHomeMock<T extends ExtensionTarget>(target: T) {
137+
const {invoke} = createMockStandardApi(target).intents;
138+
137139
return {
138140
...createMockStandardRenderingApi(target),
139141
toast: createMockToastApi(),
140142
app: createMockAppApi(),
141143
loading: createMockLoadingApi(),
142144
tools: createMockToolsApi(),
143145
intents: {
144-
...createMockStandardApi(target).intents,
146+
invoke,
145147
request: {
146148
value: null,
147149
subscribe: () => () => {},

packages/ui-extensions-tester/src/tests/admin-app-home-intents.test.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,12 @@ import type {
88
} from '@shopify/ui-extensions/admin';
99

1010
import {createMockAdminTargetApi} from '../admin/factories';
11+
import {assertType, type Equals} from './type-assertions';
1112

1213
// ---------------------------------------------------------------------------
1314
// Compile-time assertions
1415
// ---------------------------------------------------------------------------
1516

16-
type Equals<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B
17-
? 1
18-
: 2
19-
? true
20-
: false;
21-
22-
function assertType<_T extends true>() {}
23-
2417
type AppHome = AppHomeApi<'admin.app.home.render'>;
2518

2619
// AppHomeApi exposes a richer `Intents` shape than `StandardApi`: a signal-
@@ -29,9 +22,7 @@ type AppHome = AppHomeApi<'admin.app.home.render'>;
2922
assertType<Equals<AppHome['intents'], AppHomeIntents>>();
3023
assertType<Equals<AppHome['intents']['request'], AppHomeIntentRequest>>();
3124

32-
// `AppHomeIntents` extends the base `Intents` so `launchUrl` and `invoke`
33-
// remain reachable.
34-
assertType<Equals<AppHomeIntents['launchUrl'], Intents['launchUrl']>>();
25+
// `AppHomeIntents` keeps the standard invocation helper.
3526
assertType<Equals<AppHomeIntents['invoke'], Intents['invoke']>>();
3627

3728
// `WithGeneratedIntents` narrows `request.value` to the generated payload
@@ -74,11 +65,9 @@ describe('app home intents api', () => {
7465
expect(() => unsubscribe()).not.toThrow();
7566
});
7667

77-
it('exposes the standard `Intents` members alongside `request`', () => {
68+
it('exposes the standard `invoke` helper alongside `request`', () => {
7869
const api = createMockAdminTargetApi('admin.app.home.render');
7970

80-
// `launchUrl` and `invoke` come from the base `Intents` shape.
81-
expect(api.intents.launchUrl).toBeUndefined();
8271
expect(typeof api.intents.invoke).toBe('function');
8372
});
8473
});

packages/ui-extensions-tester/src/tests/admin-tools.test.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,12 @@ import type {
66
} from '@shopify/ui-extensions/admin';
77

88
import {createMockAdminTargetApi} from '../admin/factories';
9+
import {assertType, type Equals} from './type-assertions';
910

1011
// ---------------------------------------------------------------------------
1112
// Compile-time assertions
1213
// ---------------------------------------------------------------------------
1314

14-
type Equals<A, B> = (<T>() => T extends A ? 1 : 2) extends <T>() => T extends B
15-
? 1
16-
: 2
17-
? true
18-
: false;
19-
20-
function assertType<_T extends true>() {}
21-
2215
interface UpdateFaqInput {
2316
id: string;
2417
body: string;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export type Equals<A, B> = (<T>() => T extends A ? 1 : 2) extends <
2+
T,
3+
>() => T extends B ? 1 : 2
4+
? true
5+
: false;
6+
7+
export function assertType<_T extends true>(): void {
8+
return undefined;
9+
}

packages/ui-extensions/src/surfaces/admin/api/app-home/app-home.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ import type {AppApi} from '../app/app';
55
import type {LoadingApi} from '../loading/loading';
66
import type {Tools} from '../tools/tools';
77
import type {
8+
IntentInvokeApi,
89
IntentQueryOptions,
910
IntentResponseApi,
10-
Intents,
1111
} from '../intents/intents';
1212

1313
/**
@@ -38,14 +38,13 @@ export interface AppHomeIntentRequest {
3838
}
3939

4040
/**
41-
* The intents API available to app home extensions. Extends the standard
42-
* `Intents` API with a signal-like `request` that streams link intents into
43-
* the long-running extension. `response` is only present while an intent is
44-
* active and is bound to the current `request.value`.
41+
* The intents API available to app home extensions. It exposes a signal-like
42+
* `request` that streams link intents into the long-running extension. Inspect
43+
* `request.value` for information about the active intent.
4544
*
4645
* @publicDocs
4746
*/
48-
export interface AppHomeIntents extends Intents {
47+
export interface AppHomeIntents {
4948
/**
5049
* The current link intent delivered to the extension. Subscribe to receive
5150
* new intents over the lifetime of the extension.
@@ -56,6 +55,10 @@ export interface AppHomeIntents extends Intents {
5655
* non-null; the runtime swaps in a fresh handle for each new intent.
5756
*/
5857
response?: IntentResponseApi;
58+
/**
59+
* Launches an intent workflow for creating or editing Shopify resources.
60+
*/
61+
invoke?: IntentInvokeApi;
5962
}
6063

6164
/**

0 commit comments

Comments
 (0)