Skip to content

Commit 8c5fc4e

Browse files
committed
resolve CR comments
1 parent 33016ca commit 8c5fc4e

File tree

4 files changed

+93
-56
lines changed

4 files changed

+93
-56
lines changed

src/app/features/admin-institutions/helpers/download-url.helper.ts

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,76 @@
11
import { DOWNLOAD_FORMATS } from '../constants';
22
import { DownloadType } from '../enums';
3+
import { CurrentResourceType } from '@shared/enums';
4+
5+
interface ResourceNameText {
6+
singular_upper: string;
7+
plural_lower: string;
8+
}
9+
10+
export const INSTITUTIONS_CSV_TSV_FIELDS = {
11+
[CurrentResourceType.Preprints]: [
12+
'title',
13+
'dateCreated',
14+
'dateModified',
15+
'sameAs',
16+
'rights.name',
17+
'creator.@id',
18+
'creator.name',
19+
'usage.viewCount',
20+
'usage.downloadCount',
21+
],
22+
[CurrentResourceType.Projects]: [
23+
'title',
24+
'dateCreated',
25+
'dateModified',
26+
'sameAs',
27+
'storageRegion.prefLabel',
28+
'storageByteCount',
29+
'creator.@id',
30+
'creator.name',
31+
'usage.viewCount',
32+
'resourceNature.displayLabel',
33+
'rights.name',
34+
'hasOsfAddon.prefLabel',
35+
'funder.name',
36+
],
37+
[CurrentResourceType.Registrations]: [
38+
'title',
39+
'dateCreated',
40+
'dateModified',
41+
'sameAs',
42+
'storageRegion.prefLabel',
43+
'storageByteCount',
44+
'creator.@id',
45+
'creator.name',
46+
'usage.viewCount',
47+
'resourceNature.displayLabel',
48+
'rights.name',
49+
'funder.name',
50+
'conformsTo.title',
51+
],
52+
};
53+
54+
export const INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE = {
55+
[CurrentResourceType.Projects]: {
56+
singular_upper: 'Project',
57+
plural_lower: 'projects',
58+
},
59+
[CurrentResourceType.Registrations]: {
60+
singular_upper: 'Registration',
61+
plural_lower: 'registrations',
62+
},
63+
[CurrentResourceType.Preprints]: {
64+
singular_upper: 'Preprint',
65+
plural_lower: 'preprints',
66+
},
67+
};
368

