forked from microsoft/PowerBI-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqna.ts
83 lines (73 loc) · 2.03 KB
/
qna.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { IHttpPostMessageResponse } from 'http-post-message';
import { IError, IQnaInterpretInputData, validateLoadQnaConfiguration } from 'powerbi-models';
import { Embed, IEmbedConfigurationBase } from './embed';
import { Service } from './service';
/**
* The Power BI Q&A embed component
*
* @export
* @class Qna
* @extends {Embed}
*/
export class Qna extends Embed {
/** @hidden */
static type = "Qna";
/** @hidden */
static allowedEvents = ["loaded", "visualRendered"];
/**
* @hidden
*/
constructor(service: Service, element: HTMLElement, config: IEmbedConfigurationBase, phasedRender?: boolean, isBootstrap?: boolean) {
super(service, element, config, /* iframe */ undefined, phasedRender, isBootstrap);
this.loadPath = "/qna/load";
this.phasedLoadPath = "/qna/prepare";
Array.prototype.push.apply(this.allowedEvents, Qna.allowedEvents);
}
/**
* The ID of the Q&A embed component
*
* @returns {string}
*/
getId(): string {
return null;
}
/**
* Change the question of the Q&A embed component
*
* @param {string} question - question which will render Q&A data
* @returns {Promise<IHttpPostMessageResponse<void>>}
*/
async setQuestion(question: string): Promise<IHttpPostMessageResponse<void>> {
const qnaData: IQnaInterpretInputData = {
question: question
};
try {
return await this.service.hpm.post<void>('/qna/interpret', qnaData, { uid: this.config.uniqueId }, this.iframe.contentWindow);
} catch (response) {
throw response.body;
}
}
/**
* Handle config changes.
*
* @returns {void}
*/
configChanged(_isBootstrap: boolean): void {
// Nothing to do in Q&A embed.
}
/**
* @hidden
* @returns {string}
*/
getDefaultEmbedUrlEndpoint(): string {
return "qnaEmbed";
}
/**
* Validate load configuration.
*/
validate(config: IEmbedConfigurationBase): IError[] {
return validateLoadQnaConfiguration(config);
}
}