|
5 | 5 |
|
6 | 6 | import powerbi from "powerbi-visuals-api"; |
7 | 7 |
|
8 | | -import { IFormattingSettingsSlice } from "./FormattingSettingsInterfaces"; |
| 8 | +import { IFormattingSettingsSlice, ILocalizedItemMember } from "./FormattingSettingsInterfaces"; |
9 | 9 | import * as FormattingSettingsParser from "./utils/FormattingSettingsUtils"; |
10 | 10 |
|
11 | 11 | import data = powerbi.data; |
@@ -126,9 +126,16 @@ export abstract class SimpleSlice<T = any> extends NamedEntity implements IForma |
126 | 126 | } |
127 | 127 | // eslint-disable-next-line |
128 | 128 | getFormattingComponent?(objectName: string, localizationManager?: powerbi.extensibility.ILocalizationManager): visuals.SimpleComponentBase<any> { |
| 129 | + let value: T | ILocalizedItemMember = this.value as ILocalizedItemMember; |
| 130 | + if (value.displayNameKey) { |
| 131 | + value = { |
| 132 | + displayName: localizationManager?.getDisplayName(value.displayNameKey), |
| 133 | + value: value.value |
| 134 | + } as T; |
| 135 | + } |
129 | 136 | return { |
130 | 137 | descriptor: FormattingSettingsParser.getDescriptor(objectName, this), |
131 | | - value: this.value, |
| 138 | + value: value, |
132 | 139 | } |
133 | 140 | } |
134 | 141 |
|
@@ -235,21 +242,35 @@ export class DatePicker extends SimpleSlice<Date> { |
235 | 242 | } |
236 | 243 | } |
237 | 244 |
|
238 | | -export class ItemDropdown extends SimpleSlice<powerbi.IEnumMember> { |
239 | | - items: powerbi.IEnumMember[]; |
| 245 | +export class ItemDropdown extends SimpleSlice<powerbi.IEnumMember | ILocalizedItemMember> { |
| 246 | + items: powerbi.IEnumMember[] | ILocalizedItemMember[]; |
240 | 247 |
|
241 | 248 | type?= visuals.FormattingComponent.Dropdown; |
242 | 249 |
|
243 | 250 | constructor(object: ItemDropdown) { |
244 | 251 | super(object); |
245 | 252 | } |
246 | 253 |
|
247 | | - getFormattingComponent?(objectName: string): visuals.ItemDropdown { |
| 254 | + getFormattingComponent?(objectName: string, localizationManager?: powerbi.extensibility.ILocalizationManager): visuals.ItemDropdown { |
248 | 255 | return { |
249 | | - ... super.getFormattingComponent(objectName), |
250 | | - items: this.items |
| 256 | + ... super.getFormattingComponent(objectName, localizationManager), |
| 257 | + items: this.getFormattingItems(localizationManager, this.items) |
251 | 258 | } |
252 | 259 | } |
| 260 | + |
| 261 | + getFormattingItems?(localizationManager?: powerbi.extensibility.ILocalizationManager, items?: powerbi.IEnumMember[] | ILocalizedItemMember[]): powerbi.IEnumMember[] { |
| 262 | + return items.map((item) => { |
| 263 | + return { |
| 264 | + ...item, |
| 265 | + displayName: (localizationManager && item.displayNameKey) ? localizationManager.getDisplayName(item.displayNameKey) : item.displayName |
| 266 | + } |
| 267 | + }) |
| 268 | + } |
| 269 | + |
| 270 | + setValue?(value: powerbi.EnumMemberValue, localizationManager?: powerbi.extensibility.ILocalizationManager) { |
| 271 | + const newValue = this.getFormattingItems(localizationManager, this.items).find((item) => item.value === value); |
| 272 | + this.value = newValue ? newValue : this.items[0]; |
| 273 | + } |
253 | 274 | } |
254 | 275 |
|
255 | 276 | export class AutoDropdown extends SimpleSlice<powerbi.EnumMemberValue> { |
|
0 commit comments