-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(admin-ui): Implement custom fields on newly-supported entities
Relates to #1185
- Loading branch information
1 parent
cd8b93d
commit 2da2ec9
Showing
21 changed files
with
589 additions
and
99 deletions.
There are no files selected for viewing
200 changes: 192 additions & 8 deletions
200
packages/admin-ui/src/lib/core/src/common/generated-types.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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
46 changes: 40 additions & 6 deletions
46
...mer/src/components/customer-group-detail-dialog/customer-group-detail-dialog.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 |
---|---|---|
@@ -1,21 +1,55 @@ | ||
import { ChangeDetectionStrategy, Component } from '@angular/core'; | ||
import { Dialog } from '@vendure/admin-ui/core'; | ||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | ||
import { FormBuilder, FormControl, FormGroup, Validators } from '@angular/forms'; | ||
import { | ||
CreateCustomerGroupInput, | ||
CustomFieldConfig, | ||
Dialog, | ||
ServerConfigService, | ||
UpdateCustomerGroupInput, | ||
} from '@vendure/admin-ui/core'; | ||
|
||
@Component({ | ||
selector: 'vdr-customer-group-detail-dialog', | ||
templateUrl: './customer-group-detail-dialog.component.html', | ||
styleUrls: ['./customer-group-detail-dialog.component.scss'], | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class CustomerGroupDetailDialogComponent implements Dialog<string> { | ||
group: { id?: string; name: string }; | ||
resolveWith: (result?: string) => void; | ||
export class CustomerGroupDetailDialogComponent implements Dialog<CreateCustomerGroupInput>, OnInit { | ||
group: { id?: string; name: string; customFields?: { [name: string]: any } }; | ||
resolveWith: (result?: CreateCustomerGroupInput) => void; | ||
customFields: CustomFieldConfig[]; | ||
form: FormGroup; | ||
|
||
constructor(private serverConfigService: ServerConfigService, private formBuilder: FormBuilder) { | ||
this.customFields = this.serverConfigService.getCustomFieldsFor('CustomerGroup'); | ||
} | ||
|
||
ngOnInit() { | ||
this.form = this.formBuilder.group({ | ||
name: [this.group.name, Validators.required], | ||
customFields: this.formBuilder.group( | ||
this.customFields.reduce((hash, field) => ({ ...hash, [field.name]: '' }), {}), | ||
), | ||
}); | ||
if (this.customFields.length) { | ||
const customFieldsGroup = this.form.get('customFields') as FormGroup; | ||
|
||
for (const fieldDef of this.customFields) { | ||
const key = fieldDef.name; | ||
const value = this.group.customFields?.[key]; | ||
const control = customFieldsGroup.get(key); | ||
if (control) { | ||
control.patchValue(value); | ||
} | ||
} | ||
} | ||
} | ||
|
||
cancel() { | ||
this.resolveWith(); | ||
} | ||
|
||
save() { | ||
this.resolveWith(this.group.name); | ||
this.resolveWith(this.form.value); | ||
} | ||
} |
Oops, something went wrong.