-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from UoA-eResearch/IDS-957-display-information…
…-retrieved-from-backend IDS-957 display information retrieved from backend
- Loading branch information
Showing
14 changed files
with
277 additions
and
226 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
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
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,62 @@ | ||
/** | ||
* Functions for loading information about the archive request. | ||
*/ | ||
import { requestInfo } from "@/store"; | ||
import { getDriveInfoApiV1ResdriveinfoGet } from "./sdk.gen"; | ||
import type { ProjectWithDriveMember, ResearchDriveService } from "./types.gen"; | ||
|
||
/** | ||
* Retrieves project information based on project code in URL. | ||
* @returns Project information from server. | ||
* @throws Exception if server did not return data or received an error status code. | ||
*/ | ||
async function getProject(): Promise<ProjectWithDriveMember> { | ||
const params = new URLSearchParams(window.location.search); | ||
const driveId = params.get("drive"); | ||
if (driveId === null) { | ||
throw new Error("No drive name found in parameter."); | ||
} | ||
const response = await getDriveInfoApiV1ResdriveinfoGet({ | ||
query: { | ||
drive_id: driveId | ||
} | ||
}); | ||
if (response.error || !response.response.ok || response.data === undefined) { | ||
throw response.error; | ||
} | ||
return response.data; | ||
} | ||
|
||
/** | ||
* Retrieves drive information from server. | ||
* @returns Drive information from server. | ||
* @throws Exception if server did not return data. | ||
*/ | ||
async function getDrive(): Promise<ResearchDriveService> { | ||
const project = await getProject(); | ||
if (!project) { | ||
throw new Error("Project is not loaded."); | ||
} | ||
return project.research_drives[0]; | ||
} | ||
|
||
/** | ||
* Retrieves archive information from server and stores it in the requestInfo store. | ||
* @returns True if request was loaded successfully, false if not. | ||
*/ | ||
export async function loadRequestInfo(): Promise<boolean> { | ||
// Pre-populate archive request info. | ||
try { | ||
requestInfo.isLoading = true; | ||
requestInfo.project = await getProject(); | ||
requestInfo.drive = await getDrive(); | ||
requestInfo.isLoading = false; | ||
return true; | ||
} catch (e) { | ||
requestInfo.isLoading = false; | ||
requestInfo.error = e; | ||
console.error("Could not retrieve request information. Bad invite link?"); | ||
console.error(e); | ||
return false; | ||
} | ||
} |
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
This file was deleted.
Oops, something went wrong.
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
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 @@ | ||
/** | ||
* Additional methods for Members. | ||
*/ | ||
|
||
import type { MemberPublic } from "@/client"; | ||
|
||
|
||
/** | ||
* Given a list of members, filter for project owners. | ||
* @param members List of members to search through | ||
* @returns Members who are project owners. | ||
*/ | ||
export function getProjectOwners(members: MemberPublic[]): MemberPublic[] { | ||
return members.filter(member => | ||
member.role.name === "Project Owner" | ||
); | ||
} | ||
|
||
/** | ||
* Given a list of project members, filter for ordinary members. | ||
* @param members List of members to search through | ||
* @returns Members who are not project owners. | ||
*/ | ||
export function getProjectMembers(members: MemberPublic[]): MemberPublic[] { | ||
return members.filter(member => | ||
member.role.name !== "Project Owner" | ||
); | ||
} | ||
|
||
/** | ||
* Given a list of members, return a string of their names. | ||
* @param members Members to return names for. | ||
* @returns A string representing all member names. | ||
*/ | ||
export function membersToString(members: MemberPublic[]): string { | ||
|
||
return members.filter((_, idx, arr) => | ||
// Filter for unique members | ||
arr.findIndex(member => member.person.email) === idx | ||
).map(member => | ||
member.person.full_name | ||
).join(", "); | ||
} |
Oops, something went wrong.