-
Notifications
You must be signed in to change notification settings - Fork 100
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update request for project related resources; Cleanup to match back-end #408
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0bc341e
Basic "clear type errors" commit
jeffdaley 2c67252
Mark todos; cleanup Mirage config
jeffdaley d98a188
Add JiraIssue and HermesDocument
jeffdaley 9128372
Cleanup
jeffdaley b6afb0b
Fix v1 reference and related-resource URL
jeffdaley 6c55660
Update config.ts
jeffdaley File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,14 +1,30 @@ | ||
import Route from "@ember/routing/route"; | ||
import { inject as service } from "@ember/service"; | ||
import ConfigService from "hermes/services/config"; | ||
import FetchService from "hermes/services/fetch"; | ||
import { HermesProject } from "hermes/types/project"; | ||
|
||
export default class AuthenticatedProjectsIndexRoute extends Route { | ||
@service("fetch") declare fetchSvc: FetchService; | ||
@service("config") declare configSvc: ConfigService; | ||
|
||
async model(): Promise<Record<string, HermesProject>> { | ||
return await this.fetchSvc | ||
.fetch("/api/v1/projects") | ||
async model() { | ||
const projects = await this.fetchSvc | ||
.fetch(`/api/${this.configSvc.config.api_version}/projects`) | ||
.then((response) => response?.json()); | ||
|
||
return await Promise.all( | ||
projects.map(async (project: HermesProject) => { | ||
const resources = await this.fetchSvc | ||
.fetch( | ||
`/api/${this.configSvc.config.api_version}/projects/${project.id}/related-resources`, | ||
) | ||
.then((response) => response?.json()); | ||
|
||
const { hermesDocuments, externalLinks } = resources; | ||
|
||
return { ...project, hermesDocuments, externalLinks }; | ||
}), | ||
); | ||
} | ||
} |
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,14 +1,32 @@ | ||
import Route from "@ember/routing/route"; | ||
import { inject as service } from "@ember/service"; | ||
import ConfigService from "hermes/services/config"; | ||
import FetchService from "hermes/services/fetch"; | ||
import { HermesProject } from "hermes/types/project"; | ||
|
||
export default class AuthenticatedProjectsProjectRoute extends Route { | ||
@service("fetch") declare fetchSvc: FetchService; | ||
@service("config") declare configSvc: ConfigService; | ||
|
||
async model(params: { project_id: string }): Promise<HermesProject> { | ||
return await this.fetchSvc | ||
.fetch("/api/v1/projects/" + params.project_id) | ||
const project = await this.fetchSvc | ||
.fetch( | ||
`/api/${this.configSvc.config.api_version}/projects/${params.project_id}`, | ||
) | ||
.then((response) => response?.json()); | ||
|
||
const projectResources = await this.fetchSvc | ||
.fetch( | ||
`/api/${this.configSvc.config.api_version}/projects/${params.project_id}/related-resources`, | ||
) | ||
.then((response) => response?.json()); | ||
|
||
const { hermesDocuments, externalLinks } = projectResources; | ||
|
||
return { | ||
...project, | ||
hermesDocuments, | ||
externalLinks, | ||
}; | ||
} | ||
} |
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 |
---|---|---|
|
@@ -188,7 +188,11 @@ export default function (mirageConfig) { | |
// Fetch a list of projects. | ||
this.get("/projects", () => { | ||
const projects = this.schema.projects.all().models; | ||
return new Response(200, {}, projects); | ||
return new Response( | ||
200, | ||
{}, | ||
projects.map((project) => project.attrs), | ||
); | ||
}); | ||
|
||
// Fetch a single project. | ||
|
@@ -199,6 +203,19 @@ export default function (mirageConfig) { | |
return new Response(200, {}, project.attrs); | ||
}); | ||
|
||
/** | ||
* Fetch a project's related resources. | ||
* Since Mirage doesn't yet know the relationship between projects and resources, | ||
* so simply return the documents and links created within tests via | ||
* `project.update({ hermesDocuments, externalLinks })`. | ||
*/ | ||
this.get("/projects/:project_id/related-resources", (schema, request) => { | ||
const projectID = request.params.project_id; | ||
const project = schema.projects.findBy({ id: projectID }); | ||
const { hermesDocuments, externalLinks } = project.attrs; | ||
return new Response(200, {}, { hermesDocuments, externalLinks }); | ||
}); | ||
|
||
// Fetch a project's related resources | ||
this.put("/projects/:project_id", (schema, request) => { | ||
let project = schema.projects.findBy({ | ||
|
@@ -516,24 +533,6 @@ export default function (mirageConfig) { | |
); | ||
}); | ||
|
||
/** | ||
* Used by the /projects route to fetch a list of projects. | ||
*/ | ||
this.get("/projects", () => { | ||
const projects = this.schema.projects.all().models; | ||
return new Response(200, {}, projects); | ||
}); | ||
|
||
/** | ||
* Used by the /projects/:project_id route to fetch a single project. | ||
*/ | ||
this.get("/projects/:project_id", (schema, request) => { | ||
const project = schema.projects.findBy({ | ||
id: request.params.project_id, | ||
}); | ||
return new Response(200, {}, project.attrs); | ||
}); | ||
|
||
Comment on lines
-519
to
-536
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These were duplicates. Probably a merge error. |
||
/** | ||
* Used by the Dashboard route to get a user's recently viewed documents. | ||
*/ | ||
|
File renamed without changes.
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 |
---|---|---|
|
@@ -4,25 +4,25 @@ import { HermesProject } from "hermes/types/project"; | |
export default Factory.extend({ | ||
id: (i: number) => i, | ||
title: (i: number) => `Test Project ${i}`, | ||
dateCreated: 1, | ||
dateModified: 1, | ||
createdDate: 1, | ||
modifiedDate: 1, | ||
creator: "[email protected]", | ||
status: "active", | ||
|
||
// @ts-ignore - Bug https://github.com/miragejs/miragejs/issues/1052 | ||
afterCreate(project: ModelInstance<HermesProject>, server: any): void { | ||
server.createList("related-hermes-document", 1); | ||
server.create("jira-object"); | ||
server.create("jira-issue"); | ||
|
||
const relatedHermesDocuments = server.schema.relatedHermesDocument | ||
.all() | ||
.models.map((doc: ModelInstance) => doc.attrs); | ||
|
||
const jiraObject = server.schema.jiraObjects.first()?.attrs; | ||
const jiraIssue = server.schema.jiraIssues.first()?.attrs; | ||
|
||
project.update({ | ||
hermesDocuments: relatedHermesDocuments, | ||
jiraObject, | ||
jiraIssue, | ||
}); | ||
}, | ||
}); |
File renamed without changes.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is
jiraIssueID
supposed to represent the internal Jira ID (if so, curious how we use that)? Can we put that as part of aJiraIssue
? Note/caveat: I haven't dove into the Jira part of the backend work yet so I'm cool with this changing as we start to incorporate that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I interpreted JiraIssueID to be an external reference, like "LABS-123" (as in
test-org.atlassian.com/issues/LABS-123
that would be used to query the Jira API for the fullJiraIssue
object.