Skip to content

Commit 740a6f3

Browse files
committed
ai page add views
1 parent 13ca984 commit 740a6f3

3 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/apis/html-page-api.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,15 @@ class HTMLPageAPI {
5151
return this.req.put(url, data, { headers: { 'Content-Type': 'application/json' } });
5252
}
5353

54-
listRows(page_id, table_name, start, limit) {
54+
listRows(page_id, table_name, start, limit, view_name, view_config) {
5555
const url = `${this.server}api/v2.1/universal-apps/${this.appUuid}/html-page-rows/`;
5656
const params = { page_id, table_name, start, limit };
57+
if (view_name) {
58+
params.view_name = view_name;
59+
}
60+
if (view_config && typeof view_config === 'object') {
61+
params.view_config = JSON.stringify(view_config);
62+
}
5763
return this.req.get(url, { params });
5864
}
5965

src/iframe-adapter.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const POST_MESSAGE_REQUEST_TYPE = {
1010
GET_ACCESS_TOKEN: 'get_access_token',
1111
GET_APP_UUID: 'get_app_uuid',
1212
GET_PAGE_ID: 'get_page_id',
13+
GET_VIEWS: 'get_views',
1314
};
1415

1516
const WINDOW_EVENT_SOURCE_TYPE = {

src/sdk.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ export class HTMLPageSDK {
2121
if (!this.options.pageId) {
2222
this.options.pageId = await this.iframeAdapter.request(POST_MESSAGE_REQUEST_TYPE.GET_PAGE_ID);
2323
}
24+
// Pull preview-mode view configs (only meaningful for the ai_agent preview page).
25+
// For real pages the server resolves views from app_config; the inline map is ignored server-side.
26+
if (!this.options.views) {
27+
try {
28+
this.options.views = await this.iframeAdapter.request(POST_MESSAGE_REQUEST_TYPE.GET_VIEWS);
29+
} catch (e) {
30+
this.options.views = null;
31+
}
32+
}
2433
if (this.options.accountToken) {
2534
// dev: try to get access-token via accountToken
2635
const { server, accountToken, appUuid } = this.options;
@@ -34,8 +43,13 @@ export class HTMLPageSDK {
3443
}
3544
}
3645

37-
listRows({ tableName, start, limit }) {
38-
return this.htmlPageAPI.listRows(this.options.pageId, tableName, start, limit);
46+
listRows({ tableName, viewName, start, limit }) {
47+
let viewConfig = null;
48+
if (viewName && this.options.views && typeof this.options.views === 'object') {
49+
const cfg = this.options.views[viewName];
50+
if (cfg && typeof cfg === 'object') viewConfig = cfg;
51+
}
52+
return this.htmlPageAPI.listRows(this.options.pageId, tableName, start, limit, viewName, viewConfig);
3953
}
4054

4155
addRow({ tableName, rowData }) {

0 commit comments

Comments
 (0)