Skip to content

Commit a89e735

Browse files
authored
Fix/overview (#349)
* fix(add): updated add project and component dialog * fix(move-file): updated button * fix(overview): updated project overview
1 parent 760e324 commit a89e735

18 files changed

+166
-224
lines changed

src/app/core/constants/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@ export * from './error-messages';
22
export * from './nav-items.constant';
33
export * from './ngxs-states.constant';
44
export * from './social-icons.constant';
5-
export * from './storage-locations.constant';

src/app/core/constants/storage-locations.constant.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/app/features/files/components/move-file-dialog/move-file-dialog.component.html

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,14 @@ <h2 class="font-normal">{{ storageName }}</h2>
3737
{{ file?.name ?? '' }}
3838
</div>
3939
} @else {
40-
<osf-icon iconClass="fas fa-folder"></osf-icon>
41-
42-
<div
43-
class="filename-link overflow-ellipsis"
44-
tabindex="0"
40+
<p-button
41+
class="filename-link link-btn-no-padding overflow-ellipsis font-normal"
42+
icon="fas fa-folder"
43+
severity="secondary"
44+
[link]="true"
45+
[label]="file?.name ?? ''"
4546
(click)="openFolder(file)"
46-
(keydown.enter)="openFolder(file)"
47-
>
48-
{{ file?.name ?? '' }}
49-
</div>
47+
/>
5048
}
5149
</div>
5250
</div>
@@ -69,11 +67,11 @@ <h3 class="font-normal text-no-transform">{{ 'files.emptyState' | translate }}</
6967
}
7068

7169
<div class="flex justify-content-end gap-2 mt-4">
72-
<p-button (click)="dialogRef.close()" severity="info" [label]="'common.buttons.cancel' | translate"></p-button>
70+
<p-button severity="info" [label]="'common.buttons.cancel' | translate" (onClick)="dialogRef.close()"></p-button>
7371

7472
<p-button
7573
[disabled]="isFolderSame() || isLoading() || isFilesUpdating()"
7674
[label]="(config.data.action === 'move' ? 'common.buttons.move' : 'common.buttons.copy') | translate"
77-
(click)="moveFile()"
75+
(onClick)="moveFile()"
7876
></p-button>
7977
</div>

src/app/features/files/components/move-file-dialog/move-file-dialog.component.scss

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@use "styles/variables" as var;
21
@use "styles/mixins" as mix;
32

43
:host {
@@ -7,12 +6,12 @@
76
}
87

98
.files-table {
10-
border: 1px solid var.$grey-2;
9+
border: 1px solid var(--grey-2);
1110
border-radius: mix.rem(8px);
1211

1312
&-row {
14-
border-bottom: 1px solid var.$grey-2;
15-
color: var.$dark-blue-1;
13+
border-bottom: 1px solid var(--grey-2);
14+
color: var(--dark-blue-1);
1615
}
1716

1817
&-row:last-child {
@@ -26,7 +25,7 @@
2625
cursor: pointer;
2726

2827
&.disabled {
29-
color: var.$grey-1;
28+
color: var(--grey-1);
3029
cursor: not-allowed;
3130
}
3231

@@ -35,6 +34,12 @@
3534
}
3635
}
3736

37+
.link-btn-no-padding {
38+
--p-button-label-font-weight: 400;
39+
--p-button-link-hover-color: var(--dark-blue-1);
40+
--p-button-link-color: var(--dark-blue-1);
41+
}
42+
3843
.disabled-icon {
39-
color: var.$grey-1;
44+
color: var(--grey-1);
4045
}

src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.html

Lines changed: 29 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,16 @@
77
</div>
88

