Skip to content
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

Fix incorrect total user count display on members page #426

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions backend/src/intelligence/intelligence.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ApiTags,
} from "@nestjs/swagger";
import { IntelligenceService } from "./intelligence.service";
import { AuthroizedRequest } from "src/utils/types/req.type";
import { AuthorizedRequest } from "src/utils/types/req.type";
import { Feature } from "./types/feature.type";
import { RunFeatureDto } from "./dto/run-feature.dto";
import { Response } from "express";
Expand All @@ -30,7 +30,7 @@ export class IntelligenceController {
})
@ApiOkResponse({ type: String })
async runFollowUp(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Res() res: Response,
@Body() runFollowUpDto: RunFollowUpDto
): Promise<void> {
Expand All @@ -53,7 +53,7 @@ export class IntelligenceController {
})
@ApiOkResponse({ type: String })
async runFeature(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Res() res: Response,
@Param("feature") feature: Feature,
@Body() runFeatureDto: RunFeatureDto
Expand Down
6 changes: 3 additions & 3 deletions backend/src/users/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ApiTags,
} from "@nestjs/swagger";
import { UsersService } from "./users.service";
import { AuthroizedRequest } from "src/utils/types/req.type";
import { AuthorizedRequest } from "src/utils/types/req.type";
import { FindUserResponse } from "./types/find-user-response.type";
import { ChangeNicknameDto } from "./dto/change-nickname.dto";

