Skip to content

Commit

Permalink
feat: Update Project List (#443)
Browse files Browse the repository at this point in the history
* refactor: update list_all_projects API

* refactor: clean up Project types and API calls

* refactor: update Project List style and add link to PR

* fix: small style and logic fixes on frontend

* fix: respond comments

Co-authored-by: Charles Perier <[email protected]>

---------

Co-authored-by: Charles Perier <[email protected]>
  • Loading branch information
eric-nguyen-cs and perierc authored Mar 20, 2024
1 parent d94376c commit ca0512c
Show file tree
Hide file tree
Showing 13 changed files with 226 additions and 205 deletions.
9 changes: 3 additions & 6 deletions backend/editor/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,11 @@ async def pong(response: Response):


@app.get("/projects")
async def list_all_projects(response: Response, status: Optional[ProjectStatus] = None):
async def get_all_projects() -> list[Project]:
"""
List projects created in the Taxonomy Editor with a status filter
List projects created in the Taxonomy Editor
"""
# Listing all projects doesn't require a taxonomy name or branch name
taxonomy = TaxonomyGraph("", "")
result = await taxonomy.list_projects(status)
return result
return await project_controller.get_all_projects()


@app.get("/{taxonomy_name}/{branch}/project")
Expand Down
15 changes: 14 additions & 1 deletion backend/editor/controllers/node_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from openfoodfacts_taxonomy_parser import utils as parser_utils

from ..graph_db import get_current_transaction
from ..models.node_models import EntryNodeCreate
from ..models.node_models import EntryNodeCreate, ErrorNode


async def delete_project_nodes(project_id: str):
Expand Down Expand Up @@ -43,3 +43,16 @@ async def create_entry_node(

result = await get_current_transaction().run(query, params)
return (await result.data())[0]["n.id"]


async def get_error_node(project_id: str) -> ErrorNode | None:
query = """
MATCH (n:ERRORS {id: $project_id})
RETURN n
"""
params = {"project_id": project_id}
result = await get_current_transaction().run(query, params)
error_node = await result.single()
if error_node is None:
return None
return ErrorNode(**error_node["n"])
10 changes: 10 additions & 0 deletions backend/editor/controllers/project_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ async def get_projects_by_status(status: ProjectStatus) -> list[Project]:
return [Project(**record["p"]) async for record in result]


async def get_all_projects() -> list[Project]:
query = """
MATCH (p:PROJECT)
RETURN p
ORDER BY p.created_at DESC
"""
result = await get_current_transaction().run(query)
return [Project(**record["p"]) async for record in result]


async def create_project(project: ProjectCreate):
"""
Create project
Expand Down
17 changes: 13 additions & 4 deletions backend/editor/entries.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from openfoodfacts_taxonomy_parser import utils as parser_utils

from . import settings, utils
from .controllers.node_controller import create_entry_node
from .controllers.node_controller import create_entry_node, get_error_node
from .controllers.project_controller import create_project, edit_project, get_project
from .exceptions import GithubBranchExistsError # Custom exceptions
from .exceptions import (
Expand Down Expand Up @@ -132,11 +132,20 @@ async def get_and_parse_taxonomy(self, uploadfile: UploadFile | None = None):
)
await run_in_threadpool(self.parse_taxonomy, filepath)
async with TransactionCtx():
await edit_project(self.project_name, ProjectEdit(status=ProjectStatus.OPEN))
error_node = await get_error_node(self.project_name)
errors_count = len(error_node.errors) if error_node else 0
await edit_project(
self.project_name,
ProjectEdit(status=ProjectStatus.OPEN, errors_count=errors_count),
)
except Exception as e:
# add an error node so we can display it with errors in the app
async with TransactionCtx():
await edit_project(self.project_name, ProjectEdit(status=ProjectStatus.FAILED))
error_node = await get_error_node(self.project_name)
errors_count = len(error_node.errors) if error_node else 0
await edit_project(
self.project_name,
ProjectEdit(status=ProjectStatus.FAILED, errors_count=errors_count),
)
log.exception(e)
raise e

Expand Down
3 changes: 3 additions & 0 deletions backend/editor/models/project_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ class ProjectCreate(BaseModel):


class Project(ProjectCreate):
owner_name: str | None = None
created_at: DateTime
errors_count: int = 0
github_checkout_commit_sha: str | None = None
github_file_latest_sha: str | None = None
github_pr_url: str | None = None


class ProjectEdit(BaseModel):
errors_count: int | None = None
status: ProjectStatus | None = None
github_checkout_commit_sha: str | None = None
github_file_latest_sha: str | None = None
Expand Down
41 changes: 17 additions & 24 deletions backend/openapi/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,19 @@
},
"/projects": {
"get": {
"summary": "List All Projects",
"description": "List projects created in the Taxonomy Editor with a status filter",
"operationId": "list_all_projects_projects_get",
"parameters": [
{
"name": "status",
"in": "query",
"required": false,
"schema": {
"anyOf": [
{ "$ref": "#/components/schemas/ProjectStatus" },
{ "type": "null" }
],
"title": "Status"
}
}
],
"summary": "Get All Projects",
"description": "List projects created in the Taxonomy Editor",
"operationId": "get_all_projects_projects_get",
"responses": {
"200": {
"description": "Successful Response",
"content": { "application/json": { "schema": {} } }
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": { "$ref": "#/components/schemas/HTTPValidationError" }
"schema": {
"items": { "$ref": "#/components/schemas/Project" },
"type": "array",
"title": "Response Get All Projects Projects Get"
}
}
}
}
Expand Down Expand Up @@ -1248,13 +1234,21 @@
"taxonomyName": { "type": "string", "title": "Taxonomyname" },
"branchName": { "type": "string", "title": "Branchname" },
"description": { "type": "string", "title": "Description" },
"ownerName": { "type": "string", "title": "Ownername" },
"ownerName": {
"anyOf": [{ "type": "string" }, { "type": "null" }],
"title": "Ownername"
},
"isFromGithub": { "type": "boolean", "title": "Isfromgithub" },
"createdAt": {
"type": "string",
"format": "date-time",
"title": "Createdat"
},
"errorsCount": {
"type": "integer",
"title": "Errorscount",
"default": 0
},
"githubCheckoutCommitSha": {
"anyOf": [{ "type": "string" }, { "type": "null" }],
"title": "Githubcheckoutcommitsha"
Expand All @@ -1274,7 +1268,6 @@
"taxonomyName",
"branchName",
"description",
"ownerName",
"isFromGithub",
"createdAt"
],
Expand Down
63 changes: 63 additions & 0 deletions taxonomy-editor-frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions taxonomy-editor-frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"@material-table/core": "^6.2.11",
"@mui/icons-material": "^5.15.10",
"@mui/material": "^5.14.20",
"@mui/x-data-grid": "^6.19.6",
"@tanstack/react-query": "^5.17.9",
"@vitejs/plugin-react": "^4.2.1",
"@yaireo/dragsort": "^1.3.1",
Expand Down
38 changes: 0 additions & 38 deletions taxonomy-editor-frontend/src/backend-types/types.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,3 @@
type ProjectType = {
branch_name: string;
created_at: {
_DateTime__date: {
_Date__ordinal: number;
_Date__year: number;
_Date__month: number;
_Date__day: number;
};
_DateTime__time: {
_Time__ticks: number;
_Time__hour: number;
_Time__minute: number;
_Time__second: number;
_Time__nanosecond: number;
_Time__tzinfo: any;
};
};
description: string;
id: string;
taxonomy_name: string;
owner_name: string;
errors_count: number;
status: string;
};

export type ProjectsAPIResponse = ProjectType[];

type NodeType = {
id: string;
string: string | Array<string>;
Expand All @@ -36,13 +8,3 @@ export type RootEntriesAPIResponse = Array<NodeType[]>;
export type SearchAPIResponse = string[];

export type ParentsAPIResponse = string[];

export type ProjectInfoAPIResponse = ProjectType;

export enum ProjectStatus {
FAILED = "FAILED",
OPEN = "OPEN",
LOADING = "LOADING",
EXPORTED = "EXPORTED",
CLOSED = "CLOSED",
}
9 changes: 5 additions & 4 deletions taxonomy-editor-frontend/src/client/models/Project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ export type Project = {
taxonomyName: string;
branchName: string;
description: string;
ownerName: string;
ownerName: string | null;
isFromGithub: boolean;
createdAt: string;
githubCheckoutCommitSha?: string | null;
githubFileLatestSha?: string | null;
githubPrUrl?: string | null;
errorsCount: number;
githubCheckoutCommitSha: string | null;
githubFileLatestSha: string | null;
githubPrUrl: string | null;
};
17 changes: 4 additions & 13 deletions taxonomy-editor-frontend/src/client/services/DefaultService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,15 @@ export class DefaultService {
});
}
/**
* List All Projects
* List projects created in the Taxonomy Editor with a status filter
* @param status
* @returns any Successful Response
* Get All Projects
* List projects created in the Taxonomy Editor
* @returns Project Successful Response
* @throws ApiError
*/
public static listAllProjectsProjectsGet(
status?: ProjectStatus | null
): CancelablePromise<any> {
public static getAllProjectsProjectsGet(): CancelablePromise<Array<Project>> {
return __request(OpenAPI, {
method: "GET",
url: "/projects",
query: {
status: status,
},
errors: {
422: `Validation Error`,
},
});
}
/**
Expand Down
Loading

0 comments on commit ca0512c

Please sign in to comment.