Skip to content

Commit 503652d

Browse files
authored
Fix - Institution dashboard bugs (#403)
* fix(global-search): Fixed correct order of index-card * fix(institution-dashboard): Showing contributors sorted by permissions * fix(institution-dashboard): Showing contributors sorted by permissions * fix(moderators-search): Fixed searching moderators
1 parent ad51418 commit 503652d

26 files changed

+198
-124
lines changed

src/app/features/admin-institutions/components/admin-table/admin-table.component.html

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -110,37 +110,57 @@
110110
@for (col of columns; track col.field) {
111111
<td class="relative">
112112
<div class="flex align-items-center hover-group">
113-
@if (col.isLink && isLink(rowData[col.field])) {
113+
@let currentColumnField = rowData[col.field];
114+
@if (col.isLink && isLink(currentColumnField)) {
114115
<a
115-
[href]="getLinkUrl(rowData[col.field])"
116-
[target]="getLinkTarget(rowData[col.field], col)"
116+
[href]="currentColumnField.url"
117+
[target]="col.linkTarget ?? '_self'"
117118
class="font-bold no-underline hover:underline"
118119
>
119120
@if (col.dateFormat) {
120-
{{ getCellValue(rowData[col.field]) | date: col.dateFormat }}
121+
{{ getCellValue(currentColumnField) | date: col.dateFormat }}
121122
} @else {
122-
{{ getCellValue(rowData[col.field]) }}
123+
{{ getCellValue(currentColumnField) }}
123124
}
124125
</a>
126+
} @else if (col.isLink && col.isArray && isLinkArray(currentColumnField)) {
127+
<div class="flex gap-1 align-items-center">
128+
@for (link of currentColumnField; track $index) {
129+
<a [href]="link.url" [target]="col.linkTarget ?? '_self'" class="font-bold">
130+
{{ link.text }}<span>{{ $last ? '' : ',' }}</span>
131+
</a>
132+
@if (col.showIcon) {
133+
<p-button
134+
[pTooltip]="col.iconTooltip | translate"
135+
class="icon-button"
136+
[icon]="col.iconClass"
137+
variant="text"
138+
severity="info"
139+
[ariaLabel]="'common.accessibility.tooltipBtn' | translate"
140+
(onClick)="onIconClick(rowData, col, $index)"
141+
/>
142+
}
143+
}
144+
</div>
125145
} @else {
126-
@if (col.dateFormat && rowData[col.field]) {
127-
{{ getCellValue(rowData[col.field]) | date: col.dateFormat }}
128-
} @else if (!col.dateFormat && rowData[col.field]) {
129-
{{ getCellValue(rowData[col.field]) }}
146+
@if (col.dateFormat && currentColumnField) {
147+
{{ getCellValue(currentColumnField) | date: col.dateFormat }}
148+
} @else if (!col.dateFormat && currentColumnField) {
149+
{{ getCellValue(currentColumnField) }}
130150
} @else {
131-
{{ rowData[col.field] ?? '-' }}
151+
{{ currentColumnField ?? '-' }}
132152
}
133153
}
134154

135-
@if (col.showIcon) {
155+
@if (col.showIcon && !col.isArray) {
136156
<p-button
137157
[pTooltip]="col.iconTooltip | translate"
138-
class="icon-button pl-3"
158+
class="icon-button"
139159
[icon]="col.iconClass"
140160
variant="text"
141161
severity="info"
142162
[ariaLabel]="'common.accessibility.tooltipBtn' | translate"
143-
(onClick)="onIconClick(rowData, col)"
163+
(onClick)="onIconClick(rowData, col, $index)"
144164
/>
145165
}
146166
</div>

src/app/features/admin-institutions/components/admin-table/admin-table.component.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,11 @@ export class AdminTableComponent {
121121
}
122122
}
123123

124-
onIconClick(rowData: TableCellData, column: TableColumn): void {
124+
onIconClick(rowData: TableCellData, column: TableColumn, arrayIndex?: number): void {
125125
if (column.iconAction) {
126126
this.iconClicked.emit({
127127
rowData,
128+
arrayIndex,
128129
column,
129130
action: column.iconAction,
130131
});
@@ -135,6 +136,10 @@ export class AdminTableComponent {
135136
return value !== null && value !== undefined && typeof value === 'object' && 'text' in value && 'url' in value;
136137
}
137138

139+
isLinkArray(value: unknown): value is TableCellLink[] {
140+
return Array.isArray(value) && value.every((v) => v && typeof v === 'object' && 'url' in v);
141+
}
142+
138143
getCellValue(value: string | number | TableCellLink | undefined): string {
139144
if (this.isLink(value)) {
140145
return this.translateService.instant(value.text);
@@ -152,11 +157,4 @@ export class AdminTableComponent {
152157
}
153158
return '';
154159
}
155-
156-
getLinkTarget(value: string | number | TableCellLink | undefined, column: TableColumn): string {
157-
if (this.isLink(value)) {
158-
return value.target || column.linkTarget || '_self';
159-
}
160-
return column.linkTarget || '_self';
161-
}
162160
}

src/app/features/admin-institutions/constants/preprints-table-columns.constant.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ export const preprintsTableColumns: TableColumn[] = [
3636
header: 'adminInstitutions.projects.license',
3737
},
3838
{
39-
field: 'contributorName',
39+
field: 'creator',
4040
header: 'adminInstitutions.projects.contributorName',
4141
isLink: true,
42+
isArray: true,
4243
linkTarget: '_blank',
4344
},
4445
{

src/app/features/admin-institutions/constants/project-table-columns.constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export const projectTableColumns: TableColumn[] = [
4646
header: 'adminInstitutions.projects.contributorName',
4747
isLink: true,
4848
linkTarget: '_blank',
49+
isArray: true,
4950
showIcon: true,
5051
iconClass: 'fa-solid fa-comment text-primary',
5152
iconTooltip: 'adminInstitutions.institutionUsers.sendMessage',

src/app/features/admin-institutions/constants/registration-table-columns.constant.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ export const registrationTableColumns: TableColumn[] = [
4242
sortField: 'storageByteCount',
4343
},
4444
{
45-
field: 'contributorName',
45+
field: 'creator',
4646
header: 'adminInstitutions.projects.contributorName',
4747
isLink: true,
48+
isArray: true,
4849
linkTarget: '_blank',
4950
},
5051
{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { getSortedContributorsByPermissions } from '@shared/helpers';
2+
import { ResourceModel } from '@shared/models';
3+
4+
export function mapCreators(project: ResourceModel, currentInstitutionId: string) {
5+
const creatorsRoles = project.qualifiedAttribution.map((qa) => {
6+
let role;
7+
if (qa.hadRole.includes('admin')) {
8+
role = 'Administrator';
9+
} else if (qa.hadRole.includes('write')) {
10+
role = 'Read + Write';
11+
} else {
12+
role = 'Read';
13+
}
14+
return {
15+
id: qa.agentId,
16+
role,
17+
};
18+
});
19+
20+
return getSortedContributorsByPermissions(project)
21+
?.filter((creator) => creator.affiliationAbsoluteUrl === currentInstitutionId)
22+
?.map((creator) => {
23+
const name = creator.name.trim();
24+
const role = creatorsRoles.find((cr) => cr.id === creator.absoluteUrl)!.role;
25+
return {
26+
text: `${name} (${role})`,
27+
url: creator.absoluteUrl,
28+
};
29+
});
30+
}

src/app/features/admin-institutions/mappers/institution-preprint-to-table-data.mapper.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
import { ResourceModel } from '@shared/models';
22

33
import { extractPathAfterDomain } from '../helpers';
4-
import { TableCellData, TableCellLink } from '../models';
4+
import { TableCellData } from '../models';
55

6-
export function mapPreprintResourceToTableData(preprint: ResourceModel): TableCellData {
6+
import { mapCreators } from './creators.mapper';
7+
8+
export function mapPreprintResourceToTableData(preprint: ResourceModel, currentInstitutionId: string): TableCellData {
79
return {
810
title: preprint.title,
911
link: {
1012
text: preprint.absoluteUrl.split('/').pop() || preprint.absoluteUrl,
1113
url: preprint.absoluteUrl,
12-
target: '_blank',
13-
} as TableCellLink,
14+
},
1415
dateCreated: preprint.dateCreated,
1516
dateModified: preprint.dateModified,
1617
doi: preprint.doi[0]
17-
? ({
18+
? {
1819
text: extractPathAfterDomain(preprint.doi[0]),
1920
url: preprint.doi[0],
20-
} as TableCellLink)
21+
}
2122
: '-',
2223
license: preprint.license?.name || '-',
23-
contributorName: preprint.creators[0]
24-
? ({
25-
text: preprint.creators[0].name,
26-
url: preprint.creators[0].absoluteUrl,
27-
target: '_blank',
28-
} as TableCellLink)
29-
: '-',
24+
creator: mapCreators(preprint, currentInstitutionId),
3025
viewsLast30Days: preprint.viewsCount || '-',
3126
downloadsLast30Days: preprint.downloadCount || '-',
3227
};

src/app/features/admin-institutions/mappers/institution-project-to-table-data.mapper.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,28 @@
11
import { ResourceModel } from '@shared/models';
22

33
import { extractPathAfterDomain } from '../helpers';
4-
import { TableCellData, TableCellLink } from '../models';
4+
import { TableCellData } from '../models';
55

6-
export function mapProjectResourceToTableCellData(project: ResourceModel): TableCellData {
6+
import { mapCreators } from './creators.mapper';
7+
8+
export function mapProjectResourceToTableCellData(project: ResourceModel, currentInstitutionId: string): TableCellData {
79
return {
810
title: project.title,
911
link: {
1012
url: project.absoluteUrl,
1113
text: project.absoluteUrl.split('/').pop() || project.absoluteUrl,
12-
} as TableCellLink,
14+
},
1315
dateCreated: project.dateCreated!,
1416
dateModified: project.dateModified!,
1517
doi: project.doi[0]
16-
? ({
18+
? {
1719
text: extractPathAfterDomain(project.doi[0]),
1820
url: project.doi[0],
19-
} as TableCellLink)
21+
}
2022
: '-',
2123
storageLocation: project.storageRegion || '-',
2224
totalDataStored: project.storageByteCount ? `${(+project.storageByteCount / (1024 * 1024)).toFixed(1)} MB` : '0 B',
23-
creator: {
24-
url: project.creators[0].absoluteUrl || '#',
25-
text: project.creators[0].name || '-',
26-
} as TableCellLink,
25+
creator: mapCreators(project, currentInstitutionId),
2726
views: project.viewsCount || '-',
2827
resourceType: project.resourceNature || '-',
2928
license: project.license?.name || '-',

src/app/features/admin-institutions/mappers/institution-registration-to-table-data.mapper.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,33 @@
11
import { extractPathAfterDomain } from '@osf/features/admin-institutions/helpers';
22
import { ResourceModel } from '@shared/models';
33

4-
import { TableCellData, TableCellLink } from '../models';
4+
import { TableCellData } from '../models';
55

6-
export function mapRegistrationResourceToTableData(registration: ResourceModel): TableCellData {
6+
import { mapCreators } from './creators.mapper';
7+
8+
export function mapRegistrationResourceToTableData(
9+
registration: ResourceModel,
10+
currentInstitutionId: string
11+
): TableCellData {
712
return {
813
title: registration.title,
914
link: {
1015
text: registration.absoluteUrl.split('/').pop() || registration.absoluteUrl,
1116
url: registration.absoluteUrl,
12-
target: '_blank',
13-
} as TableCellLink,
17+
},
1418
dateCreated: registration.dateCreated,
1519
dateModified: registration.dateModified,
1620
doi: registration.doi[0]
17-
? ({
21+
? {
1822
text: extractPathAfterDomain(registration.doi[0]),
1923
url: registration.doi[0],
20-
} as TableCellLink)
24+
}
2125
: '-',
2226
storageLocation: registration.storageRegion || '-',
2327
totalDataStored: registration.storageByteCount
2428
? `${(+registration.storageByteCount / (1024 * 1024)).toFixed(1)} MB`
2529
: '0 B',
26-
contributorName: registration.creators[0]
27-
? ({
28-
text: registration.creators[0].name,
29-
url: registration.creators[0].absoluteUrl,
30-
target: '_blank',
31-
} as TableCellLink)
32-
: '-',
30+
creator: mapCreators(registration, currentInstitutionId),
3331
views: registration.viewsCount || '-',
3432
resourceType: registration.resourceNature || '-',
3533
license: registration.license?.name || '-',

src/app/features/admin-institutions/mappers/institution-user-to-table-data.mapper.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ export function mapUserToTableCellData(user: InstitutionUser): TableCellData {
1010
userLink: {
1111
text: user.userId,
1212
url: `${environment.webUrl}/${user.userId}`,
13-
target: '_blank',
1413
},
1514
orcidId: user.orcidId
1615
? {
1716
text: user.orcidId,
1817
url: `https://orcid.org/${user.orcidId}`,
19-
target: '_blank',
2018
}
2119
: '-',
2220
publicProjects: user.publicProjects,

0 commit comments

Comments
 (0)