Skip to content

Commit

Permalink
fix(ui): data table inconsistencies
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba committed Nov 10, 2024
1 parent 55763e5 commit 1cde582
Show file tree
Hide file tree
Showing 31 changed files with 1,538 additions and 1,454 deletions.
2 changes: 1 addition & 1 deletion console/api/models/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CountResponse(BaseModel):

class GenericListResponse(BaseModel):
totalElements: int
totalPages: int | None = Field(None)
totalPages: int
page: int
size: int
data: List[Any]
Expand Down
11 changes: 9 additions & 2 deletions console/api/routers/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ async def get_all_groups(data: Annotated[GroupListRequest, Depends()]):
groups, count = fetch_groups(page=data.page, size=data.size)

return GroupListResponse(
data=groups, totalElements=count, page=data.page, size=data.size
data=groups,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand All @@ -101,9 +105,12 @@ async def get_search_groups(data: Annotated[GroupSearchRequest, Depends()]):
hits.append(group)
except NotFoundException:
pass
count = len(groups["hits"])

return GroupListResponse(
data=hits,
totalElements=len(groups["hits"]),
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
Expand Down
6 changes: 5 additions & 1 deletion console/api/routers/invitation.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ async def get_all_invitations(data: Annotated[InvitationListRequest, Depends()])
invitations, count = fetch_invitations(page=data.page, size=data.size)

return InvitationListResponse(
data=invitations, totalElements=count, page=data.page, size=data.size
data=invitations,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand Down
29 changes: 24 additions & 5 deletions console/api/routers/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ async def get_all_organizations(data: Annotated[OrganizationListRequest, Depends
organizations, count = fetch_organizations(page=data.page, size=data.size)

return OrganizationListResponse(
data=organizations, totalElements=count, page=data.page, size=data.size
data=organizations,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand Down Expand Up @@ -118,9 +122,12 @@ async def get_search_organizations(
hits.append(organization)
except NotFoundException:
pass
count = len(organizations["hits"])

return OrganizationListResponse(
data=hits,
totalElements=len(organizations["hits"]),
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
Expand All @@ -145,7 +152,11 @@ async def get_organization_users(
)

return OrganizationUserListResponse(
data=users, totalElements=count, page=data.page, size=data.size
data=users,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand All @@ -171,7 +182,11 @@ async def get_organization_workspaces(
)

return OrganizationWorkspaceListResponse(
data=workspaces, totalElements=count, page=data.page, size=data.size
data=workspaces,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand All @@ -197,7 +212,11 @@ async def get_organization_groups(
)

return OrganizationWorkspaceListResponse(
data=groups, totalElements=count, page=data.page, size=data.size
data=groups,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand Down
6 changes: 5 additions & 1 deletion console/api/routers/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ async def get_all_snapshots(data: Annotated[SnapshotListRequest, Depends()]):
snapshots, count = fetch_snapshots(page=data.page, size=data.size)

return SnapshotListResponse(
data=snapshots, totalElements=count["count"], page=data.page, size=data.size
data=snapshots,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand Down
18 changes: 15 additions & 3 deletions console/api/routers/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ async def get_user_organizations(
)

return UserOrganizationListResponse(
data=organizations, totalElements=count, page=data.page, size=data.size
data=organizations,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand All @@ -83,7 +87,11 @@ async def get_user_workspaces(data: Annotated[UserWorkspaceListRequest, Depends(
)

return UserWorkspaceListResponse(
data=workspaces, totalElements=count, page=data.page, size=data.size
data=workspaces,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand All @@ -106,7 +114,11 @@ async def get_user_groups(data: Annotated[UserGroupListRequest, Depends()]):
)

return UserGroupListResponse(
data=groups, totalElements=count, page=data.page, size=data.size
data=groups,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand Down
11 changes: 9 additions & 2 deletions console/api/routers/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ async def get_all_workspaces(data: Annotated[WorkspaceListRequest, Depends()]):
workspaces, count = fetch_workspaces(page=data.page, size=data.size)

return WorkspaceListResponse(
data=workspaces, totalElements=count, page=data.page, size=data.size
data=workspaces,
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
except EmptyDataException as e:
logger.error(e)
Expand All @@ -117,9 +121,12 @@ async def get_search_workspaces(data: Annotated[WorkspaceSearchRequest, Depends(
hits.append(workspace)
except NotFoundException:
pass
count = len(workspaces["hits"])

return WorkspaceListResponse(
data=hits,
totalElements=len(workspaces["hits"]),
totalElements=count,
totalPages=(count + data.size - 1) // data.size,
page=data.page,
size=data.size,
)
Expand Down
3 changes: 3 additions & 0 deletions idp/src/user/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface UserAdminList {
page: number
size: number
totalElements: number
totalPages: number
}

export type PictureDTO = {
Expand Down Expand Up @@ -147,6 +148,7 @@ export async function list({
)
).map((value) => adminMapEntity(value)),
totalElements: users.totalElements,
totalPages: Math.floor((users.totalElements + size - 1) / size),
size: size,
page: page,
}
Expand All @@ -156,6 +158,7 @@ export async function list({
adminMapEntity(value),
),
totalElements: await userRepo.getCount(),
totalPages: Math.floor(((await userRepo.getCount()) + size - 1) / size),
size: size,
page: page,
}
Expand Down
Binary file modified ui/bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@emotion/react": "11.13.3",
"@emotion/styled": "11.13.0",
"@google/model-viewer": "4.0.0",
"@koupr/ui": "1.10.8",
"@koupr/ui": "1.10.9",
"@nivo/core": "0.87.0",
"@nivo/pie": "0.87.0",
"@reduxjs/toolkit": "2.3.0",
Expand Down
2 changes: 1 addition & 1 deletion ui/src/client/console/console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type ConsoleObject =

export interface ListResponse<T> {
totalElements: number
totalPages: number | null
totalPages: number
page: number
size: number
data: T[]
Expand Down
1 change: 1 addition & 0 deletions ui/src/client/idp/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export interface ConsoleUser extends User {
export interface List {
data: ConsoleUser[]
totalElements: number
totalPages: number
page: number
size: number
}
Expand Down
Loading

0 comments on commit 1cde582

Please sign in to comment.