Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/apis/html-page-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ class HTMLPageAPI {
return this.req.put(url, data, { headers: { 'Content-Type': 'application/json' } });
}

listRows(page_id, table_name, start, limit) {
listRows(page_id, table_name, start, limit, view_name, view_config) {
const url = `${this.server}api/v2.1/universal-apps/${this.appUuid}/html-page-rows/`;
const params = { page_id, table_name, start, limit };
if (view_name) {
params.view_name = view_name;
}
if (view_config && typeof view_config === 'object') {
params.view_config = JSON.stringify(view_config);
}
return this.req.get(url, { params });
}

Expand Down
1 change: 1 addition & 0 deletions src/iframe-adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export const POST_MESSAGE_REQUEST_TYPE = {
GET_ACCESS_TOKEN: 'get_access_token',
GET_APP_UUID: 'get_app_uuid',
GET_PAGE_ID: 'get_page_id',
GET_VIEWS: 'get_views',
};

const WINDOW_EVENT_SOURCE_TYPE = {
Expand Down
18 changes: 16 additions & 2 deletions src/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ export class HTMLPageSDK {
if (!this.options.pageId) {
this.options.pageId = await this.iframeAdapter.request(POST_MESSAGE_REQUEST_TYPE.GET_PAGE_ID);
}
// Pull preview-mode view configs (only meaningful for the ai_agent preview page).
// For real pages the server resolves views from app_config; the inline map is ignored server-side.
if (!this.options.views) {
try {
this.options.views = await this.iframeAdapter.request(POST_MESSAGE_REQUEST_TYPE.GET_VIEWS);
} catch (e) {
this.options.views = null;
}
}
if (this.options.accountToken) {
// dev: try to get access-token via accountToken
const { server, accountToken, appUuid } = this.options;
Expand All @@ -34,8 +43,13 @@ export class HTMLPageSDK {
}
}

listRows({ tableName, start, limit }) {
return this.htmlPageAPI.listRows(this.options.pageId, tableName, start, limit);
listRows({ tableName, viewName, start, limit }) {
let viewConfig = null;
if (viewName && this.options.views && typeof this.options.views === 'object') {
const cfg = this.options.views[viewName];
if (cfg && typeof cfg === 'object') viewConfig = cfg;
}
return this.htmlPageAPI.listRows(this.options.pageId, tableName, start, limit, viewName, viewConfig);
}

addRow({ tableName, rowData }) {
Expand Down
Loading