469
export function downloadResults(
570
downloadUrl: string | null,
671
type: DownloadType,
772
fields: string[],
8-
resourceType: string
73+
resourceNameText: ResourceNameText
974
) {
1075
if (!downloadUrl) {
1176
return;
@@ -17,10 +82,10 @@ export function downloadResults(
1782
cardSearchUrl.searchParams.set('page[size]', '10000');
1883
cardSearchUrl.searchParams.set('page[cursor]', '');
1984
cardSearchUrl.searchParams.set('acceptMediatype', format);
20-
cardSearchUrl.searchParams.set('withFileName', `${resourceType.toLowerCase()}s-search-results`);
85+
cardSearchUrl.searchParams.set('withFileName', `${resourceNameText.plural_lower}-search-results`);
2186

2287
if (type === DownloadType.CSV || type === DownloadType.TSV) {
23-
cardSearchUrl.searchParams.set(`fields[${resourceType}]`, fields.join(','));
88+
cardSearchUrl.searchParams.set(`fields[${resourceNameText.singular_upper}]`, fields.join(','));
2489
}
2590

2691
const downloadLink = cardSearchUrl.toString();

src/app/features/admin-institutions/pages/institutions-preprints/institutions-preprints.component.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Button } from 'primeng/button';
77
import { CommonModule } from '@angular/common';
88
import { ChangeDetectionStrategy, Component, computed, OnDestroy, OnInit, signal } from '@angular/core';
99

10-
import { ResourceType, SortOrder } from '@osf/shared/enums';
10+
import { CurrentResourceType, ResourceType, SortOrder } from '@osf/shared/enums';
1111
import { PaginationLinksModel, ResourceModel, SearchFilters } from '@osf/shared/models';
1212
import {
1313
FetchResources,
@@ -23,10 +23,11 @@ import { AdminTableComponent } from '../../components';
2323
import { FiltersSectionComponent } from '../../components/filters-section/filters-section.component';
2424
import { preprintsTableColumns } from '../../constants';
2525
import { DownloadType } from '../../enums';
26-
import { downloadResults } from '../../helpers';
26+
import { INSTITUTIONS_CSV_TSV_FIELDS, INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE, downloadResults } from '../../helpers';
2727
import { mapPreprintResourceToTableData } from '../../mappers/institution-preprint-to-table-data.mapper';
2828
import { TableCellData } from '../../models';
2929
import { InstitutionsAdminSelectors } from '../../store';
30+
import { CurrentResourceSelectors } from '@shared/stores/current-resource';
3031

3132
@Component({
3233
selector: 'osf-institutions-preprints',
@@ -105,18 +106,11 @@ export class InstitutionsPreprintsComponent implements OnInit, OnDestroy {
105106
}
106107

107108
download(type: DownloadType) {
108-
const fields = [
109-
'title',
110-
'dateCreated',
111-
'dateModified',
112-
'sameAs',
113-
'rights.name',
114-
'creator.@id',
115-
'creator.name',
116-
'usage.viewCount',
117-
'usage.downloadCount',
118-
];
119-
const resourceType = 'Preprint';
120-
downloadResults(this.selfLink(), type, fields, resourceType);
109+
downloadResults(
110+
this.selfLink(),
111+
type,
112+
INSTITUTIONS_CSV_TSV_FIELDS[CurrentResourceType.Preprints],
113+
INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE[CurrentResourceType.Preprints]
114+
);
121115
}
122116
}

src/app/features/admin-institutions/pages/institutions-projects/institutions-projects.component.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
2121

2222
import { UserSelectors } from '@core/store/user';
2323
import { RequestAccessErrorDialogComponent } from '@osf/features/admin-institutions/components/request-access-error-dialog/request-access-error-dialog.component';
24-
import { ResourceType, SortOrder } from '@osf/shared/enums';
24+
import { CurrentResourceType, ResourceType, SortOrder } from '@osf/shared/enums';
2525
import { PaginationLinksModel, ResourceModel, SearchFilters } from '@osf/shared/models';
2626
import { CustomDialogService, ToastService } from '@osf/shared/services';
2727
import {
@@ -39,7 +39,7 @@ import { FiltersSectionComponent } from '../../components/filters-section/filter
3939
import { projectTableColumns } from '../../constants';
4040
import { ContactDialogComponent } from '../../dialogs';
4141
import { ContactOption, DownloadType } from '../../enums';
42-
import { downloadResults } from '../../helpers';
42+
import { INSTITUTIONS_CSV_TSV_FIELDS, downloadResults, INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE } from '../../helpers';
4343
import { mapProjectResourceToTableCellData } from '../../mappers/institution-project-to-table-data.mapper';
4444
import { ContactDialogData, TableCellData, TableCellLink, TableIconClickEvent } from '../../models';
4545
import { InstitutionsAdminSelectors, RequestProjectAccess, SendUserMessage } from '../../store';
@@ -128,23 +128,12 @@ export class InstitutionsProjectsComponent implements OnInit, OnDestroy {
128128
}
129129

130130
download(type: DownloadType) {
131-
const fields = [
132-
'title',
133-
'dateCreated',
134-
'dateModified',
135-
'sameAs',
136-
'storageRegion.prefLabel',
137-
'storageByteCount',
138-
'creator.@id',
139-
'creator.name',
140-
'usage.viewCount',
141-
'resourceNature.displayLabel',
142-
'rights.name',
143-
'hasOsfAddon.prefLabel',
144-
'funder.name',
145-
];
146-
const resourceType = 'Project';
147-
downloadResults(this.selfLink(), type, fields, resourceType);
131+
downloadResults(
132+
this.selfLink(),
133+
type,
134+
INSTITUTIONS_CSV_TSV_FIELDS[CurrentResourceType.Projects],
135+
INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE[CurrentResourceType.Projects]
136+
);
148137
}
149138

150139
onIconClick(event: TableIconClickEvent): void {

src/app/features/admin-institutions/pages/institutions-registrations/institutions-registrations.component.ts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { CommonModule } from '@angular/common';
88
import { ChangeDetectionStrategy, Component, computed, OnDestroy, OnInit, signal } from '@angular/core';
99

1010
import { TableCellData } from '@osf/features/admin-institutions/models';
11-
import { ResourceType, SortOrder } from '@osf/shared/enums';
11+
import { CurrentResourceType, ResourceType, SortOrder } from '@osf/shared/enums';
1212
import { PaginationLinksModel, ResourceModel, SearchFilters } from '@osf/shared/models';
1313
import {
1414
ClearFilterSearchResults,
@@ -25,7 +25,7 @@ import { AdminTableComponent } from '../../components';
2525
import { FiltersSectionComponent } from '../../components/filters-section/filters-section.component';
2626
import { registrationTableColumns } from '../../constants';
2727
import { DownloadType } from '../../enums';
28-
import { downloadResults } from '../../helpers';
28+
import { INSTITUTIONS_CSV_TSV_FIELDS, downloadResults, INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE } from '../../helpers';
2929
import { mapRegistrationResourceToTableData } from '../../mappers/institution-registration-to-table-data.mapper';
3030
import { InstitutionsAdminSelectors } from '../../store';
3131

@@ -106,22 +106,11 @@ export class InstitutionsRegistrationsComponent implements OnInit, OnDestroy {
106106
}
107107

108108
download(type: DownloadType) {
109-
const fields = [
110-
'title',
111-
'dateCreated',
112-
'dateModified',
113-
'sameAs',
114-
'storageRegion.prefLabel',
115-
'storageByteCount',
116-
'creator.@id',
117-
'creator.name',
118-
'usage.viewCount',
119-
'resourceNature.displayLabel',
120-
'rights.name',
121-
'funder.name',
122-
'conformsTo.title',
123-
];
124-
const resourceType = 'Registration';
125-
downloadResults(this.selfLink(), type, fields, resourceType);
109+
downloadResults(
110+
this.selfLink(),
111+
type,
112+
INSTITUTIONS_CSV_TSV_FIELDS[CurrentResourceType.Registrations],
113+
INSTITUTIONS_DOWNLOAD_CSV_TSV_RESOURCE[CurrentResourceType.Registrations]
114+
);
126115
}
127116
}

0 commit comments

Comments
 (0)