Repository navigation
[NAE-2496] Custom Component Registry for Case Views #362
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
base: release/7.1.0
Are you sure you want to change the base?
Changes from all commits
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,7 @@ | ||
| <span class="panel-text enumeration-value-panel-item" | ||
| [ngClass]="{'text-column-ellipsis': data.textEllipsis, 'text-column-word-wrap': !data.textEllipsis}" | ||
| [style.backgroundColor]="backgroundColor" | ||
| [style.color]="color" | ||
| [matTooltip]="data.featuredValue.value" | ||
| [matTooltipDisabled]="!data.textEllipsis" | ||
| [matTooltipClass]="'pre-line-dialog'">{{data.featuredValue.value}}</span> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| .enumeration-value-panel-item { | ||
| display: inline-block; | ||
| min-width: 0; | ||
| padding: 4px 12px; | ||
| font-weight: 600; | ||
| line-height: 24px; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import {Component, Inject} from '@angular/core'; | ||
| import {NAE_PANEL_ITEM_DATA, PanelItemPortalData} from 'netgrif-components-core'; | ||
|
|
||
| @Component({ | ||
| selector: 'nae-enumeration-value-panel-item', | ||
| templateUrl: './enumeration-value-panel-item.component.html', | ||
| styleUrls: ['./enumeration-value-panel-item.component.scss'] | ||
| }) | ||
| export class EnumerationValuePanelItemComponent { | ||
| public readonly backgroundColor: string | undefined; | ||
| public readonly color: string | undefined; | ||
|
|
||
| constructor(@Inject(NAE_PANEL_ITEM_DATA) public readonly data: PanelItemPortalData) { | ||
| const optionKey = this.resolveOptionKey(data.featuredValue.rawValue); | ||
| this.backgroundColor = this.resolveStyleProperty(optionKey, 'background'); | ||
| this.color = this.resolveStyleProperty(optionKey, 'color'); | ||
| } | ||
|
|
||
| private resolveOptionKey(rawValue: unknown): string | undefined { | ||
| if (typeof rawValue === 'string') { | ||
| return rawValue; | ||
| } | ||
| if (rawValue && typeof rawValue === 'object' && 'defaultValue' in rawValue | ||
| && typeof rawValue.defaultValue === 'string') { | ||
| return rawValue.defaultValue; | ||
| } | ||
| return undefined; | ||
| } | ||
|
|
||
| private resolveStyleProperty(optionKey: string | undefined, property: string): string | undefined { | ||
| const properties = this.data.featuredValue.component?.properties; | ||
| return optionKey ? properties?.[`${optionKey}-${property}`] ?? properties?.[property] : properties?.[property]; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -388,6 +388,15 @@ export abstract class DataField<T> { | |
| return this.component?.name ?? DEFAULT; | ||
| } | ||
|
|
||
| public getTypedDefaultComponentType(): string { | ||
| const componentType = this.getComponentType(); | ||
| const typedComponentType = this.getTypedComponentType(); | ||
| if (componentType === DEFAULT || !typedComponentType.endsWith(componentType)) { | ||
| return typedComponentType; | ||
| } | ||
| return `${typedComponentType.slice(0, -componentType.length)}${DEFAULT}`; | ||
|
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. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
# Inspect the field-specific typed-key implementation and component-name handling.
ast-grep outline projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts \
--match getTypedComponentType --view expanded
rg -n -C 5 'getTypedComponentType|getComponentType|component\?\.name' \
projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts \
projects/netgrif-components-core/src/lib/data-fields/models/abstract-data-field.tsRepository: netgrif/components Length of output: 4740 🏁 Script executed: rg -n -F --glob '*.ts' -e 'enumeration-default' -e 'component.name' -e 'name?: string' -e 'name: string' -e 'getComponentType()' -e 'new EnumerationField' projects/netgrif-components-core/src projects/netgrif-components-core/test || test "$?" -eq 1
rg -n -C 6 -F --glob '*.ts' -e 'component?:' -e 'component: {' -e 'class Component' -e 'interface Component' projects/netgrif-components-core/src projects/netgrif-components-core/test || test "$?" -eq 1Repository: netgrif/components Length of output: 41821 🏁 Script executed: sed -n '1,95p' projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.ts
sed -n '185,230p' projects/netgrif-components-core/src/lib/task-content/services/field-converter.service.ts
sed -n '1,85p' projects/netgrif-components-core/src/lib/data-fields/enumeration-field/models/enumeration-field.spec.ts
sed -n '1,90p' projects/netgrif-components-core/src/lib/data-fields/data-field-template/abstract-data-field-template.component.spec.ts
sed -n '1,45p' projects/netgrif-components-core/src/lib/data-fields/models/component.tsRepository: netgrif/components Length of output: 10764 Normalize empty component names before deriving the fallback key.
Treat an empty component name as the default component before deriving the typed fallback key. 🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| public abstract getTypedComponentType(): string; | ||
|
|
||
| public destroy(): void { | ||
|
|
||
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.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Example field
component.namedoes not match the registered key.The app registers the renderer under the name
"totok"at Lines 303-306. The example data inpanels.component.tsusescomponent.namevalues'value'and'icon'. No'value'renderer is registered forenumeration. That field falls back to the default renderer, and the customEnumerationValuePanelItemComponentnever renders in the example. Align the registered name with the example data, or change the example data to'totok'. Also use single quotes to match the surrounding code, and remove the extra blank line.Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents