Skip to content

Commit 873abb2

Browse files
committed
Add app home loading API types
1 parent f23628a commit 873abb2

7 files changed

Lines changed: 40 additions & 1 deletion

File tree

packages/ui-extensions-tester/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,8 @@ 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()`.
405+
404406
When testing `admin.app.intent.render`, the mock `shopify.intents` object also includes `response.ok()`, `response.error()`, and `response.closed()`.
405407

406408
#### `extension.fetch`

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ extension.shopify.storage = createStorage({
2323
});
2424
```
2525

26+
## 🏠 App home mocks
27+
28+
The `admin.app.home.render` target mock includes `shopify.toast`, `shopify.app`, and `shopify.loading()`.
29+
2630
## 🧭 App intent mocks
2731

2832
The `admin.app.intent.render` target mock includes `shopify.intents.response.ok()`, `.error()`, and `.closed()`.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
Intents,
99
ToastApi,
1010
AppApi,
11+
LoadingApi,
1112
} from '@shopify/ui-extensions/admin';
1213
import {createReadonlySignalLike} from '../mocks/signals';
1314
import {createMockI18n} from '../mocks/i18n';
@@ -119,11 +120,16 @@ function createMockAppApi(): AppApi {
119120
};
120121
}
121122

123+
function createMockLoadingApi(): LoadingApi {
124+
return () => {};
125+
}
126+
122127
function createAppHomeMock<T extends ExtensionTarget>(target: T) {
123128
return {
124129
...createMockStandardRenderingApi(target),
125130
toast: createMockToastApi(),
126131
app: createMockAppApi(),
132+
loading: createMockLoadingApi(),
127133
};
128134
}
129135

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,17 @@ describe('createMockAdminTargetApi', () => {
4040
expect(api).not.toHaveProperty('resourcePicker');
4141
});
4242

43+
it('creates an app home api with loading controls', () => {
44+
const api = createMockAdminTargetApi('admin.app.home.render');
45+
46+
expect(api.extension.target).toBe('admin.app.home.render');
47+
expect(typeof api.resourcePicker).toBe('function');
48+
expect(typeof api.picker).toBe('function');
49+
expect(typeof api.toast.show).toBe('function');
50+
expect(typeof api.app.extensions).toBe('function');
51+
expect(typeof api.loading).toBe('function');
52+
});
53+
4354
it('creates a standard rendering api for app intent targets', () => {
4455
const api = createMockAdminTargetApi('admin.app.intent.render');
4556

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export type {I18n, I18nTranslate} from '../../api';
22
export type {StandardApi, Intents} from './api/standard/standard';
33
export type {ToastApi, ToastOptions} from './api/toast/toast';
4+
export type {LoadingApi} from './api/loading/loading';
45
export type {
56
AppApi,
67
ExtensionInfo,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ import type {StandardApi} from '../standard/standard';
22
import type {ExtensionTarget as AnyExtensionTarget} from '../../extension-targets';
33
import type {ToastApi} from '../toast/toast';
44
import type {AppApi} from '../app/app';
5+
import type {LoadingApi} from '../loading/loading';
56

67
/**
7-
* The `AppHomeApi` object provides methods for app home extensions. Access the following properties on the `AppHomeApi` object to authenticate users, query the [GraphQL Admin API](/docs/api/admin-graphql), translate content, handle intents, persist data, display toast notifications, and access app-level data.
8+
* The `AppHomeApi` object provides methods for app home extensions. Access the following properties on the `AppHomeApi` object to authenticate users, query the [GraphQL Admin API](/docs/api/admin-graphql), translate content, handle intents, persist data, display toast notifications, control the Admin page-level loading indicator, and access app-level data.
89
* @publicDocs
910
*/
1011
export interface AppHomeApi<ExtensionTarget extends AnyExtensionTarget>
@@ -18,4 +19,9 @@ export interface AppHomeApi<ExtensionTarget extends AnyExtensionTarget>
1819
* Provides access to app-level data and functionality. Use this API to query information about extensions registered for the current app, including their activation status and target information.
1920
*/
2021
app: AppApi;
22+
23+
/**
24+
* Sets the Admin page-level loading indicator. Call `loading(true)` to show the loading indicator while your app home extension performs an asynchronous task. Call `loading(false)`, or call `loading()` without an argument, to hide it when the task completes.
25+
*/
26+
loading: LoadingApi;
2127
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/**
2+
* Sets the Admin page-level loading indicator for hosted app home extensions.
3+
*
4+
* Call with `true` to start loading. Call with `false`, or without an argument,
5+
* to stop loading.
6+
*
7+
* @publicDocs
8+
*/
9+
export type LoadingApi = (isLoading?: boolean) => void;

0 commit comments

Comments
 (0)