src/app/core/import/update-existing/import-match-existing/import-match-existing.component.ts

Description

Allow the user to configure entity fields that are used to match imported data to existing entities in the DB.

Example

Metadata

Relationships

Used by

Depends on

import {
  Component,
  input,
  model,
  ChangeDetectionStrategy,
} from "@angular/core";
import { MatExpansionModule } from "@angular/material/expansion";
import { MatFormField, MatHint, MatLabel } from "@angular/material/form-field";
import { EntityFieldSelectComponent } from "../../../entity/entity-field-select/entity-field-select.component";
import { HelpButtonComponent } from "../../../common-components/help-button/help-button.component";
import { MatSlideToggle } from "@angular/material/slide-toggle";
import { FormsModule } from "@angular/forms";
import { ImportExistingSettings } from "../../import-metadata";

/**
 * Allow the user to configure entity fields that are used to match imported data to existing entities in the DB.
 */
@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  selector: "app-import-match-existing",
  standalone: true,
  imports: [
    MatExpansionModule,
    MatFormField,
    MatLabel,
    MatHint,
    EntityFieldSelectComponent,
    HelpButtonComponent,
    MatSlideToggle,
    FormsModule,
  ],
  templateUrl: "./import-match-existing.component.html",
  styleUrl: "./import-match-existing.component.scss",
})
export class ImportMatchExistingComponent {
  entityType = input<string>();
  settings = model<ImportExistingSettings | undefined>();

  updateMatchFields(newValue: string[] | string) {
    const fields = newValue as string[]; // component is set to multi=true, so this is always an array
    if (!fields?.length) {
      this.settings.set(undefined);
      return;
    }

    this.settings.update((s) => ({
      ...(s ?? {}),
      matchExistingByFields: fields,
    }));
  }

  updateStrictMatching(value: boolean) {
    this.settings.update((s) => ({
      ...(s ?? {}),
      strictMatching: value,
    }));
  }
}
<mat-expansion-panel [disabled]="!entityType()">
  <mat-expansion-panel-header>
    <mat-panel-title>
      <span i18n>Check/Update existing instead of creating new records</span>
      <app-help-button
        style="float: right"
        text="You can configure the system to match your imported data with existing records in the system.
        If a match is found based on the fields you select here, the system will offer update the existing record instead of creating a new one."
        i18n-text="import - match existing - help text"
      >
      </app-help-button>
    </mat-panel-title>
  </mat-expansion-panel-header>

  <mat-form-field class="full-width">
    <mat-label i18n>Fields that identify a unique record</mat-label>
    <app-entity-field-select
      [multi]="true"
      [entityType]="entityType()"
      [value]="settings()?.matchExistingByFields"
      (valueChange)="updateMatchFields($event)"
      [showInternalIdField]="true"
    ></app-entity-field-select>
    <mat-hint i18n
      >All selected fields have to be equal in an existing record and your
      imported column to match.
    </mat-hint>
  </mat-form-field>

  <div class="flex-row gap-regular align-center">
    <mat-slide-toggle
      [ngModel]="settings()?.strictMatching"
      (ngModelChange)="updateStrictMatching($event)"
      i18n
      >Strict matching</mat-slide-toggle
    >
    <app-help-button
      text="enable this to use case-sensitive, exact comparisons only"
      i18n-text="import - strict matching - help text"
    ></app-help-button>
  </div>
</mat-expansion-panel>

./import-match-existing.component.scss

Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""