Skip to content

Commit

Permalink
fix: tweak bulk upload to remember select field mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
MrYuion committed Jan 21, 2025
1 parent 354477a commit 6b69731
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ export interface BulkItemModalData<T = HashMap<any>> {
<bulk-item-match-fields
[list]="data_list"
[field_list]="available_fields"
[mappings]="mappings"
(new_mappings)="mappings = $event"
(mapping_done)="handleList($event, true)"
(previous)="flow_step = ''"
></bulk-item-match-fields>
Expand Down Expand Up @@ -113,6 +115,7 @@ export class BulkItemModalComponent<T = HashMap<any>> {
public loading: boolean;
/** Template data for use */
public template: HashMap[] = [];
public mappings: Record<string, string> = {};

public available_fields: Identity[] = [];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import {
SimpleChanges,
EventEmitter,
Output,
OnChanges,
OnInit,
} from '@angular/core';

import { HashMap, Identity } from 'apps/backoffice/src/app/common/types';
Expand Down Expand Up @@ -51,23 +53,35 @@ import { HashMap, Identity } from 'apps/backoffice/src/app/common/types';
`,
styles: [``],
})
export class MatchFieldsComponent {
export class MatchFieldsComponent implements OnChanges, OnInit {
/** List of bulk items to add */
@Input() public list: HashMap<any>[];
/** List of fields available for building new item */
@Input() public field_list: Identity[] = [];
/** User selected mappings for field mappings */
@Input() public mappings: Record<string, string> = {};
/** Emitter for mapped changes to list */
@Output() public mapping_done = new EventEmitter<HashMap<any>[]>();
/** Emitter user want to return to previous step in flow */
@Output() public previous = new EventEmitter<void>();
/** Emitter for changes to user selected field mappings */
@Output() public new_mappings = new EventEmitter<Record<string, string>>();
/** List of fields available to be selected */
public source_fields: Identity[] = [];
/** Mapping of raw data fields ids to item fields ids */
public field_mapping: HashMap<string> = {};

public ngOnInit() {
if (this.mappings) {
this.field_mapping = {
...this.field_mapping,
...this.mappings,
};
}
}

public ngOnChanges(changes: SimpleChanges) {
if (changes.list && this.list && this.list.length) {
console.log('List:', this.list);
this.source_fields = Object.keys(this.list[0]).map((i) => ({
id: i.toLowerCase().split(' ').join('_'),
name: i.split('_').join(' '),
Expand All @@ -77,6 +91,15 @@ export class MatchFieldsComponent {
this.field_mapping[`${field.id}`] = `${field.id}`;
}
});
if (this.mappings) {
this.field_mapping = {
...this.field_mapping,
...this.mappings,
};
}
}
if (changes.mappings && this.mappings) {
this.field_mapping = { ...this.field_mapping, ...this.mappings };
}
}

Expand All @@ -90,6 +113,8 @@ export class MatchFieldsComponent {
}
return mapped_item;
});
this.mappings = { ...this.field_mapping };
this.new_mappings.emit(this.mappings);
this.mapping_done.emit(mapped_list);
}
}

0 comments on commit 6b69731

Please sign in to comment.