-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use new utility package for contributor field
- Loading branch information
1 parent
7269b4d
commit a6318d1
Showing
3 changed files
with
77 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 8 additions & 6 deletions
14
app/institutions/dashboard/-components/object-list/contributors-field/template.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
{{#each this.topInstitutionAffiliatedContributors as |contributor|}} | ||
<OsfLink | ||
@href={{contributor.url}} | ||
> | ||
{{contributor.name}} | ||
</OsfLink> | ||
{{t 'institutions.dashboard.object-list.table-items.permission-level' permissionLevel=contributor.permissionLevel}} | ||
<div> | ||
<OsfLink | ||
@href={{contributor.url}} | ||
> | ||
{{contributor.name}} | ||
</OsfLink> | ||
{{t 'institutions.dashboard.object-list.table-items.permission-level' permissionLevel=contributor.permissionLevel}} | ||
</div> | ||
{{/each}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
export function *iterOsfmapObjects(osfmapObject: any, propertyPath: string[]): IterableIterator<any> { | ||
const [property, ...remainingPath] = propertyPath; | ||
const innerObjArray = osfmapObject[property] || []; | ||
if (remainingPath.length) { | ||
for (const innerObj of innerObjArray) { | ||
yield* iterOsfmapObjects(innerObj, remainingPath); | ||
} | ||
} else { | ||
yield* innerObjArray; | ||
} | ||
} | ||
|
||
export function *iterOsfmapValues(osfmapObject: any, propertyPath: string[]): IterableIterator<any> { | ||
for (const obj of iterOsfmapObjects(osfmapObject, propertyPath)) { | ||
yield (Object.hasOwn(obj, '@id') ? obj['@id'] : obj['@value']); | ||
} | ||
} | ||
|
||
export function getOsfmapValues(osfmapObject: any, propertyPath: string[]) { | ||
return Array.from(iterOsfmapValues(osfmapObject, propertyPath)); | ||
} | ||
|
||
export function getSingleOsfmapValue(osfmapObject: any, propertyPath: string[]) { | ||
return iterOsfmapValues(osfmapObject, propertyPath).next().value; | ||
} | ||
|
||
export function getOsfmapObjects(osfmapObject: any, propertyPath: string[]) { | ||
return Array.from(iterOsfmapObjects(osfmapObject, propertyPath)); | ||
} | ||
|
||
export function getSingleOsfmapObject(osfmapObject: any, propertyPath: string[]) { | ||
return iterOsfmapObjects(osfmapObject, propertyPath).next().value; | ||
} | ||
|
||
export function hasOsfmapValue(osfmapObject: any, propertyPath: string[], expectedValue: any) { | ||
// could use `Iterator.prototype.some()` instead, if polyfilled | ||
for (const value of iterOsfmapValues(osfmapObject, propertyPath)) { | ||
if (value === expectedValue) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} |