Skip to content

Commit 193d7bb

Browse files
committed
feat(ENG-9833): cleanup and delete dead code
1 parent 3eef635 commit 193d7bb

78 files changed

Lines changed: 136 additions & 3564 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/app/features/collections/components/add-to-collection/add-to-collection.component.html

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ <h1 class="collections-heading flex align-items-center">{{ collectionProvider()?
4747
[stepperActiveValue]="stepperActiveValue()"
4848
[targetStepValue]="AddToCollectionSteps.CollectionMetadata"
4949
[isDisabled]="isCollectionMetadataDisabled()"
50-
[primaryCollectionId]="primaryCollectionId()"
51-
[isCedarMode]="isCedarMode()"
5250
[cedarTemplate]="requiredMetadataTemplate()"
5351
[existingCedarRecord]="existingCedarRecord()"
54-
(metadataSaved)="handleCollectionMetadataSaved($event)"
5552
(cedarDataSaved)="handleCedarDataSaved($event)"
5653
(stepChange)="handleChangeStep($event)"
5754
/>

src/app/features/collections/components/add-to-collection/add-to-collection.component.spec.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { MockComponents, MockProvider } from 'ng-mocks';
22

33
import { ComponentFixture, TestBed } from '@angular/core/testing';
4-
import { FormGroup } from '@angular/forms';
54
import { ActivatedRoute, Router } from '@angular/router';
65

76
import { UserSelectors } from '@core/store/user';
@@ -118,15 +117,6 @@ describe('AddToCollectionComponent', () => {
118117
expect(component.projectContributorsSaved()).toBe(true);
119118
});
120119

121-
it('should handle collection metadata saved', () => {
122-
const mockForm = new FormGroup({});
123-
component.handleCollectionMetadataSaved(mockForm);
124-
125-
expect(component.collectionMetadataForm).toBe(mockForm);
126-
expect(component.collectionMetadataSaved()).toBe(true);
127-
expect(component.stepperActiveValue()).toBe(AddToCollectionSteps.Complete);
128-
});
129-
130120
it('should handle cedar data saved', () => {
131121
const mockCedarData: CedarRecordDataBinding = {
132122
data: {} as CedarRecordDataBinding['data'],

src/app/features/collections/components/add-to-collection/add-to-collection.component.ts

Lines changed: 14 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@ import {
2020
signal,
2121
} from '@angular/core';
2222
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
23-
import { FormGroup } from '@angular/forms';
2423
import { ActivatedRoute, Router, RouterLink } from '@angular/router';
2524

26-
import { ENVIRONMENT } from '@core/provider/environment.provider';
2725
import { UserSelectors } from '@core/store/user';
2826
import { CedarMetadataRecordData, CedarRecordDataBinding } from '@osf/features/metadata/models';
2927
import {
@@ -52,7 +50,6 @@ import {
5250
ClearAddToCollectionState,
5351
GetCurrentCollectionSubmission,
5452
RemoveCollectionSubmission,
55-
UpdateCollectionSubmission,
5653
} from '../../store/add-to-collection';
5754

5855
import { AddToCollectionConfirmationDialogComponent } from './add-to-collection-confirmation-dialog/add-to-collection-confirmation-dialog.component';
@@ -90,16 +87,13 @@ export class AddToCollectionComponent implements CanDeactivateComponent {
9087
private readonly headerStyleHelper = inject(HeaderStyleService);
9188
private readonly platformId = inject(PLATFORM_ID);
9289
private readonly isBrowser = isPlatformBrowser(this.platformId);
93-
private readonly environment = inject(ENVIRONMENT);
9490

9591
readonly selectedProjectId = toSignal<string | null>(
9692
this.route.params.pipe(map((params) => params['id'])) ?? of(null)
9793
);
9894

9995
readonly AddToCollectionSteps = AddToCollectionSteps;
10096

101-
collectionMetadataForm = new FormGroup({});
102-
10397
isProviderLoading = select(CollectionsSelectors.getCollectionProviderLoading);
10498
collectionProvider = select(CollectionsSelectors.getCollectionProvider);
10599
requiredMetadataTemplate = select(CollectionsSelectors.getRequiredMetadataTemplate);
@@ -123,7 +117,6 @@ export class AddToCollectionComponent implements CanDeactivateComponent {
123117
isCollectionMetadataDisabled = computed(
124118
() => !this.selectedProject() || !this.projectMetadataSaved() || !this.projectContributorsSaved()
125119
);
126-
isCedarMode = computed(() => this.environment.collectionSubmissionWithCedar && !!this.requiredMetadataTemplate());
127120
existingCedarRecord = computed<CedarMetadataRecordData | null>(() => {
128121
const records = this.cedarRecords();
129122
const templateId = this.requiredMetadataTemplate()?.id;
@@ -134,7 +127,6 @@ export class AddToCollectionComponent implements CanDeactivateComponent {
134127
readonly actions = createDispatchMap({
135128
getCollectionProvider: GetCollectionProvider,
136129
clearAddToCollectionState: ClearAddToCollectionState,
137-
updateCollectionSubmission: UpdateCollectionSubmission,
138130
deleteCollectionSubmission: RemoveCollectionSubmission,
139131
setSelectedProject: SetSelectedProject,
140132
getCurrentCollectionSubmission: GetCurrentCollectionSubmission,
@@ -191,12 +183,6 @@ export class AddToCollectionComponent implements CanDeactivateComponent {
191183
this.projectContributorsSaved.set(true);
192184
}
193185

194-
handleCollectionMetadataSaved(form: FormGroup): void {
195-
this.collectionMetadataForm = form;
196-
this.collectionMetadataSaved.set(true);
197-
this.stepperActiveValue.set(AddToCollectionSteps.Complete);
198-
}
199-
200186
handleCedarDataSaved(data: CedarRecordDataBinding): void {
201187
this.pendingCedarData.set(data);
202188
this.collectionMetadataSaved.set(true);
@@ -207,19 +193,14 @@ export class AddToCollectionComponent implements CanDeactivateComponent {
207193
const payload = {
208194
collectionId: this.primaryCollectionId() || '',
209195
projectId: this.selectedProject()?.id || '',
210-
collectionMetadata: this.isCedarMode() ? {} : this.collectionMetadataForm.value || {},
211196
userId: this.currentUser()?.id || '',
212197
};
213198

214-
const isEditMode = this.isEditMode();
215-
216-
if (isEditMode) {
199+
if (this.isEditMode()) {
217200
this.loaderService.show();
218201

219-
this.actions
220-
.updateCollectionSubmission(payload)
202+
this.saveCedarRecordIfNeeded()
221203
.pipe(
222-
switchMap(() => this.saveCedarRecordIfNeeded()),
223204
finalize(() => this.loaderService.hide()),
224205
takeUntilDestroyed(this.destroyRef)
225206
)
@@ -234,15 +215,17 @@ export class AddToCollectionComponent implements CanDeactivateComponent {
234215
},
235216
});
236217
} else {
237-
this.customDialogService
238-
.open(AddToCollectionConfirmationDialogComponent, {
239-
header: 'collections.addToCollection.confirmationDialogHeader',
240-
width: '500px',
241-
data: { payload, project: this.selectedProject() },
242-
})
243-
.onClose.pipe(
244-
filter((res) => !!res),
245-
switchMap(() => this.saveCedarRecordIfNeeded()),
218+
this.saveCedarRecordIfNeeded()
219+
.pipe(
220+
switchMap(() =>
221+
this.customDialogService
222+
.open(AddToCollectionConfirmationDialogComponent, {
223+
header: 'collections.addToCollection.confirmationDialogHeader',
224+
width: '500px',
225+
data: { payload, project: this.selectedProject() },
226+
})
227+
.onClose.pipe(filter((res) => !!res))
228+
),
246229
takeUntilDestroyed(this.destroyRef)
247230
)
248231
.subscribe({
@@ -294,8 +277,6 @@ export class AddToCollectionComponent implements CanDeactivateComponent {
294277
}
295278

296279
private saveCedarRecordIfNeeded(): Observable<unknown> {
297-
if (!this.isCedarMode()) return of(null);
298-
299280
const cedarData = this.pendingCedarData();
300281
const projectId = this.selectedProject()?.id;
301282
const templateId = this.requiredMetadataTemplate()?.id;
@@ -348,8 +329,7 @@ export class AddToCollectionComponent implements CanDeactivateComponent {
348329

349330
effect(() => {
350331
const projectId = this.selectedProjectId();
351-
const isCedar = this.isCedarMode();
352-
if (isCedar && projectId) {
332+
if (projectId) {
353333
this.actions.getCedarRecords(projectId, ResourceType.Project);
354334
}
355335
});

src/app/features/collections/components/add-to-collection/collection-metadata-step/collection-metadata-step.component.html

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,13 @@
1010
<h3>{{ 'collections.addToCollection.collectionMetadata' | translate }}</h3>
1111

1212
@if (!isDisabled() && stepperActiveValue() !== targetStepValue()) {
13-
@if (collectionMetadataSaved()) {
14-
@if (isCedarMode()) {
15-
@if (cedarTemplate()) {
16-
<cedar-artifact-viewer
17-
#cedarViewer
18-
[config]="cedarViewerConfig"
19-
[templateObject]="cedarTemplate()!.attributes.template"
20-
[instanceObject]="cedarFormData()"
21-
></cedar-artifact-viewer>
22-
}
23-
} @else {
24-
@for (filterEntry of availableFilterEntries(); track filterEntry.key) {
25-
<div>
26-
<p class="font-bold">{{ filterEntry.labelKey | translate }}</p>
27-
28-
<p class="mt-2">
29-
{{ collectionMetadataForm().get(filterEntry.key)?.value }}
30-
</p>
31-
</div>
32-
}
33-
}
13+
@if (collectionMetadataSaved() && cedarTemplate()) {
14+
<cedar-artifact-viewer
15+
#cedarViewer
16+
[config]="cedarViewerConfig"
17+
[templateObject]="cedarTemplate()!.attributes.template"
18+
[instanceObject]="cedarFormData()"
19+
></cedar-artifact-viewer>
3420
}
3521

3622
<p-button
@@ -46,58 +32,28 @@ <h3>{{ 'collections.addToCollection.collectionMetadata' | translate }}</h3>
4632

4733
<p-step-panel [value]="targetStepValue()" class="p-0">
4834
<ng-template class="m-0" #content let-activateCallback="activateCallback">
49-
@if (isCedarMode()) {
50-
@if (cedarTemplate()) {
51-
<div class="cedar-editor-container mt-3">
52-
<cedar-embeddable-editor
53-
#cedarEditor
54-
[config]="cedarConfig"
55-
[templateObject]="cedarTemplate()!.attributes.template"
56-
[metadata]="cedarFormData()"
57-
(change)="onCedarChange($event)"
58-
(keyup)="onCedarChange($event)"
59-
></cedar-embeddable-editor>
60-
</div>
61-
62-
<div class="flex justify-content-end gap-3 mt-4">
63-
<p-button
64-
severity="info"
65-
[label]="'common.buttons.discardChanges' | translate"
66-
(onClick)="handleDiscardChanges()"
67-
/>
68-
<p-button [label]="'common.buttons.saveAndContinue' | translate" (onClick)="handleSaveCedarMetadata()" />
69-
</div>
70-
} @else {
71-
<p class="mt-3">{{ 'collections.addToCollection.cedarFormNotAvailable' | translate }}</p>
72-
}
73-
} @else {
74-
<form [formGroup]="collectionMetadataForm()" class="grid row-gap-2 mt-3">
75-
@for (filterEntry of availableFilterEntries(); track filterEntry.key) {
76-
<div class="flex flex-column gap-1 col-12 md:col-6">
77-
<label [for]="filterEntry.key">{{ filterEntry.labelKey | translate }}</label>
78-
<p-select
79-
[id]="filterEntry.key"
80-
[options]="filterEntry.options"
81-
[formControlName]="filterEntry.key"
82-
[placeholder]="filterEntry.labelKey | translate"
83-
appendTo="body"
84-
></p-select>
85-
</div>
86-
}
87-
</form>
35+
@if (cedarTemplate()) {
36+
<div class="cedar-editor-container mt-3">
37+
<cedar-embeddable-editor
38+
#cedarEditor
39+
[config]="cedarConfig"
40+
[templateObject]="cedarTemplate()!.attributes.template"
41+
[metadata]="cedarFormData()"
42+
(change)="onCedarChange($event)"
43+
(keyup)="onCedarChange($event)"
44+
></cedar-embeddable-editor>
45+
</div>
8846

8947
<div class="flex justify-content-end gap-3 mt-4">
9048
<p-button
9149
severity="info"
9250
[label]="'common.buttons.discardChanges' | translate"
9351
(onClick)="handleDiscardChanges()"
9452
/>
95-
<p-button
96-
[label]="'common.buttons.saveAndContinue' | translate"
97-
[disabled]="!collectionMetadataForm().valid"
98-
(onClick)="handleSaveMetadata()"
99-
/>
53+
<p-button [label]="'common.buttons.saveAndContinue' | translate" (onClick)="handleSaveCedarMetadata()" />
10054
</div>
55+
} @else {
56+
<p class="mt-3">{{ 'collections.addToCollection.cedarFormNotAvailable' | translate }}</p>
10157
}
10258
</ng-template>
10359
</p-step-panel>

0 commit comments

Comments
 (0)