99
@if (currentProject()?.affiliatedInstitutions?.length) {
10-
<div class="flex flex-column gap-2">
11-
<div class="relative">
12-
<h3 class="font-normal affiliation-label mb-2">
13-
{{ 'project.overview.dialog.addComponent.affiliation.title' | translate }}
14-
</h3>
15-
<div class="flex gap-4 absolute top-0 right-0">
16-
<p-button
17-
class="secondary-transparent"
18-
severity="secondary"
19-
[label]="'project.overview.dialog.addComponent.affiliation.selectAll' | translate"
20-
(click)="selectAllAffiliations()"
21-
(keydown.enter)="selectAllAffiliations()"
22-
>
23-
</p-button>
24-
<p-button
25-
class="secondary-transparent"
26-
severity="secondary"
27-
[label]="'project.overview.dialog.addComponent.affiliation.removeAll' | translate"
28-
(click)="removeAllAffiliations()"
29-
(keydown.enter)="removeAllAffiliations()"
30-
>
31-
</p-button>
32-
</div>
33-
</div>
10+
<div>
11+
<h3 class="font-normal mb-2">
12+
{{ 'myProjects.createProject.affiliation.title' | translate }}
13+
</h3>
3414

35-
<div class="flex gap-2" role="group" aria-label="Affiliations">
36-
@for (affiliation of currentProject()?.affiliatedInstitutions; track affiliation.id) {
37-
<div class="flex align-items-center relative gap-2">
38-
<p-checkbox
39-
class="absolute top-0 affiliation-checkbox"
40-
[value]="affiliation.id"
41-
[formControlName]="ComponentFormControls.Affiliations"
42-
[inputId]="affiliation.id"
43-
[name]="'affiliations'"
44-
/>
45-
<img class="fit-contain" [ngSrc]="affiliation.assets.logo" alt="Institution Logo" height="44" width="44" />
46-
</div>
47-
}
48-
</div>
15+
<osf-affiliated-institution-select
16+
[institutions]="currentProject()?.affiliatedInstitutions || []"
17+
[selectedInstitutions]="currentProject()?.affiliatedInstitutions || []"
18+
(selectedInstitutionsChange)="setSelectedInstitutions($event)"
19+
/>
4920
</div>
5021
}
5122

@@ -55,42 +26,35 @@ <h3 class="font-normal affiliation-label mb-2">
5526
</label>
5627
<p-select
5728
id="storage-location"
58-
[options]="storageLocations"
29+
optionLabel="name"
30+
optionValue="id"
31+
[options]="storageLocations()"
32+
[loading]="areRegionsLoading()"
5933
[formControlName]="ComponentFormControls.StorageLocation"
6034
></p-select>
6135
</div>
6236

63-
<div
64-
class="cursor-pointer flex align-items-start gap-2"
65-
(click)="toggleAddContributors()"
66-
(keydown.enter)="toggleAddContributors()"
67-
tabindex="0"
68-
role="checkbox"
69-
[attr.aria-checked]="componentForm.get(ComponentFormControls.AddContributors)?.value"
70-
>
71-
<p-checkbox [formControlName]="ComponentFormControls.AddContributors" [binary]="true"></p-checkbox>
37+
<div class="flex align-items-start gap-2">
38+
<p-checkbox
39+
inputId="add-contributors"
40+
[formControlName]="ComponentFormControls.AddContributors"
41+
[binary]="true"
42+
></p-checkbox>
7243
<div>
73-
<p>
44+
<label for="add-contributors" class="cursor-pointer m-0">
7445
{{ ('project.overview.dialog.addComponent.addContributors' | translate) + ' ' + currentProject()?.title }}
75-
</p>
76-
<small>{{
77-
currentProject()?.title + ' ' + ('project.overview.dialog.addComponent.contributorsMessage' | translate)
78-
}}</small>
46+
</label>
47+
<small>
48+
{{ currentProject()?.title + ' ' + ('project.overview.dialog.addComponent.contributorsMessage' | translate) }}
49+
</small>
7950
</div>
8051
</div>
8152

82-
<div
83-
class="cursor-pointer flex align-items-start gap-2"
84-
(click)="toggleAddTags()"
85-
(keydown.enter)="toggleAddTags()"
86-
tabindex="0"
87-
role="checkbox"
88-
[attr.aria-checked]="componentForm.get(ComponentFormControls.AddTags)?.value"
89-
>
90-
<p-checkbox [formControlName]="ComponentFormControls.AddTags" [binary]="true"></p-checkbox>
91-
<p>
53+
<div class="flex align-items-center gap-2">
54+
<p-checkbox inputId="add-tags" [formControlName]="ComponentFormControls.AddTags" [binary]="true"></p-checkbox>
55+
<label for="add-tags" class="cursor-pointer m-0">
9256
{{ ('project.overview.dialog.addComponent.addTags' | translate) + ' ' + currentProject()?.title }}
93-
</p>
57+
</label>
9458
</div>
9559