Expand All @@ -24,7 +24,7 @@ export class UsersController {
description: "Return the user information",
})
@ApiOkResponse({ type: FindUserResponse })
async findOne(@Req() req: AuthroizedRequest): Promise<FindUserResponse> {
async findOne(@Req() req: AuthorizedRequest): Promise<FindUserResponse> {
return this.usersService.findOne(req.user.id);
}

Expand All @@ -39,7 +39,7 @@ export class UsersController {
@ApiOkResponse()
@ApiConflictResponse({ description: "The nickname conflicts" })
async changeNickname(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Body() changeNicknameDto: ChangeNicknameDto
): Promise<void> {
return this.usersService.changeNickname(req.user.id, changeNicknameDto.nickname);
Expand Down
2 changes: 1 addition & 1 deletion backend/src/utils/types/req.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export type AuthorizedUser = {
nickname: string;
};

export type AuthroizedRequest = Request & { user: AuthorizedUser };
export type AuthorizedRequest = Request & { user: AuthorizedUser };
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
ApiQuery,
ApiTags,
} from "@nestjs/swagger";
import { AuthroizedRequest } from "src/utils/types/req.type";
import { AuthorizedRequest } from "src/utils/types/req.type";
import { CreateWorkspaceDocumentDto } from "./dto/create-workspace-document.dto";
import { CreateWorkspaceDocumentResponse } from "./types/create-workspace-document-response.type";
import { UpdateDocumentTitleDto } from "./dto/update-document-title.dto";
Expand Down Expand Up @@ -68,7 +68,7 @@ export class WorkspaceDocumentsController {
@Param("workspace_id") workspaceId: string,
@Param("document_id") documentId: string,
@Body() updateDocumentTitleDto: UpdateDocumentTitleDto,
@Req() req: AuthroizedRequest
@Req() req: AuthorizedRequest
): Promise<void> {
await this.workspaceDocumentsService.updateTitle(
req.user.id,
Expand Down Expand Up @@ -101,7 +101,7 @@ export class WorkspaceDocumentsController {
required: false,
})
async findMany(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Param("workspace_id") workspaceId: string,
@Query("page_size", new DefaultValuePipe(10), ParseIntPipe) pageSize: number,
@Query("cursor", new DefaultValuePipe(undefined)) cursor?: string
Expand All @@ -120,7 +120,7 @@ export class WorkspaceDocumentsController {
"The workspace or document does not exist, or the user lacks the appropriate permissions.",
})
async findOne(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Param("workspace_id") workspaceId: string,
@Param("document_id") documentId: string
): Promise<FindWorkspaceDocumentResponse> {
Expand All @@ -138,7 +138,7 @@ export class WorkspaceDocumentsController {
description: "The workspace does not exist, or the user lacks the appropriate permissions.",
})
async create(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Param("workspace_id") workspaceId: string,
@Body() createWorkspaceDocumentDto: CreateWorkspaceDocumentDto
): Promise<CreateWorkspaceDocumentResponse> {
Expand All @@ -161,7 +161,7 @@ export class WorkspaceDocumentsController {
"The workspace or document does not exist, or the user lacks the appropriate permissions.",
})
async createShareToken(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Param("workspace_id") workspaceId: string,
@Param("document_id") documentId: string,
@Body() createWorkspaceDocumentShareTokenDto: CreateWorkspaceDocumentShareTokenDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export class FindWorkspaceUsersResponse {

@ApiProperty({ type: String, description: "The ID of last workspace user" })
cursor: string | null;

@ApiProperty({ type: Number, description: "The number of total workspace users" })
totalLength: number;
}
4 changes: 2 additions & 2 deletions backend/src/workspace-users/workspace-users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
ApiTags,
} from "@nestjs/swagger";
import { FindWorkspaceUsersResponse } from "./types/find-workspace-users-response.type";
import { AuthroizedRequest } from "src/utils/types/req.type";
import { AuthorizedRequest } from "src/utils/types/req.type";
import { WorkspaceUsersService } from "./workspace-users.service";
import { HttpExceptionResponse } from "src/utils/types/http-exception-response.type";

Expand Down Expand Up @@ -42,7 +42,7 @@ export class WorkspaceUsersController {
required: false,
})
async findMany(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Param("workspace_id") workspaceId: string,
@Query("page_size", new DefaultValuePipe(10), ParseIntPipe) pageSize: number,
@Query("cursor", new DefaultValuePipe(undefined)) cursor?: string
Expand Down
13 changes: 13 additions & 0 deletions backend/src/workspace-users/workspace-users.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,22 @@ export class WorkspaceUsersService {
...additionalOptions,
});

const totalLength = await this.prismaService.user.count({
where: {
userWorkspaceList: {
some: {
workspaceId: {
equals: workspaceId,
},
},
},
},
});

return {
workspaceUsers: workspaceUserList.slice(0, pageSize),
cursor: workspaceUserList.length > pageSize ? workspaceUserList[pageSize].id : null,
totalLength,
};
}
}
12 changes: 6 additions & 6 deletions backend/src/workspaces/workspaces.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
ApiUnauthorizedResponse,
} from "@nestjs/swagger";
import { HttpExceptionResponse } from "src/utils/types/http-exception-response.type";
import { AuthroizedRequest } from "src/utils/types/req.type";
import { AuthorizedRequest } from "src/utils/types/req.type";
import { CreateInvitationTokenDto } from "./dto/create-invitation-token.dto";
import { CreateWorkspaceDto } from "./dto/create-workspace.dto";
import { JoinWorkspaceDto } from "./dto/join-workspace.dto";
Expand All @@ -48,7 +48,7 @@ export class WorkspacesController {
@ApiBody({ type: CreateWorkspaceDto })
@ApiCreatedResponse({ type: CreateWorkspaceResponse })
async create(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Body() createWorkspaceDto: CreateWorkspaceDto
): Promise<CreateWorkspaceResponse> {
return this.workspacesService.create(req.user.id, createWorkspaceDto.title);
Expand All @@ -65,7 +65,7 @@ export class WorkspacesController {
description: "The workspace does not exist, or the user lacks the appropriate permissions.",
})
async findOne(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Param("workspace_slug") workspaceSlug: string
): Promise<FindWorkspaceResponse> {
return this.workspacesService.findOneBySlug(req.user.id, encodeURI(workspaceSlug));
Expand All @@ -91,7 +91,7 @@ export class WorkspacesController {
required: false,
})
async findMany(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Query("page_size", new DefaultValuePipe(10), ParseIntPipe) pageSize: number,
@Query("cursor", new DefaultValuePipe(undefined)) cursor?: string
): Promise<FindWorkspacesResponse> {
Expand All @@ -115,7 +115,7 @@ export class WorkspacesController {
description: "The workspace does not exist, or the user lacks the appropriate permissions.",
})
async createInvitationToken(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Param("workspace_id") workspaceId: string,
@Body() createInvitationTokenDto: CreateInvitationTokenDto
): Promise<CreateInvitationTokenResponse> {
Expand Down Expand Up @@ -143,7 +143,7 @@ export class WorkspacesController {
type: HttpExceptionResponse,
})
async join(
@Req() req: AuthroizedRequest,
@Req() req: AuthorizedRequest,
@Body() joinWorkspaceDto: JoinWorkspaceDto
): Promise<JoinWorkspaceResponse> {
return this.workspacesService.join(req.user.id, joinWorkspaceDto.invitationToken);
Expand Down
18 changes: 9 additions & 9 deletions frontend/src/components/drawers/WorkspaceDrawer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import KeyboardDoubleArrowLeftIcon from "@mui/icons-material/KeyboardDoubleArrowLeft";
import KeyboardDoubleArrowRightIcon from "@mui/icons-material/KeyboardDoubleArrowRight";
import PeopleIcon from "@mui/icons-material/People";
import SpaceDashboardIcon from "@mui/icons-material/SpaceDashboard";
import {
Box,
Collapse,
Expand All @@ -7,16 +11,12 @@ import {
ListItemText,
Paper,
} from "@mui/material";
import { useDispatch } from "react-redux";
import { useMemo, useState } from "react";
import SpaceDashboardIcon from "@mui/icons-material/SpaceDashboard";
import PeopleIcon from "@mui/icons-material/People";
import { WorkspaceDrawerHeader } from "../layouts/WorkspaceLayout";
import { useDispatch } from "react-redux";
import { useLocation, useNavigate, useParams } from "react-router-dom";
import { COLLAPESED_DRAWER_WIDTH, DRAWER_WIDTH } from "../../constants/layout";
import KeyboardDoubleArrowRightIcon from "@mui/icons-material/KeyboardDoubleArrowRight";
import KeyboardDoubleArrowLeftIcon from "@mui/icons-material/KeyboardDoubleArrowLeft";
import { COLLAPSED_DRAWER_WIDTH, DRAWER_WIDTH } from "../../constants/layout";
import { setDrawerOpen } from "../../store/configSlice";
import { WorkspaceDrawerHeader } from "../layouts/WorkspaceLayout";

interface WorkspaceDrawerProps {
open: boolean;
Expand Down Expand Up @@ -64,7 +64,7 @@ function WorkspaceDrawer(props: WorkspaceDrawerProps) {

return (
<Box>
<Box sx={{ width: open ? DRAWER_WIDTH : COLLAPESED_DRAWER_WIDTH }} />
<Box sx={{ width: open ? DRAWER_WIDTH : COLLAPSED_DRAWER_WIDTH }} />
<Paper
sx={{
position: "fixed",
Expand All @@ -77,7 +77,7 @@ function WorkspaceDrawer(props: WorkspaceDrawerProps) {
<Collapse
orientation="horizontal"
in={hovered || open}
collapsedSize={COLLAPESED_DRAWER_WIDTH}
collapsedSize={COLLAPSED_DRAWER_WIDTH}
>
<Box
sx={{
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/constants/layout.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const DRAWER_WIDTH = 256;
export const COLLAPESED_DRAWER_WIDTH = 64;
export const COLLAPSED_DRAWER_WIDTH = 64;
1 change: 1 addition & 0 deletions frontend/src/hooks/api/types/workspaceUser.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { User } from "./user";
export class GetWorkspaceUserListResponse {
cursor: string | null;
workspaceUsers: Array<User>;
totalLength: number;
}
20 changes: 11 additions & 9 deletions frontend/src/pages/workspace/member/Index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { useParams } from "react-router-dom";
import { useGetWorkspaceQuery } from "../../../hooks/api/workspace";
import AddIcon from "@mui/icons-material/Add";
import {
Box,
Button,
Expand All @@ -15,27 +14,30 @@ import {
TableRow,
Typography,
} from "@mui/material";
import InfiniteScroll from "react-infinite-scroller";
import { useGetWorkspaceUserListQuery } from "../../../hooks/api/workspaceUser";
import { useMemo, useState } from "react";
import AddIcon from "@mui/icons-material/Add";
import { User } from "../../../hooks/api/types/user";
import InfiniteScroll from "react-infinite-scroller";
import { useParams } from "react-router-dom";
import MemberModal from "../../../components/modals/MemberModal";
import { User } from "../../../hooks/api/types/user";
import { useGetWorkspaceQuery } from "../../../hooks/api/workspace";
import { useGetWorkspaceUserListQuery } from "../../../hooks/api/workspaceUser";

function MemberIndex() {
const params = useParams();
const { data: workspace } = useGetWorkspaceQuery(params.workspaceSlug);

const {
data: workspaceUserPageList,
fetchNextPage,
hasNextPage,
} = useGetWorkspaceUserListQuery(workspace?.id);
const [memberModalOpen, setMemberModalOpen] = useState(false);

const userList = useMemo(() => {
return (
workspaceUserPageList?.pages.reduce((prev, page) => {
return prev.concat(page.workspaceUsers);
}, [] as Array<User>) ?? []
}, [] as User[]) ?? []
);
}, [workspaceUserPageList?.pages]);

Expand All @@ -50,7 +52,7 @@ function MemberIndex() {
<Typography variant="h5" fontWeight="bold">
{workspace?.title}{" "}
<Typography component="span" variant="inherit" color="primary">
{workspaceUserPageList?.pages[0].workspaceUsers.length}
{workspaceUserPageList?.pages[0].totalLength}
</Typography>
</Typography>
<Button
Expand All @@ -69,7 +71,7 @@ function MemberIndex() {
hasMore={hasNextPage}
loader={
<Box className="loader" key={0}>
<CircularProgress size="sm" />
<CircularProgress size={20} />
</Box>
}
useWindow={false}
Expand Down
Loading