From e5d4ff586682630d66bd9f5e6b20f50567b2bccf Mon Sep 17 00:00:00 2001 From: Dahyeon Park Date: Tue, 11 Nov 2025 01:34:44 +0900 Subject: [PATCH] Introduces space entity for page organization Adds comprehensive space management capabilities, enabling users to organize pages within distinct, self-contained spaces. This change includes: - Introduces a new 'Space' entity with dedicated API endpoints for CRUD operations. - Develops new UI pages for listing all available spaces and for creating new spaces. - Refactors existing page list, detail, and edit views to operate within the context of a specific space, accessed via a `spaceKey` in the URL. - Updates application routing to establish a hierarchical structure, nesting page-related routes under `/spaces/:spaceKey`. - Enhances navigation and breadcrumbs to reflect the current space context. --- src/app/App.tsx | 12 ++-- src/entities/space/api.ts | 113 ++++++++++++++++++++++++++++++ src/entities/space/index.ts | 2 + src/entities/space/types.ts | 27 ++++++++ src/pages/PageDetailPage.tsx | 11 +-- src/pages/PageEditPage.tsx | 24 ++++--- src/pages/PageListPage.tsx | 69 +++++++++++++++---- src/pages/SpaceEditPage.tsx | 130 +++++++++++++++++++++++++++++++++++ src/pages/SpaceListPage.tsx | 101 +++++++++++++++++++++++++++ src/pages/index.ts | 10 +-- 10 files changed, 463 insertions(+), 36 deletions(-) create mode 100644 src/entities/space/api.ts create mode 100644 src/entities/space/index.ts create mode 100644 src/entities/space/types.ts create mode 100644 src/pages/SpaceEditPage.tsx create mode 100644 src/pages/SpaceListPage.tsx diff --git a/src/app/App.tsx b/src/app/App.tsx index e6b72a3..688fb1e 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -3,7 +3,7 @@ import { BrowserRouter, Routes, Route } from 'react-router-dom'; import { MsalProvider } from '@azure/msal-react'; import { PublicClientApplication } from '@azure/msal-browser'; import { msalConfig } from '../config/authConfig'; -import { PageListPage, PageDetailPage, PageEditPage, TestApiPage } from '../pages'; +import { SpaceListPage, SpaceEditPage, PageListPage, PageDetailPage, PageEditPage, TestApiPage } from '../pages'; const queryClient = new QueryClient({ defaultOptions: { @@ -23,10 +23,12 @@ function App() { - } /> - } /> - } /> - } /> + } /> + } /> + } /> + } /> + } /> + } /> } /> diff --git a/src/entities/space/api.ts b/src/entities/space/api.ts new file mode 100644 index 0000000..62de970 --- /dev/null +++ b/src/entities/space/api.ts @@ -0,0 +1,113 @@ +import type { Space, CreateSpaceData, UpdateSpaceData } from './types'; +import type { ApiClient } from '../../kiota/apiClient'; +import type { SpaceResponseDto, CreateSpaceDto, UpdateSpaceDto } from '../../kiota/models'; +import type { Guid } from '@microsoft/kiota-abstractions'; + +/** + * Convert SpaceResponseDto to local Space type + */ +function mapSpaceResponseToSpace(dto: SpaceResponseDto): Space { + return { + id: dto.spaceId?.toString() || '', + name: dto.nameEscaped || '', + spaceKey: dto.spaceKey || '', + description: dto.description?.toString() || null, + createdAt: dto.createdAt?.toISOString() || new Date().toISOString(), + createdByUserId: dto.createdByUserId?.toString() || '', + }; +} + +/** + * Get all spaces + */ +export async function getSpaces(apiClient: ApiClient): Promise { + const response = await apiClient.v1.space.get(); + + if (!response) { + return []; + } + + return response.map(mapSpaceResponseToSpace); +} + +/** + * Get a specific space by ID + */ +export async function getSpace(apiClient: ApiClient, spaceId: string): Promise { + const response = await apiClient.v1.space.bySpaceId(spaceId as Guid).get(); + + if (!response) { + throw new Error(`Space with id ${spaceId} not found`); + } + + return mapSpaceResponseToSpace(response); +} + +/** + * Get a space by spaceKey + */ +export async function getSpaceByKey(apiClient: ApiClient, spaceKey: string): Promise { + const response = await apiClient.v1.space.key.bySpaceKey(spaceKey).get(); + + if (!response) { + throw new Error(`Space with key ${spaceKey} not found`); + } + + return mapSpaceResponseToSpace(response); +} + +/** + * Create a new space + */ +export async function createSpace( + apiClient: ApiClient, + data: CreateSpaceData, + userId: string +): Promise { + const createDto: CreateSpaceDto = { + name: data.name, + spaceKey: data.spaceKey, + description: data.description, + userId: userId as Guid, + }; + + const response = await apiClient.v1.space.post(createDto); + + if (!response) { + throw new Error('Failed to create space'); + } + + return mapSpaceResponseToSpace(response); +} + +/** + * Update an existing space + */ +export async function updateSpace( + apiClient: ApiClient, + spaceId: string, + data: UpdateSpaceData +): Promise { + const updateDto: UpdateSpaceDto = { + name: data.name, + description: data.description, + }; + + const response = await apiClient.v1.space.bySpaceId(spaceId as Guid).put(updateDto); + + if (!response) { + throw new Error(`Failed to update space ${spaceId}`); + } + + return mapSpaceResponseToSpace(response); +} + +/** + * Delete a space + */ +export async function deleteSpace( + apiClient: ApiClient, + spaceId: string +): Promise { + await apiClient.v1.space.bySpaceId(spaceId as Guid).delete(); +} diff --git a/src/entities/space/index.ts b/src/entities/space/index.ts new file mode 100644 index 0000000..f3b202c --- /dev/null +++ b/src/entities/space/index.ts @@ -0,0 +1,2 @@ +export * from './types'; +export * from './api'; diff --git a/src/entities/space/types.ts b/src/entities/space/types.ts new file mode 100644 index 0000000..0d12cd6 --- /dev/null +++ b/src/entities/space/types.ts @@ -0,0 +1,27 @@ +export interface Space { + id: string; + name: string; + spaceKey: string; + description?: string | null; + createdAt: string; + createdByUserId: string; +} + +export interface CreateSpaceData { + name: string; + spaceKey: string; + description?: string; +} + +export interface UpdateSpaceData { + name: string; + description?: string; +} + +export interface SpaceStatistics { + space: Space; + statistics: { + pageCount?: number; + lastUpdated?: string; + }; +} diff --git a/src/pages/PageDetailPage.tsx b/src/pages/PageDetailPage.tsx index f35f496..c305d15 100644 --- a/src/pages/PageDetailPage.tsx +++ b/src/pages/PageDetailPage.tsx @@ -11,7 +11,7 @@ import { useState } from 'react'; import { useApiClient, useUserId } from '../shared/hooks/useApiClient'; function PageDetailContent() { - const { id } = useParams<{ id: string }>(); + const { spaceKey, id } = useParams<{ spaceKey: string; id: string }>(); const navigate = useNavigate(); const queryClient = useQueryClient(); const [showDeleteDialog, setShowDeleteDialog] = useState(false); @@ -32,7 +32,7 @@ function PageDetailContent() { onSuccess: () => { queryClient.invalidateQueries({ queryKey: ['pages'] }); queryClient.removeQueries({ queryKey: ['page', id] }); - navigate('/'); + navigate(`/spaces/${spaceKey}`); }, }); @@ -53,7 +53,7 @@ function PageDetailContent() { return (

페이지를 찾을 수 없습니다.

- + 목록으로 돌아가기
@@ -64,7 +64,8 @@ function PageDetailContent() { <> @@ -75,7 +76,7 @@ function PageDetailContent() {

{page.title}

diff --git a/src/pages/PageEditPage.tsx b/src/pages/PageEditPage.tsx index acffbe9..5664496 100644 --- a/src/pages/PageEditPage.tsx +++ b/src/pages/PageEditPage.tsx @@ -1,21 +1,25 @@ import { useParams, useNavigate } from 'react-router-dom'; import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'; import { getPage, createPage, updatePage } from '../entities/page'; +import { getSpaceByKey } from '../entities/space'; import { PageForm } from '../features/page'; import { Layout } from '../shared/Layout'; import { Breadcrumb } from '../shared/Breadcrumb'; import { useApiClient, useUserId } from '../shared/hooks/useApiClient'; export function PageEditPage() { - const { id } = useParams<{ id: string }>(); + const { spaceKey, id } = useParams<{ spaceKey: string; id: string }>(); const navigate = useNavigate(); const queryClient = useQueryClient(); const isNew = !id; const apiClient = useApiClient(); const userId = useUserId(); - // TODO: Get spaceId from context or props - using placeholder for now - const spaceId = 'default-space-id'; // This should come from app context or route params + const { data: space } = useQuery({ + queryKey: ['space', spaceKey], + queryFn: () => getSpaceByKey(apiClient, spaceKey!), + enabled: !!spaceKey, + }); const { data: page, isLoading } = useQuery({ queryKey: ['page', id], @@ -26,11 +30,12 @@ export function PageEditPage() { const createMutation = useMutation({ mutationFn: (data: { title: string; content: string }) => { if (!userId) throw new Error('User not authenticated'); - return createPage(apiClient, data, userId, spaceId); + if (!space?.id) throw new Error('Space not found'); + return createPage(apiClient, data, userId, space.id); }, onSuccess: (newPage) => { - queryClient.invalidateQueries({ queryKey: ['pages'] }); - navigate(`/pages/${newPage.id}`); + queryClient.invalidateQueries({ queryKey: ['pages', space?.id] }); + navigate(`/spaces/${spaceKey}/pages/${newPage.id}`); }, }); @@ -41,8 +46,8 @@ export function PageEditPage() { }, onSuccess: (updatedPage) => { queryClient.setQueryData(['page', id], updatedPage); - queryClient.invalidateQueries({ queryKey: ['pages'] }); - navigate(`/pages/${id}`); + queryClient.invalidateQueries({ queryKey: ['pages', space?.id] }); + navigate(`/spaces/${spaceKey}/pages/${id}`); }, }); @@ -74,7 +79,8 @@ export function PageEditPage() { diff --git a/src/pages/PageListPage.tsx b/src/pages/PageListPage.tsx index bf318cb..cc525f7 100644 --- a/src/pages/PageListPage.tsx +++ b/src/pages/PageListPage.tsx @@ -1,18 +1,30 @@ import { useQuery } from '@tanstack/react-query'; -import { Link } from 'react-router-dom'; +import { Link, useParams } from 'react-router-dom'; import { getPages } from '../entities/page'; +import { getSpaceByKey } from '../entities/space'; import { Layout } from '../shared/Layout'; import { Breadcrumb } from '../shared/Breadcrumb'; -import { FileTextIcon } from '@radix-ui/react-icons'; +import { FileTextIcon, PlusIcon } from '@radix-ui/react-icons'; import { useApiClient } from '../shared/hooks/useApiClient'; export function PageListPage() { + const { spaceKey } = useParams<{ spaceKey: string }>(); const apiClient = useApiClient(); - const { data: pages = [], isLoading, error } = useQuery({ - queryKey: ['pages'], - queryFn: () => getPages(apiClient), + const { data: space, isLoading: isLoadingSpace, error: spaceError } = useQuery({ + queryKey: ['space', spaceKey], + queryFn: () => getSpaceByKey(apiClient, spaceKey!), + enabled: !!spaceKey, }); + + const { data: pages = [], isLoading: isLoadingPages, error: pagesError } = useQuery({ + queryKey: ['pages', space?.id], + queryFn: () => getPages(apiClient, space!.id), + enabled: !!space?.id, + }); + + const isLoading = isLoadingSpace || isLoadingPages; + const error = spaceError || pagesError; if (isLoading) { return ( @@ -34,21 +46,50 @@ export function PageListPage() { ); } + if (!space && !isLoading) { + return ( + +
+

스페이스를 찾을 수 없습니다.

+ + 스페이스 목록으로 돌아가기 + +
+
+ ); + } + return ( - +
-

위키 페이지

-

- 모든 문서를 찾아보세요. 왼쪽 사이드바에서 검색하거나 아래 목록을 탐색할 수 있습니다. -

+
+
+

{space?.name}

+ {space?.description && ( +

{space.description}

+ )} +
+ + + 새 페이지 + +
{pages.map((page) => (
@@ -66,13 +107,15 @@ export function PageListPage() { ))}
- {pages.length === 0 && ( + {pages.length === 0 && !isLoading && (
+

아직 페이지가 없습니다.

+ 첫 페이지 만들기
diff --git a/src/pages/SpaceEditPage.tsx b/src/pages/SpaceEditPage.tsx new file mode 100644 index 0000000..d4c73c0 --- /dev/null +++ b/src/pages/SpaceEditPage.tsx @@ -0,0 +1,130 @@ +import { useState } from 'react'; +import { useNavigate } from 'react-router-dom'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { createSpace } from '../entities/space'; +import { Layout } from '../shared/Layout'; +import { Breadcrumb } from '../shared/Breadcrumb'; +import { useApiClient, useUserId } from '../shared/hooks/useApiClient'; + +export function SpaceEditPage() { + const navigate = useNavigate(); + const queryClient = useQueryClient(); + const apiClient = useApiClient(); + const userId = useUserId(); + + const [formData, setFormData] = useState({ + name: '', + spaceKey: '', + description: '', + }); + + const createMutation = useMutation({ + mutationFn: (data: { name: string; spaceKey: string; description?: string }) => { + if (!userId) throw new Error('User not authenticated'); + return createSpace(apiClient, data, userId); + }, + onSuccess: (newSpace) => { + queryClient.invalidateQueries({ queryKey: ['spaces'] }); + navigate(`/spaces/${newSpace.spaceKey}`); + }, + }); + + const handleSubmit = (e: React.FormEvent) => { + e.preventDefault(); + createMutation.mutate(formData); + }; + + const handleCancel = () => { + navigate('/'); + }; + + return ( + + + +
+

새 스페이스 만들기

+ +
+
+ + setFormData({ ...formData, name: e.target.value })} + className="w-full px-4 py-2 bg-[#1e1e1e] border border-[#3e3e42] rounded text-[#e4e4e4] focus:outline-none focus:border-[#0078d4]" + placeholder="예: 개발 문서" + /> +
+ +
+ + setFormData({ ...formData, spaceKey: e.target.value.toLowerCase().replace(/[^a-z0-9-]/g, '') })} + className="w-full px-4 py-2 bg-[#1e1e1e] border border-[#3e3e42] rounded text-[#e4e4e4] focus:outline-none focus:border-[#0078d4] font-mono" + placeholder="예: dev-docs" + /> +

+ URL에 사용됩니다. 영문 소문자, 숫자, 하이픈만 사용 가능합니다. +

+
+ +
+ +