9660
<div class="flex flex-column">
@@ -117,7 +81,7 @@ <h3 class="font-normal affiliation-label mb-2">
11781
class="w-12rem btn-full-width"
11882
[label]="'project.overview.dialog.addComponent.cancelButton' | translate"
11983
severity="info"
120-
(click)="dialogRef.close()"
84+
(onClick)="dialogRef.close()"
12185
[disabled]="isSubmitting()"
12286
/>
12387
<p-button

src/app/features/project/overview/components/add-component-dialog/add-component-dialog.component.ts

Lines changed: 51 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,69 @@
1-
import { select, Store } from '@ngxs/store';
1+
import { createDispatchMap, select } from '@ngxs/store';
22

33
import { TranslatePipe } from '@ngx-translate/core';
44

5-
import { ButtonModule } from 'primeng/button';
6-
import { CheckboxModule } from 'primeng/checkbox';
7-
import { DropdownModule } from 'primeng/dropdown';
5+
import { Button } from 'primeng/button';
6+
import { Checkbox } from 'primeng/checkbox';
87
import { DynamicDialogRef } from 'primeng/dynamicdialog';
9-
import { InputTextModule } from 'primeng/inputtext';
8+
import { InputText } from 'primeng/inputtext';
109
import { Select } from 'primeng/select';
1110
import { Textarea } from 'primeng/textarea';
1211

13-
import { CommonModule, NgOptimizedImage } from '@angular/common';
14-
import { ChangeDetectionStrategy, Component, DestroyRef, inject, OnInit } from '@angular/core';
15-
import { takeUntilDestroyed, toSignal } from '@angular/core/rxjs-interop';
12+
import { ChangeDetectionStrategy, Component, DestroyRef, effect, inject, OnInit } from '@angular/core';
13+
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
1614
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
1715

18-
import { STORAGE_LOCATIONS } from '@core/constants';
16+
import { UserSelectors } from '@core/store/user';
17+
import { AffiliatedInstitutionSelectComponent } from '@osf/shared/components';
1918
import { ComponentFormControls } from '@osf/shared/enums';
20-
import { IS_XSMALL } from '@osf/shared/helpers';
21-
import { ComponentForm } from '@osf/shared/models';
19+
import { CustomValidators } from '@osf/shared/helpers';
20+
import { ComponentForm, Institution } from '@osf/shared/models';
2221
import { ToastService } from '@osf/shared/services';
22+
import { FetchRegions, RegionsSelectors } from '@osf/shared/stores';
2323

2424
import { CreateComponent, GetComponents, ProjectOverviewSelectors } from '../../store';
2525

