Repository navigation
Refactor filters from crud model to get/set model with objects representing each level instead of targets. #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
a2844ec
c91abd9
0c9ea68
3251cb5
7da90d2
d2f82dc
7ee2685
19afc8e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // Place your settings in this file to overwrite default and user settings. | ||
| { | ||
| "editor.tabSize": 4, | ||
| "editor.insertSpaces": true | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| const config = { | ||
| version: '2.0.0-beta.7', | ||
| version: '2.0.0-beta.8', | ||
| type: 'js' | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| import * as models from 'powerbi-models'; | ||
|
|
||
| export interface IFilterable { | ||
| getFilters(): Promise<(models.IBasicFilter | models.IAdvancedFilter)[]>; | ||
| setFilters(filters: (models.IBasicFilter | models.IAdvancedFilter)[]): Promise<void>; | ||
| removeFilters(): Promise<void>; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { IFilterable } from './ifilterable'; | ||
| import { IReportNode } from './report'; | ||
| import { Visual } from './visual'; | ||
| import * as models from 'powerbi-models'; | ||
|
|
||
| export interface IPageNode { | ||
| report: IReportNode; | ||
| name: string; | ||
| } | ||
|
|
||
| export class Page implements IPageNode, IFilterable { | ||
| report: IReportNode; | ||
| name: string; | ||
| // This can be undefined in cases where page is created manually | ||
| displayName: string; | ||
|
|
||
| constructor(report: IReportNode, name: string, displayName?: string) { | ||
| this.report = report; | ||
| this.name = name; | ||
| this.displayName = displayName; | ||
| } | ||
|
|
||
| /** | ||
| * Gets all page level filters within report | ||
| * | ||
| * ```javascript | ||
| * page.getFilters() | ||
| * .then(pages => { ... }); | ||
| * ``` | ||
| */ | ||
| getFilters() { | ||
| return this.report.service.hpm.get<models.IFilter[]>(`/report/pages/${this.name}/filters`, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow) | ||
| .then(response => response.body, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. or is this supposed to be a |
||
| response => { | ||
| throw response.body; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assuming these
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not understanding the relationship with WFE code. For both fulfilled and rejected responses from the server we want to return the body of the response instead of just the response. For the fulfill case the body should be a list of filters, and for the rejected case it should be an error object. The throw is needed to preserve rejected state for the chain. |
||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Gets all the visuals on the page. | ||
| * | ||
| * ```javascript | ||
| * page.getVisuals() | ||
| * .then(visuals => { ... }); | ||
| * ``` | ||
| */ | ||
| getVisuals(): Promise<Visual[]> { | ||
| return this.report.service.hpm.get<models.IVisual[]>(`/report/pages/${this.name}/visuals`, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow) | ||
| .then(response => { | ||
| return response.body | ||
| .map(visual => { | ||
| return new Visual(this, visual.name); | ||
| }); | ||
| }, response => { | ||
| throw response.body; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Remove all filters on this page within the report | ||
| * | ||
| * ```javascript | ||
| * page.removeFilters(); | ||
| * ``` | ||
| */ | ||
| removeFilters() { | ||
| return this.setFilters([]); | ||
| } | ||
|
|
||
| /** | ||
| * Make the current page the active page of the report. | ||
| * | ||
| * ```javascripot | ||
| * page.setActive(); | ||
| * ``` | ||
| */ | ||
| setActive() { | ||
| const page: models.IPage = { | ||
| name: this.name, | ||
| displayName: null | ||
| }; | ||
|
|
||
| return this.report.service.hpm.put<models.IError[]>('/report/pages/active', page, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow) | ||
| .catch(response => { | ||
| throw response.body; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Sets all filters on the current page. | ||
| * | ||
| * ```javascript | ||
| * page.setFilters(filters); | ||
| * .catch(errors => { ... }); | ||
| * ``` | ||
| */ | ||
| setFilters(filters: (models.IBasicFilter | models.IAdvancedFilter)[]) { | ||
| return this.report.service.hpm.put<models.IError[]>(`/report/pages/${this.name}/filters`, filters, { uid: this.report.config.uniqueId }, this.report.iframe.contentWindow) | ||
| .catch(response => { | ||
| throw response.body; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Creates new Visual object given a name of the visual. | ||
| * | ||
| * Normally you would get Visual objects by calling `page.getVisuals()` but in the case | ||
| * that the visual name is known and you want to perform an action on a visaul such as setting a filters | ||
| * without having to retrieve it first you can create it directly. | ||
| * | ||
| * Note: Since you are creating the visual manually there is no guarantee that the visual actually exists in the report and the subsequence requests could fail. | ||
| * | ||
| * ```javascript | ||
| * const visual = report.page('ReportSection1').visual('BarChart1'); | ||
| * visual.setFilters(filters); | ||
| * ``` | ||
| */ | ||
| visual(name: string): Visual { | ||
| return new Visual(this, name); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated but I noticed half of the files are using 2 spaces and others using 4. Going to reformat everything to 2 space after the code review is complete, but didn't want to do it now since it introduces lot of white-space change noise in the review.