-
Notifications
You must be signed in to change notification settings - Fork 392
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: read-only view for textfield configurator (#13963)
Introduces a read-only mode for the textfield (template) configurator page. Includes the routes, OCC, state, facade and component layer. Allows to view a configuration attached to an order entry in order history. Closes #13939
- Loading branch information
1 parent
b8af7ca
commit 19848ed
Showing
29 changed files
with
543 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 25 additions & 12 deletions
37
...product-configurator/textfield/components/form/configurator-textfield-form.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,27 @@ | ||
<ng-container *ngIf="configuration$ | async as configuration"> | ||
<div | ||
class="cx-attribute" | ||
*ngFor="let attribute of configuration.configurationInfos" | ||
> | ||
<cx-configurator-textfield-input-field | ||
[attribute]="attribute" | ||
(inputChange)="updateConfiguration($event)" | ||
></cx-configurator-textfield-input-field> | ||
</div> | ||
<cx-configurator-textfield-add-to-cart-button | ||
[configuration]="configuration" | ||
></cx-configurator-textfield-add-to-cart-button> | ||
<ng-container *ngIf="isEditable$ | async as isEditable; else readonly"> | ||
<div | ||
class="cx-attribute" | ||
*ngFor="let attribute of configuration.configurationInfos" | ||
> | ||
<cx-configurator-textfield-input-field | ||
[attribute]="attribute" | ||
(inputChange)="updateConfiguration($event)" | ||
></cx-configurator-textfield-input-field> | ||
</div> | ||
|
||
<cx-configurator-textfield-add-to-cart-button | ||
[configuration]="configuration" | ||
></cx-configurator-textfield-add-to-cart-button> | ||
</ng-container> | ||
<ng-template #readonly> | ||
<div | ||
class="cx-attribute" | ||
*ngFor="let attribute of configuration.configurationInfos" | ||
> | ||
<cx-configurator-textfield-input-field-readonly | ||
[attribute]="attribute" | ||
></cx-configurator-textfield-input-field-readonly> | ||
</div> | ||
</ng-template> | ||
</ng-container> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
feature-libs/product-configurator/textfield/components/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './add-to-cart-button/configurator-textfield-add-to-cart-button.component'; | ||
export * from './form/configurator-textfield-form.component'; | ||
export * from './input-field/configurator-textfield-input-field.component'; | ||
export * from './input-field-readonly/configurator-textfield-input-field-readonly.component'; | ||
export * from './textfield-configurator-components.module'; |
8 changes: 8 additions & 0 deletions
8
...omponents/input-field-readonly/configurator-textfield-input-field-readonly.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<label | ||
id="{{ getIdLabel(attribute) }}" | ||
[attr.aria-label]="attribute.configurationLabel" | ||
>{{ attribute.configurationLabel }}</label | ||
> | ||
<div attr.aria-labelledby="{{ getIdLabel(attribute) }}"> | ||
{{ attribute.configurationValue }} | ||
</div> |
58 changes: 58 additions & 0 deletions
58
...onents/input-field-readonly/configurator-textfield-input-field-readonly.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { ChangeDetectionStrategy } from '@angular/core'; | ||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; | ||
|
||
import { ConfiguratorTextfieldInputFieldReadonlyComponent } from './configurator-textfield-input-field-readonly.component'; | ||
|
||
describe('TextfieldInputFieldReadonlyComponent', () => { | ||
let component: ConfiguratorTextfieldInputFieldReadonlyComponent; | ||
let htmlElem: HTMLElement; | ||
let fixture: ComponentFixture<ConfiguratorTextfieldInputFieldReadonlyComponent>; | ||
|
||
beforeEach( | ||
waitForAsync(() => { | ||
TestBed.configureTestingModule({ | ||
declarations: [ConfiguratorTextfieldInputFieldReadonlyComponent], | ||
}) | ||
.overrideComponent(ConfiguratorTextfieldInputFieldReadonlyComponent, { | ||
set: { | ||
changeDetection: ChangeDetectionStrategy.Default, | ||
}, | ||
}) | ||
.compileComponents(); | ||
}) | ||
); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent( | ||
ConfiguratorTextfieldInputFieldReadonlyComponent | ||
); | ||
component = fixture.componentInstance; | ||
component.attribute = { | ||
configurationLabel: 'attributeName', | ||
configurationValue: 'input123', | ||
}; | ||
fixture.detectChanges(); | ||
htmlElem = fixture.nativeElement; | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
|
||
it('should render label', () => { | ||
const idLabel = component.getIdLabel(component.attribute); | ||
const elementsLabel = htmlElem.querySelectorAll('#' + idLabel); | ||
expect(elementsLabel.length).toBe(1); | ||
const elementLabel = elementsLabel[0]; | ||
expect(elementLabel.innerHTML).toBe(component.attribute.configurationLabel); | ||
}); | ||
|
||
it('should render value', () => { | ||
const elementsDiv = htmlElem.querySelectorAll('div'); | ||
expect(elementsDiv.length).toBe(1); | ||
const elementDiv = elementsDiv[0]; | ||
expect(elementDiv.innerHTML).toContain( | ||
component.attribute.configurationValue | ||
); | ||
}); | ||
}); |
32 changes: 32 additions & 0 deletions
32
.../components/input-field-readonly/configurator-textfield-input-field-readonly.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | ||
|
||
import { ConfiguratorTextfield } from '../../core/model/configurator-textfield.model'; | ||
|
||
@Component({ | ||
selector: 'cx-configurator-textfield-input-field-readonly', | ||
templateUrl: './configurator-textfield-input-field-readonly.component.html', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class ConfiguratorTextfieldInputFieldReadonlyComponent { | ||
PREFIX_TEXTFIELD = 'cx-configurator-textfield'; | ||
|
||
@Input() attribute: ConfiguratorTextfield.ConfigurationInfo; | ||
|
||
/** | ||
* Compiles an ID for the attribute label by using the label from the backend and a prefix 'label' | ||
* @param {ConfiguratorTextfield.ConfigurationInfo} attribute Textfield configurator attribute. Carries the attribute label information from the backend | ||
* @returns {string} ID | ||
*/ | ||
getIdLabel(attribute: ConfiguratorTextfield.ConfigurationInfo): string { | ||
return ( | ||
this.PREFIX_TEXTFIELD + 'label' + this.getLabelForIdGeneration(attribute) | ||
); | ||
} | ||
|
||
protected getLabelForIdGeneration( | ||
attribute: ConfiguratorTextfield.ConfigurationInfo | ||
): string { | ||
//replace white spaces with an empty string | ||
return attribute.configurationLabel.replace(/\s/g, ''); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.