2626
@Component({
2727
selector: 'osf-add-component-dialog',
2828
imports: [
29-
CommonModule,
3029
ReactiveFormsModule,
31-
ButtonModule,
32-
InputTextModule,
33-
DropdownModule,
34-
CheckboxModule,
30+
Button,
31+
InputText,
32+
Checkbox,
3533
Select,
3634
Textarea,
37-
NgOptimizedImage,
3835
TranslatePipe,
36+
AffiliatedInstitutionSelectComponent,
3937
],
4038
templateUrl: './add-component-dialog.component.html',
4139
styleUrl: './add-component-dialog.component.scss',
4240
changeDetection: ChangeDetectionStrategy.OnPush,
4341
})
4442
export class AddComponentDialogComponent implements OnInit {
45-
private store = inject(Store);
4643
private readonly toastService = inject(ToastService);
4744

48-
isMobile = toSignal(inject(IS_XSMALL));
4945
dialogRef = inject(DynamicDialogRef);
5046
destroyRef = inject(DestroyRef);
5147
ComponentFormControls = ComponentFormControls;
52-
storageLocations = STORAGE_LOCATIONS;
53-
isSubmitting = select(ProjectOverviewSelectors.getComponentsSubmitting);
54-
currentProject = this.store.selectSignal(ProjectOverviewSelectors.getProject);
5548

56-
toggleAddContributors(): void {
57-
const control = this.componentForm.get(ComponentFormControls.AddContributors);
58-
if (control) {
59-
control.setValue(!control.value);
60-
}
61-
}
49+
storageLocations = select(RegionsSelectors.getRegions);
50+
currentUser = select(UserSelectors.getCurrentUser);
51+
currentProject = select(ProjectOverviewSelectors.getProject);
52+
areRegionsLoading = select(RegionsSelectors.areRegionsLoading);
53+
isSubmitting = select(ProjectOverviewSelectors.getComponentsSubmitting);
6254

63-
toggleAddTags(): void {
64-
const control = this.componentForm.get(ComponentFormControls.AddTags);
65-
if (control) {
66-
control.setValue(!control.value);
67-
}
68-
}
55+
actions = createDispatchMap({
56+
createComponent: CreateComponent,
57+
getComponents: GetComponents,
58+
getRegions: FetchRegions,
59+
});
6960

7061
componentForm = new FormGroup<ComponentForm>({
7162
[ComponentFormControls.Title]: new FormControl('', {
7263
nonNullable: true,
73-
validators: [Validators.required],
64+
validators: [CustomValidators.requiredTrimmed()],
7465
}),
75-
[ComponentFormControls.StorageLocation]: new FormControl('us', {
66+
[ComponentFormControls.StorageLocation]: new FormControl('', {
7667
nonNullable: true,
7768
validators: [Validators.required],
7869
}),
@@ -90,21 +81,27 @@ export class AddComponentDialogComponent implements OnInit {
9081
}),
9182
});
9283

93-
ngOnInit(): void {
94-
this.selectAllAffiliations();
84+
constructor() {
85+
effect(() => {
86+
const storageLocations = this.storageLocations();
87+
if (!storageLocations) return;
88+
89+
const defaultRegion = this.currentUser()?.defaultRegionId || storageLocations[0].id;
90+
this.componentForm.controls[ComponentFormControls.StorageLocation].setValue(defaultRegion);
91+
});
9592
}
9693

97-
selectAllAffiliations(): void {
98-
const allAffiliationValues = this.currentProject()?.affiliatedInstitutions?.map((aff) => aff.id) || [];
99-
this.componentForm.get(ComponentFormControls.Affiliations)?.setValue(allAffiliationValues);
94+
ngOnInit(): void {
95+
this.actions.getRegions();
10096
}
10197

102-
removeAllAffiliations(): void {
103-
this.componentForm.get(ComponentFormControls.Affiliations)?.setValue([]);
98+
setSelectedInstitutions(institutions: Institution[]) {
99+
const selectedValues = institutions.map((inst) => inst.id);
100+
this.componentForm.get(ComponentFormControls.Affiliations)?.setValue(selectedValues);
104101
}
105102

106103
submitForm(): void {
107-
if (!this.componentForm.valid) {
104+
if (this.componentForm.invalid) {
108105
this.componentForm.markAllAsTouched();
109106
return;
110107
}
@@ -118,23 +115,21 @@ export class AddComponentDialogComponent implements OnInit {
118115

119116
const tags = formValue.addTags ? project.tags : [];
120117

121-
this.store
122-
.dispatch(
123-
new CreateComponent(
124-
project.id,
125-
formValue.title,
126-
formValue.description,
127-
tags,
128-
formValue.storageLocation,
129-
formValue.affiliations,
130-
formValue.addContributors
131-
)
118+
this.actions
119+
.createComponent(
120+
project.id,
121+
formValue.title,
122+
formValue.description,
123+
tags,
124+
formValue.storageLocation,
125+
formValue.affiliations,
126+
formValue.addContributors
132127
)
133128
.pipe(takeUntilDestroyed(this.destroyRef))
134129
.subscribe({
135130
next: () => {
136131
this.dialogRef.close();
137-
this.store.dispatch(new GetComponents(project.id));
132+
this.actions.getComponents(project.id);
138133
this.toastService.showSuccess('project.overview.dialog.toast.addComponent.success');
139134
},
140135
});

0 commit comments

Comments
 (0)