Skip to content

Commit

Permalink
Refactor object list column interface
Browse files Browse the repository at this point in the history
  • Loading branch information
futa-ikeda committed Jan 3, 2025
1 parent d20b8f2 commit 9f243ac
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const shareDownloadFlag = config.featureFlagNames.shareDownload;

interface Column {
name: string;
sortKey?: string;
isSortable?: boolean;
sortParam?: string;
columnKey?: string;
propertyPathKey?: string;
}
interface ValueColumn extends Column {
getValue(searchResult: SearchResultModel): string;
Expand Down Expand Up @@ -95,8 +95,8 @@ export default class InstitutionalObjectList extends Component<InstitutionalObje
cardSearchUrl.searchParams.set('withFileName', `${this.args.objectType}-search-results`);

const columnDownloadKeys = this.args.columns.map(column => {
if (column.columnKey && this.visibleColumns.includes(column.name)) {
return column.columnKey;
if (column.propertyPathKey && this.visibleColumns.includes(column.name)) {
return column.propertyPathKey;
}
return null;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,10 @@ as |list|>
>
<span>
{{column.name}}
{{#if column.sortKey}}
{{#if column.isSortable}}
<SortArrow
@sortBy={{column.sortKey}}
@sortAction={{queue (fn this.updateSortKey column.sortKey column.sortParam) (perform list.searchObjectsTask)}}
@sortBy={{column.propertyPathKey}}
@sortAction={{queue (fn this.updateSortKey column.propertyPathKey column.sortParam) (perform list.searchObjectsTask)}}
/>
{{/if}}
</span>
Expand Down
24 changes: 12 additions & 12 deletions app/institutions/dashboard/preprints/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class InstitutionDashboardPreprints extends Controller {
type: 'link',
getHref: searchResult => searchResult.indexCard.get('osfIdentifier'),
getLinkText: searchResult => searchResult.displayTitle,
columnKey: 'title',
propertyPathKey: 'title',
},
{ // Link
name: this.intl.t('institutions.dashboard.object-list.table-headers.link'),
Expand All @@ -28,49 +28,49 @@ export default class InstitutionDashboardPreprints extends Controller {
{ // Date created
name: this.intl.t('institutions.dashboard.object-list.table-headers.created_date'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateCreated']),
sortKey: 'dateCreated',
columnKey: 'dateCreated',
isSortable: true,
propertyPathKey: 'dateCreated',
},
{ // Date modified
name: this.intl.t('institutions.dashboard.object-list.table-headers.modified_date'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateModified']),
sortKey: 'dateModified',
columnKey: 'dateModified',
isSortable: true,
propertyPathKey: 'dateModified',
},
{ // DOI
name: this.intl.t('institutions.dashboard.object-list.table-headers.doi'),
type: 'doi',
columnKey: 'resourceIdentifier',
propertyPathKey: 'resourceIdentifier',
},
{ // License
name: this.intl.t('institutions.dashboard.object-list.table-headers.license'),
getValue: searchResult => searchResult.license?.name || this.missingItemPlaceholder,
columnKey: 'rights.name',
propertyPathKey: 'rights.name',
},
{ // Contributor name + permissions
name: this.intl.t('institutions.dashboard.object-list.table-headers.contributor_name'),
type: 'contributors',
columnKey: 'creator.name',
propertyPathKey: 'creator.name',
},
{ // View count
name: this.intl.t('institutions.dashboard.object-list.table-headers.view_count'),
getValue: searchResult => {
const metrics = searchResult.usageMetrics;
return metrics ? metrics.viewCount : this.missingItemPlaceholder;
},
sortKey: 'usage.viewCount',
isSortable: true,
sortParam: 'integer-value',
columnKey: 'usage.viewCount',
propertyPathKey: 'usage.viewCount',
},
{ // Download count
name: this.intl.t('institutions.dashboard.object-list.table-headers.download_count'),
getValue: searchResult => {
const metrics = searchResult.usageMetrics;
return metrics ? metrics.downloadCount : this.missingItemPlaceholder;
},
sortKey: 'usage.downloadCount',
isSortable: true,
sortParam: 'integer-value',
columnKey: 'usage.downloadCount',
propertyPathKey: 'usage.downloadCount',
},
];

Expand Down
33 changes: 17 additions & 16 deletions app/institutions/dashboard/projects/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class InstitutionDashboardProjects extends Controller {
type: 'link',
getHref: searchResult => searchResult.indexCard.get('osfIdentifier'),
getLinkText: searchResult => searchResult.displayTitle,
columnKey: 'title',
propertyPathKey: 'title',
},
{ // Link
name: this.intl.t('institutions.dashboard.object-list.table-headers.link'),
Expand All @@ -28,65 +28,65 @@ export default class InstitutionDashboardProjects extends Controller {
{ // Date created
name: this.intl.t('institutions.dashboard.object-list.table-headers.created_date'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateCreated']),
sortKey: 'dateCreated',
columnKey: 'dateCreated',
propertyPathKey: 'dateCreated',
isSortable: true,
},
{ // Date modified
name: this.intl.t('institutions.dashboard.object-list.table-headers.modified_date'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateModified']),
sortKey: 'dateModified',
columnKey: 'dateModified',
propertyPathKey: 'dateModified',
isSortable: true,
},
{ // DOI
name: this.intl.t('institutions.dashboard.object-list.table-headers.doi'),
type: 'doi',
columnKey: 'resourceIdentifier',
propertyPathKey: 'resourceIdentifier',
},
{ // Storage location
name: this.intl.t('institutions.dashboard.object-list.table-headers.storage_location'),
getValue: searchResult => searchResult.storageRegion,
columnKey: 'storageRegion.prefLabel',
propertyPathKey: 'storageRegion.prefLabel',
},
{ // Total data stored
name: this.intl.t('institutions.dashboard.object-list.table-headers.total_data_stored'),
getValue: searchResult => {
const byteCount = getSingleOsfmapValue(searchResult.resourceMetadata, ['storageByteCount']);
return byteCount ? humanFileSize(byteCount) : this.missingItemPlaceholder;
},
sortKey: 'storageByteCount',
isSortable: true,
sortParam: 'integer-value',
columnKey: 'storageByteCount',
propertyPathKey: 'storageByteCount',
},
{ // Contributor name + permissions
name: this.intl.t('institutions.dashboard.object-list.table-headers.contributor_name'),
type: 'contributors',
columnKey: 'creator.name',
propertyPathKey: 'creator.name',
},
{ // View count
name: this.intl.t('institutions.dashboard.object-list.table-headers.view_count'),
getValue: searchResult => {
const metrics = searchResult.usageMetrics;
return metrics ? metrics.viewCount : this.missingItemPlaceholder;
},
sortKey: 'usage.viewCount',
isSortable: true,
sortParam: 'integer-value',
columnKey: 'usage.viewCount',
propertyPathKey: 'usage.viewCount',
},
{ // Resource type
name: this.intl.t('institutions.dashboard.object-list.table-headers.resource_nature'),
getValue: searchResult => searchResult.resourceNature || this.missingItemPlaceholder,
columnKey: 'resourceNature.displayLabel',
propertyPathKey: 'resourceNature.displayLabel',
},
{ // License
name: this.intl.t('institutions.dashboard.object-list.table-headers.license'),
getValue: searchResult => searchResult.license?.name || this.missingItemPlaceholder,
columnKey: 'rights.name',
propertyPathKey: 'rights.name',
},
{ // addons associated
name: this.intl.t('institutions.dashboard.object-list.table-headers.addons'),
getValue: searchResult => searchResult.configuredAddonNames.length ? searchResult.configuredAddonNames :
this.missingItemPlaceholder,
columnKey: 'hasOsfAddon.prefLabel',
propertyPathKey: 'hasOsfAddon.prefLabel',
},
{ // Funder name
name: this.intl.t('institutions.dashboard.object-list.table-headers.funder_name'),
Expand All @@ -96,7 +96,8 @@ export default class InstitutionDashboardProjects extends Controller {
}
return searchResult.funders.map((funder: { name: string }) => funder.name).join(', ');
},
columnKey: 'funder.name',
propertyPathKey: 'funder.name',

},
];

Expand Down
32 changes: 16 additions & 16 deletions app/institutions/dashboard/registrations/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default class InstitutionDashboardRegistrations extends Controller {
type: 'link',
getHref: searchResult => searchResult.indexCard.get('osfIdentifier'),
getLinkText: searchResult => searchResult.displayTitle,
columnKey: 'title',
propertyPathKey: 'title',
},
{ // Link
name: this.intl.t('institutions.dashboard.object-list.table-headers.link'),
Expand All @@ -27,59 +27,59 @@ export default class InstitutionDashboardRegistrations extends Controller {
{ // Date created
name: this.intl.t('institutions.dashboard.object-list.table-headers.created_date'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateCreated']),
sortKey: 'dateCreated',
columnKey: 'dateCreated',
isSortable: true,
propertyPathKey: 'dateCreated',
},
{ // Date modified
name: this.intl.t('institutions.dashboard.object-list.table-headers.modified_date'),
getValue: searchResult => getSingleOsfmapValue(searchResult.resourceMetadata, ['dateModified']),
sortKey: 'dateModified',
columnKey: 'dateModified',
isSortable: true,
propertyPathKey: 'dateModified',
},
{ // DOI
name: this.intl.t('institutions.dashboard.object-list.table-headers.doi'),
type: 'doi',
columnKey: 'resourceIdentifier',
propertyPathKey: 'resourceIdentifier',
},
{ // Storage location
name: this.intl.t('institutions.dashboard.object-list.table-headers.storage_location'),
getValue: searchResult => searchResult.storageRegion,
columnKey: 'storageRegion.prefLabel',
propertyPathKey: 'storageRegion.prefLabel',
},
{ // Total data stored
name: this.intl.t('institutions.dashboard.object-list.table-headers.total_data_stored'),
getValue: searchResult => {
const byteCount = getSingleOsfmapValue(searchResult.resourceMetadata, ['storageByteCount']);
return byteCount ? humanFileSize(byteCount) : this.missingItemPlaceholder;
},
sortKey: 'storageByteCount',
isSortable: true,
sortParam: 'integer-value',
columnKey: 'storageByteCount',
propertyPathKey: 'storageByteCount',
},
{ // Contributor name + permissions
name: this.intl.t('institutions.dashboard.object-list.table-headers.contributor_name'),
type: 'contributors',
columnKey: 'creator.name',
propertyPathKey: 'creator.name',
},
{ // View count
name: this.intl.t('institutions.dashboard.object-list.table-headers.view_count'),
getValue: searchResult => {
const metrics = searchResult.usageMetrics;
return metrics ? metrics.viewCount : this.missingItemPlaceholder;
},
sortKey: 'usage.viewCount',
isSortable: true,
sortParam: 'integer-value',
columnKey: 'usage.viewCount',
propertyPathKey: 'usage.viewCount',
},
{ // Resource type
name: this.intl.t('institutions.dashboard.object-list.table-headers.resource_nature'),
getValue: searchResult => searchResult.resourceNature || this.missingItemPlaceholder,
columnKey: 'resourceNature.displayLabel',
propertyPathKey: 'resourceNature.displayLabel',
},
{ // License
name: this.intl.t('institutions.dashboard.object-list.table-headers.license'),
getValue: searchResult => searchResult.license?.name || this.missingItemPlaceholder,
columnKey: 'rights.name',
propertyPathKey: 'rights.name',
},
{ // Funder name
name: this.intl.t('institutions.dashboard.object-list.table-headers.funder_name'),
Expand All @@ -89,12 +89,12 @@ export default class InstitutionDashboardRegistrations extends Controller {
}
return searchResult.funders.map((funder: { name: string }) => funder.name).join(', ');
},
columnKey: 'funders.name',
propertyPathKey: 'funders.name',
},
{ // schema
name: this.intl.t('institutions.dashboard.object-list.table-headers.registration_schema'),
getValue: searchResult => searchResult.registrationTemplate,
columnKey: 'conformsTo.title',
propertyPathKey: 'conformsTo.title',
},
];

Expand Down

0 comments on commit 9f243ac

Please sign in to comment.