}
editAction() {
- this.hostService.getLabels().subscribe((resp: string[]) => {
- const host = this.selection.first();
- const labels = new Set(resp.concat(this.hostService.predefinedLabels));
+ const host = this.selection.first();
+ this.hostService.getLabels().subscribe((resp) => {
+ const hostLabels: string[] = Array.isArray(host['labels'])
+ ? [...(host['labels'] as string[])]
+ : [];
+ const labels = new Set(resp.concat(this.hostService.predefinedLabels).concat(hostLabels));
const allLabels = Array.from(labels).map((label) => {
- return { content: label, selected: host['labels'].includes(label) };
+ return { content: label, selected: hostLabels.includes(label) };
});
this.cdsModalService.show(FormModalComponent, {
titleText: $localize`Edit Host: ${host.hostname}`,
{
type: 'select-badges',
name: 'labels',
- value: host['labels'],
+ value: hostLabels,
label: $localize`Labels`,
typeConfig: {
customBadges: true,
submitButtonText: $localize`Edit Host`,
onSubmit: (values: any) => {
this.hostService.update(host['hostname'], true, values.labels).subscribe(() => {
+ const selectedHost = this.selection.first();
+ if (selectedHost && selectedHost['hostname'] === host.hostname) {
+ host['labels'] = values.labels;
+ Object.assign(selectedHost, host);
+ }
this.notificationService.show(
NotificationType.success,
$localize`Updated Host "${host.hostname}"`
import { CdFormBuilder } from '~/app/shared/forms/cd-form-builder';
import { CdFormGroup } from '~/app/shared/forms/cd-form-group';
import { CdFormModalFieldConfig } from '~/app/shared/models/cd-form-modal-field-config';
+import { ComboBoxItem } from '~/app/shared/models/combo-box.model';
import { DimlessBinaryPipe } from '~/app/shared/pipes/dimless-binary.pipe';
import { FormatterService } from '~/app/shared/services/formatter.service';
field.setAsyncValidators(validator);
field.updateValueAndValidity();
}
+
+ onLabelsUpdated(field: CdFormModalFieldConfig, updatedItems: ComboBoxItem[]) {
+ const control = this.formGroup.get(field.name);
+ const currentValue: string[] = control?.value || [];
+ // Sync selected state based on current form control value to preserve existing selections
+ const itemsWithSelection: ComboBoxItem[] = updatedItems.map((item: ComboBoxItem) => ({
+ ...item,
+ selected: currentValue.includes(item.content)
+ }));
+ field.typeConfig.options = itemsWithSelection;
+ }
}