Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export class CollectionMetadataStepComponent {

collectionMetadataForm = signal<FormGroup>(new FormGroup({}));
collectionMetadataSaved = signal<boolean>(false);
originalFormValues = signal<Record<string, unknown>>({});

actions = createDispatchMap({
getCollectionDetails: GetCollectionDetails,
Expand All @@ -62,13 +63,23 @@ export class CollectionMetadataStepComponent {
}

handleDiscardChanges() {
this.collectionMetadataForm().reset();
const form = this.collectionMetadataForm();
const originalValues = this.originalFormValues();

if (this.hasFormChanges(form, originalValues)) {
this.restoreFormValues(form, originalValues);
}

this.collectionMetadataSaved.set(false);
}

handleSaveMetadata() {
const form = this.collectionMetadataForm();

this.updateOriginalValues(form);

this.collectionMetadataSaved.set(true);
this.metadataSaved.emit(this.collectionMetadataForm());
this.metadataSaved.emit(form);
this.stepChange.emit(AddToCollectionSteps.Complete);
}

Expand All @@ -82,6 +93,7 @@ export class CollectionMetadataStepComponent {

const newForm = new FormGroup(formControls);
this.collectionMetadataForm.set(newForm);
this.updateOriginalValues(newForm);
}

private setupEffects(): void {
Expand All @@ -105,4 +117,26 @@ export class CollectionMetadataStepComponent {
}
});
}

private hasFormChanges(form: FormGroup, originalValues: Record<string, unknown>): boolean {
return Object.keys(originalValues).some((key) => {
const currentValue = form.get(key)?.value;
const originalValue = originalValues[key];
return currentValue !== originalValue;
});
}

private restoreFormValues(form: FormGroup, originalValues: Record<string, unknown>): void {
Object.keys(originalValues).forEach((key) => {
form.get(key)?.setValue(originalValues[key]);
});
}

private updateOriginalValues(form: FormGroup): void {
const currentValues: Record<string, unknown> = {};
Object.keys(form.controls).forEach((key) => {
currentValues[key] = form.get(key)?.value;
});
this.originalFormValues.set(currentValues);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ <h2>{{ 'project.overview.metadata.contributors' | translate }}</h2>
</div>

@if (contributors()) {
<div class="inline-flex gap-1 line-height-2 mt-4">
<div class="inline-flex flex-wrap gap-1 line-height-2 mt-4">
@for (contributor of contributors(); track contributor.id) {
<div>
<a class="font-bold" [routerLink]="['/user', contributor.userId]"> {{ contributor.fullName }}</a>
Expand Down
Loading