Skip to content

Commit ca0512c

Browse files
feat: Update Project List (#443)
* 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]>
1 parent d94376c commit ca0512c

File tree

13 files changed

+226
-205
lines changed

13 files changed

+226
-205
lines changed

backend/editor/api.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,11 @@ async def pong(response: Response):
145145

146146

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

157154

158155
@app.get("/{taxonomy_name}/{branch}/project")

backend/editor/controllers/node_controller.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from openfoodfacts_taxonomy_parser import utils as parser_utils
22

33
from ..graph_db import get_current_transaction
4-
from ..models.node_models import EntryNodeCreate
4+
from ..models.node_models import EntryNodeCreate, ErrorNode
55

66

77
async def delete_project_nodes(project_id: str):
@@ -43,3 +43,16 @@ async def create_entry_node(
4343

4444
result = await get_current_transaction().run(query, params)
4545
return (await result.data())[0]["n.id"]
46+
47+
48+
async def get_error_node(project_id: str) -> ErrorNode | None:
49+
query = """
50+
MATCH (n:ERRORS {id: $project_id})
51+
RETURN n
52+
"""
53+
params = {"project_id": project_id}
54+
result = await get_current_transaction().run(query, params)
55+
error_node = await result.single()
56+
if error_node is None:
57+
return None
58+
return ErrorNode(**error_node["n"])

backend/editor/controllers/project_controller.py

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ async def get_projects_by_status(status: ProjectStatus) -> list[Project]:
3434
return [Project(**record["p"]) async for record in result]
3535

3636

37+
async def get_all_projects() -> list[Project]:
38+
query = """
39+
MATCH (p:PROJECT)
40+
RETURN p
41+
ORDER BY p.created_at DESC
42+
"""
43+
result = await get_current_transaction().run(query)
44+
return [Project(**record["p"]) async for record in result]
45+
46+
3747
async def create_project(project: ProjectCreate):
3848
"""
3949
Create project

backend/editor/entries.py

+13-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from openfoodfacts_taxonomy_parser import utils as parser_utils
1818

1919
from . import settings, utils
20-
from .controllers.node_controller import create_entry_node
20+
from .controllers.node_controller import create_entry_node, get_error_node
2121
from .controllers.project_controller import create_project, edit_project, get_project
2222
from .exceptions import GithubBranchExistsError # Custom exceptions
2323
from .exceptions import (
@@ -132,11 +132,20 @@ async def get_and_parse_taxonomy(self, uploadfile: UploadFile | None = None):
132132
)
133133
await run_in_threadpool(self.parse_taxonomy, filepath)
134134
async with TransactionCtx():
135-
await edit_project(self.project_name, ProjectEdit(status=ProjectStatus.OPEN))
135+
error_node = await get_error_node(self.project_name)
136+
errors_count = len(error_node.errors) if error_node else 0
137+
await edit_project(
138+
self.project_name,
139+
ProjectEdit(status=ProjectStatus.OPEN, errors_count=errors_count),
140+
)
136141
except Exception as e:
137-
# add an error node so we can display it with errors in the app
138142
async with TransactionCtx():
139-
await edit_project(self.project_name, ProjectEdit(status=ProjectStatus.FAILED))
143+
error_node = await get_error_node(self.project_name)
144+
errors_count = len(error_node.errors) if error_node else 0
145+
await edit_project(
146+
self.project_name,
147+
ProjectEdit(status=ProjectStatus.FAILED, errors_count=errors_count),
148+
)
140149
log.exception(e)
141150
raise e
142151

backend/editor/models/project_models.py

+3
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ class ProjectCreate(BaseModel):
2525

2626

2727
class Project(ProjectCreate):
28+
owner_name: str | None = None
2829
created_at: DateTime
30+
errors_count: int = 0
2931
github_checkout_commit_sha: str | None = None
3032
github_file_latest_sha: str | None = None
3133
github_pr_url: str | None = None
3234

3335

3436
class ProjectEdit(BaseModel):
37+
errors_count: int | None = None
3538
status: ProjectStatus | None = None
3639
github_checkout_commit_sha: str | None = None
3740
github_file_latest_sha: str | None = None

backend/openapi/openapi.json

+17-24
Original file line numberDiff line numberDiff line change
@@ -32,33 +32,19 @@
3232
},
3333
"/projects": {
3434
"get": {
35-
"summary": "List All Projects",
36-
"description": "List projects created in the Taxonomy Editor with a status filter",
37-
"operationId": "list_all_projects_projects_get",
38-
"parameters": [
39-
{
40-
"name": "status",
41-
"in": "query",
42-
"required": false,
43-
"schema": {
44-
"anyOf": [
45-
{ "$ref": "#/components/schemas/ProjectStatus" },
46-
{ "type": "null" }
47-
],
48-
"title": "Status"
49-
}
50-
}
51-
],
35+
"summary": "Get All Projects",
36+
"description": "List projects created in the Taxonomy Editor",
37+
"operationId": "get_all_projects_projects_get",
5238
"responses": {
5339
"200": {
5440
"description": "Successful Response",
55-
"content": { "application/json": { "schema": {} } }
56-
},
57-
"422": {
58-
"description": "Validation Error",
5941
"content": {
6042
"application/json": {
61-
"schema": { "$ref": "#/components/schemas/HTTPValidationError" }
43+
"schema": {
44+
"items": { "$ref": "#/components/schemas/Project" },
45+
"type": "array",
46+
"title": "Response Get All Projects Projects Get"
47+
}
6248
}
6349
}
6450
}
@@ -1248,13 +1234,21 @@
12481234
"taxonomyName": { "type": "string", "title": "Taxonomyname" },
12491235
"branchName": { "type": "string", "title": "Branchname" },
12501236
"description": { "type": "string", "title": "Description" },
1251-
"ownerName": { "type": "string", "title": "Ownername" },
1237+
"ownerName": {
1238+
"anyOf": [{ "type": "string" }, { "type": "null" }],
1239+
"title": "Ownername"
1240+
},
12521241
"isFromGithub": { "type": "boolean", "title": "Isfromgithub" },
12531242
"createdAt": {
12541243
"type": "string",
12551244
"format": "date-time",
12561245
"title": "Createdat"
12571246
},
1247+
"errorsCount": {
1248+
"type": "integer",
1249+
"title": "Errorscount",
1250+
"default": 0
1251+
},
12581252
"githubCheckoutCommitSha": {
12591253
"anyOf": [{ "type": "string" }, { "type": "null" }],
12601254
"title": "Githubcheckoutcommitsha"
@@ -1274,7 +1268,6 @@
12741268
"taxonomyName",
12751269
"branchName",
12761270
"description",
1277-
"ownerName",
12781271
"isFromGithub",
12791272
"createdAt"
12801273
],

taxonomy-editor-frontend/package-lock.json

+63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

taxonomy-editor-frontend/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"@material-table/core": "^6.2.11",
1010
"@mui/icons-material": "^5.15.10",
1111
"@mui/material": "^5.14.20",
12+
"@mui/x-data-grid": "^6.19.6",
1213
"@tanstack/react-query": "^5.17.9",
1314
"@vitejs/plugin-react": "^4.2.1",
1415
"@yaireo/dragsort": "^1.3.1",
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,3 @@
1-
type ProjectType = {
2-
branch_name: string;
3-
created_at: {
4-
_DateTime__date: {
5-
_Date__ordinal: number;
6-
_Date__year: number;
7-
_Date__month: number;
8-
_Date__day: number;
9-
};
10-
_DateTime__time: {
11-
_Time__ticks: number;
12-
_Time__hour: number;
13-
_Time__minute: number;
14-
_Time__second: number;
15-
_Time__nanosecond: number;
16-
_Time__tzinfo: any;
17-
};
18-
};
19-
description: string;
20-
id: string;
21-
taxonomy_name: string;
22-
owner_name: string;
23-
errors_count: number;
24-
status: string;
25-
};
26-
27-
export type ProjectsAPIResponse = ProjectType[];
28-
291
type NodeType = {
302
id: string;
313
string: string | Array<string>;
@@ -36,13 +8,3 @@ export type RootEntriesAPIResponse = Array<NodeType[]>;
368
export type SearchAPIResponse = string[];
379

3810
export type ParentsAPIResponse = string[];
39-
40-
export type ProjectInfoAPIResponse = ProjectType;
41-
42-
export enum ProjectStatus {
43-
FAILED = "FAILED",
44-
OPEN = "OPEN",
45-
LOADING = "LOADING",
46-
EXPORTED = "EXPORTED",
47-
CLOSED = "CLOSED",
48-
}

taxonomy-editor-frontend/src/client/models/Project.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ export type Project = {
99
taxonomyName: string;
1010
branchName: string;
1111
description: string;
12-
ownerName: string;
12+
ownerName: string | null;
1313
isFromGithub: boolean;
1414
createdAt: string;
15-
githubCheckoutCommitSha?: string | null;
16-
githubFileLatestSha?: string | null;
17-
githubPrUrl?: string | null;
15+
errorsCount: number;
16+
githubCheckoutCommitSha: string | null;
17+
githubFileLatestSha: string | null;
18+
githubPrUrl: string | null;
1819
};

taxonomy-editor-frontend/src/client/services/DefaultService.ts

+4-13
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,15 @@ export class DefaultService {
3737
});
3838
}
3939
/**
40-
* List All Projects
41-
* List projects created in the Taxonomy Editor with a status filter
42-
* @param status
43-
* @returns any Successful Response
40+
* Get All Projects
41+
* List projects created in the Taxonomy Editor
42+
* @returns Project Successful Response
4443
* @throws ApiError
4544
*/
46-
public static listAllProjectsProjectsGet(
47-
status?: ProjectStatus | null
48-
): CancelablePromise<any> {
45+
public static getAllProjectsProjectsGet(): CancelablePromise<Array<Project>> {
4946
return __request(OpenAPI, {
5047
method: "GET",
5148
url: "/projects",
52-
query: {
53-
status: status,
54-
},
55-
errors: {
56-
422: `Validation Error`,
57-
},
5849
});
5950
}
6051
/**

0 commit comments

Comments
 (0)