-
Notifications
You must be signed in to change notification settings - Fork 4
[NAE-2251] NAE - Map field options are not translated #310
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
f6d7bf9
37711a2
f717a58
8ea7246
92c22c5
8af27f2
42b46b6
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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import {FeaturedValue} from './featured-value'; | |
| import {CurrencyPipe} from '@angular/common'; | ||
| import {ImmediateData} from '../../resources/interface/immediate-data'; | ||
| import {OverflowService} from '../../header/services/overflow.service'; | ||
| import {I18nFieldValue} from "../../data-fields/i18n-field/models/i18n-field-value"; | ||
|
|
||
| @Component({ | ||
| selector: 'ncc-abstract-panel-with-immediate', | ||
|
|
@@ -35,33 +36,37 @@ export abstract class AbstractPanelWithImmediateDataComponent extends AbstractPa | |
| case 'dateTime': | ||
| return { | ||
| value: toMoment(immediate.value as NaeDate).format(DATE_TIME_FORMAT_STRING), | ||
| icon: 'event', type: immediate.type | ||
| icon: 'event', | ||
| type: immediate.type | ||
| }; | ||
| case 'enumeration': | ||
| return {value: immediate.value.defaultValue, icon: undefined, type: immediate.type}; | ||
| return {value: this.getTranslation(immediate.value), icon: undefined, type: immediate.type}; | ||
| case 'multichoice': | ||
| return { | ||
| value: immediate.value.map(it => it.defaultValue).join(', '), | ||
| value: immediate.value.map(it => this.getTranslation(it)).join(', '), | ||
| icon: undefined, | ||
| type: immediate.type | ||
| }; | ||
| case 'enumeration_map': | ||
| return { | ||
| value: immediate.options[immediate.value].defaultValue, | ||
| value: this.getTranslation(immediate.options[immediate.value]), | ||
| icon: undefined, | ||
| type: immediate.type | ||
| }; | ||
| case 'multichoice_map': | ||
| return { | ||
| value: immediate.value.map(it => | ||
| immediate.options[it].defaultValue).join(', '), icon: undefined, type: immediate.type | ||
| this.getTranslation(immediate.options[it])).join(', '), | ||
| icon: undefined, | ||
| type: immediate.type | ||
| }; | ||
| case 'file': | ||
| return {value: immediate.value?.name, icon: 'insert_drive_file', type: immediate.type}; | ||
| case 'fileList': | ||
| return { | ||
| value: immediate.value?.namesPaths.map(obj => obj.name).join(', '), | ||
| icon: 'file_copy', type: immediate.type | ||
| icon: 'file_copy', | ||
| type: immediate.type | ||
| }; | ||
| case 'userList': | ||
| return {value: immediate.value?.userValues.map(obj => obj.fullName).join(', '), icon: 'account_circle', type: immediate.type}; | ||
|
|
@@ -73,11 +78,18 @@ export abstract class AbstractPanelWithImmediateDataComponent extends AbstractPa | |
| icon: undefined, type: immediate.type | ||
| }; | ||
| case 'button': | ||
| let buttonValue: string; | ||
| if ((immediate as any).placeholder?.defaultValue !== undefined) { | ||
| buttonValue = this.getTranslation((immediate as any).placeholder); | ||
| } else if (immediate.name?.defaultValue !== undefined) { | ||
| buttonValue = this.getTranslation(immediate.name); | ||
| } else { | ||
| buttonValue = this._translate.instant('dialog.submit'); | ||
| } | ||
| return { | ||
| value: (immediate as any).placeholder && (immediate as any).placeholder.defaultValue !== undefined | ||
| ? (immediate as any).placeholder.defaultValue : (immediate.name && immediate.name.defaultValue !== undefined | ||
| ? immediate.name.defaultValue : this._translate.instant('dialog.submit')), | ||
| icon: undefined, type: immediate.type | ||
| value: buttonValue, | ||
| icon: undefined, | ||
| type: immediate.type | ||
| }; | ||
|
Comment on lines
+81
to
93
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. Wrap the Apply this diff: - case 'button':
+ case 'button': {
let buttonValue: string;
if ((immediate as any).placeholder?.defaultValue !== undefined) {
buttonValue = this.getTranslation((immediate as any).placeholder);
} else if (immediate.name?.defaultValue !== undefined) {
buttonValue = this.getTranslation(immediate.name);
} else {
buttonValue = this._translate.instant('dialog.submit');
}
return {
value: buttonValue,
icon: undefined,
type: immediate.type
};
+ }
🧰 Tools🪛 Biome (2.1.2)[error] 81-81: Other switch clauses can erroneously access this declaration. The declaration is defined in this switch clause: Safe fix: Wrap the declaration in a block. (lint/correctness/noSwitchDeclarations) 🤖 Prompt for AI Agents |
||
| case 'filter': | ||
| return { | ||
|
|
@@ -101,6 +113,13 @@ export abstract class AbstractPanelWithImmediateDataComponent extends AbstractPa | |
| } | ||
| } | ||
|
|
||
| protected getTranslation(i18n: I18nFieldValue | undefined): string { | ||
| const locale = this._translate.currentLang; | ||
| return (i18n && i18n.translations && locale in i18n.translations) | ||
| ? i18n.translations[locale] | ||
| : (i18n?.defaultValue ?? ''); | ||
| } | ||
|
|
||
| protected formatCurrencyPipe(value: any, code: string, fraction: number, locale: string, type: string) { | ||
| return { | ||
| value: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
🧩 Analysis chain
Verify type compatibility for immediate data values.
The code now assumes that values for enumeration, multichoice, enumeration_map, and multichoice_map field types conform to the
I18nFieldValueinterface. Ensure that:ImmediateDatainterface definitions for these field types guarantee values areI18nFieldValueobjectstranslationsfield (even if empty)Run the following script to verify the ImmediateData type definitions:
🏁 Script executed:
Length of output: 113361
Looking at the shell script results to verify the type safety concerns in the panel-with-immediate-data.ts code.
🏁 Script executed:
Length of output: 5260
🏁 Script executed:
Length of output: 6895
Type definitions for ImmediateData are insufficient for enumeration_map and multichoice_map field types.
The
ImmediateDatainterface (line 50) definesoptions?: { defaultValue?: string }, but the code at lines 52 and 59 treats it as a map ofI18nFieldValueobjects. Additionally,valueis typed asanyrather than enforcing the expectedI18nFieldValuestructure for enumeration and multichoice cases.The type mismatch should be fixed in the interface definition:
Also consider tightening the
valuefield type for these field types using discriminated unions if possible, or at minimum document the expected structure in comments.🤖 Prompt for AI Agents
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.
Options in ImmediateData interface is defined as follows:
Interface si defined in file projects/netgrif-components-core/src/lib/resources/interface/immediate-data.ts
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.
🧩 Analysis chain
🏁 Script executed:
Length of output: 1225
@tuplle, thank you for the correction! You're absolutely right. I've verified that the
ImmediateDatainterface inprojects/netgrif-components-core/src/lib/resources/interface/immediate-data.tscorrectly definesoptionsas:This properly supports the usage in
panel-with-immediate-data.tswhereimmediate.options[immediate.value]andimmediate.options[it]are accessed. The type definitions are correct, and my earlier concern was based on incorrect information. I apologize for the confusion.The implementation looks good from a type safety perspective! ✅
🧬 Code Graph Analysis Results
projects/netgrif-components-core/src/lib/resources/interface/immediate-data.ts
export interface ImmediateData { /** * @ignore */ stringId: string; /** * @ignore */ // TODO Exist only in Net Immediate data title?: any; /** * @ignore */ type: string; /** * @ignore */ value?: any; /** * Only for Fields of type `CaseRef` and `Filter` */ allowedNets?: Array; /** * Only for Fields of type `Filter` */ filterMetadata?: FilterMetadata; /** * Only for Currency Number Fields */ format?: FormatFilter; /** * Only for Currency Number Fields */ component?: Component; /** * @ignore */ // TODO Exists only in case immediate data name?: any; /** * Only for enumeration_map and multichoice_map */ options?: { [k: string]: I18nFieldValue }; }projects/netgrif-components-core/src/lib/data-fields/i18n-field/models/i18n-field-value.ts
export interface I18nFieldValue { defaultValue: string; key?: string; translations?: I18nFieldTranslations; }